-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgtagsmixer_test.cc
160 lines (137 loc) · 4.2 KB
/
gtagsmixer_test.cc
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
// Copyright 2007 Google Inc. All Rights Reserved.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
// Author: [email protected] (Stephen Chen)
#include "gtagsunit.h"
#include "gtagsmixer.h"
#include "callback.h"
namespace {
GTAGS_FIXTURE(ResultMixerTest) {
public:
GTAGS_FIXTURE_SETUP(ResultMixerTest) {
mixer = new ResultMixer(
NUM_SOURCES_PER_REQUEST,
gtags::CallbackFactory::Create(
this, &ResultMixerTest::Callback));
calledback = false;
result = "";
}
GTAGS_FIXTURE_TEARDOWN(ResultMixerTest) {}
void Callback(const string& s) {
result = s;
calledback = true;
}
protected:
ResultMixer* mixer;
bool calledback;
string result;
};
TEST_F(ResultMixerTest, set_result) {
EXPECT_FALSE(calledback);
mixer->set_result("((value (((tag tag1)))))", REMOTE);
EXPECT_FALSE(calledback);
mixer->set_result("((value (((tag tag3)))))", LOCAL);
EXPECT_TRUE(calledback);
EXPECT_EQ("((value (((tag tag3))((tag tag1)))))", result);
}
TEST_F(ResultMixerTest, partial_failure) {
EXPECT_FALSE(calledback);
mixer->set_failure("failed", REMOTE);
EXPECT_FALSE(calledback);
mixer->set_result("((value (((tag tag3)))))", LOCAL);
EXPECT_TRUE(calledback);
EXPECT_EQ("((value (((tag tag3)))))", result);
}
TEST_F(ResultMixerTest, no_tag_returned) {
EXPECT_FALSE(calledback);
mixer->set_result("((value t))", REMOTE);
EXPECT_FALSE(calledback);
mixer->set_result("((value t))", LOCAL);
EXPECT_TRUE(calledback);
EXPECT_EQ("((value t))", result);
}
TEST_F(ResultMixerTest, no_return_values) {
EXPECT_FALSE(calledback);
mixer->set_result("((balh t))", REMOTE);
EXPECT_FALSE(calledback);
mixer->set_failure("((hmm nil))", LOCAL);
EXPECT_TRUE(calledback);
EXPECT_EQ("((balh t))", result);
}
TEST_F(ResultMixerTest, all_failures) {
EXPECT_FALSE(calledback);
mixer->set_failure("remote", REMOTE);
EXPECT_FALSE(calledback);
mixer->set_failure("local", LOCAL);
EXPECT_TRUE(calledback);
EXPECT_EQ("((error ((message \"remote\"))))", result);
}
GTAGS_FIXTURE(ResultHolderTest) {
public:
GTAGS_FIXTURE_SETUP(ResultHolderTest) {
mixer = new MockMixer();
mixer->result = "";
mixer->failure = "";
holder = new ResultHolder(REMOTE, 3, mixer);
}
GTAGS_FIXTURE_TEARDOWN(ResultHolderTest) {
delete mixer;
}
class MockMixer : public ResultMixer {
public:
MockMixer() : ResultMixer(0, NULL) {}
virtual ~MockMixer() {}
virtual void set_result(const string& result, SourceId id) {
this->result = result;
this->id = id;
}
virtual void set_failure(const string& failure, SourceId id) {
this->failure = failure;
this->id = id;
}
string result;
string failure;
SourceId id;
};
protected:
MockMixer* mixer;
ResultHolder* holder;
};
TEST_F(ResultHolderTest, set_result) {
EXPECT_NE("result1", mixer->result);
holder->set_result("result1");
EXPECT_EQ("result1", mixer->result);
EXPECT_EQ(REMOTE, mixer->id);
holder->set_result("result2");
EXPECT_EQ("result1", mixer->result);
EXPECT_EQ(REMOTE, mixer->id);
holder->set_result("result3");
EXPECT_EQ("result1", mixer->result);
EXPECT_EQ(REMOTE, mixer->id);
}
TEST_F(ResultHolderTest, set_failure) {
holder->set_failure("failure1");
EXPECT_EQ("", mixer->result);
EXPECT_EQ("", mixer->failure);
holder->set_failure("failure2");
EXPECT_EQ("", mixer->result);
EXPECT_EQ("", mixer->failure);
holder->set_failure("failure3");
EXPECT_EQ("", mixer->result);
EXPECT_EQ("Failed to connect to remote services.", mixer->failure);
EXPECT_EQ(REMOTE, mixer->id);
}
} // namespace