Ignore:
Timestamp:
Jul 5, 2016, 5:03:40 PM (8 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
a922e34
Parents:
3a808fd
Message:

update include files for test programs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/tests/libcfa_vector.c

    r3a808fd r00b7cd3  
    1 #include <stdlib>
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// libcfa_vector.c --
     8//
     9// Author           : Thierry Delisle
     10// Created On       : Mon Jul  4 23:36:19 2016
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Tue Jul  5 15:08:05 2016
     13// Update Count     : 26
     14//
    215
    3 extern "C" {
    4         #include <stdio.h>
     16#include <fstream>
     17#include <vector>
     18
     19#undef assert
     20#define assert(x)                                                               \
     21        do {                                                                            \
     22                if ( !(x) ) {                                                   \
     23                        sout | "CHECK failed :" | #x | "at" | __FILE__ | " :" | __LINE__ | endl;        \
     24                        abort();                                                        \
     25                }                                                                               \
     26        } while( 0 == 1 )
     27
     28int main() {
     29        vector( int, heap_allocator(int) ) iv;
     30        ctor( &iv );
     31
     32        assert( empty( &iv ) );
     33        assert( size( &iv ) == 0 );
     34        sout | size( &iv ) | endl;
     35
     36        push_back( &iv, 1 );
     37        assert( size( &iv ) == 1 );
     38        sout | size( &iv ) | endl;
     39
     40        push_back( &iv, 2 );
     41        assert( size( &iv ) == 2 );
     42        sout | size( &iv ) | endl;
     43
     44        push_back( &iv, 3 );
     45        assert( size( &iv ) == 3 );
     46        sout | size( &iv ) | endl;
     47
     48        assert( !empty( &iv ) );
     49        assert( size( &iv ) == 3 );
     50        assert( at( &iv, 0 ) == 1 );
     51        assert( (&iv)[0] == 1 );
     52        assert( at( &iv, 1 ) == 2 );
     53        assert( (&iv)[1] == 2 );
     54        assert( at( &iv, 2 ) == 3 );
     55        assert( (&iv)[2] == 3 );
     56
     57        clear( &iv );
     58
     59        assert( empty( &iv ) );
     60        assert( size( &iv ) == 0 );
     61        sout | size( &iv ) | endl;
    562}
    663
    7 #include <containers/vector>
    8 
    9 #define assert(x) do {\
    10         if(!(x)) {\
    11                 printf("CHECK failed : %s at %s:%i\n", #x, __FILE__, __LINE__);\
    12                 abort();\
    13         }}while(0 == 1)\
    14 
    15 int main(int argc, char const *argv[]) {
    16         vector(int, heap_allocator(int)) iv;
    17         ctor(&iv);
    18 
    19         assert(empty(&iv));
    20         assert(size(&iv) == 0);
    21         printf("%d\n", size(&iv));
    22 
    23         push_back(&iv, 1);
    24         printf("%d\n", size(&iv));
    25         assert(size(&iv) == 1);
    26         push_back(&iv, 2);
    27         printf("%d\n", size(&iv));
    28         assert(size(&iv) == 2);
    29         push_back(&iv, 3);
    30         printf("%d\n", size(&iv));
    31         assert(size(&iv) == 3);
    32 
    33         assert(!empty(&iv));
    34         assert(size(&iv) == 3);
    35         assert(at(&iv, 0) == 1);
    36         assert((&iv)[0] == 1);
    37         assert(at(&iv, 1) == 2);
    38         assert((&iv)[1] == 2);
    39         assert(at(&iv, 2) == 3);
    40         assert((&iv)[2] == 3);
    41 
    42         clear(&iv);
    43 
    44         assert(empty(&iv));
    45         assert(size(&iv) == 0);
    46         printf("%d\n", size(&iv));
    47 
    48         return 0;
    49 }
     64// Local Variables: //
     65// tab-width: 4 //
     66// compile-command: "cfa libcfa_vector.c" //
     67// End: //
Note: See TracChangeset for help on using the changeset viewer.