Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a827d51

Browse files
committedApr 22, 2024·
Revert "converting 3 minimal mDNS unit tests from NL_unit to pw_unit"
This reverts commit 4271f3f.
1 parent b91314e commit a827d51

File tree

4 files changed

+185
-152
lines changed

4 files changed

+185
-152
lines changed
 

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

+2-17
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
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")
1918

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

@@ -28,32 +27,18 @@ source_set("support") {
2827
]
2928
}
3029

31-
chip_test_suite("tests") {
30+
chip_test_suite_using_nltest("tests") {
3231
output_name = "libMinimalMdnsCoreTests"
3332

3433
test_sources = [
3534
"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-
5742
public_deps = [
5843
":support",
5944
"${chip_root}/src/lib/core",

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

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

2022
namespace {
2123

@@ -36,30 +38,28 @@ class AutoFreeBuffer
3638
void * mBuffer;
3739
};
3840

39-
40-
TEST (TestFlatAllocatedQName, TestFlatAllocatedQName)
41+
void TestFlatAllocatedQName(nlTestSuite * inSuite, void * inContext)
4142
{
4243
AutoFreeBuffer buffer(128);
4344

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

4647
{
4748
FullQName built = FlatAllocatedQName::Build(buffer.Buffer(), "some", "test");
4849
const QNamePart expected[] = { "some", "test" };
4950

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

5354
{
5455
FullQName built = FlatAllocatedQName::Build(buffer.Buffer(), "1", "2", "3");
5556
const QNamePart expected[] = { "1", "2", "3" };
5657

57-
EXPECT_EQ(FullQName(expected), built);
58+
NL_TEST_ASSERT(inSuite, FullQName(expected) == built);
5859
}
5960
}
6061

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

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

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

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

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

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

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

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

120-
EXPECT_NE(kTestQName, FlatAllocatedQName::BuildFromArray(storage, kShorterArray, 3));
121-
EXPECT_EQ(FlatAllocatedQName::BuildFromArray(storage, kSameArraySameSize, 3), FlatAllocatedQName::BuildFromArray(storage, kShorterArray, 3));
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));
122125
}
123126

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+
124134
} // 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/TestQName.cpp

+122-84
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
*/
1818

1919
#include <lib/dnssd/minimal_mdns/core/QName.h>
20-
#include <gtest/gtest.h>
20+
#include <lib/support/UnitTestRegistration.h>
21+
22+
#include <nlunit-test.h>
2123

2224
namespace {
2325

@@ -38,263 +40,299 @@ static SerializedQNameIterator AsSerializedQName(const uint8_t (&v)[N])
3840
return SerializedQNameIterator(BytesRange(v, v + N - 1), v);
3941
}
4042

41-
42-
TEST (TestQName, IteratorTest)
43+
void IteratorTest(nlTestSuite * inSuite, void * inContext)
4344
{
4445
{
4546
static const uint8_t kOneItem[] = "\04test\00";
4647
SerializedQNameIterator it = AsSerializedQName(kOneItem);
4748

48-
EXPECT_TRUE(it.Next());
49-
EXPECT_FALSE(strcmp(it.Value(), "test"));
50-
EXPECT_FALSE(it.Next());
51-
EXPECT_TRUE(it.IsValid());
49+
NL_TEST_ASSERT(inSuite, it.Next());
50+
NL_TEST_ASSERT(inSuite, strcmp(it.Value(), "test") == 0);
51+
NL_TEST_ASSERT(inSuite, !it.Next());
52+
NL_TEST_ASSERT(inSuite, it.IsValid());
5253
}
5354

5455
{
5556
static const uint8_t kManyItems[] = "\04this\02is\01a\04test\00";
5657
SerializedQNameIterator it = AsSerializedQName(kManyItems);
5758

58-
EXPECT_TRUE(it.Next());
59-
EXPECT_FALSE(strcmp(it.Value(), "this"));
59+
NL_TEST_ASSERT(inSuite, it.Next());
60+
NL_TEST_ASSERT(inSuite, strcmp(it.Value(), "this") == 0);
6061

61-
EXPECT_TRUE(it.Next());
62-
EXPECT_FALSE(strcmp(it.Value(), "is"));
62+
NL_TEST_ASSERT(inSuite, it.Next());
63+
NL_TEST_ASSERT(inSuite, strcmp(it.Value(), "is") == 0);
6364

64-
EXPECT_TRUE(it.Next());
65-
EXPECT_FALSE(strcmp(it.Value(), "a"));
65+
NL_TEST_ASSERT(inSuite, it.Next());
66+
NL_TEST_ASSERT(inSuite, strcmp(it.Value(), "a") == 0);
6667

67-
EXPECT_TRUE(it.Next());
68-
EXPECT_FALSE(strcmp(it.Value(), "test"));
68+
NL_TEST_ASSERT(inSuite, it.Next());
69+
NL_TEST_ASSERT(inSuite, strcmp(it.Value(), "test") == 0);
6970

70-
EXPECT_FALSE(it.Next());
71-
EXPECT_TRUE(it.IsValid());
71+
NL_TEST_ASSERT(inSuite, !it.Next());
72+
NL_TEST_ASSERT(inSuite, it.IsValid());
7273
}
7374
{
7475
static const uint8_t kPtrItems[] = "abc\02is\01a\04test\00\04this\xc0\03";
7576
SerializedQNameIterator it(BytesRange(kPtrItems, kPtrItems + sizeof(kPtrItems)), kPtrItems + 14);
7677

77-
EXPECT_TRUE(it.Next());
78-
EXPECT_FALSE(strcmp(it.Value(), "this"));
78+
NL_TEST_ASSERT(inSuite, it.Next());
79+
NL_TEST_ASSERT(inSuite, strcmp(it.Value(), "this") == 0);
7980

80-
EXPECT_TRUE(it.Next());
81-
EXPECT_FALSE(strcmp(it.Value(), "is"));
81+
NL_TEST_ASSERT(inSuite, it.Next());
82+
NL_TEST_ASSERT(inSuite, strcmp(it.Value(), "is") == 0);
8283

83-
EXPECT_TRUE(it.Next());
84-
EXPECT_FALSE(strcmp(it.Value(), "a"));
84+
NL_TEST_ASSERT(inSuite, it.Next());
85+
NL_TEST_ASSERT(inSuite, strcmp(it.Value(), "a") == 0);
8586

86-
EXPECT_TRUE(it.Next());
87-
EXPECT_FALSE(strcmp(it.Value(), "test"));
87+
NL_TEST_ASSERT(inSuite, it.Next());
88+
NL_TEST_ASSERT(inSuite, strcmp(it.Value(), "test") == 0);
8889

89-
EXPECT_FALSE(it.Next());
90-
EXPECT_TRUE(it.IsValid());
90+
NL_TEST_ASSERT(inSuite, !it.Next());
91+
NL_TEST_ASSERT(inSuite, it.IsValid());
9192
}
9293
}
9394

94-
95-
TEST (TestQName, ErrorTest)
95+
void ErrorTest(nlTestSuite * inSuite, void * inContext)
9696
{
9797
{
9898
// Truncated before the end
9999
static const uint8_t kData[] = "\04test";
100100
SerializedQNameIterator it = AsSerializedQName(kData);
101101

102-
EXPECT_FALSE(it.Next());
103-
EXPECT_FALSE(it.IsValid());
102+
NL_TEST_ASSERT(inSuite, !it.Next());
103+
NL_TEST_ASSERT(inSuite, !it.IsValid());
104104
}
105105

106106
{
107107
// Truncated before the end
108108
static const uint8_t kData[] = "\02";
109109
SerializedQNameIterator it = AsSerializedQName(kData);
110110

111-
EXPECT_FALSE(it.Next());
112-
EXPECT_FALSE(it.IsValid());
111+
NL_TEST_ASSERT(inSuite, !it.Next());
112+
NL_TEST_ASSERT(inSuite, !it.IsValid());
113113
}
114114

115115
{
116116
// Truncated before the end
117117
static const uint8_t kData[] = "\xc0";
118118
SerializedQNameIterator it = AsSerializedQName(kData);
119119

120-
EXPECT_FALSE(it.Next());
121-
EXPECT_FALSE(it.IsValid());
120+
NL_TEST_ASSERT(inSuite, !it.Next());
121+
NL_TEST_ASSERT(inSuite, !it.IsValid());
122122
}
123123
}
124124

125-
126-
TEST (TestQName, InvalidReferencing)
125+
void InvalidReferencing(nlTestSuite * inSuite, void * inContext)
127126
{
128127
{
129128
// Truncated before the end (but seemingly valid in case of error)
130129
// does NOT use AsSerializedQName (because out of range)
131130
static const uint8_t kData[] = "\00\xc0\x00";
132131
SerializedQNameIterator it(BytesRange(kData, kData + 2), kData + 1);
133132

134-
EXPECT_FALSE(it.Next());
135-
EXPECT_FALSE(it.IsValid());
133+
NL_TEST_ASSERT(inSuite, !it.Next());
134+
NL_TEST_ASSERT(inSuite, !it.IsValid());
136135
}
137136

138137
{
139138
// Infinite recursion
140139
static const uint8_t kData[] = "\03test\xc0\x00";
141140
SerializedQNameIterator it = AsSerializedQName(kData);
142141

143-
EXPECT_TRUE(it.Next());
144-
EXPECT_FALSE(it.Next());
145-
EXPECT_FALSE(it.IsValid());
142+
NL_TEST_ASSERT(inSuite, it.Next());
143+
NL_TEST_ASSERT(inSuite, !it.Next());
144+
NL_TEST_ASSERT(inSuite, !it.IsValid());
146145
}
147146

148147
{
149148
// Infinite recursion by referencing own element (inside the stream)
150149
static const uint8_t kData[] = "\03test\xc0\x05";
151150
SerializedQNameIterator it = AsSerializedQName(kData);
152151

153-
EXPECT_TRUE(it.Next());
154-
EXPECT_FALSE(it.Next());
155-
EXPECT_FALSE(it.IsValid());
152+
NL_TEST_ASSERT(inSuite, it.Next());
153+
NL_TEST_ASSERT(inSuite, !it.Next());
154+
NL_TEST_ASSERT(inSuite, !it.IsValid());
156155
}
157156

158157
{
159158
// Infinite recursion by referencing own element at the start
160159
static const uint8_t kData[] = "\xc0\x00";
161160
SerializedQNameIterator it = AsSerializedQName(kData);
162161

163-
EXPECT_FALSE(it.Next());
164-
EXPECT_FALSE(it.IsValid());
162+
NL_TEST_ASSERT(inSuite, !it.Next());
163+
NL_TEST_ASSERT(inSuite, !it.IsValid());
165164
}
166165

167166
{
168167
// Reference that goes forwad instead of backward
169168
static const uint8_t kData[] = "\03test\xc0\x07";
170169
SerializedQNameIterator it = AsSerializedQName(kData);
171170

172-
EXPECT_TRUE(it.Next());
173-
EXPECT_FALSE(it.Next());
174-
EXPECT_FALSE(it.IsValid());
171+
NL_TEST_ASSERT(inSuite, it.Next());
172+
NL_TEST_ASSERT(inSuite, !it.Next());
173+
NL_TEST_ASSERT(inSuite, !it.IsValid());
175174
}
176175
}
177176

178-
179-
TEST (TestQName, Comparison)
177+
void Comparison(nlTestSuite * inSuite, void * inContext)
180178
{
181179
static const uint8_t kManyItems[] = "\04this\02is\01a\04test\00";
182180

183181
{
184182
const QNamePart kTestName[] = { "this" };
185-
EXPECT_NE(AsSerializedQName(kManyItems), FullQName(kTestName));
183+
NL_TEST_ASSERT(inSuite, AsSerializedQName(kManyItems) != FullQName(kTestName));
186184
}
187185

188186
{
189187
const QNamePart kTestName[] = { "this", "is" };
190-
EXPECT_NE(AsSerializedQName(kManyItems), FullQName(kTestName));
188+
NL_TEST_ASSERT(inSuite, AsSerializedQName(kManyItems) != FullQName(kTestName));
191189
}
192190

193191
{
194192
const QNamePart kTestName[] = { "is", "a", "test" };
195-
EXPECT_NE(AsSerializedQName(kManyItems), FullQName(kTestName));
193+
NL_TEST_ASSERT(inSuite, AsSerializedQName(kManyItems) != FullQName(kTestName));
196194
}
197195

198196
{
199197
const QNamePart kTestName[] = { "this", "is", "a", "test" };
200-
EXPECT_EQ(AsSerializedQName(kManyItems), FullQName(kTestName));
198+
NL_TEST_ASSERT(inSuite, AsSerializedQName(kManyItems) == FullQName(kTestName));
201199
}
202200

203201
{
204202
const QNamePart kTestName[] = { "this", "is", "a", "test", "suffix" };
205-
EXPECT_NE(AsSerializedQName(kManyItems), FullQName(kTestName));
203+
NL_TEST_ASSERT(inSuite, AsSerializedQName(kManyItems) != FullQName(kTestName));
206204
}
207205

208206
{
209207
const QNamePart kTestName[] = { "prefix", "this", "is", "a", "test" };
210-
EXPECT_NE(AsSerializedQName(kManyItems), FullQName(kTestName));
208+
NL_TEST_ASSERT(inSuite, AsSerializedQName(kManyItems) != FullQName(kTestName));
211209
}
212210
}
213211

214-
TEST (TestQName, CaseInsensitiveSerializedCompare)
212+
void CaseInsensitiveSerializedCompare(nlTestSuite * inSuite, void * inContext)
215213
{
216214
static const uint8_t kManyItems[] = "\04thIs\02iS\01a\04tEst\00";
217215

218216
{
219217
const QNamePart kTestName[] = { "this", "is", "a", "test" };
220-
EXPECT_EQ(SerializedQNameIterator(BytesRange(kManyItems, kManyItems + sizeof(kManyItems)), kManyItems), FullQName(kTestName));
218+
NL_TEST_ASSERT(inSuite,
219+
SerializedQNameIterator(BytesRange(kManyItems, kManyItems + sizeof(kManyItems)), kManyItems) ==
220+
FullQName(kTestName));
221221
}
222222

223223
{
224224
const QNamePart kTestName[] = { "THIS", "IS", "A", "test" };
225-
EXPECT_EQ(SerializedQNameIterator(BytesRange(kManyItems, kManyItems + sizeof(kManyItems)), kManyItems), FullQName(kTestName));
225+
NL_TEST_ASSERT(inSuite,
226+
SerializedQNameIterator(BytesRange(kManyItems, kManyItems + sizeof(kManyItems)), kManyItems) ==
227+
FullQName(kTestName));
226228
}
227229

228230
{
229231
const QNamePart kTestName[] = { "THIS", "IS", "A", "TEST" };
230-
EXPECT_EQ(SerializedQNameIterator(BytesRange(kManyItems, kManyItems + sizeof(kManyItems)), kManyItems), FullQName(kTestName));
232+
NL_TEST_ASSERT(inSuite,
233+
SerializedQNameIterator(BytesRange(kManyItems, kManyItems + sizeof(kManyItems)), kManyItems) ==
234+
FullQName(kTestName));
231235
}
232236
}
233237

234-
TEST (TestQName, CaseInsensitiveFullQNameCompare)
238+
void CaseInsensitiveFullQNameCompare(nlTestSuite * inSuite, void * inContext)
235239
{
236240
{
237241
const QNamePart kName1[] = { "this", "is", "a", "test" };
238242
const QNamePart kName2[] = { "this", "IS", "a", "TEST" };
239-
EXPECT_EQ(FullQName(kName1), FullQName(kName2));
243+
NL_TEST_ASSERT(inSuite, FullQName(kName1) == FullQName(kName2));
240244
}
241245

242246
{
243247
const QNamePart kName1[] = { "THIS", "IS", "a", "tesT" };
244248
const QNamePart kName2[] = { "this", "IS", "A", "TEst" };
245-
EXPECT_EQ(FullQName(kName1), FullQName(kName2));
249+
NL_TEST_ASSERT(inSuite, FullQName(kName1) == FullQName(kName2));
246250
}
247251

248252
{
249253
const QNamePart kName1[] = { "THIS", "IS", "a", "test" };
250254
const QNamePart kName2[] = { "this", "IS", "A", "NEST" };
251-
EXPECT_NE(FullQName(kName1), FullQName(kName2));
255+
NL_TEST_ASSERT(inSuite, FullQName(kName1) != FullQName(kName2));
252256
}
253257

254258
{
255259
const QNamePart kName1[] = { "THIS", "IS", "a" };
256260
const QNamePart kName2[] = { "this", "IS", "A", "NEST" };
257-
EXPECT_NE(FullQName(kName1), FullQName(kName2));
261+
NL_TEST_ASSERT(inSuite, FullQName(kName1) != FullQName(kName2));
258262
}
259263

260264
{
261265
const QNamePart kName1[] = { "THIS", "IS", "a" };
262266
const QNamePart kName2[] = { "this", "IS" };
263-
EXPECT_NE(FullQName(kName1), FullQName(kName2));
267+
NL_TEST_ASSERT(inSuite, FullQName(kName1) != FullQName(kName2));
264268
}
265269

266270
{
267271
const QNamePart kName[] = { "this" };
268-
EXPECT_NE(FullQName(), FullQName(kName));
269-
EXPECT_NE(FullQName(kName), FullQName());
272+
NL_TEST_ASSERT(inSuite, FullQName() != FullQName(kName));
273+
NL_TEST_ASSERT(inSuite, FullQName(kName) != FullQName());
270274
}
271275
}
272276

273-
TEST (TestQName, SerializedCompare)
277+
void SerializedCompare(nlTestSuite * inSuite, void * inContext)
274278
{
275279
static const uint8_t kThisIsATest1[] = "\04this\02is\01a\04test\00";
276280
static const uint8_t kThisIsATest2[] = "\04ThIs\02is\01A\04tESt\00";
277281
static const uint8_t kThisIsDifferent[] = "\04this\02is\09different\00";
278282
static const uint8_t kThisIs[] = "\04this\02is";
279283

280-
EXPECT_EQ(AsSerializedQName(kThisIsATest1), AsSerializedQName(kThisIsATest1));
281-
EXPECT_EQ(AsSerializedQName(kThisIsATest2), AsSerializedQName(kThisIsATest2));
282-
EXPECT_EQ(AsSerializedQName(kThisIsATest1), AsSerializedQName(kThisIsATest2));
283-
EXPECT_NE(AsSerializedQName(kThisIsATest1), AsSerializedQName(kThisIsDifferent));
284-
EXPECT_NE(AsSerializedQName(kThisIsDifferent), AsSerializedQName(kThisIsATest1));
285-
EXPECT_NE(AsSerializedQName(kThisIsDifferent), AsSerializedQName(kThisIs));
286-
EXPECT_NE(AsSerializedQName(kThisIs), AsSerializedQName(kThisIsDifferent));
284+
NL_TEST_ASSERT(inSuite, AsSerializedQName(kThisIsATest1) == AsSerializedQName(kThisIsATest1));
285+
NL_TEST_ASSERT(inSuite, AsSerializedQName(kThisIsATest2) == AsSerializedQName(kThisIsATest2));
286+
NL_TEST_ASSERT(inSuite, AsSerializedQName(kThisIsATest1) == AsSerializedQName(kThisIsATest2));
287+
NL_TEST_ASSERT(inSuite, AsSerializedQName(kThisIsATest1) != AsSerializedQName(kThisIsDifferent));
288+
NL_TEST_ASSERT(inSuite, AsSerializedQName(kThisIsDifferent) != AsSerializedQName(kThisIsATest1));
289+
NL_TEST_ASSERT(inSuite, AsSerializedQName(kThisIsDifferent) != AsSerializedQName(kThisIs));
290+
NL_TEST_ASSERT(inSuite, AsSerializedQName(kThisIs) != AsSerializedQName(kThisIsDifferent));
287291

288292
// These items have back references and are "this.is.a.test"
289293
static const uint8_t kPtrItems[] = "\03abc\02is\01a\04test\00\04this\xc0\04";
290294
SerializedQNameIterator thisIsATestPtr(BytesRange(kPtrItems, kPtrItems + sizeof(kPtrItems)), kPtrItems + 15);
291295

292-
EXPECT_EQ(thisIsATestPtr, AsSerializedQName(kThisIsATest1));
293-
EXPECT_EQ(thisIsATestPtr, AsSerializedQName(kThisIsATest2));
294-
EXPECT_EQ(AsSerializedQName(kThisIsATest1), thisIsATestPtr);
295-
EXPECT_EQ(AsSerializedQName(kThisIsATest2), thisIsATestPtr);
296-
EXPECT_NE(thisIsATestPtr, AsSerializedQName(kThisIs));
297-
EXPECT_NE(AsSerializedQName(kThisIs), thisIsATestPtr);
296+
NL_TEST_ASSERT(inSuite, thisIsATestPtr == AsSerializedQName(kThisIsATest1));
297+
NL_TEST_ASSERT(inSuite, thisIsATestPtr == AsSerializedQName(kThisIsATest2));
298+
NL_TEST_ASSERT(inSuite, AsSerializedQName(kThisIsATest1) == thisIsATestPtr);
299+
NL_TEST_ASSERT(inSuite, AsSerializedQName(kThisIsATest2) == thisIsATestPtr);
300+
NL_TEST_ASSERT(inSuite, thisIsATestPtr != AsSerializedQName(kThisIs));
301+
NL_TEST_ASSERT(inSuite, AsSerializedQName(kThisIs) != thisIsATestPtr);
298302
}
299303

300304
} // namespace
305+
306+
// clang-format off
307+
static const nlTest sTests[] =
308+
{
309+
NL_TEST_DEF("IteratorTest", IteratorTest),
310+
NL_TEST_DEF("ErrorTest", ErrorTest),
311+
NL_TEST_DEF("Comparison", Comparison),
312+
NL_TEST_DEF("CaseInsensitiveSerializedCompare", CaseInsensitiveSerializedCompare),
313+
NL_TEST_DEF("CaseInsensitiveFullQNameCompare", CaseInsensitiveFullQNameCompare),
314+
NL_TEST_DEF("SerializedCompare", SerializedCompare),
315+
NL_TEST_DEF("InvalidReferencing", InvalidReferencing),
316+
317+
NL_TEST_SENTINEL()
318+
};
319+
// clang-format on
320+
321+
int TestQName()
322+
{
323+
// clang-format off
324+
nlTestSuite theSuite =
325+
{
326+
"QName",
327+
&sTests[0],
328+
nullptr,
329+
nullptr
330+
};
331+
// clang-format on
332+
333+
nlTestRunner(&theSuite, nullptr);
334+
335+
return (nlTestRunnerStats(&theSuite));
336+
}
337+
338+
CHIP_REGISTER_TEST_SUITE(TestQName)

