1 | // $Id: utility_test.cc 507 2007-12-08 03:58:19Z peter $ |
---|
2 | |
---|
3 | /* |
---|
4 | Copyright (C) 2007 Peter Johansson |
---|
5 | |
---|
6 | This file is part of svndigest, http://trac.thep.lu.se/trac/svndigest |
---|
7 | |
---|
8 | svndigest is free software; you can redistribute it and/or modify it |
---|
9 | under the terms of the GNU General Public License as published by |
---|
10 | the Free Software Foundation; either version 2 of the License, or |
---|
11 | (at your option) any later version. |
---|
12 | |
---|
13 | svndigest is distributed in the hope that it will be useful, but |
---|
14 | WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
16 | General Public License for more details. |
---|
17 | |
---|
18 | You should have received a copy of the GNU General Public License |
---|
19 | along with this program; if not, write to the Free Software |
---|
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
---|
21 | 02111-1307, USA. |
---|
22 | */ |
---|
23 | |
---|
24 | #include "utility.h" |
---|
25 | |
---|
26 | #include <iostream> |
---|
27 | #include <string> |
---|
28 | |
---|
29 | bool test_hex(int, u_int, std::string); |
---|
30 | bool test_equal(bool, std::string, std::string); |
---|
31 | |
---|
32 | int main(const int argc,const char* argv[]) |
---|
33 | { |
---|
34 | bool ok=true; |
---|
35 | |
---|
36 | ok &= test_hex(15,2, "0f"); |
---|
37 | ok &= test_hex(17,1, "1"); |
---|
38 | ok &= test_hex(16,2, "10"); |
---|
39 | |
---|
40 | ok &= test_equal(true,"peter", "peter"); |
---|
41 | ok &= test_equal(false,"peter", "peterj"); |
---|
42 | ok &= test_equal(true,"p*", "peterj"); |
---|
43 | ok &= test_equal(true,"peter", "p*"); |
---|
44 | ok &= test_equal(false,"peter", "p*j"); |
---|
45 | |
---|
46 | if (ok) |
---|
47 | return 0; |
---|
48 | return 1; |
---|
49 | } |
---|
50 | |
---|
51 | bool test_equal(bool answ, std::string a, std::string b) |
---|
52 | { |
---|
53 | if (theplu::svndigest::equal(a.begin(), a.end(), b.begin(), b.end())==answ) |
---|
54 | return true; |
---|
55 | std::cerr << "equal(" << a << ", " << b << ") results " |
---|
56 | << theplu::svndigest::equal(a.begin(), a.end(),b.begin(), b.end()) |
---|
57 | << ". Expects " << answ << std::endl; |
---|
58 | return false; |
---|
59 | } |
---|
60 | |
---|
61 | bool test_hex(int x, u_int w, std::string facit) |
---|
62 | { |
---|
63 | if (theplu::svndigest::hex(x,w)==facit) |
---|
64 | return true; |
---|
65 | std::cerr << "hex(" << x << ", " << w << ") results " |
---|
66 | << theplu::svndigest::hex(x,w) << ". Expects " << facit |
---|
67 | << std::endl; |
---|
68 | return false; |
---|
69 | } |
---|
70 | |
---|