BitSetTest.cpp revision 17e66e2d341ab684eec7841fd383af85bb4aa625
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    SkTDArray<unsigned int> data;
25    set0.exportTo(&data);
26    REPORTER_ASSERT(reporter, data.count() == 2);
27    REPORTER_ASSERT(reporter, data[0] == 24);
28    REPORTER_ASSERT(reporter, data[1] == 35);
29
30    set1.setBit(12345, true);
31    set1.orBits(set0);
32    REPORTER_ASSERT(reporter, set0.isBitSet(12345) == false);
33    REPORTER_ASSERT(reporter, set1.isBitSet(12345) == true);
34    REPORTER_ASSERT(reporter, set1.isBitSet(22) == false);
35    REPORTER_ASSERT(reporter, set1.isBitSet(24) == true);
36    REPORTER_ASSERT(reporter, set0.isBitSet(35) == true);
37    REPORTER_ASSERT(reporter, set1 != set0);
38
39    set1.clearAll();
40    REPORTER_ASSERT(reporter, set0.isBitSet(12345) == false);
41    REPORTER_ASSERT(reporter, set1.isBitSet(12345) == false);
42    REPORTER_ASSERT(reporter, set1.isBitSet(22) == false);
43    REPORTER_ASSERT(reporter, set1.isBitSet(24) == false);
44    REPORTER_ASSERT(reporter, set1.isBitSet(35) == false);
45
46    set1.orBits(set0);
47    REPORTER_ASSERT(reporter, set1 == set0);
48
49    SkBitSet set2(1);
50    SkBitSet set3(1);
51    SkBitSet set4(4);
52    SkBitSet set5(33);
53
54    REPORTER_ASSERT(reporter, set2 == set3);
55    REPORTER_ASSERT(reporter, set2 != set4);
56    REPORTER_ASSERT(reporter, set2 != set5);
57
58    set2.setBit(0, true);
59    REPORTER_ASSERT(reporter, set2 != set5);
60    set5.setBit(0, true);
61    REPORTER_ASSERT(reporter, set2 != set5);
62    REPORTER_ASSERT(reporter, set2 != set3);
63    set3.setBit(0, true);
64    REPORTER_ASSERT(reporter, set2 == set3);
65    set3.clearAll();
66    set3 = set2;
67    set2 = set2;
68    REPORTER_ASSERT(reporter, set2 == set3);
69}
70
71#include "TestClassDef.h"
72DEFINE_TESTCLASS("BitSet", BitSetTest, TestBitSet)
73