Esempio n. 1
0
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);
}
Esempio n. 2
0
/* 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);
}
Esempio n. 3
0
void *load_map(int nb, void **args)
{
  const char *file_name = yeGetString(args[0]);
  int fd = open(file_name, O_RDONLY);
  int width = 0;
  Entity *mod_description = nb > 1 ? args[1] : NULL;
  char *name = nb > 3 ? args[3] : NULL;
  Entity *father = nb > 2 ? args[2] : yeCreateArray(NULL, name);
  Entity *map = yeCreateArray(father, "map");

  if (fd < 0) {
    DPRINT_ERR("error when opening '%s'\n", file_name);
    goto error;
  }

  if (!read_map(fd, map, mod_description, file_name, &width, NULL, NULL)) {
    yeReCreateInt(width, father, "width");
    return father;
  }

 error:
  if (nb > 2)
    YE_DESTROY(father);
  YE_DESTROY(map);
  return NULL;
}
Esempio n. 4
0
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);

}
Esempio n. 5
0
static int shooterInit(YWidgetState *wid, YEvent *eve, Entity *arg)
{
    Entity *tmp;

    (void)wid;
    (void)eve;
    yeCreateInt(MAP_SIZE_W, arg, "width");
    arg = yeCreateArray(arg, "map");
    for (int i = 0; i < MAP_SIZE_W * MAP_SIZE_H; ++i) {
        tmp = yeCreateArray(arg, NULL);
        yeCreateInt(0, tmp, NULL);
    }
    ywinAddCallback(ywinCreateNativeCallback("shooterAction", shooterAction));
    ywidBind(wid, "action", "shooterAction");
    return NOTHANDLE;
}
Esempio n. 6
0
File: map.c Progetto: IGLOU-EU/yirl
Entity *ywMapCreatePos(int posX, int posY, Entity *father, const char *str)
{
  Entity *ret = yeCreateArray(father, str);

  yeCreateInt(posX, ret, "x");
  yeCreateInt(posY, ret, "y");
  return ret;
}
Esempio n. 7
0
static int read_map(int fd, Entity *map, Entity *resources,
		    const char *file_name, int *width, int *len, Entity *desc)
{
  int check, pos = 0, i;
  char buff[SM_BUFF_LEN];
  Entity *layers[3];

  if (desc) {
    if (!(yeGetByStrFast(desc, "start_pos") &&
	  yeGetByStrFast(desc, "start_id") &&
	  yeGetByStrFast(desc, "ground_char"))) {
      DPRINT_ERR("missing field in map entity");
      return -1;
    }
    layers[0] = yeCreateArray(yeGetByIdx(map, 0), "map");
    layers[1] = yeCreateArray(yeGetByIdx(map, 1), "map");
    layers[2] = yeCreateArray(yeGetByIdx(map, 2), "map");
  }

 again:
  check = read(fd, buff, SM_BUFF_LEN);
  if (check < 0) {
    DPRINT_ERR("error when reading '%s'\n", file_name);
    return -1;
  }

  for (i = 0; i < check; ++i) {
    if (buff[i] == '\n') {
      *width = *width ? *width : i;
    } else {
      if (desc) {
	create_tild_multi_layers(resources, buff[i], layers, desc, pos, *width);
      } else {
	create_tild(resources, buff[i], map);
      }
      ++pos;
    }
  }
  if (check > 0)
    goto again;
  if (len)
    *len = pos;
  return 0;
}
Esempio n. 8
0
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);
}
Esempio n. 9
0
static void create_tild(Entity *mod_description, int tild, Entity *map)
{
  if (mod_description) {
    Y_BLOCK_ARRAY_FOREACH_PTR(YE_TO_ARRAY(mod_description)->values, tmp,
			      it, ArrayEntry) {
      const char *char_str;

      if (!tmp)
	continue;

      char_str = yeGetString(yeGetByStr(tmp->entity, "map-char"));
      if (char_str[0] == tild) {
	yeCreateInt(it, yeCreateArray(map, NULL), NULL);
	return;
      }
    }
  }
  yeCreateInt(tild, yeCreateArray(map, NULL), NULL);
}
Esempio n. 10
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();
}
Esempio n. 11
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);
}
Esempio n. 12
0
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");
  }
Esempio n. 13
0
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);
}
Esempio n. 14
0
void testMazeGenMod(void)
{
  Entity *maze_info;
  Entity *pos;

#define ymaze_create(maze_info, father, name)				\
  ysCall(ygGetTccManager(), "maze_create", maze_info, father, name)

  GameConfig cfg;

  g_assert(!ygInitGameConfig(&cfg, NULL, NONE));
  g_assert(!ygInit(&cfg));
  g_assert(ygLoadMod(TESTS_PATH"../modules/maze/"));
  yuiRandInit();

  pos = ywPosCreateInts(0, 0, NULL, NULL);
  maze_info = yeCreateArray(NULL, NULL);
  yeCreateInt(0, maze_info, "type");
  yeCreateInt(25, maze_info, "width");
  yeCreateInt(20, maze_info, "height");
  yeCreateInt(4, maze_info, "nb_wall");
  yeCreateInt(1, maze_info, "wall_elem");
  /* maze = ymaze_create(maze_info, NULL, NULL); */
  /* g_assert(maze); */

  /* for (int i = 0; i < 20; ++i) { */
  /*   for (int j = 0; j < 25; ++j) { */
  /*     ywPosSet(pos, j, i); */
  /*     if (yeLen(ywMapGetCase(maze, pos))) */
  /* 	printf("#"); */
  /*     else */
  /* 	printf("."); */
  /*   } */
  /*   printf("\n"); */
  /* } */
  yeMultDestroy(maze_info, pos);
  ygEnd();
  ygCleanGameConfig(&cfg);
}
Esempio n. 15
0
void testListMod(void)
{
  yeInitMem();
  GameConfig cfg;
  Entity *gc = yeCreateArray(NULL, NULL);
  Entity *e1 = yeCreateInt(0, gc, NULL);
  Entity *e2 = yeCreateInt(0, gc, NULL);
  Entity *e3 = yeCreateInt(0, gc, NULL);

  Entity *l;
  Entity *l2;
  Entity *l3;

  g_assert(!ygInitGameConfig(&cfg, NULL, NONE));
  g_assert(!ygInit(&cfg));
  ygLoadMod(TESTS_PATH"../modules/list/");

#define list_init_from_array(elem, father, name) ysCall(ygGetTccManager(), \
							"list_init_from_array",	\
							elem, father, name)
