Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/gtest/utilities/test_tribool.cpp
41144 views
1
/*
2
* Copyright Amazon.com Inc. 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
#include "precompiled.hpp"
25
#include "unittest.hpp"
26
#include "utilities/tribool.hpp"
27
28
TEST(tribool, TriBool) {
29
TriBool t1;
30
ASSERT_EQ(t1.is_default(), true);
31
ASSERT_EQ((bool)t1, false);
32
33
TriBool t2(false);
34
ASSERT_TRUE(t2.is_default() == false && (bool)t2 == false);
35
36
TriBool t3(true);
37
ASSERT_TRUE(t3.is_default() == false && (bool)t3 == true);
38
39
TriBool t4 = false;
40
ASSERT_TRUE(t4.is_default() == false && (bool)t4 == false);
41
42
if (t2 || !t3 || t4) {
43
ASSERT_TRUE(false); //boom
44
}
45
46
TriBool flags[4];
47
flags[0] = TriBool();
48
flags[1] = false;
49
flags[2] = true;
50
51
ASSERT_EQ(flags[0].is_default(), true) << "should be default";
52
ASSERT_EQ(!flags[1].is_default() && !flags[1], true) << "should be not default and not set";
53
ASSERT_EQ(!flags[2].is_default() && flags[2], true) << "should be not default and set";
54
ASSERT_EQ(flags[3].is_default() == true, true) << "should be default";
55
}
56
57
template <size_t SZ, typename T>
58
struct Tester {
59
static void doit() {
60
// test fill_in(value)
61
control_words.fill_in(TriBool());
62
for (size_t i = 0; i < SZ; ++i) {
63
EXPECT_TRUE(control_words[i].is_default());
64
}
65
66
TriBool F = false;
67
control_words.fill_in(F);
68
for (size_t i = 0; i < SZ; ++i) {
69
EXPECT_TRUE(!control_words[i].is_default() && control_words[i] == false);
70
}
71
72
// test fill_in(beg, end)
73
TriBool Vec[4];
74
Vec[0] = TriBool();
75
Vec[1] = TriBool();
76
Vec[2] = true;
77
Vec[3] = false;
78
79
control_words.fill_in(&Vec[0], Vec + 4);
80
81
if (0 < SZ) {
82
EXPECT_TRUE(control_words[0].is_default());
83
}
84
85
if (1 < SZ) {
86
EXPECT_TRUE(control_words[1].is_default());
87
}
88
89
if (2 < SZ) {
90
EXPECT_TRUE(!control_words[2].is_default() && control_words[2] == true);
91
}
92
93
if (3 < SZ) {
94
EXPECT_TRUE(!control_words[3].is_default() && control_words[3] == false);
95
}
96
97
// test assignment
98
for (size_t i = 0; i < SZ; ++i) {
99
control_words[i] = true;
100
EXPECT_TRUE(!control_words[i].is_default() && control_words[i] == true);
101
}
102
103
for (size_t i = 0; i < SZ; ++i) {
104
control_words[i] = false;
105
EXPECT_TRUE(!control_words[i].is_default() && control_words[i] == false);
106
}
107
108
for (size_t i = 0; i < SZ; ++i) {
109
if ((i%2) == 0) {
110
control_words[i] = TriBool(true);
111
}
112
else {
113
control_words[i] = TriBool(false);
114
}
115
}
116
117
// test copy constructor(default)
118
copy = control_words;
119
for (size_t i = 0; i < SZ; ++i) {
120
if ((i%2) == 0) {
121
EXPECT_TRUE(!copy[i].is_default() && copy[i] == true)
122
<< "even value must be true.";
123
}
124
else {
125
EXPECT_TRUE(!copy[i].is_default() && copy[i] == false)
126
<< "odd value must be false.";
127
}
128
}
129
130
// test const operator[](fastpath)
131
const TriBoolArray<SZ, T>& cref = control_words;
132
for (size_t i = 0; i < SZ; ++i) {
133
if ((i%2) == 0) {
134
EXPECT_TRUE(!cref[i].is_default() && cref[i] == true)
135
<< "even value must be true.";
136
}
137
else {
138
EXPECT_TRUE(!cref[i].is_default() && cref[i] == false)
139
<< "odd value must be false.";
140
}
141
}
142
143
EXPECT_GE(sizeof(control_words) * 8, (2 * SZ)) << "allocated too less";
144
EXPECT_LE(sizeof(control_words), (((2 * SZ) / (sizeof(T) * 8) + 1) * sizeof(T)))
145
<< "allocated too much";
146
}
147
148
// because doit probably can't allocate jumbo arrays on stack, use static members
149
static TriBoolArray<SZ, T> control_words;
150
static TriBoolArray<SZ, T> copy;
151
};
152
153
template<size_t SZ, typename T>
154
TriBoolArray<SZ, T> Tester<SZ, T>::control_words;
155
156
template<size_t SZ, typename T>
157
TriBoolArray<SZ, T> Tester<SZ, T>::copy;
158
159
TEST(tribool, TriBoolArray) {
160
Tester<1, int>::doit();
161
Tester<2, int>::doit();
162
Tester<3, int>::doit();
163
Tester<7, int>::doit();
164
Tester<8, int>::doit();
165
Tester<14, int>::doit();
166
Tester<16, int>::doit();
167
Tester<27, int>::doit();
168
Tester<32, int>::doit();
169
Tester<34, int>::doit();
170
Tester<81, int>::doit();
171
Tester<128, int>::doit();
172
Tester<328, int>::doit(); // the no of intrinsics in jdk15
173
174
Tester<1024, int>::doit();
175
Tester<1025, int>::doit();
176
177
Tester<4 <<10/*4k*/ , int>::doit();
178
Tester<16<<10/*16k*/, int>::doit();
179
Tester<32<<10/*32k*/, int>::doit();
180
Tester<1 <<20/*1M*/ , int>::doit();
181
Tester<4 <<20/*4M*/ , int>::doit();
182
}
183
184
TriBool global_single;
185
TriBoolArray<2, unsigned int> global_tuple;
186
TEST(tribool, StaticInitializer) {
187
EXPECT_TRUE(global_single.is_default());
188
EXPECT_TRUE(global_tuple[0].is_default());
189
EXPECT_TRUE(global_tuple[1].is_default());
190
}
191
192