14
14
* See the License for the specific language governing permissions and
15
15
* limitations under the License.
16
16
*/
17
- #include < lib/dnssd/minimal_mdns/core/FlatAllocatedQName.h>
18
- #include < lib/support/UnitTestRegistration.h>
17
+ #include < gtest/gtest.h>
19
18
20
- #include < nlunit-test .h>
19
+ #include < lib/dnssd/minimal_mdns/core/FlatAllocatedQName .h>
21
20
22
21
namespace {
23
22
@@ -38,28 +37,28 @@ class AutoFreeBuffer
38
37
void * mBuffer ;
39
38
};
40
39
41
- void TestFlatAllocatedQName (nlTestSuite * inSuite, void * inContext )
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
+ TEST (TestFlatAllocatedQName, SizeCompare )
63
62
{
64
63
static const char kThis [] = " this" ;
65
64
static const char kIs [] = " is" ;
@@ -79,23 +78,22 @@ void SizeCompare(nlTestSuite * inSuite, void * inContext)
79
78
80
79
const size_t kTestStorageSize = FlatAllocatedQName::RequiredStorageSize (kThis , kIs , kA , kTest );
81
80
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 ));
86
85
87
86
// 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 ));
89
88
// 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 ));
91
90
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 ));
96
94
}
97
95
98
- void BuildCompare (nlTestSuite * inSuite, void * inContext )
96
+ TEST (TestFlatAllocatedQName, BuildCompare )
99
97
{
100
98
static const char kThis [] = " this" ;
101
99
static const char kIs [] = " is" ;
@@ -111,33 +109,15 @@ void BuildCompare(nlTestSuite * inSuite, void * inContext)
111
109
112
110
const FullQName kTestQName = FlatAllocatedQName::Build (storage, kThis , kIs , kA , kTest );
113
111
114
- NL_TEST_ASSERT (inSuite, kTestQName == FlatAllocatedQName::BuildFromArray (storage, kSameArraySameSize , 4 ));
112
+ EXPECT_EQ ( kTestQName , FlatAllocatedQName::BuildFromArray (storage, kSameArraySameSize , 4 ));
115
113
116
114
// 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 ));
118
116
// 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 ));
120
118
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 ));
125
122
}
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
-
134
123
} // 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