]> SALOME platform Git repositories - modules/med.git/blob - src/MEDMEM/tests/testUPointerOf.cxx
Salome HOME
update from the MedMemory V1.0.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
13
14 int main (int argc, char ** argv) 
15 {
16   cout << "PointerOf Test" << endl ;
17   cout << "--------------" << endl;
18
19   const int size=10;
20   PointerOf<int> P;
21
22   // Creation d'un PointerOf de int
23   // et vérification de la methode set en essayant avec 
24   // une taille nulle, négative puis positive
25   try
26   {
27         P.set(0);
28         ASSERT((int *)P == NULL);
29   }
30   catch ( const std::exception &e )
31   {
32         cout << "-------------------------" << endl;
33         cout << " pb avec set(taille = 0) " << endl;
34         cout << "-------------------------" << endl;
35         MESSAGE( "catched exception : " << e.what() ) ;
36         return EXIT_FAILURE ;
37   }
38
39   try
40   {
41         P.set(-1 * size);
42         ASSERT((int *)P == NULL);
43   }
44   catch ( const std::exception &e )
45   {
46         cout << "---------------------" << endl;
47         cout << " pb avec set(taille) " << endl;
48         cout << "---------------------" << endl;
49         MESSAGE( "catched exception : " << e.what() ) ;
50         return EXIT_FAILURE ;
51   }
52
53   try
54   {
55         P.set(size);
56         ASSERT((int *)P != NULL);
57   }
58   catch ( const std::exception &e )
59   {
60         cout << "---------------------" << endl;
61         cout << " pb avec set(taille) " << endl;
62         cout << "---------------------" << endl;
63         MESSAGE( "catched exception : " << e.what() ) ;
64         return EXIT_FAILURE ;
65   }
66   for (int i=0; i < size; i++)
67   {
68         P[i]=i;
69   }
70
71   PointerOf<int> P2(10);
72
73   P2=P;
74   for (int i=0; i < size; i++)
75   {
76         SCRUTE(P2[i]);
77   }
78
79   int * p=new int [size];
80   for (int i=0; i < size; i++)
81   {
82         p[i]=i*10;
83   }
84   
85   P2.set(p);
86   PointerOf<int> P3(p);
87
88   for (int i=0; i < size; i++)
89   {
90         SCRUTE(P2[i]);
91         SCRUTE(P3[i]);
92   }
93
94   const PointerOf<int> P4(p);
95   const PointerOf<int> P5(P4);
96   delete [] p;
97   
98 }