tdeui & tdewallet: add tests

Signed-off-by: Alexander Golubev <fatzer2@gmail.com>
pull/1/head
Alexander Golubev 8 years ago committed by Slávek Banko
parent ed74769bfa
commit 16a176dab1

@ -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 tdeui-shared )
tde_add_check_executable( ${PROG} AUTOMOC LINK tdeui-shared )
endforeach( PROG ${test_PROGS} )

@ -11,3 +11,4 @@
add_subdirectory( client )
add_subdirectory( backend )
add_subdirectory( tests )

@ -9,6 +9,8 @@
#
#################################################
add_subdirectory ( tests )
include_directories(
${TQT_INCLUDE_DIRS}
${CMAKE_BINARY_DIR}

@ -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 )

@ -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;
}

@ -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(" ");
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;
}
printf("\n");
} else printf("Error - getHash() returned NULL!\n");
delete sha1;
}
return 0;
}

@ -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 )
Loading…
Cancel
Save