WXK
2024-09-18 05e2e954bd127de378a9d1dfbb0ed95d725aad63
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
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
 
#include <stddef.h>
#include <string.h>
#include "testutil/testutil.h"
#include "ble_hs_test.h"
#include "host/ble_uuid.h"
#include "ble_hs_test_util.h"
 
TEST_CASE_SELF(ble_uuid_test)
{
    uint8_t buf_16[2] = { 0x00, 0x18 };
    uint8_t buf_128[16] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
                            0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF };
 
    const ble_uuid_t *uuid16_1 = BLE_UUID16_DECLARE(0x1800);
    const ble_uuid_t *uuid16_2 = BLE_UUID16_DECLARE(0x1801);
 
    const ble_uuid_t *uuid128_1 =
        BLE_UUID128_DECLARE(0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
                            0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF);
    const ble_uuid_t *uuid128_2 =
        BLE_UUID128_DECLARE(0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
                                0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xEE);
 
    ble_uuid_any_t uuid;
    int rc;
 
    rc = ble_uuid_init_from_buf(&uuid, buf_16, 2);
    TEST_ASSERT(rc == 0);
 
    rc = ble_uuid_cmp(&uuid.u, uuid16_1);
    TEST_ASSERT(rc == 0);
 
    rc = ble_uuid_cmp(&uuid.u, uuid16_2);
    TEST_ASSERT(rc != 0);
 
    rc = ble_uuid_cmp(uuid16_1, uuid16_2);
    TEST_ASSERT(rc != 0);
 
    rc = ble_uuid_init_from_buf(&uuid, buf_128, 16);
    TEST_ASSERT(rc == 0);
 
    rc = ble_uuid_cmp(&uuid.u, uuid128_1);
    TEST_ASSERT(rc == 0);
 
    rc = ble_uuid_cmp(&uuid.u, uuid128_2);
    TEST_ASSERT(rc != 0);
 
    rc = ble_uuid_cmp(uuid128_1, uuid128_2);
    TEST_ASSERT(rc != 0);
 
    ble_hs_test_util_assert_mbufs_freed(NULL);
}
 
TEST_SUITE(ble_uuid_test_suite)
{
    ble_uuid_test();
}