Skip to content

Commit 0515c61

Browse files
authored
Replaced nlunit-test with pw_unit_test in src/ble/tests/ (project-chip#32891)
1 parent 8e12436 commit 0515c61

File tree

3 files changed

+22
-84
lines changed

3 files changed

+22
-84
lines changed

src/ble/tests/BUILD.gn

+2-7
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@
1414

1515
import("//build_overrides/build.gni")
1616
import("//build_overrides/chip.gni")
17-
import("//build_overrides/nlunit_test.gni")
1817

1918
import("${chip_root}/build/chip/chip_test_suite.gni")
2019

21-
chip_test_suite_using_nltest("tests") {
20+
chip_test_suite("tests") {
2221
output_name = "libBleLayerTests"
2322

2423
test_sources = [
@@ -28,9 +27,5 @@ chip_test_suite_using_nltest("tests") {
2827

2928
cflags = [ "-Wconversion" ]
3029

31-
public_deps = [
32-
"${chip_root}/src/ble",
33-
"${chip_root}/src/lib/support:testing_nlunit",
34-
"${nlunit_test_root}:nlunit-test",
35-
]
30+
public_deps = [ "${chip_root}/src/ble" ]
3631
}

src/ble/tests/TestBleErrorStr.cpp

+4-38
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@
3030

3131
#include <ble/BleError.h>
3232
#include <lib/core/ErrorStr.h>
33-
#include <lib/support/UnitTestRegistration.h>
3433

35-
#include <nlunit-test.h>
34+
#include <gtest/gtest.h>
3635

3736
using namespace chip;
3837

@@ -69,7 +68,7 @@ static const CHIP_ERROR kTestElements[] =
6968
};
7069
// clang-format on
7170

72-
static void CheckBleErrorStr(nlTestSuite * inSuite, void * inContext)
71+
TEST(TestBleErrorStr, CheckBleErrorStr)
7372
{
7473
// Register the layer error formatter
7574

@@ -83,45 +82,12 @@ static void CheckBleErrorStr(nlTestSuite * inSuite, void * inContext)
8382

8483
// Assert that the error string contains the error number in hex.
8584
snprintf(expectedText, sizeof(expectedText), "%08" PRIX32, err.AsInteger());
86-
NL_TEST_ASSERT(inSuite, (strstr(errStr, expectedText) != nullptr));
85+
EXPECT_NE(strstr(errStr, expectedText), nullptr);
8786

8887
#if !CHIP_CONFIG_SHORT_ERROR_STR
8988
// Assert that the error string contains a description, which is signaled
9089
// by a presence of a colon proceeding the description.
91-
NL_TEST_ASSERT(inSuite, (strchr(errStr, ':') != nullptr));
90+
EXPECT_NE(strchr(errStr, ':'), nullptr);
9291
#endif // !CHIP_CONFIG_SHORT_ERROR_STR
9392
}
9493
}
95-
96-
/**
97-
* Test Suite. It lists all the test functions.
98-
*/
99-
100-
// clang-format off
101-
static const nlTest sTests[] =
102-
{
103-
NL_TEST_DEF("BleErrorStr", CheckBleErrorStr),
104-
105-
NL_TEST_SENTINEL()
106-
};
107-
// clang-format on
108-
109-
int TestBleErrorStr()
110-
{
111-
// clang-format off
112-
nlTestSuite theSuite =
113-
{
114-
"Test BLE range error strings conversions",
115-
&sTests[0],
116-
nullptr,
117-
nullptr
118-
};
119-
// clang-format on
120-
121-
// Run test suite against one context.
122-
nlTestRunner(&theSuite, nullptr);
123-
124-
return nlTestRunnerStats(&theSuite);
125-
}
126-
127-
CHIP_REGISTER_TEST_SUITE(TestBleErrorStr)

src/ble/tests/TestBleUUID.cpp

+16-39
Original file line numberDiff line numberDiff line change
@@ -25,80 +25,57 @@
2525
*/
2626

2727
#include <ble/BleUUID.h>
28-
#include <lib/support/UnitTestRegistration.h>
2928

30-
#include <nlunit-test.h>
29+
#include <gtest/gtest.h>
3130

3231
using namespace chip;
3332
using namespace chip::Ble;
3433

3534
namespace {
3635

37-
void CheckStringToUUID_ChipUUID(nlTestSuite * inSuite, void * inContext)
36+
TEST(TestBleUUID, CheckStringToUUID_ChipUUID)
3837
{
3938
// Test positive scenario - CHIP Service UUID
4039
ChipBleUUID uuid;
41-
NL_TEST_ASSERT(inSuite, StringToUUID("0000FFF6-0000-1000-8000-00805F9B34FB", uuid));
42-
NL_TEST_ASSERT(inSuite, UUIDsMatch(&uuid, &CHIP_BLE_SVC_ID));
40+
EXPECT_TRUE(StringToUUID("0000FFF6-0000-1000-8000-00805F9B34FB", uuid));
41+
EXPECT_TRUE(UUIDsMatch(&uuid, &CHIP_BLE_SVC_ID));
4342
}
4443

45-
void CheckStringToUUID_ChipUUID_RandomCase(nlTestSuite * inSuite, void * inContext)
44+
TEST(TestBleUUID, CheckStringToUUID_ChipUUID_RandomCase)
4645
{
4746
// Test that letter case doesn't matter
4847
ChipBleUUID uuid;
49-
NL_TEST_ASSERT(inSuite, StringToUUID("0000FfF6-0000-1000-8000-00805f9B34Fb", uuid));
50-
NL_TEST_ASSERT(inSuite, UUIDsMatch(&uuid, &CHIP_BLE_SVC_ID));
48+
EXPECT_TRUE(StringToUUID("0000FfF6-0000-1000-8000-00805f9B34Fb", uuid));
49+
EXPECT_TRUE(UUIDsMatch(&uuid, &CHIP_BLE_SVC_ID));
5150
}
5251

53-
void CheckStringToUUID_ChipUUID_NoSeparators(nlTestSuite * inSuite, void * inContext)
52+
TEST(TestBleUUID, CheckStringToUUID_ChipUUID_NoSeparators)
5453
{
5554
// Test that separators don't matter
5655
ChipBleUUID uuid;
57-
NL_TEST_ASSERT(inSuite, StringToUUID("0000FFF600001000800000805F9B34FB", uuid));
58-
NL_TEST_ASSERT(inSuite, UUIDsMatch(&uuid, &CHIP_BLE_SVC_ID));
56+
EXPECT_TRUE(StringToUUID("0000FFF600001000800000805F9B34FB", uuid));
57+
EXPECT_TRUE(UUIDsMatch(&uuid, &CHIP_BLE_SVC_ID));
5958
}
6059

61-
void CheckStringToUUID_TooLong(nlTestSuite * inSuite, void * inContext)
60+
TEST(TestBleUUID, CheckStringToUUID_TooLong)
6261
{
6362
// Test that even one more digit is too much
6463
ChipBleUUID uuid;
65-
NL_TEST_ASSERT(inSuite, !StringToUUID("0000FFF600001000800000805F9B34FB0", uuid));
64+
EXPECT_FALSE(StringToUUID("0000FFF600001000800000805F9B34FB0", uuid));
6665
}
6766

68-
void CheckStringToUUID_TooShort(nlTestSuite * inSuite, void * inContext)
67+
TEST(TestBleUUID, CheckStringToUUID_TooShort)
6968
{
7069
// Test that even one less digit is too little
7170
ChipBleUUID uuid;
72-
NL_TEST_ASSERT(inSuite, !StringToUUID("0000FFF600001000800000805F9B34F", uuid));
71+
EXPECT_FALSE(StringToUUID("0000FFF600001000800000805F9B34F", uuid));
7372
}
7473

75-
void CheckStringToUUID_InvalidChar(nlTestSuite * inSuite, void * inContext)
74+
TEST(TestBleUUID, CheckStringToUUID_InvalidChar)
7675
{
7776
// Test that non-hex digits don't pass
7877
ChipBleUUID uuid;
79-
NL_TEST_ASSERT(inSuite, !StringToUUID("0000GFF6-0000-1000-8000-00805F9B34FB0", uuid));
78+
EXPECT_FALSE(StringToUUID("0000GFF6-0000-1000-8000-00805F9B34FB0", uuid));
8079
}
8180

82-
// clang-format off
83-
const nlTest sTests[] =
84-
{
85-
NL_TEST_DEF("CheckStringToUUID_ChipUUID", CheckStringToUUID_ChipUUID),
86-
NL_TEST_DEF("CheckStringToUUID_ChipUUID_RandomCase", CheckStringToUUID_ChipUUID_RandomCase),
87-
NL_TEST_DEF("CheckStringToUUID_ChipUUID_NoSeparators", CheckStringToUUID_ChipUUID_NoSeparators),
88-
NL_TEST_DEF("CheckStringToUUID_TooLong", CheckStringToUUID_TooLong),
89-
NL_TEST_DEF("CheckStringToUUID_TooShort", CheckStringToUUID_TooShort),
90-
NL_TEST_DEF("CheckStringToUUID_InvalidChar", CheckStringToUUID_InvalidChar),
91-
NL_TEST_SENTINEL()
92-
};
93-
// clang-format on
94-
9581
} // namespace
96-
97-
int TestBleUUID()
98-
{
99-
nlTestSuite theSuite = { "BleUUID", &sTests[0], nullptr, nullptr };
100-
nlTestRunner(&theSuite, nullptr);
101-
return nlTestRunnerStats(&theSuite);
102-
}
103-
104-
CHIP_REGISTER_TEST_SUITE(TestBleUUID)

0 commit comments

Comments
 (0)