00001
00002
00003
00004
00005 #include "libtorrent/hasher.hpp"
00006 #include <boost/lexical_cast.hpp>
00007
00008 #include "test.hpp"
00009
00010 using namespace libtorrent;
00011
00012 char const* test_array[4] =
00013 {
00014 "abc",
00015 "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
00016 "a",
00017 "0123456701234567012345670123456701234567012345670123456701234567"
00018 };
00019
00020 long int repeat_count[4] = { 1, 1, 1000000, 10 };
00021
00022 char const* result_array[4] =
00023 {
00024 "A9993E364706816ABA3E25717850C26C9CD0D89D",
00025 "84983E441C3BD26EBAAE4AA1F95129E5E54670F1",
00026 "34AA973CD4C4DAA4F61EEB2BDBAD27316534016F",
00027 "DEA356A2CDDD90C7A7ECEDC5EBB563934F460452"
00028 };
00029
00030 int test_main()
00031 {
00032 using namespace libtorrent;
00033
00034 for (int test = 0; test < 4; ++test)
00035 {
00036 hasher h;
00037 for (int i = 0; i < repeat_count[test]; ++i)
00038 h.update(test_array[test], std::strlen(test_array[test]));
00039
00040 sha1_hash result = boost::lexical_cast<sha1_hash>(result_array[test]);
00041 TEST_CHECK(result == h.final());
00042 }
00043
00044 return 0;
00045 }
00046