Path: blob/master/test/hotspot/gtest/gc/z/test_zBitField.cpp
41149 views
/*1* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223#include "precompiled.hpp"24#include "gc/z/zBitField.hpp"25#include "unittest.hpp"2627TEST(ZBitFieldTest, test) {28typedef ZBitField<uint64_t, bool, 0, 1> field_bool;29typedef ZBitField<uint64_t, uint8_t, 1, 8> field_uint8;30typedef ZBitField<uint64_t, uint16_t, 2, 16> field_uint16;31typedef ZBitField<uint64_t, uint32_t, 32, 32> field_uint32;32typedef ZBitField<uint64_t, uint64_t, 0, 63> field_uint64;33typedef ZBitField<uint64_t, void*, 1, 61, 3> field_pointer;3435uint64_t entry;3637{38const bool value = false;39entry = field_bool::encode(value);40EXPECT_EQ(field_bool::decode(entry), value) << "Should be equal";41}4243{44const bool value = true;45entry = field_bool::encode(value);46EXPECT_EQ(field_bool::decode(entry), value) << "Should be equal";47}4849{50const uint8_t value = ~(uint8_t)0;51entry = field_uint8::encode(value);52EXPECT_EQ(field_uint8::decode(entry), value) << "Should be equal";53}5455{56const uint16_t value = ~(uint16_t)0;57entry = field_uint16::encode(value);58EXPECT_EQ(field_uint16::decode(entry), value) << "Should be equal";59}6061{62const uint32_t value = ~(uint32_t)0;63entry = field_uint32::encode(value);64EXPECT_EQ(field_uint32::decode(entry), value) << "Should be equal";65}6667{68const uint64_t value = ~(uint64_t)0 >> 1;69entry = field_uint64::encode(value);70EXPECT_EQ(field_uint64::decode(entry), value) << "Should be equal";71}7273{74void* const value = (void*)(~(uintptr_t)0 << 3);75entry = field_pointer::encode(value);76EXPECT_EQ(field_pointer::decode(entry), value) << "Should be equal";77}78}798081