From 574bf8fe02b4bc465ac257dc6db9a4ec355cb6a8 Mon Sep 17 00:00:00 2001 From: Andrew Beltrano Date: Fri, 19 Jan 2024 17:41:01 +0000 Subject: [PATCH] Update 'netremote-test-unit' tests. --- tests/unit/CMakeLists.txt | 3 +- tests/unit/TestNetRemoteServer.cxx | 41 +++++++++++++---------- tests/unit/TestNetRemoteServiceClient.cxx | 21 ++++++++---- 3 files changed, 40 insertions(+), 25 deletions(-) diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index 6b87e9f9..5d75b34c 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -16,10 +16,11 @@ target_sources(${PROJECT_NAME}-test-unit target_link_libraries(${PROJECT_NAME}-test-unit PRIVATE + ${PROJECT_NAME}-server Catch2::Catch2WithMain gRPC::grpc++ magic_enum::magic_enum - ${PROJECT_NAME}-server + wifi-test-helpers ) catch_discover_tests(${PROJECT_NAME}-test-unit) diff --git a/tests/unit/TestNetRemoteServer.cxx b/tests/unit/TestNetRemoteServer.cxx index b7fa6ec2..7bcc6449 100644 --- a/tests/unit/TestNetRemoteServer.cxx +++ b/tests/unit/TestNetRemoteServer.cxx @@ -1,4 +1,5 @@ +#include #include #include @@ -6,17 +7,23 @@ #include #include #include +#include #include "TestNetRemoteCommon.hxx" +using Microsoft::Net::Remote::Test::EstablishClientConnections; +using Microsoft::Net::Remote::Test::RemoteServiceAddressHttp; +using Microsoft::Net::Remote::Test::RemoteServiceConnectionTimeout; +using Microsoft::Net::Wifi::Test::AccessPointFactoryTest; + TEST_CASE("Create a NetRemoteServer instance", "[basic][rpc][remote]") { using namespace Microsoft::Net::Remote; using namespace Microsoft::Net::Wifi; NetRemoteServerConfiguration Configuration{ - .ServerAddress = Test::RemoteServiceAddressHttp, - .AccessPointManager = AccessPointManager::Create(), + .ServerAddress = RemoteServiceAddressHttp, + .AccessPointManager = AccessPointManager::Create(std::make_unique()), }; SECTION("Create doesn't cause a crash") @@ -32,8 +39,8 @@ TEST_CASE("Destroy a NetRemoteServer instance", "[basic][rpc][remote]") using namespace Microsoft::Net::Wifi; NetRemoteServerConfiguration Configuration{ - .ServerAddress = Test::RemoteServiceAddressHttp, - .AccessPointManager = AccessPointManager::Create(), + .ServerAddress = RemoteServiceAddressHttp, + .AccessPointManager = AccessPointManager::Create(std::make_unique()), }; std::optional server{ Configuration }; @@ -50,7 +57,7 @@ TEST_CASE("Destroy a NetRemoteServer instance", "[basic][rpc][remote]") const auto numClientsToCreate = Catch::Generators::range(1, 2); // Establish client connections to the server. - const auto clients = Test::EstablishClientConnections(static_cast(numClientsToCreate.get())); + const auto clients = EstablishClientConnections(static_cast(numClientsToCreate.get())); REQUIRE_NOTHROW(server.reset()); } @@ -63,8 +70,8 @@ TEST_CASE("NetRemoteServer can be reached", "[basic][rpc][remote]") using namespace Microsoft::Net::Wifi; NetRemoteServerConfiguration Configuration{ - .ServerAddress = Test::RemoteServiceAddressHttp, - .AccessPointManager = AccessPointManager::Create(), + .ServerAddress = RemoteServiceAddressHttp, + .AccessPointManager = AccessPointManager::Create(std::make_unique()), }; NetRemoteServer server{ Configuration }; @@ -72,10 +79,10 @@ TEST_CASE("NetRemoteServer can be reached", "[basic][rpc][remote]") SECTION("Can be reached using insecure channel") { - auto channel = grpc::CreateChannel(Test::RemoteServiceAddressHttp, grpc::InsecureChannelCredentials()); + auto channel = grpc::CreateChannel(RemoteServiceAddressHttp, grpc::InsecureChannelCredentials()); auto client = NetRemote::NewStub(channel); - REQUIRE(channel->WaitForConnected(std::chrono::system_clock::now() + Test::RemoteServiceConnectionTimeout)); + REQUIRE(channel->WaitForConnected(std::chrono::system_clock::now() + RemoteServiceConnectionTimeout)); } } @@ -86,8 +93,8 @@ TEST_CASE("NetRemoteServer shuts down correctly", "[basic][rpc][remote]") using namespace Microsoft::Net::Wifi; NetRemoteServerConfiguration Configuration{ - .ServerAddress = Test::RemoteServiceAddressHttp, - .AccessPointManager = AccessPointManager::Create(), + .ServerAddress = RemoteServiceAddressHttp, + .AccessPointManager = AccessPointManager::Create(std::make_unique()), }; NetRemoteServer server{ Configuration }; @@ -104,7 +111,7 @@ TEST_CASE("NetRemoteServer shuts down correctly", "[basic][rpc][remote]") const auto numClientsToCreate = Catch::Generators::range(1, 3); // Establish client connections to the server. - const auto clients = Test::EstablishClientConnections(static_cast(numClientsToCreate.get())); + const auto clients = EstablishClientConnections(static_cast(numClientsToCreate.get())); // Stop the server. REQUIRE_NOTHROW(server.Stop()); @@ -127,7 +134,7 @@ TEST_CASE("NetRemoteServer shuts down correctly", "[basic][rpc][remote]") const auto numClientsToCreate = Catch::Generators::range(1, 3); // Establish client connections to the server. - const auto clients = Test::EstablishClientConnections(static_cast(numClientsToCreate.get())); + const auto clients = EstablishClientConnections(static_cast(numClientsToCreate.get())); REQUIRE_NOTHROW(server.Stop()); REQUIRE(server.GetGrpcServer() == nullptr); @@ -141,8 +148,8 @@ TEST_CASE("NetRemoteServer can be cycled through run/stop states", "[basic][rpc] using namespace Microsoft::Net::Wifi; NetRemoteServerConfiguration Configuration{ - .ServerAddress = Test::RemoteServiceAddressHttp, - .AccessPointManager = AccessPointManager::Create(), + .ServerAddress = RemoteServiceAddressHttp, + .AccessPointManager = AccessPointManager::Create(std::make_unique()), }; NetRemoteServer server{ Configuration }; @@ -156,9 +163,9 @@ TEST_CASE("NetRemoteServer can be cycled through run/stop states", "[basic][rpc] REQUIRE_NOTHROW(server.Stop()); REQUIRE_NOTHROW(server.Run()); - auto channel = grpc::CreateChannel(Test::RemoteServiceAddressHttp, grpc::InsecureChannelCredentials()); + auto channel = grpc::CreateChannel(RemoteServiceAddressHttp, grpc::InsecureChannelCredentials()); auto client = NetRemote::NewStub(channel); - REQUIRE(channel->WaitForConnected(std::chrono::system_clock::now() + Test::RemoteServiceConnectionTimeout)); + REQUIRE(channel->WaitForConnected(std::chrono::system_clock::now() + RemoteServiceConnectionTimeout)); } } } diff --git a/tests/unit/TestNetRemoteServiceClient.cxx b/tests/unit/TestNetRemoteServiceClient.cxx index b5bf6136..61cd3dff 100644 --- a/tests/unit/TestNetRemoteServiceClient.cxx +++ b/tests/unit/TestNetRemoteServiceClient.cxx @@ -1,8 +1,9 @@ #include #include -#include +#include #include +#include #include #include @@ -10,9 +11,13 @@ #include #include #include +#include #include "TestNetRemoteCommon.hxx" +using Microsoft::Net::Remote::Test::RemoteServiceAddressHttp; +using Microsoft::Net::Wifi::Test::AccessPointFactoryTest; + TEST_CASE("WifiEnumerateAccessPoints API", "[basic][rpc][client][remote]") { using namespace Microsoft::Net::Remote; @@ -20,15 +25,17 @@ TEST_CASE("WifiEnumerateAccessPoints API", "[basic][rpc][client][remote]") using namespace Microsoft::Net::Remote::Wifi; using namespace Microsoft::Net::Wifi; + using Microsoft::Net::Remote::Test::RemoteServiceAddressHttp; + NetRemoteServerConfiguration Configuration{ - .ServerAddress = Test::RemoteServiceAddressHttp, - .AccessPointManager = AccessPointManager::Create(), + .ServerAddress = RemoteServiceAddressHttp, + .AccessPointManager = AccessPointManager::Create(std::make_unique()), }; NetRemoteServer server{ Configuration }; server.Run(); - auto channel = grpc::CreateChannel(Test::RemoteServiceAddressHttp, grpc::InsecureChannelCredentials()); + auto channel = grpc::CreateChannel(RemoteServiceAddressHttp, grpc::InsecureChannelCredentials()); auto client = NetRemote::NewStub(channel); SECTION("Can be called") @@ -71,14 +78,14 @@ TEST_CASE("WifiAccessPointEnable API", "[basic][rpc][client][remote]") constexpr auto SsidName{ "TestWifiAccessPointEnable" }; NetRemoteServerConfiguration Configuration{ - .ServerAddress = Test::RemoteServiceAddressHttp, - .AccessPointManager = AccessPointManager::Create(), + .ServerAddress = RemoteServiceAddressHttp, + .AccessPointManager = AccessPointManager::Create(std::make_unique()), }; NetRemoteServer server{ Configuration }; server.Run(); - auto channel = grpc::CreateChannel(Test::RemoteServiceAddressHttp, grpc::InsecureChannelCredentials()); + auto channel = grpc::CreateChannel(RemoteServiceAddressHttp, grpc::InsecureChannelCredentials()); auto client = NetRemote::NewStub(channel); SECTION("Can be called")