OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [host/] [infra/] [testsuite/] [cyginfra/] [tassert1.cxx] - Blame information for rev 790

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      tassert1.cxx
4
//
5
//      Assertion test case                                                                
6
//
7
//==========================================================================
8
// ####ECOSHOSTGPLCOPYRIGHTBEGIN####                                        
9
// -------------------------------------------                              
10
// This file is part of the eCos host tools.                                
11
// Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.            
12
//
13
// This program is free software; you can redistribute it and/or modify     
14
// it under the terms of the GNU General Public License as published by     
15
// the Free Software Foundation; either version 2 or (at your option) any   
16
// later version.                                                           
17
//
18
// This program is distributed in the hope that it will be useful, but      
19
// WITHOUT ANY WARRANTY; without even the implied warranty of               
20
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        
21
// General Public License for more details.                                 
22
//
23
// You should have received a copy of the GNU General Public License        
24
// along with this program; if not, write to the                            
25
// Free Software Foundation, Inc., 51 Franklin Street,                      
26
// Fifth Floor, Boston, MA  02110-1301, USA.                                
27
// -------------------------------------------                              
28
// ####ECOSHOSTGPLCOPYRIGHTEND####                                          
29
//==========================================================================
30
//#####DESCRIPTIONBEGIN####                                             
31
//
32
// Author(s):           bartv
33
// Contributors:        bartv
34
// Date:                1998-11-27
35
// Purpose:
36
// Description:         By default all assertions should be disabled, but
37
//                      they should compile just fine. This module uses all
38
//                      assertions except CYGFAIL. As a fringe benefit, all
39
//                      of the macros get checked for correct argument usage.
40
//
41
//####DESCRIPTIONEND####
42
//==========================================================================
43
 
44
 
45
#include <cyg/infra/testcase.h>
46
#include <cyg/infra/cyg_ass.h>
47
#include <cstdlib>
48
 
49
#ifdef CYGDBG_USE_ASSERTS
50
# error Assertions should not be enabled by default.
51
#endif
52
 
53
static const char message[] = "This should never be seen.";
54
 
55
class dummy {
56
  private:
57
    int       random;
58
  public:
59
    dummy() {
60
        random = rand();
61
    }
62
    ~dummy() {
63
        random = 0;
64
    }
65
    void assertions();
66
    static void extern_assertions(dummy*);
67
    bool check_this(cyg_assert_class_zeal) const;
68
};
69
 
70
int main(int argc, char** argv)
71
{
72
    dummy object;
73
 
74
    CYG_ASSERT( true, message);
75
    CYG_ASSERT( false, message);
76
    CYG_ASSERTC(true);
77
    CYG_ASSERTC(false);
78
 
79
    CYG_FAIL(message);
80
 
81
    CYG_CHECK_DATA_PTR( &argc, message);
82
    CYG_CHECK_DATA_PTR( 0,     message);
83
    CYG_CHECK_FUNC_PTR( &main, message);
84
    CYG_CHECK_FUNC_PTR( 0,     message);
85
    CYG_CHECK_DATA_PTRC(&argc);
86
    CYG_CHECK_DATA_PTRC(0);
87
    CYG_CHECK_FUNC_PTRC(&main);
88
    CYG_CHECK_FUNC_PTRC(0);
89
 
90
    CYG_ASSERT_CLASS(  &object, message);
91
    CYG_ASSERT_CLASSC( &object);
92
    CYG_ASSERT_CLASSO( object, message);
93
    CYG_ASSERT_CLASSOC( object);
94
    CYG_ASSERTCLASS(   &object, message);
95
    CYG_ASSERTCLASSO(  object, message);
96
 
97
    CYG_PRECONDITION(true, message);
98
    CYG_PRECONDITION(false, message);
99
    CYG_PRECONDITIONC(true);
100
    CYG_PRECONDITIONC(false);
101
    CYG_PRECONDITION_CLASS(&object, message);
102
    CYG_PRECONDITION_CLASSC(&object);
103
    CYG_PRECONDITION_CLASSO(object, message);
104
    CYG_PRECONDITION_CLASSOC(object);
105
 
106
    CYG_POSTCONDITION(true, message);
107
    CYG_POSTCONDITION(false, message);
108
    CYG_POSTCONDITIONC(true);
109
    CYG_POSTCONDITIONC(false);
110
    CYG_POSTCONDITION_CLASS(&object, message);
111
    CYG_POSTCONDITION_CLASSC(&object);
112
    CYG_POSTCONDITION_CLASSO(object, message);
113
    CYG_POSTCONDITION_CLASSOC(object);
114
 
115
    CYG_LOOP_INVARIANT(true, message);
116
    CYG_LOOP_INVARIANT(false, message);
117
    CYG_LOOP_INVARIANTC(true);
118
    CYG_LOOP_INVARIANTC(false);
119
    CYG_LOOP_INVARIANT_CLASS(&object, message);
120
    CYG_LOOP_INVARIANT_CLASSC(&object);
121
    CYG_LOOP_INVARIANT_CLASSO(object, message);
122
    CYG_LOOP_INVARIANT_CLASSOC(object);
123
 
124
    CYG_INVARIANT(true, message);
125
    CYG_INVARIANT(false, message);
126
    CYG_INVARIANTC(true);
127
    CYG_INVARIANTC(false);
128
 
129
    dummy::extern_assertions( &object);
130
    dummy::extern_assertions( 0);
131
    object.assertions( );
132
 
133
    CYG_TEST_PASS_FINISH("disabled assertions do nothing");
134
    return 0;
135
}
136
 
