From 07f5ca1b227b7c4698a9c53d572d9e7da1a30784 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Kijewski?= Date: Fri, 28 Feb 2014 18:51:36 +0100 Subject: [PATCH] Add automatized test for sha256 --- tests/test_sha256/main.c | 3 ++ tests/test_sha256/tests/01-test | 76 +++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100755 tests/test_sha256/tests/01-test diff --git a/tests/test_sha256/main.c b/tests/test_sha256/main.c index 20b2d6b5d2..39e625bf72 100644 --- a/tests/test_sha256/main.c +++ b/tests/test_sha256/main.c @@ -46,6 +46,8 @@ void sha256_calc(const char *str, const char *expected) int main(void) { + puts("Start."); + sha256_calc("1234567890_1", "3eda9ffe5537a588f54d0b2a453e5fa932986d0bc0f9556924f5c2379b2c91b0"); sha256_calc("1234567890_2", @@ -63,5 +65,6 @@ int main(void) sha256_calc("", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"); + puts("Done."); return 0; } diff --git a/tests/test_sha256/tests/01-test b/tests/test_sha256/tests/01-test new file mode 100755 index 0000000000..c0047aaf48 --- /dev/null +++ b/tests/test_sha256/tests/01-test @@ -0,0 +1,76 @@ +#!/usr/bin/env expect + +set timeout 5 + +set pid [spawn make term] +puts "-*- Spawened $pid -*-\n" + +set result 0 +expect { + "Start." {} + timeout { + set result 1 + } +} + +while { $result == 0 } { + set result 1 + expect { + -regex {Input: +} { + expect { + "\r\n" {} + "\r" {} + "\n" {} + timeout { break } + } + set val_input $expect_out(buffer) + + expect { + -regex {Expected: +} { + expect { + "\r\n" {} + "\r" {} + "\n" {} + timeout { break } + } + } + timeout { break } + } + set val_expected $expect_out(buffer) + + expect { + -regex {Calculated: +} { + expect { + "\r\n" {} + "\r" {} + "\n" {} + timeout { break } + } + } + timeout { break } + } + set val_calculated $expect_out(buffer) + + if { $val_expected == $val_calculated } { + set result 0 + } else { + puts "-*- ERROR FOR INPUT <$val_input> -*-" + } + } + "Done." { + set result 0 + break + } + timeout { break } + } +} + +if { $result == 0 } { + puts "\n-*- Test successful! -*-\n" +} else { + puts "\n-*- TEST HAD ERRORS! -*-\n" +} +spawn kill -9 $pid +wait +close +exit $result