summaryrefslogtreecommitdiffstats
path: root/test/direct_bt/test_uuid.cpp
blob: 46d06d9a899df0e3bb981888d675c1b629341fd9 (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
94
95
96
97
98
99
100
101
102
103
#include <iostream>
#include <cassert>
#include <cinttypes>
#include <cstring>

#define CATCH_CONFIG_RUNNER
// #define CATCH_CONFIG_MAIN
#include <catch2/catch_amalgamated.hpp>
#include <jau/test/catch2_ext.hpp>

#include <direct_bt/UUID.hpp>

using namespace direct_bt;

TEST_CASE( "UUID Test 01", "[datatype][uuid]" ) {
    std::cout << "Hello COUT" << std::endl;
    std::cerr << "Hello CERR" << std::endl;

    uint8_t buffer[100];
    static uint8_t uuid128_bytes[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
                                       0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB };

    {
        const uuid128_t v01 = uuid128_t(uuid128_bytes, 0, true);
        REQUIRE(v01.getTypeSizeInt() == 16);
        REQUIRE(v01.getTypeSizeInt() == sizeof(v01.value));
        REQUIRE(v01.getTypeSizeInt() == sizeof(v01.value.data));
        REQUIRE( 0 == memcmp(uuid128_bytes, v01.data(), 16) );

        v01.put(buffer, 0, true /* littleEndian */);
        std::shared_ptr<const uuid_t> v02 = uuid_t::create(uuid_t::TypeSize::UUID128_SZ, buffer, 0, true);
        REQUIRE(v02->getTypeSizeInt() == 16);
        REQUIRE( 0 == memcmp(v01.data(), v02->data(), 16) );
        REQUIRE( v01.toString() == v02->toString() );
    }

    {
        const uuid32_t v01 = uuid32_t(uuid32_t(0x12345678));
        REQUIRE(v01.getTypeSizeInt() == 4);
        REQUIRE(v01.getTypeSizeInt() == sizeof(v01.value));
        REQUIRE(0x12345678 == v01.value);

        v01.put(buffer, 0, true /* littleEndian */);
        std::shared_ptr<const uuid_t> v02 = uuid_t::create(uuid_t::TypeSize::UUID32_SZ, buffer, 0, true);
        REQUIRE(v02->getTypeSizeInt() == 4);
        REQUIRE( 0 == memcmp(v01.data(), v02->data(), 4) );
        REQUIRE( v01.toString() == v02->toString() );
    }

    {
        const uuid16_t v01 = uuid16_t(uuid16_t(0x1234));
        REQUIRE(v01.getTypeSizeInt() == 2);
        REQUIRE(v01.getTypeSizeInt() == sizeof(v01.value));
        REQUIRE(0x1234 == v01.value);

        v01.put(buffer, 0, true /* littleEndian */);
        std::shared_ptr<const uuid_t> v02 = uuid_t::create(uuid_t::TypeSize::UUID16_SZ, buffer, 0, true);
        REQUIRE(v02->getTypeSizeInt() == 2);
        REQUIRE( 0 == memcmp(v01.data(), v02->data(), 2) );
        REQUIRE( v01.toString() == v02->toString() );
    }



    {
        const uuid16_t v01("1234");
        REQUIRE(v01.getTypeSizeInt() == uuid_t::number( uuid_t::TypeSize::UUID16_SZ ));
        REQUIRE(v01.getTypeSizeInt() == sizeof(v01.value));
        REQUIRE(0x1234 == v01.value);
        REQUIRE("1234" == v01.toString());
    }
    {
        const uuid32_t v01("12345678");
        REQUIRE(v01.getTypeSizeInt() == uuid_t::number( uuid_t::TypeSize::UUID32_SZ ));
        REQUIRE(v01.getTypeSizeInt() == sizeof(v01.value));
        REQUIRE(0x12345678 == v01.value);
        REQUIRE("12345678" == v01.toString());
    }
    {
        const uuid128_t v01("00001234-5678-100A-800B-00805F9B34FB");
        REQUIRE(v01.getTypeSizeInt() == uuid_t::number( uuid_t::TypeSize::UUID128_SZ) );
        REQUIRE(v01.getTypeSizeInt() == sizeof(v01.value));
        REQUIRE("00001234-5678-100a-800b-00805f9b34fb" == v01.toString());
    }



    {
        std::shared_ptr<const uuid_t> v01 = uuid_t::create("1234");
        REQUIRE(v01->getTypeSizeInt() == uuid_t::number( uuid_t::TypeSize::UUID16_SZ ));
        REQUIRE("1234" == v01->toString());
    }
    {
        std::shared_ptr<const uuid_t> v01 = uuid_t::create("12345678");
        REQUIRE(v01->getTypeSizeInt() == uuid_t::number( uuid_t::TypeSize::UUID32_SZ));
        REQUIRE("12345678" == v01->toString());
    }
    {
        std::shared_ptr<const uuid_t> v01 = uuid_t::create("00001234-5678-100A-800B-00805F9B34FB");
        REQUIRE(v01->getTypeSizeInt() == uuid_t::number( uuid_t::TypeSize::UUID128_SZ ));
        REQUIRE("00001234-5678-100a-800b-00805f9b34fb" == v01->toString());
    }
}