aboutsummaryrefslogtreecommitdiff
path: root/tests/test_shlib_spm_shlib_deps.c
blob: 2320ea1531716685f1fbc0e95106ef79b9fd4dd4 (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
#include "spm.h"
#include "framework.h"

struct TestCase testCase[] = {
        {.caseValue.sptr = "/bin/sh", .truthValue.signed_integer = 0},
        {.caseValue.sptr = "/usr/bin/tar", .truthValue.signed_integer = 0},
        {.caseValue.sptr = "/dev/null", .truthValue.signed_integer = -1}, // not an object
        {.caseValue.sptr = NULL, .truthValue.signed_integer = -1}, // invalid call
};
size_t numCases = sizeof(testCase) / sizeof(struct TestCase);

int main(int argc, char *argv[]) {
    for (size_t i = 0; i < numCases; i++) {
        StrList *result = shlib_deps(testCase[i].caseValue.sptr);
        if (result == NULL && testCase[i].truthValue.signed_integer < 0 && spmerrno == EINVAL) {
            // expected failure
            continue;
        }

        myassert(spmerrno == 0, "case %zu: raised unhandled exception %d: %s\n", i, spmerrno, spm_strerror(spmerrno));
        myassert(result != NULL, "case %zu: unexpected NULL", i);
        for (size_t j = 0; j < strlist_count(result);  j++) {
            char *item = strlist_item(result, j);
            myassert(exists(item) == testCase[i].truthValue.signed_integer,
                    "library record found, but does not exist: '%s' (your OS is broken)\n", item);
        }
        strlist_free(result);
    }
    return 0;
}