3 * Copyright (c) 2020 Project CHIP Authors
4 * Copyright (c) 2016-2017 Nest Labs, Inc.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 * This file implements a process to effect a functional test for
23 * the CHIP BLE layer library error string support interfaces.
27 #ifndef __STDC_FORMAT_MACROS
28 #define __STDC_FORMAT_MACROS
31 #ifndef __STDC_LIMIT_MACROS
32 #define __STDC_LIMIT_MACROS
39 #include <ble/BleError.h>
40 #include <support/ErrorStr.h>
41 #include <support/UnitTestRegistration.h>
43 #include <nlunit-test.h>
50 static int32_t sContext[] =
53 BLE_ERROR_INCORRECT_STATE,
54 BLE_ERROR_NO_ENDPOINTS,
55 BLE_ERROR_NO_CONNECTION_RECEIVED_CALLBACK,
56 BLE_ERROR_CENTRAL_UNSUBSCRIBED,
57 BLE_ERROR_GATT_SUBSCRIBE_FAILED,
58 BLE_ERROR_GATT_UNSUBSCRIBE_FAILED,
59 BLE_ERROR_GATT_WRITE_FAILED,
60 BLE_ERROR_GATT_INDICATE_FAILED,
61 BLE_ERROR_NOT_IMPLEMENTED,
62 BLE_ERROR_CHIPOBLE_PROTOCOL_ABORT,
63 BLE_ERROR_REMOTE_DEVICE_DISCONNECTED,
64 BLE_ERROR_APP_CLOSED_CONNECTION,
65 BLE_ERROR_OUTBOUND_MESSAGE_TOO_BIG,
66 BLE_ERROR_NOT_CHIP_DEVICE,
67 BLE_ERROR_INCOMPATIBLE_PROTOCOL_VERSIONS,
69 BLE_ERROR_MESSAGE_INCOMPLETE,
70 BLE_ERROR_INVALID_FRAGMENT_SIZE,
71 BLE_ERROR_START_TIMER_FAILED,
72 BLE_ERROR_CONNECT_TIMED_OUT,
73 BLE_ERROR_RECEIVE_TIMED_OUT,
74 BLE_ERROR_INVALID_MESSAGE,
75 BLE_ERROR_FRAGMENT_ACK_TIMED_OUT,
76 BLE_ERROR_KEEP_ALIVE_TIMED_OUT,
77 BLE_ERROR_NO_CONNECT_COMPLETE_CALLBACK,
78 BLE_ERROR_INVALID_ACK,
79 BLE_ERROR_REASSEMBLER_MISSING_DATA,
80 BLE_ERROR_INVALID_BTP_HEADER_FLAGS,
81 BLE_ERROR_INVALID_BTP_SEQUENCE_NUMBER,
82 BLE_ERROR_REASSEMBLER_INCORRECT_STATE,
83 BLE_ERROR_RECEIVED_MESSAGE_TOO_BIG
87 static const size_t kTestElements = sizeof(sContext) / sizeof(sContext[0]);
89 static void CheckBleErrorStr(nlTestSuite * inSuite, void * inContext)
91 // Register the layer error formatter
93 Ble::RegisterLayerErrorFormatter();
95 // For each defined error...
96 for (size_t i = 0; i < kTestElements; i++)
98 int32_t err = sContext[i];
99 const char * errStr = ErrorStr(err);
100 char expectedText[9];
102 // Assert that the error string contains the error number in hex.
103 snprintf(expectedText, sizeof(expectedText), "%08" PRIX32, err);
104 NL_TEST_ASSERT(inSuite, (strstr(errStr, expectedText) != NULL));
106 #if !CHIP_CONFIG_SHORT_ERROR_STR
107 // Assert that the error string contains a description, which is signaled
108 // by a presence of a colon proceeding the description.
109 NL_TEST_ASSERT(inSuite, (strchr(errStr, ':') != NULL));
110 #endif // !CHIP_CONFIG_SHORT_ERROR_STR
115 * Test Suite. It lists all the test functions.
119 static const nlTest sTests[] =
121 NL_TEST_DEF("BleErrorStr", CheckBleErrorStr),
127 int TestBleErrorStr(void)
130 nlTestSuite theSuite =
139 // Run test suit againt one context.
140 nlTestRunner(&theSuite, &sContext);
142 return nlTestRunnerStats(&theSuite);
145 CHIP_REGISTER_TEST_SUITE(TestBleErrorStr)