-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChannelListTests.cpp
executable file
·151 lines (130 loc) · 3.15 KB
/
ChannelListTests.cpp
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
// Template for a test suite.
// #include <config.h>
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/Asserter.h>
#include "Asserts.h"
#include <CChannel.h>
#include <CChannelList.h>
#include "CChannelVisitor.h"
#include <string>
#include <iostream>
#include <time.h>
#ifdef HAVE_STD_NAMESPACE
using namespace std;
#endif
class ChannelListTests : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(ChannelListTests);
CPPUNIT_TEST(StockTest); // Test ability to build list.
CPPUNIT_TEST(IterationTest); // Test veracity of the iterators.
CPPUNIT_TEST(ForeachTest); // Test visitation rights.
CPPUNIT_TEST_SUITE_END();
private:
void Stock(CChannelList& rList); // Fill the channel list (common).
void CheckChannels(CChannelList& rList,
time_t UpdateTime); // Check channels look ok.
public:
void setUp() {
}
void tearDown() {
}
protected:
void StockTest();
void IterationTest();
void ForeachTest();
void Update1Test();
void UpdateGroupTest();
void UpdateTest();
};
CPPUNIT_TEST_SUITE_REGISTRATION(ChannelListTests);
const string GoodName("Z002DH"); // Good name but no units.
const string BadName("NOSUCHNAME"); // Bad name (no such channel.
const string RealName("Z001DV"); // Good name with units
const char* Names[] = {
"Z002DH",
"Z001DV",
"STRCHAN50",
"STRCHAN40",
"FLTCHAN59",
"FLTCHAN67",
"FLTCHAN70"
};
const int nNames=(sizeof(Names)/sizeof(char*));
//
// Common code to stock a channel list with the channels named in names.
//
void
ChannelListTests::Stock(CChannelList& l)
{
for(int i =0; i < nNames; i++) {
// The lookup below ensures that regardless of what we do to
// the channel it will be destroyable.
//
CChannel* p = new CChannel(string(Names[i]));
p->Connect();
l.push_back(*p);
}
CChannel::doEvents(0.5);
}
// Stock a list channel list:
// Expected results:
// size == nNames.
// begin != end.
// Can iterate nNames times.
//
void
ChannelListTests::StockTest()
{
CChannelList clist;
Stock(clist);
EQ(nNames, clist.size());
ASSERT(clist.begin() != clist.end());
CChannelList::ChannelIterator p = clist.begin();
int i = 0;
while (p != clist.end()) {
p++;
i++;
}
EQ(nNames, i);
}
// Stock a channel list..
// Iterate through requiring that:
// names of the channels are the same as those put in (order preserved!).
//
void
ChannelListTests::IterationTest()
{
CChannelList clist;
Stock(clist);
CChannelList::ChannelIterator p = clist.begin();
int i = 0;
while(p != clist.end()) {
EQ(string(Names[i]), (*p)->getName());
p++;
i++;
}
}
//
/// The class below is a simple channel list iterator... it ensures
// all channels visited match the ones put in in the same order.
//
class CNameCheckVisitor : public CChannelVisitor
{
private:
int i;
public:
CNameCheckVisitor() : i(0) {}
virtual void operator()(CChannel* p) {
EQ(string(Names[i]), p->getName());
i++;
}
};
// Check that channel list foreach visits channels in the order in
// which they are put in and visits all of them:
void
ChannelListTests::ForeachTest()
{
CChannelList clist;
Stock(clist);
CNameCheckVisitor v;
clist.foreach(v);
}