|
@@ -1538,4 +1538,190 @@ TEST(Notifications, TwoMessages) {
|
|
Notifications::userTimeStamps.clear();
|
|
Notifications::userTimeStamps.clear();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+TEST(ExtendedList, positive) {
|
|
|
|
+ FileManagerMock fileManager;
|
|
|
|
+
|
|
|
|
+ JsonCommander jsonCommander(fileManager);
|
|
|
|
+
|
|
|
|
+ const std::string command = "extendedlist";
|
|
|
|
+ Json::Value message;
|
|
|
|
+ message["command"] = command;
|
|
|
|
+
|
|
|
|
+ EXPECT_CALL(fileManager, getRemainingExtendedListChunks()).WillOnce(testing::Return(0));
|
|
|
|
+ EXPECT_CALL(fileManager, openExtendedList()).WillOnce(testing::Return(1));
|
|
|
|
+ EXPECT_CALL(fileManager, getExtendedListSize()).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(ExtendedList, negative) {
|
|
|
|
+ FileManagerMock fileManager;
|
|
|
|
+
|
|
|
|
+ JsonCommander jsonCommander(fileManager);
|
|
|
|
+
|
|
|
|
+ const std::string command = "extendedlist";
|
|
|
|
+ Json::Value message;
|
|
|
|
+ message["command"] = command;
|
|
|
|
+
|
|
|
|
+ EXPECT_CALL(fileManager, getRemainingExtendedListChunks()).WillOnce(testing::Return(0));
|
|
|
|
+ EXPECT_CALL(fileManager, openExtendedList()).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(ExtendedList, EmptyList) {
|
|
|
|
+ FileManagerMock fileManager;
|
|
|
|
+
|
|
|
|
+ JsonCommander jsonCommander(fileManager);
|
|
|
|
+
|
|
|
|
+ const std::string command = "extendedlist";
|
|
|
|
+ Json::Value message;
|
|
|
|
+ message["command"] = command;
|
|
|
|
+
|
|
|
|
+ EXPECT_CALL(fileManager, getRemainingExtendedListChunks()).WillOnce(testing::Return(0));
|
|
|
|
+ EXPECT_CALL(fileManager, openExtendedList()).WillOnce(testing::Return(0));
|
|
|
|
+ EXPECT_CALL(fileManager, getExtendedListSize()).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(), "");
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+TEST(ExtendedListData, Positive) {
|
|
|
|
+ FileManagerMock fileManager;
|
|
|
|
+
|
|
|
|
+ JsonCommander jsonCommander(fileManager);
|
|
|
|
+
|
|
|
|
+ const std::string command = "extendedlistdata";
|
|
|
|
+ Json::Value message;
|
|
|
|
+ message["command"] = command;
|
|
|
|
+ message["chunk"] = 0;
|
|
|
|
+ message["cancel"] = false;
|
|
|
|
+
|
|
|
|
+ std::vector<std::tuple<std::string, std::string, double>> chunks;
|
|
|
|
+ std::tuple<std::string, std::string, double> chunk = std::tuple("asdf", "asdfghjkasdfghjkasdfghjkasdfghjk", 41.2);
|
|
|
|
+ chunks.push_back(chunk);
|
|
|
|
+ EXPECT_CALL(fileManager, getRemainingExtendedListChunks()).WillOnce(testing::Return(1));
|
|
|
|
+ EXPECT_CALL(fileManager, getNextChunkFromExtendedList()).WillOnce(testing::Return(chunks));
|
|
|
|
+
|
|
|
|
+ JsonCommander::Response response = jsonCommander.execute(message);
|
|
|
|
+
|
|
|
|
+ EXPECT_EQ(response.json["command"].asString(), command);
|
|
|
|
+ EXPECT_FALSE(response.json["cancel"].asBool());
|
|
|
|
+ EXPECT_EQ(response.json["remaining"].asInt(), 0);
|
|
|
|
+ EXPECT_TRUE(response.json["files"].isArray());
|
|
|
|
+ EXPECT_EQ(response.json["files"].size(), 1);
|
|
|
|
+ EXPECT_EQ(response.json["files"][0]["name"].asString(), "asdf");
|
|
|
|
+ EXPECT_NE(response.json["files"][0]["head"].asString(), "");
|
|
|
|
+ EXPECT_EQ(response.json["files"][0]["size"].asDouble(), 41.2);
|
|
|
|
+ EXPECT_EQ(response.json["error"].asString(), "");
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+TEST(ExtendedListData, Cancel) {
|
|
|
|
+ FileManagerMock fileManager;
|
|
|
|
+
|
|
|
|
+ JsonCommander jsonCommander(fileManager);
|
|
|
|
+
|
|
|
|
+ const std::string command = "extendedlistdata";
|
|
|
|
+ Json::Value message;
|
|
|
|
+ message["command"] = command;
|
|
|
|
+ message["chunk"] = 0;
|
|
|
|
+ message["cancel"] = true;
|
|
|
|
+
|
|
|
|
+ EXPECT_CALL(fileManager, getRemainingExtendedListChunks()).WillOnce(testing::Return(1));
|
|
|
|
+ EXPECT_CALL(fileManager, cancelExtendedList());
|
|
|
|
+
|
|
|
|
+ JsonCommander::Response response = jsonCommander.execute(message);
|
|
|
|
+
|
|
|
|
+ EXPECT_EQ(response.json["command"].asString(), command);
|
|
|
|
+ EXPECT_TRUE(response.json["cancel"].asBool());
|
|
|
|
+ EXPECT_EQ(response.json["remaining"].asInt(), 0);
|
|
|
|
+ EXPECT_TRUE(response.json["files"].isArray());
|
|
|
|
+ EXPECT_EQ(response.json["error"].asString(), "");
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+TEST(ExtendedListData, WrongChunkNumber) {
|
|
|
|
+ FileManagerMock fileManager;
|
|
|
|
+
|
|
|
|
+ JsonCommander jsonCommander(fileManager);
|
|
|
|
+
|
|
|
|
+ const std::string command = "extendedlistdata";
|
|
|
|
+ Json::Value message;
|
|
|
|
+ message["command"] = command;
|
|
|
|
+ message["chunk"] = 1;
|
|
|
|
+ message["cancel"] = false;
|
|
|
|
+
|
|
|
|
+ EXPECT_CALL(fileManager, getRemainingExtendedListChunks()).WillOnce(testing::Return(1));
|
|
|
|
+
|
|
|
|
+ JsonCommander::Response response = jsonCommander.execute(message);
|
|
|
|
+ EXPECT_TRUE(response.action == JsonCommander::Action::closeAndSend);
|
|
|
|
+ EXPECT_EQ(response.json["command"].asString(), command);
|
|
|
|
+ EXPECT_TRUE(response.json["cancel"].asBool());
|
|
|
|
+ EXPECT_EQ(response.json["remaining"].asInt(), -1);
|
|
|
|
+ EXPECT_TRUE(response.json["files"].isArray());
|
|
|
|
+ EXPECT_TRUE(response.json["error"].asString().compare("") != 0);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+TEST(ExtendedListData, NoChunksToBeSend) {
|
|
|
|
+ FileManagerMock fileManager;
|
|
|
|
+
|
|
|
|
+ JsonCommander jsonCommander(fileManager);
|
|
|
|
+
|
|
|
|
+ const std::string command = "extendedlistdata";
|
|
|
|
+ Json::Value message;
|
|
|
|
+ message["command"] = command;
|
|
|
|
+ message["chunk"] = 1;
|
|
|
|
+ message["cancel"] = false;
|
|
|
|
+
|
|
|
|
+ EXPECT_CALL(fileManager, getRemainingExtendedListChunks()).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["cancel"].asBool());
|
|
|
|
+ EXPECT_EQ(response.json["remaining"].asInt(), -1);
|
|
|
|
+ EXPECT_TRUE(response.json["files"].isArray());
|
|
|
|
+ EXPECT_TRUE(response.json["error"].asString().compare("") != 0);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+TEST(ExtendedListData, InvalidRequest) {
|
|
|
|
+ FileManagerMock fileManager;
|
|
|
|
+
|
|
|
|
+ JsonCommander jsonCommander(fileManager);
|
|
|
|
+
|
|
|
|
+ const std::string command = "extendedlistdata";
|
|
|
|
+ Json::Value message;
|
|
|
|
+ message["command"] = command;
|
|
|
|
+ message["chunk"] = 5;
|
|
|
|
+
|
|
|
|
+ EXPECT_CALL(fileManager, getRemainingExtendedListChunks()).WillOnce(testing::Return(0));
|
|
|
|
+
|
|
|
|
+ JsonCommander::Response response = jsonCommander.execute(message);
|
|
|
|
+ EXPECT_TRUE(response.action == JsonCommander::Action::closeAndSend);
|
|
|
|
+ EXPECT_EQ(response.json["command"].asString(), command);
|
|
|
|
+ EXPECT_TRUE(response.json["cancel"].asBool());
|
|
|
|
+ EXPECT_EQ(response.json["remaining"].asInt(), -1);
|
|
|
|
+ EXPECT_TRUE(response.json["files"].isArray());
|
|
|
|
+ EXPECT_TRUE(response.json["error"].asString().compare("") != 0);
|
|
|
|
+}
|
|
|
|
+
|
|
} // namespace
|
|
} // namespace
|