• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  */
7 
8 #include "src/utils/SkBitSet.h"
9 #include "tests/Test.h"
10 
11 #include <vector>
12 
DEF_TEST(BitSet,reporter)13 DEF_TEST(BitSet, reporter) {
14     SkBitSet set0(65536);
15     REPORTER_ASSERT(reporter, set0.size() == 65536);
16     REPORTER_ASSERT(reporter, set0.test(0) == false);
17     REPORTER_ASSERT(reporter, set0.test(32767) == false);
18     REPORTER_ASSERT(reporter, set0.test(65535) == false);
19     REPORTER_ASSERT(reporter, !set0.findFirst());
20 
21     set0.set(22);
22     REPORTER_ASSERT(reporter, set0.test(22) == true);
23     REPORTER_ASSERT(reporter, set0.findFirst());
24     REPORTER_ASSERT(reporter, *set0.findFirst() == 22);
25     set0.set(24);
26     REPORTER_ASSERT(reporter, set0.test(24) == true);
27     REPORTER_ASSERT(reporter, *set0.findFirst() == 22);
28     set0.set(35);  // on a different DWORD
29     REPORTER_ASSERT(reporter, set0.test(35) == true);
30     REPORTER_ASSERT(reporter, *set0.findFirst() == 22);
31     REPORTER_ASSERT(reporter, set0.test(24) == true);
32     REPORTER_ASSERT(reporter, set0.test(35) == true);
33     set0.set(21);
34     REPORTER_ASSERT(reporter, set0.test(21) == true);
35     REPORTER_ASSERT(reporter, *set0.findFirst() == 21);
36     set0.reset(21);
37     REPORTER_ASSERT(reporter, set0.test(21) == false);
38     REPORTER_ASSERT(reporter, *set0.findFirst() == 22);
39 
40     std::vector<unsigned int> data;
41     set0.forEachSetIndex([&data](unsigned v) { data.push_back(v); });
42 
43     REPORTER_ASSERT(reporter, data.size() == 3);
44     REPORTER_ASSERT(reporter, data[0] == 22);
45     REPORTER_ASSERT(reporter, data[1] == 24);
46     REPORTER_ASSERT(reporter, data[2] == 35);
47 
48     SkBitSet set1(65536);
49     set1.set(12345);
50     REPORTER_ASSERT(reporter, set0.test(12345) == false);
51     REPORTER_ASSERT(reporter, set1.test(12345) == true);
52     REPORTER_ASSERT(reporter, set1.test(22) == false);
53     REPORTER_ASSERT(reporter, set0.test(35) == true);
54 
55     set0.reset();
56     REPORTER_ASSERT(reporter, !set0.findFirst());
57     REPORTER_ASSERT(reporter, set0.test(1234) == false);
58 
59     set0.set();
60     REPORTER_ASSERT(reporter, !set0.findFirstUnset());
61     REPORTER_ASSERT(reporter, set0.test(5678) == true);
62 }
63