diff options
author | Alexander Golubev <[email protected]> | 2016-12-21 01:13:31 +0300 |
---|---|---|
committer | Slávek Banko <[email protected]> | 2017-01-29 02:48:50 +0100 |
commit | 0e614010bd32bccc8bd5b9a9e49894a9f466b08d (patch) | |
tree | 05309c2dbd304806feceac88e3eff2c5b0d3b819 /tdewallet/backend/tests/testsha.cpp | |
parent | 86921d65c5c218a2c721d905a93885cf2fe9b7b7 (diff) | |
download | tdelibs-0e614010bd32bccc8bd5b9a9e49894a9f466b08d.tar.gz tdelibs-0e614010bd32bccc8bd5b9a9e49894a9f466b08d.zip |
tdeui & tdewallet: add tests
Signed-off-by: Alexander Golubev <[email protected]>
(cherry picked from commit 16a176dab1e978bef8f8d49801fa98a028d1d17b)
Diffstat (limited to 'tdewallet/backend/tests/testsha.cpp')
-rw-r--r-- | tdewallet/backend/tests/testsha.cpp | 54 |
1 files changed, 39 insertions, 15 deletions
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; +} |