summaryrefslogtreecommitdiffstats
path: root/tdewallet
diff options
context:
space:
mode:
authorAlexander Golubev <fatzer2@gmail.com>2016-12-21 01:13:31 +0300
committerSlávek Banko <slavek.banko@axis.cz>2017-01-29 02:27:15 +0100
commit16a176dab1e978bef8f8d49801fa98a028d1d17b (patch)
treeb183e4bc3b28c6e858bb07c696cfdd3af41ac565 /tdewallet
parented74769bfaae171809c0bc1a10a8ba0f6ff8895f (diff)
downloadtdelibs-16a176dab1e978bef8f8d49801fa98a028d1d17b.tar.gz
tdelibs-16a176dab1e978bef8f8d49801fa98a028d1d17b.zip
tdeui & tdewallet: add tests
Signed-off-by: Alexander Golubev <fatzer2@gmail.com>
Diffstat (limited to 'tdewallet')
-rw-r--r--tdewallet/CMakeLists.txt1
-rw-r--r--tdewallet/backend/CMakeLists.txt2
-rw-r--r--tdewallet/backend/tests/CMakeLists.txt33
-rw-r--r--tdewallet/backend/tests/backendtest.cpp46
-rw-r--r--tdewallet/backend/tests/testsha.cpp54
-rw-r--r--tdewallet/tests/CMakeLists.txt39
6 files changed, 142 insertions, 33 deletions
diff --git a/tdewallet/CMakeLists.txt b/tdewallet/CMakeLists.txt
index fcc0f90d5..ea861f6da 100644
--- a/tdewallet/CMakeLists.txt
+++ b/tdewallet/CMakeLists.txt
@@ -11,3 +11,4 @@
add_subdirectory( client )
add_subdirectory( backend )
+add_subdirectory( tests )
diff --git a/tdewallet/backend/CMakeLists.txt b/tdewallet/backend/CMakeLists.txt
index 886e6c385..57a1e77ac 100644
--- a/tdewallet/backend/CMakeLists.txt
+++ b/tdewallet/backend/CMakeLists.txt
@@ -9,6 +9,8 @@
#
#################################################
+add_subdirectory ( tests )
+
include_directories(
${TQT_INCLUDE_DIRS}
${CMAKE_BINARY_DIR}
diff --git a/tdewallet/backend/tests/CMakeLists.txt b/tdewallet/backend/tests/CMakeLists.txt
new file mode 100644
index 000000000..6f2b8a023
--- /dev/null
+++ b/tdewallet/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}/tdewallet/client
+ ${CMAKE_SOURCE_DIR}/tdewallet/backend
+ ${CMAKE_BINARY_DIR}/tdecore
+ ${CMAKE_SOURCE_DIR}/tdecore
+)
+
+link_directories(
+ ${TQT_LIBRARY_DIRS}
+)
+
+tde_add_check_executable( backendtest AUTOMOC
+ LINK tdewalletbackend-shared tdewalletclient-shared TEST )
+tde_add_check_executable( testbf AUTOMOC
+ LINK tdewalletbackend-shared tdewalletclient-shared TEST )
+tde_add_check_executable( testsha AUTOMOC
+ LINK tdewalletbackend-shared tdewalletclient-shared TEST )
diff --git a/tdewallet/backend/tests/backendtest.cpp b/tdewallet/backend/tests/backendtest.cpp
index 85e916940..306aa3c4b 100644
--- a/tdewallet/backend/tests/backendtest.cpp
+++ b/tdewallet/backend/tests/backendtest.cpp
@@ -2,12 +2,28 @@
#include <stdio.h>
#include <tdeapplication.h>
+#include <tdeaboutdata.h>
+#include <tdecmdlineargs.h>
#include <tqstring.h>
#include "tdewalletbackend.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) {
- TDEApplication a(argc, argv, "tdewalletbackendtest");
+ TDEAboutData aboutData( "tdewalletbackendtest", "tdewallet backend testing routine", "0.1" );
+
+ TDECmdLineArgs::init( argc, argv, &aboutData );
+ TDEApplication a(false, false);
TDEWallet::Backend be("ktestwallet");
printf("TDEWalletBackend 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/tdewallet/backend/tests/testsha.cpp b/tdewallet/backend/tests/testsha.cpp
index 70879f015..cc6263edb 100644
--- a/tdewallet/backend/tests/testsha.cpp
+++ b/tdewallet/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/tdewallet/tests/CMakeLists.txt b/tdewallet/tests/CMakeLists.txt
new file mode 100644
index 000000000..a5f9435be
--- /dev/null
+++ b/tdewallet/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}/tdewallet/client
+ ${CMAKE_BINARY_DIR}/tdecore
+ ${CMAKE_SOURCE_DIR}/tdecore
+)
+
+link_directories(
+ ${TQT_LIBRARY_DIRS}
+)
+
+add_definitions (
+ -DKDE_NO_COMPAT
+ -DQT_NO_COMPAT
+ -DQT_NO_ASCII_CAST
+)
+
+tde_add_check_executable( tdewalletsync AUTOMOC LINK tdewalletclient-shared )
+tde_add_check_executable( tdewalletasync AUTOMOC
+ SOURCES tdewalletasync.cpp tdewallettest.cpp
+ LINK tdewalletclient-shared )
+tde_add_check_executable( tdewalletaboth AUTOMOC
+ SOURCES tdewalletboth.cpp tdewallettest.cpp
+ LINK tdewalletclient-shared )