Skip to content

Commit c223397

Browse files
mbknustarkq
andauthored
Switched to pw_unit_test in src/lib/dnssd/minimal_mdns/core/ (#33069)
* Switched to pw_unit_test in src/lib/dnssd/minimal_mdns/core/ * Update src/lib/dnssd/minimal_mdns/core/tests/TestHeapQName.cpp --------- Co-authored-by: Arkadiusz Bokowy <arkadiusz.bokowy@gmail.com> Co-authored-by: Arkadiusz Bokowy <a.bokowy@samsung.com>
1 parent 8238f98 commit c223397

File tree

7 files changed

+146
-272
lines changed

7 files changed

+146
-272
lines changed

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

+1-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
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

@@ -27,7 +26,7 @@ source_set("support") {
2726
]
2827
}
2928

30-
chip_test_suite_using_nltest("tests") {
29+
chip_test_suite("tests") {
3130
output_name = "libMinimalMdnsCoreTests"
3231

3332
test_sources = [
@@ -43,7 +42,5 @@ chip_test_suite_using_nltest("tests") {
4342
":support",
4443
"${chip_root}/src/lib/core",
4544
"${chip_root}/src/lib/dnssd/minimal_mdns/core",
46-
"${chip_root}/src/lib/support:testing_nlunit",
47-
"${nlunit_test_root}:nlunit-test",
4845
]
4946
}

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

+23-43
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
#include <lib/dnssd/minimal_mdns/core/FlatAllocatedQName.h>
18-
#include <lib/support/UnitTestRegistration.h>
17+
#include <gtest/gtest.h>
1918

20-
#include <nlunit-test.h>
19+
#include <lib/dnssd/minimal_mdns/core/FlatAllocatedQName.h>
2120

2221
namespace {
2322

@@ -38,28 +37,28 @@ class AutoFreeBuffer
3837
void * mBuffer;
3938
};
4039

41-
void TestFlatAllocatedQName(nlTestSuite * inSuite, void * inContext)
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+
TEST(TestFlatAllocatedQName, SizeCompare)
6362
{
6463
static const char kThis[] = "this";
6564
static const char kIs[] = "is";
@@ -79,23 +78,22 @@ void SizeCompare(nlTestSuite * inSuite, void * inContext)
7978

8079
const size_t kTestStorageSize = FlatAllocatedQName::RequiredStorageSize(kThis, kIs, kA, kTest);
8180

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));
81+
EXPECT_EQ(kTestStorageSize, FlatAllocatedQName::RequiredStorageSizeFromArray(kSameArraySameSize, 4));
82+
EXPECT_EQ(kTestStorageSize, FlatAllocatedQName::RequiredStorageSizeFromArray(kDifferentArraySameSize, 4));
83+
EXPECT_LT(kTestStorageSize, FlatAllocatedQName::RequiredStorageSizeFromArray(kDifferenArrayLongerWord, 4));
84+
EXPECT_GT(kTestStorageSize, FlatAllocatedQName::RequiredStorageSizeFromArray(kDifferenArrayShorterWord, 4));
8685

8786
// 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));
87+
EXPECT_EQ(kTestStorageSize, FlatAllocatedQName::RequiredStorageSizeFromArray(kSameArrayExtraWord, 4));
8988
// If we add the extra word, the sizes should not match
90-
NL_TEST_ASSERT(inSuite, kTestStorageSize < FlatAllocatedQName::RequiredStorageSizeFromArray(kSameArrayExtraWord, 5));
89+
EXPECT_LT(kTestStorageSize, FlatAllocatedQName::RequiredStorageSizeFromArray(kSameArrayExtraWord, 5));
9190

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));
91+
EXPECT_GT(kTestStorageSize, FlatAllocatedQName::RequiredStorageSizeFromArray(kShorterArray, 3));
92+
EXPECT_EQ(FlatAllocatedQName::RequiredStorageSizeFromArray(kSameArraySameSize, 3),
93+
FlatAllocatedQName::RequiredStorageSizeFromArray(kShorterArray, 3));
9694
}
9795

98-
void BuildCompare(nlTestSuite * inSuite, void * inContext)
96+
TEST(TestFlatAllocatedQName, BuildCompare)
9997
{
10098
static const char kThis[] = "this";
10199
static const char kIs[] = "is";
@@ -111,33 +109,15 @@ void BuildCompare(nlTestSuite * inSuite, void * inContext)
111109

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

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

116114
// 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));
115+
EXPECT_EQ(kTestQName, FlatAllocatedQName::BuildFromArray(storage, kSameArrayExtraWord, 4));
118116
// If we add the extra word, the names
119-
NL_TEST_ASSERT(inSuite, kTestQName != FlatAllocatedQName::BuildFromArray(storage, kSameArrayExtraWord, 5));
117+
EXPECT_NE(kTestQName, FlatAllocatedQName::BuildFromArray(storage, kSameArrayExtraWord, 5));
120118

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));
119+
EXPECT_NE(kTestQName, FlatAllocatedQName::BuildFromArray(storage, kShorterArray, 3));
120+
EXPECT_EQ(FlatAllocatedQName::BuildFromArray(storage, kSameArraySameSize, 3),
121+
FlatAllocatedQName::BuildFromArray(storage, kShorterArray, 3));
125122
}
126-
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-
134123
} // 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)

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

