comparison graal/com.oracle.graal.options.test/src/com/oracle/graal/options/test/NestedBooleanOptionValueTest.java @ 19650:d0600f479309

Add NestedBooleanOptionValueTest.
author Josef Eisl <josef.eisl@jku.at>
date Mon, 02 Mar 2015 14:03:56 +0100
parents
children
comparison
equal deleted inserted replaced
19649:4726801eedfc 19650:d0600f479309
1 /*
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23 package com.oracle.graal.options.test;
24
25 import static com.oracle.graal.options.test.NestedBooleanOptionValueTest.Options.*;
26 import static org.junit.Assert.*;
27
28 import org.junit.*;
29
30 import com.oracle.graal.options.*;
31 import com.oracle.graal.options.OptionValue.OverrideScope;
32
33 public class NestedBooleanOptionValueTest {
34
35 public static class Options {
36 public static final OptionValue<Boolean> Master0 = new OptionValue<>(true);
37 public static final OptionValue<Boolean> NestedOption0 = new NestedBooleanOptionValue(Master0, true);
38 public static final OptionValue<Boolean> Master1 = new OptionValue<>(true);
39 public static final OptionValue<Boolean> NestedOption1 = new NestedBooleanOptionValue(Master1, true);
40 public static final OptionValue<Boolean> Master2 = new OptionValue<>(true);
41 public static final OptionValue<Boolean> NestedOption2 = new NestedBooleanOptionValue(Master2, false);
42 }
43
44 static final OptionDescriptor master0 = new OptionDescriptor("Master0", Boolean.class, "", Options.class, "Master0", Master0);
45 static final OptionDescriptor nestedOption0 = new OptionDescriptor("NestedOption0", Boolean.class, "", Options.class, "NestedOption0", NestedOption0);
46 static final OptionDescriptor master1 = new OptionDescriptor("Master1", Boolean.class, "", Options.class, "Master1", Master1);
47 static final OptionDescriptor nestedOption1 = new OptionDescriptor("NestedOption1", Boolean.class, "", Options.class, "NestedOption1", NestedOption1);
48 static final OptionDescriptor master2 = new OptionDescriptor("Master2", Boolean.class, "", Options.class, "Master2", Master2);
49 static final OptionDescriptor nestedOption2 = new OptionDescriptor("NestedOption2", Boolean.class, "", Options.class, "NestedOption2", NestedOption2);
50
51 @Test
52 public void runOverrides() {
53 assertTrue(Master0.getValue());
54 assertTrue(NestedOption0.getValue());
55 try (OverrideScope s1 = OptionValue.override(Master0, false)) {
56 assertFalse(Master0.getValue());
57 assertFalse(NestedOption0.getValue());
58 try (OverrideScope s2 = OptionValue.override(NestedOption0, false)) {
59 assertFalse(NestedOption0.getValue());
60 }
61 try (OverrideScope s2 = OptionValue.override(NestedOption0, true)) {
62 assertTrue(NestedOption0.getValue());
63 }
64 }
65 assertTrue(Master0.getValue());
66 try (OverrideScope s1 = OptionValue.override(NestedOption0, false)) {
67 assertFalse(NestedOption0.getValue());
68 }
69 try (OverrideScope s1 = OptionValue.override(NestedOption0, true)) {
70 assertTrue(NestedOption0.getValue());
71 }
72 }
73
74 @Test
75 public void runDefaultTrue() {
76 Master1.setValue(true);
77 assertTrue(Master1.getValue());
78 assertTrue(NestedOption1.getValue());
79 // nested value unset
80 Master1.setValue(false);
81 assertFalse(Master1.getValue());
82 assertFalse(NestedOption1.getValue());
83 // set false
84 Master1.setValue(false);
85 NestedOption1.setValue(false);
86 assertFalse(Master1.getValue());
87 assertFalse(NestedOption1.getValue());
88 Master1.setValue(true);
89 assertTrue(Master1.getValue());
90 assertFalse(NestedOption1.getValue());
91 // set true
92 Master1.setValue(false);
93 NestedOption1.setValue(true);
94 assertFalse(Master1.getValue());
95 assertTrue(NestedOption1.getValue());
96 Master1.setValue(true);
97 assertTrue(Master1.getValue());
98 assertTrue(NestedOption1.getValue());
99 }
100
101 @Test
102 public void runDefaultFalse() {
103 Master2.setValue(true);
104 assertTrue(Master2.getValue());
105 assertFalse(NestedOption2.getValue());
106 // nested value unset
107 Master2.setValue(false);
108 assertFalse(Master2.getValue());
109 assertFalse(NestedOption2.getValue());
110 // set false
111 Master2.setValue(false);
112 NestedOption2.setValue(false);
113 assertFalse(Master2.getValue());
114 assertFalse(NestedOption2.getValue());
115 Master2.setValue(true);
116 assertTrue(Master2.getValue());
117 assertFalse(NestedOption2.getValue());
118 // set true
119 Master2.setValue(false);
120 NestedOption2.setValue(true);
121 assertFalse(Master2.getValue());
122 assertTrue(NestedOption2.getValue());
123 Master2.setValue(true);
124 assertTrue(Master2.getValue());
125 assertTrue(NestedOption2.getValue());
126 }
127
128 }