/* this tests is actually usefull only with valgrind */ void testLifecycleFlow(void) { Entity *mainStruct = yeCreateArray(NULL, NULL); Entity *subStruct1 = yeCreateArray(mainStruct, NULL); Entity *subStruct2 = yeCreateArray(NULL, NULL); Entity *test2 = yeCreateInt(1, subStruct2, NULL); Entity *test3 = yeCreateFloat(1, subStruct2, NULL); g_assert(test2); g_assert(test3); g_assert(mainStruct); g_assert(subStruct1); g_assert(subStruct2); g_assert(yeLen(mainStruct) == 1); g_assert(yeLen(subStruct2) == 2); g_assert(!yePushBack(mainStruct, subStruct2, NULL)); g_assert(yeLen(mainStruct) == 2); g_assert(mainStruct->refCount == 1); g_assert(subStruct1->refCount == 1); g_assert(test3->refCount == 1); g_assert(test2->refCount == 1); g_assert(subStruct2->refCount == 2); YE_DESTROY(subStruct2); g_assert(subStruct2); g_assert(subStruct2->refCount == 1); YE_DESTROY(mainStruct); g_assert(mainStruct == 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(); }
static char getPrintableChar(Entity *mapCases, Entity *res) { size_t ret = ywMapGetIdByElem(yeGet(mapCases, yeLen(mapCases) - 1)); res = yeGet(yeGet(res, ret), "map-char"); return res != NULL ? yeGetString(res)[0] : '-'; }
void testLifeDeathRebirdAndAgain(void) { Entity *mainEnt = yeCreateArray(NULL, NULL); Entity *map; Entity *tmp; yeCreateInt(100, mainEnt, "width"); map = yeCreateArray(mainEnt, "map"); g_assert(map); for (int i = 0; i < 2000; ++i) { tmp = yeCreateArray(map, NULL); g_assert(tmp); g_assert(yeCreateInt(0, tmp, NULL)); } tmp = yeGet(map, 500); g_assert(tmp); yeCreateInt(1, tmp, "hr"); int good = 0;; for (int j = 500; j < 1000; ++j) { tmp = yeGet(map, j); for (unsigned int i = 0; i < yeLen(tmp); ++i) { Entity *curHero = yeGet(tmp, i); if (yeGetInt(curHero) == 1) { good = 1; /* You can get it Noww !!!! */ g_assert(yeLen(tmp) == 2); yeRemoveChild(tmp, curHero); g_assert(yeLen(tmp) == 1); break; } } } g_assert(good); YE_DESTROY(mainEnt); }
static int cursesRender(YWidgetState *state, int t) { CWidget *wid = ywidGetRenderData(state, t); int x,y,h,w; unsigned int curx = 0, cury = 0; Entity *map = yeGet(state->entity, "map"); Entity *res = ywMapGetResources(state); unsigned int lenMap = yeLen(map); unsigned int wMap = yeGetInt(yeGet(state->entity, "width")); unsigned int hMap = lenMap / wMap; wmove(wid->win,0,0); getyx(wid->win, y, x); getmaxyx(wid->win, h, w); w -= x; h -= y; for (unsigned int i = 0; i < lenMap; ++i) { Entity *mapCase = yeGet(map, i); if (curx >= wMap) { curx = 0; ++cury; } mvwaddch(wid->win, (cury + 1) + (h/2 - hMap / 2), (curx + 1) + (w/2 - wMap / 2), getPrintableChar(mapCase, res)); ++curx; } wrefresh(wid->win); return 0; }