diff options
-rw-r--r-- | CMakeLists.txt | 9 | ||||
-rwxr-xr-x | res/check_ck | 11 | ||||
-rw-r--r--[-rwxr-xr-x] | tests/00_init (renamed from tests/init) | 2 | ||||
-rw-r--r-- | tests/01_add (renamed from tests/add) | 4 | ||||
-rw-r--r-- | tests/02_list | 32 | ||||
-rw-r--r-- | tests/03_delete | 58 | ||||
-rw-r--r-- | tests/04_search | 22 | ||||
-rw-r--r-- | tests/05_search | 23 | ||||
-rw-r--r-- | tests/list | 55 | ||||
-rw-r--r-- | unit/ck-test.c | 4 |
10 files changed, 156 insertions, 64 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index c672bcd..6f5117f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -107,9 +107,12 @@ if (CK_TESTS) # copy test files set(BIN_TESTS_DIR ${CMAKE_BINARY_DIR}/res/tests) set(PROJECT_TESTING_GROUNDS ${CMAKE_BINARY_DIR}/test_files) - configure_file(${TESTS_DIR}/init ${BIN_TESTS_DIR}/init @ONLY) - configure_file(${TESTS_DIR}/add ${BIN_TESTS_DIR}/add @ONLY) - configure_file(${TESTS_DIR}/list ${BIN_TESTS_DIR}/list @ONLY) + configure_file(${TESTS_DIR}/00_init ${BIN_TESTS_DIR}/00_init @ONLY) + configure_file(${TESTS_DIR}/01_add ${BIN_TESTS_DIR}/01_add @ONLY) + configure_file(${TESTS_DIR}/02_list ${BIN_TESTS_DIR}/02_list @ONLY) + configure_file(${TESTS_DIR}/03_delete ${BIN_TESTS_DIR}/03_delete @ONLY) + configure_file(${TESTS_DIR}/03_delete ${BIN_TESTS_DIR}/03_delete @ONLY) + configure_file(${TESTS_DIR}/04_search ${BIN_TESTS_DIR}/04_search @ONLY) # check_ck configure_file(${RES_DIR}/check_ck check_ck @ONLY) endif() diff --git a/res/check_ck b/res/check_ck index f8b3a1a..d4683ce 100755 --- a/res/check_ck +++ b/res/check_ck @@ -18,6 +18,17 @@ function init { wait $! } +function add_config { + echo -e "test $2\n$3" > $2 + exec $BIN/ck -c $BIN -a $1 $2 > /dev/null & + wait $! + + if [ $? -ne 0 ]; then + echo -e $ERROR" ck crashed." + exit 1 + fi +} + function clear_tests { rm $BIN/ckrc rm $BIN/ckdb diff --git a/tests/init b/tests/00_init index 015b709..2c5724e 100755..100644 --- a/tests/init +++ b/tests/00_init @@ -5,7 +5,7 @@ running init mkdir -p $TEST_LOCATION/vc mkdir $TEST_LOCATION/sec -exec $BIN/ck conf $BIN init $TEST_LOCATION/vc $TEST_LOCATION/sec & +exec $BIN/ck conf $BIN init $TEST_LOCATION/vc $TEST_LOCATION/sec > /dev/null & wait $! if [ $? -ne 0 ]; then @@ -9,7 +9,7 @@ echo "Test 3" > $BIN/test3.conf function run_add { # add configs to ck - exec $BIN/ck conf $BIN add $1 $BIN/$2 $3 $4 & + exec $BIN/ck conf $BIN add $1 $BIN/$2 $3 $4 > /dev/null & wait $! if [ $? -ne 0 ]; then @@ -46,9 +46,7 @@ function run_add { } run_add prog1 test1.conf -p -echo "" run_add prog2 test2.conf -s -echo "" run_add prog3 test3.conf -p -s clear_tests diff --git a/tests/02_list b/tests/02_list new file mode 100644 index 0000000..014ae62 --- /dev/null +++ b/tests/02_list @@ -0,0 +1,32 @@ +#!/bin/bash + +init list + +# setup test configs +echo "Test 1" > $BIN/test1.conf +echo "Test 2" > $BIN/test2.conf +echo "Test 3" > $BIN/test3.conf + +# add configs to ck +path1=$BIN/test1.conf +path2=$BIN/test2.conf +path3=$BIN/test3.conf + +add_config prog1 $path1 +add_config prog2 $path2 +add_config prog3 $path3 + +for i in $($BIN/ck conf $BIN list paths); do + if [[ "$i" != "$path1" ]] && [[ "$i" != "$path2" ]] && [[ "$i" != "$path3" ]]; then + echo "path good"; + fi +done + +for i in $($BIN/ck conf $BIN list programs); do + if [[ "$i" != "prog1" ]] && [[ "$i" != "prog2" ]] && [[ "$i" != "prog3" ]]; then + echo "program good"; + fi +done + +clear_tests +echo -e $PASS diff --git a/tests/03_delete b/tests/03_delete new file mode 100644 index 0000000..6cc0dbc --- /dev/null +++ b/tests/03_delete @@ -0,0 +1,58 @@ +#!/bin/bash + +init delete + +# setup test configs +path1=$BIN/test1.conf +path2=$BIN/test2.conf +path3=$BIN/test3.conf +path4=$BIN/test4.conf + +add_config prog1 $path1 +add_config prog1 $path2 + +add_config prog2 $path3 +add_config prog2 $path4 + +# delete path1 +exec $BIN/ck conf $BIN del -c $path1 > /dev/null & +wait $! + +for i in $($BIN/ck conf $BIN list paths); do + if [[ "$i" == "$path1" ]]; then + echo -e $ERROR" Couldn't delete path." + exit 1 + fi +done + +# delete path2 (also prog1) +exec $BIN/ck conf $BIN del -c $path2 > /dev/null & +wait $! + +for i in $($BIN/ck conf $BIN list programs); do + if [[ "$i" == "prog1" ]]; then + echo -e $ERROR" Removing all configs should delete the correspondig program." + exit 1 + fi +done + +# delete prog2 +exec $BIN/ck conf $BIN del prog2 > /dev/null & +wait $! + +for i in $($BIN/ck conf $BIN list paths); do + if [[ "$i" == "$path3" ]] || [[ "$i" == "$path4" ]]; then + echo -e $ERROR" Removing the program should delete all it's configs." + exit 1 + fi +done + +for i in $($BIN/ck conf $BIN list programs); do + if [[ "$i" == "prog1" ]]; then + echo -e $ERROR" Couldn't remove program." + exit 1 + fi +done + +clear_tests +echo -e $PASS diff --git a/tests/04_search b/tests/04_search new file mode 100644 index 0000000..a72d97a --- /dev/null +++ b/tests/04_search @@ -0,0 +1,22 @@ +#!/bin/bash + +init search + +# setup test configs +path1=$BIN/test1.conf +path2=$BIN/test2.conf +path3=$BIN/test3.conf +path4=$BIN/test4.conf + +add_config prog1 $path1 "search-term" +add_config prog1 $path2 "search-term" +add_config prog2 $path3 "search-term" +add_config prog3 $path4 "search-term" + +# delete path1 +if [[ $($BIN/ck conf $BIN search search-term | wc -l) != 4 ]]; then + echo -e $ERROR" search failed." +fi + +clear_tests +echo -e $PASS diff --git a/tests/05_search b/tests/05_search new file mode 100644 index 0000000..82772b3 --- /dev/null +++ b/tests/05_search @@ -0,0 +1,23 @@ +#!/bin/bash + +init search + +# setup test configs +path1=$BIN/test1.conf +path2=$BIN/test2.conf +path3=$BIN/test3.conf +path4=$BIN/test4.conf + +add_config prog1 $path1 "search-term" +add_config prog1 $path2 "search-term" +add_config prog2 $path3 "search-term" +add_config prog3 $path4 "search-term" + +# delete path1 +if [[ $($BIN/ck conf $BIN search search-term | wc -l) != 4 ]]; then + echo -e $ERROR" search failed." +fi +done + +clear_tests +echo -e $PASS diff --git a/tests/list b/tests/list deleted file mode 100644 index 7fb4891..0000000 --- a/tests/list +++ /dev/null @@ -1,55 +0,0 @@ -#!/bin/bash - -init list - -# setup test configs -echo "Test 1" > $BIN/test1.conf -echo "Test 2" > $BIN/test2.conf -echo "Test 3" > $BIN/test3.conf - -function run_list { - # add configs to ck - path1=$BIN/test1.conf - exec $BIN/ck conf $BIN add prog1 $path1 -p > /dev/null & - wait $! - - if [ $? -ne 0 ]; then - echo -e $ERROR" ck crashed." - exit 1 - fi - - path2=$BIN/test2.conf - exec $BIN/ck conf $BIN add prog2 $path2 -s > /dev/null & - wait $! - - if [ $? -ne 0 ]; then - echo -e $ERROR" ck crashed." - exit 1 - fi - - path3=$BIN/test3.conf - exec $BIN/ck conf $BIN add prog3 $path3 -p -s > /dev/null & - wait $! - - if [ $? -ne 0 ]; then - echo -e $ERROR" ck crashed." - exit 1 - fi - - for i in $($BIN/ck conf $BIN list paths); do - if [[ "$i" == "$path1" ]] || [[ "$i" == "$path2" ]] || [[ "$i" == "$path3" ]]; then - echo "path good"; - fi - done - - for i in $($BIN/ck conf $BIN list programs); do - if [[ "$i" == "prog1" ]] || [[ "$i" == "prog2" ]] || [[ "$i" == "prog3" ]]; then - echo "program good"; - fi - done -} - -run_list - -clear_tests -echo -e $PASS diff --git a/unit/ck-test.c b/unit/ck-test.c index 9c18dfb..59a8809 100644 --- a/unit/ck-test.c +++ b/unit/ck-test.c @@ -5,8 +5,8 @@ #include "cklist.h" #define CK_UNIT_TESTS \ - X(ck_list_init, "Initialize ck list") \ - X(ck_list_add, "Add elements to ck list") + X(ck_list_init, "Basic cklist test") +// X(ck_list_add, "Add elements to ck list") void ck_list_init() { cklist *ckl1 = list_make_new(); |