blob: da023763bafeee5fcd99f77f2004a6546a9606f7 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
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 */
tfarina@chromium.orge4fafb12013-12-12 21:11:12 +00007
vandebo@chromium.orgd3a8c942011-07-02 01:26:37 +00008#include "SkBitSet.h"
tfarina@chromium.org8f6884a2014-01-24 20:56:26 +00009#include "Test.h"
vandebo@chromium.orgd3a8c942011-07-02 01:26:37 +000010
tfarina@chromium.orge4fafb12013-12-12 21:11:12 +000011DEF_TEST(BitSet, reporter) {
vandebo@chromium.orgd3a8c942011-07-02 01:26:37 +000012 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}