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

Subversion Repositories openrisc_me

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

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

Line No. Rev Author Line
1 26 unneback
//==========================================================================
2
//
3
//      tassert2.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-12-21
38
// Purpose:
39
// Description:         All assertions are enabled but should pass.
40
//
41
//####DESCRIPTIONEND####
42
//==========================================================================
43
 
44
#define CYGDBG_USE_ASSERTS
45
#define CYGDBG_INFRA_DEBUG_PRECONDITIONS
46
#define CYGDBG_INFRA_DEBUG_POSTCONDITIONS
47
#define CYGDBG_INFRA_DEBUG_LOOP_INVARIANTS
48
#define CYGDBG_INFRA_DEBUG_INVARIANTS
49
 
50
#include <cyg/infra/testcase.h>
51
#include <cyg/infra/cyg_ass.h>
52
#include <cstdlib>
53
 
54
 
55
static const char message[] = "This should never be seen.";
56
 
57
class dummy {
58
  private:
59
    int       random;
60
  public:
61
    dummy() {
62
        random = rand();
63
    }
64
    ~dummy() {
65
        random = 0;
66
    }
67
    void assertions();
68
    void zero_assertions();
69
    static void extern_assertions(dummy*);
70
    static void zero_assertions(dummy*);
71
    bool check_this(cyg_assert_class_zeal) const;
72
};
73
 
74
int main(int argc, char** argv)
75
{
76
    dummy object;
77
 
78
    CYG_ASSERT( true, message);
79
    CYG_ASSERTC(true);
80
 
81
    CYG_CHECK_DATA_PTR( &argc, message);
82
    CYG_CHECK_FUNC_PTR( &main, message);
83
    CYG_CHECK_DATA_PTRC(&argc);
84
    CYG_CHECK_FUNC_PTRC(&main);
85
 
86
    CYG_ASSERT_CLASS(  &object, message);
87
    CYG_ASSERT_CLASSC( &object);
88
    CYG_ASSERT_CLASSO( object, message);
89
    CYG_ASSERT_CLASSOC( object);
90
    CYG_ASSERTCLASS(   &object, message);
91
    CYG_ASSERTCLASSO(  object, message);
92
 
93
    CYG_PRECONDITION(true, message);
94
    CYG_PRECONDITIONC(true);
95
    CYG_PRECONDITION_CLASS(&object, message);
96
    CYG_PRECONDITION_CLASSC(&object);
97
    CYG_PRECONDITION_CLASSO(object, message);
98
    CYG_PRECONDITION_CLASSOC(object);
99
 
100
    CYG_POSTCONDITION(true, message);
101
    CYG_POSTCONDITIONC(true);
102
    CYG_POSTCONDITION_CLASS(&object, message);
103
    CYG_POSTCONDITION_CLASSC(&object);
104
    CYG_POSTCONDITION_CLASSO(object, message);
105
    CYG_POSTCONDITION_CLASSOC(object);
106
 
107
    CYG_LOOP_INVARIANT(true, message);
108
    CYG_LOOP_INVARIANTC(true);
109
    CYG_LOOP_INVARIANT_CLASS(&object, message);
110
    CYG_LOOP_INVARIANT_CLASSC(&object);
111
    CYG_LOOP_INVARIANT_CLASSO(object, message);
112
    CYG_LOOP_INVARIANT_CLASSOC(object);
113
 
114
    CYG_INVARIANT(true, message);
115
    CYG_INVARIANTC(true);
116
 
117
    dummy::extern_assertions( &object);
118
    dummy::zero_assertions( &object);
119
    object.assertions( );
120
 
121
    CYG_TEST_PASS_FINISH("true assertions do nothing");
122
    return 0;
123
}
124
 
125
// A utility routine which performs assertions on this.
126
void
127
dummy::assertions()
128
{
129
    CYG_INVARIANT_THIS(dummy, message);
130
    CYG_INVARIANT_THISC(dummy);
131
 
132
    CYG_ASSERT_THIS(message);
133
    CYG_ASSERT_THISC();
134
    CYG_PRECONDITION_THIS(message);
135
    CYG_PRECONDITION_THISC();
136
    CYG_POSTCONDITION_THIS(message);
137
    CYG_POSTCONDITION_THISC();
138
    CYG_LOOP_INVARIANT_THIS(message);
139
    CYG_LOOP_INVARIANT_THISC();
140
}
141
 
142
// Another utility which gets passed an object pointer.
143
// This is useful for the ZERO_OR_CLASS() variants.
144
void
145
dummy::extern_assertions(dummy* obj)
146
{
147
    dummy obj2;
148
    CYG_INVARIANT_CLASSO(dummy, obj2, message);
149
    CYG_INVARIANT_CLASSOC(dummy, obj2);
150
    CYG_INVARIANT_CLASS(dummy, obj, message);
151
    CYG_INVARIANT_CLASSC(dummy, obj);
152
 
153
    CYG_ASSERT_ZERO_OR_CLASS(obj, message);
154
    CYG_ASSERT_ZERO_OR_CLASSC(obj);
155
    CYG_PRECONDITION_ZERO_OR_CLASS(obj, message);
156
    CYG_PRECONDITION_ZERO_OR_CLASSC(obj);
157
    CYG_POSTCONDITION_ZERO_OR_CLASS(obj, message);
158
    CYG_POSTCONDITION_ZERO_OR_CLASSC(obj);
159
    CYG_LOOP_INVARIANT_ZERO_OR_CLASS(obj, message);
160
    CYG_LOOP_INVARIANT_ZERO_OR_CLASSC(obj);
161
}
162
 
163
void
164
dummy::zero_assertions(dummy* obj)
165
{
166
    CYG_ASSERT_ZERO_OR_CLASS(obj, message);
167
    CYG_ASSERT_ZERO_OR_CLASSC(obj);
168
    CYG_PRECONDITION_ZERO_OR_CLASS(obj, message);
169
    CYG_PRECONDITION_ZERO_OR_CLASSC(obj);
170
    CYG_POSTCONDITION_ZERO_OR_CLASS(obj, message);
171
    CYG_POSTCONDITION_ZERO_OR_CLASSC(obj);
172
    CYG_LOOP_INVARIANT_ZERO_OR_CLASS(obj, message);
173
    CYG_LOOP_INVARIANT_ZERO_OR_CLASSC(obj);
174
}
175
 
176
bool
177
dummy::check_this(cyg_assert_class_zeal zeal) const
178
{
179
    // The default zeal should be cyg_quick.
180
    switch(zeal) {
181
    case cyg_quick:
182
        return true;
183
 
184
    case cyg_system_test:
185
    case cyg_extreme:
186
    case cyg_thorough:
187
    case cyg_trivial:
188
    case cyg_none:
189
        CYG_TEST_FAIL_FINISH("incorrect default zeal passed to check_this() member function");
190
 
191
    default:
192
        CYG_TEST_FAIL_FINISH("invalid zeal passed to check_this() member function");
193
    }
194
    return false;
195
}

powered by: WebSVN 2.1.0

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