Modify unit test case
authorKazumasa Mitsunari <knimitz@witz-inc.co.jp>
Tue, 19 Jun 2018 06:44:03 +0000 (15:44 +0900)
committerKazumasa Mitsunari <knimitz@witz-inc.co.jp>
Tue, 19 Jun 2018 06:44:03 +0000 (15:44 +0900)
Change-Id: I357ec0d4642716d196be3aca6bda2c92483028e8
Signed-off-by: Kazumasa Mitsunari <knimitz@witz-inc.co.jp>
test/CMakeLists.txt
test/test.cpp
test/windowmanager-client.cpp [deleted symlink]
test/windowmanager-client.hpp [deleted symlink]
test/wm_client.cpp [new symlink]
test/wm_client.hpp [new symlink]
test/wm_error.cpp [new symlink]
test/wm_error.hpp [new symlink]

index 8c693ce..3a44268 100644 (file)
@@ -32,7 +32,8 @@ include_directories(${GTEST_ROOT}/include/)
 link_directories(${GTEST_ROOT}/build/)
 add_executable(${TARGET_TEST}
   test.cpp
-  windowmanager-client.cpp
+  wm_client.cpp
+  wm_error.cpp
   applist.cpp
   request.cpp
 )
index 46195b6..0c4583c 100644 (file)
@@ -1,12 +1,10 @@
 #include <iostream>
-//#include "cpputest/include/CppUTest/CommandLineTestRunner.h"
 #include <gtest/gtest.h>
 #include <memory>
 #include "applist.hpp"
 #include "wm_client.hpp"
+#include "wm_error.hpp"
 
-// テストグループの定義 TEST_GROUP(group)
-// フィクスチャの準備
 using std::cout;
 using std::endl;
 using std::string;
@@ -17,10 +15,21 @@ namespace
 const string test1 = "testApp";
 const string test2 = "testApp2";
 const string test3 = "testApp3";
-const string test_role = "testRole";
-const string test_area = "testArea";
+const string test_role1 = "testRole1";
+const string test_role2 = "testRole2";
+const string test_role3 = "testRole3";
+const string test_area1 = "testArea1";
+const string test_area2 = "testArea2";
+const string test_area3 = "testArea3";
 const string test1_errname = "testApp_false";
 const string test_role_err = "testRole_false";
+const string test_area_err = "testRole_false";
+
+const unsigned test_surface1 = 1;
+const unsigned test_surface2 = 2;
+const unsigned test_surface3 = 3;
+const unsigned test_layer = 1;
+
 static wm::AppList app_list;
 
 class dbtest : public ::testing::Test
@@ -28,20 +37,29 @@ class dbtest : public ::testing::Test
 public:
   void SetUp() {}
   void TearDown() {}
+  void createTestClient(){
+    app_list.addClient(test1, test_layer, test_surface1, test_role1);
+    app_list.addClient(test2, test_layer, test_surface2, test_role2);
+    app_list.addClient(test3, test_layer, test_surface3, test_role2);
+  }
 
 protected:
 };
 
-TEST_F(dbtest, contains)
+TEST_F(dbtest, add_and_contains_client)
 {
-  app_list.addClient(test1, test_role);
+  app_list.addClient(test1, test_layer, test_surface1, test_role1);
+  app_list.addClient(test2, test_layer, test_surface2, test_role2);
+  app_list.addClient(test3, test_layer, test_surface2, test_role2);
   bool result = app_list.contains(test1);
   EXPECT_EQ(true, result);
+  result = app_list.contains(test2);
+  EXPECT_EQ(true, result);
   result = app_list.contains(test1_errname);
   EXPECT_EQ(false, result);
 }
 
-TEST_F(dbtest, lookup)
+TEST_F(dbtest, lookup_client)
 {
   auto test = app_list.lookUpClient(test1);
   cout << "Check getting client object" << endl;
@@ -50,15 +68,70 @@ TEST_F(dbtest, lookup)
   EXPECT_EQ(test1, test->appID());
   cout << "Check exception throwing of out_of_range" << endl;
   ASSERT_THROW(app_list.lookUpClient(test1_errname), std::out_of_range);
-  app_list.client_dump();
+  app_list.clientDump();
+}
+
+TEST_F(dbtest, get_app_id)
+{
+  bool found = false;
+  string appid = app_list.getAppID(test_surface1, test_role1, &found);
+  EXPECT_EQ(true, found);
+  EXPECT_EQ(test1, appid);
+  appid = app_list.getAppID(test_surface2, test_role1, &found);
+  EXPECT_EQ(false, found);
+  EXPECT_EQ("", appid);
 }
 
