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