reprtest.cc 3.11 KB
Newer Older
thomas.forbriger's avatar
thomas.forbriger committed
1
2
3
4
5
/*! \file reprtest.cc
 * \brief test representation classes (implementation)
 * 
 * ----------------------------------------------------------------------------
 * 
thomas.forbriger's avatar
thomas.forbriger committed
6
 * $Id: reprtest.cc,v 1.9 2002-12-31 17:19:47 forbrig Exp $
thomas.forbriger's avatar
thomas.forbriger committed
7
8
9
10
 * \author Thomas Forbriger
 * \date 10/05/2002
 * 
 * test representation classes (implementation)
thomas.forbriger's avatar
thomas.forbriger committed
11
12
13
 *
 * \todo
 * Test ALL constructors etc intensively!
thomas.forbriger's avatar
thomas.forbriger committed
14
15
16
17
18
 * 
 * Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt) 
 * 
 * REVISIONS and CHANGES 
 *  - 10/05/2002   V1.0   Thomas Forbriger
thomas.forbriger's avatar
thomas.forbriger committed
19
20
 *  - 16/12/2002   V1.1   (thof)
 *                        - compiles and works
thomas.forbriger's avatar
thomas.forbriger committed
21
22
 *  - 28/12/2002   V1.2   (thof)
 *                        - new term for containers of const elements
thomas.forbriger's avatar
thomas.forbriger committed
23
24
25
 *  - 31/12/2002   V1.3   (thof)
 *                        - initializing an aff::ConstSharedHeap to a defined
 *                          size is a useless exercise
thomas.forbriger's avatar
thomas.forbriger committed
26
27
28
 * 
 * ============================================================================
 */
thomas.forbriger's avatar
huuu    
thomas.forbriger committed
29
#define AFF_REPRTEST_CC_VERSION \
thomas.forbriger's avatar
thomas.forbriger committed
30
  "AFF_REPRTEST_CC   V1.3"
thomas.forbriger's avatar
huuu    
thomas.forbriger committed
31
#define AFF_REPRTEST_CC_CVSID \
thomas.forbriger's avatar
thomas.forbriger committed
32
  "$Id: reprtest.cc,v 1.9 2002-12-31 17:19:47 forbrig Exp $"
thomas.forbriger's avatar
thomas.forbriger committed
33

thomas.forbriger's avatar
huuu    
thomas.forbriger committed
34
35
#include <aff/lib/sharedheap.h>
#include <aff/dump.h>
thomas.forbriger's avatar
thomas.forbriger committed
36
37
38
39

using std::cout;
using std::endl;

thomas.forbriger's avatar
thomas.forbriger committed
40
41
42
43
/*! \example tests/reprtest.cc
 *
 * Test representation class aff::SharedHeap.
 *
thomas.forbriger's avatar
thomas.forbriger committed
44
45
46
47
48
49
50
 * This test program gives an example of the usage of the following classes
 * and preprocessor macros:
 *   - aff::SharedHeap
 *   - aff::ConstSharedHeap
 *   - #DUMP
 *   - #CODE
 *
thomas.forbriger's avatar
thomas.forbriger committed
51
52
53
 * \sa tests/reprtest.cc
 */

thomas.forbriger's avatar
thomas.forbriger committed
54
55
56
57
58
59
60
61
62
63
64
65
66
//! print headline
void section(const char* s)
{
  cout << endl
       << s << endl;
  const char* p=s;
  while (*p) {
    cout << "-";
    ++p;
  }
  cout << endl;
}

thomas.forbriger's avatar
huuu    
thomas.forbriger committed
67
//! testing SharedHeap
thomas.forbriger's avatar
thomas.forbriger committed
68
69
int main()
{
thomas.forbriger's avatar
huuu    
thomas.forbriger committed
70
71
  cout << AFF_REPRTEST_CC_VERSION << endl;
  cout << AFF_REPRTEST_CC_CVSID << endl;
thomas.forbriger's avatar
thomas.forbriger committed
72

thomas.forbriger's avatar
thomas.forbriger committed
73
74
75
  section("array dimensions");
  CODE( const int N=10; )
  CODE( const int N2=23; )
thomas.forbriger's avatar
thomas.forbriger committed
76

thomas.forbriger's avatar
thomas.forbriger committed
77
78
79
  section("instantiate arrays");
  CODE( aff::SharedHeap<int> A(N); )
  CODE( aff::SharedHeap<int> B(N2); )
thomas.forbriger's avatar
thomas.forbriger committed
80
81
82
83
84
#ifdef SENSELESS
#warning intentionally compiling senseless code
  CODE( aff::ConstSharedHeap<int> Cuseless(N2); )
#endif
  CODE( aff::ConstSharedHeap<int> C; )
thomas.forbriger's avatar
thomas.forbriger committed
85
  CODE( aff::SharedHeap<float> D(N2); )
thomas.forbriger's avatar
thomas.forbriger committed
86

thomas.forbriger's avatar
thomas.forbriger committed
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
  section("create a const reference to D");
  CODE( aff::SharedHeap<float>::Tcoc E(D); )

  section("const int array should share memory with int array");
  CODE( C=B; )

  section("fill arrays");
  CODE( for (int i=0; i<N; i++) { A[i]=(i+1)*10; } )
  CODE( for (int i=0; i<N2; i++) { B[i]=(i+4)*3; } )
  CODE( for (int i=0; i<N2; i++) { D[i]=(i+2.45)*2; } )

  section("dump contents - C is filled through B and E is filled through D");
  DUMP( aff::SharedHeap<int>::Tcontainer_of_const(A) );
  DUMP( B );
  DUMP( C );
  DUMP( E );

  section("modify C through B");
  CODE( B[8]=632; )
  DUMP( C );
thomas.forbriger's avatar
huuu    
thomas.forbriger committed
107

thomas.forbriger's avatar
thomas.forbriger committed
108
#ifdef ILLEGAL1
thomas.forbriger's avatar
thomas.forbriger committed
109
110
  // you may activate this section by passing -DILLEGAL1 to the compiler
  section("modify C directly - is illegal");
thomas.forbriger's avatar
thomas.forbriger committed
111
  C[9]=354;
thomas.forbriger's avatar
thomas.forbriger committed
112
  DUMP( C );
thomas.forbriger's avatar
thomas.forbriger committed
113
114
#endif

thomas.forbriger's avatar
thomas.forbriger committed
115
116
117
118
119
120
121
  section("make B a reference to A");
  CODE( B=A; )
  section("modification should be visible through B");
  CODE( A[5]=453; )
  DUMP( B );
  section("but C holds the original values");
  DUMP( C );
thomas.forbriger's avatar
thomas.forbriger committed
122
123
124
}

/* ----- END OF reprtest.cc ----- */