1 #include <tests/Example.hxx>
2 #include <libsex/Exception.hxx>
3 #include <libfsafe/checkpoint.hxx>
4 #include <libfsafe/assert.hxx>
7 // main() is the entry point -- both for our example
8 // "application" and this unit test.
10 void tests::Example::main()
12 std::stringstream cout
;
15 // Real work starts now.
21 // Real work finished.
23 } catch (libsex::Exception
& e
) {
28 __FILE__
":54: In 'c = calculate(a)':\n"
29 __FILE__
":64: Precondition 'ptr[1] < 42' violated.";
30 CPPUNIT_ASSERT_EQUAL(exp
, cout
.str());
33 void tests::Example::initialize()
35 // Some boring initialization stuff.
38 void tests::Example::cleanup()
40 // Boring cleanup here.
43 void tests::Example::run()
45 // The really important part of our code.
51 // Note that we can't declare c in CHECKPOINT
52 // because it would be wrapped in try-catch.
54 CHECKPOINT(c
= calculate(a
));
56 // Now do something with c.
60 int tests::Example::calculate(int* ptr
)
62 ASSERT_PRE(ptr
!= NULL
);
63 ASSERT_PRE(ptr
[0] < 42);
64 ASSERT_PRE(ptr
[1] < 42);
66 int result
= ptr
[0] + ptr
[1];
68 ASSERT_POST(result
<= 82);