OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [tools/] [src/] [infra/] [testsuite/] [cyginfra/] [tassert1.cxx] - Blame information for rev 196

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

Line No. Rev Author Line
1 26 unneback
//==========================================================================
2
//
3
//      tassert1.cxx
4
//
5
//      Assertion test case                                                                
6
//
7
//==========================================================================
8
//####COPYRIGHTBEGIN####
9
//                                                                          
10
// ----------------------------------------------------------------------------
11
// Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
12
//
13
// This file is part of the eCos host tools.
14
//
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) 
18
// any later version.
19
// 
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 
23
// more details.
24
// 
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.
28
//
29
// ----------------------------------------------------------------------------
30
//                                                                          
31
//####COPYRIGHTEND####
32
//==========================================================================
33
//#####DESCRIPTIONBEGIN####                                             
34
//
35
// Author(s):           bartv
36
// Contributors:        bartv
37
// Date:                1998-11-27
38
// Purpose:
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.
43
//
44
//####DESCRIPTIONEND####
45
//==========================================================================
46
 
47
 
48
#include <cyg/infra/testcase.h>
49
#include <cyg/infra/cyg_ass.h>
50
#include <cstdlib>
51
 
52
#ifdef CYGDBG_USE_ASSERTS
53
# error Assertions should not be enabled by default.
54
#endif
55
 
56
static const char message[] = "This should never be seen.";
57
 
58
class dummy {
59
  private:
60
    int       random;
61
  public:
62
    dummy() {
63
        random = rand();
64
    }
65
    ~dummy() {
66
        random = 0;
67
    }
68
    void assertions();
69
    static void extern_assertions(dummy*);
70
    bool check_this(cyg_assert_class_zeal) const;
71
};
72
 
73
int main(int argc, char** argv)
74
{
75
    dummy object;
76
 
77
    CYG_ASSERT( true, message);
78
    CYG_ASSERT( false, message);
79
    CYG_ASSERTC(true);
80
    CYG_ASSERTC(false);
81
 
82
    CYG_FAIL(message);
83
 
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);
92
 
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);
99
 
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);
108
 
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);
117
 
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);
126
 
127
    CYG_INVARIANT(true, message);
128
    CYG_INVARIANT(false, message);
129
    CYG_INVARIANTC(true);
130
    CYG_INVARIANTC(false);
131
 
132
    dummy::extern_assertions( &object);
133
    dummy::extern_assertions( 0);
134
    object.assertions( );
135
 
136
    CYG_TEST_PASS_FINISH("disabled assertions do nothing");
137
    return 0;
138
}
139
 
140
// A utility routine which performs assertions on this.
141
void
142
dummy::assertions()
143
{
144
    CYG_INVARIANT_THIS(dummy, message);
145
    CYG_INVARIANT_THISC(dummy);
146
 
147
    CYG_ASSERT_THIS(message);
148
    CYG_ASSERT_THISC();
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();
155
}
156
 
157
// Another utility which gets passed an object pointer.
158
// This is useful for the ZERO_OR_CLASS() variants.
159
void
160
dummy::extern_assertions(dummy* obj)
161
{
162
    dummy obj2;
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);
175
}
176
 
177
bool
178
dummy::check_this(cyg_assert_class_zeal zeal) const
179
{
180
    // The default zeal should be cyg_quick.
181
    switch(zeal) {
182
    case cyg_quick:
183
        return true;
184
 
185
    case cyg_system_test:
186
    case cyg_extreme:
187
    case cyg_thorough:
188
    case cyg_trivial:
189
    case cyg_none:
190
        CYG_TEST_FAIL_FINISH("incorrect default zeal passed to check_this() member function");
191
 
192
    default:
193
        CYG_TEST_FAIL_FINISH("invalid zeal passed to check_this() member function");
194
    }
195
    return false;
196
}
197
 

powered by: WebSVN 2.1.0

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