BitSetTest.cpp revision e4fafb146e85cdfcf9d5418597b6818aa0754ada
1/*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "Test.h"
9#include "TestClassDef.h"
10#include "SkBitSet.h"
11
12DEF_TEST(BitSet, reporter) {
13    SkBitSet set0(65536);
14    REPORTER_ASSERT(reporter, set0.isBitSet(0) == false);
15    REPORTER_ASSERT(reporter, set0.isBitSet(32767) == false);
16    REPORTER_ASSERT(reporter, set0.isBitSet(65535) == false);
17
18    SkBitSet set1(65536);
19    REPORTER_ASSERT(reporter, set0 == set1);
20
21    set0.setBit(22, true);
22    REPORTER_ASSERT(reporter, set0.isBitSet(22) == true);
23    set0.setBit(24, true);
24    REPORTER_ASSERT(reporter, set0.isBitSet(24) == true);
25    set0.setBit(35, true);  // on a different DWORD
26    REPORTER_ASSERT(reporter, set0.isBitSet(35) == true);
27    set0.setBit(22, false);
28    REPORTER_ASSERT(reporter, set0.isBitSet(22) == false);
29    REPORTER_ASSERT(reporter, set0.isBitSet(24) == true);
30    REPORTER_ASSERT(reporter, set0.isBitSet(35) == true);
31
32    SkTDArray<unsigned int> data;
33    set0.exportTo(&data);
34    REPORTER_ASSERT(reporter, data.count() == 2);
35    REPORTER_ASSERT(reporter, data[0] == 24);
36    REPORTER_ASSERT(reporter, data[1] == 35);
37
38    set1.setBit(12345, true);
39    set1.orBits(set0);
40    REPORTER_ASSERT(reporter, set0.isBitSet(12345) == false);
41    REPORTER_ASSERT(reporter, set1.isBitSet(12345) == true);
42    REPORTER_ASSERT(reporter, set1.isBitSet(22) == false);
43    REPORTER_ASSERT(reporter, set1.isBitSet(24) == true);
44    REPORTER_ASSERT(reporter, set0.isBitSet(35) == true);
45    REPORTER_ASSERT(reporter, set1 != set0);
46
47    set1.clearAll();
48    REPORTER_ASSERT(reporter, set0.isBitSet(12345) == false);
49    REPORTER_ASSERT(reporter, set1.isBitSet(12345) == false);
50    REPORTER_ASSERT(reporter, set1.isBitSet(22) == false);
51    REPORTER_ASSERT(reporter, set1.isBitSet(24) == false);
52    REPORTER_ASSERT(reporter, set1.isBitSet(35) == false);
53
54    set1.orBits(set0);
55    REPORTER_ASSERT(reporter, set1 == set0);
56
57    SkBitSet set2(1);
58    SkBitSet set3(1);
59    SkBitSet set4(4);
60    SkBitSet set5(33);
61
62    REPORTER_ASSERT(reporter, set2 == set3);
63    REPORTER_ASSERT(reporter, set2 != set4);
64    REPORTER_ASSERT(reporter, set2 != set5);
65
66    set2.setBit(0, true);
67    REPORTER_ASSERT(reporter, set2 != set5);
68    set5.setBit(0, true);
69    REPORTER_ASSERT(reporter, set2 != set5);
70    REPORTER_ASSERT(reporter, set2 != set3);
71    set3.setBit(0, true);
72    REPORTER_ASSERT(reporter, set2 == set3);
73    set3.clearAll();
74    set3 = set2;
75    set2 = set2;
76    REPORTER_ASSERT(reporter, set2 == set3);
77}
78