Browse Source

Add google test for testing the library.

Godzil 2 months ago
parent
commit
ff5cfce715
5 changed files with 38 additions and 0 deletions
  1. 3 0
      .gitmodules
  2. 8 0
      CMakeLists.txt
  3. 1 0
      external/googletest
  4. 19 0
      test/CMakeLists.txt
  5. 7 0
      test/fs_opening.cpp

+ 3 - 0
.gitmodules

@@ -1,3 +1,6 @@
 [submodule "external/cJSON"]
 	path = external/cJSON
 	url = https://github.com/DaveGamble/cJSON.git
+[submodule "external/googletest"]
+	path = external/googletest
+	url = https://github.com/google/googletest.git

+ 8 - 0
CMakeLists.txt

@@ -19,6 +19,7 @@ set(BUILD_PLATFORM MEMORY CACHE STRING "Platform to build for")
 set_property(CACHE BUILD_PLATFORM PROPERTY STRINGS ${VALID_BUILD_PLATFORM})
 
 option(BUILD_HOST_TOOLS "Build offline tools" ON)
+option(RUN_TESTS "Run the test suite to verify everything is ok!" ON)
 
 string(TOLOWER ${BUILD_PLATFORM} PLATFORM_FILE)
 
@@ -39,3 +40,10 @@ if (BUILD_HOST_TOOLS)
     target_compile_definitions(mffs PRIVATE BUILD_PLATFORM_FILE)
     target_compile_definitions(mffs PRIVATE BUILD_HOST_TOOLS)
 endif()
+
+if(RUN_TESTS)
+    enable_testing()
+    include(GoogleTest)
+    add_subdirectory("${PROJECT_SOURCE_DIR}/external/googletest" "external/googletest")
+    add_subdirectory(test)
+endif()

+ 1 - 0
external/googletest

@@ -0,0 +1 @@
+Subproject commit 56246cdb94de94f7f43c9df59635db92c41d4064

+ 19 - 0
test/CMakeLists.txt

@@ -0,0 +1,19 @@
+project(MiniFFSTests)
+
+set(THREADS_PREFER_PTHREAD_FLAG ON)
+find_package(Threads REQUIRED)
+
+include_directories(../includes)
+link_libraries(miniffs)
+
+set(TESTS_SRC fs_opening.cpp)
+
+add_executable(miniffs_test)
+target_include_directories(miniffs_test PUBLIC ${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
+target_sources(miniffs_test PRIVATE ${TESTS_SRC})
+target_link_libraries(miniffs_test gtest gtest_main Threads::Threads)
+
+gtest_discover_tests(miniffs_test
+        WORKING_DIRECTORY ${PROJECT_DIR}
+        PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${PROJECT_DIR}"
+)

+ 7 - 0
test/fs_opening.cpp

@@ -0,0 +1,7 @@
+/******************************************************************************
+ * MiniFFS : Mini Flat File System
+ * This file is part of the test suite of MiniFFS
+ *
+ * Copyright (c) 2008-2022 986-Studio. All rights reserved.
+ *
+ ******************************************************************************/