13
13
* See the License for the specific language governing permissions and
14
14
* limitations under the License.
15
15
*/
16
- #include < lib/address_resolve/AddressResolve_DefaultImpl.h>
17
-
18
- #include < lib/support/UnitTestRegistration.h>
16
+ #include < gtest/gtest.h>
19
17
20
- #include < nlunit-test .h>
18
+ #include < lib/address_resolve/AddressResolve_DefaultImpl .h>
21
19
22
20
using namespace chip ;
23
21
using namespace chip ::AddressResolve;
@@ -66,7 +64,7 @@ Transport::PeerAddress GetAddressWithHighScore(uint16_t port = CHIP_PORT, Inet::
66
64
return Transport::PeerAddress::UDP (ipAddress, port, interfaceId);
67
65
}
68
66
69
- void TestLookupResult (nlTestSuite * inSuite, void * inContext )
67
+ TEST (TestAddressResolveDefaultImpl, TestLookupResult )
70
68
{
71
69
ResolveResult lowResult;
72
70
lowResult.address = GetAddressWithLowScore ();
@@ -83,8 +81,8 @@ void TestLookupResult(nlTestSuite * inSuite, void * inContext)
83
81
IpScore mediumScore = ScoreIpAddress (mediumResult.address .GetIPAddress (), Inet::InterfaceId::Null ());
84
82
IpScore highScore = ScoreIpAddress (highResult.address .GetIPAddress (), Inet::InterfaceId::Null ());
85
83
86
- NL_TEST_ASSERT (inSuite, to_underlying (lowScore) < to_underlying (mediumScore));
87
- NL_TEST_ASSERT (inSuite, to_underlying (mediumScore) < to_underlying (highScore));
84
+ EXPECT_LT ( to_underlying (lowScore), to_underlying (mediumScore));
85
+ EXPECT_LT ( to_underlying (mediumScore), to_underlying (highScore));
88
86
89
87
ResolveResult outResult;
90
88
@@ -95,20 +93,20 @@ void TestLookupResult(nlTestSuite * inSuite, void * inContext)
95
93
handle.ResetForLookup (now, request);
96
94
97
95
// Check that no result exists.
98
- NL_TEST_ASSERT (inSuite, ! handle.HasLookupResult ());
96
+ EXPECT_FALSE ( handle.HasLookupResult ());
99
97
100
98
// Fill a single slot.
101
99
handle.LookupResult (lowResult);
102
100
103
101
// Check that a result exists.
104
- NL_TEST_ASSERT (inSuite, handle.HasLookupResult ());
102
+ EXPECT_TRUE ( handle.HasLookupResult ());
105
103
106
104
// Check that the result match what has been inserted.
107
105
outResult = handle.TakeLookupResult ();
108
- NL_TEST_ASSERT (inSuite, lowResult.address == outResult.address );
106
+ EXPECT_EQ ( lowResult.address , outResult.address );
109
107
110
108
// Check that the result has been consumed properly
111
- NL_TEST_ASSERT (inSuite, ! handle.HasLookupResult ());
109
+ EXPECT_FALSE ( handle.HasLookupResult ());
112
110
113
111
handle.ResetForLookup (now, request);
114
112
@@ -121,13 +119,13 @@ void TestLookupResult(nlTestSuite * inSuite, void * inContext)
121
119
// Read back all results and validate that they match the input.
122
120
for (auto i = 0 ; i < kNumberOfAvailableSlots ; i++)
123
121
{
124
- NL_TEST_ASSERT (inSuite, handle.HasLookupResult ());
122
+ EXPECT_TRUE ( handle.HasLookupResult ());
125
123
outResult = handle.TakeLookupResult ();
126
- NL_TEST_ASSERT (inSuite, lowResult.address == outResult.address );
124
+ EXPECT_EQ ( lowResult.address , outResult.address );
127
125
}
128
126
129
127
// Check that the results has been consumed properly.
130
- NL_TEST_ASSERT (inSuite, ! handle.HasLookupResult ());
128
+ EXPECT_FALSE ( handle.HasLookupResult ());
131
129
132
130
handle.ResetForLookup (now, request);
133
131
@@ -140,13 +138,13 @@ void TestLookupResult(nlTestSuite * inSuite, void * inContext)
140
138
// Read back all results and validate that they match the input.
141
139
for (auto i = 0 ; i < kNumberOfAvailableSlots ; i++)
142
140
{
143
- NL_TEST_ASSERT (inSuite, handle.HasLookupResult ());
141
+ EXPECT_TRUE ( handle.HasLookupResult ());
144
142
outResult = handle.TakeLookupResult ();
145
- NL_TEST_ASSERT (inSuite, lowResult.address == outResult.address );
143
+ EXPECT_EQ ( lowResult.address , outResult.address );
146
144
}
147
145
148
146
// Check that the results has been consumed properly.
149
- NL_TEST_ASSERT (inSuite, ! handle.HasLookupResult ());
147
+ EXPECT_FALSE ( handle.HasLookupResult ());
150
148
151
149
handle.ResetForLookup (now, request);
152
150
@@ -158,9 +156,9 @@ void TestLookupResult(nlTestSuite * inSuite, void * inContext)
158
156
159
157
// Add a result with a medium score and ensure it sits at the top.
160
158
handle.LookupResult (mediumResult);
161
- NL_TEST_ASSERT (inSuite, handle.HasLookupResult ());
159
+ EXPECT_TRUE ( handle.HasLookupResult ());
162
160
outResult = handle.TakeLookupResult ();
163
- NL_TEST_ASSERT (inSuite, mediumResult.address == outResult.address );
161
+ EXPECT_EQ ( mediumResult.address , outResult.address );
164
162
165
163
handle.ResetForLookup (now, request);
166
164
@@ -173,45 +171,30 @@ void TestLookupResult(nlTestSuite * inSuite, void * inContext)
173
171
// Add a result with a medium score and a result with a high score and ensure the result with the high score comes first.
174
172
handle.LookupResult (mediumResult);
175
173
handle.LookupResult (highResult);
176
- NL_TEST_ASSERT (inSuite, handle.HasLookupResult ());
174
+ EXPECT_TRUE ( handle.HasLookupResult ());
177
175
outResult = handle.TakeLookupResult ();
178
- NL_TEST_ASSERT (inSuite, highResult.address == outResult.address );
176
+ EXPECT_EQ ( highResult.address , outResult.address );
179
177
180
178
if (kNumberOfAvailableSlots > 1 )
181
179
{
182
180
// Ensure the second result is the medium result.
183
- NL_TEST_ASSERT (inSuite, handle.HasLookupResult ());
181
+ EXPECT_TRUE ( handle.HasLookupResult ());
184
182
outResult = handle.TakeLookupResult ();
185
- NL_TEST_ASSERT (inSuite, mediumResult.address == outResult.address );
183
+ EXPECT_EQ ( mediumResult.address , outResult.address );
186
184
}
187
185
188
186
if (kNumberOfAvailableSlots > 2 )
189
187
{
190
188
// Ensure that all the other results are low results.
191
189
for (auto i = 2 ; i < kNumberOfAvailableSlots ; i++)
192
190
{
193
- NL_TEST_ASSERT (inSuite, handle.HasLookupResult ());
191
+ EXPECT_TRUE ( handle.HasLookupResult ());
194
192
outResult = handle.TakeLookupResult ();
195
- NL_TEST_ASSERT (inSuite, lowResult.address == outResult.address );
193
+ EXPECT_EQ ( lowResult.address , outResult.address );
196
194
}
197
195
}
198
196
199
197
// Check that the results has been consumed properly.
200
- NL_TEST_ASSERT (inSuite, ! handle.HasLookupResult ());
198
+ EXPECT_FALSE ( handle.HasLookupResult ());
201
199
}
202
-
203
- const nlTest sTests [] = {
204
- NL_TEST_DEF (" TestLookupResult" , TestLookupResult), //
205
- NL_TEST_SENTINEL () //
206
- };
207
-
208
200
} // namespace
209
-
210
- int TestAddressResolve_DefaultImpl ()
211
- {
212
- nlTestSuite theSuite = { " AddressResolve_DefaultImpl" , sTests , nullptr , nullptr };
213
- nlTestRunner (&theSuite, nullptr );
214
- return nlTestRunnerStats (&theSuite);
215
- }
216
-
217
- CHIP_REGISTER_TEST_SUITE (TestAddressResolve_DefaultImpl)
0 commit comments