source: trunk/tests/c/test-nom.c

Last change on this file was 368, checked in by cinc, 17 years ago

Added simple test case for NOMClassMgr

File size: 10.9 KB
Line 
1/* ***** BEGIN LICENSE BLOCK *****
2* Version: CDDL 1.0/LGPL 2.1
3*
4* The contents of this file are subject to the COMMON DEVELOPMENT AND
5* DISTRIBUTION LICENSE (CDDL) Version 1.0 (the "License"); you may not use
6* this file except in compliance with the License. You may obtain a copy of
7* the License at http://www.sun.com/cddl/
8*
9* Software distributed under the License is distributed on an "AS IS" basis,
10* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11* for the specific language governing rights and limitations under the
12* License.
13*
14* The Original Code is "NOM" Netlabs Object Model
15*
16* The Initial Developer of the Original Code is
17* netlabs.org: Chris Wohlgemuth <cinc-ml@netlabs.org>.
18* Portions created by the Initial Developer are Copyright (C) 2007
19* the Initial Developer. All Rights Reserved.
20*
21* Contributor(s):
22*
23* Alternatively, the contents of this file may be used under the terms of
24* the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
25* case the provisions of the LGPL are applicable instead of those above. If
26* you wish to allow use of your version of this file only under the terms of
27* the LGPL, and not to allow others to use your version of this file under
28* the terms of the CDDL, indicate your decision by deleting the provisions
29* above and replace them with the notice and other provisions required by the
30* LGPL. If you do not delete the provisions above, a recipient may use your
31* version of this file under the terms of any one of the CDDL or the LGPL.
32*
33* ***** END LICENSE BLOCK ***** */
34#ifdef __OS2__
35# define INCL_DOSPROCESS
36# define INCL_DOS
37# define INCL_DOSPROFILE
38# define INCL_DOSERRORS
39# include <os2.h>
40#endif /* __OS2__ */
41
42#include <stdio.h>
43#include <stdlib.h>
44#include <string.h>
45
46#ifdef HAVE_IO_H
47# include <io.h>
48#endif
49#ifdef HAVE_UNISTD_H
50# include <unistd.h>
51#endif
52#include <fcntl.h>
53#include <sys/stat.h>
54
55#include <glib.h>
56#include <glib/gprintf.h>
57
58#include "nom.h"
59#include "nomtk.h"
60#include "nomgc.h"
61
62#include "aclass.h"
63#include "bclass.h"
64
65/* For unit test */
66#include "nomarray.h"
67#include "nomstring.h"
68#include "nommethod.h"
69#include "nomtestresult.h"
70#include "testnomobject.h"
71#include "testnomclassmgr.h"
72
73
74#define ULONG_TESTVALUE_1 0xffeeddcc
75#define ULONG_TESTVALUE_2 0x55aa1122
76#define ULONG_TESTVALUE_BCLASS_1 0x50403020
77#define ULONG_TESTVALUE_BCLASS_2 0xf0e0d0c0
78
79AClass* createAClassObject()
80{
81 AClass* aClass;
82
83 aClass=AClassNew();
84
85 if(nomIsObj(aClass))
86 g_message("AClass creation\t\t\t\tOK\n");
87 else
88 g_message("AClass creation\t\t\t\t\tFAILED\n");
89 return aClass;
90}
91
92AClass* createBClassObject()
93{
94 BClass* bClass;
95
96 bClass=BClassNew();
97
98 if(nomIsObj(bClass))
99 g_message("BClass creation\t\t\t\tOK\n");
100 else
101 g_message("BClass creation\t\t\t\t\tFAILED\n");
102 return bClass;
103}
104
105void tstAClassInstanceVarInitValues(AClass * aObject)
106{
107 gulong ulRC;
108
109 g_message("================================================================");
110 g_message("===== Testing init values of instance variables. Must be 0 =====");
111 g_message("================================================================");
112
113 ulRC=_tstQueryUlongVar1(aObject, NULL);
114 g_message("Calling tstQueryUlongVar1():\t%ld\t\t%s", ulRC, (0!=ulRC ? "FAILED" : "OK"));
115 g_assert(0==ulRC);
116
117 ulRC=_tstQueryUlongVar2(aObject, NULL);
118 g_message("Calling tstQueryUlongVar2():\t%ld\t\t%s\n", ulRC, (0!=ulRC ? "FAILED" : "OK"));
119 g_assert(0==ulRC);
120}
121
122
123void tstBClassInstanceVarInitValues(BClass * aObject)
124{
125 gulong ulRC;
126
127 g_message("================================================================");
128 g_message("===== Testing init values of instance variables. Must be 0 =====");
129 g_message("================================================================");
130
131 ulRC=_tstQueryBClassUlongVar1(aObject, NULL);
132 g_message("Calling tstQueryBClassUlongVar1():\t%ld\t\t%s", ulRC, (0!=ulRC ? "FAILED" : "OK"));
133 g_assert(0==ulRC);
134
135 ulRC=_tstQueryBClassUlongVar2(aObject, NULL);
136 g_message("Calling tstQueryBClassUlongVar2():\t%ld\t\t%s\n", ulRC, (0!=ulRC ? "FAILED" : "OK"));
137 g_assert(0==ulRC);
138}
139
140
141void tstSetAClassInstanceVar(AClass * aObject)
142{
143 gulong ulRC;
144
145 g_message("========================================================");
146 g_message("===== Testing setting of AClass instance variables =====");
147 g_message("========================================================");
148 /* Set 1. value */
149 _tstSetUlongVar1(aObject, ULONG_TESTVALUE_1, NULL);
150 ulRC=_tstQueryUlongVar1(aObject, NULL);
151 g_message("Calling tstQueryUlongVar1():\t0x%lx\t\t%s", ulRC, (ULONG_TESTVALUE_1!=ulRC ? "FAILED" : "OK"));
152 g_assert(ULONG_TESTVALUE_1==ulRC);
153
154 ulRC=_tstQueryUlongVar2(aObject, NULL);
155 g_message("Calling tstQueryUlongVar2():\t0x%lx\t\t\t%s\n", ulRC, (0!=ulRC ? "FAILED" : "OK"));
156 g_assert(0==ulRC);
157
158 /* Set 2. value */
159 _tstSetUlongVar2(aObject, ULONG_TESTVALUE_2, NULL);
160 ulRC=_tstQueryUlongVar1(aObject, NULL);
161 g_message("Calling tstQueryUlongVar1():\t0x%lx\t\t%s", ulRC, (ULONG_TESTVALUE_1!=ulRC ? "FAILED" : "OK"));
162 g_assert(ULONG_TESTVALUE_1==ulRC);
163
164 ulRC=_tstQueryUlongVar2(aObject, NULL);
165 g_message("Calling tstQueryUlongVar2():\t0x%lx\t\t%s\n\n", ulRC, (ULONG_TESTVALUE_2!=ulRC ? "FAILED" : "OK"));
166 g_assert(ULONG_TESTVALUE_2==ulRC);
167}
168
169void tstSetBClassInstanceVar(BClass * aObject)
170{
171 gulong ulRC;
172
173 g_message("========================================================");
174 g_message("===== Testing setting of BClass instance variables =====");
175 g_message("========================================================");
176 /* Set 1. value */
177 _tstSetBClassUlongVar1(aObject, ULONG_TESTVALUE_BCLASS_1, NULL);
178
179 /* AClass */
180 ulRC=_tstQueryUlongVar1(aObject, NULL);
181 g_message("Calling tstQueryUlongVar1():\t0x%lx\t\t%s", ulRC, (ULONG_TESTVALUE_1!=ulRC ? "FAILED" : "OK"));
182 g_assert(ULONG_TESTVALUE_1==ulRC);
183 ulRC=_tstQueryUlongVar2(aObject, NULL);
184 g_message("Calling tstQueryUlongVar2():\t0x%lx\t\t%s", ulRC, (ULONG_TESTVALUE_2!=ulRC ? "FAILED" : "OK"));
185 g_assert(ULONG_TESTVALUE_2==ulRC);
186
187 /* BClass*/
188 ulRC=_tstQueryBClassUlongVar1(aObject, NULL);
189 g_message("Calling tstQueryBClassUlongVar1():\t0x%lx\t\t%s", ulRC, (ULONG_TESTVALUE_BCLASS_1!=ulRC ? "FAILED" : "OK"));
190 g_assert(ULONG_TESTVALUE_BCLASS_1==ulRC);
191
192 ulRC=_tstQueryBClassUlongVar2(aObject, NULL);
193 g_message("Calling tstQueryBClassUlongVar2():\t0x%lx\t\t\t%s\n\n", ulRC, (0!=ulRC ? "FAILED" : "OK"));
194 g_assert(0==ulRC);
195
196
197
198 /* Set 2. value */
199 _tstSetBClassUlongVar2(aObject, ULONG_TESTVALUE_BCLASS_2, NULL);
200
201 /* AClass */
202 ulRC=_tstQueryUlongVar1(aObject, NULL);
203 g_message("Calling tstQueryUlongVar1():\t0x%lx\t\t%s", ulRC, (ULONG_TESTVALUE_1!=ulRC ? "FAILED" : "OK"));
204 g_assert(ULONG_TESTVALUE_1==ulRC);
205 ulRC=_tstQueryUlongVar2(aObject, NULL);
206 g_message("Calling tstQueryUlongVar2():\t0x%lx\t\t%s", ulRC, (ULONG_TESTVALUE_2!=ulRC ? "FAILED" : "OK"));
207 g_assert(ULONG_TESTVALUE_2==ulRC);
208
209 /* BClass*/
210 ulRC=_tstQueryBClassUlongVar1(aObject, NULL);
211 g_message("Calling tstQueryBClassUlongVar1():\t0x%lx\t\t%s", ulRC, (ULONG_TESTVALUE_BCLASS_1!=ulRC ? "FAILED" : "OK"));
212 g_assert(ULONG_TESTVALUE_BCLASS_1==ulRC);
213
214 ulRC=_tstQueryBClassUlongVar2(aObject, NULL);
215 g_message("Calling tstQueryBClassUlongVar2():\t0x%lx\t\t%s\n\n", ulRC, (ULONG_TESTVALUE_BCLASS_2!=ulRC ? "FAILED" : "OK"));
216 g_assert(ULONG_TESTVALUE_BCLASS_2==ulRC);
217
218}
219
220
221static void printTestResults(NOMArray* nArray)
222{
223 int a;
224
225 for(a=0; a < NOMArray_length(nArray, NULL) ; a++)
226 {
227 g_message("Test '%s()': %s", _queryString(NOMTestResult_queryName(NOMArray_queryObjectAtIdx(nArray, a, NULL), NULL), NULL),
228 NOMTestResult_success(NOMArray_queryObjectAtIdx(nArray, a, NULL), NULL) ? "Ok" : "Not ok");
229 }
230}
231
232
233/**
234 Main entry point for the idl compiler.
235 */
236int main(int argc, char **argv)
237{
238 NOMClassMgr *NOMClassMgrObject;
239 HREGDLL hReg=NULL;
240 AClass* aObject;
241 BClass* bObject;
242
243 /* Unit test */
244 NOMArray* nArray;
245 TestNomObject* tstNomObject;
246 TestNOMClassMgr* tstNOMClassMgr;
247 int a;
248
249#if 0
250 /* Preload the DLL otherwise it won't be found by the GC registering function */
251 if((rc=DosLoadModule(uchrError, sizeof(uchrError),"nobjtk.dll", &hModuleGC))!=NO_ERROR)
252 {
253 printf("DosLoadmodule for nobjtk.dll failed with rc=0x%x because of module %s.\n", (int)rc, uchrError);
254 return 1;
255 };
256 fprintf(stderr, "DLL handle for nobjtk.dll is: 0x%x\n", (int)hModuleGC);
257#endif
258 nomInitGarbageCollection(NULL);
259
260 /* Register DLLs with the garbage collector */
261 hReg=nomBeginRegisterDLLWithGC();
262 if(NULL==hReg)
263 return 1;
264
265#if 0
266 //g_assert(nomRegisterDLLByName(hReg, "GLIB2.DLL" ));
267 //g_assert(nomRegisterDLLByName(hReg, "GOBJECT2.DLL"));
268 g_assert(nomRegisterDLLByName(hReg, "GMODULE2.DLL"));
269 g_assert(nomRegisterDLLByName(hReg, "GDK2.DLL"));
270 g_assert(nomRegisterDLLByName(hReg, "GDKPIX2.DLL"));
271 g_assert(nomRegisterDLLByName(hReg, "GTK2.DLL" ));
272 g_assert(nomRegisterDLLByName(hReg, "ATK.DLL" ));
273#endif
274 g_assert(nomRegisterDLLByName(hReg, "NOBJTK.DLL"));
275
276 nomEndRegisterDLLWithGC(hReg);
277
278 g_message("NOM test application started.");
279
280 /* Init NOM */
281 NOMClassMgrObject=nomEnvironmentNew();
282
283 g_message("\n");
284 g_message("================================================================");
285 g_message("===== Testing AClass, child of NOMObject =====");
286 g_message("================================================================");
287 /* Try to create an AClass object */
288 aObject=createAClassObject();
289 g_assert(aObject);
290
291 /* -- Call methods on the object --- */
292 tstAClassInstanceVarInitValues(aObject);
293 tstSetAClassInstanceVar(aObject);
294
295 g_message("================================================================");
296 g_message("===== Testing BClass, child of AClass =====");
297 g_message("================================================================");
298 /* Try to create an AClass object */
299 bObject=createBClassObject();
300 g_assert(bObject);
301
302 tstAClassInstanceVarInitValues(bObject);
303 tstBClassInstanceVarInitValues(bObject);
304
305 tstSetAClassInstanceVar(bObject);
306 tstSetBClassInstanceVar(bObject);
307
308 nomPrintf("\n");
309 g_message("================================================================");
310 g_message("===== Testing NOMObject base class =====");
311 g_message("================================================================");
312 tstNomObject=TestNomObjectNew();
313 _setClassMgrObject(tstNomObject, NOMClassMgrObject, NULL);
314 nArray=_runTests(tstNomObject, NULL);
315 nomPrintf("\n");
316 printTestResults(nArray);
317
318 nomPrintf("\n");
319 g_message("================================================================");
320 g_message("===== Testing NOMClassMgr base class =====");
321 g_message("================================================================");
322 tstNOMClassMgr=TestNOMClassMgrNew();
323 _setClassMgrObject(tstNOMClassMgr, NOMClassMgrObject, NULL);
324 nArray=_runTests(tstNOMClassMgr, NULL);
325 nomPrintf("\n");
326 printTestResults(nArray);
327
328 return 0;
329};
330
331
332
333
334
335
336
337
Note: See TracBrowser for help on using the repository browser.