‎src/lib/dnssd/minimal_mdns/core/tests/TestRecordWriter.cpp

+19-28
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,16 @@
1717
*/
1818

1919
#include <lib/dnssd/minimal_mdns/core/RecordWriter.h>
20-
//#include <lib/support/UnitTestRegistration.h>
20+
#include <lib/support/UnitTestRegistration.h>
2121

22-
//#include <nlunit-test.h>
23-
#include <gtest/gtest.h>
22+
#include <nlunit-test.h>
2423

2524
namespace {
2625

2726
using namespace mdns::Minimal;
2827
using namespace chip::Encoding::BigEndian;
2928

30-
31-
//void BasicWriteTest(nlTestSuite * inSuite, void * inContext)
32-
TEST (TestRecordWriter, BasicWriteTest)
29+
void BasicWriteTest(nlTestSuite * inSuite, void * inContext)
3330
{
3431
const QNamePart kName1[] = { "some", "name" };
3532
const QNamePart kName2[] = { "abc", "xyz", "here" };
@@ -55,12 +52,11 @@ TEST (TestRecordWriter, BasicWriteTest)
5552
};
5653
// clang-format on
5754

58-
EXPECT_EQ(output.Needed(),sizeof(expectedOutput));
59-
EXPECT_EQ(memcmp(dataBuffer, expectedOutput, sizeof(expectedOutput)), 0);
55+
NL_TEST_ASSERT(inSuite, output.Needed() == sizeof(expectedOutput));
56+
NL_TEST_ASSERT(inSuite, memcmp(dataBuffer, expectedOutput, sizeof(expectedOutput)) == 0);
6057
}
6158

