summaryrefslogtreecommitdiff
path: root/tests/test_hide.cc
blob: bec7def428ab8988542ddbbc71a9d8aba833d058 (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
/* Copyright 2002 - 2016, The libsigc++ Development Team
 *  Assigned to public domain.  Use as you wish without restriction.
 */

#include "testutilities.h"
#include <sigc++/adaptors/hide.h>

namespace
{
std::ostringstream result_stream;

struct foo
{
  int operator()()
  {
    result_stream << "foo() ";
    return true;
  }

  int operator()(int j)
  {
    result_stream << "foo(int " << j << ") ";
    return 1 + j;
  }
};

struct foo_void
{
  void operator()() { result_stream << "foo_void()"; }
};

} // end anonymous namespace

int
main(int argc, char* argv[])
{
  auto util = TestUtilities::get_instance();

  if (!util->check_command_args(argc, argv))
    return TestUtilities::get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;

  result_stream << sigc::hide<0>(foo())(1, 2);
  util->check_result(result_stream, "foo(int 2) 3");

  result_stream << sigc::hide<1>(foo())(1, 2);
  util->check_result(result_stream, "foo(int 1) 2");

  result_stream << sigc::hide<-1>(foo())(1);
  util->check_result(result_stream, "foo() 1");

  result_stream << sigc::hide(foo())(1);
  util->check_result(result_stream, "foo() 1");

  sigc::hide(foo_void())(1); // void test
  util->check_result(result_stream, "foo_void()");

  return TestUtilities::get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;
}