-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathtestExceptions.cxx
More file actions
50 lines (43 loc) · 1.15 KB
/
testExceptions.cxx
File metadata and controls
50 lines (43 loc) · 1.15 KB
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
#include "../include/Common/Exceptions.h"
#define BOOST_TEST_MODULE Exceptions test
#define BOOST_TEST_MAIN
#define BOOST_TEST_DYN_LINK
#include <cmath>
#include <boost/test/unit_test.hpp>
#include <assert.h>
#include <boost/test/output_test_stream.hpp>
#include <iostream>
#include <time.h>
using namespace std;
using namespace AliceO2::Common;
using boost::test_tools::output_test_stream;
void foo()
{
BOOST_THROW_EXCEPTION(ObjectNotFoundError() << errinfo_object_name("object1"));
}
void bar()
{
BOOST_THROW_EXCEPTION(ObjectNotFoundError());
}
BOOST_AUTO_TEST_CASE(exceptions_test)
{
BOOST_CHECK_THROW(foo(), ObjectNotFoundError);
try {
foo();
} catch (ObjectNotFoundError& e) {
cout << e.what() << endl;
output_test_stream output;
output << e.what();
BOOST_CHECK( !output.is_empty( false ) );
BOOST_CHECK( output.is_equal( "Object not found: object1" ) );
}
try {
bar();
} catch (ObjectNotFoundError& e) {
cout << e.what() << endl;
output_test_stream output;
output << e.what();
BOOST_CHECK(!output.is_empty(false));
BOOST_CHECK(output.is_equal("Object not found: (object_name not specified)"));
}
}