Remove client when the app is terminated
[apps/agl-service-windowmanager.git] / test / test.cpp
1 #include <iostream>
2 //#include "cpputest/include/CppUTest/CommandLineTestRunner.h"
3 #include <gtest/gtest.h>
4 #include <memory>
5 #include "applist.hpp"
6 #include "windowmanager-client.hpp"
7
8 // テストグループの定義 TEST_GROUP(group)
9 // フィクスチャの準備
10 using std::cout;
11 using std::endl;
12 using std::string;
13
14 namespace
15 {
16
17 const string test1 = "testApp";
18 const string test2 = "testApp2";
19 const string test3 = "testApp3";
20 const string test_role = "testRole";
21 const string test_area = "testArea";
22 const string test1_errname = "testApp_false";
23 const string test_role_err = "testRole_false";
24 static wm::AppList app_list;
25
26 class dbtest : public ::testing::Test
27 {
28 public:
29   void SetUp() {}
30   void TearDown() {}
31
32 protected:
33 };
34
35 TEST_F(dbtest, contains)
36 {
37   app_list.addClient(test1, test_role);
38   bool result = app_list.contains(test1);
39   EXPECT_EQ(true, result);
40   result = app_list.contains(test1_errname);
41   EXPECT_EQ(false, result);
42 }
43
44 TEST_F(dbtest, lookup)
45 {
46   auto test = app_list.lookUpClient(test1);
47   cout << "Check getting client object" << endl;
48   EXPECT_EQ(true, (test) ? true : false);
49   cout << "Check client name" << endl;
50   EXPECT_EQ(test1, test->appID());
51   cout << "Check exception throwing of out_of_range" << endl;
52   ASSERT_THROW(app_list.lookUpClient(test1_errname), std::out_of_range);
53   app_list.client_dump();
54 }
55
56 TEST_F(dbtest, remove)
57 {
58   ASSERT_NO_THROW(app_list.removeClient(test1_errname));
59   ASSERT_NO_THROW(app_list.removeClient(test1));
60   EXPECT_EQ(0, app_list.countClient());
61   app_list.addClient(test1, test_role);
62 }
63
64 class reqtest : public ::testing::Test
65 {
66 public:
67   void SetUp() {}
68   void TearDown() {}
69
70 protected:
71 };
72
73 TEST_F(reqtest, currentSequenceNumber)
74 {
75   EXPECT_EQ(1, app_list.currentSequenceNumber());
76 }
77
78 TEST_F(reqtest, allocate_sequence)
79 {
80   app_list.addClient(test2, test_role);
81
82   wm::WMRequest req1(test1, test_role, test_area, wm::Task::TASK_ALLOCATE);
83   wm::WMRequest req2(test2, test_role, test_area, wm::Task::TASK_RELEASE);
84   unsigned seq1 = app_list.addAllocateRequest(req1);
85   unsigned seq2 = app_list.addAllocateRequest(req2);
86
87   unsigned current = app_list.currentSequenceNumber();
88   EXPECT_EQ(1, current);
89   EXPECT_EQ(1, seq1);
90   EXPECT_EQ(2, seq2);
91
92   bool result = app_list.requestFinished();
93   EXPECT_EQ(false, result);
94
95   auto trg = app_list.getRequest(seq1);
96
97   result = app_list.setAction(seq1, trg.appid, trg.role, trg.area);
98   result &= app_list.setAction(seq1, test3, test_role, test_area);
99   EXPECT_EQ(true, result);
100
101   app_list.req_dump();
102
103   result = app_list.setEndDrawFinished(current, test1, test_role);
104   EXPECT_EQ(true, result);
105
106   result = app_list.endDrawFullfilled(current);
107   EXPECT_EQ(false, result);
108
109   result = app_list.setEndDrawFinished(current, test3, test_role);
110   EXPECT_EQ(true, result);
111
112   app_list.req_dump();
113
114   result = app_list.endDrawFullfilled(current);
115   EXPECT_EQ(true, result);
116
117   auto actions = app_list.getActions(current);
118   EXPECT_EQ(test1, actions[0].appid);
119   EXPECT_EQ(test_role, actions[0].role);
120   EXPECT_EQ(test_area, actions[0].area);
121   EXPECT_EQ(test3, actions[1].appid);
122   EXPECT_EQ(test_role, actions[1].role);
123   EXPECT_EQ(test_area, actions[1].area);
124
125   app_list.removeRequest(current);
126   /* lookup_seq_err = app_list.lookUpAllocatingApp(test1);
127   EXPECT_EQ(0, lookup_seq_err); */
128
129   app_list.next();
130   unsigned next_seq = app_list.currentSequenceNumber();
131   EXPECT_EQ(seq2, next_seq);
132   result = app_list.haveRequest();
133   EXPECT_EQ(true, result);
134
135   app_list.req_dump();
136 }
137
138 TEST_F(reqtest, release_sequence)
139 {
140
141 }
142
143 } // namespace
144
145 int main(int argc, char **argv)
146 {
147   ::testing::InitGoogleTest(&argc, argv);
148   return RUN_ALL_TESTS();
149 }