diff options
-rw-r--r-- | kdeui/tests/CMakeLists.txt | 4 | ||||
-rw-r--r-- | kwallet/CMakeLists.txt | 1 | ||||
-rw-r--r-- | kwallet/backend/CMakeLists.txt | 2 | ||||
-rw-r--r-- | kwallet/backend/tests/CMakeLists.txt | 33 | ||||
-rw-r--r-- | kwallet/backend/tests/backendtest.cpp | 46 | ||||
-rw-r--r-- | kwallet/backend/tests/testsha.cpp | 54 | ||||
-rw-r--r-- | kwallet/tests/CMakeLists.txt | 39 |
7 files changed, 144 insertions, 35 deletions
diff --git a/kdeui/tests/CMakeLists.txt b/kdeui/tests/CMakeLists.txt index c6baf54ab..56fdf748c 100644 --- a/kdeui/tests/CMakeLists.txt +++ b/kdeui/tests/CMakeLists.txt @@ -22,7 +22,7 @@ link_directories( ${TQT_LIBRARY_DIRS} ) -set( test_PROGS +set( check_PROGS kaboutdialogtest kblendtest kbuttonboxtest kcharselecttest kcolortest kcolordlgtest kcomboboxtest kcompletiontest kdatepicktest kdatewidgettest kdialogbasetest @@ -45,5 +45,5 @@ set( test_PROGS ) foreach( PROG ${test_PROGS} ) - tde_add_executable( ${PROG} AUTOMOC SOURCES "${PROG}.cpp" LINK kdeui-shared ) + tde_add_check_executable( ${PROG} AUTOMOC LINK kdeui-shared ) endforeach( PROG ${test_PROGS} ) diff --git a/kwallet/CMakeLists.txt b/kwallet/CMakeLists.txt index fcc0f90d5..ea861f6da 100644 --- a/kwallet/CMakeLists.txt +++ b/kwallet/CMakeLists.txt @@ -11,3 +11,4 @@ add_subdirectory( client ) add_subdirectory( backend ) +add_subdirectory( tests ) diff --git a/kwallet/backend/CMakeLists.txt b/kwallet/backend/CMakeLists.txt index d447cc255..6ff630d18 100644 --- a/kwallet/backend/CMakeLists.txt +++ b/kwallet/backend/CMakeLists.txt @@ -9,6 +9,8 @@ # ################################################# +add_subdirectory ( tests ) + include_directories( ${TQT_INCLUDE_DIRS} ${CMAKE_BINARY_DIR} diff --git a/kwallet/backend/tests/CMakeLists.txt b/kwallet/backend/tests/CMakeLists.txt new file mode 100644 index 000000000..5f79bd5d9 --- /dev/null +++ b/kwallet/backend/tests/CMakeLists.txt @@ -0,0 +1,33 @@ +################################################# +# +# (C) 2016 Alexander Golubev +# fatzer2 (AT) gmail.com +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +include_directories( + ${TQT_INCLUDE_DIRS} + ${CMAKE_BINARY_DIR} + ${CMAKE_SOURCE_DIR} + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_SOURCE_DIR}/dcop + ${CMAKE_SOURCE_DIR}/kwallet/client + ${CMAKE_SOURCE_DIR}/kwallet/backend + ${CMAKE_BINARY_DIR}/kdecore + ${CMAKE_SOURCE_DIR}/kdecore +) + +link_directories( + ${TQT_LIBRARY_DIRS} +) + +tde_add_check_executable( backendtest AUTOMOC + LINK kwalletbackend-shared kwalletclient-shared TEST ) +tde_add_check_executable( testbf AUTOMOC + LINK kwalletbackend-shared kwalletclient-shared TEST ) +tde_add_check_executable( testsha AUTOMOC + LINK kwalletbackend-shared kwalletclient-shared TEST ) diff --git a/kwallet/backend/tests/backendtest.cpp b/kwallet/backend/tests/backendtest.cpp index e7599b3a2..c96fa42ce 100644 --- a/kwallet/backend/tests/backendtest.cpp +++ b/kwallet/backend/tests/backendtest.cpp @@ -2,12 +2,28 @@ #include <stdio.h> #include <kapplication.h> +#include <kaboutdata.h> +#include <kcmdlineargs.h> #include <tqstring.h> #include "kwalletbackend.h" +#define CHECK_RETURN(func, test, test_str) { \ + int rc = (func); \ + test_cnt++;\ + if (test) {\ + printf("%-20s returned %d as expected (should be %s)\n", #func, rc, test_str);\ + } else {\ + printf("%-20s returned %d UNEXPECTEDLY (should be %s)\n", #func, rc, test_str);\ + test_failed++;\ + }\ +} + int main(int argc, char **argv) { - KApplication a(argc, argv, "kwalletbackendtest"); + KAboutData aboutData( "kwalletbackendtest", "kwallet backend testing routine", "0.1" ); + + KCmdLineArgs::init( argc, argv, &aboutData ); + KApplication a(false, false); KWallet::Backend be("ktestwallet"); printf("KWalletBackend constructed\n"); @@ -18,28 +34,22 @@ int main(int argc, char **argv) { bpass.duplicate("bpassword", 9); cpass.duplicate("cpassword", 9); - printf("Passwords initialised.\n"); - int rc = be.close(apass); - - printf("be.close(apass) returned %d (should be -255)\n", rc); - rc = be.open(bpass); + int test_cnt = 0; + int test_failed = 0; - printf("be.open(bpass) returned %d (should be 0 or 1)\n", rc); - - rc = be.close(bpass); - - printf("be.close(bpass) returned %d (should be 0)\n", rc); - - rc = be.open(apass); - - printf("be.open(apass) returned %d (should be negative)\n", rc); + printf("Passwords initialised.\n"); - rc = be.open(bpass); + CHECK_RETURN(be.close(apass), rc==-255, "-255"); + CHECK_RETURN(be.open(bpass), rc==0 || rc==1, "0 or 1"); + CHECK_RETURN(be.close(bpass), rc==0, "0 or 1"); + CHECK_RETURN(be.open(apass), rc<0, "negative"); + CHECK_RETURN(be.open(bpass), rc==0, "0"); - printf("be.open(bpass) returned %d (should be 0)\n", rc); + printf ("===========================================\n"); + printf ("%d test failed out of %d\n", test_failed, test_cnt); - return 0; + return test_failed == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/kwallet/backend/tests/testsha.cpp b/kwallet/backend/tests/testsha.cpp index 70879f015..cc6263edb 100644 --- a/kwallet/backend/tests/testsha.cpp +++ b/kwallet/backend/tests/testsha.cpp @@ -3,12 +3,27 @@ #include <string.h> #include "sha1.h" +void printHex (const unsigned char *data) { + for (int i = 0; i < 20; i++) { + printf("%.2X", *data++); + if (i>0 && (i-1)%2 == 0) printf(" "); + } + printf("\n"); +} int main() { -SHA1 *sha1; -unsigned char data[] = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"; -unsigned long et[] = {0x11223344}; -int rc; + SHA1 *sha1; + const unsigned char data[] = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"; + const unsigned char expected[20] = { + 0x84, 0x98, 0x3e, 0x44, + 0x1c, 0x3b, 0xd2, 0x6e, + 0xba, 0xae, 0x4a, 0xa1, + 0xf9, 0x51, 0x29, 0xe5, + 0xe5, 0x46, 0x70, 0xf1 + }; + + unsigned long et[] = {0x11223344}; + int rc; printf("%d: 0x11 == %d and 0x44 == %d\n", ((unsigned char *)et)[0], 0x11, 0x44); @@ -22,22 +37,31 @@ int rc; printf("About to process [%s]\n", data); rc = sha1->process(data, strlen((char *)data)); - if (rc != strlen((char *)data)) { + if (rc != (int)strlen((char *)data)) { printf("Error processing the data. rc=%d\n", rc); + return -1; } else printf("Done.\n"); -const unsigned char *res = sha1->getHash(); + const unsigned char *res = sha1->hash(); if (res) { - for (int i = 0; i < 20; i++) { - printf("%.2X", *res++); - if (i>0 && (i-1)%2 == 0) printf(" "); - } - printf("\n"); - } else printf("Error - getHash() returned NULL!\n"); + if (memcmp (res, expected, 20) ==0 ) { + printf("The result is expected: "); + printHex (res); + } else { + printf("The result is different from expected:\n"); + printf("Result: "); + printHex (res); + printf("Expected: "); + printHex (expected); + return -1; + } + } else { + printf("Error - hash() returned NULL!\n"); + return -1; + } delete sha1; -} - - + return 0; +} diff --git a/kwallet/tests/CMakeLists.txt b/kwallet/tests/CMakeLists.txt new file mode 100644 index 000000000..88dea2666 --- /dev/null +++ b/kwallet/tests/CMakeLists.txt @@ -0,0 +1,39 @@ +################################################# +# +# (C) 2016 Alexander Golubev +# fatzer2 (AT) gmail.com +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +include_directories( + ${TQT_INCLUDE_DIRS} + ${CMAKE_BINARY_DIR} + ${CMAKE_SOURCE_DIR} + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_SOURCE_DIR}/dcop + ${CMAKE_SOURCE_DIR}/kwallet/client + ${CMAKE_BINARY_DIR}/kdecore + ${CMAKE_SOURCE_DIR}/kdecore +) + +link_directories( + ${TQT_LIBRARY_DIRS} +) + +add_definitions ( + -DKDE_NO_COMPAT + -DQT_NO_COMPAT + -DQT_NO_ASCII_CAST +) + +tde_add_check_executable( kwalletsync AUTOMOC LINK kwalletclient-shared ) +tde_add_check_executable( kwalletasync AUTOMOC + SOURCES kwalletasync.cpp kwallettest.cpp + LINK kwalletclient-shared ) +tde_add_check_executable( kwalletaboth AUTOMOC + SOURCES kwalletboth.cpp kwallettest.cpp + LINK kwalletclient-shared ) |