blob: 7139495217534fe345b1dc33becf64921ba76b3f [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
2/*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
vandebo@chromium.orgd3a8c942011-07-02 01:26:37 +00008#include "Test.h"
9#include "SkBitSet.h"
10
11static void TestBitSet(skiatest::Reporter* reporter) {
12 SkBitSet set0(65536);
13 REPORTER_ASSERT(reporter, set0.isBitSet(0) == false);
14 REPORTER_ASSERT(reporter, set0.isBitSet(32767) == false);
15 REPORTER_ASSERT(reporter, set0.isBitSet(65535) == false);
16
17 SkBitSet set1(65536);
18 REPORTER_ASSERT(reporter, set0 == set1);
19
20 set0.setBit(22, true);
21 REPORTER_ASSERT(reporter, set0.isBitSet(22) == true);
22 set0.setBit(24, true);
23 REPORTER_ASSERT(reporter, set0.isBitSet(24) == true);
24 set0.setBit(35, true); // on a different DWORD
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
vandebo@chromium.org17e66e22011-07-27 20:59:55 +000031 SkTDArray<unsigned int> data;
32 set0.exportTo(&data);
33 REPORTER_ASSERT(reporter, data.count() == 2);
34 REPORTER_ASSERT(reporter, data[0] == 24);
35 REPORTER_ASSERT(reporter, data[1] == 35);
36
vandebo@chromium.orgd3a8c942011-07-02 01:26:37 +000037 set1.setBit(12345, true);
38 set1.orBits(set0);
39 REPORTER_ASSERT(reporter, set0.isBitSet(12345) == false);
40 REPORTER_ASSERT(reporter, set1.isBitSet(12345) == true);
41 REPORTER_ASSERT(reporter, set1.isBitSet(22) == false);
42 REPORTER_ASSERT(reporter, set1.isBitSet(24) == 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 set3 = set2;
74 set2 = set2;
75 REPORTER_ASSERT(reporter, set2 == set3);
76}
77
78#include "TestClassDef.h"
79DEFINE_TESTCLASS("BitSet", BitSetTest, TestBitSet)