Skip to content

Commit

Permalink
Merge branch 'unit-test-for-master' into 'master'
Browse files Browse the repository at this point in the history
Create first unit test for master

See merge request eriknellessen/encrypting-cloud-storages!5
  • Loading branch information
eriknellessen committed Jan 14, 2022
2 parents 6d22b32 + 7cc2db3 commit d5c6da4
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 18 deletions.
35 changes: 20 additions & 15 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,36 @@ stages:
include:
- template: Code-Quality.gitlab-ci.yml

before_script:
- apt update && apt -y install cmake libgpgme-dev libgcrypt-dev libfuse-dev makepasswd encfs python3-pgpdump opensc-pkcs11 libc6-dev pcscd automake libpcsclite-dev libgtk-3-dev libcriterion-dev
- ln -s /usr/lib/x86_64-linux-gnu/libopensc.so.7.0.0 /usr/lib/x86_64-linux-gnu/libopensc.so

build:
stage: build
# instead of calling g++ directly you can also use some build toolkit like make
# install the necessary build tools when needed
before_script:
- apt update && apt -y install cmake libgpgme-dev libgcrypt-dev libfuse-dev makepasswd encfs python3-pgpdump opensc-pkcs11 libc6-dev pcscd automake libpcsclite-dev libgtk-3-dev
- ln -s /usr/lib/x86_64-linux-gnu/libopensc.so.7.0.0 /usr/lib/x86_64-linux-gnu/libopensc.so
script:
- cd build
- cmake ..
- make install

artifacts:
paths:
# - mybinary
# depending on your build setup it's most likely a good idea to cache outputs to reduce the build time
# cache:
# paths:
# - "*.o"
- build/bin
# depending on your build setup it's most likely a good idea to cache outputs to reduce the build time
cache:
key: build-cache
paths:
- build/

# run tests using the binary built before
#test:
# stage: test
# script:
# - ./runmytests.sh
test:
stage: test
script:
- cd build
- make test
cache:
key: build-cache
paths:
- build/

code_quality:
before_script:
Expand All @@ -50,4 +55,4 @@ code_quality:
variables:
REPORT_FORMAT: html
artifacts:
paths: [gl-code-quality-report.html]
paths: [gl-code-quality-report.html]
27 changes: 27 additions & 0 deletions CMake-Modules/FindCriterion.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# This file is licensed under the WTFPL version 2 -- you can see the full
# license over at http:https://www.wtfpl.net/txt/copying/
#
# - Try to find Criterion
#
# Once done this will define
# CRITERION_FOUND - System has Criterion
# CRITERION_INCLUDE_DIRS - The Criterion include directories
# CRITERION_LIBRARIES - The libraries needed to use Criterion

find_package(PkgConfig)

find_path(CRITERION_INCLUDE_DIR criterion/criterion.h
PATH_SUFFIXES criterion)

find_library(CRITERION_LIBRARY NAMES criterion libcriterion)

set(CRITERION_LIBRARIES ${CRITERION_LIBRARY})
set(CRITERION_INCLUDE_DIRS ${CRITERION_INCLUDE_DIR})

include(FindPackageHandleStandardArgs)
# handle the QUIET and REQUIRED arguments and set CRITERION_FOUND to TRUE
# if all listed variables are TRUE
find_package_handle_standard_args(Criterion DEFAULT_MSG
CRITERION_LIBRARY CRITERION_INCLUDE_DIR)

mark_as_advanced(CRITERION_INCLUDE_DIR CRITERION_LIBRARY)
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,11 @@ if(NOT GTK3_FOUND)
message(FATAL_ERROR "Could not find GTK3")
endif()

find_package(Criterion REQUIRED)
if(NOT CRITERION_FOUND)
message(FATAL_ERROR "Could not find criterion")
endif()

enable_testing()
add_subdirectory(fuseecs)
add_subdirectory(share_a_folder)
add_subdirectory(share_a_folder)
4 changes: 3 additions & 1 deletion fuseecs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 3.0.2)

add_subdirectory(show_signer)

add_subdirectory(test)

execute_process(COMMAND ./configuration.sh ${CMAKE_INSTALL_FULL_BINDIR} ${CMAKE_INSTALL_FULL_LIBDIR} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})

add_library(fuseecsl SHARED fusexmp.c gpg_operations.c)
Expand All @@ -13,4 +15,4 @@ add_executable(fuseecs fuseecs.c)
target_link_libraries(fuseecs fuseecsl)
install(TARGETS fuseecs DESTINATION ${CMAKE_INSTALL_FULL_BINDIR})

install(PROGRAMS start_fuseecs.sh DESTINATION ${CMAKE_INSTALL_FULL_BINDIR})
install(PROGRAMS start_fuseecs.sh DESTINATION ${CMAKE_INSTALL_FULL_BINDIR})
6 changes: 6 additions & 0 deletions fuseecs/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
cmake_minimum_required(VERSION 3.0.2)

add_executable(data_operations_test data_operations_test.c)
target_link_libraries(data_operations_test criterion)

add_test(NAME data_operations_test WORKING_DIRECTORY fuseecs/test COMMAND ./data_operations_test)
9 changes: 9 additions & 0 deletions fuseecs/test/data_operations_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <string.h>
#include <criterion/criterion.h>
#include <criterion/new/assert.h>
#include "../data_operations.h"

Test(data_operations_test_suite, local_string_concatenation_test) {
LOCAL_STR_CAT("foo", "bar", concatenated_string)
cr_assert(eq(str, concatenated_string, "foobar"), "Did not concatenate strings as expected!");
}
2 changes: 1 addition & 1 deletion share_a_folder/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ add_definitions(-Wall -D_FILE_OFFSET_BITS=64)
target_link_libraries(share_a_folder fuseecsl)
install(TARGETS share_a_folder DESTINATION ${CMAKE_INSTALL_FULL_BINDIR})

install(PROGRAMS start_share_a_folder.sh DESTINATION ${CMAKE_INSTALL_FULL_BINDIR})
install(PROGRAMS start_share_a_folder.sh DESTINATION ${CMAKE_INSTALL_FULL_BINDIR})

0 comments on commit d5c6da4

Please sign in to comment.