|
@@ -6,34 +6,84 @@
|
|
|
|
|
|
namespace {
|
|
|
/* Version tests */
|
|
|
+TEST(testVersion, PositiveAllEqual) {
|
|
|
+ FileManagerMock fileManager;
|
|
|
+
|
|
|
+ JsonCommander jsonCommander(fileManager);
|
|
|
+ Json::Value message;
|
|
|
+ message["major"] = 0;
|
|
|
+ message["minor"] = 1;
|
|
|
+
|
|
|
+ JsonCommander::Response response = jsonCommander.testVersion(message);
|
|
|
+
|
|
|
+ EXPECT_TRUE(response.action == JsonCommander::Action::send);
|
|
|
+ EXPECT_TRUE(response.json["accept"].asBool());
|
|
|
+ EXPECT_EQ(response.json["major"].asInt(), jsonCommander.protocolMajorVersion);
|
|
|
+ EXPECT_EQ(response.json["minor"].asInt(), jsonCommander.protocolMinorVersion);
|
|
|
+}
|
|
|
+
|
|
|
TEST(testVersion, Positive) {
|
|
|
FileManagerMock fileManager;
|
|
|
|
|
|
JsonCommander jsonCommander(fileManager);
|
|
|
+ Json::Value message;
|
|
|
+ message["major"] = jsonCommander.protocolMajorVersion;
|
|
|
+ message["minor"] = jsonCommander.protocolMinorVersion - 1;
|
|
|
|
|
|
- const std::string versionString = "0.2";
|
|
|
- Json::Value version;
|
|
|
- version["version"] = versionString;
|
|
|
+ JsonCommander::Response response = jsonCommander.testVersion(message);
|
|
|
|
|
|
- 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);
|
|
|
+ EXPECT_EQ(response.json["major"].asInt(), jsonCommander.protocolMajorVersion);
|
|
|
+ EXPECT_EQ(response.json["minor"].asInt(), jsonCommander.protocolMinorVersion);
|
|
|
+}
|
|
|
+
|
|
|
+TEST(testVersion, InvalidRequest) {
|
|
|
+ FileManagerMock fileManager;
|
|
|
+
|
|
|
+ JsonCommander jsonCommander(fileManager);
|
|
|
+ Json::Value message;
|
|
|
+ message["major"] = "def";
|
|
|
+ message["minor"] = "abc";
|
|
|
+
|
|
|
+ JsonCommander::Response response = jsonCommander.testVersion(message);
|
|
|
+
|
|
|
+ EXPECT_TRUE(response.action == JsonCommander::Action::closeAndSend);
|
|
|
+ EXPECT_FALSE(response.json["accept"].asBool());
|
|
|
+ EXPECT_EQ(response.json["major"].asInt(), jsonCommander.protocolMajorVersion);
|
|
|
+ EXPECT_EQ(response.json["minor"].asInt(), jsonCommander.protocolMinorVersion);
|
|
|
+}
|
|
|
+
|
|
|
+TEST(testVersion, NotEqualMajorNumber) {
|
|
|
+ FileManagerMock fileManager;
|
|
|
+
|
|
|
+ JsonCommander jsonCommander(fileManager);
|
|
|
+ Json::Value message;
|
|
|
+ message["major"] = jsonCommander.protocolMajorVersion + 1;
|
|
|
+ message["minor"] = jsonCommander.protocolMinorVersion;
|
|
|
+
|
|
|
+ JsonCommander::Response response = jsonCommander.testVersion(message);
|
|
|
+
|
|
|
+ EXPECT_TRUE(response.action == JsonCommander::Action::closeAndSend);
|
|
|
+ EXPECT_FALSE(response.json["accept"].asBool());
|
|
|
+ EXPECT_EQ(response.json["major"].asInt(), jsonCommander.protocolMajorVersion);
|
|
|
+ EXPECT_EQ(response.json["minor"].asInt(), jsonCommander.protocolMinorVersion);
|
|
|
}
|
|
|
|
|
|
-TEST(testVersion, Negative) {
|
|
|
+TEST(testVersion, BiggerMinorNumber) {
|
|
|
FileManagerMock fileManager;
|
|
|
|
|
|
JsonCommander jsonCommander(fileManager);
|
|
|
+ Json::Value message;
|
|
|
+ message["major"] = jsonCommander.protocolMajorVersion;
|
|
|
+ message["minor"] = jsonCommander.protocolMinorVersion + 1;
|
|
|
|
|
|
- const std::string versionString = "0.1";
|
|
|
- Json::Value version;
|
|
|
- version["version"] = versionString;
|
|
|
+ JsonCommander::Response response = jsonCommander.testVersion(message);
|
|
|
|
|
|
- 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);
|
|
|
+ EXPECT_EQ(response.json["major"].asInt(), jsonCommander.protocolMajorVersion);
|
|
|
+ EXPECT_EQ(response.json["minor"].asInt(), jsonCommander.protocolMinorVersion);
|
|
|
}
|
|
|
|
|
|
/* Status tests */
|