aboutsummaryrefslogtreecommitdiffstats
path: root/test/test.cpp
blob: 0c4583c7b0dcdd4cacd3d5c7e7c71389ceac85bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#include <iostream>
#include <gtest/gtest.h>
#include <memory>
#include "applist.hpp"
#include "wm_client.hpp"
#include "wm_error.hpp"

using std::cout;
using std::endl;
using std::string;

namespace
{

const string test1 = "testApp";
const string test2 = "testApp2";
const string test3 = "testApp3";
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
{
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, add_and_contains_client)
{
  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_client)
{
  auto test = app_list.lookUpClient(test1);
  cout << "Check getting client object" << endl;
  EXPECT_EQ(true, (test) ? true : false);
  cout << "Check client name" << endl;
  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.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_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(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
{
public:
  void SetUp() {}
  void TearDown() {}

protected:
};

TEST_F(reqtest, currentRequestNumber)
{
  EXPECT_EQ(1, app_list.currentRequestNumber());
}

TEST_F(reqtest, 3_allocate_sequence)
{
  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.currentRequestNumber();
  EXPECT_EQ(1, current);
  EXPECT_EQ(1, seq1);
  EXPECT_EQ(2, seq2);
  EXPECT_EQ(3, seq3);

  auto trg = app_list.getRequest(seq1, &found);
  EXPECT_EQ(true, found);

  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);

  app_list.reqDump();

  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_role1);
  EXPECT_EQ(true, result);

  app_list.reqDump();

  result = app_list.endDrawFullfilled(current);
  EXPECT_EQ(true, result);

  auto actions = app_list.getActions(current, &found);
  EXPECT_EQ(true, found);
  EXPECT_EQ(test1, actions[0].appid);
  EXPECT_EQ(test_role1, actions[0].role);
  EXPECT_EQ(test_area1, actions[0].area);
  EXPECT_EQ(test3, actions[1].appid);
  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.currentRequestNumber();
  EXPECT_EQ(seq2, next_seq);
  result = app_list.haveRequest();
  EXPECT_EQ(true, result);

  app_list.reqDump();
}

} // namespace

int main(int argc, char **argv)
{
  ::testing::InitGoogleTest(&argc, argv);
  return RUN_ALL_TESTS();
}