| 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 | #define INCL_DOSPROCESS
|
|---|
| 35 | #define INCL_DOS
|
|---|
| 36 | #define INCL_DOSPROFILE
|
|---|
| 37 | #define INCL_DOSERRORS
|
|---|
| 38 |
|
|---|
| 39 | #include <os2.h>
|
|---|
| 40 | #include <stdio.h>
|
|---|
| 41 | #include <stdlib.h>
|
|---|
| 42 | #include <string.h>
|
|---|
| 43 |
|
|---|
| 44 | #include <io.h>
|
|---|
| 45 | #include <fcntl.h>
|
|---|
| 46 | #include <sys\stat.h>
|
|---|
| 47 |
|
|---|
| 48 | #include <glib.h>
|
|---|
| 49 | #include <glib/gprintf.h>
|
|---|
| 50 |
|
|---|
| 51 | #include "nom.h"
|
|---|
| 52 | #include "nomtk.h"
|
|---|
| 53 | #include "nomgc.h"
|
|---|
| 54 |
|
|---|
| 55 | #include "aclass.h"
|
|---|
| 56 | #include "bclass.h"
|
|---|
| 57 |
|
|---|
| 58 | #define ULONG_TESTVALUE_1 0xffeeddcc
|
|---|
| 59 | #define ULONG_TESTVALUE_2 0x55aa1122
|
|---|
| 60 | #define ULONG_TESTVALUE_BCLASS_1 0x50403020
|
|---|
| 61 | #define ULONG_TESTVALUE_BCLASS_2 0xf0e0d0c0
|
|---|
| 62 |
|
|---|
| 63 | AClass* createAClassObject()
|
|---|
| 64 | {
|
|---|
| 65 | AClass* aClass;
|
|---|
| 66 |
|
|---|
| 67 | aClass=AClassNew();
|
|---|
| 68 |
|
|---|
| 69 | if(nomIsObj(aClass))
|
|---|
| 70 | g_message("AClass creation\t\t\t\tOK\n");
|
|---|
| 71 | else
|
|---|
| 72 | g_message("AClass creation\t\t\t\t\tFAILED\n");
|
|---|
| 73 | return aClass;
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | AClass* createBClassObject()
|
|---|
| 77 | {
|
|---|
| 78 | BClass* bClass;
|
|---|
| 79 |
|
|---|
| 80 | bClass=BClassNew();
|
|---|
| 81 |
|
|---|
| 82 | if(nomIsObj(bClass))
|
|---|
| 83 | g_message("BClass creation\t\t\t\tOK\n");
|
|---|
| 84 | else
|
|---|
| 85 | g_message("BClass creation\t\t\t\t\tFAILED\n");
|
|---|
| 86 | return bClass;
|
|---|
| 87 | }
|
|---|
| 88 |
|
|---|
| 89 | void tstAClassInstanceVarInitValues(AClass * aObject)
|
|---|
| 90 | {
|
|---|
| 91 | ULONG ulRC;
|
|---|
| 92 |
|
|---|
| 93 | g_message("================================================================");
|
|---|
| 94 | g_message("===== Testing init values of instance variables. Must be 0 =====");
|
|---|
| 95 | g_message("================================================================");
|
|---|
| 96 |
|
|---|
| 97 | ulRC=_tstQueryUlongVar1(aObject, NULLHANDLE);
|
|---|
| 98 | g_message("Calling tstQueryUlongVar1():\t%ld\t\t%s", ulRC, (0!=ulRC ? "FAILED" : "OK"));
|
|---|
| 99 | g_assert(0==ulRC);
|
|---|
| 100 |
|
|---|
| 101 | ulRC=_tstQueryUlongVar2(aObject, NULLHANDLE);
|
|---|
| 102 | g_message("Calling tstQueryUlongVar2():\t%ld\t\t%s\n", ulRC, (0!=ulRC ? "FAILED" : "OK"));
|
|---|
| 103 | g_assert(0==ulRC);
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 |
|
|---|
| 107 | void tstBClassInstanceVarInitValues(BClass * aObject)
|
|---|
| 108 | {
|
|---|
| 109 | ULONG ulRC;
|
|---|
| 110 |
|
|---|
| 111 | g_message("================================================================");
|
|---|
| 112 | g_message("===== Testing init values of instance variables. Must be 0 =====");
|
|---|
| 113 | g_message("================================================================");
|
|---|
| 114 |
|
|---|
| 115 | ulRC=_tstQueryBClassUlongVar1(aObject, NULLHANDLE);
|
|---|
| 116 | g_message("Calling tstQueryBClassUlongVar1():\t%ld\t\t%s", ulRC, (0!=ulRC ? "FAILED" : "OK"));
|
|---|
| 117 | g_assert(0==ulRC);
|
|---|
| 118 |
|
|---|
| 119 | ulRC=_tstQueryBClassUlongVar2(aObject, NULLHANDLE);
|
|---|
| 120 | g_message("Calling tstQueryBClassUlongVar2():\t%ld\t\t%s\n", ulRC, (0!=ulRC ? "FAILED" : "OK"));
|
|---|
| 121 | g_assert(0==ulRC);
|
|---|
| 122 | }
|
|---|
| 123 |
|
|---|
| 124 |
|
|---|
| 125 | void tstSetAClassInstanceVar(AClass * aObject)
|
|---|
| 126 | {
|
|---|
| 127 | ULONG ulRC;
|
|---|
| 128 |
|
|---|
| 129 | g_message("========================================================");
|
|---|
| 130 | g_message("===== Testing setting of AClass instance variables =====");
|
|---|
| 131 | g_message("========================================================");
|
|---|
| 132 | /* Set 1. value */
|
|---|
| 133 | _tstSetUlongVar1(aObject, ULONG_TESTVALUE_1, NULLHANDLE);
|
|---|
| 134 | ulRC=_tstQueryUlongVar1(aObject, NULLHANDLE);
|
|---|
| 135 | g_message("Calling tstQueryUlongVar1():\t0x%lx\t\t%s", ulRC, (ULONG_TESTVALUE_1!=ulRC ? "FAILED" : "OK"));
|
|---|
| 136 | g_assert(ULONG_TESTVALUE_1==ulRC);
|
|---|
| 137 |
|
|---|
| 138 | ulRC=_tstQueryUlongVar2(aObject, NULLHANDLE);
|
|---|
| 139 | g_message("Calling tstQueryUlongVar2():\t0x%lx\t\t\t%s\n", ulRC, (0!=ulRC ? "FAILED" : "OK"));
|
|---|
| 140 | g_assert(0==ulRC);
|
|---|
| 141 |
|
|---|
| 142 | /* Set 2. value */
|
|---|
| 143 | _tstSetUlongVar2(aObject, ULONG_TESTVALUE_2, NULLHANDLE);
|
|---|
| 144 | ulRC=_tstQueryUlongVar1(aObject, NULLHANDLE);
|
|---|
| 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, NULLHANDLE);
|
|---|
| 149 | g_message("Calling tstQueryUlongVar2():\t0x%lx\t\t%s\n\n", ulRC, (ULONG_TESTVALUE_2!=ulRC ? "FAILED" : "OK"));
|
|---|
| 150 | g_assert(ULONG_TESTVALUE_2==ulRC);
|
|---|
| 151 | }
|
|---|
| 152 |
|
|---|
| 153 | void tstSetBClassInstanceVar(BClass * aObject)
|
|---|
| 154 | {
|
|---|
| 155 | ULONG ulRC;
|
|---|
| 156 |
|
|---|
| 157 | g_message("========================================================");
|
|---|
| 158 | g_message("===== Testing setting of BClass instance variables =====");
|
|---|
| 159 | g_message("========================================================");
|
|---|
| 160 | /* Set 1. value */
|
|---|
| 161 | _tstSetBClassUlongVar1(aObject, ULONG_TESTVALUE_BCLASS_1, NULLHANDLE);
|
|---|
| 162 | ulRC=_tstQueryBClassUlongVar1(aObject, NULLHANDLE);
|
|---|
| 163 | g_message("Calling tstQueryBClassUlongVar1():\t0x%lx\t\t%s", ulRC, (ULONG_TESTVALUE_BCLASS_1!=ulRC ? "FAILED" : "OK"));
|
|---|
| 164 | g_assert(ULONG_TESTVALUE_BCLASS_1==ulRC);
|
|---|
| 165 |
|
|---|
| 166 | ulRC=_tstQueryBClassUlongVar2(aObject, NULLHANDLE);
|
|---|
| 167 | g_message("Calling tstQueryBClassUlongVar2():\t0x%lx\t\t\t%s\n", ulRC, (0!=ulRC ? "FAILED" : "OK"));
|
|---|
| 168 | g_assert(0==ulRC);
|
|---|
| 169 |
|
|---|
| 170 | /* Set 2. value */
|
|---|
| 171 | _tstSetBClassUlongVar2(aObject, ULONG_TESTVALUE_BCLASS_2, NULLHANDLE);
|
|---|
| 172 | ulRC=_tstQueryBClassUlongVar1(aObject, NULLHANDLE);
|
|---|
| 173 | g_message("Calling tstQueryBClassUlongVar1():\t0x%lx\t\t%s", ulRC, (ULONG_TESTVALUE_BCLASS_1!=ulRC ? "FAILED" : "OK"));
|
|---|
| 174 | g_assert(ULONG_TESTVALUE_BCLASS_1==ulRC);
|
|---|
| 175 |
|
|---|
| 176 | ulRC=_tstQueryBClassUlongVar2(aObject, NULLHANDLE);
|
|---|
| 177 | g_message("Calling tstQueryBClassUlongVar2():\t0x%lx\t\t%s\n\n", ulRC, (ULONG_TESTVALUE_BCLASS_2!=ulRC ? "FAILED" : "OK"));
|
|---|
| 178 | g_assert(ULONG_TESTVALUE_BCLASS_2==ulRC);
|
|---|
| 179 | }
|
|---|
| 180 |
|
|---|
| 181 |
|
|---|
| 182 | /**
|
|---|
| 183 | Main entry point for the idl compiler.
|
|---|
| 184 | */
|
|---|
| 185 | int main(int argc, char **argv)
|
|---|
| 186 | {
|
|---|
| 187 | NOMClassMgr *NOMClassMgrObject;
|
|---|
| 188 | HREGDLL hReg=NULLHANDLE;
|
|---|
| 189 | AClass* aObject;
|
|---|
| 190 | BClass* bObject;
|
|---|
| 191 |
|
|---|
| 192 | #if 0
|
|---|
| 193 | /* Preload the DLL otherwise it won't be found by the GC registering function */
|
|---|
| 194 | if((rc=DosLoadModule(uchrError, sizeof(uchrError),"nobjtk.dll", &hModuleGC))!=NO_ERROR)
|
|---|
| 195 | {
|
|---|
| 196 | printf("DosLoadmodule for nobjtk.dll failed with rc=0x%x because of module %s.\n", (int)rc, uchrError);
|
|---|
| 197 | return 1;
|
|---|
| 198 | };
|
|---|
| 199 | fprintf(stderr, "DLL handle for nobjtk.dll is: 0x%x\n", (int)hModuleGC);
|
|---|
| 200 | #endif
|
|---|
| 201 | nomInitGarbageCollection(NULL);
|
|---|
| 202 |
|
|---|
| 203 | /* Register DLLs with the garbage collector */
|
|---|
| 204 | hReg=nomBeginRegisterDLLWithGC();
|
|---|
| 205 | if(NULLHANDLE==hReg)
|
|---|
| 206 | return 1;
|
|---|
| 207 |
|
|---|
| 208 | #if 0
|
|---|
| 209 | //g_assert(nomRegisterDLLByName(hReg, "GLIB2.DLL" ));
|
|---|
| 210 | //g_assert(nomRegisterDLLByName(hReg, "GOBJECT2.DLL"));
|
|---|
| 211 | g_assert(nomRegisterDLLByName(hReg, "GMODULE2.DLL"));
|
|---|
| 212 | g_assert(nomRegisterDLLByName(hReg, "GDK2.DLL"));
|
|---|
| 213 | g_assert(nomRegisterDLLByName(hReg, "GDKPIX2.DLL"));
|
|---|
| 214 | g_assert(nomRegisterDLLByName(hReg, "GTK2.DLL" ));
|
|---|
| 215 | g_assert(nomRegisterDLLByName(hReg, "ATK.DLL" ));
|
|---|
| 216 | #endif
|
|---|
| 217 | g_assert(nomRegisterDLLByName(hReg, "NOBJTK.DLL"));
|
|---|
| 218 |
|
|---|
| 219 | nomEndRegisterDLLWithGC(hReg);
|
|---|
| 220 |
|
|---|
| 221 | g_message("NOM test application started.");
|
|---|
| 222 |
|
|---|
| 223 | /* Init NOM */
|
|---|
| 224 | NOMClassMgrObject=nomEnvironmentNew();
|
|---|
| 225 |
|
|---|
| 226 | g_message("\n");
|
|---|
| 227 | g_message("================================================================");
|
|---|
| 228 | g_message("===== Testing AClass, child of NOMObject =====");
|
|---|
| 229 | g_message("================================================================");
|
|---|
| 230 | /* Try to create an AClass object */
|
|---|
| 231 | aObject=createAClassObject();
|
|---|
| 232 | g_assert(aObject);
|
|---|
| 233 |
|
|---|
| 234 | /* -- Call methods on the object --- */
|
|---|
| 235 | tstAClassInstanceVarInitValues(aObject);
|
|---|
| 236 | tstSetAClassInstanceVar(aObject);
|
|---|
| 237 |
|
|---|
| 238 | g_message("================================================================");
|
|---|
| 239 | g_message("===== Testing BClass, child of AClass =====");
|
|---|
| 240 | g_message("================================================================");
|
|---|
| 241 | /* Try to create an AClass object */
|
|---|
| 242 | bObject=createBClassObject();
|
|---|
| 243 | g_assert(bObject);
|
|---|
| 244 |
|
|---|
| 245 | tstAClassInstanceVarInitValues(bObject);
|
|---|
| 246 | tstBClassInstanceVarInitValues(bObject);
|
|---|
| 247 |
|
|---|
| 248 | tstSetAClassInstanceVar(bObject);
|
|---|
| 249 | tstSetBClassInstanceVar(bObject);
|
|---|
| 250 |
|
|---|
| 251 | return 0;
|
|---|
| 252 | };
|
|---|
| 253 |
|
|---|
| 254 |
|
|---|
| 255 |
|
|---|
| 256 |
|
|---|
| 257 |
|
|---|
| 258 |
|
|---|
| 259 |
|
|---|
| 260 |
|
|---|