From d202883e6d642ba5a973996654cfed674420da22 Mon Sep 17 00:00:00 2001 From: Anastasis Grammenos Date: Sun, 7 Oct 2018 14:10:52 +0300 Subject: Update regression tests --- CMakeLists.txt | 9 ++++++--- res/check_ck | 11 +++++++++++ tests/00_init | 29 +++++++++++++++++++++++++++++ tests/01_add | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/02_list | 32 +++++++++++++++++++++++++++++++ tests/03_delete | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/04_search | 22 ++++++++++++++++++++++ tests/05_search | 23 +++++++++++++++++++++++ tests/add | 55 ------------------------------------------------------ tests/init | 29 ----------------------------- tests/list | 55 ------------------------------------------------------ unit/ck-test.c | 4 ++-- 12 files changed, 236 insertions(+), 144 deletions(-) create mode 100644 tests/00_init create mode 100644 tests/01_add create mode 100644 tests/02_list create mode 100644 tests/03_delete create mode 100644 tests/04_search create mode 100644 tests/05_search delete mode 100644 tests/add delete mode 100755 tests/init delete mode 100644 tests/list 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/00_init b/tests/00_init new file mode 100644 index 0000000..2c5724e --- /dev/null +++ b/tests/00_init @@ -0,0 +1,29 @@ +#!/bin/bash + +running init + +mkdir -p $TEST_LOCATION/vc +mkdir $TEST_LOCATION/sec + +exec $BIN/ck conf $BIN init $TEST_LOCATION/vc $TEST_LOCATION/sec > /dev/null & +wait $! + +if [ $? -ne 0 ]; then + echo -e $ERROR" ck crashed." + exit 1 +fi + +if [ ! -f $BIN/ckrc ]; then + echo -e $ERROR" Config file not created." + exit 1 +fi + +if [ ! -f $BIN/ckdb ]; then + echo -e $ERROR" DB file not created." + exit 1 +fi + +rm $BIN/ckrc +rm $BIN/ckdb +rm -rf $TEST_LOCATION +echo -e $PASS diff --git a/tests/01_add b/tests/01_add new file mode 100644 index 0000000..15ff2b0 --- /dev/null +++ b/tests/01_add @@ -0,0 +1,53 @@ +#!/bin/bash + +init add + +# setup test configs +echo "Test 1" > $BIN/test1.conf +echo "Test 2" > $BIN/test2.conf +echo "Test 3" > $BIN/test3.conf + +function run_add { + # add configs to ck + exec $BIN/ck conf $BIN add $1 $BIN/$2 $3 $4 > /dev/null & + wait $! + + if [ $? -ne 0 ]; then + echo -e $ERROR" ck crashed." + exit 1 + fi + + # check db + if [ "$(sqlite3 $BIN/ckdb "select name from program where name = '$1'")" != "$1" ]; then + echo -e $ERROR $1" is not in the db." + exit 1 + fi + + if [ "$(sqlite3 $BIN/ckdb "select path from config where path = '$BIN/$2'")" != "$BIN/$2" ]; then + echo -e $ERROR $2" is not in the db." + exit 1 + fi + + # check files + FOLDER=vc + if [[ "$3" = "-s" || "$4" = "-s" ]]; then + FOLDER=sec + fi + + if [ ! -f $TEST_LOCATION/$FOLDER/$1/$2 ]; then + echo -e $ERROR$2" No move (add "$3" "$4")" + exit 1 + fi + + if [ ! -L $BIN/$2 ]; then + echo -e $ERROR$2" No symlink (add "$3" "$4")" + exit 1 + fi +} + +run_add prog1 test1.conf -p +run_add prog2 test2.conf -s +run_add prog3 test3.conf -p -s + +clear_tests +echo -e $PASS 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/add b/tests/add deleted file mode 100644 index b1c592f..0000000 --- a/tests/add +++ /dev/null @@ -1,55 +0,0 @@ -#!/bin/bash - -init add - -# setup test configs -echo "Test 1" > $BIN/test1.conf -echo "Test 2" > $BIN/test2.conf -echo "Test 3" > $BIN/test3.conf - -function run_add { - # add configs to ck - exec $BIN/ck conf $BIN add $1 $BIN/$2 $3 $4 & - wait $! - - if [ $? -ne 0 ]; then - echo -e $ERROR" ck crashed." - exit 1 - fi - - # check db - if [ "$(sqlite3 $BIN/ckdb "select name from program where name = '$1'")" != "$1" ]; then - echo -e $ERROR $1" is not in the db." - exit 1 - fi - - if [ "$(sqlite3 $BIN/ckdb "select path from config where path = '$BIN/$2'")" != "$BIN/$2" ]; then - echo -e $ERROR $2" is not in the db." - exit 1 - fi - - # check files - FOLDER=vc - if [[ "$3" = "-s" || "$4" = "-s" ]]; then - FOLDER=sec - fi - - if [ ! -f $TEST_LOCATION/$FOLDER/$1/$2 ]; then - echo -e $ERROR$2" No move (add "$3" "$4")" - exit 1 - fi - - if [ ! -L $BIN/$2 ]; then - echo -e $ERROR$2" No symlink (add "$3" "$4")" - exit 1 - fi -} - -run_add prog1 test1.conf -p -echo "" -run_add prog2 test2.conf -s -echo "" -run_add prog3 test3.conf -p -s - -clear_tests -echo -e $PASS diff --git a/tests/init b/tests/init deleted file mode 100755 index 015b709..0000000 --- a/tests/init +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash - -running init - -mkdir -p $TEST_LOCATION/vc -mkdir $TEST_LOCATION/sec - -exec $BIN/ck conf $BIN init $TEST_LOCATION/vc $TEST_LOCATION/sec & -wait $! - -if [ $? -ne 0 ]; then - echo -e $ERROR" ck crashed." - exit 1 -fi - -if [ ! -f $BIN/ckrc ]; then - echo -e $ERROR" Config file not created." - exit 1 -fi - -if [ ! -f $BIN/ckdb ]; then - echo -e $ERROR" DB file not created." - exit 1 -fi - -rm $BIN/ckrc -rm $BIN/ckdb -rm -rf $TEST_LOCATION -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(); -- cgit v1.2.3