aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2020-04-24 12:26:16 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2020-04-24 12:26:16 -0400
commita9f644c24f0b2cccf5b38872a50812efb2dd1e79 (patch)
tree791b63c715305be5005e01c32d96baf24b499aa4 /tests
parentd78903961ee95376bccde7c1313be5b583911ab7 (diff)
downloadspmc-a9f644c24f0b2cccf5b38872a50812efb2dd1e79.tar.gz
Add spm_shlib_deps test
Diffstat (limited to 'tests')
-rw-r--r--tests/test_shlib_spm_shlib_deps.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/test_shlib_spm_shlib_deps.c b/tests/test_shlib_spm_shlib_deps.c
new file mode 100644
index 0000000..2320ea1
--- /dev/null
+++ b/tests/test_shlib_spm_shlib_deps.c
@@ -0,0 +1,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;
+} \ No newline at end of file