|
@@ -0,0 +1,110 @@
|
|
|
|
+#include <gtest/gtest.h>
|
|
|
|
+#include <gmock/gmock.h>
|
|
|
|
+
|
|
|
|
+#include "../include/JsonCommander.h"
|
|
|
|
+#include "FileManagerMock.h"
|
|
|
|
+
|
|
|
|
+namespace {
|
|
|
|
+ /* Version tests */
|
|
|
|
+ TEST(testVersion, Positive) {
|
|
|
|
+ FileManagerMock fileManager;
|
|
|
|
+
|
|
|
|
+ JsonCommander jsonCommander(fileManager);
|
|
|
|
+
|
|
|
|
+ const std::string versionString = "0.2";
|
|
|
|
+ Json::Value version;
|
|
|
|
+ version["version"] = versionString;
|
|
|
|
+
|
|
|
|
+ JsonCommander::Response response = jsonCommander.testVersion(version);
|
|
|
|
+ EXPECT_TRUE(response.action == JsonCommander::Action::send);
|
|
|
|
+ EXPECT_TRUE(response.json["accept"].asBool());
|
|
|
|
+ EXPECT_EQ(response.json["version"].asString(), versionString);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ TEST(testVersion, Negative) {
|
|
|
|
+ FileManagerMock fileManager;
|
|
|
|
+
|
|
|
|
+ JsonCommander jsonCommander(fileManager);
|
|
|
|
+
|
|
|
|
+ const std::string versionString = "0.1";
|
|
|
|
+ Json::Value version;
|
|
|
|
+ version["version"] = versionString;
|
|
|
|
+
|
|
|
|
+ JsonCommander::Response response = jsonCommander.testVersion(version);
|
|
|
|
+ EXPECT_TRUE(response.action == JsonCommander::Action::closeAndSend);
|
|
|
|
+ EXPECT_FALSE(response.json["accept"].asBool());
|
|
|
|
+ EXPECT_FALSE(response.json["version"].asString().compare(versionString) == 0);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /* Status tests */
|
|
|
|
+ TEST(Status, Ok) {
|
|
|
|
+ FileManagerMock fileManager;
|
|
|
|
+
|
|
|
|
+ JsonCommander jsonCommander(fileManager);
|
|
|
|
+
|
|
|
|
+ const std::string command = "status";
|
|
|
|
+ Json::Value message;
|
|
|
|
+ message["command"] = command;
|
|
|
|
+
|
|
|
|
+ JsonCommander::Response response = jsonCommander.execute(message);
|
|
|
|
+
|
|
|
|
+ EXPECT_TRUE(response.action == JsonCommander::Action::send);
|
|
|
|
+ EXPECT_EQ(response.json["command"].asString(), command);
|
|
|
|
+ EXPECT_EQ(response.json["response"].asString(), "ok");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ TEST(Status, Downloading) {
|
|
|
|
+ FileManagerMock fileManager;
|
|
|
|
+
|
|
|
|
+ JsonCommander jsonCommander(fileManager);
|
|
|
|
+
|
|
|
|
+ const std::string command = "status";
|
|
|
|
+ Json::Value message;
|
|
|
|
+ message["command"] = command;
|
|
|
|
+
|
|
|
|
+ ON_CALL(fileManager, isDownloading()).WillByDefault(testing::Return(true));
|
|
|
|
+
|
|
|
|
+ JsonCommander::Response response = jsonCommander.execute(message);
|
|
|
|
+
|
|
|
|
+ EXPECT_TRUE(response.action == JsonCommander::Action::send);
|
|
|
|
+ EXPECT_EQ(response.json["command"].asString(), command);
|
|
|
|
+ EXPECT_EQ(response.json["response"].asString(), "download running");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ TEST(Status, Uploading) {
|
|
|
|
+ FileManagerMock fileManager;
|
|
|
|
+
|
|
|
|
+ JsonCommander jsonCommander(fileManager);
|
|
|
|
+
|
|
|
|
+ const std::string command = "status";
|
|
|
|
+ Json::Value message;
|
|
|
|
+ message["command"] = command;
|
|
|
|
+
|
|
|
|
+ ON_CALL(fileManager, isUploading()).WillByDefault(testing::Return(true));
|
|
|
|
+
|
|
|
|
+ JsonCommander::Response response = jsonCommander.execute(message);
|
|
|
|
+
|
|
|
|
+ EXPECT_TRUE(response.action == JsonCommander::Action::send);
|
|
|
|
+ EXPECT_EQ(response.json["command"].asString(), command);
|
|
|
|
+ EXPECT_EQ(response.json["response"].asString(), "upload running");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ TEST(Status, UploadingAndDownloading) {
|
|
|
|
+ FileManagerMock fileManager;
|
|
|
|
+
|
|
|
|
+ JsonCommander jsonCommander(fileManager);
|
|
|
|
+
|
|
|
|
+ const std::string command = "status";
|
|
|
|
+ Json::Value message;
|
|
|
|
+ message["command"] = command;
|
|
|
|
+
|
|
|
|
+ ON_CALL(fileManager, isDownloading()).WillByDefault(testing::Return(true));
|
|
|
|
+ ON_CALL(fileManager, isUploading()).WillByDefault(testing::Return(true));
|
|
|
|
+
|
|
|
|
+ JsonCommander::Response response = jsonCommander.execute(message);
|
|
|
|
+
|
|
|
|
+ EXPECT_TRUE(response.action == JsonCommander::Action::send);
|
|
|
|
+ EXPECT_EQ(response.json["command"].asString(), command);
|
|
|
|
+ EXPECT_EQ(response.json["response"].asString(), "download and upload running");
|
|
|
|
+ }
|
|
|
|
+}
|