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