source: trunk/debathena/third/schroot/test/test-helpers.h @ 24167

Revision 24167, 2.0 KB checked in by broder, 15 years ago (diff)
Import schroot upstream into subversion.
Line 
1/* Copyright © 2006-2007  Roger Leigh <rleigh@debian.org>
2 *
3 * schroot is free software: you can redistribute it and/or modify it
4 * under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
7 *
8 * schroot is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program.  If not, see
15 * <http://www.gnu.org/licenses/>.
16 *
17 *********************************************************************/
18
19#ifndef TEST_HELPERS_H
20#define TEST_HELPERS_H
21
22#include <sbuild/sbuild-types.h>
23
24#include <algorithm>
25#include <iostream>
26
27#include <cppunit/extensions/HelperMacros.h>
28
29using namespace CppUnit;
30
31template<class T>
32void test_list(T&                         itype,
33               sbuild::string_list const& list,
34               sbuild::string_list const& (T::*getter)(void) const,
35               void (T::*setter)(sbuild::string_list const&))
36{
37  // Set items from list.
38  (itype.*setter)(list);
39
40  // Check set items exist, but make no assumptions about ordering.
41  sbuild::string_list set_items = (itype.*getter)();
42
43  sbuild::string_list orig_list = list;
44  sort(orig_list.begin(), orig_list.end());
45  sort(set_items.begin(), set_items.end());
46
47  sbuild::string_list missing;
48  set_symmetric_difference(orig_list.begin(), orig_list.end(),
49                           set_items.begin(), set_items.end(),
50                           std::back_inserter(missing));
51
52  if (!missing.empty())
53  for (sbuild::string_list::const_iterator pos = missing.begin();
54       pos != missing.end();
55       ++pos)
56    {
57      std::cout << "Missing list item: " << *pos << std::endl;
58    }
59  // Ensure the test is working.
60  CPPUNIT_ASSERT(missing.empty());
61  CPPUNIT_ASSERT(set_items.size() == list.size());
62}
63
64#endif /* TEST_HELPERS_H */
65
66/*
67 * Local Variables:
68 * mode:C++
69 * End:
70 */
Note: See TracBrowser for help on using the repository browser.