blob: 902b7ab0e3f111319d7c59c287933a75b1f15937 (
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
221
222
223
224
225
226
|
/****************************************************************************
* stationdatabase_test.cpp - Test Program for StationDatabase Class
* -------------------
* begin : Friday June 4 2004
* copyright : (C) 2004 by John Ratke
* email : jratke@comcast.net
****************************************************************************/
/****************************************************************************
* *
* 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. *
* *
****************************************************************************/
#include <iostream>
#include <cstdlib>
using namespace std;
#include <qfile.h>
#include <qstring.h>
#include <qdatetime.h>
#include <krfcdate.h>
#include "stationdatabase.h"
int main()
{
bool anyFailed = false;
bool found = false;
// try the stations.dat file in the current directory first.
QString path("stations.dat");
if (QFile::exists(path))
{
found = true;
}
else
{
// If we couldn't find it, then maybe the build directory is not the
// same as the source directory. If that is the case, try to read it
// from its location in the share/apps/kweatherservice directory, which
// means that make install would have had to be done first before calling
// make check so that the file will be there.
QString kdeDirs(getenv("KDEDIR"));
path = kdeDirs + "/share/apps/kweatherservice/stations.dat";
if (QFile::exists(path))
{
found = true;
}
}
if (found)
{
cout << "found stations.dat at " << path.latin1() << endl;
}
else
{
cout << "couldn't find stations.dat!! try \"make install\" before \"make check\"" << endl;
return 1;
}
StationDatabase stationDb(path);
cout << "Testing station name from ID with known station...";
if (stationDb.stationNameFromID("KORD") == "Chicago, Chicago-O'Hare International Airport")
{
cout << "passed" << endl;
}
else
{
cout << "failed" << endl;
anyFailed = true;
}
cout << "Testing station name from ID with unknown station...";
if (stationDb.stationNameFromID("KXYZ") == "Unknown Station")
{
cout << "passed" << endl;
}
else
{
cout << "failed" << endl;
anyFailed = true;
}
cout << "Testing station name from ID with known station already loaded...";
// station should be cached this time.
if (stationDb.stationNameFromID("KORD") == "Chicago, Chicago-O'Hare International Airport")
{
cout << "passed" << endl;
}
else
{
cout << "failed" << endl;
anyFailed = true;
}
cout << "Testing latitude from ID with known station...";
if (stationDb.stationLatitudeFromID("KPWK") == "42-07-15N")
{
cout << "passed" << endl;
}
else
{
cout << "failed" << endl;
anyFailed = true;
}
cout << "Testing latitude from ID with unknown station...";
if (stationDb.stationLatitudeFromID("KZZZ") == "Unknown Station")
{
cout << "passed" << endl;
}
else
{
cout << "failed" << endl;
anyFailed = true;
}
cout << "Testing latitude from ID with known station already loaded...";
if (stationDb.stationLatitudeFromID("KPWK") == "42-07-15N")
{
cout << "passed" << endl;
}
else
{
cout << "failed" << endl;
anyFailed = true;
}
cout << "Testing longitude from ID with known station...";
if (stationDb.stationLongitudeFromID("KAAA") == "089-20-06W")
{
cout << "passed" << endl;
}
else
{
cout << "failed" << endl;
anyFailed = true;
}
cout << "Testing longitude from ID with unknown station...";
if (stationDb.stationLongitudeFromID("KZYY") == "Unknown Station")
{
cout << "passed" << endl;
}
else
{
cout << "failed" << endl;
anyFailed = true;
}
cout << "Testing longitude from ID with known station already loaded...";
if (stationDb.stationLongitudeFromID("KAAA") == "089-20-06W")
{
cout << "passed" << endl;
}
else
{
cout << "failed" << endl;
anyFailed = true;
}
cout << "Testing country from ID with known station...";
if (stationDb.stationCountryFromID("KUGN") == "United States")
{
cout << "passed" << endl;
}
else
{
cout << "failed" << endl;
anyFailed = true;
}
cout << "Testing country from ID with unknown station...";
if (stationDb.stationCountryFromID("KYYY") == "Unknown Station")
{
cout << "passed" << endl;
}
else
{
cout << "failed" << endl;
anyFailed = true;
}
cout << "Testing country from ID with known station already loaded...";
if (stationDb.stationCountryFromID("KUGN") == "United States")
{
cout << "passed" << endl;
}
else
{
cout << "failed" << endl;
anyFailed = true;
}
// If success, return 0, else return 1
if (anyFailed)
{
return 1;
}
else
{
return 0;
}
}
|