1// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
5#include "vm/flags.h"
6#include "platform/assert.h"
7#include "vm/heap/heap.h"
8#include "vm/unit_test.h"
9
10namespace dart {
11
12DEFINE_FLAG(bool, basic_flag, true, "Testing of a basic boolean flag.");
13
14DECLARE_FLAG(bool, print_flags);
15
16VM_UNIT_TEST_CASE(BasicFlags) {
17 EXPECT_EQ(true, FLAG_basic_flag);
18 EXPECT_EQ(false, FLAG_verbose_gc);
19 EXPECT_EQ(false, FLAG_print_flags);
20}
21
22DEFINE_FLAG(bool, parse_flag_bool_test, true, "Flags::Parse (bool) testing");
23DEFINE_FLAG(charp, string_opt_test, NULL, "Testing: string option.");
24DEFINE_FLAG(charp, entrypoint_test, "main", "Testing: entrypoint");
25DEFINE_FLAG(int, counter, 100, "Testing: int flag");
26
27VM_UNIT_TEST_CASE(ParseFlags) {
28 EXPECT_EQ(true, FLAG_parse_flag_bool_test);
29 Flags::Parse("no_parse_flag_bool_test");
30 EXPECT_EQ(false, FLAG_parse_flag_bool_test);
31 Flags::Parse("parse_flag_bool_test");
32 EXPECT_EQ(true, FLAG_parse_flag_bool_test);
33 Flags::Parse("parse_flag_bool_test=false");
34 EXPECT_EQ(false, FLAG_parse_flag_bool_test);
35 Flags::Parse("parse_flag_bool_test=true");
36 EXPECT_EQ(true, FLAG_parse_flag_bool_test);
37
38 EXPECT_EQ(true, FLAG_string_opt_test == NULL);
39 Flags::Parse("string_opt_test=doobidoo");
40 EXPECT_EQ(true, FLAG_string_opt_test != NULL);
41 EXPECT_EQ(0, strcmp(FLAG_string_opt_test, "doobidoo"));
42
43 EXPECT_EQ(true, FLAG_entrypoint_test != NULL);
44 EXPECT_EQ(0, strcmp(FLAG_entrypoint_test, "main"));
45
46 EXPECT_EQ(100, FLAG_counter);
47 Flags::Parse("counter=-300");
48 EXPECT_EQ(-300, FLAG_counter);
49 Flags::Parse("counter=$300");
50 EXPECT_EQ(-300, FLAG_counter);
51}
52
53} // namespace dart
54