-TEST_F(dbtest, remove)
+TEST_F(dbtest, remove_surface)
+{
+  bool ret = app_list.contains(test1);
+  EXPECT_EQ(true, ret);
+  auto client = app_list.lookUpClient(test1);
+  unsigned surface = client->surfaceID(test_role1);
+  EXPECT_NE(0, surface);
+  app_list.removeSurface(test_surface1);
+  surface = client->surfaceID(test_role1);
+  EXPECT_EQ(0, surface);
+}
+
+TEST_F(dbtest, remove_client)
 {
   ASSERT_NO_THROW(app_list.removeClient(test1_errname));
   ASSERT_NO_THROW(app_list.removeClient(test1));
-  EXPECT_EQ(0, app_list.countClient());
-  app_list.addClient(test1, test_role);
+  EXPECT_EQ(2, app_list.countClient());
+}
+
+TEST_F(dbtest, cl_get_function)
+{
+  bool ret = app_list.contains(test2);
+  EXPECT_EQ(true, ret);
+  auto client = app_list.lookUpClient(test2);
+  EXPECT_EQ(test2, client->appID());
+  EXPECT_EQ(test_surface2, client->surfaceID(test_role2));
+  EXPECT_EQ(test_layer, client->layerID());
+  EXPECT_EQ(test_role2, client->role(test_surface2));
+  unsigned layer2 = 1000;
+  client->registerLayer(layer2);
+  EXPECT_EQ(layer2, client->layerID());
+  unsigned surface_1000 = 1000;
+  client->addSurface(test_role3, surface_1000);
+  EXPECT_EQ(test_surface2, client->surfaceID(test_role2));
+  EXPECT_EQ(surface_1000, client->surfaceID(test_role3));
+}
+
+TEST_F(dbtest, cl_remove_function)
+{
+  bool ret = app_list.contains(test2);
+  EXPECT_EQ(true, ret);
+  auto client = app_list.lookUpClient(test2);
+  EXPECT_EQ(false, client->removeSurfaceIfExist(test_surface1));
+  EXPECT_EQ(true, client->removeSurfaceIfExist(test_surface2));
+  EXPECT_EQ(false, client->removeRole(test_role1));
+  EXPECT_EQ(true, client->removeRole(test_role3));
+  app_list.removeClient(test2);
+  app_list.removeClient(test3);
+  app_list.clientDump();
+  this->createTestClient();
 }
 
 class reqtest : public ::testing::Test
@@ -70,74 +143,72 @@ public:
 protected:
 };
 
-TEST_F(reqtest, currentSequenceNumber)
+TEST_F(reqtest, currentRequestNumber)
 {
-  EXPECT_EQ(1, app_list.currentSequenceNumber());
+  EXPECT_EQ(1, app_list.currentRequestNumber());
 }
 
