summaryrefslogtreecommitdiffstats
path: root/reladminif/test/test_databaseif.cc
blob: 46caa5ffdd72fc15cf51af087ae43520dd7b1e44 (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
/*
* This file is part of rasdaman community.
*
* Rasdaman community 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 3 of the License, or
* (at your option) any later version.
*
* Rasdaman community 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with rasdaman community.  If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
rasdaman GmbH.
*
* For more information please see <http://www.rasdaman.org>
* or contact Peter Baumann via <baumann@rasdaman.com>.
*/
/*************************************************************************
 *
 *
 * PURPOSE:
 * test class DatabaseIf.
 *
 *
 * PREREQUISITES:
 * - needs COMPDATE (compilation date) defined, eg. cc -DCOMPDATE=\"`date`\"
 *
 * COMMENTS:
 *
 ***********************************************************************/

static const char rcsid[] = "@(#)reladminif,DatabaseIf: $Id: databaseif.ec,v 1.9 2003/12/27 23:11:43 rasdev Exp $";

using namespace std;

#include <iostream.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "error.hh"
#include "adminif.hh"
#include "databaseif.hh"
#include "externs.h"

#include "raslib/rmdebug.hh"
#define DEBUG_MAIN
#include "debug.hh"


RMINITGLOBALS('C')


// test environment:
#include "testcenter.h"

#define ELLIPSIS "..."
/// test macro for checking error condition, printing result, and aborting on error
#define CHECK(p)  {	cout << "CHECKING " << "p"; \
			if (!(p)) \
			{	cout << TEST_ERROR << endl; \
				return false; \
			} \
			else \
			{ \
				cout << TEST_OK << endl; \
			} \
		  }

/// ObjectBroker: dummy class to satisfy linker; real ObjectBroker functionality never used here.
class ObjectBroker
{
	public:
		void init();
		void deinit();
		bool freeMemory();
};

void ObjectBroker::init()
{
}
void ObjectBroker::deinit()
{
}
bool ObjectBroker::freeMemory()
{
	return true;
}

/// from server/rasserver_main.cc:
char globalConnectId[256];

/// doTest(): run the test cases
/// preconditions:
///	database does NOT yet exist
/// @params:
///	dbname	name of database
/// @returns:
///	true	if all tests succeeded
///	false	if some test failed

bool doTest( const char *dbname )
{
	bool result = false;		// overall test result
	DatabaseIf *db = NULL;		// our test candidate

	try				// capture eny eventual exception for reporting
	{
		// --- (1) good scenario

		cout << "DatabaseIf constructor" << ELLIPSIS << flush;
		db = new DatabaseIf();
		cout << "new state is: " << *db;
		CHECK( db != NULL );

		cout << "create" << ELLIPSIS << endl;
		db->createDB( dbname, NULL, NULL );
		CHECK( db->isConnected() );
		CHECK( db->isOpen() );

		cout << "db open" << ELLIPSIS << endl;
		db->open( dbname );
		CHECK( db->isConnected() );
		CHECK( db->isOpen() );

		cout << "db close" << ELLIPSIS << endl;
		db->close();
		CHECK( db->isConnected() );
		CHECK( db->isOpen() );

		cout << "db destroy" << ELLIPSIS << endl;
		db->destroyDB( dbname );
		CHECK( db->isConnected() );
		CHECK( db->isOpen() );

		result = true;
	}
	// FIXME: what else should be caught explicitly?
	catch(r_Error& myErr)
	{
		cout << "caught r_Error exception #" << myErr.get_errorno() << ": " << myErr.what() << endl;
		result = false;
	}
	catch(bad_alloc)
	{
		cout << "caught bad_alloc exception" << endl;
		result = false;
	}
	catch(...)
	{
		cout << "caught unknown exception" << endl;
		result = false;
	}

	return result;
}

int
main(int argc, char *argv[])
{
	const char *progName = argv[0];	// name of this test program

	int RManDebug2 = 5;		// debug trace settings
	int RManModule = 1;		// dito

	char* dbName = "RASBASE"; 	// default database name
	int result = RC_ERROR;		// overall test exit code
	char *resultText = NULL;	// overall test status string

	// --- parameter evaluation, launch msg
	if (argc == 2)
		dbName = argv[1];
	else if (argc > 2)
	{
		cout << "usage: " << progName << " [dbname]" << endl;
		return( RC_USAGE );
	}
	cout << progName << ", generated on " << COMPDATE << " for rasdaman version " << RMANVERSION << " and base DBMS " << BASEDBSTRING << "; using database '" << dbName << "'" << endl;

	// --- all is fine, let's do the test
	bool allFine = doTest( dbName );

	if (allFine)
	{
		resultText = TEST_OK;
		result = RC_OK;
	}
	else
	{
		resultText = TEST_ERROR;
		result = RC_ERROR;
	}

	// --- done, epilogue
	cout << progName << ": overall test result is " << resultText << endl;

	return( result );
}