File: test_text_file.txt

package info (click to toggle)
libdap 3.20.11-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 24,568 kB
  • sloc: cpp: 50,809; sh: 41,536; xml: 23,511; ansic: 20,030; yacc: 2,508; exp: 1,544; makefile: 990; lex: 309; perl: 52; fortran: 8
file content (370 lines) | stat: -rw-r--r-- 11,473 bytes parent folder | download | duplicates (9)
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370

// -*- mode: c++; c-basic-offset:4 -*-

// This file is part of libdap, A C++ implementation of the OPeNDAP Data
// Access Protocol.

// Copyright (c) 2003 OPeNDAP, Inc.
// Author: James Gallagher <jgallagher@opendap.org>
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library 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
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.

// Tests for the AISMerge class.

#include <cppunit/TextTestRunner.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/extensions/HelperMacros.h>

//#define DODS_DEBUG

#include "Connect.h"
#include "AISMerge.h"
#include "debug.h"
#include <test_config.h>

#include "testFile.h"

using namespace CppUnit;

namespace libdap
{

class AISMergeTest:public TestFixture {
  private:
    AISMerge * ais_merge;

    static string fnoc1, fnoc2, fnoc3, bears, coads, three_fnoc;
    static string fnoc1_ais, fnoc2_ais, digit_ais, fnoc3_das;

    static string fnoc1_ais_string, bears_1_ais_string, coads_ais_string;
    static string fnoc1_merge_ais, fnoc2_merge_ais, fnoc3_merge_ais;
    static string three_fnoc_merge_ais, starts_with_number_ais_string;

    string dump2string(FILE * res) {
        string stuff = "";
        char line[256];
        while (!feof(res) && !ferror(res)
               && fgets(&line[0], 256, res) != 0)
             stuff += line;

         return stuff;
  } public:
     AISMergeTest() {
    }
    ~AISMergeTest() {
    }

    void setUp() {
        ais_merge = new AISMerge("ais_testsuite/ais_database.xml");
    }

    void tearDown() {
        delete ais_merge;
        ais_merge = 0;
    }

    CPPUNIT_TEST_SUITE(AISMergeTest);

    CPPUNIT_TEST(get_ais_resource_test);
    CPPUNIT_TEST(merge_test);

    CPPUNIT_TEST_SUITE_END();

    void get_ais_resource_test() {
        try {
            ResourceVector rv = ais_merge->d_ais_db.get_resource(fnoc1);
            Response *res = ais_merge->get_ais_resource(rv[0].get_url());
            string stuff = dump2string(res->get_stream());
            DBG(cerr << "AIS Resource: " << stuff << endl);
            CPPUNIT_ASSERT(stuff.find(fnoc1_ais_string)
                           != string::npos);

            rv = ais_merge->d_ais_db.get_resource(coads);
            res = ais_merge->get_ais_resource(rv[0].get_url());
            CPPUNIT_ASSERT(dump2string(res->get_stream()).
                           find(coads_ais_string)
                           != string::npos);

            rv = ais_merge->d_ais_db.get_resource(three_fnoc);
            res = ais_merge->get_ais_resource(rv[0].get_url());
            CPPUNIT_ASSERT(dump2string(res->get_stream()).
                           find(starts_with_number_ais_string)
                           != string::npos);
        }
        catch(Error & e) {
            cerr << "Error: " << e.get_error_message() << endl;
            // If the exception is Not Found then this is not an error; there
            // are many reasons why the resource might not be found...
            if (e.get_error_message().find("Not Found:") == string::npos)
                CPPUNIT_ASSERT(!"Error");
        }
    }

