mirror of
https://github.com/falk-werner/webfuse-provider
synced 2024-10-27 20:44:10 +00:00
chore: refactored test
This commit is contained in:
parent
384de32bf5
commit
4b418a45d4
@ -15,30 +15,15 @@ using testing::_;
|
||||
namespace
|
||||
{
|
||||
|
||||
struct Context
|
||||
class ClientProtocolTest: public ::testing::Test
|
||||
{
|
||||
lws_context * context;
|
||||
std::atomic<bool> isShutdownRequested;
|
||||
};
|
||||
|
||||
void run(Context * context)
|
||||
{
|
||||
while (!context->isShutdownRequested)
|
||||
protected:
|
||||
void SetUp()
|
||||
{
|
||||
lws_service(context->context, 100);
|
||||
}
|
||||
}
|
||||
server = new FakeAdapterServer(54321);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
TEST(client_protocol, connect)
|
||||
{
|
||||
FakeAdapterServer server(54321);
|
||||
|
||||
wfp_client_config * config = wfp_client_config_create();
|
||||
wfp_client_protocol * protocol = wfp_client_protocol_create(config);
|
||||
config = wfp_client_config_create();
|
||||
protocol = wfp_client_protocol_create(config);
|
||||
|
||||
struct lws_protocols protocols[2];
|
||||
memset(protocols, 0, sizeof(struct lws_protocols) * 2);
|
||||
@ -52,21 +37,50 @@ TEST(client_protocol, connect)
|
||||
info.uid = -1;
|
||||
info.gid = -1;
|
||||
|
||||
struct lws_context * context = lws_create_context(&info);
|
||||
context = lws_create_context(&info);
|
||||
wfp_client_protocol_connect(protocol, context, "ws://localhost:54321/");
|
||||
|
||||
Context ctx;
|
||||
ctx.context = context;
|
||||
ctx.isShutdownRequested = false;
|
||||
std::thread client_thread(run, &ctx);
|
||||
isShutdownRequested = false;
|
||||
thread = std::thread(run, this);
|
||||
}
|
||||
|
||||
server.waitForConnection();
|
||||
|
||||
ctx.isShutdownRequested = true;
|
||||
client_thread.join();
|
||||
void TearDown()
|
||||
{
|
||||
isShutdownRequested = true;
|
||||
thread.join();
|
||||
|
||||
lws_context_destroy(context);
|
||||
|
||||
wfp_client_protocol_dispose(protocol);
|
||||
wfp_client_config_dispose(config);
|
||||
|
||||
delete server;
|
||||
}
|
||||
|
||||
FakeAdapterServer * server;
|
||||
|
||||
private:
|
||||
static void run(ClientProtocolTest * self)
|
||||
{
|
||||
while (!self->isShutdownRequested)
|
||||
{
|
||||
lws_service(self->context, 100);
|
||||
}
|
||||
}
|
||||
|
||||
wfp_client_config * config;
|
||||
wfp_client_protocol * protocol;
|
||||
std::thread thread;
|
||||
std::atomic<bool> isShutdownRequested;
|
||||
lws_context * context;
|
||||
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
TEST_F(ClientProtocolTest, connect)
|
||||
{
|
||||
server->waitForConnection();
|
||||
}
|
Loading…
Reference in New Issue
Block a user