OpenShot Audio Library | OpenShotAudio: juce_EnumHelpers_test.cpp Source File

OpenShot Audio Library | OpenShotAudio 0.4.0

Loading...
Searching...
No Matches
juce_EnumHelpers_test.cpp
1/*
2==============================================================================
3
4This file is part of the JUCE library.
5Copyright (c) 2022 - Raw Material Software Limited
6
7JUCE is an open source library subject to commercial or open-source
8licensing.
9
10The code included in this file is provided under the terms of the ISC license
11http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12To use, copy, modify, and/or distribute this software for any purpose with or
13without fee is hereby granted provided that the above copyright notice and
14this permission notice appear in all copies.
15
16JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18DISCLAIMED.
19
20==============================================================================
21*/
22
23namespace juce
24{
25
26namespace detail
27{
28enum class TestEnum
29{
30 one = 1 << 0,
31 four = 1 << 1,
32 other = 1 << 2
33};
34
35JUCE_DECLARE_SCOPED_ENUM_BITWISE_OPERATORS (TestEnum)
36}
37
38class EnumHelperTest final : public UnitTest
39{
40public:
41 EnumHelperTest() : UnitTest ("EnumHelpers", UnitTestCategories::containers) {}
42
43 void runTest() override
44 {
45 using detail::TestEnum;
46
47 TestEnum e = {};
48
49 beginTest ("Default initialised enum is 'none'");
50 {
51 expect (e == TestEnum{});
52 expect (! hasBitValueSet (e, TestEnum{}));
53 }
54
55 beginTest ("withBitValueSet sets correct bit on empty enum");
56 {
57 e = withBitValueSet (e, TestEnum::other);
58 expect (e == TestEnum::other);
59 expect (hasBitValueSet (e, TestEnum::other));
60 }
61
62 beginTest ("withBitValueSet sets correct bit on non-empty enum");
63 {
64 e = withBitValueSet (e, TestEnum::one);
65 expect (hasBitValueSet (e, TestEnum::one));
66 }
67
68 beginTest ("withBitValueCleared clears correct bit");
69 {
70 e = withBitValueCleared (e, TestEnum::one);
71 expect (e != TestEnum::one);
72 expect (hasBitValueSet (e, TestEnum::other));
73 expect (! hasBitValueSet (e, TestEnum::one));
74 }
75
76 beginTest ("operators work as expected");
77 {
78 e = TestEnum::one;
79 expect ((e & TestEnum::one) != TestEnum{});
80 e |= TestEnum::other;
81 expect ((e & TestEnum::other) != TestEnum{});
82
83 e &= ~TestEnum::one;
84 expect ((e & TestEnum::one) == TestEnum{});
85 expect ((e & TestEnum::other) != TestEnum{});
86 }
87 }
88};
89
90static EnumHelperTest enumHelperTest;
91
92} // namespace juce
juce::UnitTest::UnitTest
UnitTest(const String &name, const String &category=String())
Definition juce_UnitTest.cpp:26
juce::UnitTest::beginTest
void beginTest(const String &testName)
Definition juce_UnitTest.cpp:89
juce::UnitTest::expect
void expect(bool testResult, const String &failureMessage=String())
Definition juce_UnitTest.cpp:97