    void merge_test() {
        try {
            Connect *conn;
            DAS das;
            string sof;

            conn = new Connect(fnoc1);  // test overwrite (default)
            conn->request_das(das);
            ais_merge->merge(fnoc1, das);
            FILE2string(sof, of, das.print(of));
            DBG(cerr << "Merged fnoc1 DAS: " << sof << endl);
            CPPUNIT_ASSERT(sof.find(fnoc1_merge_ais) != string::npos);

            delete conn;
            conn = 0;
            das.erase();

            conn = new Connect(fnoc2);  // test replace
            conn->request_das(das);
            ais_merge->merge(fnoc2, das);
            FILE2string(sof, of, das.print(of));
            CPPUNIT_ASSERT(sof.find(fnoc2_merge_ais) != string::npos);

            delete conn;
            conn = 0;
            das.erase();

            conn = new Connect(fnoc3);  // test fallback
            conn->request_das(das);     // with a non-empty das, nothing happens
            ais_merge->merge(fnoc3, das);
            FILE2string(sof, of, das.print(of));
            CPPUNIT_ASSERT(sof.find(fnoc3_das) != string::npos);

            das.erase();        // empty das, should add attributes
            ais_merge->merge(fnoc3, das);
            FILE2string(sof, of, das.print(of));
            CPPUNIT_ASSERT(sof.find(fnoc3_merge_ais) != string::npos);

            conn = new Connect(three_fnoc);     // test regexp
            conn->request_das(das);     // with a non-empty das, nothing happens
            ais_merge->merge(three_fnoc, das);
            FILE2string(sof, of, das.print(of));
            CPPUNIT_ASSERT(sof.find(three_fnoc_merge_ais)
                           != string::npos);
        }
        catch(Error & e) {
            cerr << "Error: " << e.get_error_message() << endl;
            if (e.get_error_message().find("Not Found:") == string::npos)
                CPPUNIT_ASSERT(!"Error");
        }
    }
};

string AISMergeTest::fnoc1 =
    "http://test.opendap.org/opendap/data/nc/fnoc1.nc";
string AISMergeTest::fnoc2 =
    "http://test.opendap.org/opendap/data/nc/fnoc2.nc";
string AISMergeTest::fnoc3 =
    "http://test.opendap.org/opendap/data/nc/fnoc3.nc";
string AISMergeTest::bears =
    "http://test.opendap.org/opendap/data/nc/bears.nc";
string AISMergeTest::coads =
    "http://test.opendap.org/opendap/data/nc/coads_climatology.nc";
string AISMergeTest::three_fnoc =
    "http://test.opendap.org/opendap/data/nc/3fnoc.nc";

string AISMergeTest::fnoc1_ais =
    "http://test.opendap.org/ais/fnoc1.nc.das";
string AISMergeTest::fnoc2_ais =
    "http://test.opendap.org/ais/fnoc2.nc.das";
string AISMergeTest::digit_ais = (string)TEST_SRC_DIR + "/ais_testsuite/starts_with_number.das";

string AISMergeTest::fnoc1_ais_string = "Attributes {\n\
    u {\n\
	String DODS_Name \"UWind\";\n\
    }\n\
    v {\n\
	String DODS_Name \"VWind\";\n\
    }\n\
}";

string AISMergeTest::bears_1_ais_string = "Attributes {\n\
    bears {\n\
	String longname \"Test data\";\n\
    }\n\
}";

string AISMergeTest::coads_ais_string = "Attributes {\n\
    COADSX {\n\
        String long_name \"Longitude\";\n\
    }\n\
}";

string AISMergeTest::starts_with_number_ais_string = "Attributes {\n\
    NC_GLOBAL {\n\
        String AIS_Test_info \"This dataset's name starts with a digit.\";\n\
    }\n\
}";

string AISMergeTest::fnoc3_das = "Attributes {\n\
    u {\n\
        String units \"meter per second\";\n\
        String long_name \"Vector wind eastward component\";\n\
        String missing_value \"-32767\";\n\
        String scale_factor \"0.005\";\n\
    }\n\
    v {\n\
        String units \"meter per second\";\n\
        String long_name \"Vector wind northward component\";\n\
        String missing_value \"-32767\";\n\
        String scale_factor \"0.005\";\n\
    }\n\
    lat {\n\
        String units \"degree North\";\n\
    }\n\
    lon {\n\
        String units \"degree East\";\n\
    }\n\
    time {\n\
        String units \"hours from base_time\";\n\
    }\n\
    NC_GLOBAL {\n\
        String base_time \"88-245-00:00:00\";\n\
        String title \" FNOC UV wind components from 1988-245 to 1988-247.\";\n\
    }\n\
    DODS_EXTRA {\n\
        String Unlimited_Dimension \"time_a\";\n\
    }\n\
}";

string AISMergeTest::fnoc1_merge_ais = "Attributes {\n\
    u {\n\
        String units \"meter per second\";\n\
        String long_name \"Vector wind eastward component\";\n\
        String missing_value \"-32767\";\n\
        String scale_factor \"0.005\";\n\
        String DODS_Name \"UWind\", \"UWind\";\n\
        Byte b 128;\n\
        Int32 i 32000;\n\
        Url WOA01 \"http://localhost/junk\";\n\
    }\n\
    v {\n\
        String units \"meter per second\";\n\
        String long_name \"Vector wind northward component\";\n\
        String missing_value \"-32767\";\n\
        String scale_factor \"0.005\";\n\
        String DODS_Name \"VWind\", \"VWind\";\n\
    }\n\
    lat {\n\
        String units \"degree North\";\n\
    }\n\
    lon {\n\
        String units \"degree East\";\n\
    }\n\
    time {\n\
        String units \"hours from base_time\";\n\
    }\n\
    NC_GLOBAL {\n\
        String base_time \"88- 10-00:00:00\";\n\
        String title \" FNOC UV wind components from 1988- 10 to 1988- 13.\";\n\
    }\n\
    DODS_EXTRA {\n\
        String Unlimited_Dimension \"time_a\";\n\
    }\n\
}";

string AISMergeTest::fnoc2_merge_ais = "Attributes {\n\
    u {\n\
        String units \"meter per second\";\n\
        String long_name \"UWind\";\n\
    }\n\
    v {\n\
        String units \"meter per second\";\n\
        String long_name \"VWind\";\n\
    }\n\
    lat {\n\
        String units \"degree North\";\n\
        String long_name \"Latitude\";\n\
    }\n\
    lon {\n\
        String units \"degree East\";\n\
        String long_name \"Longitude\";\n\
    }\n\
    time {\n\
    }\n\
    NC_GLOBAL {\n\
    }\n\
    DODS_EXTRA {\n\
    }\n\
}";

string AISMergeTest::fnoc3_merge_ais = "Attributes {\n\
    u {\n\
        String long_name \"UWind\";\n\
    }\n\
    v {\n\
        String long_name \"VWind\";\n\
    }\n\
    lat {\n\
        String long_name \"Latitude\";\n\
    }\n\
    lon {\n\
        String long_name \"Longitude\";\n\
    }\n\
}";

string AISMergeTest::three_fnoc_merge_ais = "Attributes {\n\
    u {\n\
        String long_name \"UWind\", \"Vector wind eastward component\";\n\
        String units \"meter per second\";\n\
        String missing_value \"-32767\";\n\
        String scale_factor \"0.005\";\n\
    }\n\
    v {\n\
        String long_name \"VWind\", \"Vector wind northward component\";\n\
        String units \"meter per second\";\n\
        String missing_value \"-32767\";\n\
        String scale_factor \"0.005\";\n\
    }\n\
    lat {\n\
        String long_name \"Latitude\";\n\
        String units \"degree North\";\n\
    }\n\
    lon {\n\
        String long_name \"Longitude\";\n\
        String units \"degree East\";\n\
    }\n\
    time {\n\
        String units \"hours from base_time\";\n\
    }\n\
    NC_GLOBAL {\n\
        String base_time \"88-245-00:00:00\";\n\
        String title \" FNOC UV wind components from 1988-245 to 1988-247.\";\n\
        String AIS_Test_info \"This dataset's name starts with a digit.\";\n\
    }\n\
    DODS_EXTRA {\n\
        String Unlimited_Dimension \"time_a\";\n\
    }\n\
}";

CPPUNIT_TEST_SUITE_REGISTRATION(AISMergeTest);

} // namespace libdap

int main(int, char **)
{
    CppUnit::TextTestRunner runner;
    runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());

    bool wasSuccessful = runner.run("", false);

    return wasSuccessful ? 0 : 1;
}