62-
//void SimpleDedup(nlTestSuite * inSuite, void * inContext)
63-
TEST (TestRecordWriter, SimpleDedup)
59+
void SimpleDedup(nlTestSuite * inSuite, void * inContext)
6460
{
6561
const QNamePart kName1[] = { "some", "name" };
6662
const QNamePart kName2[] = { "other", "name" };
@@ -84,12 +80,11 @@ TEST (TestRecordWriter, SimpleDedup)
8480
};
8581
// clang-format on
8682

87-
EXPECT_EQ(output.Needed(), sizeof(expectedOutput));
88-
EXPECT_EQ(memcmp(dataBuffer, expectedOutput, sizeof(expectedOutput)), 0);
83+
NL_TEST_ASSERT(inSuite, output.Needed() == sizeof(expectedOutput));
84+
NL_TEST_ASSERT(inSuite, memcmp(dataBuffer, expectedOutput, sizeof(expectedOutput)) == 0);
8985
}
9086

91-
//void ComplexDedup(nlTestSuite * inSuite, void * inContext)
92-
TEST (TestRecordWriter, ComplexDedup)
87+
void ComplexDedup(nlTestSuite * inSuite, void * inContext)
9388
{
9489
const QNamePart kName1[] = { "some", "name" };
9590
const QNamePart kName2[] = { "other", "name" };
@@ -130,12 +125,11 @@ TEST (TestRecordWriter, ComplexDedup)
130125
};
131126
// clang-format on
132127

