blob: 32f1264f7f1ab7a8fd783596ca60dbeff1f0d1e8 [file] [log] [blame]
ager@chromium.org9258b6b2008-09-11 09:11:10 +00001// Copyright 2006-2008 the V8 project authors. All rights reserved.
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +00002// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8// * Redistributions in binary form must reproduce the above
9// copyright notice, this list of conditions and the following
10// disclaimer in the documentation and/or other materials provided
11// with the distribution.
12// * Neither the name of Google Inc. nor the names of its
13// contributors may be used to endorse or promote products derived
14// from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
27
28#include <stdlib.h>
29
30#include "v8.h"
31#include "cctest.h"
32
33using namespace v8::internal;
34
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +000035// This test must be executed first!
36TEST(Default) {
kasperl@chromium.orgb9123622008-09-17 14:05:56 +000037 CHECK(FLAG_testing_bool_flag);
38 CHECK_EQ(13, FLAG_testing_int_flag);
39 CHECK_EQ(2.5, FLAG_testing_float_flag);
40 CHECK_EQ(0, strcmp(FLAG_testing_string_flag, "Hello, world!"));
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +000041}
42
43
44static void SetFlagsToDefault() {
kasperl@chromium.orgb9123622008-09-17 14:05:56 +000045 FlagList::ResetAllFlags();
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +000046 TestDefault();
47}
48
49
50TEST(Flags1) {
kasperl@chromium.orgb9123622008-09-17 14:05:56 +000051 FlagList::PrintHelp();
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +000052}
53
54
55TEST(Flags2) {
56 SetFlagsToDefault();
57 int argc = 7;
kasperl@chromium.orgb9123622008-09-17 14:05:56 +000058 const char* argv[] = { "Test2", "-notesting-bool-flag", "notaflag",
59 "--testing_int_flag=77", "-testing_float_flag=.25",
60 "--testing_string_flag", "no way!" };
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +000061 CHECK_EQ(0, FlagList::SetFlagsFromCommandLine(&argc,
62 const_cast<char **>(argv),
63 false));
64 CHECK_EQ(7, argc);
kasperl@chromium.orgb9123622008-09-17 14:05:56 +000065 CHECK(!FLAG_testing_bool_flag);
66 CHECK_EQ(77, FLAG_testing_int_flag);
67 CHECK_EQ(.25, FLAG_testing_float_flag);
68 CHECK_EQ(0, strcmp(FLAG_testing_string_flag, "no way!"));
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +000069}
70
71
72TEST(Flags2b) {
73 SetFlagsToDefault();
74 const char* str =
kasperl@chromium.orgb9123622008-09-17 14:05:56 +000075 " -notesting-bool-flag notaflag --testing_int_flag=77 "
76 "-testing_float_flag=.25 "
77 "--testing_string_flag no_way! ";
ager@chromium.orgc4c92722009-11-18 14:12:51 +000078 CHECK_EQ(0, FlagList::SetFlagsFromString(str, StrLength(str)));
kasperl@chromium.orgb9123622008-09-17 14:05:56 +000079 CHECK(!FLAG_testing_bool_flag);
80 CHECK_EQ(77, FLAG_testing_int_flag);
81 CHECK_EQ(.25, FLAG_testing_float_flag);
82 CHECK_EQ(0, strcmp(FLAG_testing_string_flag, "no_way!"));
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +000083}
84
85
86TEST(Flags3) {
87 SetFlagsToDefault();
88 int argc = 8;
89 const char* argv[] =
kasperl@chromium.orgb9123622008-09-17 14:05:56 +000090 { "Test3", "--testing_bool_flag", "notaflag",
91 "--testing_int_flag", "-666",
92 "--testing_float_flag", "-12E10", "-testing-string-flag=foo-bar" };
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +000093 CHECK_EQ(0, FlagList::SetFlagsFromCommandLine(&argc,
94 const_cast<char **>(argv),
95 true));
96 CHECK_EQ(2, argc);
kasperl@chromium.orgb9123622008-09-17 14:05:56 +000097 CHECK(FLAG_testing_bool_flag);
98 CHECK_EQ(-666, FLAG_testing_int_flag);
99 CHECK_EQ(-12E10, FLAG_testing_float_flag);
100 CHECK_EQ(0, strcmp(FLAG_testing_string_flag, "foo-bar"));
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000101}
102
103
104TEST(Flags3b) {
105 SetFlagsToDefault();
106 const char* str =
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000107 "--testing_bool_flag notaflag --testing_int_flag -666 "
108 "--testing_float_flag -12E10 "
109 "-testing-string-flag=foo-bar";
ager@chromium.orgc4c92722009-11-18 14:12:51 +0000110 CHECK_EQ(0, FlagList::SetFlagsFromString(str, StrLength(str)));
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000111 CHECK(FLAG_testing_bool_flag);
112 CHECK_EQ(-666, FLAG_testing_int_flag);
113 CHECK_EQ(-12E10, FLAG_testing_float_flag);
114 CHECK_EQ(0, strcmp(FLAG_testing_string_flag, "foo-bar"));
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000115}
116
117
118TEST(Flags4) {
119 SetFlagsToDefault();
120 int argc = 3;
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000121 const char* argv[] = { "Test4", "--testing_bool_flag", "--foo" };
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000122 CHECK_EQ(0, FlagList::SetFlagsFromCommandLine(&argc,
123 const_cast<char **>(argv),
124 true));
125 CHECK_EQ(2, argc);
126}
127
128
129TEST(Flags4b) {
130 SetFlagsToDefault();
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000131 const char* str = "--testing_bool_flag --foo";
ager@chromium.orgc4c92722009-11-18 14:12:51 +0000132 CHECK_EQ(2, FlagList::SetFlagsFromString(str, StrLength(str)));
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000133}
134
135
136TEST(Flags5) {
137 SetFlagsToDefault();
138 int argc = 2;
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000139 const char* argv[] = { "Test5", "--testing_int_flag=\"foobar\"" };
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000140 CHECK_EQ(1, FlagList::SetFlagsFromCommandLine(&argc,
141 const_cast<char **>(argv),
142 true));
143 CHECK_EQ(2, argc);
144}
145
146
147TEST(Flags5b) {
148 SetFlagsToDefault();
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000149 const char* str = " --testing_int_flag=\"foobar\"";
ager@chromium.orgc4c92722009-11-18 14:12:51 +0000150 CHECK_EQ(1, FlagList::SetFlagsFromString(str, StrLength(str)));
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000151}
152
153
154TEST(Flags6) {
155 SetFlagsToDefault();
156 int argc = 4;
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000157 const char* argv[] = { "Test5", "--testing-int-flag", "0",
158 "--testing_float_flag" };
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000159 CHECK_EQ(3, FlagList::SetFlagsFromCommandLine(&argc,
160 const_cast<char **>(argv),
161 true));
162 CHECK_EQ(4, argc);
163}
164
165
166TEST(Flags6b) {
167 SetFlagsToDefault();
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000168 const char* str = " --testing-int-flag 0 --testing_float_flag ";
ager@chromium.orgc4c92722009-11-18 14:12:51 +0000169 CHECK_EQ(3, FlagList::SetFlagsFromString(str, StrLength(str)));
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000170}
ager@chromium.org3bf7b912008-11-17 09:09:45 +0000171
172
173TEST(FlagsJSArguments1) {
174 SetFlagsToDefault();
175 int argc = 6;
176 const char* argv[] = {"TestJSArgs1",
177 "--testing-int-flag", "42",
178 "--", "testing-float-flag", "7"};
179 CHECK_EQ(0, FlagList::SetFlagsFromCommandLine(&argc,
180 const_cast<char **>(argv),
181 true));
182 CHECK_EQ(42, FLAG_testing_int_flag);
183 CHECK_EQ(2.5, FLAG_testing_float_flag);
184 CHECK_EQ(2, FLAG_js_arguments.argc());
185 CHECK_EQ(0, strcmp(FLAG_js_arguments[0], "testing-float-flag"));
186 CHECK_EQ(0, strcmp(FLAG_js_arguments[1], "7"));
187 CHECK_EQ(1, argc);
188}
189
190
191TEST(FlagsJSArguments1b) {
192 SetFlagsToDefault();
193 const char* str = "--testing-int-flag 42 -- testing-float-flag 7";
ager@chromium.orgc4c92722009-11-18 14:12:51 +0000194 CHECK_EQ(0, FlagList::SetFlagsFromString(str, StrLength(str)));
ager@chromium.org3bf7b912008-11-17 09:09:45 +0000195 CHECK_EQ(42, FLAG_testing_int_flag);
196 CHECK_EQ(2.5, FLAG_testing_float_flag);
197 CHECK_EQ(2, FLAG_js_arguments.argc());
198 CHECK_EQ(0, strcmp(FLAG_js_arguments[0], "testing-float-flag"));
199 CHECK_EQ(0, strcmp(FLAG_js_arguments[1], "7"));
200}
201
202
203TEST(FlagsJSArguments2) {
204 SetFlagsToDefault();
205 const char* str = "--testing-int-flag 42 --js-arguments testing-float-flag 7";
ager@chromium.orgc4c92722009-11-18 14:12:51 +0000206 CHECK_EQ(0, FlagList::SetFlagsFromString(str, StrLength(str)));
ager@chromium.org3bf7b912008-11-17 09:09:45 +0000207 CHECK_EQ(42, FLAG_testing_int_flag);
208 CHECK_EQ(2.5, FLAG_testing_float_flag);
209 CHECK_EQ(2, FLAG_js_arguments.argc());
210 CHECK_EQ(0, strcmp(FLAG_js_arguments[0], "testing-float-flag"));
211 CHECK_EQ(0, strcmp(FLAG_js_arguments[1], "7"));
212}
213
214
215TEST(FlagsJSArguments3) {
216 SetFlagsToDefault();
217 const char* str = "--testing-int-flag 42 --js-arguments=testing-float-flag 7";
ager@chromium.orgc4c92722009-11-18 14:12:51 +0000218 CHECK_EQ(0, FlagList::SetFlagsFromString(str, StrLength(str)));
ager@chromium.org3bf7b912008-11-17 09:09:45 +0000219 CHECK_EQ(42, FLAG_testing_int_flag);
220 CHECK_EQ(2.5, FLAG_testing_float_flag);
221 CHECK_EQ(2, FLAG_js_arguments.argc());
222 CHECK_EQ(0, strcmp(FLAG_js_arguments[0], "testing-float-flag"));
223 CHECK_EQ(0, strcmp(FLAG_js_arguments[1], "7"));
224}
225
226
227TEST(FlagsJSArguments4) {
228 SetFlagsToDefault();
229 const char* str = "--testing-int-flag 42 --";
ager@chromium.orgc4c92722009-11-18 14:12:51 +0000230 CHECK_EQ(0, FlagList::SetFlagsFromString(str, StrLength(str)));
ager@chromium.org3bf7b912008-11-17 09:09:45 +0000231 CHECK_EQ(42, FLAG_testing_int_flag);
232 CHECK_EQ(0, FLAG_js_arguments.argc());
233}
234