source: branches/0.8-stable/test/parameter_test.cc @ 1249

Last change on this file since 1249 was 1249, checked in by Peter Johansson, 10 years ago

missing includes on Fedora

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.9 KB
Line 
1// $Id: parameter_test.cc 1249 2010-10-30 13:33:08Z peter $
2
3/*
4  Copyright (C) 2010 Peter Johansson
5
6  This file is part of svndigest, http://dev.thep.lu.se/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 3 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 svndigest. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22#include "Suite.h"
23#include "environment.h"
24
25#include "bin/svndigestParameter.h"
26#include "lib/utility.h"
27
28#include "yat/Exception.h"
29
30#include <cassert>
31#include <cerrno>
32#include <string>
33#include <vector>
34
35using namespace theplu::svndigest;
36
37void test_root(test::Suite& suite);
38void test_root(test::Suite& suite, const std::string& arg, 
39               const std::string& root, const std::string& root_basename);
40void parse(Parameter&, const std::vector<std::string>& argv);
41
42int main(int argc, char* argv[])
43{
44  test::Suite suite(argc, argv);
45  test_root(suite);
46  if (suite.ok())
47    return 0;
48  return 1;
49}
50
51
52void test_root(test::Suite& suite)
53{
54  suite.out() << "test --root ROOT\n";
55  test_root(suite, ".", test::abs_builddir()+"/testSubDir/parameter_test",
56            "parameter_test");
57  test_root(suite, "..", test::abs_builddir()+"/testSubDir","testSubDir");
58  test_root(suite, "../..", test::abs_builddir(), "test");
59  // test with absolute path
60  test_root(suite, test::abs_builddir(), test::abs_builddir(), "test");
61  // test with symbolic link
62  if (!node_exist("symlink")) {
63    if (symlink(".", "symlink")) {
64      suite.add(false);
65      suite.out() << "creating symlink failed: " << strerror(errno) << "\n";
66    }
67  }
68  test_root(suite, "symlink", 
69            test::abs_builddir()+"/testSubDir/parameter_test", "symlink");
70  test_root(suite, "symlink/.", 
71            test::abs_builddir()+"/testSubDir/parameter_test","parameter_test");
72  test_root(suite, "symlink/..", 
73            test::abs_builddir()+"/testSubDir", "testSubDir");
74  test_root(suite, test::abs_builddir()+"/testSubDir/parameter_test/symlink/..", 
75            test::abs_builddir()+"/testSubDir", "testSubDir");
76  test_root(suite, test::abs_builddir()+"/testSubDir/parameter_test/symlink", 
77            test::abs_builddir()+"/testSubDir/parameter_test", "symlink");
78 
79  try {
80    test_root(suite, "../../Makefile", test::abs_builddir()+"/Makefile", 
81              "Makefile");
82    suite.add(false);
83    suite.out() << "error: no exception thrown\n --root ../../Makefile\n";
84  }
85  catch (theplu::yat::utility::cmd_error& e) {
86    suite.out() << "caught expected errno_error: what(): " << e.what();
87  }
88}
89
90void test_root(test::Suite& suite, const std::string& arg, 
91               const std::string& root, const std::string& root_basename)
92{
93  svndigestParameter option;
94  std::vector<std::string> argv;
95  argv.push_back("svndigest");
96  argv.push_back("--no-report");
97  argv.push_back("--root");
98  argv.push_back(arg);
99  parse(option, argv);
100  if (option.root() != root) {
101    suite.add(false);
102    for (size_t i=0; i<argv.size(); ++i)
103      suite.out() << argv[i] << " ";
104    suite.out() << "\n";
105    suite.out() << "root: `" << option.root() << "'\n";
106    suite.out() << "expected: `" << root << "'\n";
107  }
108  if (option.root_basename() != root_basename) {
109    suite.add(false);
110    for (size_t i=0; i<argv.size(); ++i)
111      suite.out() << argv[i] << " ";
112    suite.out() << "\n";
113    suite.out() << "root: `" << option.root_basename() << "'\n";
114    suite.out() << "expected: `" << root_basename << "'\n";
115  }
116}
117
118
119void parse(Parameter& option, const std::vector<std::string>& vec)
120{
121  int argc = vec.size();
122  char** argv = new char*[vec.size()];
123  for (int i = 0; i<argc; ++i) {
124    argv[i] = strdup(vec[i].c_str());
125    assert(argv[i]);
126  }
127  option.parse(argc, argv);
128  for (int i = 0; i<argc; ++i) {
129    free(argv[i]);
130  }
131}
Note: See TracBrowser for help on using the repository browser.