Let's make the tests also compile with boost 1.33 (auto_unit_test.hpp is
[platform/upstream/libzypp.git] / tests / zypp / FileChecker_test.cc
1
2 #include <iostream>
3 #include <fstream>
4 #include <list>
5 #include <string>
6
7 #include "zypp/base/Logger.h"
8 #include "zypp/base/Exception.h"
9 #include "zypp/KeyRing.h"
10 #include "zypp/PublicKey.h"
11 #include "zypp/TmpPath.h"
12
13 #include "zypp/FileChecker.h"
14
15 #include <boost/test/auto_unit_test.hpp>
16
17 #include "KeyRingTestReceiver.h"
18
19 using boost::unit_test::test_suite;
20 using boost::unit_test::test_case;
21
22 using namespace std;
23 using namespace zypp;
24 using namespace zypp::filesystem;
25
26 #define DATADIR (Pathname(TESTS_SRC_DIR) + "/zypp/data/FileChecker")
27
28 BOOST_AUTO_TEST_CASE(keyring_test)
29 {
30   Pathname file( Pathname(DATADIR) + "hello.txt" );
31   Pathname file2( Pathname(DATADIR) + "hello2.txt" );
32   Pathname pubkey( Pathname(DATADIR) + "hello.txt.key" );
33   Pathname signature( Pathname(DATADIR) + "hello.txt.asc" );
34   
35   /**
36    * 1st scenario, the signature does
37    * match
38    */
39   {
40     KeyRingTestReceiver keyring_callbacks;
41     KeyRingTestSignalReceiver receiver;
42     
43     keyring_callbacks.answerTrustKey(true);
44     SignatureFileChecker sigchecker( signature );
45     sigchecker.addPublicKey(pubkey);
46     sigchecker(file); 
47   }
48   
49   /**
50    * second scenario, the signature does not
51    * match, an exception has to be thrown
52    */
53   {
54     KeyRingTestReceiver keyring_callbacks;
55     KeyRingTestSignalReceiver receiver;
56     
57     keyring_callbacks.answerTrustKey(true);
58     SignatureFileChecker sigchecker( signature );
59     sigchecker.addPublicKey(pubkey);
60     
61     BOOST_CHECK_THROW( sigchecker(file2), zypp::Exception );
62
63   }
64   
65 }
66
67 BOOST_AUTO_TEST_CASE(checksum_test)
68 {
69   Pathname file( Pathname(DATADIR) + "hello.txt" );
70   Pathname file2( Pathname(DATADIR) + "hello2.txt" );
71   Pathname pubkey( Pathname(DATADIR) + "hello.txt.key" );
72   Pathname signature( Pathname(DATADIR) + "hello.txt.asc" );
73   
74   /**
75    * 1st scenario, checksum matches
76    */
77   {
78     ChecksumFileChecker checker( CheckSum("sha1", "f2105202a0f017ab818b670d04982a89f55f090b") );
79     checker(file);
80   }
81   
82   /**
83    * 1st scenario, checksum does not matches
84    */
85   {
86     ChecksumFileChecker checker( CheckSum("sha1", "f2105202a0f017ab818b670d04982a89f55f090b") );
87     BOOST_CHECK_THROW( checker(file2), zypp::FileCheckException );
88   }
89 }
90