From 8773e743c518578584d07d35ffdafdd598af88b0 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 16 Oct 2006 13:06:41 +0000 Subject: r19339: Merge my 4.0-unittest branch. This adds an API for more fine-grained output in the testsuite rather than just True or False for a set of tests. The aim is to use this for: * known failure lists (run all tests and detect tests that started working or started failing). This would allow us to get rid of the RPC-SAMBA3-* tests * nicer torture output * simplification of the testsuite system * compatibility with other unit testing systems * easier usage of smbtorture (being able to run one test and automatically set up the environment for that) This is still a work-in-progress; expect more updates over the next couple of days. (This used to be commit 0eb6097305776325c75081356309115f445a7218) --- source4/lib/crypto/sha1test.c | 54 +++++++++++++++---------------------------- 1 file changed, 19 insertions(+), 35 deletions(-) (limited to 'source4/lib/crypto') diff --git a/source4/lib/crypto/sha1test.c b/source4/lib/crypto/sha1test.c index c3b4506dec..a37328e328 100644 --- a/source4/lib/crypto/sha1test.c +++ b/source4/lib/crypto/sha1test.c @@ -17,6 +17,7 @@ */ #include "includes.h" +#include "torture/ui.h" #include "lib/crypto/crypto.h" @@ -50,7 +51,8 @@ static const char *resultarray[4] = "DE A3 56 A2 CD DD 90 C7 A7 EC ED C5 EB B5 63 93 4F 46 04 52 " }; -BOOL torture_local_crypto_sha1(struct torture_context *torture) + +bool torture_local_crypto_sha1(struct torture_context *tctx) { struct SHA1Context sha; int i, j, err; @@ -64,52 +66,33 @@ BOOL torture_local_crypto_sha1(struct torture_context *torture) for(j = 0; j < 4; ++j) { ZERO_STRUCT(tmp); - printf( "\nTest %d: %d, '%s'\n", + torture_comment(tctx, "Test %d: %d, '%s'\n", j+1, repeatcount[j], testarray[j]); err = SHA1Init(&sha); - if (err) - { - fprintf(stderr, "SHA1Init Error %d.\n", err ); - ret = False; - break; /* out of for j loop */ - } + torture_assert_int_equal(tctx, err, 0, "SHA1Init Error"); for(i = 0; i < repeatcount[j]; ++i) { err = SHA1Update(&sha, (const unsigned char *) testarray[j], strlen(testarray[j])); - if (err) - { - fprintf(stderr, "SHA1Update Error %d.\n", err ); - ret = False; - break; /* out of for i loop */ - } + torture_assert_int_equal(tctx, err, 0, "SHA1Update Error"); } err = SHA1Final(Message_Digest, &sha); - if (err) - { - fprintf(stderr, - "SHA1Result Error %d, could not compute message digest.\n", - err ); - ret = False; - } - else + torture_assert_int_equal(tctx, err, 0, + "SHA1Result Error, could not compute message digest."); + torture_comment(tctx, "\t"); + for(i = 0; i < 20 ; ++i) { - printf("\t"); - for(i = 0; i < 20 ; ++i) - { snprintf(tmp+(i*3), sizeof(tmp) - (i*3),"%02X ", Message_Digest[i]); - printf("%02X ", Message_Digest[i]); - } - printf("\n"); + torture_comment(tctx, "%02X ", Message_Digest[i]); } - printf("Should match:\n"); - printf("\t%s\n", resultarray[j]); + torture_comment(tctx, "\n"); + torture_comment(tctx, "Should match:\n\t%s\n", resultarray[j]); if (strcmp(resultarray[j], tmp) != 0) { ret = False; } @@ -117,10 +100,11 @@ BOOL torture_local_crypto_sha1(struct torture_context *torture) /* Test some error returns */ err = SHA1Update(&sha,(const unsigned char *) testarray[1], 1); - if (err != shaStateError) ret = False; - printf ("\nError %d. Should be %d.\n", err, shaStateError ); + torture_assert_int_equal(tctx, err, shaStateError, "SHA1Update failed"); err = SHA1Init(0); - if (err != shaNull) ret = False; - printf ("\nError %d. Should be %d.\n", err, shaNull ); - return ret; + torture_assert_int_equal(tctx, err, shaNull, "SHA1Init failed"); + + return true; } + + -- cgit