Skip to content

Commit bcdef5e

Browse files
committed
Revert "converting 3 minimal mDNS unit tests from NL_unit to pw_unit"
This reverts commit 4271f3f.
1 parent 801e3dc commit bcdef5e

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)

0 commit comments

Comments
 (0)