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: By default all assertions should be disabled, but
40 // they should compile just fine. This module uses all
41 // assertions except CYGFAIL. As a fringe benefit, all
42 // of the macros get checked for correct argument usage.
44 //####DESCRIPTIONEND####
45 //==========================================================================
48 #include <cyg/infra/testcase.h>
49 #include <cyg/infra/cyg_ass.h>
52 #ifdef CYGDBG_USE_ASSERTS
53 # error Assertions should not be enabled by default.
56 static const char message[] = "This should never be seen.";
69 static void extern_assertions(dummy*);
70 bool check_this(cyg_assert_class_zeal) const;
73 int main(int argc, char** argv)
77 CYG_ASSERT( true, message);
78 CYG_ASSERT( false, message);
84 CYG_CHECK_DATA_PTR( &argc, message);
85 CYG_CHECK_DATA_PTR( 0, message);
86 CYG_CHECK_FUNC_PTR( &main, message);
87 CYG_CHECK_FUNC_PTR( 0, message);
88 CYG_CHECK_DATA_PTRC(&argc);
89 CYG_CHECK_DATA_PTRC(0);
90 CYG_CHECK_FUNC_PTRC(&main);
91 CYG_CHECK_FUNC_PTRC(0);
93 CYG_ASSERT_CLASS( &object, message);
94 CYG_ASSERT_CLASSC( &object);
95 CYG_ASSERT_CLASSO( object, message);
96 CYG_ASSERT_CLASSOC( object);
97 CYG_ASSERTCLASS( &object, message);
98 CYG_ASSERTCLASSO( object, message);
100 CYG_PRECONDITION(true, message);
101 CYG_PRECONDITION(false, message);
102 CYG_PRECONDITIONC(true);
103 CYG_PRECONDITIONC(false);
104 CYG_PRECONDITION_CLASS(&object, message);
105 CYG_PRECONDITION_CLASSC(&object);
106 CYG_PRECONDITION_CLASSO(object, message);
107 CYG_PRECONDITION_CLASSOC(object);
109 CYG_POSTCONDITION(true, message);
110 CYG_POSTCONDITION(false, message);
111 CYG_POSTCONDITIONC(true);
112 CYG_POSTCONDITIONC(false);
113 CYG_POSTCONDITION_CLASS(&object, message);
114 CYG_POSTCONDITION_CLASSC(&object);
115 CYG_POSTCONDITION_CLASSO(object, message);
116 CYG_POSTCONDITION_CLASSOC(object);
118 CYG_LOOP_INVARIANT(true, message);
119 CYG_LOOP_INVARIANT(false, message);
120 CYG_LOOP_INVARIANTC(true);
121 CYG_LOOP_INVARIANTC(false);
122 CYG_LOOP_INVARIANT_CLASS(&object, message);
123 CYG_LOOP_INVARIANT_CLASSC(&object);
124 CYG_LOOP_INVARIANT_CLASSO(object, message);
125 CYG_LOOP_INVARIANT_CLASSOC(object);
127 CYG_INVARIANT(true, message);
128 CYG_INVARIANT(false, message);
129 CYG_INVARIANTC(true);
130 CYG_INVARIANTC(false);
132 dummy::extern_assertions( &object);
133 dummy::extern_assertions( 0);
134 object.assertions( );
136 CYG_TEST_PASS_FINISH("disabled assertions do nothing");
140 // A utility routine which performs assertions on this.
144 CYG_INVARIANT_THIS(dummy, message);
145 CYG_INVARIANT_THISC(dummy);
147 CYG_ASSERT_THIS(message);
149 CYG_PRECONDITION_THIS(message);
150 CYG_PRECONDITION_THISC();
151 CYG_POSTCONDITION_THIS(message);
152 CYG_POSTCONDITION_THISC();
153 CYG_LOOP_INVARIANT_THIS(message);
154 CYG_LOOP_INVARIANT_THISC();
157 // Another utility which gets passed an object pointer.
158 // This is useful for the ZERO_OR_CLASS() variants.
160 dummy::extern_assertions(dummy* obj)
163 CYG_INVARIANT_CLASSO(dummy, obj2, message);
164 CYG_INVARIANT_CLASSOC(dummy, obj2);
165 CYG_INVARIANT_CLASS(dummy, obj, message);
166 CYG_INVARIANT_CLASSC(dummy, obj);
167 CYG_ASSERT_ZERO_OR_CLASS(obj, message);
168 CYG_ASSERT_ZERO_OR_CLASSC(obj);
169 CYG_PRECONDITION_ZERO_OR_CLASS(obj, message);
170 CYG_PRECONDITION_ZERO_OR_CLASSC(obj);
171 CYG_POSTCONDITION_ZERO_OR_CLASS(obj, message);
172 CYG_POSTCONDITION_ZERO_OR_CLASSC(obj);
173 CYG_LOOP_INVARIANT_ZERO_OR_CLASS(obj, message);
174 CYG_LOOP_INVARIANT_ZERO_OR_CLASSC(obj);
178 dummy::check_this(cyg_assert_class_zeal zeal) const
180 // The default zeal should be cyg_quick.
185 case cyg_system_test:
190 CYG_TEST_FAIL_FINISH("incorrect default zeal passed to check_this() member function");
193 CYG_TEST_FAIL_FINISH("invalid zeal passed to check_this() member function");