2019-10-06 08:02:04 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) Sebastian Krzyszkowiak <dos@dosowisko.net>
|
|
|
|
*
|
2022-07-18 19:52:55 +02:00
|
|
|
* This file is part of libsuperderpy.
|
|
|
|
*
|
|
|
|
* libsuperderpy is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published
|
|
|
|
* by the Free Software Foundation; either version 3 of the License, or
|
2019-10-06 08:02:04 +02:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
2022-07-18 19:52:55 +02:00
|
|
|
* libsuperderpy is distributed in the hope that it will be useful,
|
2019-10-06 08:02:04 +02:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2022-07-18 19:52:55 +02:00
|
|
|
* GNU Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with libsuperderpy. If not, see <http://www.gnu.org/licenses/>.
|
2019-10-06 08:02:04 +02:00
|
|
|
*
|
2022-07-18 19:52:55 +02:00
|
|
|
* Also, ponies.
|
2019-10-06 08:02:04 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "tests.h"
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
// -----------------------------------------
|
|
|
|
|
|
|
|
static char* anim = "[animation]\nduration=100\nframes=3\nrepeats=0\nfile=dummy\n";
|
|
|
|
static char* tmpdir = NULL;
|
|
|
|
|
|
|
|
static int character_setup(void** state) {
|
|
|
|
char dir[255] = "libsuperderpy-XXXXXX";
|
2019-11-12 01:25:49 +01:00
|
|
|
if (!mkdtemp(dir)) {
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (chdir(dir)) {
|
|
|
|
exit(2);
|
|
|
|
}
|
2019-10-06 08:02:04 +02:00
|
|
|
mkdir("data", 0700);
|
|
|
|
mkdir("data/sprites", 0700);
|
|
|
|
mkdir("data/sprites/test", 0700);
|
|
|
|
FILE* file = fopen("data/sprites/test/animation.ini", "we");
|
|
|
|
fputs(anim, file);
|
|
|
|
fclose(file);
|
|
|
|
tmpdir = strdup(dir);
|
|
|
|
return engine_setup(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int character_teardown(void** state) {
|
|
|
|
unlink("data/sprites/test/animation.ini");
|
|
|
|
rmdir("data/sprites/test");
|
|
|
|
rmdir("data/sprites");
|
|
|
|
rmdir("data");
|
2019-11-12 01:25:49 +01:00
|
|
|
if (chdir("..")) {
|
|
|
|
exit(3);
|
|
|
|
}
|
2019-10-06 08:02:04 +02:00
|
|
|
rmdir(tmpdir);
|
|
|
|
free(tmpdir);
|
|
|
|
return engine_teardown(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------
|
|
|
|
|
|
|
|
static void character_spritesheet_stops(void** state) {
|
|
|
|
struct Game* game = *state;
|
|
|
|
struct Character* character = CreateCharacter(game, "test");
|
|
|
|
RegisterSpritesheet(game, character, "animation");
|
|
|
|
SelectSpritesheet(game, character, "animation");
|
|
|
|
|
|
|
|
assert_int_equal(character->pos, 0);
|
|
|
|
AnimateCharacter(game, character, 0.1, 1.0);
|
|
|
|
assert_int_equal(character->pos, 1);
|
|
|
|
AnimateCharacter(game, character, 0.1, 1.0);
|
|
|
|
assert_int_equal(character->pos, 2);
|
|
|
|
AnimateCharacter(game, character, 0.1, 1.0);
|
|
|
|
assert_int_equal(character->pos, 2);
|
|
|
|
AnimateCharacter(game, character, 0.1, 1.0);
|
|
|
|
assert_int_equal(character->pos, 2);
|
2022-07-29 17:08:01 +02:00
|
|
|
|
|
|
|
DestroyCharacter(game, character);
|
2019-10-06 08:02:04 +02:00
|
|
|
}
|
|
|
|
|
2019-10-06 08:03:30 +02:00
|
|
|
static void character_spritesheet_reversed_stops(void** state) {
|
|
|
|
struct Game* game = *state;
|
|
|
|
struct Character* character = CreateCharacter(game, "test");
|
|
|
|
RegisterSpritesheet(game, character, "animation");
|
|
|
|
SelectSpritesheet(game, character, "-animation");
|
|
|
|
|
|
|
|
assert_int_equal(character->pos, 2);
|
|
|
|
AnimateCharacter(game, character, 0.1, 1.0);
|
|
|
|
assert_int_equal(character->pos, 1);
|
|
|
|
AnimateCharacter(game, character, 0.1, 1.0);
|
|
|
|
assert_int_equal(character->pos, 0);
|
|
|
|
AnimateCharacter(game, character, 0.1, 1.0);
|
|
|
|
assert_int_equal(character->pos, 0);
|
|
|
|
AnimateCharacter(game, character, 0.1, 1.0);
|
|
|
|
assert_int_equal(character->pos, 0);
|
2022-07-29 17:08:01 +02:00
|
|
|
|
|
|
|
DestroyCharacter(game, character);
|
2019-10-06 08:03:30 +02:00
|
|
|
}
|
|
|
|
|
2019-10-06 08:02:04 +02:00
|
|
|
int test_character(void) {
|
|
|
|
const struct CMUnitTest character_tests[] = {
|
|
|
|
cmocka_unit_test(character_spritesheet_stops),
|
2019-10-06 08:03:30 +02:00
|
|
|
cmocka_unit_test(character_spritesheet_reversed_stops),
|
2019-10-06 08:02:04 +02:00
|
|
|
};
|
|
|
|
return cmocka_run_group_tests(character_tests, character_setup, character_teardown);
|
|
|
|
}
|