skia2/tests/SkEnumBitMaskTest.cpp
Robert Phillips 0326a9f27a Move skgpu::graphite::Mask to SkEnumBitMask
This will let us use this utility everywhere.

Bug: skia:12701
Change-Id: I9342d0b40a81789ed93e3ec4009e5602033d6691
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/534662
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
2022-04-28 14:04:16 +00:00

47 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 "src/core/SkEnumBitMask.h"
#include "tests/Test.h"
enum class Flags {
kNone = 0,
kA = 1,
kB = 2,
kC = 4
};
SK_MAKE_BITMASK_OPS(Flags);
DEF_TEST(skgpu_Mask, r) {
SkEnumBitMask<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));
}