source: trunk/test/utility_test.cc @ 513

Last change on this file since 513 was 507, checked in by Peter Johansson, 14 years ago

added function comparing strings with wildcards - needed for #122

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 1.9 KB
Line 
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
29bool test_hex(int, u_int, std::string);
30bool test_equal(bool, std::string, std::string);
31
32int 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
51bool 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
61bool 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
Note: See TracBrowser for help on using the repository browser.