summaryrefslogtreecommitdiff
path: root/test/test-helpers.h
blob: 3094f774c1107818eee2f3839e6efda04a78f902 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/* Copyright © 2006  Roger Leigh <rleigh@debian.org>
 *
 * schroot is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * schroot is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 * MA  02111-1307  USA
 *
 *********************************************************************/

#ifndef TEST_HELPERS_H
#define TEST_HELPERS_H

#include <sbuild/sbuild-types.h>

#include <algorithm>
#include <iostream>

#include <cppunit/extensions/HelperMacros.h>

using namespace CppUnit;

template<class T>
void test_list(T&                         itype,
	       sbuild::string_list const& list,
	       sbuild::string_list const& (T::*getter)(void) const,
	       void (T::*setter)(sbuild::string_list const&))
{
  // Set items from list.
  (itype.*setter)(list);

  // Check set items exist, but make no assumptions about ordering.
  sbuild::string_list set_items = (itype.*getter)();

  sbuild::string_list orig_list = list;
  sort(orig_list.begin(), orig_list.end());
  sort(set_items.begin(), set_items.end());

  sbuild::string_list missing;
  set_symmetric_difference(orig_list.begin(), orig_list.end(),
			   set_items.begin(), set_items.end(),
			   std::back_inserter(missing));

  if (!missing.empty())
  for (sbuild::string_list::const_iterator pos = missing.begin();
       pos != missing.end();
       ++pos)
    {
      std::cout << "Missing list item: " << *pos << std::endl;
    }
  // Ensure the test is working.
  CPPUNIT_ASSERT(missing.empty());
  CPPUNIT_ASSERT(set_items.size() == list.size());
}

#endif /* TEST_HELPERS_H */

/*
 * Local Variables:
 * mode:C++
 * End:
 */