mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2025-05-11 21:53:57 +00:00
Cleanup test code
This commit is contained in:
parent
0b49065583
commit
d1f903fc58
23
test/test.cc
23
test/test.cc
@ -208,7 +208,7 @@ protected:
|
|||||||
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
||||||
, svr_(SERVER_CERT_FILE, SERVER_PRIVATE_KEY_FILE)
|
, svr_(SERVER_CERT_FILE, SERVER_PRIVATE_KEY_FILE)
|
||||||
#endif
|
#endif
|
||||||
, up_(false) {}
|
{}
|
||||||
|
|
||||||
virtual void SetUp() {
|
virtual void SetUp() {
|
||||||
svr_.set_base_dir("./www");
|
svr_.set_base_dir("./www");
|
||||||
@ -272,7 +272,6 @@ protected:
|
|||||||
persons_["john"] = "programmer";
|
persons_["john"] = "programmer";
|
||||||
|
|
||||||
t_ = thread([&](){
|
t_ = thread([&](){
|
||||||
up_ = true;
|
|
||||||
svr_.listen(HOST, PORT);
|
svr_.listen(HOST, PORT);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -295,7 +294,6 @@ protected:
|
|||||||
Server svr_;
|
Server svr_;
|
||||||
#endif
|
#endif
|
||||||
thread t_;
|
thread t_;
|
||||||
bool up_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(ServerTest, GetMethod200)
|
TEST_F(ServerTest, GetMethod200)
|
||||||
@ -589,31 +587,25 @@ protected:
|
|||||||
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
||||||
, svr_(SERVER_CERT_FILE, SERVER_PRIVATE_KEY_FILE)
|
, svr_(SERVER_CERT_FILE, SERVER_PRIVATE_KEY_FILE)
|
||||||
#endif
|
#endif
|
||||||
, up_(false) {}
|
{}
|
||||||
|
|
||||||
virtual void SetUp() {
|
virtual void SetUp() {
|
||||||
svr_.get("/hi", [&](const Request& /*req*/, Response& res) {
|
svr_.get("/hi", [&](const Request& /*req*/, Response& res) {
|
||||||
res.set_content("Hello World!", "text/plain");
|
res.set_content("Hello World!", "text/plain");
|
||||||
});
|
});
|
||||||
|
|
||||||
svr_.get("/stop", [&](const Request& /*req*/, Response& /*res*/) {
|
t_ = thread([&](){
|
||||||
svr_.stop();
|
|
||||||
});
|
|
||||||
|
|
||||||
f_ = async([&](){
|
|
||||||
up_ = true;
|
|
||||||
svr_.listen(nullptr, PORT, AI_PASSIVE);
|
svr_.listen(nullptr, PORT, AI_PASSIVE);
|
||||||
});
|
});
|
||||||
|
|
||||||
while (!up_) {
|
while (!svr_.is_running()) {
|
||||||
msleep(1);
|
msleep(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void TearDown() {
|
virtual void TearDown() {
|
||||||
//svr_.stop(); // NOTE: This causes dead lock on Windows.
|
svr_.stop();
|
||||||
cli_.get("/stop");
|
t_.join();
|
||||||
f_.get();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
||||||
@ -623,8 +615,7 @@ protected:
|
|||||||
Client cli_;
|
Client cli_;
|
||||||
Server svr_;
|
Server svr_;
|
||||||
#endif
|
#endif
|
||||||
future<void> f_;
|
thread t_;
|
||||||
bool up_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(ServerTestWithAI_PASSIVE, GetMethod200)
|
TEST_F(ServerTestWithAI_PASSIVE, GetMethod200)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user