Added code tests.

This commit is contained in:
Ryan "Lofenyy" Medeiros 2023-07-02 05:55:47 -06:00
parent 4b6ea77913
commit 326be07b4a
5 changed files with 111 additions and 27 deletions

View File

@ -56,6 +56,9 @@ editMaps:
editMaps-debug:
cd Build/;gcc ../Source/editMaps.c -lncurses -g3 -Og -Wall -fanalyzer -o librewands_editmaps
test:
cd Build/;gcc ../Tests/main.c -lncurses -g3 -Og -Wall -fanalyzer -o tests;./tests
format:
clang-format -i Source/*
clang-format -i Tests/*

View File

@ -342,7 +342,7 @@ int main()
if (k == KEY_F(5))
{
echo();
//Get our save name
// Get our save name
mvprintw(4, 0, "Save name: ");
getnstr(buffer1, 8);
@ -351,7 +351,7 @@ int main()
if (k == KEY_F(6))
{
echo();
//Get our load name
// Get our load name
mvprintw(4, 0, "Load name: ");
getnstr(buffer1, 8);

View File

@ -14,6 +14,8 @@
// ---
#include "engineMaps.h"
#include <ncurses.h>
#include <string.h>
// To run at the beginning of the game.
void initEngine()

View File

@ -11,6 +11,31 @@
// You should have received a copy of the GNU General Public License along with LibreWands. If
// not, see https://www.gnu.org/licenses/.
// Allocate memory for our internal map
int newMaps()
{
char buffer[1] = "";
// Allocate the needed memory
map = malloc(255 * sizeof(struct maps));
// On failure, report error.
if (map == NULL)
{
mvprintw(2, 0, "Unable to allocate memory.");
getnstr(buffer, 1);
return 1;
}
else
{
// Or else, record our new number of maps.
nMap = 255;
}
// Exit gracefully
return 0;
}
// Add a new Base tile
uint_fast8_t addBase(uint_fast16_t x, uint_fast16_t y, uint_fast8_t z, uint_fast8_t xmax,
uint_fast8_t ymax, uint_fast8_t t, uint_fast8_t c, uint_fast8_t walk)
@ -207,31 +232,6 @@ int delTile(uint_fast16_t x, uint_fast16_t y, uint_fast8_t z, uint_fast8_t xmax,
return 0;
}
// Allocate memory for our internal map
int newMaps()
{
char buffer[1] = "";
// Allocate the needed memory
map = malloc(255 * sizeof(struct maps));
// On failure, report error.
if (map == NULL)
{
mvprintw(2, 0, "Unable to allocate memory.");
getnstr(buffer, 1);
return 1;
}
else
{
// Or else, record our new number of maps.
nMap = 255;
}
// Exit gracefully
return 0;
}
// Save our internal world map as an XML document.
int saveMaps(char filename[256])
{

View File

@ -10,3 +10,82 @@
// You should have received a copy of the GNU General Public License along with LibreWands. If
// not, see https://www.gnu.org/licenses/.
#include "../Source/engineCore.c"
#include <stdio.h>
#include <stdlib.h>
struct mapmonster mon[5];
// The test function
int test(int input, int value)
{
// If our input doesn't match the expected value
if (input != value)
{
// The test failed.
printf("Test failed.\n");
exit(1);
}
else
{
// Unless it passed.
printf("Passed. \n");
return 0;
}
}
// Test our source code for unexpected output.
int main()
{
// Test allocating our map memory.
printf("newMaps(): ");
test(newMaps(), 0);
// Test creating base tiles.
for (int C = 0; C < 512; C++)
{
printf("addBase(): ");
test(addBase(1, 1, 1, 1, 1, 1, 1, 1), 0);
}
// Test creating info tiles.
for (int C = 0; C < 512; C++)
{
printf("addInfo(): ");
test(addInfo(1, 1, 1, 1, 1, 1, 1, "1"), 0);
}
// Test creating item tiles.
for (int C = 0; C < 512; C++)
{
printf("addItem(): ");
test(addItem(1, 1, 1, 1, 1, 1, 1, 1), 0);
}
// Test creating door tiles.
for (int C = 0; C < 512; C++)
{
printf("addDoor(): ");
test(addDoor(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), 0);
}
// Test creating char tiles.
for (int C = 0; C < 512; C++)
{
printf("addChar(): ");
test(addChar(1, 1, 1, 1, 1, 1, 1, 1, 1, "1", "1", "1", mon), 0);
}
// Test deleting tiles.
printf("delTile(): ");
test(delTile(1, 1, 1, 1, 1), 0);
// Test saving maps
printf("saveMaps(): ");
test(saveMaps("testfile"), 0);
// Test saving maps
printf("loadMaps(): ");
test(loadMaps("testfile"), 0);
}