Flutter Engine
The Flutter Engine
bitfield_test.cc
Go to the documentation of this file.
1// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
5#include "platform/assert.h"
6
7#include "vm/bitfield.h"
8#include "vm/globals.h"
9#include "vm/unit_test.h"
10
11namespace dart {
12
14 class TestBitFields : public BitField<uword, int32_t, 1, 8> {};
17 EXPECT_EQ(0x00ffU, TestBitFields::mask());
18 EXPECT_EQ(0x001feU, TestBitFields::mask_in_place());
19 EXPECT_EQ(1, TestBitFields::shift());
20 EXPECT_EQ(8, TestBitFields::bitsize());
21 EXPECT_EQ(32U, TestBitFields::encode(16));
22 EXPECT_EQ(16, TestBitFields::decode(32));
23 EXPECT_EQ(2U, TestBitFields::update(1, 16));
24}
25
26template <typename T>
28 class F1 : public BitField<T, intptr_t, 0, 8, /*sign_extend=*/true> {};
29 class F2
30 : public BitField<T, uintptr_t, F1::kNextBit, 8, /*sign_extend=*/false> {
31 };
32 class F3
33 : public BitField<T, intptr_t, F2::kNextBit, 8, /*sign_extend=*/true> {};
34 class F4
35 : public BitField<T, uintptr_t, F3::kNextBit, 8, /*sign_extend=*/false> {
36 };
37
38 const uint32_t value =
39 F1::encode(-1) | F2::encode(1) | F3::encode(-2) | F4::encode(2);
40 EXPECT_EQ(0x02fe01ffU, value);
41 EXPECT_EQ(-1, F1::decode(value));
42 EXPECT_EQ(1U, F2::decode(value));
43 EXPECT_EQ(-2, F3::decode(value));
44 EXPECT_EQ(2U, F4::decode(value));
45}
46
47template <typename T>
49 class F1 : public BitField<T, intptr_t, 0, 8, /*sign_extend=*/false> {};
50 class F2
51 : public BitField<T, uintptr_t, F1::kNextBit, 8, /*sign_extend=*/false> {
52 };
53 class F3
54 : public BitField<T, intptr_t, F2::kNextBit, 8, /*sign_extend=*/false> {};
55 class F4
56 : public BitField<T, uintptr_t, F3::kNextBit, 8, /*sign_extend=*/false> {
57 };
58
59 const uint32_t value =
60 F1::encode(-1) | F2::encode(1) | F3::encode(-2) | F4::encode(2);
61 EXPECT_EQ(0x02fe01ffU, value);
62 EXPECT_EQ(3, F1::decode(value));
63 EXPECT_EQ(1, F2::decode(value));
64 EXPECT_EQ(2, F3::decode(value));
65 EXPECT_EQ(2, F3::decode(value));
66}
67
68VM_UNIT_TEST_CASE(BitFields_SignedField) {
69 TestSignExtendedBitField<uint32_t>();
70 TestSignExtendedBitField<int32_t>();
71}
72
73#if defined(DEBUG)
74#define DEBUG_CRASH "Crash"
75#else
76#define DEBUG_CRASH "Pass"
77#endif
78
80 class F : public BitField<uint32_t, uint32_t, 0, 8, /*sign_extend=*/false> {};
81 const uint32_t value = F::encode(kMaxUint32);
82 EXPECT_EQ(kMaxUint8, value);
83}
84
85} // namespace dart
static void F2(DFData *curr, int width)
static void encode(uint8_t output[16], const uint32_t input[4])
Definition: SkMD5.cpp:240
static bool is_valid(SkISize dim)
static constexpr F F1
Definition: Transform_inl.h:28
#define EXPECT(type, expectedAlignment, expectedSize)
#define DEBUG_CRASH
uint8_t value
Definition: dart_vm.cc:33
constexpr uint8_t kMaxUint8
Definition: globals.h:478
VM_UNIT_TEST_CASE_WITH_EXPECTATION(BitFields_Assert, DEBUG_CRASH)
constexpr uint32_t kMaxUint32
Definition: globals.h:484
static void TestNotSignExtendedBitField()
static void TestSignExtendedBitField()
VM_UNIT_TEST_CASE(DirectoryCurrentNoScope)
static DecodeResult decode(std::string path)
Definition: png_codec.cpp:124
Definition: SkMD5.cpp:120