BitSetTest.cpp revision d3a8c94dfdabb333b12da3ff796d1f558cb06fba
1d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org#include "Test.h"
2d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org#include "SkBitSet.h"
3d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org
4d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.orgstatic void TestBitSet(skiatest::Reporter* reporter) {
5d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org    SkBitSet set0(65536);
6d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org    REPORTER_ASSERT(reporter, set0.isBitSet(0) == false);
7d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org    REPORTER_ASSERT(reporter, set0.isBitSet(32767) == false);
8d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org    REPORTER_ASSERT(reporter, set0.isBitSet(65535) == false);
9d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org
10d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org    SkBitSet set1(65536);
11d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org    REPORTER_ASSERT(reporter, set0 == set1);
12d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org
13d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org    set0.setBit(22, true);
14d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org    REPORTER_ASSERT(reporter, set0.isBitSet(22) == true);
15d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org    set0.setBit(24, true);
16d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org    REPORTER_ASSERT(reporter, set0.isBitSet(24) == true);
17d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org    set0.setBit(35, true);  // on a different DWORD
18d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org    REPORTER_ASSERT(reporter, set0.isBitSet(35) == true);
19d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org    set0.setBit(22, false);
20d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org    REPORTER_ASSERT(reporter, set0.isBitSet(22) == false);
21d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org    REPORTER_ASSERT(reporter, set0.isBitSet(24) == true);
22d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org    REPORTER_ASSERT(reporter, set0.isBitSet(35) == true);
23d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org
24d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org    set1.setBit(12345, true);
25d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org    set1.orBits(set0);
26d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org    REPORTER_ASSERT(reporter, set0.isBitSet(12345) == false);
27d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org    REPORTER_ASSERT(reporter, set1.isBitSet(12345) == true);
28d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org    REPORTER_ASSERT(reporter, set1.isBitSet(22) == false);
29d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org    REPORTER_ASSERT(reporter, set1.isBitSet(24) == true);
30d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org    REPORTER_ASSERT(reporter, set0.isBitSet(35) == true);
31d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org    REPORTER_ASSERT(reporter, set1 != set0);
32d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org
33d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org    set1.clearAll();
34d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org    REPORTER_ASSERT(reporter, set0.isBitSet(12345) == false);
35d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org    REPORTER_ASSERT(reporter, set1.isBitSet(12345) == false);
36d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org    REPORTER_ASSERT(reporter, set1.isBitSet(22) == false);
37d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org    REPORTER_ASSERT(reporter, set1.isBitSet(24) == false);
38d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org    REPORTER_ASSERT(reporter, set1.isBitSet(35) == false);
39d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org
40d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org    set1.orBits(set0);
41d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org    REPORTER_ASSERT(reporter, set1 == set0);
42d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org
43d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org    SkBitSet set2(1);
44d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org    SkBitSet set3(1);
45d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org    SkBitSet set4(4);
46d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org    SkBitSet set5(33);
47d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org
48d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org    REPORTER_ASSERT(reporter, set2 == set3);
49d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org    REPORTER_ASSERT(reporter, set2 != set4);
50d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org    REPORTER_ASSERT(reporter, set2 != set5);
51d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org
52d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org    set2.setBit(0, true);
53d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org    REPORTER_ASSERT(reporter, set2 != set5);
54d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org    set5.setBit(0, true);
55d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org    REPORTER_ASSERT(reporter, set2 != set5);
56d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org    REPORTER_ASSERT(reporter, set2 != set3);
57d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org    set3.setBit(0, true);
58d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org    REPORTER_ASSERT(reporter, set2 == set3);
59d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org    set3.clearAll();
60d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org    set3 = set2;
61d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org    set2 = set2;
62d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org    REPORTER_ASSERT(reporter, set2 == set3);
63d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org}
64d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org
65d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.org#include "TestClassDef.h"
66d3a8c94dfdabb333b12da3ff796d1f558cb06fbavandebo@chromium.orgDEFINE_TESTCLASS("BitSet", BitSetTest, TestBitSet)
67