]> SALOME platform Git repositories - modules/med.git/blob - src/MEDMEM/tests/testUPointerOf.cxx
Salome HOME
correct a small bug appearing when using the gcc 3.2.1.
[modules/med.git] / src / MEDMEM / tests / testUPointerOf.cxx
1 //  Copyright (C) 2003  CEA/DEN, EDF R&D
2 //
3 //
4 //
5 //  File   : testUPointerOf.cxx
6 //  Module : MED
7
8 using namespace std;
9 #include "utilities.h"
10 #include "MEDMEM_PointerOf.hxx"
11 #include "MEDMEM_Exception.hxx"
12 using namespace MEDMEM;
13
14
15 int main (int argc, char ** argv) 
16 {
17   cout << "PointerOf Test" << endl ;
18   cout << "--------------" << endl;
19
20   const int size=10;
21   PointerOf<int> P;
22
23   // Creation d'un PointerOf de int
24   // et vérification de la methode set en essayant avec 
25   // une taille nulle, négative puis positive
26   try
27   {
28         P.set(0);
29         ASSERT((int *)P == NULL);
30   }
31   catch ( const std::exception &e )
32   {
33         cout << "-------------------------" << endl;
34         cout << " pb avec set(taille = 0) " << endl;
35         cout << "-------------------------" << endl;
36         MESSAGE( "catched exception : " << e.what() ) ;
37         return EXIT_FAILURE ;
38   }
39
40   try
41   {
42         P.set(-1 * size);
43         ASSERT((int *)P == NULL);
44   }
45   catch ( const std::exception &e )
46   {
47         cout << "---------------------" << endl;
48         cout << " pb avec set(taille) " << endl;
49         cout << "---------------------" << endl;
50         MESSAGE( "catched exception : " << e.what() ) ;
51         return EXIT_FAILURE ;
52   }
53
54   try
55   {
56         P.set(size);
57         ASSERT((int *)P != NULL);
58   }
59   catch ( const std::exception &e )
60   {
61         cout << "---------------------" << endl;
62         cout << " pb avec set(taille) " << endl;
63         cout << "---------------------" << endl;
64         MESSAGE( "catched exception : " << e.what() ) ;
65         return EXIT_FAILURE ;
66   }
67   for (int i=0; i < size; i++)
68   {
69         P[i]=i;
70   }
71
72   PointerOf<int> P2(10);
73
74   P2=P;
75   for (int i=0; i < size; i++)
76   {
77         SCRUTE(P2[i]);
78   }
79
80   int * p=new int [size];
81   for (int i=0; i < size; i++)
82   {
83         p[i]=i*10;
84   }
85   
86   P2.set(p);
87   PointerOf<int> P3(p);
88
89   for (int i=0; i < size; i++)
90   {
91         SCRUTE(P2[i]);
92         SCRUTE(P3[i]);
93   }
94
95   const PointerOf<int> P4(p);
96   const PointerOf<int> P5(P4);
97   delete [] p;
98   
99 }