blob: 183bebf722d3ad2cf14335cba6fde508a7c2d087 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
///////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2015 Microsoft Corporation. All rights reserved.
//
// This code is licensed under the MIT License (MIT).
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
///////////////////////////////////////////////////////////////////////////////
#include <UnitTest++/UnitTest++.h>
#include <gsl/gsl_byte.h>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <string>
#include <vector>
using namespace std;
using namespace gsl;
namespace
{
SUITE(byte_tests)
{
TEST(construction)
{
{
byte b = static_cast<byte>(4);
CHECK(static_cast<unsigned char>(b) == 4);
}
{
byte b = byte(12);
CHECK(static_cast<unsigned char>(b) == 12);
}
// waiting for C++17 enum class direct initializer support
//{
// byte b { 14 };
// CHECK(static_cast<unsigned char>(b) == 14);
//}
}
TEST(bitwise_operations)
{
byte b = byte(0xFF);
byte a = byte(0x00);
CHECK((b | a) == byte(0xFF));
CHECK(a == byte(0x00));
a |= b;
CHECK(a == byte(0xFF));
a = byte(0x01);
CHECK((b & a) == byte(0x01));
a &= b;
CHECK(a == byte(0x01));
CHECK((b ^ a) == byte(0xFE));
CHECK(a == byte(0x01));
a ^= b;
CHECK(a == byte(0xFE));
a = byte(0x01);
CHECK(~a == byte(0xFE));
a = byte(0xFF);
CHECK((a << 4) == byte(0xF0));
CHECK((a >> 4) == byte(0x0F));
a <<= 4;
CHECK(a == byte(0xF0));
a >>= 4;
CHECK(a == byte(0x0F));
}
}
}
int main(int, const char* []) { return UnitTest::RunAllTests(); }
|