diff options
author | 2017-10-09 13:37:50 -0700 | |
---|---|---|
committer | 2017-10-09 13:40:53 -0700 | |
commit | 2f366292b51789bcecb1bde53e07d7f78802bc4f (patch) | |
tree | d18ad8237837f1716706a074e738076842f9b212 /runtime/base/bit_struct_test.cc | |
parent | 797e6d4d2a2786da42c20a718723a72038f7a01c (diff) |
base: Fix integer conversion in MaskLeastSignificant, add more asserts
T x = (1 << bits) was being truncated for sizeof(T) > sizeof(bits).
Also add more static_asserts to BITSTRUCT_DEFINE_END to make it more
error-proof.
Test: make test-art-{host,target}-gtest-bit_{struct,utils}_test{32,64}
Change-Id: Ifedf53c1211b4a9492ebd785c321a39d906dc87a
Diffstat (limited to 'runtime/base/bit_struct_test.cc')
-rw-r--r-- | runtime/base/bit_struct_test.cc | 21 |
1 files changed, 5 insertions, 16 deletions
diff --git a/runtime/base/bit_struct_test.cc b/runtime/base/bit_struct_test.cc index 872ada324c..9fc9762054 100644 --- a/runtime/base/bit_struct_test.cc +++ b/runtime/base/bit_struct_test.cc @@ -70,17 +70,10 @@ struct CustomBitStruct { int8_t data; }; -template <typename T> -void ZeroInitialize(T& value) { - memset(&value, 0, sizeof(T)); - // TODO: replace with value initialization -} - TEST(BitStructs, Custom) { CustomBitStruct expected(0b1111); - BitStructField<CustomBitStruct, /*lsb*/4, /*width*/4> f; - ZeroInitialize(f); + BitStructField<CustomBitStruct, /*lsb*/4, /*width*/4> f{}; // NOLINT EXPECT_EQ(1u, sizeof(f)); @@ -102,8 +95,7 @@ TEST(BitStructs, TwoCustom) { VALIDATE_BITSTRUCT_SIZE(TestTwoCustom); - TestTwoCustom cst; - ZeroInitialize(cst); + TestTwoCustom cst{}; // NOLINT // Test the write to most-significant field doesn't clobber least-significant. cst.f4_a = CustomBitStruct(0b0110); @@ -130,8 +122,7 @@ TEST(BitStructs, TwoCustom) { } TEST(BitStructs, Number) { - BitStructNumber<uint16_t, /*lsb*/4, /*width*/4> bsn; - ZeroInitialize(bsn); + BitStructNumber<uint16_t, /*lsb*/4, /*width*/4> bsn{}; // NOLINT EXPECT_EQ(2u, sizeof(bsn)); bsn = 0b1111; @@ -163,8 +154,7 @@ TEST(BitStructs, Test1) { EXPECT_EQ(1u, sizeof(u4)); EXPECT_EQ(1u, sizeof(alias_all)); } - TestBitStruct tst; - ZeroInitialize(tst); + TestBitStruct tst{}; // NOLINT // Check minimal size selection is correct. EXPECT_EQ(1u, sizeof(TestBitStruct)); @@ -239,8 +229,7 @@ BITSTRUCT_DEFINE_END(MixedSizeBitStruct); TEST(BitStructs, Mixed) { EXPECT_EQ(4u, sizeof(MixedSizeBitStruct)); - MixedSizeBitStruct tst; - ZeroInitialize(tst); + MixedSizeBitStruct tst{}; // NOLINT // Check operator assignment. tst.u3 = 0b111u; |