-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuuid_test.cpp
58 lines (45 loc) · 1.45 KB
/
uuid_test.cpp
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
#include "uuid.hpp"
// std
#include <iostream>
#include <sstream>
// local
#include "literals.hpp"
#include "simple_unit_test.hpp"
namespace util::test {
template <size_t N>
std::ostream& operator<<(std::ostream& os, const std::array<char, N>& a)
{
char buffer[N+1];
strncpy(buffer, &a[0], N);
buffer[N] = 0;
os << buffer;
return os;
}
}
int main(int argc, char* argv[])
{
using namespace util;
using namespace util::test;
using namespace std::literals;
// check default constructed is zero'd out
uuid u;
ASSERT_EQUAL( u.data, decltype(uuid::data){0} );
// check to_string
ASSERT_EQUAL( u.to_string(), "00000000-0000-0000-0000-000000000000"s );
// check accessors
uint64_t v {};
v = 0x01000000; memcpy( &u.data[0], &v, 4 );
v = 0x0200; memcpy( &u.data[4], &v, 2 );
v = 0x0300; memcpy( &u.data[6], &v, 2 );
v = 0x04; memcpy( &u.data[8], &v, 1 );
v = 0x05; memcpy( &u.data[9], &v, 1 );
v = 0x0000060000000000; memcpy( &u.data[10], &v, 6 );
ASSERT_EQUAL( u.to_string(), "00000001-0002-0003-0405-000000000006"s );
ASSERT_EQUAL( u.time_low(), 1 );
ASSERT_EQUAL( u.time_mid(), 2 );
ASSERT_EQUAL( u.time_hi_version(), 3 );
ASSERT_EQUAL( u.clock_seq_hi_reserved(), 4 );
ASSERT_EQUAL( u.clock_seq_low(), 5 );
ASSERT_EQUAL( u.node(), 6 );
return failed_tests;
}