epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 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 | */ |
tfarina@chromium.org | e4fafb1 | 2013-12-12 21:11:12 +0000 | [diff] [blame] | 7 | |
vandebo@chromium.org | d3a8c94 | 2011-07-02 01:26:37 +0000 | [diff] [blame] | 8 | #include "SkBitSet.h" |
tfarina@chromium.org | 8f6884a | 2014-01-24 20:56:26 +0000 | [diff] [blame] | 9 | #include "Test.h" |
vandebo@chromium.org | d3a8c94 | 2011-07-02 01:26:37 +0000 | [diff] [blame] | 10 | |
tfarina@chromium.org | e4fafb1 | 2013-12-12 21:11:12 +0000 | [diff] [blame] | 11 | DEF_TEST(BitSet, reporter) { |
vandebo@chromium.org | d3a8c94 | 2011-07-02 01:26:37 +0000 | [diff] [blame] | 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.org | 17e66e2 | 2011-07-27 20:59:55 +0000 | [diff] [blame] | 31 | 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.org | d3a8c94 | 2011-07-02 01:26:37 +0000 | [diff] [blame] | 37 | 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 | } |