summaryrefslogtreecommitdiff
path: root/tests/test_exception_catch.cc
diff options
context:
space:
mode:
authorKjell Ahlstedt <kjell.ahlstedt@bredband.net>2012-10-18 14:45:53 +0200
committerKjell Ahlstedt <kjell.ahlstedt@bredband.net>2012-10-18 14:45:53 +0200
commit12bbd742f1e47422940c3068619cac62a5f5d708 (patch)
treeaba6765f7a87091a8417dff1be3d70ee55c1af5d /tests/test_exception_catch.cc
parenta69953b559d4212db1fb8a475d2c999f1faad959 (diff)
downloadsigc++-12bbd742f1e47422940c3068619cac62a5f5d708.tar.gz
Test cases: Report pass/fail with exit status.
* tests/testutilities.[h|cc]: New files. Code common to all test cases. * tests/*.cc: Use class TestUtilities. Don't print anything if the test passes. Return EXIT_FAILURE if the test fails. * tests/Makefile.am: Add testutilities.[h|cc] to all test cases. Bug #684956.
Diffstat (limited to 'tests/test_exception_catch.cc')
-rw-r--r--tests/test_exception_catch.cc67
1 files changed, 46 insertions, 21 deletions
diff --git a/tests/test_exception_catch.cc b/tests/test_exception_catch.cc
index 8c6fa0d..c048f29 100644
--- a/tests/test_exception_catch.cc
+++ b/tests/test_exception_catch.cc
@@ -3,58 +3,83 @@
* Assigned to public domain. Use as you wish without restriction.
*/
+#include "testutilities.h"
#include <sigc++/adaptors/exception_catch.h>
-#include <iostream>
+#include <sstream>
#include <stdexcept>
+#include <cstdlib>
-SIGC_USING_STD(cout)
-SIGC_USING_STD(cerr)
-SIGC_USING_STD(endl)
-SIGC_USING_STD(exception)
+namespace
+{
+std::ostringstream result_stream;
struct f : public sigc::functor_base
{
typedef int result_type;
- int operator()(int i)
- {std::cout << "f(int "<<i<< ")"<< std::endl;
- throw std::range_error("out of range");}
+
+ int operator()(int i)
+ {
+ result_stream << "f(int " << i << ") ";
+ throw std::range_error("out of range ");
+ }
};
struct g : public sigc::functor_base
{
typedef int result_type;
- int operator()()
- {std::cout << "g()" << std::endl;
- throw std::range_error("out of range");}
+
+ int operator()()
+ {
+ result_stream << "g() ";
+ throw std::range_error("out of range ");
+ }
};
struct g_void : public sigc::functor_base
{
typedef void result_type;
+
void operator()()
- {std::cout << "g_void()" << std::endl;
- throw std::range_error("out of range");}
+ {
+ result_stream << "g_void() ";
+ throw std::range_error("out of range ");
+ }
};
-
struct my_catch
{
int operator()()
{
- try { throw; }
+ try
+ {
+ throw;
+ }
catch (std::range_error e) // catch what types we know
- {
- std::cerr << "caught "<< e.what() <<std::endl;
- }
+ {
+ result_stream << "caught " << e.what();
+ }
return 1;
// all else continues out.
}
};
+} // end anonymous namespace
-int main()
+int main(int argc, char* argv[])
{
- std::cout << sigc::exception_catch(f(), my_catch())(1) << std::endl;
- std::cout << sigc::exception_catch(g(), my_catch())() << std::endl;
+ TestUtilities* util = TestUtilities::get_instance();
+
+ if (!util->check_command_args(argc, argv))
+ return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;
+
+ result_stream << sigc::exception_catch(f(), my_catch())(2);
+ util->check_result(result_stream, "f(int 2) caught out of range 1");
+
+ result_stream << sigc::exception_catch(g(), my_catch())();
+ util->check_result(result_stream, "g() caught out of range 1");
+
sigc::exception_catch(g_void(), my_catch())(); // void test
+ util->check_result(result_stream, "g_void() caught out of range ");
+
+ return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;
}