aboutsummaryrefslogtreecommitdiffstats
path: root/tests/internals/test_internals.c
blob: b388ddbba30b54a280e25251c2a7bad202738526 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65

#include "misc.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>

int failures = 0;

#define TEST_ASSERT(expr) do { if (!(expr)) { printf("Assertion failed: `%s'\n", #expr); failures++; } } while (0);

void test_my_dirname(char *arg, const char *expected)
{
    char *orig = strdup(arg);
    
    const char *ret = my_dirname(arg);
    if (strcmp(ret, expected) != 0) {
        printf("Expected my_dirname(`%s') to return `%s' but got `%s'\n", orig, expected, ret);
        failures++;
    }
    
    free(orig);
}

void my_dirname_suite()
{
    char buf[256];
    
    strcpy(buf, "/foo/bar/baz");
    test_my_dirname(buf, "/foo/bar");
    
    strcpy(buf, "/foo/bar");
    test_my_dirname(buf, "/foo");
    
    strcpy(buf, "/foo");
    test_my_dirname(buf, "/");
    
    strcpy(buf, "/foo/");
    test_my_dirname(buf, "/foo");
    
    strcpy(buf, "/");
    test_my_dirname(buf, "/");
    
    strcpy(buf, "foo");
    test_my_dirname(buf, ".");
    
    strcpy(buf, "foo/bar");
    test_my_dirname(buf, "foo");
    
    strcpy(buf, "./foo/bar");
    test_my_dirname(buf, "./foo");
    
    strcpy(buf, "./foo");
    test_my_dirname(buf, ".");
    
    strcpy(buf, ".");
    test_my_dirname(buf, "..");
}

int main()
{
    my_dirname_suite();

    return (failures > 0) ? 1 : 0;
}