blob: 3bbb0748ce1e50547da8f9853bb760113aa3429f [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
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.orge4fafb12013-12-12 21:11:12 +00007
vandebo@chromium.orgd3a8c942011-07-02 01:26:37 +00008#include "SkBitSet.h"
tfarina@chromium.org8f6884a2014-01-24 20:56:26 +00009#include "Test.h"
vandebo@chromium.orgd3a8c942011-07-02 01:26:37 +000010
Hal Canary9e41c212018-09-03 12:00:23 -040011#include <vector>
12
tfarina@chromium.orge4fafb12013-12-12 21:11:12 +000013DEF_TEST(BitSet, reporter) {
vandebo@chromium.orgd3a8c942011-07-02 01:26:37 +000014 SkBitSet set0(65536);
halcanarye2348cc2016-08-19 16:23:23 -070015 REPORTER_ASSERT(reporter, set0.has(0) == false);
16 REPORTER_ASSERT(reporter, set0.has(32767) == false);
17 REPORTER_ASSERT(reporter, set0.has(65535) == false);
vandebo@chromium.orgd3a8c942011-07-02 01:26:37 +000018
halcanarye2348cc2016-08-19 16:23:23 -070019 set0.set(22);
20 REPORTER_ASSERT(reporter, set0.has(22) == true);
21 set0.set(24);
22 REPORTER_ASSERT(reporter, set0.has(24) == true);
23 set0.set(35); // on a different DWORD
24 REPORTER_ASSERT(reporter, set0.has(35) == true);
25 REPORTER_ASSERT(reporter, set0.has(24) == true);
26 REPORTER_ASSERT(reporter, set0.has(35) == true);
vandebo@chromium.orgd3a8c942011-07-02 01:26:37 +000027
Hal Canary9e41c212018-09-03 12:00:23 -040028 std::vector<unsigned int> data;
Hal Canary52514d52018-10-19 10:08:42 -040029 set0.getSetValues([&data](unsigned v) { data.push_back(v); });
30
Hal Canary9e41c212018-09-03 12:00:23 -040031 REPORTER_ASSERT(reporter, data.size() == 3);
halcanarye2348cc2016-08-19 16:23:23 -070032 REPORTER_ASSERT(reporter, data[0] == 22);
33 REPORTER_ASSERT(reporter, data[1] == 24);
34 REPORTER_ASSERT(reporter, data[2] == 35);
vandebo@chromium.org17e66e22011-07-27 20:59:55 +000035
halcanarye2348cc2016-08-19 16:23:23 -070036 SkBitSet set1(65536);
37 set1.set(12345);
38 REPORTER_ASSERT(reporter, set0.has(12345) == false);
39 REPORTER_ASSERT(reporter, set1.has(12345) == true);
40 REPORTER_ASSERT(reporter, set1.has(22) == false);
41 REPORTER_ASSERT(reporter, set0.has(35) == true);
vandebo@chromium.orgd3a8c942011-07-02 01:26:37 +000042}