mirror of
https://github.com/obsproject/obs-studio.git
synced 2024-07-04 10:33:30 +00:00
test: Add a test for os_get_path_extension
This commit is contained in:
parent
af01bea6a0
commit
7bd27b4da8
|
@ -21,3 +21,10 @@ target_include_directories(test_bitstream PRIVATE ${CMOCKA_INCLUDE_DIR})
|
|||
target_link_libraries(test_bitstream PRIVATE OBS::libobs ${CMOCKA_LIBRARIES})
|
||||
|
||||
add_test(test_bitstream ${CMAKE_CURRENT_BINARY_DIR}/test_bitstream)
|
||||
|
||||
# OS path test
|
||||
add_executable(test_os_path test_os_path.c)
|
||||
target_include_directories(test_os_path PRIVATE ${CMOCKA_INCLUDE_DIR})
|
||||
target_link_libraries(test_os_path PRIVATE OBS::libobs ${CMOCKA_LIBRARIES})
|
||||
|
||||
add_test(test_os_path ${CMAKE_CURRENT_BINARY_DIR}/test_os_path)
|
||||
|
|
54
test/cmocka/test_os_path.c
Normal file
54
test/cmocka/test_os_path.c
Normal file
|
@ -0,0 +1,54 @@
|
|||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <util/platform.h>
|
||||
|
||||
struct testcase {
|
||||
const char *path;
|
||||
const char *ext;
|
||||
};
|
||||
|
||||
static void run_testcases(struct testcase *testcases)
|
||||
{
|
||||
for (size_t i = 0; testcases[i].path; i++) {
|
||||
const char *path = testcases[i].path;
|
||||
|
||||
const char *ext = os_get_path_extension(path);
|
||||
|
||||
printf("path: '%s' ext: '%s'\n", path, ext);
|
||||
if (testcases[i].ext)
|
||||
assert_string_equal(ext, testcases[i].ext);
|
||||
else
|
||||
assert_ptr_equal(ext, testcases[i].ext);
|
||||
}
|
||||
}
|
||||
|
||||
static void os_get_path_extension_test(void **state)
|
||||
{
|
||||
UNUSED_PARAMETER(state);
|
||||
|
||||
static struct testcase testcases[] = {
|
||||
{"/home/user/a.txt", ".txt"},
|
||||
{"C:\\Users\\user\\Documents\\video.mp4", ".mp4"},
|
||||
{"./\\", NULL},
|
||||
{".\\/", NULL},
|
||||
{"/.\\", NULL},
|
||||
{"/\\.", "."},
|
||||
{"\\/.", "."},
|
||||
{"\\./", NULL},
|
||||
{"", NULL},
|
||||
{NULL, NULL}};
|
||||
|
||||
run_testcases(testcases);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test(os_get_path_extension_test),
|
||||
};
|
||||
|
||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||
}
|
Loading…
Reference in a new issue