skia2/tests/graphite/MaskTest.cpp
Chris Dalton 1ab7ff6abf [graphite] Clean up bitwise operators for enum masks
* Rename TFlagsMask<> to Mask<>
* Make Mask<> implicitly convertible to bool
* Rename SKGPU_MAKE_BITFIELD_CLASS_OPS to SKGPU_MAKE_MASK_OPS
* Remove the macro for non-class enums

Change-Id: I86059335d731f34c9c9c20a4cd6d5491543aa3b1
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/456816
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Commit-Queue: Chris Dalton <csmartdalton@google.com>
2021-10-08 00:32:54 +00:00

50 lines
1.4 KiB
C++

/*
* Copyright 2019 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "experimental/graphite/include/GraphiteTypes.h"
#include "tests/Test.h"
enum class Flags {
kNone = 0,
kA = 1,
kB = 2,
kC = 4
};
SKGPU_MAKE_MASK_OPS(Flags);
using namespace skgpu;
DEF_TEST(skgpu_Mask, r) {
Mask<Flags> flags = Flags::kNone;
REPORTER_ASSERT(r, !flags);
flags |= Flags::kA;
REPORTER_ASSERT(r, flags);
REPORTER_ASSERT(r, !(flags & Flags::kB));
REPORTER_ASSERT(r, (flags & Flags::kA));
flags |= (Flags::kB | Flags::kC);
auto mask = Flags::kB | Flags::kC;
REPORTER_ASSERT(r, (flags & mask) == mask);
REPORTER_ASSERT(r, flags == (Flags::kA | Flags::kB | Flags::kC));
flags &= ~Flags::kC;
REPORTER_ASSERT(r, flags == (Flags::kA | Flags::kB));
REPORTER_ASSERT(r, (flags & mask) != mask);
REPORTER_ASSERT(r, (flags & mask) != Flags::kNone);
REPORTER_ASSERT(r, (flags & mask));
REPORTER_ASSERT(r, flags);
flags &= ~Flags::kB;
REPORTER_ASSERT(r, (flags & mask) == Flags::kNone);
REPORTER_ASSERT(r, !(flags & mask));
REPORTER_ASSERT(r, flags);
flags = (flags | flags) ^ (flags);
REPORTER_ASSERT(r, !flags);
flags ^= mask;
REPORTER_ASSERT(r, flags == mask);
REPORTER_ASSERT(r, !(Flags::kA & Flags::kB));
REPORTER_ASSERT(r, (Flags::kA ^ Flags::kB) == (Flags::kA | Flags::kB));
}