1 //==========================================================================
7 //==========================================================================
8 //####COPYRIGHTBEGIN####
10 // ----------------------------------------------------------------------------
11 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
13 // This file is part of the eCos host tools.
15 // This program is free software; you can redistribute it and/or modify it
16 // under the terms of the GNU General Public License as published by the Free
17 // Software Foundation; either version 2 of the License, or (at your option)
20 // This program is distributed in the hope that it will be useful, but WITHOUT
21 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
22 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
25 // You should have received a copy of the GNU General Public License along with
26 // this program; if not, write to the Free Software Foundation, Inc.,
27 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 // ----------------------------------------------------------------------------
31 //####COPYRIGHTEND####
32 //==========================================================================
33 //#####DESCRIPTIONBEGIN####
36 // Contributors: bartv
39 // Description: This routine checks the invariant assertions.
40 // The entry tests will have been taken care of by
41 // tassert6.cxx, but it is also necessary to check
44 //####DESCRIPTIONEND####
45 //==========================================================================
48 #define CYG_DECLARE_HOST_ASSERTION_SUPPORT
49 #define CYGDBG_USE_ASSERTS
50 #define CYGDBG_INFRA_DEBUG_PRECONDITIONS
51 #define CYGDBG_INFRA_DEBUG_POSTCONDITIONS
52 #define CYGDBG_INFRA_DEBUG_LOOP_INVARIANTS
53 #define CYGDBG_INFRA_DEBUG_INVARIANTS
55 #include <cyg/infra/testcase.h>
56 #include <cyg/infra/cyg_ass.h>
61 // This is used to "recover" from an assertion failure
62 static jmp_buf setjmp_buffer;
64 // The number of assertions that have triggered.
65 static int failed_assertions = 0;
67 // The number of assertions that have been triggered.
68 static int counter = 0;
70 // Are objects currently valid?
71 static bool check_this_should_fail = false;
73 static const char message[] = "so long and thanks for all the fish";
89 static void invariant3(dummy&);
90 static void invariant4(dummy&);
91 static void invariant5(dummy*);
92 static void invariant6(dummy*);
93 bool check_this(cyg_assert_class_zeal) const;
97 dummy::check_this(cyg_assert_class_zeal zeal) const
99 // The default zeal should be cyg_quick.
102 return !check_this_should_fail;
104 case cyg_system_test:
109 CYG_TEST_FAIL_FINISH("incorrect default zeal passed to check_this() member function");
112 CYG_TEST_FAIL_FINISH("invalid zeal passed to check_this() member function");
119 dummy::invariant1(void)
121 CYG_INVARIANT_THIS(dummy, message);
122 check_this_should_fail = true;
126 dummy::invariant2(void)
128 CYG_INVARIANT_THISC(dummy);
129 check_this_should_fail = true;
133 dummy::invariant3(dummy& obj)
135 CYG_INVARIANT_CLASSO(dummy, obj, message);
136 check_this_should_fail = true;
140 dummy::invariant4(dummy& obj)
142 CYG_INVARIANT_CLASSOC(dummy, obj);
143 check_this_should_fail = true;
147 dummy::invariant5(dummy* obj)
149 CYG_INVARIANT_CLASS(dummy, obj, message);
150 check_this_should_fail = true;
154 dummy::invariant6(dummy* obj)
156 CYG_INVARIANT_CLASSC(dummy, obj);
157 check_this_should_fail = true;
162 failure_handler(const char* fn, const char* file, cyg_uint32 line, const char* msg)
164 if (false == check_this_should_fail) {
165 CYG_TEST_FAIL("assertion triggered when everything should be ok");
169 longjmp(setjmp_buffer, 1);
174 main(int argc, char **argv)
178 cyg_assert_install_failure_handler(&failure_handler);
179 setjmp(setjmp_buffer);
181 for ( bool done = false; !done; counter++ ) {
182 check_this_should_fail = false;
187 CYG_TEST_FAIL("CYG_INVARIANT_THIS() test should not have returned");
192 CYG_TEST_FAIL("CYG_INVARIANT_THISC() test should not have returned");
196 dummy::invariant3(object);
197 CYG_TEST_FAIL("CYG_INVARIANT_CLASSO() test should not have returned");
201 dummy::invariant4(object);
202 CYG_TEST_FAIL("CYG_INVARIANT_CLASSOC() test should not have returned");
206 dummy::invariant5(&object);
207 CYG_TEST_FAIL("CYG_INVARIANT_CLASS() test should not have returned");
211 dummy::invariant6(&object);
212 CYG_TEST_FAIL("CYG_INVARIANT_CLASSC() test should not have returned");
217 counter--; // About to get incremented again...
222 if (failed_assertions != 6) {
223 CYG_TEST_FAIL("Broken test case, not all assertions have been tried");
226 if (failed_assertions == counter) {
227 CYG_TEST_PASS("All assertions trigger successfully");
229 CYG_TEST_FAIL("Not all assertions trigger");