Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Side by Side Diff: tools/gn/c_include_iterator_unittest.cc

Issue 216903004: Add optional public header checking to GN build (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review comments Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "testing/gtest/include/gtest/gtest.h"
6 #include "tools/gn/c_include_iterator.h"
7
8 TEST(CIncludeIterator, Basic) {
9 std::string buffer;
10 buffer.append("// Some comment\n");
11 buffer.append("\n");
12 buffer.append("#include \"foo/bar.h\"\n");
13 buffer.append("\n");
14 buffer.append("#include <stdio.h>\n");
15 buffer.append("\n");
16 buffer.append(" #include \"foo/baz.h\"\n"); // Leading whitespace
17 buffer.append("#include \"la/deda.h\"\n");
18 buffer.append("#import \"weird_mac_import.h\"\n");
19 buffer.append("\n");
20 buffer.append("void SomeCode() {\n");
21
22 CIncludeIterator iter(buffer);
23
24 base::StringPiece contents;
25 EXPECT_TRUE(iter.GetNextIncludeString(&contents));
26 EXPECT_EQ("foo/bar.h", contents);
27 EXPECT_TRUE(iter.GetNextIncludeString(&contents));
28 EXPECT_EQ("foo/baz.h", contents);
29 EXPECT_TRUE(iter.GetNextIncludeString(&contents));
30 EXPECT_EQ("la/deda.h", contents);
31 EXPECT_TRUE(iter.GetNextIncludeString(&contents));
32 EXPECT_EQ("weird_mac_import.h", contents);
33 EXPECT_FALSE(iter.GetNextIncludeString(&contents));
34 }
35
36 // Tests that we don't search for includes indefinitely.
37 TEST(CIncludeIterator, GiveUp) {
38 std::string buffer;
39 for (size_t i = 0; i < 1000; i++)
40 buffer.append("x\n");
41 buffer.append("#include \"foo/bar.h\"\n");
42
43 base::StringPiece contents;
44
45 CIncludeIterator iter(buffer);
46 EXPECT_FALSE(iter.GetNextIncludeString(&contents));
47 EXPECT_TRUE(contents.empty());
48 }
49
50 // Don't count blank lines, comments, and preprocessor when giving up.
51 TEST(CIncludeIterator, DontGiveUp) {
52
53 std::string buffer;
54 for (size_t i = 0; i < 1000; i++)
55 buffer.push_back('\n');
56 for (size_t i = 0; i < 1000; i++)
57 buffer.append("// comment\n");
58 for (size_t i = 0; i < 1000; i++)
59 buffer.append("#preproc\n");
60 buffer.append("#include \"foo/bar.h\"\n");
61
62 base::StringPiece contents;
63
64 CIncludeIterator iter(buffer);
65 EXPECT_TRUE(iter.GetNextIncludeString(&contents));
66 EXPECT_EQ("foo/bar.h", contents);
67 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698