Changeset 55acc3a for tests


Ignore:
Timestamp:
Nov 6, 2020, 4:48:34 PM (3 years ago)
Author:
m3zulfiq <m3zulfiq@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
139775e
Parents:
ea3fa25
Message:

Added free for multiple frees in the same call. Added adelete tests.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/alloc.cfa

    rea3fa25 r55acc3a  
    208208
    209209
     210        int const_count, dest_count;
    210211        struct Struct { int x; double y; };
     212        void  ?{}( Struct & a ) {                                       // construct
     213                a.[ x, y ] = [ -1, -1.0 ];
     214        }
     215        void  ?{}( Struct & a, int x, double y ) {      // initialize
     216                a.[ x, y ] = [ x, y ];
     217                const_count++;
     218        }
     219        void ^?{}( Struct & a ) {  dest_count++; }      // destruct
    211220        Struct st, st1, sta[dim], sta1[dim], * stp, * stp1;
    212221
     
    329338        printf( "\n" );
    330339
     340        const_count = dest_count = 0;
    331341        stp = new( 42, 42.5 );
     342        assert( const_count == 1 && dest_count == 0 );                                          // assertion for testing
    332343        stp1 = new( 42, 42.5 );
     344        assert( const_count == 2 && dest_count == 0 );                                          // assertion for testing
     345
    333346        printf( "CFA new initialize\n%d %g %d %g\n", stp->x, stp->y, stp1->x, stp1->y );
    334347        delete( stp, stp1 );
     348        assert( const_count == 2 && dest_count == 2 );                                          // assertion for testing
    335349
    336350        // new, array types
    337351        stp = anew( dim, 42, 42.5 );
     352        assert( const_count == 2 + dim && dest_count == 2 );                            // assertion for testing
    338353        printf( "CFA array new initialize\n" );
    339354        for ( i; dim ) { printf( "%d %g, ", stp[i].x, stp[i].y ); }
    340355        printf( "\n" );
     356
    341357        stp1 = anew( dim, 42, 42.5 );
     358        assert( const_count == 2 + 2 * dim && dest_count == 2 );                        // assertion for testing
    342359        for ( i; dim ) { printf( "%d %g, ", stp1[i].x, stp1[i].y ); }
    343360        printf( "\n" );
    344361        adelete( stp, stp1 );
     362        assert( const_count == 2 + 2 * dim && dest_count == 2 + 2 * dim);       // assertion for testing
    345363
    346364        // extras
     
    354372        *ip = 0xdeadbeef;
    355373        printf( "CFA deep malloc %#x\n", *ip );
    356         free( ip );
     374
     375        dp = alloc(5.0`fill); // just for testing multiple free
     376        assert(*dp == 5.0);
     377        free( ip, dp );
    357378
    358379#ifdef ERR1
Note: See TracChangeset for help on using the changeset viewer.