-TEST_F(reqtest, allocate_sequence)
+TEST_F(reqtest, 3_allocate_sequence)
 {
-  app_list.addClient(test2, test_role);
-
-  wm::WMRequest req1(test1, test_role, test_area, wm::Task::TASK_ALLOCATE);
-  wm::WMRequest req2(test2, test_role, test_area, wm::Task::TASK_RELEASE);
+  wm::WMRequest req1(test1, test_role1, test_area1, wm::Task::TASK_ALLOCATE);
+  wm::WMRequest req2(test2, test_role2, test_area2, wm::Task::TASK_RELEASE);
+  wm::WMRequest req3(test3, test_role3, test_area3, wm::Task::TASK_ALLOCATE);
   unsigned seq1 = app_list.addAllocateRequest(req1);
   unsigned seq2 = app_list.addAllocateRequest(req2);
+  unsigned seq3 = app_list.addAllocateRequest(req3);
+  bool found = false;
+  bool result = false;
 
-  unsigned current = app_list.currentSequenceNumber();
+  unsigned current = app_list.currentRequestNumber();
   EXPECT_EQ(1, current);
   EXPECT_EQ(1, seq1);
   EXPECT_EQ(2, seq2);
+  EXPECT_EQ(3, seq3);
 
-  bool result = app_list.requestFinished();
-  EXPECT_EQ(false, result);
+  auto trg = app_list.getRequest(seq1, &found);
+  EXPECT_EQ(true, found);
 
-  auto trg = app_list.getRequest(seq1);
+  wm::WMError werr = app_list.setAction(seq1, trg.appid, trg.role, trg.area, wm::TaskVisible::VISIBLE);
+  wm::WMError werr_sub = app_list.setAction(seq1, test3, test_role1, test_area3, wm::TaskVisible::VISIBLE);
+  EXPECT_EQ(wm::WMError::SUCCESS, werr);
+  EXPECT_EQ(wm::WMError::SUCCESS, werr_sub);
 
-  result = app_list.setAction(seq1, trg.appid, trg.role, trg.area);
-  result &= app_list.setAction(seq1, test3, test_role, test_area);
-  EXPECT_EQ(true, result);
+  app_list.reqDump();
 
-  app_list.req_dump();
-
-  result = app_list.setEndDrawFinished(current, test1, test_role);
+  result = app_list.setEndDrawFinished(current, test1, test_role1);
   EXPECT_EQ(true, result);
 
   result = app_list.endDrawFullfilled(current);
   EXPECT_EQ(false, result);
 
-  result = app_list.setEndDrawFinished(current, test3, test_role);
+  result = app_list.setEndDrawFinished(current, test3, test_role1);
   EXPECT_EQ(true, result);
 
-  app_list.req_dump();
+  app_list.reqDump();
 
   result = app_list.endDrawFullfilled(current);
   EXPECT_EQ(true, result);
 
-  auto actions = app_list.getActions(current);
+  auto actions = app_list.getActions(current, &found);
+  EXPECT_EQ(true, found);
   EXPECT_EQ(test1, actions[0].appid);
-  EXPECT_EQ(test_role, actions[0].role);
-  EXPECT_EQ(test_area, actions[0].area);
+  EXPECT_EQ(test_role1, actions[0].role);
+  EXPECT_EQ(test_area1, actions[0].area);
   EXPECT_EQ(test3, actions[1].appid);
-  EXPECT_EQ(test_role, actions[1].role);
-  EXPECT_EQ(test_area, actions[1].area);
+  EXPECT_EQ(test_role1, actions[1].role);
+  EXPECT_EQ(test_area3, actions[1].area);
 
   app_list.removeRequest(current);
   /* lookup_seq_err = app_list.lookUpAllocatingApp(test1);
   EXPECT_EQ(0, lookup_seq_err); */
 
   app_list.next();
-  unsigned next_seq = app_list.currentSequenceNumber();
+  unsigned next_seq = app_list.currentRequestNumber();
   EXPECT_EQ(seq2, next_seq);
   result = app_list.haveRequest();
   EXPECT_EQ(true, result);
 
-  app_list.req_dump();
-}
-
-TEST_F(reqtest, release_sequence)
-{
-
+  app_list.reqDump();
 }
 
 } // namespace
diff --git a/test/windowmanager-client.cpp b/test/windowmanager-client.cpp
deleted file mode 120000 (symlink)
index ae92ca0..0000000
+++ /dev/null
@@ -1 +0,0 @@
-../src/windowmanager-client.cpp
\ No newline at end of file
diff --git a/test/windowmanager-client.hpp b/test/windowmanager-client.hpp
deleted file mode 120000 (symlink)
index a750a64..0000000
+++ /dev/null
@@ -1 +0,0 @@
-../src/windowmanager-client.hpp
\ No newline at end of file
diff --git a/test/wm_client.cpp b/test/wm_client.cpp
new file mode 120000 (symlink)
index 0000000..e36d4b4
--- /dev/null
@@ -0,0 +1 @@
+../src/wm_client.cpp
\ No newline at end of file
diff --git a/test/wm_client.hpp b/test/wm_client.hpp
new file mode 120000 (symlink)
index 0000000..269e331
--- /dev/null
@@ -0,0 +1 @@
+../src/wm_client.hpp
\ No newline at end of file
diff --git a/test/wm_error.cpp b/test/wm_error.cpp
new file mode 120000 (symlink)
index 0000000..8ec7eaa
--- /dev/null
@@ -0,0 +1 @@
+../src/wm_error.cpp
\ No newline at end of file
diff --git a/test/wm_error.hpp b/test/wm_error.hpp
new file mode 120000 (symlink)
index 0000000..3ad9ecd
--- /dev/null
@@ -0,0 +1 @@
+../src/wm_error.hpp
\ No newline at end of file