137
// A utility routine which performs assertions on this.
138
void
139
dummy::assertions()
140
{
141
    CYG_INVARIANT_THIS(dummy, message);
142
    CYG_INVARIANT_THISC(dummy);
143
 
144
    CYG_ASSERT_THIS(message);
145
    CYG_ASSERT_THISC();
146
    CYG_PRECONDITION_THIS(message);
147
    CYG_PRECONDITION_THISC();
148
    CYG_POSTCONDITION_THIS(message);
149
    CYG_POSTCONDITION_THISC();
150
    CYG_LOOP_INVARIANT_THIS(message);
151
    CYG_LOOP_INVARIANT_THISC();
152
}
153
 
154
// Another utility which gets passed an object pointer.
155
// This is useful for the ZERO_OR_CLASS() variants.
156
void
157
dummy::extern_assertions(dummy* obj)
158
{
159
    dummy obj2;
160
    CYG_INVARIANT_CLASSO(dummy, obj2, message);
161
    CYG_INVARIANT_CLASSOC(dummy, obj2);
162
    CYG_INVARIANT_CLASS(dummy, obj, message);
163
    CYG_INVARIANT_CLASSC(dummy, obj);
164
    CYG_ASSERT_ZERO_OR_CLASS(obj, message);
165
    CYG_ASSERT_ZERO_OR_CLASSC(obj);
166
    CYG_PRECONDITION_ZERO_OR_CLASS(obj, message);
167
    CYG_PRECONDITION_ZERO_OR_CLASSC(obj);
168
    CYG_POSTCONDITION_ZERO_OR_CLASS(obj, message);
169
    CYG_POSTCONDITION_ZERO_OR_CLASSC(obj);
170
    CYG_LOOP_INVARIANT_ZERO_OR_CLASS(obj, message);
171
    CYG_LOOP_INVARIANT_ZERO_OR_CLASSC(obj);
172
}
173
 
174
bool
175
dummy::check_this(cyg_assert_class_zeal zeal) const
176
{
177
    // The default zeal should be cyg_quick.
178
    switch(zeal) {
179
    case cyg_quick:
180
        return true;
181
 
182
    case cyg_system_test:
183
    case cyg_extreme:
184
    case cyg_thorough:
185
    case cyg_trivial:
186
    case cyg_none:
187
        CYG_TEST_FAIL_FINISH("incorrect default zeal passed to check_this() member function");
188
 
189
    default:
190
        CYG_TEST_FAIL_FINISH("invalid zeal passed to check_this() member function");
191
    }
192
    return false;
193
}
194
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.