summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt18
-rw-r--r--tests/data/CEP140_512kb.mp4bin0 -> 3628135 bytes
-rw-r--r--tests/test_lib.c28
-rw-r--r--tests/test_source.c53
4 files changed, 99 insertions, 0 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
new file mode 100644
index 0000000..ddfe4f9
--- /dev/null
+++ b/tests/CMakeLists.txt
@@ -0,0 +1,18 @@
+find_package(CUnit)
+
+add_executable(test_lib
+ test_lib.c
+ test_source.c
+)
+
+include_directories(${CUNIT_INCLUDE_DIR} . ../include/)
+if(MINGW)
+ target_link_libraries(test_lib mingw32)
+endif()
+target_link_libraries(test_lib
+ SDL_kitchensink_static
+ ${CUNIT_LIBRARIES}
+ ${SDL2_LIBRARIES}
+ ${FFMPEG_LIBRARIES}
+)
+add_custom_target(unittest test_lib)
diff --git a/tests/data/CEP140_512kb.mp4 b/tests/data/CEP140_512kb.mp4
new file mode 100644
index 0000000..4341032
--- /dev/null
+++ b/tests/data/CEP140_512kb.mp4
Binary files differ
diff --git a/tests/test_lib.c b/tests/test_lib.c
new file mode 100644
index 0000000..92eb058
--- /dev/null
+++ b/tests/test_lib.c
@@ -0,0 +1,28 @@
+#include <CUnit/CUnit.h>
+#include <CUnit/Basic.h>
+#include "kitchensink/kitchensink.h"
+
+void source_test_suite(CU_pSuite suite);
+
+int main(int argc, char **argv) {
+ CU_pSuite suite = NULL;
+
+ Kit_Init(KIT_INIT_NETWORK|KIT_INIT_FORMATS);
+
+ if(CU_initialize_registry() != CUE_SUCCESS) {
+ return CU_get_error();
+ }
+
+ suite = CU_add_suite("Source functions", NULL, NULL);
+ if(suite == NULL) goto end;
+ source_test_suite(suite);
+
+ // Run tests
+ CU_basic_set_mode(CU_BRM_VERBOSE);
+ CU_basic_run_tests();
+
+end:
+ CU_cleanup_registry();
+ Kit_Quit();
+ return CU_get_error();
+}
diff --git a/tests/test_source.c b/tests/test_source.c
new file mode 100644
index 0000000..772ebfd
--- /dev/null
+++ b/tests/test_source.c
@@ -0,0 +1,53 @@
+#include <CUnit/CUnit.h>
+#include <CUnit/Basic.h>
+#include <kitchensink/kitchensink.h>
+
+Kit_Source *src = NULL;
+
+void test_Kit_CreateSourceFromUrl(void) {
+ CU_ASSERT_PTR_NULL(Kit_CreateSourceFromUrl(NULL));
+ CU_ASSERT_PTR_NULL(Kit_CreateSourceFromUrl("nonexistent"));
+ src = Kit_CreateSourceFromUrl("../../tests/data/CEP140_512kb.mp4");
+ CU_ASSERT_PTR_NOT_NULL(src);
+}
+
+void test_Kit_GetBestSourceStream(void) {
+ CU_ASSERT(Kit_GetBestSourceStream(src, KIT_STREAMTYPE_VIDEO) == 0);
+ CU_ASSERT(Kit_GetBestSourceStream(src, KIT_STREAMTYPE_AUDIO) == 1);
+ CU_ASSERT(Kit_GetBestSourceStream(NULL, KIT_STREAMTYPE_AUDIO) == -1);
+ CU_ASSERT(Kit_GetBestSourceStream(src, KIT_STREAMTYPE_UNKNOWN) == -1);
+ CU_ASSERT(Kit_GetBestSourceStream(src, KIT_STREAMTYPE_DATA) == -1);
+ CU_ASSERT(Kit_GetBestSourceStream(src, KIT_STREAMTYPE_ATTACHMENT) == -1);
+ CU_ASSERT(Kit_GetBestSourceStream(src, KIT_STREAMTYPE_SUBTITLE) == -1);
+}
+
+void test_Kit_GetSourceStreamCount(void) {
+ CU_ASSERT(Kit_GetSourceStreamCount(NULL) == -1);
+ CU_ASSERT(Kit_GetSourceStreamCount(src) == 2);
+}
+
+void test_Kit_SetSourceStream(void) {
+ CU_ASSERT(Kit_SetSourceStream(NULL, KIT_STREAMTYPE_VIDEO, 0) == 1);
+ CU_ASSERT(Kit_SetSourceStream(src, KIT_STREAMTYPE_VIDEO, 0) == 0);
+ CU_ASSERT(Kit_SetSourceStream(src, KIT_STREAMTYPE_UNKNOWN, 0) == 1);
+}
+
+void test_Kit_GetSourceStream(void) {
+ CU_ASSERT(Kit_GetSourceStream(NULL, KIT_STREAMTYPE_VIDEO) == -1);
+ CU_ASSERT(Kit_GetSourceStream(src, KIT_STREAMTYPE_VIDEO) == 0);
+ CU_ASSERT(Kit_GetSourceStream(src, KIT_STREAMTYPE_AUDIO) == 1);
+ CU_ASSERT(Kit_GetSourceStream(src, KIT_STREAMTYPE_UNKNOWN) == -1);
+}
+
+void test_Kit_CloseSource(void) {
+ Kit_CloseSource(src);
+}
+
+void source_test_suite(CU_pSuite suite) {
+ if(CU_add_test(suite, "Kit_CreateSourceFromUrl", test_Kit_CreateSourceFromUrl) == NULL) { return; }
+ if(CU_add_test(suite, "Kit_GetBestSourceStream", test_Kit_GetBestSourceStream) == NULL) { return; }
+ if(CU_add_test(suite, "Kit_GetSourceStreamCount", test_Kit_GetSourceStreamCount) == NULL) { return; }
+ if(CU_add_test(suite, "Kit_SetSourceStream", test_Kit_SetSourceStream) == NULL) { return; }
+ if(CU_add_test(suite, "Kit_GetSourceStream", test_Kit_GetSourceStream) == NULL) { return; }
+ if(CU_add_test(suite, "Kit_CloseSource", test_Kit_CloseSource) == NULL) { return; }
+}