Skip to content

Commit 7489e02

Browse files
feasel0arkq
andauthored
Updated unit tests in src/transport/raw/tests/ to use PW instead of NL. (project-chip#33099)
* Updated unit tests in src/transport/tests/ to use PW instead of NL. * Updated unit tests in src/protocols/bdx/tests/ to use PW instead of NL * Updated unit tests in src/transport/raw/tests/ to use PW instead of NL. * Undid the accidental reformatting of the comments at the top. * Update src/transport/raw/tests/TestTCP.cpp Co-authored-by: Arkadiusz Bokowy <arkadiusz.bokowy@gmail.com> * Update src/transport/raw/tests/TestUDP.cpp Co-authored-by: Arkadiusz Bokowy <arkadiusz.bokowy@gmail.com> * Changed some EXPECT_ to ASSERT_. Changed C-casts to unsigned literals. Chagned strcmp to EXPECT_STREQ. * Resolved merge conflicts in test_components[_nl].txt * Added a destructor to TestUDP to delete the TestContext. * Added destructor to TestTCP to delete the TestContext. * Added destructor to TestTCP to delete TestContext. * Fixed issue with SystemLayerTests being listed multiple times. * Changed MemoryInit line to ASSERT instead of EXPECT. Added corresponding MemoryShutdown. * Inherited TCP test from IOContext so we don't have to create a new context. * Moved ChckSimpleInitTest and CheckMessageTest into the test context class. --------- Co-authored-by: Arkadiusz Bokowy <arkadiusz.bokowy@gmail.com>
1 parent 80c19cd commit 7489e02

File tree

7 files changed

+316
-500
lines changed

7 files changed

+316
-500
lines changed

src/test_driver/openiotsdk/unit-tests/test_components.txt

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ CoreTests
1010
MdnsTests
1111
CredentialsTest
1212
PlatformTests
13+
RawTransportTests
1314
RetransmitTests
1415
TestShell
1516
SetupPayloadTests

src/test_driver/openiotsdk/unit-tests/test_components_nl.txt

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ AppTests
22
DataModelTests
33
InetLayerTests
44
MessagingLayerTests
5-
RawTransportTests
65
SecureChannelTestsNL
76
SupportTestsNL
87
TransportLayerTests

src/transport/raw/tests/BUILD.gn

+2-5
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@
1414

1515
import("//build_overrides/build.gni")
1616
import("//build_overrides/chip.gni")
17-
import("//build_overrides/nlunit_test.gni")
17+
import("//build_overrides/pigweed.gni")
1818

1919
import("${chip_root}/build/chip/chip_test_suite.gni")
20-
2120
static_library("helpers") {
2221
output_name = "libNetworkTestHelpers"
2322
output_dir = "${root_out_dir}/lib"
@@ -35,7 +34,7 @@ static_library("helpers") {
3534
]
3635
}
3736

38-
chip_test_suite_using_nltest("tests") {
37+
chip_test_suite("tests") {
3938
output_name = "libRawTransportTests"
4039

4140
test_sources = [
@@ -51,10 +50,8 @@ chip_test_suite_using_nltest("tests") {
5150
"${chip_root}/src/lib/core",
5251
"${chip_root}/src/lib/support",
5352
"${chip_root}/src/lib/support:test_utils",
54-
"${chip_root}/src/lib/support:testing_nlunit",
5553
"${chip_root}/src/transport",
5654
"${chip_root}/src/transport/raw",
57-
"${nlunit_test_root}:nlunit-test",
5855
]
5956

6057
cflags = [ "-Wconversion" ]

src/transport/raw/tests/TestMessageHeader.cpp

+138-162
Large diffs are not rendered by default.

src/transport/raw/tests/TestPeerAddress.cpp

+13-47
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@
2424
#include <inet/IPAddress.h>
2525
#include <lib/core/DataModelTypes.h>
2626
#include <lib/core/PeerId.h>
27-
#include <lib/support/UnitTestRegistration.h>
2827
#include <transport/raw/PeerAddress.h>
2928

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

3231
namespace {
3332

@@ -39,47 +38,47 @@ using chip::Transport::PeerAddress;
3938
/**
4039
* Test correct identification of IPv6 multicast addresses.
4140
*/
42-
void TestPeerAddressMulticast(nlTestSuite * inSuite, void * inContext)
41+
TEST(TestPeerAddress, TestPeerAddressMulticast)
4342
{
4443
constexpr chip::FabricId fabric = 0xa1a2a4a8b1b2b4b8;
4544
constexpr chip::GroupId group = 0xe10f;
4645
PeerAddress addr = PeerAddress::Multicast(fabric, group);
47-
NL_TEST_ASSERT(inSuite, chip::Transport::Type::kUdp == addr.GetTransportType());
48-
NL_TEST_ASSERT(inSuite, addr.IsMulticast());
46+
EXPECT_EQ(chip::Transport::Type::kUdp, addr.GetTransportType());
47+
EXPECT_TRUE(addr.IsMulticast());
4948

5049
const Inet::IPAddress & ip = addr.GetIPAddress();
51-
NL_TEST_ASSERT(inSuite, ip.IsIPv6Multicast());
52-
NL_TEST_ASSERT(inSuite, chip::Inet::IPAddressType::kIPv6 == ip.Type());
50+
EXPECT_TRUE(ip.IsIPv6Multicast());
51+
EXPECT_EQ(chip::Inet::IPAddressType::kIPv6, ip.Type());
5352

5453
constexpr uint8_t expected[NL_INET_IPV6_ADDR_LEN_IN_BYTES] = { 0xff, 0x35, 0x00, 0x40, 0xfd, 0xa1, 0xa2, 0xa4,
5554
0xa8, 0xb1, 0xb2, 0xb4, 0xb8, 0x00, 0xe1, 0x0f };
5655
uint8_t result[NL_INET_IPV6_ADDR_LEN_IN_BYTES];
5756
uint8_t * p = result;
5857
ip.WriteAddress(p);
59-
NL_TEST_ASSERT(inSuite, !memcmp(expected, result, NL_INET_IPV6_ADDR_LEN_IN_BYTES));
58+
EXPECT_EQ(0, memcmp(expected, result, NL_INET_IPV6_ADDR_LEN_IN_BYTES));
6059
}
6160

62-
void TestToString(nlTestSuite * inSuite, void * inContext)
61+
TEST(TestPeerAddress, TestToString)
6362
{
6463
char buff[PeerAddress::kMaxToStringSize];
6564
IPAddress ip;
6665
{
6766
IPAddress::FromString("::1", ip);
6867
PeerAddress::UDP(ip, 1122).ToString(buff);
6968

70-
NL_TEST_ASSERT(inSuite, !strcmp(buff, "UDP:[::1]:1122"));
69+
EXPECT_STREQ(buff, "UDP:[::1]:1122");
7170
}
7271

7372
{
7473
IPAddress::FromString("::1", ip);
7574
PeerAddress::TCP(ip, 1122).ToString(buff);
7675

77-
NL_TEST_ASSERT(inSuite, !strcmp(buff, "TCP:[::1]:1122"));
76+
EXPECT_STREQ(buff, "TCP:[::1]:1122");
7877
}
7978

8079
{
8180
PeerAddress::BLE().ToString(buff);
82-
NL_TEST_ASSERT(inSuite, !strcmp(buff, "BLE"));
81+
EXPECT_STREQ(buff, "BLE");
8382
}
8483

8584
{
@@ -89,49 +88,16 @@ void TestToString(nlTestSuite * inSuite, void * inContext)
8988
int res1 = strcmp(buff, "UDP:[1223::3456:789a]:8080");
9089
int res2 = strcmp(buff, "UDP:[1223::3456:789A]:8080");
9190

92-
NL_TEST_ASSERT(inSuite, (!res1 || !res2));
91+
EXPECT_TRUE(!res1 || !res2);
9392
}
9493

9594
{
9695

9796
PeerAddress udp = PeerAddress(Transport::Type::kUdp);
9897
udp.SetPort(5840);
9998
udp.ToString(buff);
100-
NL_TEST_ASSERT(inSuite, !strcmp(buff, "UDP:[::]:5840"));
99+
EXPECT_STREQ(buff, "UDP:[::]:5840");
101100
}
102101
}
103102

104-
/**
105-
* Test Suite. It lists all the test functions.
106-
*/
107-
108-
// clang-format off
109-
const nlTest sTests[] =
110-
{
111-
NL_TEST_DEF("PeerAddress Multicast", TestPeerAddressMulticast),
112-
NL_TEST_DEF("ToString", TestToString),
113-
NL_TEST_SENTINEL()
114-
};
115-
// clang-format on
116-
117103
} // namespace
118-
119-
int TestPeerAddress()
120-
{
121-
// clang-format off
122-
nlTestSuite theSuite =
123-
{
124-
"PeerAddress",
125-
&sTests[0],
126-
nullptr,
127-
nullptr
128-
};
129-
// clang-format on
130-
131-
// Run test suite against one context.
132-
nlTestRunner(&theSuite, nullptr);
133-
134-
return (nlTestRunnerStats(&theSuite));
135-
}
136-
137-
CHIP_REGISTER_TEST_SUITE(TestPeerAddress)

0 commit comments

Comments
 (0)