Imported Upstream version 17.23.5
[platform/upstream/libzypp.git] / tests / zypp / Digest_test.cc
1
2 #include <iostream>
3 #include <sstream>
4 #include <fstream>
5 #include <list>
6 #include <string>
7
8 #include <boost/test/unit_test.hpp>
9
10 #include <zypp/base/Logger.h>
11 #include <zypp/base/Exception.h>
12 #include <zypp/PathInfo.h>
13 #include <zypp/Digest.h>
14
15 using boost::unit_test::test_case;
16
17 using namespace zypp;
18 using namespace zypp::filesystem;
19
20 /**
21  * Test case for
22  * static std::string digest(const std::string& name, std::istream& is, size_t bufsize = 4096);
23  */
24 BOOST_AUTO_TEST_CASE(digest)
25 {
26   std::string data("I will test the checksum of this");
27   std::stringstream str1(data);
28   std::stringstream str2(data);
29   std::stringstream str3(data);
30
31   BOOST_CHECK_EQUAL( Digest::digest( "sha1", str1 ), "142df4277c326f3549520478c188cab6e3b5d042" ); 
32   BOOST_CHECK_EQUAL( Digest::digest( "md5", str2 ), "f139a810b84d82d1f29fc53c5e59beae" ); 
33   // FIXME i think it should throw
34   BOOST_CHECK_EQUAL( Digest::digest( "lalala", str3) , "" ); 
35 }