|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r80502 - branches/release/libs/uuid/test
From: atompkins_at_[hidden]
Date: 2012-09-11 21:55:33
Author: atompkins
Date: 2012-09-11 21:55:32 EDT (Tue, 11 Sep 2012)
New Revision: 80502
URL: http://svn.boost.org/trac/boost/changeset/80502
Log:
added sha1 tests for really long messages
Text files modified:
branches/release/libs/uuid/test/test_sha1.cpp | 40 ++++++++++++++++++++++++++++------------
1 files changed, 28 insertions(+), 12 deletions(-)
Modified: branches/release/libs/uuid/test/test_sha1.cpp
==============================================================================
--- branches/release/libs/uuid/test/test_sha1.cpp (original)
+++ branches/release/libs/uuid/test/test_sha1.cpp 2012-09-11 21:55:32 EDT (Tue, 11 Sep 2012)
@@ -50,7 +50,7 @@
}
-#define BOOST_TEST_SHA1_DEGEST(lhs, rhs) ( test_sha1_digest_equal_array(__FILE__, __LINE__, BOOST_CURRENT_FUNCTION, lhs, rhs) )
+#define BOOST_TEST_SHA1_DIGEST(lhs, rhs) ( test_sha1_digest_equal_array(__FILE__, __LINE__, BOOST_CURRENT_FUNCTION, lhs, rhs) )
void test_sha1(char const*const message, unsigned int length, const unsigned int (&correct_digest)[5])
{
@@ -60,7 +60,7 @@
unsigned int digest[5];
sha.get_digest(digest);
- BOOST_TEST_SHA1_DEGEST(digest, correct_digest);
+ BOOST_TEST_SHA1_DIGEST(digest, correct_digest);
}
void test_quick()
@@ -259,32 +259,48 @@
unsigned int digest[5];
sha.get_digest(digest);
- BOOST_TEST_SHA1_DEGEST(digest, tc.digest);
+ BOOST_TEST_SHA1_DIGEST(digest, tc.digest);
}
}
+// test long strings of 'a's
void test_long()
{
+
// test 1 million 'a's
+ struct test_case
+ {
+ unsigned int count;
+ unsigned int digest[5];
+ };
+ test_case cases[] =
+ { { 1000000, { 0x34aa973c, 0xd4c4daa4, 0xf61eeb2b, 0xdbad2731, 0x6534016f } }
+ , { 1000000000, { 0xd0f3e4f2, 0xf31c665a, 0xbbd8f518, 0xe848d5cb, 0x80ca78f7 } }
+ //, { 2000000000, { 0xda19be1b, 0x5ec3bc13, 0xda5533bd, 0x0c225a2f, 0x38da50ed } }
+ //, { 2147483647, { 0x1e5b490b, 0x10255e37, 0xfd96d096, 0x4f2fbfb9, 0x1ed47536 } }
+ //, { 4294967295 /*2^32 - 1*/, { 0xd84b866e, 0x70f6348f, 0xb0ddc21f, 0x373fe956, 0x1bf1005d } }
+ };
- boost::uuids::detail::sha1 sha;
- for (size_t i=0; i<1000000; i++) {
- sha.process_byte('a');
- }
+ for (size_t iCase=0; iCase<sizeof(cases)/sizeof(cases[0]); iCase++) {
+ test_case const& tc = cases[iCase];
- unsigned int correct_digest[5] =
- { 0x34aa973c, 0xd4c4daa4, 0xf61eeb2b, 0xdbad2731, 0x6534016f };
+ boost::uuids::detail::sha1 sha;
+ for (size_t i=0; i<tc.count; i++) {
+ sha.process_byte('a');
+ }
- unsigned int digest[5];
- sha.get_digest(digest);
+ unsigned int digest[5];
+ sha.get_digest(digest);
- BOOST_TEST_SHA1_DEGEST(digest, correct_digest);
+ BOOST_TEST_SHA1_DIGEST(digest, tc.digest);
+ }
}
int main(int, char*[])
{
test_quick();
test_short_messages();
+ test_long();
return boost::report_errors();
}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk