Flutter Engine
The Flutter Engine
BitSetTest.cpp
Go to the documentation of this file.
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
9#include "tests/Test.h"
10
11#include <vector>
12
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);
20
21 set0.set(22);
22 REPORTER_ASSERT(reporter, set0.test(22) == true);
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();
57 REPORTER_ASSERT(reporter, set0.test(1234) == false);
58
59 set0.set();
61 REPORTER_ASSERT(reporter, set0.test(5678) == true);
62}
DEF_TEST(BitSet, reporter)
Definition: BitSetTest.cpp:13
reporter
Definition: FontMgrTest.cpp:39
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
OptionalIndex findFirst()
Definition: SkBitSet.h:95
void set(size_t index)
Definition: SkBitSet.h:41
bool test(size_t index) const
Definition: SkBitSet.h:66
void forEachSetIndex(FN f) const
Definition: SkBitSet.h:77
size_t size() const
Definition: SkBitSet.h:71
void reset(size_t index)
Definition: SkBitSet.h:54
OptionalIndex findFirstUnset()
Definition: SkBitSet.h:109
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63