File: D4SequenceTest.cc

package info (click to toggle)
libdap 3.18.2-2%2Bdeb9u1
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 18,808 kB
  • sloc: sh: 54,436; cpp: 46,087; ansic: 16,793; xml: 2,730; yacc: 2,452; exp: 1,544; makefile: 1,001; lex: 305; perl: 52; fortran: 8
file content (246 lines) | stat: -rw-r--r-- 7,121 bytes parent folder | download
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

// -*- 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 <cppunit/TextTestRunner.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/extensions/HelperMacros.h>

#include <string>
#include <sstream>

//#define DODS_DEBUG

#include "DMR.h"
#include "D4Group.h"
#include "D4RValue.h"
#include "D4FilterClause.h"

#include "../tests/D4TestTypeFactory.h"
#include "../tests/TestD4Sequence.h"
#include "../tests/TestInt32.h"
#include "../tests/TestStr.h"
#include "../tests/TestFloat32.h"

#include "testFile.h"
#include "test_config.h"

#include "GNURegex.h"
#include "GetOpt.h"
#include "debug.h"

static bool debug = false;

#undef DBG
#define DBG(x) do { if (debug) (x); } while(false);

using namespace CppUnit;
using namespace std;

int test_variable_sleep_interval;

const static string prefix = string(TEST_SRC_DIR) + "/D4-type-testsuite/";

const static string s_txt = "TestD4Sequence_s.txt";
const static string one_clause_txt = "TestD4Sequence_one_clause.txt";
const static string two_clause_txt = "TestD4Sequence_two_clause.txt";

namespace libdap
{

class D4SequenceTest : public TestFixture {
private:
    TestD4Sequence *s;

public:
    D4SequenceTest() : s(0) {}
    ~D4SequenceTest() {}

    void setUp() {
        // Set up a simple sequence. Used to test ctor, assigment, et cetera.
        s = new TestD4Sequence("s");
        s->add_var_nocopy(new TestInt32("i32"));
        s->add_var_nocopy(new TestStr("str"));
        s->add_var_nocopy(new TestFloat32("f32"));
        s->set_series_values(true);
        s->set_send_p(true);
        s->set_length(7);
    }

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

    void ctor_test() {
        s->intern_data();
        CPPUNIT_ASSERT(s->length() == 7);

        ostringstream oss;
        s->output_values(oss);

        DBG(cerr << "s: " << oss.str() << endl);
        DBG(cerr << "Baseline: " << readTestBaseline(prefix + s_txt) << endl);

        CPPUNIT_ASSERT(oss.str() == readTestBaseline(prefix + s_txt));
    }

    void assignment_test() {
        TestD4Sequence ts = *s;
        ts.intern_data();
        CPPUNIT_ASSERT(ts.length() == 7);

        ostringstream oss;
        ts.output_values(oss);

        DBG(cerr << "ts: " << oss.str() << endl);
        //CPPUNIT_ASSERT(oss.str() == readTestBaseline(prefix + s_txt));
    }

    void copy_ctor_test() {
        unique_ptr<TestD4Sequence> ts(new TestD4Sequence(*s));
        ts->intern_data();

        CPPUNIT_ASSERT(ts->length() == 7);

        ostringstream oss;
        ts->output_values(oss);

        DBG(cerr << "ts: " << oss.str() << endl);
        //CPPUNIT_ASSERT(oss.str() == readTestBaseline(prefix + s_txt));
    }

    void one_clause_test() {
        D4RValue *arg1 = new D4RValue(s->var("i32"));
        D4RValue *arg2 = new D4RValue((long long)1024);
        s->clauses().add_clause(new D4FilterClause(D4FilterClause::equal, arg1, arg2));

        s->intern_data();

        DBG(cerr << "one_clause_test, s->length(): " << s->length() << endl);

        ostringstream oss;
        s->output_values(oss);

        DBG(cerr << "one_clause_test, s: " << oss.str() << endl);
        CPPUNIT_ASSERT(s->length() == 1);

        CPPUNIT_ASSERT(oss.str() == readTestBaseline(prefix + one_clause_txt));
    }


    void two_clause_test() {
        D4RValue *arg1 = new D4RValue(s->var("i32"));
        D4RValue *arg2 = new D4RValue((long long)1024);
        s->clauses().add_clause(new D4FilterClause(D4FilterClause::greater_equal, arg1, arg2));

        D4RValue *arg1_2 = new D4RValue(s->var("i32"));
        D4RValue *arg2_2 = new D4RValue((long long)1048576);
        s->clauses().add_clause(new D4FilterClause(D4FilterClause::less_equal, arg1_2, arg2_2));

        s->intern_data();

        DBG(cerr << "two_clause_test, s->length(): " << s->length() << endl);

        ostringstream oss;
        s->output_values(oss);

        DBG(cerr << "two_clause_test, s: " << oss.str() << endl);

        CPPUNIT_ASSERT(s->length() == 3);

        CPPUNIT_ASSERT(oss.str() == readTestBaseline(prefix + two_clause_txt));
    }

    void two_variable_test() {
        D4RValue *arg1 = new D4RValue(s->var("i32"));
        D4RValue *arg2 = new D4RValue((long long)1024);
        s->clauses().add_clause(new D4FilterClause(D4FilterClause::greater_equal, arg1, arg2));

        D4RValue *arg1_2 = new D4RValue(s->var("f32"));
        D4RValue *arg2_2 = new D4RValue((long long)0.0);
        s->clauses().add_clause(new D4FilterClause(D4FilterClause::less, arg1_2, arg2_2));

        s->intern_data();

        DBG(cerr << "two_variable_test, s->length(): " << s->length() << endl);

        ostringstream oss;
        s->output_values(oss);

        DBG(cerr << "two_variable_test, s: " << oss.str() << endl);

        CPPUNIT_ASSERT(s->length() == 1);
        // ...just happens to be hte same baseline file at one_clause_test()
        CPPUNIT_ASSERT(oss.str() == readTestBaseline(prefix + one_clause_txt));
    }

    CPPUNIT_TEST_SUITE( D4SequenceTest );

    CPPUNIT_TEST(ctor_test);
    CPPUNIT_TEST(assignment_test);
    CPPUNIT_TEST(copy_ctor_test);

    CPPUNIT_TEST(one_clause_test);
    CPPUNIT_TEST(two_clause_test);
    CPPUNIT_TEST(two_variable_test);

    CPPUNIT_TEST_SUITE_END();
};

CPPUNIT_TEST_SUITE_REGISTRATION(D4SequenceTest);

}

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

    GetOpt getopt(argc, argv, "d");
    int option_char;
    while ((option_char = getopt()) != -1)
        switch (option_char) {
        case 'd':
            debug = 1;  // debug is a static global
            break;
        default:
            break;
        }

    bool wasSuccessful = true;
    string test = "";
    int i = getopt.optind;
    if (i == argc) {
        // run them all
        wasSuccessful = runner.run("");
    }
    else {
        while (i < argc) {
            test = string("libdap::D4SequenceTest::") + argv[i++];

            wasSuccessful = wasSuccessful && runner.run(test);
        }
    }

    return wasSuccessful ? 0 : 1;
}