2024-02-28 16:10:56 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <string.h>
|
2024-03-12 20:33:01 +00:00
|
|
|
#include <stdio.h>
|
2024-02-28 16:10:56 +00:00
|
|
|
|
|
|
|
#include "spitwad.h"
|
|
|
|
|
2024-03-12 20:33:01 +00:00
|
|
|
// Values from manually inspecting DOOM1.WAD with a third-party tool
|
|
|
|
void assert_doom1_wad(struct WAD *wad) {
|
2024-02-28 16:10:56 +00:00
|
|
|
assert(wad->type == IWAD);
|
|
|
|
assert(wad->dir_sz == 1264);
|
|
|
|
assert(wad->dir_offset == 4175796);
|
|
|
|
assert(wad->directory[0].offset == 12);
|
|
|
|
assert(wad->directory[0].length == 10752);
|
|
|
|
assert(strcmp(wad->directory[0].name, "PLAYPAL") == 0);
|
2024-03-12 20:33:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void basic_test() {
|
|
|
|
struct WAD *wad = malloc(sizeof(struct WAD));
|
|
|
|
assert(new_WAD_from_file(wad, "DOOM1.WAD") == 0);
|
|
|
|
assert_doom1_wad(wad);
|
|
|
|
destroy_WAD(wad);
|
|
|
|
wad = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void read_write_test() {
|
|
|
|
struct WAD *orig = malloc(sizeof(struct WAD));
|
|
|
|
assert(new_WAD_from_file(orig, "DOOM1.WAD") == 0);
|
|
|
|
|
|
|
|
assert(write_to_file(orig, "TEST.WAD") == 0);
|
|
|
|
struct WAD *new = malloc(sizeof(struct WAD));
|
|
|
|
assert(new_WAD_from_file(new, "TEST.WAD") == 0);
|
|
|
|
assert_doom1_wad(new);
|
|
|
|
|
|
|
|
destroy_WAD(orig);
|
|
|
|
orig = NULL;
|
|
|
|
destroy_WAD(new);
|
|
|
|
new = NULL;
|
|
|
|
remove("TEST.WAD");
|
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
basic_test();
|
|
|
|
read_write_test();
|
2024-02-28 16:10:56 +00:00
|
|
|
}
|