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

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

Fixed minor calculation error when reporting

  • Property svn:executable set to *
File size: 10.1 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#define MEMSIZE 17
66#define NUMALLOCS 250
67
68#define ULONG_TESTVALUE_1 0xffeeddcc
69#define ULONG_TESTVALUE_2 0x55aa1122
70#define ULONG_TESTVALUE_BCLASS_1 0x50403020
71#define ULONG_TESTVALUE_BCLASS_2 0xf0e0d0c0
72
73AClass* createAClassObject()
74{
75 AClass* aClass;
76
77 aClass=AClassNew();
78
79 if(nomIsObj(aClass))
80 g_message("AClass creation\t\t\t\tOK");
81 else
82 g_message("AClass creation\t\t\t\t\tFAILED\n");
83 return aClass;
84}
85
86AClass* createBClassObject()
87{
88 BClass* bClass;
89
90 bClass=BClassNew();
91
92 if(nomIsObj(bClass))
93 g_message("BClass creation\t\t\t\tOK\n");
94 else
95 g_message("BClass creation\t\t\t\t\tFAILED\n");
96 return bClass;
97}
98
99void tstAClassInstanceVarInitValues(AClass * aObject)
100{
101 gulong ulRC;
102
103 g_message("================================================================");
104 g_message("===== Testing init values of instance variables. Must be 0 =====");
105 g_message("================================================================");
106
107 ulRC=_tstQueryUlongVar1(aObject, NULL);
108 g_message("Calling tstQueryUlongVar1():\t%ld\t\t%s", ulRC, (0!=ulRC ? "FAILED" : "OK"));
109 g_assert(0==ulRC);
110
111 ulRC=_tstQueryUlongVar2(aObject, NULL);
112 g_message("Calling tstQueryUlongVar2():\t%ld\t\t%s\n", ulRC, (0!=ulRC ? "FAILED" : "OK"));
113 g_assert(0==ulRC);
114}
115
116
117void tstBClassInstanceVarInitValues(BClass * aObject)
118{
119 gulong ulRC;
120
121 g_message("================================================================");
122 g_message("===== Testing init values of instance variables. Must be 0 =====");
123 g_message("================================================================");
124
125 ulRC=_tstQueryBClassUlongVar1(aObject, NULL);
126 g_message("Calling tstQueryBClassUlongVar1():\t%ld\t\t%s", ulRC, (0!=ulRC ? "FAILED" : "OK"));
127 g_assert(0==ulRC);
128
129 ulRC=_tstQueryBClassUlongVar2(aObject, NULL);
130 g_message("Calling tstQueryBClassUlongVar2():\t%ld\t\t%s\n", ulRC, (0!=ulRC ? "FAILED" : "OK"));
131 g_assert(0==ulRC);
132}
133
134
135void tstSetAClassInstanceVar(AClass * aObject)
136{
137 gulong ulRC;
138
139 g_message("========================================================");
140 g_message("===== Testing setting of AClass instance variables =====");
141 g_message("========================================================");
142 /* Set 1. value */
143 _tstSetUlongVar1(aObject, ULONG_TESTVALUE_1, NULL);
144 ulRC=_tstQueryUlongVar1(aObject, NULL);
145 g_message("Calling tstQueryUlongVar1():\t0x%lx\t\t%s", ulRC, (ULONG_TESTVALUE_1!=ulRC ? "FAILED" : "OK"));
146 g_assert(ULONG_TESTVALUE_1==ulRC);
147
148 ulRC=_tstQueryUlongVar2(aObject, NULL);
149 g_message("Calling tstQueryUlongVar2():\t0x%lx\t\t\t%s\n", ulRC, (0!=ulRC ? "FAILED" : "OK"));
150 g_assert(0==ulRC);
151
152 /* Set 2. value */
153 _tstSetUlongVar2(aObject, ULONG_TESTVALUE_2, NULL);
154 ulRC=_tstQueryUlongVar1(aObject, NULL);
155 g_message("Calling tstQueryUlongVar1():\t0x%lx\t\t%s", ulRC, (ULONG_TESTVALUE_1!=ulRC ? "FAILED" : "OK"));
156 g_assert(ULONG_TESTVALUE_1==ulRC);
157
158 ulRC=_tstQueryUlongVar2(aObject, NULL);
159 g_message("Calling tstQueryUlongVar2():\t0x%lx\t\t%s\n\n", ulRC, (ULONG_TESTVALUE_2!=ulRC ? "FAILED" : "OK"));
160 g_assert(ULONG_TESTVALUE_2==ulRC);
161}
162
163void tstSetBClassInstanceVar(BClass * aObject)
164{
165 gulong ulRC;
166
167 g_message("========================================================");
168 g_message("===== Testing setting of BClass instance variables =====");
169 g_message("========================================================");
170 /* Set 1. value */
171 _tstSetBClassUlongVar1(aObject, ULONG_TESTVALUE_BCLASS_1, NULL);
172
173 /* AClass */
174 ulRC=_tstQueryUlongVar1(aObject, NULL);
175 g_message("Calling tstQueryUlongVar1():\t0x%lx\t\t%s", ulRC, (ULONG_TESTVALUE_1!=ulRC ? "FAILED" : "OK"));
176 g_assert(ULONG_TESTVALUE_1==ulRC);
177 ulRC=_tstQueryUlongVar2(aObject, NULL);
178 g_message("Calling tstQueryUlongVar2():\t0x%lx\t\t%s", ulRC, (ULONG_TESTVALUE_2!=ulRC ? "FAILED" : "OK"));
179 g_assert(ULONG_TESTVALUE_2==ulRC);
180
181 /* BClass*/
182 ulRC=_tstQueryBClassUlongVar1(aObject, NULL);
183 g_message("Calling tstQueryBClassUlongVar1():\t0x%lx\t\t%s", ulRC, (ULONG_TESTVALUE_BCLASS_1!=ulRC ? "FAILED" : "OK"));
184 g_assert(ULONG_TESTVALUE_BCLASS_1==ulRC);
185
186 ulRC=_tstQueryBClassUlongVar2(aObject, NULL);
187 g_message("Calling tstQueryBClassUlongVar2():\t0x%lx\t\t\t%s\n\n", ulRC, (0!=ulRC ? "FAILED" : "OK"));
188 g_assert(0==ulRC);
189
190
191
192 /* Set 2. value */
193 _tstSetBClassUlongVar2(aObject, ULONG_TESTVALUE_BCLASS_2, NULL);
194
195 /* AClass */
196 ulRC=_tstQueryUlongVar1(aObject, NULL);
197 g_message("Calling tstQueryUlongVar1():\t0x%lx\t\t%s", ulRC, (ULONG_TESTVALUE_1!=ulRC ? "FAILED" : "OK"));
198 g_assert(ULONG_TESTVALUE_1==ulRC);
199 ulRC=_tstQueryUlongVar2(aObject, NULL);
200 g_message("Calling tstQueryUlongVar2():\t0x%lx\t\t%s", ulRC, (ULONG_TESTVALUE_2!=ulRC ? "FAILED" : "OK"));
201 g_assert(ULONG_TESTVALUE_2==ulRC);
202
203 /* BClass*/
204 ulRC=_tstQueryBClassUlongVar1(aObject, NULL);
205 g_message("Calling tstQueryBClassUlongVar1():\t0x%lx\t\t%s", ulRC, (ULONG_TESTVALUE_BCLASS_1!=ulRC ? "FAILED" : "OK"));
206 g_assert(ULONG_TESTVALUE_BCLASS_1==ulRC);
207
208 ulRC=_tstQueryBClassUlongVar2(aObject, NULL);
209 g_message("Calling tstQueryBClassUlongVar2():\t0x%lx\t\t%s\n\n", ulRC, (ULONG_TESTVALUE_BCLASS_2!=ulRC ? "FAILED" : "OK"));
210 g_assert(ULONG_TESTVALUE_BCLASS_2==ulRC);
211
212}
213
214
215/**
216 Main entry point for the idl compiler.
217 */
218int main(int argc, char **argv)
219{
220 NOMClassMgr *NOMClassMgrObject;
221 HREGDLL hReg=NULL;
222 AClass* aObject;
223 BClass* bObject;
224 int a;
225
226 /* GSlice isn't GC aware */
227 g_slice_set_config(G_SLICE_CONFIG_ALWAYS_MALLOC, TRUE);
228
229 nomInitGarbageCollection(NULL);
230
231 /* Register DLLs with the garbage collector */
232 hReg=nomBeginRegisterDLLWithGC();
233 if(NULL==hReg)
234 return 1;
235
236 g_assert(nomRegisterDLLByName(hReg, "NOBJTK.DLL"));
237
238 nomEndRegisterDLLWithGC(hReg);
239
240 g_message("NOM test application started.");
241
242 /* Init NOM */
243 NOMClassMgrObject=nomEnvironmentNew();
244
245 g_message("\n");
246 g_message("================================================================");
247 g_message("===== Testing AClass, child of NOMObject =====");
248 g_message("================================================================");
249
250 for(a=1; a<=100;a++)
251 {
252 int b;
253
254 g_message("------------------------------------------------------------------");
255 g_message("Loop: %d", a);
256
257 /* */
258 for(b=1; b<=NUMALLOCS;b++)
259 {
260 gpointer gp;
261
262 gp=g_malloc(MEMSIZE*a);
263 g_assert(gp);
264
265 /* Try to create an AClass object */
266 aObject=createAClassObject();
267 g_assert(aObject);
268
269 /* -- Call methods on the object --- */
270 tstAClassInstanceVarInitValues(aObject);
271 tstSetAClassInstanceVar(aObject);
272
273 }
274 g_message("Allocated %d chunks of %d bytes of memory -> %d bytes. Allocated %d objects.", NUMALLOCS, MEMSIZE*a, NUMALLOCS*MEMSIZE*a, NUMALLOCS);
275 }
276 g_message("Allocated %d objects at all.", NUMALLOCS*(a-1));
277
278
279 g_message("================================================================");
280 g_message("===== Testing BClass, child of AClass =====");
281 g_message("================================================================");
282
283
284 for(a =1; a<=100;a++)
285 {
286 int b;
287
288 g_message("------------------------------------------------------------------");
289 g_message("Loop: %d", a);
290
291 /* */
292 for(b=1; b<=NUMALLOCS;b++)
293 {
294 gpointer gp;
295
296 gp=g_malloc(MEMSIZE*a);
297 g_assert(gp);
298
299
300 /* Try to create an AClass object */
301 bObject=createBClassObject();
302 g_assert(bObject);
303
304
305 tstAClassInstanceVarInitValues(bObject);
306 tstBClassInstanceVarInitValues(bObject);
307
308 tstSetAClassInstanceVar(bObject);
309 tstSetBClassInstanceVar(bObject);
310
311 }
312 g_message("Allocated %d chunks of %d bytes of memory -> %d bytes. Allocated %d objects.", NUMALLOCS, MEMSIZE*a, NUMALLOCS*MEMSIZE*a, NUMALLOCS);
313 }
314 g_message("Allocated %d objects at all.", NUMALLOCS*(a-1));
315
316 return 0;
317};
Note: See TracBrowser for help on using the repository browser.