1 | /* |
2 | * Copyright (c) 2017, 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 | #include "precompiled.hpp" |
25 | #include "gc/z/zBitField.hpp" |
26 | #include "unittest.hpp" |
27 | |
28 | TEST(ZBitFieldTest, test) { |
29 | typedef ZBitField<uint64_t, bool, 0, 1> field_bool; |
30 | typedef ZBitField<uint64_t, uint8_t, 1, 8> field_uint8; |
31 | typedef ZBitField<uint64_t, uint16_t, 2, 16> field_uint16; |
32 | typedef ZBitField<uint64_t, uint32_t, 32, 32> field_uint32; |
33 | typedef ZBitField<uint64_t, uint64_t, 0, 63> field_uint64; |
34 | typedef ZBitField<uint64_t, void*, 1, 61, 3> field_pointer; |
35 | |
36 | uint64_t entry; |
37 | |
38 | { |
39 | const bool value = false; |
40 | entry = field_bool::encode(value); |
41 | EXPECT_EQ(field_bool::decode(entry), value) << "Should be equal" ; |
42 | } |
43 | |
44 | { |
45 | const bool value = true; |
46 | entry = field_bool::encode(value); |
47 | EXPECT_EQ(field_bool::decode(entry), value) << "Should be equal" ; |
48 | } |
49 | |
50 | { |
51 | const uint8_t value = ~(uint8_t)0; |
52 | entry = field_uint8::encode(value); |
53 | EXPECT_EQ(field_uint8::decode(entry), value) << "Should be equal" ; |
54 | } |
55 | |
56 | { |
57 | const uint16_t value = ~(uint16_t)0; |
58 | entry = field_uint16::encode(value); |
59 | EXPECT_EQ(field_uint16::decode(entry), value) << "Should be equal" ; |
60 | } |
61 | |
62 | { |
63 | const uint32_t value = ~(uint32_t)0; |
64 | entry = field_uint32::encode(value); |
65 | EXPECT_EQ(field_uint32::decode(entry), value) << "Should be equal" ; |
66 | } |
67 | |
68 | { |
69 | const uint64_t value = ~(uint64_t)0 >> 1; |
70 | entry = field_uint64::encode(value); |
71 | EXPECT_EQ(field_uint64::decode(entry), value) << "Should be equal" ; |
72 | } |
73 | |
74 | { |
75 | void* const value = (void*)(~(uintptr_t)0 << 3); |
76 | entry = field_pointer::encode(value); |
77 | EXPECT_EQ(field_pointer::decode(entry), value) << "Should be equal" ; |
78 | } |
79 | } |
80 | |