From a16d2be9bb501ae7e40f180e243dbd8b03df04fd Mon Sep 17 00:00:00 2001 From: Moritz W Date: Tue, 22 May 2018 13:54:46 +0200 Subject: [PATCH] Fix unittests for HueCommandAPI --- hueplusplus/test/test_HueCommandAPI.cpp | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/hueplusplus/test/test_HueCommandAPI.cpp b/hueplusplus/test/test_HueCommandAPI.cpp index 894afa1..b3633a7 100644 --- a/hueplusplus/test/test_HueCommandAPI.cpp +++ b/hueplusplus/test/test_HueCommandAPI.cpp @@ -30,35 +30,35 @@ TEST(HueCommandAPI, PUTRequest) using namespace ::testing; std::shared_ptr httpHandler = std::make_shared(); - HueCommandAPI api(bridge_ip, bridge_username, httpHandler); + HueCommandAPI api(getBridgeIp(), getBridgeUsername(), httpHandler); Json::Value request; Json::Value result = Json::objectValue; result["ok"] = true; //empty path { - EXPECT_CALL(*httpHandler, PUTJson("/api/" + bridge_username, request, bridge_ip, 80)).WillOnce(Return(result)); + EXPECT_CALL(*httpHandler, PUTJson("/api/" + getBridgeUsername(), request, getBridgeIp(), 80)).WillOnce(Return(result)); EXPECT_EQ(result, api.PUTRequest("", request)); Mock::VerifyAndClearExpectations(httpHandler.get()); } //not empty path, starting with slash { const std::string path = "/test"; - EXPECT_CALL(*httpHandler, PUTJson("/api/" + bridge_username + path, request, bridge_ip, 80)).WillOnce(Return(result)); + EXPECT_CALL(*httpHandler, PUTJson("/api/" + getBridgeUsername() + path, request, getBridgeIp(), 80)).WillOnce(Return(result)); EXPECT_EQ(result, api.PUTRequest(path, request)); Mock::VerifyAndClearExpectations(httpHandler.get()); } //not empty path, not starting with slash { const std::string path = "test"; - EXPECT_CALL(*httpHandler, PUTJson("/api/" + bridge_username + '/' + path, request, bridge_ip, 80)).WillOnce(Return(result)); + EXPECT_CALL(*httpHandler, PUTJson("/api/" + getBridgeUsername() + '/' + path, request, getBridgeIp(), 80)).WillOnce(Return(result)); EXPECT_EQ(result, api.PUTRequest(path, request)); Mock::VerifyAndClearExpectations(httpHandler.get()); } //recoverable error { const std::string path = "/test"; - EXPECT_CALL(*httpHandler, PUTJson("/api/" + bridge_username + path, request, bridge_ip, 80)) + EXPECT_CALL(*httpHandler, PUTJson("/api/" + getBridgeUsername() + path, request, getBridgeIp(), 80)) .WillOnce(Throw(std::system_error(std::make_error_code(std::errc::connection_reset)))) .WillOnce(Return(result)); EXPECT_EQ(result, api.PUTRequest(path, request)); @@ -67,7 +67,7 @@ TEST(HueCommandAPI, PUTRequest) //recoverable error x2 { const std::string path = "/test"; - EXPECT_CALL(*httpHandler, PUTJson("/api/" + bridge_username + path, request, bridge_ip, 80)) + EXPECT_CALL(*httpHandler, PUTJson("/api/" + getBridgeUsername() + path, request, getBridgeIp(), 80)) .WillOnce(Throw(std::system_error(std::make_error_code(std::errc::connection_reset)))) .WillOnce(Throw(std::system_error(std::make_error_code(std::errc::connection_reset)))); EXPECT_THROW(api.PUTRequest(path, request), std::system_error); @@ -76,7 +76,7 @@ TEST(HueCommandAPI, PUTRequest) //unrecoverable error { const std::string path = "/test"; - EXPECT_CALL(*httpHandler, PUTJson("/api/" + bridge_username + path, request, bridge_ip, 80)) + EXPECT_CALL(*httpHandler, PUTJson("/api/" + getBridgeUsername() + path, request, getBridgeIp(), 80)) .WillOnce(Throw(std::system_error(std::make_error_code(std::errc::not_enough_memory)))); EXPECT_THROW(api.PUTRequest(path, request), std::system_error); Mock::VerifyAndClearExpectations(httpHandler.get()); @@ -88,35 +88,35 @@ TEST(HueCommandAPI, GETRequest) using namespace ::testing; std::shared_ptr httpHandler = std::make_shared(); - HueCommandAPI api(bridge_ip, bridge_username, httpHandler); + HueCommandAPI api(getBridgeIp(), getBridgeUsername(), httpHandler); Json::Value request; Json::Value result = Json::objectValue; result["ok"] = true; //empty path { - EXPECT_CALL(*httpHandler, GETJson("/api/" + bridge_username, request, bridge_ip, 80)).WillOnce(Return(result)); + EXPECT_CALL(*httpHandler, GETJson("/api/" + getBridgeUsername(), request, getBridgeIp(), 80)).WillOnce(Return(result)); EXPECT_EQ(result, api.GETRequest("", request)); Mock::VerifyAndClearExpectations(httpHandler.get()); } //not empty path, starting with slash { const std::string path = "/test"; - EXPECT_CALL(*httpHandler, GETJson("/api/" + bridge_username + path, request, bridge_ip, 80)).WillOnce(Return(result)); + EXPECT_CALL(*httpHandler, GETJson("/api/" + getBridgeUsername() + path, request, getBridgeIp(), 80)).WillOnce(Return(result)); EXPECT_EQ(result, api.GETRequest(path, request)); Mock::VerifyAndClearExpectations(httpHandler.get()); } //not empty path, not starting with slash { const std::string path = "test"; - EXPECT_CALL(*httpHandler, GETJson("/api/" + bridge_username + '/' + path, request, bridge_ip, 80)).WillOnce(Return(result)); + EXPECT_CALL(*httpHandler, GETJson("/api/" + getBridgeUsername() + '/' + path, request, getBridgeIp(), 80)).WillOnce(Return(result)); EXPECT_EQ(result, api.GETRequest(path, request)); Mock::VerifyAndClearExpectations(httpHandler.get()); } //recoverable error { const std::string path = "/test"; - EXPECT_CALL(*httpHandler, GETJson("/api/" + bridge_username + path, request, bridge_ip, 80)) + EXPECT_CALL(*httpHandler, GETJson("/api/" + getBridgeUsername() + path, request, getBridgeIp(), 80)) .WillOnce(Throw(std::system_error(std::make_error_code(std::errc::connection_reset)))) .WillOnce(Return(result)); EXPECT_EQ(result, api.GETRequest(path, request)); @@ -125,7 +125,7 @@ TEST(HueCommandAPI, GETRequest) //recoverable error x2 { const std::string path = "/test"; - EXPECT_CALL(*httpHandler, GETJson("/api/" + bridge_username + path, request, bridge_ip, 80)) + EXPECT_CALL(*httpHandler, GETJson("/api/" + getBridgeUsername() + path, request, getBridgeIp(), 80)) .WillOnce(Throw(std::system_error(std::make_error_code(std::errc::connection_reset)))) .WillOnce(Throw(std::system_error(std::make_error_code(std::errc::connection_reset)))); EXPECT_THROW(api.GETRequest(path, request), std::system_error); @@ -134,7 +134,7 @@ TEST(HueCommandAPI, GETRequest) //unrecoverable error { const std::string path = "/test"; - EXPECT_CALL(*httpHandler, GETJson("/api/" + bridge_username + path, request, bridge_ip, 80)) + EXPECT_CALL(*httpHandler, GETJson("/api/" + getBridgeUsername() + path, request, getBridgeIp(), 80)) .WillOnce(Throw(std::system_error(std::make_error_code(std::errc::not_enough_memory)))); EXPECT_THROW(api.GETRequest(path, request), std::system_error); Mock::VerifyAndClearExpectations(httpHandler.get()); @@ -146,35 +146,35 @@ TEST(HueCommandAPI, DELETERequest) using namespace ::testing; std::shared_ptr httpHandler = std::make_shared(); - HueCommandAPI api(bridge_ip, bridge_username, httpHandler); + HueCommandAPI api(getBridgeIp(), getBridgeUsername(), httpHandler); Json::Value request; Json::Value result = Json::objectValue; result["ok"] = true; //empty path { - EXPECT_CALL(*httpHandler, DELETEJson("/api/" + bridge_username, request, bridge_ip, 80)).WillOnce(Return(result)); + EXPECT_CALL(*httpHandler, DELETEJson("/api/" + getBridgeUsername(), request, getBridgeIp(), 80)).WillOnce(Return(result)); EXPECT_EQ(result, api.DELETERequest("", request)); Mock::VerifyAndClearExpectations(httpHandler.get()); } //not empty path, starting with slash { const std::string path = "/test"; - EXPECT_CALL(*httpHandler, DELETEJson("/api/" + bridge_username + path, request, bridge_ip, 80)).WillOnce(Return(result)); + EXPECT_CALL(*httpHandler, DELETEJson("/api/" + getBridgeUsername() + path, request, getBridgeIp(), 80)).WillOnce(Return(result)); EXPECT_EQ(result, api.DELETERequest(path, request)); Mock::VerifyAndClearExpectations(httpHandler.get()); } //not empty path, not starting with slash { const std::string path = "test"; - EXPECT_CALL(*httpHandler, DELETEJson("/api/" + bridge_username + '/' + path, request, bridge_ip, 80)).WillOnce(Return(result)); + EXPECT_CALL(*httpHandler, DELETEJson("/api/" + getBridgeUsername() + '/' + path, request, getBridgeIp(), 80)).WillOnce(Return(result)); EXPECT_EQ(result, api.DELETERequest(path, request)); Mock::VerifyAndClearExpectations(httpHandler.get()); } //recoverable error { const std::string path = "/test"; - EXPECT_CALL(*httpHandler, DELETEJson("/api/" + bridge_username + path, request, bridge_ip, 80)) + EXPECT_CALL(*httpHandler, DELETEJson("/api/" + getBridgeUsername() + path, request, getBridgeIp(), 80)) .WillOnce(Throw(std::system_error(std::make_error_code(std::errc::connection_reset)))) .WillOnce(Return(result)); EXPECT_EQ(result, api.DELETERequest(path, request)); @@ -183,7 +183,7 @@ TEST(HueCommandAPI, DELETERequest) //recoverable error x2 { const std::string path = "/test"; - EXPECT_CALL(*httpHandler, DELETEJson("/api/" + bridge_username + path, request, bridge_ip, 80)) + EXPECT_CALL(*httpHandler, DELETEJson("/api/" + getBridgeUsername() + path, request, getBridgeIp(), 80)) .WillOnce(Throw(std::system_error(std::make_error_code(std::errc::connection_reset)))) .WillOnce(Throw(std::system_error(std::make_error_code(std::errc::connection_reset)))); EXPECT_THROW(api.DELETERequest(path, request), std::system_error); @@ -192,9 +192,9 @@ TEST(HueCommandAPI, DELETERequest) //unrecoverable error { const std::string path = "/test"; - EXPECT_CALL(*httpHandler, GETJson("/api/" + bridge_username + path, request, bridge_ip, 80)) + EXPECT_CALL(*httpHandler, GETJson("/api/" + getBridgeUsername() + path, request, getBridgeIp(), 80)) .WillOnce(Throw(std::system_error(std::make_error_code(std::errc::not_enough_memory)))); EXPECT_THROW(api.GETRequest(path, request), std::system_error); Mock::VerifyAndClearExpectations(httpHandler.get()); } -} \ No newline at end of file +} -- libgit2 0.21.4