Skip to content

Commit

Permalink
Update 'netremote-test-unit' tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
abeltrano committed Jan 19, 2024
1 parent 6a01ff0 commit 574bf8f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 25 deletions.
3 changes: 2 additions & 1 deletion tests/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
41 changes: 24 additions & 17 deletions tests/unit/TestNetRemoteServer.cxx
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@

#include <memory>
#include <optional>

#include <catch2/catch_test_macros.hpp>
#include <catch2/generators/catch_generators_range.hpp>
#include <grpcpp/create_channel.h>
#include <microsoft/net/remote/NetRemoteServer.hxx>
#include <microsoft/net/remote/protocol/NetRemoteService.grpc.pb.h>
#include <microsoft/net/wifi/test/AccessPointTest.hxx>

#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<AccessPointFactoryTest>()),
};

SECTION("Create doesn't cause a crash")
Expand All @@ -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<AccessPointFactoryTest>()),
};

std::optional<NetRemoteServer> server{ Configuration };
Expand All @@ -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<std::size_t>(numClientsToCreate.get()));
const auto clients = EstablishClientConnections(static_cast<std::size_t>(numClientsToCreate.get()));

REQUIRE_NOTHROW(server.reset());
}
Expand All @@ -63,19 +70,19 @@ 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<AccessPointFactoryTest>()),
};

NetRemoteServer server{ Configuration };
server.Run();

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));
}
}

Expand All @@ -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<AccessPointFactoryTest>()),
};

NetRemoteServer server{ Configuration };
Expand All @@ -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<std::size_t>(numClientsToCreate.get()));
const auto clients = EstablishClientConnections(static_cast<std::size_t>(numClientsToCreate.get()));

// Stop the server.
REQUIRE_NOTHROW(server.Stop());
Expand All @@ -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<std::size_t>(numClientsToCreate.get()));
const auto clients = EstablishClientConnections(static_cast<std::size_t>(numClientsToCreate.get()));

REQUIRE_NOTHROW(server.Stop());
REQUIRE(server.GetGrpcServer() == nullptr);
Expand All @@ -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<AccessPointFactoryTest>()),
};

NetRemoteServer server{ Configuration };
Expand All @@ -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));
}
}
}
21 changes: 14 additions & 7 deletions tests/unit/TestNetRemoteServiceClient.cxx
Original file line number Diff line number Diff line change
@@ -1,34 +1,41 @@

#include <format>
#include <iostream>
#include <string>
#include <memory>
#include <string_view>
#include <string>

#include <catch2/catch_test_macros.hpp>
#include <grpcpp/create_channel.h>
#include <magic_enum.hpp>
#include <microsoft/net/remote/NetRemoteServer.hxx>
#include <microsoft/net/remote/protocol/NetRemoteService.grpc.pb.h>
#include <microsoft/net/wifi/AccessPointManager.hxx>
#include <microsoft/net/wifi/test/AccessPointTest.hxx>

#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;
using namespace Microsoft::Net::Remote::Service;
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<AccessPointFactoryTest>()),
};

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")
Expand Down Expand Up @@ -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<AccessPointFactoryTest>()),
};

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")
Expand Down

0 comments on commit 574bf8f

Please sign in to comment.