Skip to content

Commit

Permalink
test improve
Browse files Browse the repository at this point in the history
  • Loading branch information
abtink committed Sep 16, 2023
1 parent 98e4881 commit 58f4365
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions tests/mdns/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,23 @@ void PublishServiceSubTypes(void *aContext)
[](otbrError aError) { SuccessOrDie(aError, "ServiceWithSubTypes._meshcop._udp"); });
}

typedef void (*TestRunner)(void *aContext, Mdns::Publisher::State aState);

otbrError Test(TestRunner aTestRunner)
{
otbrError error = OTBR_ERROR_NONE;

Mdns::Publisher *pub = Mdns::Publisher::Create(
[aTestRunner](Mdns::Publisher::State aState) { aTestRunner(&sContext, aState); });
sContext.mPublisher = pub;
SuccessOrExit(error = pub->Start());
RunMainloop();

exit:
Mdns::Publisher::Destroy(pub);
return error;
}

otbrError TestSingleServiceWithCustomHost(void)
{
otbrError error = OTBR_ERROR_NONE;
Expand Down Expand Up @@ -547,13 +564,13 @@ int main(int argc, char *argv[])
switch (argv[1][1])
{
case 'c':
ret = TestSingleServiceWithCustomHost();
ret = Test(PublishSingleServiceWithCustomHost);
break;
case 'e':
ret = TestSingleServiceWithEmptyName();
ret = Test(PublishSingleServiceWithEmptyName);
break;
default:
ret = TestSingleService();
ret = Test(PublishSingleService);
break;
}
break;
Expand Down

0 comments on commit 58f4365

Please sign in to comment.