void selectorTest() { const TCHAR* tName; SEL tSel; SEL s1 = q_allocSelector(_T("addSomeObject:")); SEL s2 = q_allocSelector(_T("buttonPush")); SEL s3 = q_allocSelector(_T("someSel")); q_registerSelector(s2); q_registerSelector(s3); tSel = q_selectorByName(_T("addSomeObject:")); if (tSel) testFailure(tm1); tSel = q_selectorByName(_T("buttonPush")); if (!tSel) testFailure(tm1); if (q_isMappedSelector(s1) || !q_isMappedSelector(s3)) testFailure(tm2); tName = q_nameBySelector(s1); if (tName) testFailure(tm3); tName = q_nameBySelector(s2); if (_tcscmp(tName, _T("buttonPush"))) testFailure(tm3); Q_RELEASE(s1); Q_RELEASE(s2); Q_RELEASE(s3); }
void registerClassTest() { Class tst; Class notReg = q_allocClass(_T("NotRegister")); Class baseCls = q_allocClass(_T("Base")); Class deriv1Cls = q_allocClass(_T("Der1")); Class deriv2Cls = q_allocClass(_T("Der2")); Class secondDer = q_allocClass(_T("SecLevel")); q_registerClass(baseCls, Q_CLASS_OBJ(Object)); q_registerClass(deriv1Cls, baseCls); q_registerClass(deriv2Cls, baseCls); q_registerClass(secondDer, deriv2Cls); tst = q_classByName(_T("NotRegister")); if (tst) testFailure(tm4); tst = q_classByName(_T("Der1")); if (!tst) testFailure(tm4); tst = q_classByName(_T("SecLevel")); if (!tst) testFailure(tm4); methodsLookupTest(baseCls, deriv2Cls, secondDer); Q_RELEASE(secondDer); Q_RELEASE(deriv2Cls); Q_RELEASE(deriv1Cls); Q_RELEASE(baseCls); Q_RELEASE(notReg); }
void runMiscTest() { AutoreleasePool pool = q_allocAutoreleasePool(); MyType obj1 = allocMyType(); MyType obj2 = allocMyType(); MyType obj3 = allocMyType(); MyType obj4 = allocMyType(); ArrType myArr = q_allocArrType(); MyType tst = nil; obj2->height = 25; obj3->height = 30; obj4->height = 45; q_addItemToArrType(obj1, myArr); q_addItemToArrType(obj2, myArr); q_addItemToArrType(obj3, myArr); q_addItemToArrType(obj4, myArr); Q_RELEASE(obj1); Q_RELEASE(obj2); Q_RELEASE(obj3); Q_RELEASE(obj4); tst = q_itemAtIndexInArrType(1, myArr); tst = q_itemAtIndexInArrType(2, myArr); tst = q_itemAtIndexInArrType(3, myArr); q_removeItemAtIndexInArrType(1, myArr); tst = q_itemAtIndexInArrType(1, myArr); if (tst->height != 30) testFailure(tm1); tst = q_itemAtIndexInArrType(2, myArr); if (tst->height != 45) testFailure(tm1); Q_AUTORELEASE(myArr); { int h = q_itemAtIndexInArrType(1, myArr)->height; int vv = 0; ++vv; } { unsigned int i; for (i = 0; i < 1000; ++i) { MyType obj = allocMyType(); Q_AUTORELEASE(obj); } } Q_AUTORELEASE(pool); { int al = 9; ++al; } }
void methodsLookupTest(Class cls1, Class cls2, Class cls3) { SEL sel1 = q_allocSelector(_T("Sel1")); SEL sel2 = q_allocSelector(_T("Sel2")); SEL sel3 = q_allocSelector(_T("Sel3")); q_registerSelector(sel1); q_registerSelector(sel2); q_registerSelector(sel3); { Method tst; Method m1 = q_allocMethod(sel1, (IMP)0x1, "+v"); Method m2 = q_allocMethod(sel2, (IMP)0x1, "+v"); Method m3 = q_allocMethod(sel3, (IMP)0x1, "+v"); MethodListArray mla1 = q_allocMethodListArray(); MethodListArray mla2 = q_allocMethodListArray(); MethodListArray mla3 = q_allocMethodListArray(); MethodList mlist1 = q_allocMethodList(); MethodList mlist2 = q_allocMethodList(); MethodList mlist3 = q_allocMethodList(); q_addItemToMethodListArray(mlist1, mla1); q_addItemToMethodListArray(mlist2, mla2); q_addItemToMethodListArray(mlist3, mla3); q_addItemToMethodList(m1, mlist1); q_addItemToMethodList(m2, mlist2); q_addItemToMethodList(m3, mlist3); q_setMethodListArray(cls1, mla1); q_setMethodListArray(cls2, mla2); // setMethodListArray(cls3, mla3); tst = q_lookupMethodInMethodList(sel2, mlist2); if (!tst || _tcscmp(tst->sel->name, _T("Sel2"))) testFailure(tm5); tst = q_lookupMethodInMethodListArray(sel2, mla2); if (!tst || _tcscmp(tst->sel->name, _T("Sel2"))) testFailure(tm5); tst = q_lookupMethodInClassHierarchy(sel1, cls3); if (!tst || _tcscmp(tst->sel->name, _T("Sel1"))) testFailure(tm5); Q_RELEASE(mlist1); Q_RELEASE(mlist2); Q_RELEASE(mlist3); Q_RELEASE(mla1); Q_RELEASE(mla2); Q_RELEASE(mla3); Q_RELEASE(m1); Q_RELEASE(m2); Q_RELEASE(m3); } Q_RELEASE(sel1); Q_RELEASE(sel2); Q_RELEASE(sel3); }
void sizeEncodeTest() { size_t realSize = sizeof(struct StrComplexSimple); size_t encodeSize = q_sizeOfTypeEncode("\"var\"{StrComplexSimple={SimpleS=i{StrBit=b5cb2isb1lb12s}d}@#cCsSiIlLfd^i*{TwiceStrTest={StrTestAlign=c\"name\"ci}i\"pointr\"^{StrTestAlign2=icc}}[14i][131(UnionTest=id{StrTestAlign=cci})]}"); if (realSize != encodeSize) testFailure(_T("realSize != encodeSize!!!")); realSize = sizeof(struct StrBit); encodeSize = q_sizeOfTypeEncode("{StrBit=b5cb2isb1lb12s}"); if (realSize != encodeSize) testFailure(_T("Not work bit fields!")); }
void start() { testAddition(); testSubtraction(); testFailure(); suite->runNextCase(); }
void methodTypeEncodeTest(SEL sel) { struct _Method m; size_t ret_size = 0; size_t all_size = 0; m.imp = (IMP)0x1; // some address, not important, this test value m.sel = sel; m.types = "+\"retval\"{StrTestAlign=cci}+\"param1\"{TwiceStrTest={StrTestAlign=cci}i^{StrTestAlign2=icc}}+\"param2\"d"; ret_size = q_sizeOfMethodRetTypeEncode(&m); all_size = q_sizeOfMethodAllArgTypesEncode(&m, nil); if (ret_size != sizeof(struct StrTestAlign)) testFailure(_T("Method type encoding don't work!")); if (all_size != sizeof(struct TwiceStrTest) + sizeof(double) + sizeof(id) + sizeof(SEL)) testFailure(_T("Method type encoding don't work!")); }