xref: /nrf52832-nimble/packages/NimBLE-latest/nimble/host/test/src/ble_uuid_test.c (revision 042d53a763ad75cb1465103098bb88c245d95138)
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements.  See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership.  The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License.  You may obtain a copy of the License at
9  *
10  *  http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied.  See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19 
20 #include <stddef.h>
21 #include <string.h>
22 #include "testutil/testutil.h"
23 #include "host/ble_hs_test.h"
24 #include "host/ble_uuid.h"
25 #include "ble_hs_test_util.h"
26 
TEST_CASE(ble_uuid_test)27 TEST_CASE(ble_uuid_test)
28 {
29     uint8_t buf_16[2] = { 0x00, 0x18 };
30     uint8_t buf_128[16] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
31                             0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF };
32 
33     const ble_uuid_t *uuid16_1 = BLE_UUID16_DECLARE(0x1800);
34     const ble_uuid_t *uuid16_2 = BLE_UUID16_DECLARE(0x1801);
35 
36     const ble_uuid_t *uuid128_1 =
37         BLE_UUID128_DECLARE(0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
38                             0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF);
39     const ble_uuid_t *uuid128_2 =
40         BLE_UUID128_DECLARE(0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
41                                 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xEE);
42 
43     ble_uuid_any_t uuid;
44     int rc;
45 
46     rc = ble_uuid_init_from_buf(&uuid, buf_16, 2);
47     TEST_ASSERT(rc == 0);
48 
49     rc = ble_uuid_cmp(&uuid.u, uuid16_1);
50     TEST_ASSERT(rc == 0);
51 
52     rc = ble_uuid_cmp(&uuid.u, uuid16_2);
53     TEST_ASSERT(rc != 0);
54 
55     rc = ble_uuid_cmp(uuid16_1, uuid16_2);
56     TEST_ASSERT(rc != 0);
57 
58     rc = ble_uuid_init_from_buf(&uuid, buf_128, 16);
59     TEST_ASSERT(rc == 0);
60 
61     rc = ble_uuid_cmp(&uuid.u, uuid128_1);
62     TEST_ASSERT(rc == 0);
63 
64     rc = ble_uuid_cmp(&uuid.u, uuid128_2);
65     TEST_ASSERT(rc != 0);
66 
67     rc = ble_uuid_cmp(uuid128_1, uuid128_2);
68     TEST_ASSERT(rc != 0);
69 }
70 
TEST_SUITE(ble_uuid_test_suite)71 TEST_SUITE(ble_uuid_test_suite)
72 {
73     tu_suite_set_post_test_cb(ble_hs_test_util_post_test, NULL);
74 
75     ble_uuid_test();
76 }
77 
78 int
ble_uuid_test_all(void)79 ble_uuid_test_all(void)
80 {
81     ble_uuid_test_suite();
82 
83     return tu_any_failed;
84 }
85