Skip to content

Commit 4271f3f

Browse files
committed
converting 3 minimal mDNS unit tests from NL_unit to pw_unit
1 parent d8245cb commit 4271f3f

File tree

4 files changed

+152
-185
lines changed

4 files changed

+152
-185
lines changed

src/lib/dnssd/minimal_mdns/core/tests/BUILD.gn

+17-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import("//build_overrides/build.gni")
1616
import("//build_overrides/chip.gni")
1717
import("//build_overrides/nlunit_test.gni")
18+
import("//build_overrides/pigweed.gni")
1819

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

@@ -27,18 +28,32 @@ source_set("support") {
2728
]
2829
}
2930

30-
chip_test_suite_using_nltest("tests") {
31+
chip_test_suite("tests") {
3132
output_name = "libMinimalMdnsCoreTests"
3233

3334
test_sources = [
3435
"TestFlatAllocatedQName.cpp",
35-
"TestHeapQName.cpp",
3636
"TestQName.cpp",
3737
"TestRecordWriter.cpp",
3838
]
3939

4040
cflags = [ "-Wconversion" ]
4141

42+
public_deps = [
43+
":support",
44+
"${chip_root}/src/lib/core",
45+
"${chip_root}/src/lib/dnssd/minimal_mdns/core",
46+
]
47+
}
48+
49+
#nl tests will not be compiled
50+
chip_test_suite_using_nltest("tests_nltest") {
51+
output_name = "libMinimalMdnsCoreTestsNL"
52+
53+
test_sources = [ "TestHeapQName.cpp" ]
54+
55+
cflags = [ "-Wconversion" ]
56+
4257
public_deps = [
4358
":support",
4459
"${chip_root}/src/lib/core",

src/lib/dnssd/minimal_mdns/core/tests/TestFlatAllocatedQName.cpp

+23-42
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
* limitations under the License.
1616
*/
1717
#include <lib/dnssd/minimal_mdns/core/FlatAllocatedQName.h>
18-
#include <lib/support/UnitTestRegistration.h>
19-
20-
#include <nlunit-test.h>
18+
#include <gtest/gtest.h>
2119

2220
namespace {
2321

@@ -38,28 +36,30 @@ class AutoFreeBuffer
3836
void * mBuffer;
3937
};
4038

41-
void TestFlatAllocatedQName(nlTestSuite * inSuite, void * inContext)
39+
40+
TEST (TestFlatAllocatedQName, TestFlatAllocatedQName)
4241
{
4342
AutoFreeBuffer buffer(128);
4443

45-
NL_TEST_ASSERT(inSuite, FlatAllocatedQName::RequiredStorageSize("some", "test") == (sizeof(char * [2]) + 5 + 5));
44+
EXPECT_EQ(FlatAllocatedQName::RequiredStorageSize("some", "test"), (sizeof(char * [2]) + 5 + 5));
4645

4746
{
4847
FullQName built = FlatAllocatedQName::Build(buffer.Buffer(), "some", "test");
4948
const QNamePart expected[] = { "some", "test" };
5049

51-
NL_TEST_ASSERT(inSuite, FullQName(expected) == built);
50+
EXPECT_EQ(FullQName(expected), built);
5251
}
5352

5453
{
5554
FullQName built = FlatAllocatedQName::Build(buffer.Buffer(), "1", "2", "3");
5655
const QNamePart expected[] = { "1", "2", "3" };
5756

58-
NL_TEST_ASSERT(inSuite, FullQName(expected) == built);
57+
EXPECT_EQ(FullQName(expected), built);
5958
}
6059
}
6160

62-
void SizeCompare(nlTestSuite * inSuite, void * inContext)
61+
62+
TEST (TestFlatAllocatedQName, SizeCompare)
6363
{
6464
static const char kThis[] = "this";
6565
static const char kIs[] = "is";
@@ -79,23 +79,22 @@ void SizeCompare(nlTestSuite * inSuite, void * inContext)
7979

8080
const size_t kTestStorageSize = FlatAllocatedQName::RequiredStorageSize(kThis, kIs, kA, kTest);
8181

82-
NL_TEST_ASSERT(inSuite, kTestStorageSize == FlatAllocatedQName::RequiredStorageSizeFromArray(kSameArraySameSize, 4));
83-
NL_TEST_ASSERT(inSuite, kTestStorageSize == FlatAllocatedQName::RequiredStorageSizeFromArray(kDifferentArraySameSize, 4));
84-
NL_TEST_ASSERT(inSuite, kTestStorageSize < FlatAllocatedQName::RequiredStorageSizeFromArray(kDifferenArrayLongerWord, 4));
85-
NL_TEST_ASSERT(inSuite, kTestStorageSize > FlatAllocatedQName::RequiredStorageSizeFromArray(kDifferenArrayShorterWord, 4));
82+
EXPECT_EQ(kTestStorageSize, FlatAllocatedQName::RequiredStorageSizeFromArray(kSameArraySameSize, 4));
83+
EXPECT_EQ(kTestStorageSize, FlatAllocatedQName::RequiredStorageSizeFromArray(kDifferentArraySameSize, 4));
84+
EXPECT_LT(kTestStorageSize, FlatAllocatedQName::RequiredStorageSizeFromArray(kDifferenArrayLongerWord, 4));
85+
EXPECT_GT(kTestStorageSize, FlatAllocatedQName::RequiredStorageSizeFromArray(kDifferenArrayShorterWord, 4));
8686

8787
// Although the size of the array is larger, if we tell the function there are only 4 words, it should still work.
88-
NL_TEST_ASSERT(inSuite, kTestStorageSize == FlatAllocatedQName::RequiredStorageSizeFromArray(kSameArrayExtraWord, 4));
88+
EXPECT_EQ(kTestStorageSize, FlatAllocatedQName::RequiredStorageSizeFromArray(kSameArrayExtraWord, 4));
8989
// If we add the extra word, the sizes should not match
90-
NL_TEST_ASSERT(inSuite, kTestStorageSize < FlatAllocatedQName::RequiredStorageSizeFromArray(kSameArrayExtraWord, 5));
90+
EXPECT_LT(kTestStorageSize, FlatAllocatedQName::RequiredStorageSizeFromArray(kSameArrayExtraWord, 5));
9191

92-
NL_TEST_ASSERT(inSuite, kTestStorageSize > FlatAllocatedQName::RequiredStorageSizeFromArray(kShorterArray, 3));
93-
NL_TEST_ASSERT(inSuite,
94-
FlatAllocatedQName::RequiredStorageSizeFromArray(kSameArraySameSize, 3) ==
95-
FlatAllocatedQName::RequiredStorageSizeFromArray(kShorterArray, 3));
92+
EXPECT_GT(kTestStorageSize, FlatAllocatedQName::RequiredStorageSizeFromArray(kShorterArray, 3));
93+
EXPECT_EQ(FlatAllocatedQName::RequiredStorageSizeFromArray(kSameArraySameSize, 3), FlatAllocatedQName::RequiredStorageSizeFromArray(kShorterArray, 3));
9694
}
9795

98-
void BuildCompare(nlTestSuite * inSuite, void * inContext)
96+
97+
TEST (TestFlatAllocatedQName, BuildCompare)
9998
{
10099
static const char kThis[] = "this";
101100
static const char kIs[] = "is";
@@ -111,33 +110,15 @@ void BuildCompare(nlTestSuite * inSuite, void * inContext)
111110

112111
const FullQName kTestQName = FlatAllocatedQName::Build(storage, kThis, kIs, kA, kTest);
113112

114-
NL_TEST_ASSERT(inSuite, kTestQName == FlatAllocatedQName::BuildFromArray(storage, kSameArraySameSize, 4));
113+
EXPECT_EQ(kTestQName, FlatAllocatedQName::BuildFromArray(storage, kSameArraySameSize, 4));
115114

116115
// Although the size of the array is larger, if we tell the function there are only 4 words, it should still work.
117-
NL_TEST_ASSERT(inSuite, kTestQName == FlatAllocatedQName::BuildFromArray(storage, kSameArrayExtraWord, 4));
116+
EXPECT_EQ(kTestQName, FlatAllocatedQName::BuildFromArray(storage, kSameArrayExtraWord, 4));
118117
// If we add the extra word, the names
119-
NL_TEST_ASSERT(inSuite, kTestQName != FlatAllocatedQName::BuildFromArray(storage, kSameArrayExtraWord, 5));
118+
EXPECT_NE(kTestQName, FlatAllocatedQName::BuildFromArray(storage, kSameArrayExtraWord, 5));
120119

121-
NL_TEST_ASSERT(inSuite, kTestQName != FlatAllocatedQName::BuildFromArray(storage, kShorterArray, 3));
122-
NL_TEST_ASSERT(inSuite,
123-
FlatAllocatedQName::BuildFromArray(storage, kSameArraySameSize, 3) ==
124-
FlatAllocatedQName::BuildFromArray(storage, kShorterArray, 3));
120+
EXPECT_NE(kTestQName, FlatAllocatedQName::BuildFromArray(storage, kShorterArray, 3));
121+
EXPECT_EQ(FlatAllocatedQName::BuildFromArray(storage, kSameArraySameSize, 3), FlatAllocatedQName::BuildFromArray(storage, kShorterArray, 3));
125122
}
126123

127-
const nlTest sTests[] = {
128-
NL_TEST_DEF("TestFlatAllocatedQName", TestFlatAllocatedQName), //
129-
NL_TEST_DEF("TestFlatAllocatedQNameRequiredSizes", SizeCompare), //
130-
NL_TEST_DEF("TestFlatAllocatedQNameBuild", BuildCompare), //
131-
NL_TEST_SENTINEL() //
132-
};
133-
134124
} // namespace
135-
136-
int TestFlatAllocatedQName()
137-
{
138-
nlTestSuite theSuite = { "FlatAllocatedQName", sTests, nullptr, nullptr };
139-
nlTestRunner(&theSuite, nullptr);
140-
return nlTestRunnerStats(&theSuite);
141-
}
142-
143-
CHIP_REGISTER_TEST_SUITE(TestFlatAllocatedQName)

0 commit comments

Comments
 (0)