15
15
* limitations under the License.
16
16
*/
17
17
#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>
19
21
20
22
namespace {
21
23
@@ -36,30 +38,28 @@ class AutoFreeBuffer
36
38
void * mBuffer ;
37
39
};
38
40
39
-
40
- TEST (TestFlatAllocatedQName, TestFlatAllocatedQName)
41
+ void TestFlatAllocatedQName (nlTestSuite * inSuite, void * inContext)
41
42
{
42
43
AutoFreeBuffer buffer (128 );
43
44
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 ));
45
46
46
47
{
47
48
FullQName built = FlatAllocatedQName::Build (buffer.Buffer (), " some" , " test" );
48
49
const QNamePart expected[] = { " some" , " test" };
49
50
50
- EXPECT_EQ ( FullQName (expected), built);
51
+ NL_TEST_ASSERT (inSuite, FullQName (expected) == built);
51
52
}
52
53
53
54
{
54
55
FullQName built = FlatAllocatedQName::Build (buffer.Buffer (), " 1" , " 2" , " 3" );
55
56
const QNamePart expected[] = { " 1" , " 2" , " 3" };
56
57
57
- EXPECT_EQ ( FullQName (expected), built);
58
+ NL_TEST_ASSERT (inSuite, FullQName (expected) == built);
58
59
}
59
60
}
60
61
61
-
62
- TEST (TestFlatAllocatedQName, SizeCompare)
62
+ void SizeCompare (nlTestSuite * inSuite, void * inContext)
63
63
{
64
64
static const char kThis [] = " this" ;
65
65
static const char kIs [] = " is" ;
@@ -79,22 +79,23 @@ TEST (TestFlatAllocatedQName, SizeCompare)
79
79
80
80
const size_t kTestStorageSize = FlatAllocatedQName::RequiredStorageSize (kThis , kIs , kA , kTest );
81
81
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 ));
86
86
87
87
// 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 ));
89
89
// 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 ));
91
91
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 ));
94
96
}
95
97
96
-
97
- TEST (TestFlatAllocatedQName, BuildCompare)
98
+ void BuildCompare (nlTestSuite * inSuite, void * inContext)
98
99
{
99
100
static const char kThis [] = " this" ;
100
101
static const char kIs [] = " is" ;
@@ -110,15 +111,33 @@ TEST (TestFlatAllocatedQName, BuildCompare)
110
111
111
112
const FullQName kTestQName = FlatAllocatedQName::Build (storage, kThis , kIs , kA , kTest );
112
113
113
- EXPECT_EQ ( kTestQName , FlatAllocatedQName::BuildFromArray (storage, kSameArraySameSize , 4 ));
114
+ NL_TEST_ASSERT (inSuite, kTestQName == FlatAllocatedQName::BuildFromArray (storage, kSameArraySameSize , 4 ));
114
115
115
116
// 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 ));
117
118
// 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 ));
119
120
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 ));
122
125
}
123
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
+
124
134
} // 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