1 /*
2 * Copyright 2019 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 "experimental/graphite/src/EnumBitMask.h"
9 #include "tests/Test.h"
10
11 enum class Flags {
12 kNone = 0,
13 kA = 1,
14 kB = 2,
15 kC = 4
16 };
17
18 SKGPU_MAKE_MASK_OPS(Flags);
19
20 using namespace skgpu;
21
DEF_GRAPHITE_TEST(skgpu_Mask,r)22 DEF_GRAPHITE_TEST(skgpu_Mask, r) {
23 Mask<Flags> flags = Flags::kNone;
24 REPORTER_ASSERT(r, !flags);
25 flags |= Flags::kA;
26 REPORTER_ASSERT(r, flags);
27 REPORTER_ASSERT(r, !(flags & Flags::kB));
28 REPORTER_ASSERT(r, (flags & Flags::kA));
29 flags |= (Flags::kB | Flags::kC);
30 auto mask = Flags::kB | Flags::kC;
31 REPORTER_ASSERT(r, (flags & mask) == mask);
32 REPORTER_ASSERT(r, flags == (Flags::kA | Flags::kB | Flags::kC));
33 flags &= ~Flags::kC;
34 REPORTER_ASSERT(r, flags == (Flags::kA | Flags::kB));
35 REPORTER_ASSERT(r, (flags & mask) != mask);
36 REPORTER_ASSERT(r, (flags & mask) != Flags::kNone);
37 REPORTER_ASSERT(r, (flags & mask));
38 REPORTER_ASSERT(r, flags);
39 flags &= ~Flags::kB;
40 REPORTER_ASSERT(r, (flags & mask) == Flags::kNone);
41 REPORTER_ASSERT(r, !(flags & mask));
42 REPORTER_ASSERT(r, flags);
43 flags = (flags | flags) ^ (flags);
44 REPORTER_ASSERT(r, !flags);
45 flags ^= mask;
46 REPORTER_ASSERT(r, flags == mask);
47 REPORTER_ASSERT(r, !(Flags::kA & Flags::kB));
48 REPORTER_ASSERT(r, (Flags::kA ^ Flags::kB) == (Flags::kA | Flags::kB));
49 }
50