+22-55
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,33 @@
1616
* limitations under the License.
1717
*/
1818

19+
#include <gtest/gtest.h>
20+
1921
#include <lib/dnssd/minimal_mdns/core/HeapQName.h>
2022
#include <lib/dnssd/minimal_mdns/core/tests/QNameStrings.h>
21-
#include <lib/support/UnitTestRegistration.h>
22-
23-
#include <nlunit-test.h>
2423

2524
namespace {
2625

2726
using namespace mdns::Minimal;
2827

29-
void Construction(nlTestSuite * inSuite, void * inContext)
28+
class TestHeapQName : public ::testing::Test
29+
{
30+
public:
31+
static void SetUpTestSuite() { ASSERT_EQ(chip::Platform::MemoryInit(), CHIP_NO_ERROR); }
32+
static void TearDownTestSuite() { chip::Platform::MemoryShutdown(); }
33+
};
34+
35+
TEST_F(TestHeapQName, Construction)
3036
{
3137
{
3238

3339
const testing::TestQName<2> kShort({ "some", "test" });
3440

3541
HeapQName heapQName(kShort.Serialized());
3642

37-
NL_TEST_ASSERT(inSuite, heapQName.IsOk());
38-
NL_TEST_ASSERT(inSuite, heapQName.Content() == kShort.Full());
39-
NL_TEST_ASSERT(inSuite, kShort.Serialized() == heapQName.Content());
43+
EXPECT_TRUE(heapQName.IsOk());
44+
EXPECT_EQ(heapQName.Content(), kShort.Full());
45+
EXPECT_EQ(kShort.Serialized(), heapQName.Content());
4046
}
4147

4248
{
@@ -45,13 +51,13 @@ void Construction(nlTestSuite * inSuite, void * inContext)
4551

4652
HeapQName heapQName(kLonger.Serialized());
4753

48-
NL_TEST_ASSERT(inSuite, heapQName.IsOk());
49-
NL_TEST_ASSERT(inSuite, heapQName.Content() == kLonger.Full());
50-
NL_TEST_ASSERT(inSuite, kLonger.Serialized() == heapQName.Content());
54+
EXPECT_TRUE(heapQName.IsOk());
55+
EXPECT_EQ(heapQName.Content(), kLonger.Full());
56+
EXPECT_EQ(kLonger.Serialized(), heapQName.Content());
5157
}
5258
}
5359

54-
void Copying(nlTestSuite * inSuite, void * inContext)
60+
TEST_F(TestHeapQName, Copying)
5561
{
5662
const testing::TestQName<2> kShort({ "some", "test" });
5763

@@ -61,50 +67,11 @@ void Copying(nlTestSuite * inSuite, void * inContext)
6167

6268
name3 = name2;
6369

64-
NL_TEST_ASSERT(inSuite, name1.IsOk());
65-
NL_TEST_ASSERT(inSuite, name2.IsOk());
66-
NL_TEST_ASSERT(inSuite, name3.IsOk());
67-
NL_TEST_ASSERT(inSuite, name1.Content() == name2.Content());
68-
NL_TEST_ASSERT(inSuite, name1.Content() == name3.Content());
69-
}
70-
71-
static const nlTest sTests[] = { //
72-
NL_TEST_DEF("Construction", Construction), //
73-
NL_TEST_DEF("Copying", Copying), //
74-
NL_TEST_SENTINEL()
75-
};
76-
77-
int Setup(void * inContext)
78-
{
79-
CHIP_ERROR error = chip::Platform::MemoryInit();
80-
if (error != CHIP_NO_ERROR)
81-
return FAILURE;
82-
return SUCCESS;
83-
}
84-
85-
/**
86-
* Tear down the test suite.
87-
*/
88-
int Teardown(void * inContext)
89-
{
90-
chip::Platform::MemoryShutdown();
91-
return SUCCESS;
70+
EXPECT_TRUE(name1.IsOk());
71+
EXPECT_TRUE(name2.IsOk());
72+
EXPECT_TRUE(name3.IsOk());
73+
EXPECT_EQ(name1.Content(), name2.Content());
74+
EXPECT_EQ(name1.Content(), name3.Content());
9275
}
9376

9477
} // namespace
95-
96-
int TestHeapQName()
97-
{
98-
nlTestSuite theSuite = {
99-
"HeapQName",
100-
&sTests[0],
101-
&Setup,
102-
&Teardown,
103-
};
104-
105-
nlTestRunner(&theSuite, nullptr);
106-
107-
return (nlTestRunnerStats(&theSuite));
108-
}
109-
110-
CHIP_REGISTER_TEST_SUITE(TestHeapQName)

0 commit comments

Comments
 (0)