133-
EXPECT_EQ(output.Needed(), sizeof(expectedOutput));
134-
EXPECT_EQ(memcmp(dataBuffer, expectedOutput, sizeof(expectedOutput)), 0);
128+
NL_TEST_ASSERT(inSuite, output.Needed() == sizeof(expectedOutput));
129+
NL_TEST_ASSERT(inSuite, memcmp(dataBuffer, expectedOutput, sizeof(expectedOutput)) == 0);
135130
}
136131

137-
//void TonsOfReferences(nlTestSuite * inSuite, void * inContext)
138-
TEST (TestRecordWriter, TonsOfReferences)
132+
void TonsOfReferences(nlTestSuite * inSuite, void * inContext)
139133
{
140134
const QNamePart kName1[] = { "some", "name" };
141135
const QNamePart kName2[] = { "different", "name" };
@@ -165,26 +159,24 @@ TEST (TestRecordWriter, TonsOfReferences)
165159
writer.WriteQName(FullQName(kName2));
166160
}
167161

168-
EXPECT_TRUE(output.Fit());
169-
EXPECT_EQ(output.Needed(), size_t(423));
162+
NL_TEST_ASSERT(inSuite, output.Fit());
163+
NL_TEST_ASSERT(inSuite, output.Needed() == 423);
170164
}
171165

172166
} // namespace
173167

174168
// clang-format off
175-
176-
/* static const nlTest sTests[] =
169+
static const nlTest sTests[] =
177170
{
178171
NL_TEST_DEF("BasicWriteTest", BasicWriteTest),
179172
NL_TEST_DEF("SimpleDedup", SimpleDedup),
180173
NL_TEST_DEF("ComplexDedup", ComplexDedup),
181174
NL_TEST_DEF("TonsOfReferences", TonsOfReferences),
182175

183176
NL_TEST_SENTINEL()
184-
}; */
185-
177+
};
186178
// clang-format on
187-
/*
179+
188180
int TestRecordWriter()
189181
{
190182
// clang-format off
@@ -200,7 +192,6 @@ int TestRecordWriter()
200192
nlTestRunner(&theSuite, nullptr);
201193

202194
return (nlTestRunnerStats(&theSuite));
203-
}*/
204-
/*
195+
}
196+
205197
CHIP_REGISTER_TEST_SUITE(TestRecordWriter)
206-
*/

0 commit comments

Comments
 (0)
Please sign in to comment.