| 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 | #include "nomarray.h"
|
|---|
| 65 | #include "nomstring.h"
|
|---|
| 66 | #include "nommethod.h"
|
|---|
| 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 |
|
|---|
| 73 | AClass* createAClassObject()
|
|---|
| 74 | {
|
|---|
| 75 | AClass* aClass;
|
|---|
| 76 |
|
|---|
| 77 | aClass=AClassNew();
|
|---|
| 78 |
|
|---|
| 79 | if(nomIsObj(aClass))
|
|---|
| 80 | g_message("AClass creation\t\t\t\tOK\n");
|
|---|
| 81 | else
|
|---|
| 82 | g_message("AClass creation\t\t\t\t\tFAILED\n");
|
|---|
| 83 | return aClass;
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | AClass* 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 |
|
|---|
| 99 | void 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 |
|
|---|
| 117 | void 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 |
|
|---|
| 135 | void 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 |
|
|---|
| 163 | void 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 | */
|
|---|
| 218 | int main(int argc, char **argv)
|
|---|
| 219 | {
|
|---|
| 220 | NOMClassMgr *NOMClassMgrObject;
|
|---|
| 221 | HREGDLL hReg=NULL;
|
|---|
| 222 | AClass* aObject;
|
|---|
| 223 | BClass* bObject;
|
|---|
| 224 | NOMArray* nArray;
|
|---|
| 225 | int a;
|
|---|
| 226 |
|
|---|
| 227 | #if 0
|
|---|
| 228 | /* Preload the DLL otherwise it won't be found by the GC registering function */
|
|---|
| 229 | if((rc=DosLoadModule(uchrError, sizeof(uchrError),"nobjtk.dll", &hModuleGC))!=NO_ERROR)
|
|---|
| 230 | {
|
|---|
| 231 | printf("DosLoadmodule for nobjtk.dll failed with rc=0x%x because of module %s.\n", (int)rc, uchrError);
|
|---|
| 232 | return 1;
|
|---|
| 233 | };
|
|---|
| 234 | fprintf(stderr, "DLL handle for nobjtk.dll is: 0x%x\n", (int)hModuleGC);
|
|---|
| 235 | #endif
|
|---|
| 236 | nomInitGarbageCollection(NULL);
|
|---|
| 237 |
|
|---|
| 238 | /* Register DLLs with the garbage collector */
|
|---|
| 239 | hReg=nomBeginRegisterDLLWithGC();
|
|---|
| 240 | if(NULL==hReg)
|
|---|
| 241 | return 1;
|
|---|
| 242 |
|
|---|
| 243 | #if 0
|
|---|
| 244 | //g_assert(nomRegisterDLLByName(hReg, "GLIB2.DLL" ));
|
|---|
| 245 | //g_assert(nomRegisterDLLByName(hReg, "GOBJECT2.DLL"));
|
|---|
| 246 | g_assert(nomRegisterDLLByName(hReg, "GMODULE2.DLL"));
|
|---|
| 247 | g_assert(nomRegisterDLLByName(hReg, "GDK2.DLL"));
|
|---|
| 248 | g_assert(nomRegisterDLLByName(hReg, "GDKPIX2.DLL"));
|
|---|
| 249 | g_assert(nomRegisterDLLByName(hReg, "GTK2.DLL" ));
|
|---|
| 250 | g_assert(nomRegisterDLLByName(hReg, "ATK.DLL" ));
|
|---|
| 251 | #endif
|
|---|
| 252 | g_assert(nomRegisterDLLByName(hReg, "NOBJTK.DLL"));
|
|---|
| 253 |
|
|---|
| 254 | nomEndRegisterDLLWithGC(hReg);
|
|---|
| 255 |
|
|---|
| 256 | g_message("NOM test application started.");
|
|---|
| 257 |
|
|---|
| 258 | /* Init NOM */
|
|---|
| 259 | NOMClassMgrObject=nomEnvironmentNew();
|
|---|
| 260 |
|
|---|
| 261 | g_message("\n");
|
|---|
| 262 | g_message("================================================================");
|
|---|
| 263 | g_message("===== Testing AClass, child of NOMObject =====");
|
|---|
| 264 | g_message("================================================================");
|
|---|
| 265 | /* Try to create an AClass object */
|
|---|
| 266 | aObject=createAClassObject();
|
|---|
| 267 | g_assert(aObject);
|
|---|
| 268 |
|
|---|
| 269 | nArray=_nomGetMethodList(aObject, FALSE, NULL);
|
|---|
| 270 | g_message("Num methods: %d", NOMArray_length(nArray, NULL));
|
|---|
| 271 |
|
|---|
| 272 | for(a=0; a < NOMArray_length(nArray, NULL) ; a++)
|
|---|
| 273 | {
|
|---|
| 274 | typedef void* NOMLINK nomProc(void*, void*);
|
|---|
| 275 |
|
|---|
| 276 | nomProc* nProc=_queryMethodToken(NOMArray_queryObjectAtIdx(nArray, a, NULL), NULL);
|
|---|
| 277 |
|
|---|
| 278 | g_message(" Method %s %x", _queryString(_getName(NOMArray_queryObjectAtIdx(nArray, a, NULL), NULL), NULL),
|
|---|
| 279 | _queryMethodToken(NOMArray_queryObjectAtIdx(nArray, a, NULL), NULL));
|
|---|
| 280 | if(a==0)
|
|---|
| 281 | nProc(aObject, NULL);
|
|---|
| 282 | }
|
|---|
| 283 |
|
|---|
| 284 | exit(1);
|
|---|
| 285 |
|
|---|
| 286 | /* -- Call methods on the object --- */
|
|---|
| 287 | tstAClassInstanceVarInitValues(aObject);
|
|---|
| 288 | tstSetAClassInstanceVar(aObject);
|
|---|
| 289 |
|
|---|
| 290 | g_message("================================================================");
|
|---|
| 291 | g_message("===== Testing BClass, child of AClass =====");
|
|---|
| 292 | g_message("================================================================");
|
|---|
| 293 | /* Try to create an AClass object */
|
|---|
| 294 | bObject=createBClassObject();
|
|---|
| 295 | g_assert(bObject);
|
|---|
| 296 |
|
|---|
| 297 | tstAClassInstanceVarInitValues(bObject);
|
|---|
| 298 | tstBClassInstanceVarInitValues(bObject);
|
|---|
| 299 |
|
|---|
| 300 | tstSetAClassInstanceVar(bObject);
|
|---|
| 301 | tstSetBClassInstanceVar(bObject);
|
|---|
| 302 |
|
|---|
| 303 | return 0;
|
|---|
| 304 | };
|
|---|
| 305 |
|
|---|
| 306 |
|
|---|
| 307 |
|
|---|
| 308 |
|
|---|
| 309 |
|
|---|
| 310 |
|
|---|
| 311 |
|
|---|
| 312 |
|
|---|