~ajdobbs/maus/scifi-efficiency-2

« back to all changes in this revision

Viewing changes to tests/cpp_unit/Utils/ExceptionTest.cc

MergeĀ inĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#include "gtest/gtest.h"
21
21
 
22
22
#include "src/common_cpp/Utils/Exception.hh"
 
23
#include "src/common_cpp/Utils/ExceptionLevel.hh"
23
24
 
24
25
namespace MAUS {
25
26
 
26
27
TEST(ExceptionTest, ConstructorAccessorTest) {
27
28
    // just check it doesnt do anything daft
28
 
    Exception* exception = new Exception();
 
29
    Exceptions::Exception* exception = new Exceptions::Exception();
29
30
    delete exception;
30
31
 
31
 
    exception = new Exception(Exception::recoverable, "error", "location");
32
 
    EXPECT_EQ(exception->GetErrorLevel(), Exception::recoverable);
 
32
    exception = new Exceptions::Exception(Exceptions::recoverable, "error", "location");
 
33
    EXPECT_EQ(exception->GetErrorLevel(), Exceptions::recoverable);
33
34
    EXPECT_EQ(exception->GetMessage(), "error");
34
35
    EXPECT_EQ(exception->GetLocation(), "location");
35
36
    EXPECT_EQ(std::string(exception->what()), std::string("error at location"));
38
39
}
39
40
 
40
41
TEST(ExceptionTest, SetGetMessageTest) {
41
 
    Exception exception(Exception::recoverable, "error", "location");
 
42
    Exceptions::Exception exception(Exceptions::recoverable, "error", "location");
42
43
    exception.SetMessage("new error");
43
44
    EXPECT_EQ(exception.GetMessage(), "new error");
44
45
    EXPECT_EQ(std::string(exception.what()), std::string("new error at location"));
46
47
 
47
48
std::string test_make_stack_trace(size_t skips, int recursion_level) {
48
49
    if (recursion_level <= 0) {
49
 
        return Exception::MakeStackTrace(skips);
 
50
        return Exceptions::Exception::MakeStackTrace(skips);
50
51
    } else {
51
52
        return test_make_stack_trace(skips, recursion_level-1);
52
53
    }
70
71
TEST(ExceptionTest, PrintTest) {
71
72
    // just run the code; probably if I was being careful I would check the
72
73
    // output by redirecting Squeak...
73
 
    Exception exception(Exception::recoverable, "error", "location");
 
74
    Exceptions::Exception exception(Exceptions::recoverable, "error", "location");
74
75
    exception.Print();
75
76
}
76
77
 
77
78
TEST(ExceptionTest, TestWillDoStackTrace) {
78
 
    Exception::SetWillDoStackTrace(true);
79
 
    EXPECT_TRUE(Exception::GetWillDoStackTrace());
80
 
    Exception exception_1(Exception::recoverable, "error", "location");
 
79
    Exceptions::Exception::SetWillDoStackTrace(true);
 
80
    EXPECT_TRUE(Exceptions::Exception::GetWillDoStackTrace());
 
81
    Exceptions::Exception exception_1(Exceptions::recoverable, "error", "location");
81
82
    EXPECT_TRUE(exception_1.GetStackTrace() != "");
82
83
 
83
 
    Exception::SetWillDoStackTrace(false);
84
 
    EXPECT_FALSE(Exception::GetWillDoStackTrace());
85
 
    Exception exception_2(Exception::recoverable, "error", "location");
 
84
    Exceptions::Exception::SetWillDoStackTrace(false);
 
85
    EXPECT_FALSE(Exceptions::Exception::GetWillDoStackTrace());
 
86
    Exceptions::Exception exception_2(Exceptions::recoverable, "error", "location");
86
87
    EXPECT_TRUE(exception_2.GetStackTrace() == "");
87
88
 
88
 
    Exception::SetWillDoStackTrace(true);
89
 
    EXPECT_TRUE(Exception::GetWillDoStackTrace());
90
 
    Exception exception_3(Exception::recoverable, "error", "location");
 
89
    Exceptions::Exception::SetWillDoStackTrace(true);
 
90
    EXPECT_TRUE(Exceptions::Exception::GetWillDoStackTrace());
 
91
    Exceptions::Exception exception_3(Exceptions::recoverable, "error", "location");
91
92
    EXPECT_TRUE(exception_3.GetStackTrace() != "");
92
93
}
93
94
}