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