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

Side by Side Diff: test/cctest/test-flags.cc

Issue 1935: New static flags system (Closed)
Patch Set: Merge, again. Created 12 years, 3 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
« no previous file with comments | « test/cctest/test-debug.cc ('k') | test/cctest/test-mark-compact.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 14 matching lines...) Expand all
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #include <stdlib.h> 28 #include <stdlib.h>
29 29
30 #include "v8.h" 30 #include "v8.h"
31 #include "cctest.h" 31 #include "cctest.h"
32 32
33 using namespace v8::internal; 33 using namespace v8::internal;
34 34
35 DEFINE_bool(bool_flag, true, "bool_flag");
36 DEFINE_int(int_flag, 13, "int_flag");
37 DEFINE_float(float_flag, 2.5, "float-flag");
38 DEFINE_string(string_flag, "Hello, world!", "string-flag");
39
40
41 // This test must be executed first! 35 // This test must be executed first!
42 TEST(Default) { 36 TEST(Default) {
43 CHECK(FLAG_bool_flag); 37 CHECK(FLAG_testing_bool_flag);
44 CHECK_EQ(13, FLAG_int_flag); 38 CHECK_EQ(13, FLAG_testing_int_flag);
45 CHECK_EQ(2.5, FLAG_float_flag); 39 CHECK_EQ(2.5, FLAG_testing_float_flag);
46 CHECK_EQ(0, strcmp(FLAG_string_flag, "Hello, world!")); 40 CHECK_EQ(0, strcmp(FLAG_testing_string_flag, "Hello, world!"));
47 } 41 }
48 42
49 43
50 static void SetFlagsToDefault() { 44 static void SetFlagsToDefault() {
51 for (Flag* f = FlagList::list(); f != NULL; f = f->next()) { 45 FlagList::ResetAllFlags();
52 f->SetToDefault();
53 }
54 TestDefault(); 46 TestDefault();
55 } 47 }
56 48
57 49
58 TEST(Flags1) { 50 TEST(Flags1) {
59 FlagList::Print(__FILE__, false); 51 FlagList::PrintHelp();
60 FlagList::Print(NULL, true);
61 } 52 }
62 53
63 54
64 TEST(Flags2) { 55 TEST(Flags2) {
65 SetFlagsToDefault(); 56 SetFlagsToDefault();
66 int argc = 7; 57 int argc = 7;
67 const char* argv[] = { "Test2", "-nobool-flag", "notaflag", "--int_flag=77", 58 const char* argv[] = { "Test2", "-notesting-bool-flag", "notaflag",
68 "-float_flag=.25", "--string_flag", "no way!" }; 59 "--testing_int_flag=77", "-testing_float_flag=.25",
60 "--testing_string_flag", "no way!" };
69 CHECK_EQ(0, FlagList::SetFlagsFromCommandLine(&argc, 61 CHECK_EQ(0, FlagList::SetFlagsFromCommandLine(&argc,
70 const_cast<char **>(argv), 62 const_cast<char **>(argv),
71 false)); 63 false));
72 CHECK_EQ(7, argc); 64 CHECK_EQ(7, argc);
73 CHECK(!FLAG_bool_flag); 65 CHECK(!FLAG_testing_bool_flag);
74 CHECK_EQ(77, FLAG_int_flag); 66 CHECK_EQ(77, FLAG_testing_int_flag);
75 CHECK_EQ(.25, FLAG_float_flag); 67 CHECK_EQ(.25, FLAG_testing_float_flag);
76 CHECK_EQ(0, strcmp(FLAG_string_flag, "no way!")); 68 CHECK_EQ(0, strcmp(FLAG_testing_string_flag, "no way!"));
77 } 69 }
78 70
79 71
80 TEST(Flags2b) { 72 TEST(Flags2b) {
81 SetFlagsToDefault(); 73 SetFlagsToDefault();
82 const char* str = 74 const char* str =
83 " -nobool-flag notaflag --int_flag=77 -float_flag=.25 " 75 " -notesting-bool-flag notaflag --testing_int_flag=77 "
84 "--string_flag no_way! "; 76 "-testing_float_flag=.25 "
77 "--testing_string_flag no_way! ";
85 CHECK_EQ(0, FlagList::SetFlagsFromString(str, strlen(str))); 78 CHECK_EQ(0, FlagList::SetFlagsFromString(str, strlen(str)));
86 CHECK(!FLAG_bool_flag); 79 CHECK(!FLAG_testing_bool_flag);
87 CHECK_EQ(77, FLAG_int_flag); 80 CHECK_EQ(77, FLAG_testing_int_flag);
88 CHECK_EQ(.25, FLAG_float_flag); 81 CHECK_EQ(.25, FLAG_testing_float_flag);
89 CHECK_EQ(0, strcmp(FLAG_string_flag, "no_way!")); 82 CHECK_EQ(0, strcmp(FLAG_testing_string_flag, "no_way!"));
90 } 83 }
91 84
92 85
93 TEST(Flags3) { 86 TEST(Flags3) {
94 SetFlagsToDefault(); 87 SetFlagsToDefault();
95 int argc = 8; 88 int argc = 8;
96 const char* argv[] = 89 const char* argv[] =
97 { "Test3", "--bool_flag", "notaflag", "--int_flag", "-666", 90 { "Test3", "--testing_bool_flag", "notaflag",
98 "--float_flag", "-12E10", "-string-flag=foo-bar" }; 91 "--testing_int_flag", "-666",
92 "--testing_float_flag", "-12E10", "-testing-string-flag=foo-bar" };
99 CHECK_EQ(0, FlagList::SetFlagsFromCommandLine(&argc, 93 CHECK_EQ(0, FlagList::SetFlagsFromCommandLine(&argc,
100 const_cast<char **>(argv), 94 const_cast<char **>(argv),
101 true)); 95 true));
102 CHECK_EQ(2, argc); 96 CHECK_EQ(2, argc);
103 CHECK(FLAG_bool_flag); 97 CHECK(FLAG_testing_bool_flag);
104 CHECK_EQ(-666, FLAG_int_flag); 98 CHECK_EQ(-666, FLAG_testing_int_flag);
105 CHECK_EQ(-12E10, FLAG_float_flag); 99 CHECK_EQ(-12E10, FLAG_testing_float_flag);
106 CHECK_EQ(0, strcmp(FLAG_string_flag, "foo-bar")); 100 CHECK_EQ(0, strcmp(FLAG_testing_string_flag, "foo-bar"));
107 } 101 }
108 102
109 103
110 TEST(Flags3b) { 104 TEST(Flags3b) {
111 SetFlagsToDefault(); 105 SetFlagsToDefault();
112 const char* str = 106 const char* str =
113 "--bool_flag notaflag --int_flag -666 --float_flag -12E10 " 107 "--testing_bool_flag notaflag --testing_int_flag -666 "
114 "-string-flag=foo-bar"; 108 "--testing_float_flag -12E10 "
109 "-testing-string-flag=foo-bar";
115 CHECK_EQ(0, FlagList::SetFlagsFromString(str, strlen(str))); 110 CHECK_EQ(0, FlagList::SetFlagsFromString(str, strlen(str)));
116 CHECK(FLAG_bool_flag); 111 CHECK(FLAG_testing_bool_flag);
117 CHECK_EQ(-666, FLAG_int_flag); 112 CHECK_EQ(-666, FLAG_testing_int_flag);
118 CHECK_EQ(-12E10, FLAG_float_flag); 113 CHECK_EQ(-12E10, FLAG_testing_float_flag);
119 CHECK_EQ(0, strcmp(FLAG_string_flag, "foo-bar")); 114 CHECK_EQ(0, strcmp(FLAG_testing_string_flag, "foo-bar"));
120 } 115 }
121 116
122 117
123 TEST(Flags4) { 118 TEST(Flags4) {
124 SetFlagsToDefault(); 119 SetFlagsToDefault();
125 int argc = 3; 120 int argc = 3;
126 const char* argv[] = { "Test4", "--bool_flag", "--foo" }; 121 const char* argv[] = { "Test4", "--testing_bool_flag", "--foo" };
127 CHECK_EQ(0, FlagList::SetFlagsFromCommandLine(&argc, 122 CHECK_EQ(0, FlagList::SetFlagsFromCommandLine(&argc,
128 const_cast<char **>(argv), 123 const_cast<char **>(argv),
129 true)); 124 true));
130 CHECK_EQ(2, argc); 125 CHECK_EQ(2, argc);
131 } 126 }
132 127
133 128
134 TEST(Flags4b) { 129 TEST(Flags4b) {
135 SetFlagsToDefault(); 130 SetFlagsToDefault();
136 const char* str = "--bool_flag --foo"; 131 const char* str = "--testing_bool_flag --foo";
137 CHECK_EQ(2, FlagList::SetFlagsFromString(str, strlen(str))); 132 CHECK_EQ(2, FlagList::SetFlagsFromString(str, strlen(str)));
138 } 133 }
139 134
140 135
141 TEST(Flags5) { 136 TEST(Flags5) {
142 SetFlagsToDefault(); 137 SetFlagsToDefault();
143 int argc = 2; 138 int argc = 2;
144 const char* argv[] = { "Test5", "--int_flag=\"foobar\"" }; 139 const char* argv[] = { "Test5", "--testing_int_flag=\"foobar\"" };
145 CHECK_EQ(1, FlagList::SetFlagsFromCommandLine(&argc, 140 CHECK_EQ(1, FlagList::SetFlagsFromCommandLine(&argc,
146 const_cast<char **>(argv), 141 const_cast<char **>(argv),
147 true)); 142 true));
148 CHECK_EQ(2, argc); 143 CHECK_EQ(2, argc);
149 } 144 }
150 145
151 146
152 TEST(Flags5b) { 147 TEST(Flags5b) {
153 SetFlagsToDefault(); 148 SetFlagsToDefault();
154 const char* str = " --int_flag=\"foobar\""; 149 const char* str = " --testing_int_flag=\"foobar\"";
155 CHECK_EQ(1, FlagList::SetFlagsFromString(str, strlen(str))); 150 CHECK_EQ(1, FlagList::SetFlagsFromString(str, strlen(str)));
156 } 151 }
157 152
158 153
159 TEST(Flags6) { 154 TEST(Flags6) {
160 SetFlagsToDefault(); 155 SetFlagsToDefault();
161 int argc = 4; 156 int argc = 4;
162 const char* argv[] = { "Test5", "--int-flag", "0", "--float_flag" }; 157 const char* argv[] = { "Test5", "--testing-int-flag", "0",
158 "--testing_float_flag" };
163 CHECK_EQ(3, FlagList::SetFlagsFromCommandLine(&argc, 159 CHECK_EQ(3, FlagList::SetFlagsFromCommandLine(&argc,
164 const_cast<char **>(argv), 160 const_cast<char **>(argv),
165 true)); 161 true));
166 CHECK_EQ(4, argc); 162 CHECK_EQ(4, argc);
167 } 163 }
168 164
169 165
170 TEST(Flags6b) { 166 TEST(Flags6b) {
171 SetFlagsToDefault(); 167 SetFlagsToDefault();
172 const char* str = " --int-flag 0 --float_flag "; 168 const char* str = " --testing-int-flag 0 --testing_float_flag ";
173 CHECK_EQ(3, FlagList::SetFlagsFromString(str, strlen(str))); 169 CHECK_EQ(3, FlagList::SetFlagsFromString(str, strlen(str)));
174 } 170 }
OLDNEW
« no previous file with comments | « test/cctest/test-debug.cc ('k') | test/cctest/test-mark-compact.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698