1cb93a386Sopenharmony_ci/*
2cb93a386Sopenharmony_ci * Copyright 2011 Google Inc.
3cb93a386Sopenharmony_ci *
4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be
5cb93a386Sopenharmony_ci * found in the LICENSE file.
6cb93a386Sopenharmony_ci */
7cb93a386Sopenharmony_ci
8cb93a386Sopenharmony_ci#include "src/utils/SkBitSet.h"
9cb93a386Sopenharmony_ci#include "tests/Test.h"
10cb93a386Sopenharmony_ci
11cb93a386Sopenharmony_ci#include <vector>
12cb93a386Sopenharmony_ci
13cb93a386Sopenharmony_ciDEF_TEST(BitSet, reporter) {
14cb93a386Sopenharmony_ci    SkBitSet set0(65536);
15cb93a386Sopenharmony_ci    REPORTER_ASSERT(reporter, set0.size() == 65536);
16cb93a386Sopenharmony_ci    REPORTER_ASSERT(reporter, set0.test(0) == false);
17cb93a386Sopenharmony_ci    REPORTER_ASSERT(reporter, set0.test(32767) == false);
18cb93a386Sopenharmony_ci    REPORTER_ASSERT(reporter, set0.test(65535) == false);
19cb93a386Sopenharmony_ci    REPORTER_ASSERT(reporter, !set0.findFirst());
20cb93a386Sopenharmony_ci
21cb93a386Sopenharmony_ci    set0.set(22);
22cb93a386Sopenharmony_ci    REPORTER_ASSERT(reporter, set0.test(22) == true);
23cb93a386Sopenharmony_ci    REPORTER_ASSERT(reporter, set0.findFirst());
24cb93a386Sopenharmony_ci    REPORTER_ASSERT(reporter, *set0.findFirst() == 22);
25cb93a386Sopenharmony_ci    set0.set(24);
26cb93a386Sopenharmony_ci    REPORTER_ASSERT(reporter, set0.test(24) == true);
27cb93a386Sopenharmony_ci    REPORTER_ASSERT(reporter, *set0.findFirst() == 22);
28cb93a386Sopenharmony_ci    set0.set(35);  // on a different DWORD
29cb93a386Sopenharmony_ci    REPORTER_ASSERT(reporter, set0.test(35) == true);
30cb93a386Sopenharmony_ci    REPORTER_ASSERT(reporter, *set0.findFirst() == 22);
31cb93a386Sopenharmony_ci    REPORTER_ASSERT(reporter, set0.test(24) == true);
32cb93a386Sopenharmony_ci    REPORTER_ASSERT(reporter, set0.test(35) == true);
33cb93a386Sopenharmony_ci    set0.set(21);
34cb93a386Sopenharmony_ci    REPORTER_ASSERT(reporter, set0.test(21) == true);
35cb93a386Sopenharmony_ci    REPORTER_ASSERT(reporter, *set0.findFirst() == 21);
36cb93a386Sopenharmony_ci    set0.reset(21);
37cb93a386Sopenharmony_ci    REPORTER_ASSERT(reporter, set0.test(21) == false);
38cb93a386Sopenharmony_ci    REPORTER_ASSERT(reporter, *set0.findFirst() == 22);
39cb93a386Sopenharmony_ci
40cb93a386Sopenharmony_ci    std::vector<unsigned int> data;
41cb93a386Sopenharmony_ci    set0.forEachSetIndex([&data](unsigned v) { data.push_back(v); });
42cb93a386Sopenharmony_ci
43cb93a386Sopenharmony_ci    REPORTER_ASSERT(reporter, data.size() == 3);
44cb93a386Sopenharmony_ci    REPORTER_ASSERT(reporter, data[0] == 22);
45cb93a386Sopenharmony_ci    REPORTER_ASSERT(reporter, data[1] == 24);
46cb93a386Sopenharmony_ci    REPORTER_ASSERT(reporter, data[2] == 35);
47cb93a386Sopenharmony_ci
48cb93a386Sopenharmony_ci    SkBitSet set1(65536);
49cb93a386Sopenharmony_ci    set1.set(12345);
50cb93a386Sopenharmony_ci    REPORTER_ASSERT(reporter, set0.test(12345) == false);
51cb93a386Sopenharmony_ci    REPORTER_ASSERT(reporter, set1.test(12345) == true);
52cb93a386Sopenharmony_ci    REPORTER_ASSERT(reporter, set1.test(22) == false);
53cb93a386Sopenharmony_ci    REPORTER_ASSERT(reporter, set0.test(35) == true);
54cb93a386Sopenharmony_ci
55cb93a386Sopenharmony_ci    set0.reset();
56cb93a386Sopenharmony_ci    REPORTER_ASSERT(reporter, !set0.findFirst());
57cb93a386Sopenharmony_ci    REPORTER_ASSERT(reporter, set0.test(1234) == false);
58cb93a386Sopenharmony_ci
59cb93a386Sopenharmony_ci    set0.set();
60cb93a386Sopenharmony_ci    REPORTER_ASSERT(reporter, !set0.findFirstUnset());
61cb93a386Sopenharmony_ci    REPORTER_ASSERT(reporter, set0.test(5678) == true);
62cb93a386Sopenharmony_ci}
63