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

Subversion Repositories openrisc

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

powered by: WebSVN 2.1.0

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