Signed-off-by: geraldo netto <geraldone...@gmail.com> --- tests/tst-crypt.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-)
diff --git a/tests/tst-crypt.c b/tests/tst-crypt.c index ffc5293..0dc3de2 100644 --- a/tests/tst-crypt.c +++ b/tests/tst-crypt.c @@ -2,6 +2,16 @@ #include <stdio.h> #include <string.h> #include <crypt.h> +#include <stdbool.h> + +int tests = 0, fails = 0; + +void report(const char* name, bool passed) { + static const char* status[] = {"FAIL", "PASS"}; + printf("%s: %s\n", status[passed], name); + tests += 1; + fails += !passed; +} char* concat_str(char* first_block, char* second_block) { static char tmp[10]; @@ -21,16 +31,16 @@ int main(void) { char result4[] = "$6$Ab(d3$TB6UIPV7sprvpcQh2esPr2/ye4FTp9lLft8yAj.2x/HcTXPwzGDxdK/tIF10DdVdV9Z2hhc3MaosUBS3fdueZ1"; // 20338EPKt5xtY - if (strcmp(result1, crypt(password, salt)) != 0) return -1; + report("crypt (des)", strcmp(result1, crypt(password, salt)) == 0); // $1$Ab(d3$.SgUCw1AqIVAiXBaS6kzU. - if (strcmp(result2, crypt(password, concat_str((char*) "$1$", password))) != 0) return -2; + report("crypt (md5)", strcmp(result2, crypt(password, concat_str((char*) "$1$", password))) == 0); // $5$Ab(d3$00nkgDrj2dM68IbqFTZPJ.a3mgai49mY.Ezq5ey0xY0 - if (strcmp(result3, crypt(password, concat_str((char*) "$5$", password))) != 0) return -3; + report("crypt (sha-256)", strcmp(result3, crypt(password, concat_str((char*) "$5$", password))) == 0); // $6$Ab(d3$TB6UIPV7sprvpcQh2esPr2/ye4FTp9lLft8yAj.2x/HcTXPwzGDxdK/tIF10DdVdV9Z2hhc3MaosUBS3fdueZ1 - if (strcmp(result4, crypt(password, concat_str((char*) "$6$", password))) !=0) return -4; + report("crypt (sha-512)", strcmp(result4, crypt(password, concat_str((char*) "$6$", password))) ==0); // encrypt // http://man7.org/linux/man-pages/man3/encrypt.3.html @@ -67,5 +77,7 @@ int main(void) { txt[8] = '\0'; } - return (strcmp(password, txt) == 0) ? 0 : -6; + report("encrypt", strcmp(password, txt) == 0); + printf("SUMMARY: %u tests / %u failures\n", tests, fails); + return fails; } \ No newline at end of file -- 2.7.4 -- You received this message because you are subscribed to the Google Groups "OSv Development" group. To unsubscribe from this group and stop receiving emails from it, send an email to osv-dev+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.