Skip to content

Commit

Permalink
Replaced nlunit-test with pw_unit_test in src/ble/tests/
Browse files Browse the repository at this point in the history
  • Loading branch information
mbknust committed Apr 8, 2024
1 parent f46cdf3 commit 29e14b5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 83 deletions.
8 changes: 2 additions & 6 deletions src/ble/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import("//build_overrides/nlunit_test.gni")

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

chip_test_suite_using_nltest("tests") {
chip_test_suite("tests") {
output_name = "libBleLayerTests"

test_sources = [
Expand All @@ -28,9 +28,5 @@ chip_test_suite_using_nltest("tests") {

cflags = [ "-Wconversion" ]

public_deps = [
"${chip_root}/src/ble",
"${chip_root}/src/lib/support:testing_nlunit",
"${nlunit_test_root}:nlunit-test",
]
public_deps = [ "${chip_root}/src/ble" ]
}
42 changes: 4 additions & 38 deletions src/ble/tests/TestBleErrorStr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@

#include <ble/BleError.h>
#include <lib/core/ErrorStr.h>
#include <lib/support/UnitTestRegistration.h>

#include <nlunit-test.h>
#include <gtest/gtest.h>

using namespace chip;

Expand Down Expand Up @@ -69,7 +68,7 @@ static const CHIP_ERROR kTestElements[] =
};
// clang-format on

static void CheckBleErrorStr(nlTestSuite * inSuite, void * inContext)
TEST(TestBleErrorStr, CheckBleErrorStr)
{
// Register the layer error formatter

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

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

#if !CHIP_CONFIG_SHORT_ERROR_STR
// Assert that the error string contains a description, which is signaled
// by a presence of a colon proceeding the description.
NL_TEST_ASSERT(inSuite, (strchr(errStr, ':') != nullptr));
EXPECT_NE(strchr(errStr, ':'), nullptr);
#endif // !CHIP_CONFIG_SHORT_ERROR_STR
}
}

/**
* Test Suite. It lists all the test functions.
*/

// clang-format off
static const nlTest sTests[] =
{
NL_TEST_DEF("BleErrorStr", CheckBleErrorStr),

NL_TEST_SENTINEL()
};
// clang-format on

int TestBleErrorStr()
{
// clang-format off
nlTestSuite theSuite =
{
"Test BLE range error strings conversions",
&sTests[0],
nullptr,
nullptr
};
// clang-format on

// Run test suite against one context.
nlTestRunner(&theSuite, nullptr);

return nlTestRunnerStats(&theSuite);
}

CHIP_REGISTER_TEST_SUITE(TestBleErrorStr)
55 changes: 16 additions & 39 deletions src/ble/tests/TestBleUUID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,80 +25,57 @@
*/

#include <ble/BleUUID.h>
#include <lib/support/UnitTestRegistration.h>

#include <nlunit-test.h>
#include <gtest/gtest.h>

using namespace chip;
using namespace chip::Ble;

namespace {

void CheckStringToUUID_ChipUUID(nlTestSuite * inSuite, void * inContext)
TEST(BleUUID, CheckStringToUUID_ChipUUID)
{
// Test positive scenario - CHIP Service UUID
ChipBleUUID uuid;
NL_TEST_ASSERT(inSuite, StringToUUID("0000FFF6-0000-1000-8000-00805F9B34FB", uuid));
NL_TEST_ASSERT(inSuite, UUIDsMatch(&uuid, &CHIP_BLE_SVC_ID));
EXPECT_TRUE(StringToUUID("0000FFF6-0000-1000-8000-00805F9B34FB", uuid));
EXPECT_TRUE(UUIDsMatch(&uuid, &CHIP_BLE_SVC_ID));
}

void CheckStringToUUID_ChipUUID_RandomCase(nlTestSuite * inSuite, void * inContext)
TEST(BleUUID, CheckStringToUUID_ChipUUID_RandomCase)
{
// Test that letter case doesn't matter
ChipBleUUID uuid;
NL_TEST_ASSERT(inSuite, StringToUUID("0000FfF6-0000-1000-8000-00805f9B34Fb", uuid));
NL_TEST_ASSERT(inSuite, UUIDsMatch(&uuid, &CHIP_BLE_SVC_ID));
EXPECT_TRUE(StringToUUID("0000FfF6-0000-1000-8000-00805f9B34Fb", uuid));
EXPECT_TRUE(UUIDsMatch(&uuid, &CHIP_BLE_SVC_ID));
}

void CheckStringToUUID_ChipUUID_NoSeparators(nlTestSuite * inSuite, void * inContext)
TEST(BleUUID, CheckStringToUUID_ChipUUID_NoSeparators)
{
// Test that separators don't matter
ChipBleUUID uuid;
NL_TEST_ASSERT(inSuite, StringToUUID("0000FFF600001000800000805F9B34FB", uuid));
NL_TEST_ASSERT(inSuite, UUIDsMatch(&uuid, &CHIP_BLE_SVC_ID));
EXPECT_TRUE(StringToUUID("0000FFF600001000800000805F9B34FB", uuid));
EXPECT_TRUE(UUIDsMatch(&uuid, &CHIP_BLE_SVC_ID));
}

void CheckStringToUUID_TooLong(nlTestSuite * inSuite, void * inContext)
TEST(BleUUID, CheckStringToUUID_TooLong)
{
// Test that even one more digit is too much
ChipBleUUID uuid;
NL_TEST_ASSERT(inSuite, !StringToUUID("0000FFF600001000800000805F9B34FB0", uuid));
EXPECT_FALSE(StringToUUID("0000FFF600001000800000805F9B34FB0", uuid));
}

void CheckStringToUUID_TooShort(nlTestSuite * inSuite, void * inContext)
TEST(BleUUID, CheckStringToUUID_TooShort)
{
// Test that even one less digit is too little
ChipBleUUID uuid;
NL_TEST_ASSERT(inSuite, !StringToUUID("0000FFF600001000800000805F9B34F", uuid));
EXPECT_FALSE(StringToUUID("0000FFF600001000800000805F9B34F", uuid));
}

void CheckStringToUUID_InvalidChar(nlTestSuite * inSuite, void * inContext)
TEST(BleUUID, CheckStringToUUID_InvalidChar)
{
// Test that non-hex digits don't pass
ChipBleUUID uuid;
NL_TEST_ASSERT(inSuite, !StringToUUID("0000GFF6-0000-1000-8000-00805F9B34FB0", uuid));
EXPECT_FALSE(StringToUUID("0000GFF6-0000-1000-8000-00805F9B34FB0", uuid));
}

// clang-format off
const nlTest sTests[] =
{
NL_TEST_DEF("CheckStringToUUID_ChipUUID", CheckStringToUUID_ChipUUID),
NL_TEST_DEF("CheckStringToUUID_ChipUUID_RandomCase", CheckStringToUUID_ChipUUID_RandomCase),
NL_TEST_DEF("CheckStringToUUID_ChipUUID_NoSeparators", CheckStringToUUID_ChipUUID_NoSeparators),
NL_TEST_DEF("CheckStringToUUID_TooLong", CheckStringToUUID_TooLong),
NL_TEST_DEF("CheckStringToUUID_TooShort", CheckStringToUUID_TooShort),
NL_TEST_DEF("CheckStringToUUID_InvalidChar", CheckStringToUUID_InvalidChar),
NL_TEST_SENTINEL()
};
// clang-format on

} // namespace

int TestBleUUID()
{
nlTestSuite theSuite = { "BleUUID", &sTests[0], nullptr, nullptr };
nlTestRunner(&theSuite, nullptr);
return nlTestRunnerStats(&theSuite);
}

CHIP_REGISTER_TEST_SUITE(TestBleUUID)

0 comments on commit 29e14b5

Please sign in to comment.