#define list_elem(list) ysCall(ygGetTccManager(), "list_elem", list)
#define list_insert(list, elem) ysCall(ygGetTccManager(), "list_insert", \
				       list, elem)
#define list_next(list) ysCall(ygGetTccManager(), "list_next", list)
#define list_prev(list) ysCall(ygGetTccManager(), "list_prev", list)
#define list_head(list) ysCall(ygGetTccManager(), "list_head", list)
#define list_last(list) ysCall(ygGetTccManager(), "list_last", list)
#define list_pop(list) ysCall(ygGetTccManager(), "list_pop", list)
#define list_insert_before(list, elem) ysCall(ygGetTccManager(),	\
					      "list_insert_before",	\
					      list, elem)
#define list_roll(list) ysCall(ygGetTccManager(), "list_roll", list)
#define list_back_roll(list) ysCall(ygGetTccManager(), "list_back_roll", list)
#define list_to_array(list, father, name) ysCall(ygGetTccManager(),\
						 "list_to_array",  \
						 list, father, name)

  l = ysCall(ygGetTccManager(), "list_init", e1);
  g_assert(l);
  g_assert(list_elem(l) == e1);
  g_assert(list_prev(l) == l);
  g_assert(list_next(l) == l);

  /* test insert */
  g_assert(list_insert(l, e2) == l);
  g_assert(list_elem(list_next(l)) == e2);
  g_assert(list_elem(list_prev(l)) == e2);
  g_assert(list_elem(list_next(list_next(l))) == e1);
  g_assert(list_elem(list_next(list_prev(l))) == e1);

  /* pop second elem */
  l2 = list_pop(list_next(l));
  g_assert(l2 == l);
  g_assert(list_elem(l) == e1);
  g_assert(list_prev(l) == l);
  g_assert(list_next(l) == l);

  /* insert l2 before l1 */
  l2 = list_insert_before(l, e2);
  g_assert(l2 != l);
  g_assert(list_elem(l) == e1);
  g_assert(list_elem(l2) == e2);
  g_assert(list_elem(list_next(l)) == e2);
  g_assert(list_elem(list_prev(l)) == e2);
  g_assert(list_elem(list_next(list_next(l))) == e1);
  g_assert(list_elem(list_next(list_prev(l))) == e1);

  /* insert l3 before l1 */
  /* l2 -> l3 -> l */
  l3 = list_insert_before(l, e3);
  g_assert(l3 == l2);
  l3 = list_next(l2);
  g_assert(list_head(l) == l2);
  g_assert(l3 != l2);
  g_assert(list_elem(l) == e1);
  g_assert(list_elem(l2) == e2);
  g_assert(list_elem(l3) == e3);

  g_assert(list_elem(list_next(l)) == e2);
  g_assert(list_elem(list_prev(l)) == e3);
  g_assert(list_elem(list_next(l3)) == e1);
  g_assert(list_elem(list_prev(l3)) == e2);
  g_assert(list_elem(list_next(list_next(l))) == e3);
  g_assert(list_elem(list_next(list_prev(l))) == e1);

  l3 = list_pop(l3);
  g_assert(l3 == l2);
  g_assert(list_head(l) == l2);
  g_assert(list_next(l2) == l);
  g_assert(list_prev(l2) == l);
  g_assert(list_next(l) == l2);
  g_assert(list_prev(l) == l2);

  l2 = list_pop(l2);
  g_assert(list_head(l) == l);
  g_assert(l == l2);
  g_assert(list_next(l) == l2);
  g_assert(list_prev(l) == l2);

  g_assert(list_insert(l, e2) == l);
  l2 = list_last(l);
  g_assert(list_insert(l2, e2) == l);
  l3 = list_last(l);
  g_assert(l != l2);
  g_assert(l2 != l3);
  g_assert(l != l3);
  g_assert(list_prev(l) == l3);
  g_assert(list_next(l) == l2);
  g_assert(list_next(l2) == l3);
  g_assert(list_head(l) == l);

  g_assert(l2 == list_roll(l3));
  g_assert(l3 == list_roll(l3));
  g_assert(l == list_roll(l3));

  g_assert(l3 == list_back_roll(l3));
  g_assert(l2 == list_back_roll(l3));
  g_assert(l == list_back_roll(l3));

  ysCall(ygGetTccManager(), "list_destroy", l);

  l = list_init_from_array(gc, gc, "list :p");
  g_assert(l);
  g_assert(list_elem(l) == e1);
  g_assert(list_elem(list_next(l)) == e2);
  g_assert(list_elem(list_prev(l)) == e3);
  g_assert(list_elem(list_next(list_next(l))) == e3);
  g_assert(list_elem(list_next(list_prev(l))) == e1);
  g_assert(yeGet(gc, "list :p") == l);
  Entity *ar2 = list_to_array(l, gc, "ar2");
  g_assert(ar2 && ar2 == yeGet(gc, "ar2"));
  g_assert(yeGet(ar2, 0) == e1);
  g_assert(yeGet(ar2, 1) == e2);
  g_assert(yeGet(ar2, 2) == e3);
  ysCall(ygGetTccManager(), "list_destroy", l);
  ygCleanGameConfig(&cfg);

  yeDestroy(gc);
  ygEnd();
}