local void testSymeSExpr() { String aSimpleDomain = "+++Comment\nDom: Category == with {f: () -> () ++ f\n}"; StringList lines = listList(String)(1, aSimpleDomain); AbSynList code = listCons(AbSyn)(stdtypes(), abqParseLines(lines)); AbSyn absyn = abNewSequenceL(sposNone, code); initFile(); Stab stab = stabFile(); abPutUse(absyn, AB_Use_NoValue); scopeBind(stab, absyn); typeInfer(stab, absyn); testTrue("Declare is sefo", abIsSefo(absyn)); testIntEqual("Error Count", 0, comsgErrorCount()); SymeList symes = stabGetMeanings(stab, ablogFalse(), symInternConst("Dom")); testIntEqual("unique meaning", 1, listLength(Syme)(symes)); Syme syme = car(symes); SExpr sx = symeSExprAList(syme); finiFile(); }
local void testSymeAddCondition() { String B_imp = "import from Boolean"; String C_txt = "C: Category == with"; String D1_txt = "D1: with == add"; String D2_txt = "D2: with == add"; StringList lines = listList(String)(4, B_imp, C_txt, D1_txt, D2_txt); AbSynList code = listCons(AbSyn)(stdtypes(), abqParseLines(lines)); AbSyn absyn = abNewSequenceL(sposNone, code); initFile(); Stab stab = stabFile(); abPutUse(absyn, AB_Use_NoValue); scopeBind(stab, absyn); typeInfer(stab, absyn); AbSyn D1 = abFrSyme(uniqueMeaning(stabFile(), "D1")); AbSyn D2 = abFrSyme(uniqueMeaning(stabFile(), "D2")); AbSyn C = abFrSyme(uniqueMeaning(stabFile(), "C")); Syme syme1 = symeNewExport(symInternConst("syme2"), tfNewAbSyn(TF_General, id("D")), car(stab)); symeAddCondition(syme1, sefo(has(D1, C)), true); testIntEqual("test1", 1, listLength(Sefo)(symeCondition(syme1))); Syme syme2 = symeNewExport(symInternConst("syme1"),tfNewAbSyn(TF_General, id("D")), car(stab)); symeAddCondition(syme2, sefo(and(has(D1, C), has(D2, C))), true); testIntEqual("test2", 2, listLength(Sefo)(symeCondition(syme2))); finiFile(); }
local void testBitvToInt() { BitvClass clss = bitvClassCreate(10); int i; Bitv bitv = bitvFromInt(clss, 0); bitvPrintDb(clss, bitv); testIntEqual("", 0, bitvCount(clss, bitv)); for (i=0; i<1024; i++) { Bitv bits = bitvFromInt(clss, i); int back = bitvToInt(clss, bits); testIntEqual("Should be equal", i, back); bitvFree(bits); } for (i=0; i<10; i++) { Bitv bitv = bitvFromInt(clss, 1<<i); testIntEqual("ZZ", 1, bitvCount(clss, bitv)); bitvFree(bitv); } for (i=0; i<10; i++) { Bitv bitv = bitvFromInt(clss, (1<<i) - 1); testIntEqual("AA", i, bitvCount(clss, bitv)); bitvFree(bitv); } bitvClassDestroy(clss); }
local void testDDecl() { Foam ddecl = foamNewDDecl(FOAM_DDecl_Local, foamNewDecl(FOAM_SInt, strCopy("fred"), emptyFormatSlot), NULL); testIntEqual("tag", FOAM_DDecl, foamTag(ddecl)); testIntEqual("argc", 1, foamDDeclArgc(ddecl)); }
local void testFloatSizes() { fprintf(dbOut, "sizeof float: " LENGTH_FMT "\n", sizeof(SFloat)); fprintf(dbOut, "sizeof dfloat: " LENGTH_FMT "\n", sizeof(DFloat)); testIntEqual("float", 4, sizeof(SFloat)); testIntEqual("float", 8, sizeof(DFloat)); }
local void testBitvCount() { BitvClass clss = bitvClassCreate(10); Bitv bitv = bitvNew(clss); int i; bitvClearAll(clss, bitv); testIntEqual("A", 0, bitvCount(clss, bitv)); bitvSetAll(clss, bitv); testIntEqual("B", 10, bitvCount(clss, bitv)); for (i=0; i<10; i++) { testIntEqual("C", i, bitvCountTo(clss, bitv, i)); } bitvClassDestroy(clss); }
int main(int argc, char *argv[]) { theArgc = argc; theArgv = argv; if (testShouldRun("printf")) printfTest(); if (testShouldRun("ostream")) ostreamTest(); if (testShouldRun("bigint")) bintTestSuite(); if (testShouldRun("bitv")) bitvTestSuite(); if (testShouldRun("list")) listTestSuite(); if (testShouldRun("fname")) fnameTest(); if (testShouldRun("foam")) foamTest(); if (testShouldRun("format")) formatTest(); if (testShouldRun("flog")) flogTest(); if (testShouldRun("jflow")) jflowTest(); if (testShouldRun("tinfer")) tinferTest(); if (testShouldRun("stab")) stabTest(); if (testShouldRun("srcpos")) srcposTest(); if (testShouldRun("absyn")) absynTest(); if (testShouldRun("abnorm")) abnormTest(); if (testShouldRun("abcheck")) abcheckTest(); if (testShouldRun("ablog")) ablogTest(); if (testShouldRun("tform")) tformTest(); if (testShouldRun("scobind")) scobindTest(); if (testShouldRun("syme")) symeTest(); if (testShouldRun("tibup")) tibupTest(); if (testShouldRun("tfsat")) tfsatTest(); testIntEqual("fluidlevel", 0, fluidLevel); testShowSummary(); return testAllPassed() ? 0 : 1; }
local void scobindTestCheckUnique(Stab stab, Symbol sym) { SymeList sl = stabGetMeanings(stab, ablogFalse(), sym); testIntEqual("unique", 1, listLength(Syme)(sl)); testPointerEqual("name", sym, symeId(car(sl))); }
local void testArchive() { Archive ar; FileName fname = fnameParse("arch-test/foo.al"); int status; status = system("mkdir arch-test"); testIntEqual("", 0, status); status = system("ar r arch-test/foo.al Makefile"); testIntEqual("", 0, status); ar = arFrString("arch-test/foo.al"); testIsNotNull("t0", ar); status = system("rm -rf arch-test"); testIntEqual("", 0, status); }
void showTest(char *name, void (*fn)(void)) { int localFluidLevel = fluidLevel; printf("(Starting test %s\n", name); fn(); testIntEqual("fluidlevel", localFluidLevel, fluidLevel); printf(" Test %s complete)\n", name); }
void forgTest() { Buffer buf = bufNew(); ForeignOrigin forg1 = forgNew(FOAM_Proto_Java, strCopy("hello")); ForeignOrigin forg2 = forgNew(FOAM_Proto_C, strCopy("world")); ForeignOrigin forg3 = forgNew(FOAM_Proto_C, NULL); ForeignOrigin forg1_r, forg2_r, forg3_r; testTrue("1", forgEqual(forg1, forg1)); testTrue("2", forgEqual(forg2, forg2)); testFalse("3", forgEqual(forg1, forg2)); testFalse("4", forgEqual(forg1, forg3)); forgToBuffer(buf, forg1); forgToBuffer(buf, forg2); bufSetPosition(buf, 0); forg1_r = forgFrBuffer(buf); forg2_r = forgFrBuffer(buf); testTrue("5", forgEqual(forg1_r, forg1)); testTrue("6", forgEqual(forg2_r, forg2)); int pos = bufPosition(buf); bufSetPosition(buf, 0); forgBufferSkip(buf); forgBufferSkip(buf); testIntEqual("7", pos, bufPosition(buf)); bufSetPosition(buf, 0); forgToBuffer(buf, forg3); forgToBuffer(buf, forg1); pos = bufPosition(buf); bufSetPosition(buf, 0); forg3_r = forgFrBuffer(buf); forg1_r = forgFrBuffer(buf); testTrue("8", forgEqual(forg3_r, forg3)); testTrue("8", forgEqual(forg1_r, forg1)); testIntEqual("10", pos, bufPosition(buf)); }
local void testPrintf1() { char arr2[100]; memset(arr, 'X', 100); String fmt = "foo: %s"; String arg1 = "bar"; sprintf(arr2, fmt, arg1); int cc = xprintf(arrWrite, fmt, arg1); testStringEqual("content", arr2, arr); testIntEqual("retval", cc, strlen(arr)); }
local void testAblog() { initFile(); ablogDebug = 0; String Boolean_imp = "import from Boolean"; String C0_def = "C0: Category == with"; String C1_def = "C1: Category == C0 with"; String D0_def = "D0: C0 with == add"; String D1_def = "D1: C1 with == add"; StringList lines = listList(String)(5, Boolean_imp, C0_def, C1_def, D0_def, D1_def); AbSynList code = listCons(AbSyn)(stdtypes(), abqParseLines(lines)); AbSyn absyn = abNewSequenceL(sposNone, code); abPutUse(absyn, AB_Use_NoValue); Stab file = stabFile(); Stab stab = stabPushLevel(file, sposNone, STAB_LEVEL_LARGE); scopeBind(stab, absyn); typeInfer(stab, absyn); testTrue("Declare is sefo", abIsSefo(absyn)); testIntEqual("Error Count", 0, comsgErrorCount()); Syme C0 = uniqueMeaning(stab, "C0"); Syme C1 = uniqueMeaning(stab, "C1"); Syme D0 = uniqueMeaning(stab, "D0"); Syme D1 = uniqueMeaning(stab, "D1"); AbSyn sefo1 = has(abFrSyme(D1), abFrSyme(C1)); AbSyn sefo0 = has(abFrSyme(D1), abFrSyme(C0)); tiSefo(stab, sefo0); tiSefo(stab, sefo1); AbLogic cond0 = ablogFrSefo(sefo0); AbLogic cond1 = ablogFrSefo(sefo1); afprintf(dbOut, "Implies: %pAbLogic %pAbLogic %d\n", cond1, cond0, ablogImplies(cond1, cond0)); afprintf(dbOut, "Implies: %pAbLogic %pAbLogic %d\n", cond0, cond1, ablogImplies(cond0, cond1)); testTrue("00", ablogImplies(cond0, cond0)); testTrue("10", ablogImplies(cond1, cond0)); testFalse("01",ablogImplies(cond0, cond1)); testTrue("11", ablogImplies(cond1, cond1)); }
local void testIter() { Foam seq; int i; seq = foamNewSeq(NULL); i = -1; i = foamSeqNextReachable(seq, i); testIntEqual("1", -1, i); seq = foamNewSeq(foamNewNOp(), foamNewGoto(10), foamNewLabel(10), NULL); i = -1; i = foamSeqNextReachable(seq, i); testIntEqual("", 0, i); i = foamSeqNextReachable(seq, i); testIntEqual("", 1, i); i = foamSeqNextReachable(seq, i); testIntEqual("", 2, i); i = foamSeqNextReachable(seq, i); testIntEqual("", -1, i); seq = foamNewSeq(foamNewNOp(), foamNewGoto(10), foamNewNOp(), foamNewLabel(10), NULL); i = -1; i = foamSeqNextReachable(seq, i); testIntEqual("", 0, i); i = foamSeqNextReachable(seq, i); testIntEqual("", 1, i); i = foamSeqNextReachable(seq, i); testIntEqual("", 3, i); i = foamSeqNextReachable(seq, i); testIntEqual("", -1, i); }
local void testForeign() { String Boolean_imp = "import from Boolean"; String P_def = "Pointer: with == add"; String C_def = "C: with == add"; String F_def = "Foreign(T: Type): with == add"; String R_def = "R == Record(x: Pointer)"; String fn_imp = "import { fn: R -> () } from Foreign C"; String tst_def = "test(p: R): () == fn(p)"; StringList lines = listList(String)(7, Boolean_imp, P_def, C_def, F_def, R_def, fn_imp, tst_def); AbSynList absynList = listCons(AbSyn)(stdtypes(), abqParseLines(lines)); AbSyn absyn = abNewSequenceL(sposNone, absynList); Stab stab; Foam foam; initFile(); stab = stabFile(); abPutUse(absyn, AB_Use_NoValue); abPrintDb(absyn); scopeBind(stab, absyn); typeInfer(stab, absyn); testIntEqual("Error Count", 0, comsgErrorCount()); foam = generateFoam(stab, absyn, "test"); /* At this point, we should check that the 'test' function * calls 'fn' with a type of FOAM_Rec. In order to do this * nicely, there should be a decent way of searching a blob of * foam for certain properties. */ #if 0 FoamList pcall = foamFind(fmfAnd(fmfFoamTag(FOAM_PCall), fmfPCallProto(FOAM_Proto_C)), foam); testAIntEqual(FOAM_Rec, foamExprType(foam, pcall->first->foamPCall.argv[0])) #endif }
local void testConstructors() { Foam foam, arg1, arg2; foam = foamNewBCall0(FOAM_BVal_BoolNot); testIntEqual("argc", foamBCallSlotc, foamArgc(foam)); testIntEqual("tag", FOAM_BVal_BoolNot, foam->foamBCall.op); arg1 = foamNewLoc(int0); arg2 = foamNewLoc(int0); foam = foamNewBCall1(FOAM_BVal_BoolNot, arg1); testIntEqual("argc", 1, foamBCallArgc(foam)); testIntEqual("tag", FOAM_BVal_BoolNot, foam->foamBCall.op); testPointerEqual("arg1", arg1, foam->foamBCall.argv[0]); foam = foamNewBCall2(FOAM_BVal_BoolNot, arg1, arg2); testIntEqual("argc", 2, foamBCallArgc(foam)); testIntEqual("tag", FOAM_BVal_BoolNot, foam->foamBCall.op); testPointerEqual("arg1", arg1, foam->foamBCall.argv[0]); testPointerEqual("arg1", arg2, foam->foamBCall.argv[1]); }
local void testCall() { Foam foam; foam = foamNew(FOAM_OCall, 3, FOAM_Clos, foamNewNil(), foamNewNil()); testIntEqual("foamOCallArgc", 0, foamOCallArgc(foam)); foam = foamNew(FOAM_OCall, 4, FOAM_Clos, foamNewNil(), foamNewNil(), foamNewSInt(1)); testIntEqual("foamOCallArgc", 1, foamOCallArgc(foam)); foam = foamNewPCall(FOAM_Proto_C, FOAM_NOp, foamNewGlo(int0), NULL); testIntEqual("argc", 0, foamPCallArgc(foam)); testIntEqual("protocol", FOAM_Proto_C, foam->foamPCall.protocol); foam = foamNewCCall(FOAM_Word, foamNewGlo(int0), NULL); testIntEqual("argc", 0, foamCCallArgc(foam)); testTrue("op", foamEqual(foamNewGlo(int0), foam->foamCCall.op)); foam = foamNewCCall(FOAM_Word, foamNewGlo(int0), foamNewPar(1), NULL); testIntEqual("argc", 1, foamCCallArgc(foam)); testTrue("op", foamEqual(foamNewPar(1), foam->foamCCall.argv[0])); }
local void testHash() { AInt hULS = strHash("UnivariateLaurentSeries"); AInt hUTS = strHash("UnivariateTaylorSeries"); AInt hFRAC = strHash("Fraction"); AInt hINT = strHash("Integer"); AInt hMapping = strHash("->"); AInt twist = 32236; AInt hULS_FI; AInt hUTS_FI; /*(HASH 484208045 134808007 (|Integer|)) */ testIntEqual("INT", 484208045, hINT); testIntEqual("FRAC", 777777278, hFRAC); testIntEqual("ULS", 241975245, hULS); testIntEqual("UTS", 585167620, hUTS); testIntEqual("->", 51489085, hMapping); /*(HASH 869829933 134808007 (|Fraction| (|Integer|))) */ testIntEqual("FR_INT", 850477418, hashCombinePair(hINT, hFRAC)); /*(HASH 1027140807 134808007 (|Mapping| $ $)) */ testIntEqual("X -> X", 1021768245, hashCombinePair(134808007, hashCombinePair(twist, hashCombinePair(134808007, hMapping)))); /*(HASH 476114119 134808007 (|Mapping| $ $ $)) */ testIntEqual("(X, X) -> X", 898414238, hashCombinePair(134808007, hashCombinePair(twist, hashCombinePair(134808007, hashCombinePair(134808007, hMapping))))); /*(HASH 200862919 134808007 (|Mapping| $ (|Integer|) $)) */ testIntEqual("T1", 972614544, hashCombinePair(134808007, hashCombinePair(twist, hashCombinePair(134808007, hashCombinePair(hINT, hMapping))))); /*(HASH 134808007 0 (|UnivariateLaurentSeries| (|Fraction| (|Integer|)) |z| (0 . 1))) */ hULS_FI = hashCombinePair(7, hashCombinePair(7, hashCombinePair(hashCombinePair(hINT, hFRAC), hULS))); testIntEqual("HULS_FI", 794083080, hULS_FI); /* (HASH 350552519 134808007 (|UnivariateTaylorSeries| (|Fraction| (|Integer|)) |z| (0 . 1))) */ hUTS_FI = hashCombinePair(7, hashCombinePair(7, hashCombinePair(hashCombinePair(hINT, hFRAC), hUTS))); testIntEqual("HUTS_FI", 659312886, hUTS_FI); /*(HASH 476114119 134808007 (|Mapping| $ (|UnivariateTaylorSeries| (|Fraction| (|Integer|)) |z| (0 . 1)) $)) */ testIntEqual("(UTS_FI, X) -> X", 937065739, hashCombinePair(hULS_FI, hashCombinePair(twist, hashCombinePair(hULS_FI, hashCombinePair(hUTS_FI, hMapping))))); /* Clash: UTS_FI/ULS_FI */ testIntEqual("(X, X) -> X", 898414238, hashCombinePair(134808007, hashCombinePair(twist, hashCombinePair(134808007, hashCombinePair(134808007, hMapping))))); }