1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Tests for the bitfield helper class.
6
7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "gpu/command_buffer/common/bitfield_helpers.h"
9
10 namespace gpu {
11
12 // Tests that BitField<>::Get returns the right bits.
TEST(BitFieldTest,TestGet)13 TEST(BitFieldTest, TestGet) {
14 unsigned int value = 0x12345678u;
15 EXPECT_EQ(0x8u, (BitField<0, 4>::Get(value)));
16 EXPECT_EQ(0x45u, (BitField<12, 8>::Get(value)));
17 EXPECT_EQ(0x12345678u, (BitField<0, 32>::Get(value)));
18 }
19
20 // Tests that BitField<>::MakeValue generates the right bits.
TEST(BitFieldTest,TestMakeValue)21 TEST(BitFieldTest, TestMakeValue) {
22 EXPECT_EQ(0x00000003u, (BitField<0, 4>::MakeValue(0x3)));
23 EXPECT_EQ(0x00023000u, (BitField<12, 8>::MakeValue(0x123)));
24 EXPECT_EQ(0x87654321u, (BitField<0, 32>::MakeValue(0x87654321)));
25 }
26
27 // Tests that BitField<>::Set modifies the right bits.
TEST(BitFieldTest,TestSet)28 TEST(BitFieldTest, TestSet) {
29 unsigned int value = 0x12345678u;
30 BitField<0, 4>::Set(&value, 0x9);
31 EXPECT_EQ(0x12345679u, value);
32 BitField<12, 8>::Set(&value, 0x123);
33 EXPECT_EQ(0x12323679u, value);
34 BitField<0, 32>::Set(&value, 0x87654321);
35 EXPECT_EQ(0x87654321u, value);
36 }
37
38 } // namespace gpu
39