aboutsummaryrefslogtreecommitdiffstats
path: root/test/test.cpp
blob: f56cd2f0a7f0ee99ee51ddbd31c0f3c158616363 (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
#include <iostream>
//#include "cpputest/include/CppUTest/CommandLineTestRunner.h"
#include <gtest/gtest.h>
#include <memory>
#include "applist.hpp"
#include "windowmanager-client.hpp"

// テストグループの定義 TEST_GROUP(group)
// フィクスチャの準備
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_role = "testRole";
const string test_area = "testArea";
const string test1_errname = "testApp_false";
const string test_role_err = "testRole_false";
static wm::AppList app_list;

class dbtest : public ::testing::Test
{
public:
  void SetUp() {}
  void TearDown() {}

protected:
};

TEST_F(dbtest, contains)
{
  app_list.addClient(test1, test_role);
  bool result = app_list.contains(test1);
  EXPECT_EQ(true, result);
  result = app_list.contains(test1_errname);
  EXPECT_EQ(false, result);
}

TEST_F(dbtest, lookup)
{
  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.client_dump();
}

TEST_F(dbtest, remove)
{
  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);
}

class reqtest : public ::testing::Test
{
public:
  void SetUp() {}
  void TearDown() {}

protected:
};

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

TEST_F(reqtest, 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);
  unsigned seq1 = app_list.addAllocateRequest(req1);
  unsigned seq2 = app_list.addAllocateRequest(req2);

  unsigned current = app_list.currentSequenceNumber();
  EXPECT_EQ(1, current);
  EXPECT_EQ(1, seq1);
  EXPECT_EQ(2, seq2);

  bool result = app_list.requestFinished();
  EXPECT_EQ(false, result);

  result = app_list.setAction(seq1, test1, test_role, test_area);
  result &= app_list.setAction(seq1, test3, test_role, test_area);
  EXPECT_EQ(true, result);

  app_list.req_dump();

  result = app_list.setEndDrawFinished(current, test1, test_role);
  EXPECT_EQ(true, result);

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

  result = app_list.setEndDrawFinished(current, test3, test_role);
  EXPECT_EQ(true, result);

  app_list.req_dump();

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

  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();
  EXPECT_EQ(seq2, next_seq);
  result = app_list.haveRequest();
  EXPECT_EQ(true, result);

  app_list.req_dump();
}

TEST_F(reqtest, release_sequence)
{

}

} // namespace

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