void testLifecycleAkwarde(void) { Entity *mainStruct = yeCreateArray(NULL, NULL); Entity *subStruct1 = yeCreateArray(mainStruct, NULL); Entity *subStruct2 = yeCreateArray(subStruct1, NULL); Entity *test3 = yeCreateString("i am an int entity", NULL, NULL); g_assert(mainStruct); g_assert(subStruct1); g_assert(subStruct2); g_assert(test3); g_assert(mainStruct->refCount == 1); g_assert(subStruct1->refCount == 1); g_assert(subStruct2->refCount == 1); g_assert(test3->refCount == 1); g_assert(!yePushBack(mainStruct, test3, NULL)); g_assert(test3->refCount == 2); g_assert(!yePushBack(subStruct1, test3, NULL)); g_assert(test3->refCount == 3); g_assert(!yePushBack(subStruct2, test3, NULL)); g_assert(test3->refCount == 4); YE_DESTROY(mainStruct); g_assert(test3->refCount == 1); g_assert(mainStruct == NULL); YE_DESTROY(test3); }
void testLifecycleSimple(void) { Entity *test1 = yeCreateArray(NULL, NULL); Entity *test2 = yeCreateInt(1, NULL, NULL); Entity *test3 = yeCreateFloat(1, NULL, NULL); Entity *test4 = yeCreateString("test", NULL, NULL); Entity *test5 = yeCreateFunction("funcName", 3, NULL, NULL, NULL); g_assert(test1); g_assert(test2); g_assert(test3); g_assert(test4); g_assert(test5); YE_DESTROY(test1); YE_DESTROY(test2); YE_DESTROY(test3); YE_DESTROY(test4); YE_DESTROY(test5); g_assert(test1 == NULL); g_assert(test2 == NULL); g_assert(test3 == NULL); g_assert(test4 == NULL); g_assert(test5 == NULL); }
void testEntityPatch(void) { yeInitMem(); int t = ydJsonInit(); void *jsonManager; Entity *ret; Entity *mn; Entity *mn2; Entity *entries; Entity *patch; jsonManager = ydNewManager(t); ret = ydFromFile(jsonManager, TESTS_PATH"/widget.json", NULL); mn = yeGet(ret, "MenuTest"); mn2 = yeCreateArray(NULL, NULL); yeCopy(mn, mn2); entries = yeGet(mn2, "entries"); yeRemoveChild(entries, 2); g_assert(yeLen(entries) == 2); patch = yePatchCreate(mn, mn2, NULL, NULL); g_assert(patch); yePatchAply(mn, patch); yeDestroy(patch); g_assert(yeLen(yeGet(mn, "entries")) == 2); /* Manu rentre chez toi c'est a moi qu'tu fait d'la peine... */ yeReCreateString("manu", mn2, "<type>"); yeCreateString("ayoyoyo", mn2, "wololo"); yeRemoveChild(mn2, "background"); yeReCreateInt(1337, mn2, "button_background"); yeSetAt(yeGet(entries, 0), "text", "new text"); yeCreateFloat(3.14, entries, NULL); patch = yePatchCreate(mn, mn2, NULL, NULL); g_assert(patch); yePatchAply(mn, patch); g_assert(!yeStrCmpAt(mn, "ayoyoyo", "wololo")); /* une gonsesse de perdu c'est 10 copains qui reviennes */ g_assert(!yeStrCmpAt(mn, "manu", "<type>")); g_assert(yeGetIntAt(mn, "button_background") == 1337); g_assert(!yeGet(mn, "background")); entries = yeGet(mn, "entries"); g_assert(yeGetFloatAt(entries, 2) == 3.14); g_assert(!yeStrCmpAt(yeGet(entries, 0), "new text", "text")); ydJsonEnd(); ydDestroyManager(jsonManager); yeEnd(); }
void *load_entity(int nb, void **args) { Entity *desc = args[0]; if (nb != 1) { DPRINT_ERR("numbers of arguments incorect\n"); return NULL; } const char *file_name = yeGetString(yeGetByStrFast(desc, "map")); int fd = open(file_name, O_RDONLY); int width = 0, len = 0; Entity *resources = ywMapGetResourcesFromEntity(desc); char *name = nb > 2 ? args[2] : NULL; Entity *father = nb > 1 ? args[1] : NULL; int ret = 0; Entity *entries; if (fd < 1) { DPRINT_ERR("error when opening '%s'\n", file_name); goto error; } yeReCreateString("container", desc, "<type>"); yeCreateString("stacking", desc, "cnt-type"); entries = yeCreateArray(desc, "entries"); yeCreateArray(entries, NULL); yeCreateArray(entries, NULL); yeCreateArray(entries, NULL); if (read_map(fd, entries, resources, file_name, &width, &len, desc)) goto error; YE_ARRAY_FOREACH(entries, map) { yeCreateString("map", map, "<type>"); yeCreateInt(width, map, "width"); yeCreateInt(len, map, "len"); yePushBack(map, resources, "resources"); }
int main(void) { yeInitMem(); GameConfig cfg; char buff[1024]; Entity *modDesc = yeCreateArray(NULL, NULL); Entity *tmp; Entity *map; Entity *path; yuiDebugInit(); //Can not be init twice :) TRY_OR_DIE(ygInitGameConfig(&cfg, gamePath, NONE), -1); TRY_OR_DIE(ygInit(&cfg), die(-1, &cfg)); /* put current path inside buff */ getcwd(buff, 1024); yuistrcpy(buff + yuistrlen(buff), "/test.sm"); path = yeCreateString(buff, NULL, NULL); tmp = yeCreateArray(modDesc, NULL); yeCreateString(".", tmp, "map-char"); tmp = yeCreateArray(modDesc, NULL); yeCreateString("#",tmp, "map-char"); tmp = yeCreateArray(modDesc, NULL); yeCreateString("_", tmp, "map-char"); ygLoadMod("../../../modules/sm-reader/"); map = yesCall(yeGet(ygGetMod("sm-reader"), "load-map"), path, modDesc); char *tmpStr = yeToCStr(map, 4, 0); printf("map: %s\n", tmpStr); g_free(tmpStr); tmpStr = yeToCStr(modDesc, 3, 0); printf("m-d: %s\n", tmpStr); g_free(tmpStr); YE_DESTROY(path); YE_DESTROY(map); YE_DESTROY(modDesc); return die(0, &cfg); }
void testPanelMenuSdl2(void) { yeInitMem(); int t = ydJsonInit(); void *jsonManager; Entity *oret, *ret; YWidgetState *wid; ysRegistreFunc(ysNativeManager(), "menuTest", testMenuEnter); /* load files */ g_assert(t != -1); g_assert(ydJsonGetType() == t); jsonManager = ydNewManager(t); g_assert(jsonManager != NULL); oret = ydFromFile(jsonManager, TESTS_PATH"/widget.json", NULL); ret = yeGet(oret, "MenuTest"); g_assert(ret); g_assert(!ydJsonEnd()); g_assert(!ydDestroyManager(jsonManager)); t = ywMenuInit(); g_assert(t == 0); g_assert(ysdl2Init() != -1); g_assert(ysdl2Type() == 0); yeCreateString("panel", ret, "mn-type"); g_assert(ysdl2RegistreMenu() == 0); wid = ywidNewWidget(ret, NULL); g_assert(wid); do { g_assert(ywidRend(wid) != -1); } while(ywidDoTurn(wid) != ACTION); g_assert(!ywMenuEnd()); YWidDestroy(wid); ysdl2Destroy(); /* end libs */ YE_DESTROY(oret); yeEnd(); }