1 //
2 // Copyright 2017 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // Unit tests for VertexArray and related classes.
7 //
8
9 #include "gmock/gmock.h"
10 #include "gtest/gtest.h"
11
12 #include "common/bitset_utils.h"
13 #include "common/utilities.h"
14 #include "libANGLE/VertexArray.h"
15
16 using namespace gl;
17
18 // Tests that function GetIndexFromDirtyBit computes the index properly.
TEST(VertexArrayTest,VerifyGetIndexFromDirtyBit)19 TEST(VertexArrayTest, VerifyGetIndexFromDirtyBit)
20 {
21 VertexArray::DirtyBits dirtyBits;
22 constexpr size_t bits[] = {1, 4, 9, 16, 25, 35};
23 constexpr GLint count = sizeof(bits) / sizeof(size_t);
24 for (GLint i = 0; i < count; i++)
25 {
26 dirtyBits.set(bits[i]);
27 }
28
29 for (size_t dirtyBit : dirtyBits)
30 {
31 const size_t index = VertexArray::GetVertexIndexFromDirtyBit(dirtyBit);
32 if (dirtyBit < VertexArray::DIRTY_BIT_ATTRIB_0)
33 {
34 continue;
35 }
36 else if (dirtyBit < VertexArray::DIRTY_BIT_ATTRIB_MAX)
37 {
38 EXPECT_EQ(dirtyBit - VertexArray::DIRTY_BIT_ATTRIB_0, index);
39 }
40 else if (dirtyBit < VertexArray::DIRTY_BIT_BINDING_MAX)
41 {
42 EXPECT_EQ(dirtyBit - VertexArray::DIRTY_BIT_BINDING_0, index);
43 }
44 else if (dirtyBit < VertexArray::DIRTY_BIT_BUFFER_DATA_MAX)
45 {
46 EXPECT_EQ(dirtyBit - VertexArray::DIRTY_BIT_BUFFER_DATA_0, index);
47 }
48 else
49 ASSERT_TRUE(false);
50 }
51 }
52