fixes bug where priorities where lost when force-rechecking.
[libtorrent.git] / test / test_hasher.cpp
blobb2453a903f98443cb5560835c40e623fd4d9077b
1 /*
3 Copyright (c) 2008, Arvid Norberg
4 All rights reserved.
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
8 are met:
10 * Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
12 * Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in
14 the documentation and/or other materials provided with the distribution.
15 * Neither the name of the author nor the names of its
16 contributors may be used to endorse or promote products derived
17 from this software without specific prior written permission.
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 POSSIBILITY OF SUCH DAMAGE.
33 #include "libtorrent/hasher.hpp"
34 #include <boost/lexical_cast.hpp>
36 #include "test.hpp"
38 using namespace libtorrent;
40 // test vectors from RFC 3174
41 // http://www.faqs.org/rfcs/rfc3174.html
43 char const* test_array[4] =
45 "abc",
46 "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
47 "a",
48 "0123456701234567012345670123456701234567012345670123456701234567"
51 long int repeat_count[4] = { 1, 1, 1000000, 10 };
53 char const* result_array[4] =
55 "A9993E364706816ABA3E25717850C26C9CD0D89D",
56 "84983E441C3BD26EBAAE4AA1F95129E5E54670F1",
57 "34AA973CD4C4DAA4F61EEB2BDBAD27316534016F",
58 "DEA356A2CDDD90C7A7ECEDC5EBB563934F460452"
62 int test_main()
64 using namespace libtorrent;
66 for (int test = 0; test < 4; ++test)
68 hasher h;
69 for (int i = 0; i < repeat_count[test]; ++i)
70 h.update(test_array[test], std::strlen(test_array[test]));
72 sha1_hash result = boost::lexical_cast<sha1_hash>(result_array[test]);
73 TEST_CHECK(result == h.final());
76 return 0;