示例#1
0
文件: contener.c 项目: IGLOU-EU/yirl
void testVerticalContenerSdl(void)
{
  GameConfig cfg;
  Entity *ret;
  YWidgetState *wid;
  int t = ydJsonInit();
  void *jsonManager;

  /* Init libs */
  g_assert(!ygInitGameConfig(&cfg, NULL, SDL2));
  g_assert(!ygInit(&cfg));

  /* Parsing json */
  jsonManager = ydNewManager(t);
  ret = ydFromFile(jsonManager, TESTS_PATH"/widget.json");
  ret = yeGet(ret, "ContenerTest");
  g_assert(ret);
  ywinAddCallback(ywinCreateNativeCallback("menuTest", testMenuEnter));

  wid = ywidNewWidget(ret, NULL);
  g_assert(wid);

  do {
    g_assert(ywidRend(wid) != -1);
  } while(ywidDoTurn(wid) != ACTION);

  YE_DESTROY(ret);
  ygEnd();
}
示例#2
0
void testSukeFightMod(void)
{
  yeInitMem();
  GameConfig cfg;
  Entity *fight_example;
  Entity *mod;
  YWidgetState *wid;

  g_assert(!ygInitGameConfig(&cfg, NULL, SDL2));
  g_assert(!ygInit(&cfg));
  mod = ygLoadMod(TESTS_PATH"../modules/sukeban-fight/");
  g_assert(mod);
  fight_example = ygFileToEnt(YJSON,
			      TESTS_PATH
			      "../modules/sukeban-fight/combat_example.json",
			      NULL);
  g_assert(fight_example);
  ysRegistreNativeFunc("attack", attack);
  yeCreateFunctionSimple("attack", ysNativeManager(), mod);
  wid = ywidNewWidget(fight_example, NULL);
  g_assert(wid);
  ywidSetMainWid(wid);
  ygDoLoop();
  yeDestroy(fight_example);
  ygCleanGameConfig(&cfg);
  ygEnd();
}
示例#3
0
文件: test-game.c 项目: IGLOU-EU/yirl
void testYGameAllLibBasic(void)
{
    GameConfig cfg;

    g_assert(!ygInitGameConfig(&cfg, testPath, ALL));
    g_assert(!ygInit(&cfg));
    ywinAddCallback(ywinCreateNativeCallback("shooterInit", shooterInit));
    g_assert(!ygStartLoop(&cfg));
    ygCleanGameConfig(&cfg);
    ygEnd();
}
示例#4
0
文件: main.c 项目: cosmo-ray/yirl
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);
}
示例#5
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);
}
示例#6
0
文件: list-mod.c 项目: cosmo-ray/yirl
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();
}