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
|
// -*- mode: c++; c-basic-offset:4 -*-
// This file is part of libdap, A C++ implementation of the OPeNDAP Data
// Access Protocol.
// Copyright (c) 2002,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
#include "config.h"
#include <cppunit/TextTestRunner.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/extensions/HelperMacros.h>
//#define DODS_DEBUG
#include "dods-limits.h"
#include "D4EnumDefs.h"
#include "XMLWriter.h"
#include "debug.h"
#include "testFile.h"
#include "run_tests_cppunit.h"
#include "test_config.h"
using namespace CppUnit;
using namespace std;
using namespace libdap;
class D4EnumDefsTest: public TestFixture {
private:
XMLWriter *xml;
D4EnumDefs *d;
D4EnumDef e, e2;
public:
D4EnumDefsTest()
{
}
~D4EnumDefsTest()
{
}
void setUp()
{
d = new D4EnumDefs;
xml = new XMLWriter;
e.set_name("first");
e.set_type(dods_byte_c);
e.add_value("red", 1);
e.add_value("blue", 2);
e2.set_name("second");
e2.set_type(dods_int32_c);
e2.add_value("snow", 0);
e2.add_value("ice", 10000);
}
void tearDown()
{
delete xml;
delete d;
}
// An empty D4Dimensions object prints nothing; the XMLWriter class adds
// a xml doc preface.
void test_print_empty()
{
d->print_dap4(*xml);
string doc = xml->get_doc();
string baseline = read_test_baseline(string(TEST_SRC_DIR) + "/D4-xml/D4EnumDefs_empty.xml");
DBG(cerr << "test_print_empty: doc: " << doc << endl);DBG(cerr << "test_print_empty: baseline: " << baseline << endl);
CPPUNIT_ASSERT(doc == baseline);
}
void test_print_enum_values_only()
{
D4EnumDef e;
e.add_value("red", 1);
e.add_value("blue", 2);
e.print_dap4(*xml);
string doc = xml->get_doc();
string baseline = read_test_baseline(string(TEST_SRC_DIR) + "/D4-xml/D4EnumDefs_values_1.xml");
DBG(cerr << "test_print_enum_values_only: doc: " << doc << endl);DBG(cerr << "test_print_enum_values_only: baseline: " << baseline << endl);
CPPUNIT_ASSERT(doc == baseline);
}
void test_print_1()
{
d->add_enum(&e);
d->print_dap4(*xml);
string doc = xml->get_doc();
string baseline = read_test_baseline(string(TEST_SRC_DIR) + "/D4-xml/D4EnumDefs_1.xml");
DBG(cerr << "test_print_1: doc: " << doc << endl);DBG(cerr << "test_print_1: baseline: " << baseline << endl);
CPPUNIT_ASSERT(doc == baseline);
}
void test_print_2()
{
d->add_enum(&e);
d->add_enum(&e2);
d->print_dap4(*xml);
string doc = xml->get_doc();
string baseline = read_test_baseline(string(TEST_SRC_DIR) + "/D4-xml/D4EnumDefs_2.xml");
DBG(cerr << "test_print_2: doc: " << doc << endl);DBG(cerr << "test_print_2: baseline: " << baseline << endl);
CPPUNIT_ASSERT(doc == baseline);
}
void test_print_insert_enum()
{
d->add_enum(&e);
// "second' winds up before 'first'
D4EnumDefs::D4EnumDefIter i = d->enum_begin();
d->insert_enum(&e2, i);
d->print_dap4(*xml);
string doc = xml->get_doc();
string baseline = read_test_baseline(string(TEST_SRC_DIR) + "/D4-xml/D4EnumDefs_3.xml");
DBG(cerr << "test_print_insert_enum: doc: " << doc << endl);DBG(cerr << "test_print_insert_enum: baseline: " << baseline << endl);
CPPUNIT_ASSERT(doc == baseline);
}
void test_print_assignment()
{
d->add_enum(&e);
d->add_enum(&e2);
D4EnumDefs lhs = *d;
lhs.print_dap4(*xml);
string doc = xml->get_doc();
string baseline = read_test_baseline(string(TEST_SRC_DIR) + "/D4-xml/D4EnumDefs_2.xml");
DBG(cerr << "test_print_assignment: doc: " << doc << endl);DBG(cerr << "test_print_assignment: baseline: " << baseline << endl);
CPPUNIT_ASSERT(doc == baseline);
}
void test_print_copy_ctor()
{
d->add_enum(&e);
d->add_enum(&e2);
D4EnumDefs lhs(*d);
lhs.print_dap4(*xml);
string doc = xml->get_doc();
string baseline = read_test_baseline(string(TEST_SRC_DIR) + "/D4-xml/D4EnumDefs_2.xml");
DBG(cerr << "test_print_copy_ctor: doc: " << doc << endl);DBG(cerr << "test_print_copy_ctor: baseline: " << baseline << endl);
CPPUNIT_ASSERT(doc == baseline);
}
// D4EnumDef::is_valid_enum_value(long long value)
void test_is_valid_enum_value_1()
{
// e is an enum that holds a Byte
// e2 is an enum for int32 values
CPPUNIT_ASSERT_MESSAGE("255 Should be a valid byte value", e.is_valid_enum_value(255));
CPPUNIT_ASSERT_MESSAGE("0 Should be a valid byte value", e.is_valid_enum_value(0));
CPPUNIT_ASSERT_MESSAGE("-1 Should be a valid byte value", !e.is_valid_enum_value(-1));
}
void test_is_valid_enum_value_2()
{
CPPUNIT_ASSERT_MESSAGE("-1 Should be a valid int32 enum value", e2.is_valid_enum_value(-1));
CPPUNIT_ASSERT_MESSAGE("-65536 Should be a valid int32 enum value", e2.is_valid_enum_value(-65536));
CPPUNIT_ASSERT_MESSAGE("65536 Should be a valid int32 enum value", e2.is_valid_enum_value(-65536));
}
void test_is_valid_enum_value_3()
{
CPPUNIT_ASSERT_MESSAGE("DODS_INT_MIN Should be a valid int32 enum value", e2.is_valid_enum_value(DODS_INT_MIN));
CPPUNIT_ASSERT_MESSAGE("DODS_INT_MAX Should be a valid int32 enum value", e2.is_valid_enum_value(DODS_INT_MAX));
}
void test_is_valid_enum_value_4()
{
CPPUNIT_ASSERT_MESSAGE("DODS_UINT_MAX Should not be a valid int32 enum value", !e2.is_valid_enum_value(DODS_UINT_MAX));
}
CPPUNIT_TEST_SUITE (D4EnumDefsTest);
CPPUNIT_TEST (test_print_empty);
CPPUNIT_TEST (test_print_enum_values_only);
CPPUNIT_TEST (test_print_1);
CPPUNIT_TEST (test_print_2);
CPPUNIT_TEST (test_print_insert_enum);
CPPUNIT_TEST (test_print_assignment);
CPPUNIT_TEST (test_print_copy_ctor);
CPPUNIT_TEST (test_is_valid_enum_value_1);
CPPUNIT_TEST (test_is_valid_enum_value_2);
CPPUNIT_TEST (test_is_valid_enum_value_3);
CPPUNIT_TEST (test_is_valid_enum_value_4);
CPPUNIT_TEST_SUITE_END();
};
CPPUNIT_TEST_SUITE_REGISTRATION (D4EnumDefsTest);
int main(int argc, char*argv[])
{
return run_tests<D4EnumDefsTest>(argc, argv) ? 0: 1;
}
|