Browse Source

List tests

Jonas Pflanzer 5 years ago
parent
commit
5526dc12cc
2 changed files with 69 additions and 1 deletions
  1. 2 1
      daemon/include/FileManager.h
  2. 67 0
      daemon/test/JsonCommanderTest.cpp

+ 2 - 1
daemon/include/FileManager.h

@@ -140,7 +140,8 @@ public:
   /**
    * Open list command. Set list vector and claculate chunks
    *
-   * @return chunks of the resulting list.
+   * @return chunks of the resulting list | if a filename is too long it returns
+   * -1
    */
   virtual int openList();
 

+ 67 - 0
daemon/test/JsonCommanderTest.cpp

@@ -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