Debian Codegraph @

tests/test_eassert.cc

raw
1 // test_eassert.cc
2 //
3 // Copyright (C) 2005, 2007 Daniel Burrows
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License as
7 // published by the Free Software Foundation; either version 2 of
8 // the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; see the file COPYING. If not, write to
17 // the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 // Boston, MA 02111-1307, USA.
19
20 // TODO: eassert lives in cwidget now, this test should perhaps move
21 // there.
22
23 #include <cwidget/generic/util/eassert.h>
24
25 #include <cppunit/extensions/HelperMacros.h>
26
27 class EassertTest : public CppUnit::TestFixture
28 {
29 CPPUNIT_TEST_SUITE(EassertTest);
30
31 CPPUNIT_TEST(testEassert);
32
33 CPPUNIT_TEST_SUITE_END();
34 public:
35 void testEassert()
36 {
37 const int a = 5;
38 const int b = 6;
39
40 eassert(a == 5);
41 eassert(b != 6 ||
42 a != 2);
43
44 size_t failureLine;
45
46 // Failing asserts:
47 try
48 {
49 failureLine = __LINE__; eassert(a == 1);
50 }
51 catch(cwidget::util::AssertionFailure &e)
52 {
53 CPPUNIT_ASSERT_EQUAL(std::string("a == 1"), e.get_exp());
54 CPPUNIT_ASSERT_EQUAL(failureLine, e.get_line());
55 CPPUNIT_ASSERT_EQUAL(std::string("void EassertTest::testEassert()"), e.get_func());
56 // Having to use __FILE__ is unfortunate, but with staged
57 // builds the filename isn't predictable (e.g., with
58 // "distcheck" it's "../../tests/test_eassert.cc").
59 CPPUNIT_ASSERT_EQUAL(std::string(__FILE__), e.get_file());
60 }
61 }
62 };
63
64 CPPUNIT_TEST_SUITE_REGISTRATION(EassertTest);