Direct-BT v3.3.0-1-gc2d430c
Direct-BT - Direct Bluetooth Programming.
test_uuid.cpp
Go to the documentation of this file.
1#include <cassert>
2#include <cinttypes>
3#include <cstring>
4
6
7#include <jau/uuid.hpp>
8
9using namespace jau;
10
11TEST_CASE( "UUID Test 01", "[datatype][uuid]" ) {
12 uint8_t buffer[100];
13 static uint8_t uuid128_bytes[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
14 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB };
15
16 {
17 const uuid128_t v01 = uuid128_t(uuid128_bytes, jau::lb_endian_t::little);
18 REQUIRE(v01.getTypeSizeInt() == 16);
19 REQUIRE(v01.getTypeSizeInt() == sizeof(v01.value));
20 REQUIRE(v01.getTypeSizeInt() == sizeof(v01.value.data));
21 REQUIRE( 0 == memcmp(uuid128_bytes, v01.data(), 16) );
22
23 v01.put(buffer, jau::lb_endian_t::little);
24 std::shared_ptr<const uuid_t> v02 = uuid_t::create(uuid_t::TypeSize::UUID128_SZ, buffer, jau::lb_endian_t::little);
25 REQUIRE(v02->getTypeSizeInt() == 16);
26 REQUIRE( 0 == memcmp(v01.data(), v02->data(), 16) );
27 REQUIRE( v01.toString() == v02->toString() );
28 }
29
30 {
31 const uuid32_t v01 = uuid32_t(uuid32_t(0x12345678));
32 REQUIRE(v01.getTypeSizeInt() == 4);
33 REQUIRE(v01.getTypeSizeInt() == sizeof(v01.value));
34 REQUIRE(0x12345678 == v01.value);
35
36 v01.put(buffer, jau::lb_endian_t::little);
37 std::shared_ptr<const uuid_t> v02 = uuid_t::create(uuid_t::TypeSize::UUID32_SZ, buffer, jau::lb_endian_t::little);
38 REQUIRE(v02->getTypeSizeInt() == 4);
39 REQUIRE( 0 == memcmp(v01.data(), v02->data(), 4) );
40 REQUIRE( v01.toString() == v02->toString() );
41 }
42
43 {
44 const uuid16_t v01 = uuid16_t(uuid16_t(0x1234));
45 REQUIRE(v01.getTypeSizeInt() == 2);
46 REQUIRE(v01.getTypeSizeInt() == sizeof(v01.value));
47 REQUIRE(0x1234 == v01.value);
48
49 v01.put(buffer, jau::lb_endian_t::little);
50 std::shared_ptr<const uuid_t> v02 = uuid_t::create(uuid_t::TypeSize::UUID16_SZ, buffer, jau::lb_endian_t::little);
51 REQUIRE(v02->getTypeSizeInt() == 2);
52 REQUIRE( 0 == memcmp(v01.data(), v02->data(), 2) );
53 REQUIRE( v01.toString() == v02->toString() );
54 }
55
56
57
58 {
59 const uuid128_t v01("00001234-5678-100A-800B-00805F9B34FB");
60 REQUIRE(v01.getTypeSizeInt() == uuid_t::number( uuid_t::TypeSize::UUID128_SZ) );
61 REQUIRE(v01.getTypeSizeInt() == sizeof(v01.value));
62 REQUIRE("00001234-5678-100a-800b-00805f9b34fb" == v01.toString());
63 REQUIRE(uuid128_t("00001234-5678-100a-800b-00805f9b34fb") == v01);
64 REQUIRE(uuid128_t("00001234-5678-100a-800b-00805f9b34fc") != v01);
65 }
66 {
67 const uuid16_t v01("1234");
68 REQUIRE(v01.getTypeSizeInt() == uuid_t::number( uuid_t::TypeSize::UUID16_SZ ));
69 REQUIRE(v01.getTypeSizeInt() == sizeof(v01.value));
70 REQUIRE(0x1234 == v01.value);
71 REQUIRE("1234" == v01.toString());
72
73 const uuid16_t v01_copy = v01;
74 REQUIRE(v01_copy == v01);
75 REQUIRE(uuid16_t("1235") != v01);
76
77 const uuid128_t v01_128 = v01.toUUID128();
78 const uuid128_t v02("00001234-0000-1000-8000-00805F9B34FB");
79 REQUIRE(v01_128 == v02);
80 REQUIRE(v01 != v02);
81 REQUIRE(v01.equivalent(v02));
82 }
83 {
84 const uuid32_t v01("12345678");
85 REQUIRE(v01.getTypeSizeInt() == uuid_t::number( uuid_t::TypeSize::UUID32_SZ ));
86 REQUIRE(v01.getTypeSizeInt() == sizeof(v01.value));
87 REQUIRE(0x12345678 == v01.value);
88 REQUIRE("12345678" == v01.toString());
89
90 const uuid32_t v01_copy = v01;
91 REQUIRE(v01_copy == v01);
92 REQUIRE(uuid32_t("12345679") != v01);
93
94 const uuid128_t v01_128 = v01.toUUID128();
95 const uuid128_t v02("12345678-0000-1000-8000-00805F9B34FB");
96 REQUIRE(v01_128 == v02);
97
98 REQUIRE(v01 != v02);
99 REQUIRE(v01.equivalent(v02));
100 }
101
102
103
104 {
105 std::shared_ptr<const uuid_t> v01 = uuid_t::create("1234");
106 REQUIRE(v01->getTypeSizeInt() == uuid_t::number( uuid_t::TypeSize::UUID16_SZ ));
107 REQUIRE("1234" == v01->toString());
108 }
109 {
110 std::shared_ptr<const uuid_t> v01 = uuid_t::create("12345678");
111 REQUIRE(v01->getTypeSizeInt() == uuid_t::number( uuid_t::TypeSize::UUID32_SZ));
112 REQUIRE("12345678" == v01->toString());
113 }
114 {
115 std::shared_ptr<const uuid_t> v01 = uuid_t::create("00001234-5678-100A-800B-00805F9B34FB");
116 REQUIRE(v01->getTypeSizeInt() == uuid_t::number( uuid_t::TypeSize::UUID128_SZ ));
117 REQUIRE("00001234-5678-100a-800b-00805f9b34fb" == v01->toString());
118 }
119}
std::string toString() const noexcept override
Returns the string representation in BE network order, i.e.
Definition: uuid.cpp:177
jau::nsize_t put(uint8_t *const buffer, lb_endian_t const le_or_be) const noexcept override
Definition: uuid.hpp:236
const uint8_t * data() const noexcept override
returns the pointer to the uuid data of size getTypeSize()
Definition: uuid.hpp:228
jau::uint128dp_t value
Definition: uuid.hpp:207
uint16_t value
Definition: uuid.hpp:153
const uint8_t * data() const noexcept override
returns the pointer to the uuid data of size getTypeSize()
Definition: uuid.hpp:168
jau::nsize_t put(uint8_t *const buffer, lb_endian_t const le_or_be) const noexcept override
Definition: uuid.hpp:172
std::string toString() const noexcept override
Returns the string representation in BE network order, i.e.
Definition: uuid.cpp:135
std::string toString() const noexcept override
Returns the string representation in BE network order, i.e.
Definition: uuid.cpp:154
uint32_t value
Definition: uuid.hpp:180
jau::nsize_t put(uint8_t *const buffer, lb_endian_t const le_or_be) const noexcept override
Definition: uuid.hpp:199
const uint8_t * data() const noexcept override
returns the pointer to the uuid data of size getTypeSize()
Definition: uuid.hpp:195
uuid128_t toUUID128(uuid128_t const &base_uuid=BT_BASE_UUID, jau::nsize_t const uuid32_le_octet_index=12) const noexcept
Definition: uuid.cpp:119
jau::nsize_t getTypeSizeInt() const noexcept
Definition: uuid.hpp:126
bool equivalent(uuid_t const &o) const noexcept
Relaxed equality operator.
Definition: uuid.cpp:109
@ little
Identifier for little endian, equivalent to endian::little.
constexpr uint32_t number(const iostate rhs) noexcept
Definition: byte_stream.hpp:72
__pack(...): Produces MSVC, clang and gcc compatible lead-in and -out macros.
Definition: backtrace.hpp:32
uint8_t data[16]
Definition: int_types.hpp:114
TEST_CASE("UUID Test 01", "[datatype][uuid]")
Definition: test_uuid.cpp:11