tests: Add tests for libluna/CPath.h

This commit is contained in:
apio 2023-06-18 20:15:18 +02:00
parent 08997007f2
commit ec34937f14
Signed by: apio
GPG Key ID: B8A7D06E42258954
2 changed files with 158 additions and 0 deletions

View File

@ -18,6 +18,7 @@ luna_test(libluna/TestBase64.cpp TestBase64)
luna_test(libluna/TestUtf8.cpp TestUtf8) luna_test(libluna/TestUtf8.cpp TestUtf8)
luna_test(libluna/TestFormat.cpp TestFormat) luna_test(libluna/TestFormat.cpp TestFormat)
luna_test(libluna/TestHashTable.cpp TestHashTable) luna_test(libluna/TestHashTable.cpp TestHashTable)
luna_test(libluna/TestCPath.cpp TestCPath)
luna_app(run-tests.cpp run-tests) luna_app(run-tests.cpp run-tests)
endif() endif()

157
tests/libluna/TestCPath.cpp Normal file
View File

@ -0,0 +1,157 @@
#include <luna/CPath.h>
#include <string.h>
#include <test.h>
// Test cases taken from the basename(3) manpage on my Arch Linux system (which are taken from SUSv2).
TestResult test_dirname_usr_lib()
{
char path[] = "/usr/lib";
char* dir = dirname(path);
validate(!strcmp(dir, "/usr"));
test_success;
}
TestResult test_basename_usr_lib()
{
char path[] = "/usr/lib";
char* name = basename(path);
validate(!strcmp(name, "lib"));
test_success;
}
TestResult test_dirname_absolute_usr()
{
char path[] = "/usr/";
char* dir = dirname(path);
validate(!strcmp(dir, "/"));
test_success;
}
TestResult test_basename_absolute_usr()
{
char path[] = "/usr/";
char* name = basename(path);
validate(!strcmp(name, "usr"));
test_success;
}
TestResult test_dirname_relative_usr()
{
char path[] = "usr";
char* dir = dirname(path);
validate(!strcmp(dir, "."));
test_success;
}
TestResult test_basename_relative_usr()
{
char path[] = "usr";
char* name = basename(path);
validate(!strcmp(name, "usr"));
test_success;
}
TestResult test_dirname_root()
{
char path[] = "/";
char* dir = dirname(path);
validate(!strcmp(dir, "/"));
test_success;
}
TestResult test_basename_root()
{
char path[] = "/";
char* name = basename(path);
validate(!strcmp(name, "/"));
test_success;
}
TestResult test_dirname_self()
{
char path[] = ".";
char* dir = dirname(path);
validate(!strcmp(dir, "."));
test_success;
}
TestResult test_basename_self()
{
char path[] = ".";
char* name = basename(path);
validate(!strcmp(name, "."));
test_success;
}
TestResult test_dirname_parent()
{
char path[] = "..";
char* dir = dirname(path);
validate(!strcmp(dir, "."));
test_success;
}
TestResult test_basename_parent()
{
char path[] = "..";
char* name = basename(path);
validate(!strcmp(name, ".."));
test_success;
}
Result<void> test_main()
{
test_prelude;
run_test(test_basename_usr_lib);
run_test(test_basename_absolute_usr);
run_test(test_basename_relative_usr);
run_test(test_basename_root);
run_test(test_basename_self);
run_test(test_basename_parent);
run_test(test_dirname_usr_lib);
run_test(test_dirname_absolute_usr);
run_test(test_dirname_relative_usr);
run_test(test_dirname_root);
run_test(test_dirname_self);
run_test(test_dirname_parent);
return {};
}