summaryrefslogtreecommitdiffstats
path: root/tdewallet/backend/tests
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2013-01-26 13:17:21 -0600
committerTimothy Pearson <kb9vqf@pearsoncomputing.net>2013-01-26 13:17:21 -0600
commitdfe289850f068f19ba4a83ab4e7e22a7e09c13c9 (patch)
treec297348a55df66c571de4525646e0b9762427353 /tdewallet/backend/tests
parentb7658a0d5eca24a9d37c6e04f88298ef02389db0 (diff)
downloadtdelibs-dfe289850f068f19ba4a83ab4e7e22a7e09c13c9.tar.gz
tdelibs-dfe289850f068f19ba4a83ab4e7e22a7e09c13c9.zip
Rename a number of libraries and executables to avoid conflicts with KDE4
Diffstat (limited to 'tdewallet/backend/tests')
-rw-r--r--tdewallet/backend/tests/Makefile.am14
-rw-r--r--tdewallet/backend/tests/backendtest.cpp45
-rw-r--r--tdewallet/backend/tests/testbf.cpp67
-rw-r--r--tdewallet/backend/tests/testsha.cpp43
4 files changed, 169 insertions, 0 deletions
diff --git a/tdewallet/backend/tests/Makefile.am b/tdewallet/backend/tests/Makefile.am
new file mode 100644
index 000000000..5f5da74d9
--- /dev/null
+++ b/tdewallet/backend/tests/Makefile.am
@@ -0,0 +1,14 @@
+INCLUDES = -I$(top_srcdir)/tdewallet/backend -I$(top_srcdir)/tdewallet/client $(all_includes)
+
+AM_LDFLAGS = $(QT_LDFLAGS) $(X_LDFLAGS) $(KDE_RPATH)
+
+check_PROGRAMS = backendtest testbf testsha
+
+METASOURCES = AUTO
+
+LDADD = ../libtdewalletbackend.la ../../client/libtdewalletclient.la
+backendtest_SOURCES = backendtest.cpp
+
+testbf_SOURCES = testbf.cpp
+
+testsha_SOURCES = testsha.cpp
diff --git a/tdewallet/backend/tests/backendtest.cpp b/tdewallet/backend/tests/backendtest.cpp
new file mode 100644
index 000000000..4e19ce43f
--- /dev/null
+++ b/tdewallet/backend/tests/backendtest.cpp
@@ -0,0 +1,45 @@
+#include <stdlib.h>
+#include <stdio.h>
+
+#include <kapplication.h>
+#include <tqstring.h>
+
+#include "tdewalletbackend.h"
+
+int main(int argc, char **argv) {
+ TDEApplication a(argc, argv, "tdewalletbackendtest");
+
+ KWallet::Backend be("ktestwallet");
+ printf("KWalletBackend constructed\n");
+
+ TQByteArray apass, bpass, cpass;
+
+ apass.duplicate("apassword", 9);
+ 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);
+
+ 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);
+
+ rc = be.open(bpass);
+
+ printf("be.open(bpass) returned %d (should be 0)\n", rc);
+
+ return 0;
+}
+
+
diff --git a/tdewallet/backend/tests/testbf.cpp b/tdewallet/backend/tests/testbf.cpp
new file mode 100644
index 000000000..12dc74630
--- /dev/null
+++ b/tdewallet/backend/tests/testbf.cpp
@@ -0,0 +1,67 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "blowfish.h"
+#include "cbc.h"
+
+
+int main() {
+BlockCipher *bf;
+char data[] = "This is a test.";
+char expect[] = "\x22\x30\x7e\x2f\x42\x28\x44\x01\xda\xdf\x5a\x81\xd7\xe5\x7c\xd0";
+char key[] = "testkey";
+unsigned long et[] = {0x11223344};
+
+ printf("%d: 0x11 == %d and 0x44 == %d\n", ((unsigned char *)et)[0],
+ 0x11, 0x44);
+ bf = new BlowFish();
+// bf = new CipherBlockChain(new BlowFish());
+
+ bf->setKey((void *)key, 7*8);
+
+ if (!bf->readyToGo()) {
+ printf("Error: not ready to go!\n");
+ return -1;
+ }
+
+ printf("About to encrypt...\n"); fflush(stdout);
+ if (-1 == bf->encrypt((void *)data, 8)) {
+ printf("Error: encrypt failed!\n");
+ return -1;
+ }
+ printf("About to encrypt part 2...\n"); fflush(stdout);
+ bf->encrypt((void *)(data+8), 8);
+
+ printf("Encryption done. data[] is now: ");
+ for (int i = 0; i < 16; i++) {
+ printf("0x%x ", data[i]&0xff);
+ if ((data[i]&0xff) != (expect[i]&0xff)) {
+ printf("Error. This byte failed the comparison. It should have been 0x%x.\n", expect[i]&0xff);
+ return -1;
+ }
+ }
+ printf("\n");
+
+ delete bf;
+ bf = new BlowFish();
+// bf = new CipherBlockChain(new BlowFish());
+ bf->setKey((void *)key, 7*8);
+
+ printf("About to decrypt...\n"); fflush(stdout);
+ if (-1 == bf->decrypt((void *)data, 16)) {
+ printf("Error: decrypt failed!\n");
+ return -1;
+ }
+ //bf->decrypt((void *)(data+8), 8);
+
+ printf("All done! Result... data[] = \"%s\"\n", data);
+ if (strcmp(data, "This is a test.")) {
+ printf("ERROR. Decryption failed.\n");
+ return -1;
+ }
+
+ delete bf;
+}
+
+
+
diff --git a/tdewallet/backend/tests/testsha.cpp b/tdewallet/backend/tests/testsha.cpp
new file mode 100644
index 000000000..70879f015
--- /dev/null
+++ b/tdewallet/backend/tests/testsha.cpp
@@ -0,0 +1,43 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "sha1.h"
+
+
+int main() {
+SHA1 *sha1;
+unsigned char data[] = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
+unsigned long et[] = {0x11223344};
+int rc;
+
+ printf("%d: 0x11 == %d and 0x44 == %d\n", ((unsigned char *)et)[0],
+ 0x11, 0x44);
+ sha1 = new SHA1();
+
+ if (!sha1->readyToGo()) {
+ printf("Error: not ready to go!\n");
+ return -1;
+ }
+
+ printf("About to process [%s]\n", data);
+ rc = sha1->process(data, strlen((char *)data));
+
+ if (rc != strlen((char *)data)) {
+ printf("Error processing the data. rc=%d\n", rc);
+ } else printf("Done.\n");
+
+const unsigned char *res = sha1->getHash();
+
+ 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");
+
+ delete sha1;
+}
+
+
+