|
@@ -628,4 +628,71 @@ TEST(Getdata, WrongChunk) {
|
|
|
EXPECT_EQ(response.json["data"].asString(), "");
|
|
|
EXPECT_TRUE(response.json["error"].asString().length() > 0);
|
|
|
}
|
|
|
+
|
|
|
+/* List tests */
|
|
|
+TEST(List, Positive) {
|
|
|
+ FileManagerMock fileManager;
|
|
|
+
|
|
|
+ JsonCommander jsonCommander(fileManager);
|
|
|
+
|
|
|
+ const std::string command = "list";
|
|
|
+ Json::Value message;
|
|
|
+ message["command"] = command;
|
|
|
+
|
|
|
+ EXPECT_CALL(fileManager, openList()).WillOnce(testing::Return(1));
|
|
|
+ EXPECT_CALL(fileManager, getListSize()).WillOnce(testing::Return(5));
|
|
|
+
|
|
|
+ JsonCommander::Response response = jsonCommander.execute(message);
|
|
|
+
|
|
|
+ EXPECT_TRUE(response.action == JsonCommander::Action::send);
|
|
|
+ EXPECT_EQ(response.json["command"].asString(), command);
|
|
|
+ EXPECT_TRUE(response.json["accept"].asBool());
|
|
|
+ EXPECT_EQ(response.json["chunks"].asInt(), 1);
|
|
|
+ EXPECT_EQ(response.json["items"].asInt(), 5);
|
|
|
+ EXPECT_EQ(response.json["error"].asString(), "");
|
|
|
+}
|
|
|
+
|
|
|
+TEST(List, Negative) {
|
|
|
+ FileManagerMock fileManager;
|
|
|
+
|
|
|
+ JsonCommander jsonCommander(fileManager);
|
|
|
+
|
|
|
+ const std::string command = "list";
|
|
|
+ Json::Value message;
|
|
|
+ message["command"] = command;
|
|
|
+
|
|
|
+ EXPECT_CALL(fileManager, openList()).WillOnce(testing::Return(-1));
|
|
|
+
|
|
|
+ JsonCommander::Response response = jsonCommander.execute(message);
|
|
|
+
|
|
|
+ EXPECT_TRUE(response.action == JsonCommander::Action::send);
|
|
|
+ EXPECT_EQ(response.json["command"].asString(), command);
|
|
|
+ EXPECT_FALSE(response.json["accept"].asBool());
|
|
|
+ EXPECT_EQ(response.json["chunks"].asInt(), -1);
|
|
|
+ EXPECT_EQ(response.json["items"].asInt(), -1);
|
|
|
+ EXPECT_TRUE(response.json["error"].asString().compare("") != 0);
|
|
|
+}
|
|
|
+
|
|
|
+TEST(List, EmptyList) {
|
|
|
+ FileManagerMock fileManager;
|
|
|
+
|
|
|
+ JsonCommander jsonCommander(fileManager);
|
|
|
+
|
|
|
+ const std::string command = "list";
|
|
|
+ Json::Value message;
|
|
|
+ message["command"] = command;
|
|
|
+
|
|
|
+ EXPECT_CALL(fileManager, openList()).WillOnce(testing::Return(0));
|
|
|
+ EXPECT_CALL(fileManager, getListSize()).WillOnce(testing::Return(0));
|
|
|
+
|
|
|
+ JsonCommander::Response response = jsonCommander.execute(message);
|
|
|
+
|
|
|
+ EXPECT_TRUE(response.action == JsonCommander::Action::send);
|
|
|
+ EXPECT_EQ(response.json["command"].asString(), command);
|
|
|
+ EXPECT_TRUE(response.json["accept"].asBool());
|
|
|
+ EXPECT_EQ(response.json["chunks"].asInt(), 0);
|
|
|
+ EXPECT_EQ(response.json["items"].asInt(), 0);
|
|
|
+ EXPECT_EQ(response.json["error"].asString(), "");
|
|
|
+}
|
|
|
+
|
|
|
} // namespace
|