blob: d531368c6df405fdf0d10ef390204cd7d820c0af [file] [log] [blame]
Emeric Vigier2f625822012-08-06 11:09:52 -04001// Copyright (C) 2002-2003 Chad C. Yates cyates@uidaho.edu
2//
3// This program is free software; you can redistribute it and/or modify
4// it under the terms of the GNU General Public License as published by
5// the Free Software Foundation; either version 2 of the License, or
6// (at your option) any later version.
7//
8// This program is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11// GNU General Public License for more details.
12//
13// You should have received a copy of the GNU General Public License
14// along with this program; if not, write to the Free Software
15// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16//
17// As a special exception to the GNU General Public License, permission is
18// granted for additional uses of the text contained in its release
19// of Common C++.
20//
21// The exception is that, if you link the Common C++ library with other
22// files to produce an executable, this does not by itself cause the
23// resulting executable to be covered by the GNU General Public License.
24// Your use of that executable is in no way restricted on account of
25// linking the Common C++ library code into it.
26//
27// This exception does not however invalidate any other reasons why
28// the executable file might be covered by the GNU General Public License.
29//
30// This exception applies only to the code released under the
31// name Common C++. If you copy code from other releases into a copy of
32// Common C++, as the General Public License permits, the exception does
33// not apply to the code that you add in this way. To avoid misleading
34// anyone as to the status of such modified files, you must delete
35// this exception notice from them.
36//
37// If you write modifications of your own for Common C++, it is your choice
38// whether to permit this exception to apply to your modifications.
39// If you do not wish that, delete this exception notice.
40
41#include <cppunit/extensions/HelperMacros.h>
42#include <cc++/persist.h>
43#include "SampleObject.h"
44#include <fstream>
45
46using namespace ost;
47
48#define BINARY_BUFFER_SIZE 1000
49#define STL_CONTAINER_SIZE 1000
50
51// support macros to clean things for testing of primitive types
52// tests both primitive and pointer to primitive types
53#define TEST_PRIMITIVE_OUTPUT(type, value) \
54 type test_##type = value; \
55 type* test_##type##p = new type(value); \
56 outputEngine << test_##type; \
57 outputEngine << *test_##type##p;
58
59#define TEST_PRIMITIVE_INPUT(type) \
60 type test2_##type; \
61 type* test2_##type##p = new type; \
62 inputEngine >> test2_##type; \
63 CPPUNIT_ASSERT(test_##type == test2_##type); \
64 inputEngine >> *test2_##type##p; \
65 CPPUNIT_ASSERT(test_##type == *test2_##type##p); \
66 delete test2_##type##p; \
67 delete test_##type##p;
68
69/**
70 * Test Fixture to excercise the Common C++ Persistence engine
71 *
72 * @author Chad C. Yates
73 */
74class EngineTest : public CppUnit::TestFixture
75{
76 CPPUNIT_TEST_SUITE(EngineTest);
77 CPPUNIT_TEST(testPrimitives);
78 CPPUNIT_TEST(testRawBinary);
79 CPPUNIT_TEST(testSTLVector);
80 CPPUNIT_TEST(testSTLDeque);
81 CPPUNIT_TEST(testSTLMap);
82 CPPUNIT_TEST(testComplexObject);
83 //CPPUNIT_TEST(testModeExceptions);
84 CPPUNIT_TEST_SUITE_END();
85
86private:
87 Test complexObject;
88
89public:
90 void setUp();
91 void tearDown();
92
93 /**
94 * Test case for all supported primative types
95 *
96 * @author Chad C. Yates
97 */
98 void testPrimitives();
99
100 /**
101 * Test case for a raw chunk of binary data
102 *
103 * @author Chad C. Yates
104 */
105 void testRawBinary();
106
107 /**
108 * Test case for all an STL Vector
109 *
110 * @author Chad C. Yates
111 */
112 void testSTLVector();
113
114 /**
115 * Test case for all an STL Deque
116 *
117 * @author Chad C. Yates
118 */
119 void testSTLDeque();
120
121 /**
122 * Test case for an STL Map
123 *
124 * @author Chad C. Yates
125 */
126 void testSTLMap();
127
128 /**
129 * Test case for all a complex Object hierarchy derived from BaseObject
130 *
131 * @author Chad C. Yates
132 */
133 void testComplexObject();
134
135 /**
136 * Test case for engine mode exceptions
137 * since the persistence engine does not actually throw exceptions
138 * yet, we can't test for it.
139 *
140 * @author Chad C. Yates
141 */
142 void testModeExceptions();
143};