texdepends/test_path.c

75 lines
1.1 KiB
C
Raw Normal View History

2017-10-25 18:36:02 +02:00
/*
* test_path.c
*
* Created on: 20.10.2017
* Author: julian
*/
#include "tests.h"
#include "fs.h"
#include <string.h>
#include <unistd.h>
const char * reason_invalid_entry = "invalid entry";
void test1() {
init("a/b/c");
struct path p = {};
create_path(&p, "a/b/c");
if (p.len < 3) {
fail("%d, not enough path splits", p.len);
}
if (p.absolute) {
fail("path should be relative");
}
if (strcmp(p.entries[0], "a") != 0) {
fail(reason_invalid_entry);
}
if (strcmp(p.entries[1], "b") != 0) {
fail(reason_invalid_entry);
}
if (strcmp(p.entries[2], "c") != 0) {
fail(reason_invalid_entry);
}
free_path(&p);
pass();
}
void test2() {
init("/a/b/c");
struct path p = {};
create_path(&p, "/a/b/c");
if (p.len != 3) {
fail("%d, not enough path splits", p.len);
}
if (!p.absolute) {
fail("path should be absolute");
}
if (strcmp(p.entries[0], "a") != 0) {
fail(reason_invalid_entry);
}
if (strcmp(p.entries[1], "b") != 0) {
fail(reason_invalid_entry);
}
if (strcmp(p.entries[2], "c") != 0) {
fail(reason_invalid_entry);
}
free_path(&p);
pass();
}
int main() {
init("test_path");
test1();
test2();
pass();
}