1 /*
2  * Copyright (c) 2013, 2018, 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 
24 /**
25  * @test
26  * @run junit jdk.vm.ci.options.test.NestedBooleanOptionKeyTest
27  */
28 
29 
30 
31 package org.graalvm.compiler.options.test;
32 
33 import static org.graalvm.compiler.options.test.NestedBooleanOptionKeyTest.Options.Master0;
34 import static org.graalvm.compiler.options.test.NestedBooleanOptionKeyTest.Options.Master1;
35 import static org.graalvm.compiler.options.test.NestedBooleanOptionKeyTest.Options.Master2;
36 import static org.graalvm.compiler.options.test.NestedBooleanOptionKeyTest.Options.NestedOption0;
37 import static org.graalvm.compiler.options.test.NestedBooleanOptionKeyTest.Options.NestedOption1;
38 import static org.graalvm.compiler.options.test.NestedBooleanOptionKeyTest.Options.NestedOption2;
39 import static org.junit.Assert.assertFalse;
40 import static org.junit.Assert.assertTrue;
41 
42 import org.graalvm.compiler.options.NestedBooleanOptionKey;
43 import org.graalvm.compiler.options.OptionDescriptor;
44 import org.graalvm.compiler.options.OptionKey;
45 import org.graalvm.compiler.options.OptionType;
46 import org.graalvm.compiler.options.OptionValues;
47 import org.junit.Test;
48 
49 public class NestedBooleanOptionKeyTest {
50 
51     public static class Options {
52         public static final OptionKey<Boolean> Master0 = new OptionKey<>(true);
53         public static final OptionKey<Boolean> NestedOption0 = new NestedBooleanOptionKey(Master0, true);
54         public static final OptionKey<Boolean> Master1 = new OptionKey<>(true);
55         public static final OptionKey<Boolean> NestedOption1 = new NestedBooleanOptionKey(Master1, true);
56         public static final OptionKey<Boolean> Master2 = new OptionKey<>(true);
57         public static final OptionKey<Boolean> NestedOption2 = new NestedBooleanOptionKey(Master2, false);
58     }
59 
60     static final OptionDescriptor master0 = OptionDescriptor.create("Master0", OptionType.Debug, Boolean.class, "", Options.class, "Master0", Master0);
61     static final OptionDescriptor nestedOption0 = OptionDescriptor.create("NestedOption0", OptionType.Debug, Boolean.class, "", Options.class, "NestedOption0", NestedOption0);
62     static final OptionDescriptor master1 = OptionDescriptor.create("Master1", OptionType.Debug, Boolean.class, "", Options.class, "Master1", Master1);
63     static final OptionDescriptor nestedOption1 = OptionDescriptor.create("NestedOption1", OptionType.Debug, Boolean.class, "", Options.class, "NestedOption1", NestedOption1);
64     static final OptionDescriptor master2 = OptionDescriptor.create("Master2", OptionType.Debug, Boolean.class, "", Options.class, "Master2", Master2);
65     static final OptionDescriptor nestedOption2 = OptionDescriptor.create("NestedOption2", OptionType.Debug, Boolean.class, "", Options.class, "NestedOption2", NestedOption2);
66 
67     @Test
runDefaultTrue()68     public void runDefaultTrue() {
69         OptionValues options = new OptionValues(null, Master1, true);
70         assertTrue(Master1.getValue(options));
71         assertTrue(NestedOption1.getValue(options));
72 
73         // nested value unset
74         options = new OptionValues(null, Master1, false);
75         assertFalse(Master1.getValue(options));
76         assertFalse(NestedOption1.getValue(options));
77 
78         // set false
79         options = new OptionValues(null, Master1, false, NestedOption1, false);
80         assertFalse(Master1.getValue(options));
81         assertFalse(NestedOption1.getValue(options));
82 
83         options = new OptionValues(null, Master1, true, NestedOption1, false);
84         assertTrue(Master1.getValue(options));
85         assertFalse(NestedOption1.getValue(options));
86 
87         // set true
88         options = new OptionValues(null, Master1, false, NestedOption1, true);
89         assertFalse(Master1.getValue(options));
90         assertTrue(NestedOption1.getValue(options));
91 
92         options = new OptionValues(null, Master1, true, NestedOption1, true);
93         assertTrue(Master1.getValue(options));
94         assertTrue(NestedOption1.getValue(options));
95     }
96 
97     @Test
runDefaultFalse()98     public void runDefaultFalse() {
99         OptionValues options = new OptionValues(null, Master2, true);
100         assertTrue(Master2.getValue(options));
101         assertFalse(NestedOption2.getValue(options));
102 
103         // nested value unset
104         options = new OptionValues(null, Master2, false);
105         assertFalse(Master2.getValue(options));
106         assertFalse(NestedOption2.getValue(options));
107 
108         // set false
109         options = new OptionValues(null, Master2, false, NestedOption2, false);
110         assertFalse(Master2.getValue(options));
111         assertFalse(NestedOption2.getValue(options));
112 
113         options = new OptionValues(null, Master2, true, NestedOption2, false);
114         assertTrue(Master2.getValue(options));
115         assertFalse(NestedOption2.getValue(options));
116 
117         // set true
118         options = new OptionValues(null, Master2, false, NestedOption2, true);
119         assertFalse(Master2.getValue(options));
120         assertTrue(NestedOption2.getValue(options));
121 
122         options = new OptionValues(null, Master2, true, NestedOption2, true);
123         assertTrue(Master2.getValue(options));
124         assertTrue(NestedOption2.getValue(options));
125     }
126 }
127