예제 #1
0
파일: lifecycle.c 프로젝트: IGLOU-EU/yirl
/* 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);
}
예제 #2
0
파일: lifecycle.c 프로젝트: IGLOU-EU/yirl
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);

}
예제 #3
0
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();
}
예제 #4
0
파일: lifecycle.c 프로젝트: IGLOU-EU/yirl
void testLifecycleComplex(void)
{
  Entity *mainStruct = yeCreateArray(NULL, NULL);
  Entity *subStruct1 = yeCreateArray(mainStruct, NULL);
  Entity *subStruct2 = yeCreateArray(mainStruct, NULL);
  Entity *test3 = yeCreateFloat(1, subStruct2, NULL);

  g_assert(mainStruct);
  g_assert(subStruct1);
  g_assert(subStruct2);
  g_assert(!yePushBack(subStruct1, subStruct2, NULL));
  yeExpandArray(subStruct2, 5);
  yeAttach(subStruct2, test3, 2, NULL);
  g_assert(mainStruct->refCount == 1);
  g_assert(subStruct1->refCount == 1);
  g_assert(subStruct2->refCount == 2);
  YE_DESTROY(mainStruct);
  g_assert(mainStruct == NULL);
}