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