~ubuntu-branches/ubuntu/quantal/libgc/quantal

« back to all changes in this revision

Viewing changes to tests/test_cpp.cc

  • Committer: Bazaar Package Importer
  • Author(s): Christoph Egger
  • Date: 2011-02-19 12:19:56 UTC
  • mfrom: (1.3.2 upstream) (0.1.5 experimental)
  • mto: This revision was merged to the branch mainline in revision 14.
  • Revision ID: james.westby@ubuntu.com-20110219121956-67rb69xlt5nud3v2
Tags: 1:7.1-5
Upload to unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
#   include "gc_alloc.h"
38
38
#endif
39
39
extern "C" {
40
 
#include "private/gc_priv.h"
 
40
# include "private/gcconfig.h"
 
41
  GC_API void GC_printf(const char *format, ...);
 
42
  /* Use GC private output to reach the same log file.  */
 
43
  /* Don't include gc_priv.h, since that may include Windows system     */
 
44
  /* header files that don't take kindly to this context.               */
41
45
}
42
46
#ifdef MSWIN32
43
47
#   include <windows.h>
52
56
 
53
57
#define my_assert( e ) \
54
58
    if (! (e)) { \
55
 
        GC_printf1( "Assertion failure in " __FILE__ ", line %d: " #e "\n", \
 
59
        GC_printf( "Assertion failure in " __FILE__ ", line %d: " #e "\n", \
56
60
                    __LINE__ ); \
57
61
        exit( 1 ); }
58
62
 
119
123
    static void CleanUp( void* obj, void* data ) {
120
124
        D* self = (D*) obj;
121
125
        nFreed++;
122
 
        my_assert( self->i == (int) (long) data );}
 
126
        my_assert( self->i == (int) (GC_word) data );}
123
127
    static void Test() {
124
128
        my_assert( nFreed >= .8 * nAllocated );}
125
129
       
166
170
int F::nAllocated = 0;
167
171
   
168
172
 
169
 
long Disguise( void* p ) {
170
 
    return ~ (long) p;}
 
173
GC_word Disguise( void* p ) {
 
174
    return ~ (GC_word) p;}
171
175
 
172
 
void* Undisguise( long i ) {
 
176
void* Undisguise( GC_word i ) {
173
177
    return (void*) ~ i;}
174
178
 
175
179
 
216
220
      x = 0;
217
221
#   endif
218
222
    if (argc != 2 || (0 >= (n = atoi( argv[ 1 ] )))) {
219
 
        GC_printf0( "usage: test_cpp number-of-iterations\nAssuming 10 iters\n" );
 
223
        GC_printf( "usage: test_cpp number-of-iterations\nAssuming 10 iters\n" );
220
224
        n = 10;}
221
225
        
222
226
    for (iters = 1; iters <= n; iters++) {
223
 
        GC_printf1( "Starting iteration %d\n", iters );
 
227
        GC_printf( "Starting iteration %d\n", iters );
224
228
 
225
229
            /* Allocate some uncollectable As and disguise their pointers.
226
230
            Later we'll check to see if the objects are still there.  We're
227
231
            checking to make sure these objects really are uncollectable. */
228
 
        long as[ 1000 ];
229
 
        long bs[ 1000 ];
 
232
        GC_word as[ 1000 ];
 
233
        GC_word bs[ 1000 ];
230
234
        for (i = 0; i < 1000; i++) {
231
235
            as[ i ] = Disguise( new (NoGC) A( i ) );
232
236
            bs[ i ] = Disguise( new (NoGC) B( i ) );}
236
240
        for (i = 0; i < 1000; i++) {
237
241
            C* c = new C( 2 );
238
242
            C c1( 2 );           /* stack allocation should work too */
239
 
            D* d = ::new (USE_GC, D::CleanUp, (void*)(long)i) D( i );
 
243
            D* d = ::new (USE_GC, D::CleanUp, (void*)(GC_word)i) D( i );
240
244
            F* f = new F;
241
245
            if (0 == i % 10) delete c;}
242
246
 
282
286
      x = *xptr;
283
287
#   endif
284
288
    my_assert (29 == x[0]);
285
 
    GC_printf0( "The test appears to have succeeded.\n" );
 
289
    GC_printf( "The test appears to have succeeded.\n" );
286
290
    return( 0 );}
287
291
    
288
292