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
|
// -*- mode: c++; c-basic-offset:4 -*-
// This file is part of libdap, A C++ implementation of the OPeNDAP Data
// Access Protocol.
// Copyright (c) 2013 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.
#include "config.h"
#include <cstring>
#include <iostream>
#include <fstream>
#include <cppunit/TextTestRunner.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/extensions/HelperMacros.h>
#include "DMR.h"
#include "D4Group.h"
#include "XMLWriter.h"
#include "Array.h"
#include "D4BaseTypeFactory.h"
#include "D4ParserSax2.h"
#include "D4Maps.h"
#include "InternalErr.h"
#include "debug.h"
#include "run_tests_cppunit.h"
#include "test_config.h"
#include "testFile.h"
using namespace CppUnit;
using namespace std;
using namespace libdap;
static bool parser_debug = false;
class D4ParserSax2Test: public TestFixture {
private:
D4ParserSax2 *parser;
DMR *dmr;
D4BaseTypeFactory *btf;
XMLWriter *xml;
public:
D4ParserSax2Test() :
parser(0), dmr(0), btf(0), xml(0)
{
}
~D4ParserSax2Test()
{
}
void setUp()
{
parser = new D4ParserSax2();
btf = new D4BaseTypeFactory;
dmr = new DMR(btf);
xml = new XMLWriter(" ");
}
void tearDown()
{
delete parser;
delete dmr;
delete btf;
delete xml;
}
void compare_dmr_round_trip(const string &src, const string &bl)
{
try {
string name = string(TEST_SRC_DIR) + src;
ifstream ifile(name.c_str(), ifstream::in);
if (!ifile) throw InternalErr(__FILE__, __LINE__, "Could not open file: " + src);
parser->intern(ifile, dmr, parser_debug);
ifile.close();
dmr->print_dap4(*xml, false);
string doc = xml->get_doc();
string baseline = read_test_baseline(string(TEST_SRC_DIR) + bl);
DBG(cerr << "RESULT DMR: " << doc << endl);
CPPUNIT_ASSERT(doc == baseline);
}
catch (Error &e) {
CPPUNIT_FAIL(e.get_error_message().c_str());
}
}
void compare_dmr_round_trip_string_version(const string &src, const string &bl)
{
try {
string document = read_test_baseline(string(TEST_SRC_DIR) + src);
DBG(cerr << "Parsing: " << document << endl);
parser->intern(document, dmr, parser_debug);
dmr->print_dap4(*xml, false);
string doc = xml->get_doc();
string baseline = read_test_baseline(string(TEST_SRC_DIR) + bl);
DBG(cerr << "RESULT DMR: " << doc << endl);
CPPUNIT_ASSERT(doc == baseline);
}
catch (Error &e) {
CPPUNIT_FAIL(e.get_error_message().c_str());
}
}
void test_empty_dmr()
{
compare_dmr_round_trip("/D4-xml/DMR_empty.xml", "/D4-xml/DMR_empty_baseline.xml");
}
void test_empty_dmr_string_version()
{
compare_dmr_round_trip_string_version("/D4-xml/DMR_empty.xml", "/D4-xml/DMR_empty_baseline.xml");
}
void test_attribute_def()
{
compare_dmr_round_trip("/D4-xml/DMR_0.xml", "/D4-xml/DMR_0_baseline.xml");
}
void test_attribute_def_string_version()
{
compare_dmr_round_trip_string_version("/D4-xml/DMR_0.xml", "/D4-xml/DMR_0_baseline.xml");
}
void test_nested_attribute_def()
{
compare_dmr_round_trip("/D4-xml/DMR_0.1.xml", "/D4-xml/DMR_0.1_baseline.xml");
}
void test_dimension_def()
{
compare_dmr_round_trip("/D4-xml/DMR_1.xml", "/D4-xml/DMR_1_baseline.xml");
}
void test_enum_def()
{
compare_dmr_round_trip("/D4-xml/DMR_2.xml", "/D4-xml/DMR_2_baseline.xml");
}
void test_enum_def2()
{
compare_dmr_round_trip("/D4-xml/DMR_2.1.xml", "/D4-xml/DMR_2.1_baseline.xml");
}
void test_simple_var_def()
{
compare_dmr_round_trip("/D4-xml/DMR_3.xml", "/D4-xml/DMR_3_baseline.xml");
}
void test_simple_var_with_attributes_def()
{
compare_dmr_round_trip("/D4-xml/DMR_3.1.xml", "/D4-xml/DMR_3.1_baseline.xml");
}
void test_array_var_def()
{
compare_dmr_round_trip("/D4-xml/DMR_3.2.xml", "/D4-xml/DMR_3.2_baseline.xml");
}
void test_array_var_def2()
{
compare_dmr_round_trip("/D4-xml/DMR_3.3.xml", "/D4-xml/DMR_3.3_baseline.xml");
}
void test_array_var_def3()
{
compare_dmr_round_trip("/D4-xml/DMR_3.4.xml", "/D4-xml/DMR_3.4_baseline.xml");
}
void test_array_var_def4()
{
compare_dmr_round_trip("/D4-xml/DMR_3.5.xml", "/D4-xml/DMR_3.5_baseline.xml");
}
void test_array_var_def4_string_version()
{
compare_dmr_round_trip_string_version("/D4-xml/DMR_3.5.xml", "/D4-xml/DMR_3.5_baseline.xml");
}
void test_all_simple_var_def()
{
compare_dmr_round_trip("/D4-xml/DMR_4.xml", "/D4-xml/DMR_4_baseline.xml");
}
void test_opaque_var_def()
{
compare_dmr_round_trip("/D4-xml/DMR_4.1.xml", "/D4-xml/DMR_4.1_baseline.xml");
}
void test_structure_def()
{
compare_dmr_round_trip("/D4-xml/DMR_5.xml", "/D4-xml/DMR_5_baseline.xml");
}
void test_structure_with_attributes_def()
{
compare_dmr_round_trip("/D4-xml/DMR_5.1.xml", "/D4-xml/DMR_5.1_baseline.xml");
}
void test_structure_with_attributes_def_string_version()
{
compare_dmr_round_trip_string_version("/D4-xml/DMR_5.1.xml", "/D4-xml/DMR_5.1_baseline.xml");
}
void test_group_def()
{
compare_dmr_round_trip("/D4-xml/DMR_6.xml", "/D4-xml/DMR_6_baseline.xml");
}
void test_group_with_attributes_def()
{
compare_dmr_round_trip("/D4-xml/DMR_6.1.xml", "/D4-xml/DMR_6.1_baseline.xml");
}
void test_group_with_enums_def()
{
compare_dmr_round_trip("/D4-xml/DMR_6.2.xml", "/D4-xml/DMR_6.2_baseline.xml");
}
void test_group_with_attributes_def_string_version()
{
compare_dmr_round_trip_string_version("/D4-xml/DMR_6.1.xml", "/D4-xml/DMR_6.1_baseline.xml");
}
void test_array_1()
{
compare_dmr_round_trip_string_version("/D4-xml/DMR_7.xml", "/D4-xml/DMR_7_baseline.xml");
}
void test_array_2()
{
compare_dmr_round_trip_string_version("/D4-xml/DMR_7.1.xml", "/D4-xml/DMR_7.1_baseline.xml");
}
void test_array_3()
{
compare_dmr_round_trip_string_version("/D4-xml/DMR_7.2.xml", "/D4-xml/DMR_7.2_baseline.xml");
}
void test_array_4()
{
compare_dmr_round_trip_string_version("/D4-xml/DMR_7.3.xml", "/D4-xml/DMR_7.3_baseline.xml");
}
void test_array_5()
{
compare_dmr_round_trip_string_version("/D4-xml/DMR_7.4.xml", "/D4-xml/DMR_7.4_baseline.xml");
}
void test_array_6()
{
compare_dmr_round_trip_string_version("/D4-xml/DMR_7.5.xml", "/D4-xml/DMR_7.5_baseline.xml");
}
void test_map_1()
{
compare_dmr_round_trip_string_version("/D4-xml/DMR_8.xml", "/D4-xml/DMR_8_baseline.xml");
// NB: dmr is global
Array *b1 = dynamic_cast<Array*>(dmr->root()->var("b1"));
CPPUNIT_ASSERT(b1 && b1->name() == "b1");
Array *x = dynamic_cast<Array*>(dmr->root()->var("x")); // this is the map
CPPUNIT_ASSERT(x && x->name() == "x");
D4Maps::D4MapsIter m = b1->maps()->map_begin(); // there's only one map...
CPPUNIT_ASSERT((*m)->name() == "/x");
CPPUNIT_ASSERT((*m)->array() == x);
CPPUNIT_ASSERT((*m)->parent() == b1);
}
CPPUNIT_TEST_SUITE (D4ParserSax2Test);
CPPUNIT_TEST (test_empty_dmr);
CPPUNIT_TEST (test_dimension_def);
CPPUNIT_TEST (test_attribute_def);
CPPUNIT_TEST (test_nested_attribute_def);
CPPUNIT_TEST (test_enum_def);
CPPUNIT_TEST (test_enum_def2);
CPPUNIT_TEST (test_simple_var_def);
CPPUNIT_TEST (test_simple_var_with_attributes_def);
CPPUNIT_TEST (test_array_var_def);
CPPUNIT_TEST (test_array_var_def2);
CPPUNIT_TEST (test_array_var_def3);
CPPUNIT_TEST (test_array_var_def4);
CPPUNIT_TEST (test_all_simple_var_def);
CPPUNIT_TEST (test_opaque_var_def);
CPPUNIT_TEST (test_structure_def);
CPPUNIT_TEST (test_structure_with_attributes_def);
CPPUNIT_TEST (test_group_def);
CPPUNIT_TEST (test_group_with_attributes_def);
CPPUNIT_TEST (test_group_with_enums_def);
CPPUNIT_TEST (test_empty_dmr_string_version);
CPPUNIT_TEST (test_attribute_def_string_version);
CPPUNIT_TEST (test_group_with_attributes_def_string_version);
CPPUNIT_TEST (test_structure_with_attributes_def_string_version);
CPPUNIT_TEST (test_array_var_def4_string_version);
CPPUNIT_TEST (test_array_1);
CPPUNIT_TEST (test_array_2);
CPPUNIT_TEST (test_array_3);
CPPUNIT_TEST (test_array_4);
CPPUNIT_TEST (test_array_5);
CPPUNIT_TEST (test_array_6);
CPPUNIT_TEST (test_map_1);
CPPUNIT_TEST_SUITE_END();
};
CPPUNIT_TEST_SUITE_REGISTRATION (D4ParserSax2Test);
int main(int argc, char*argv[])
{
return run_tests<D4ParserSax2Test>(argc, argv) ? 0: 1;
}
|