Salome HOME
correct small problem from the version in the MedFileV2_2 branch.
[modules/med.git] / src / MEDMEM / tests / testUSkyLineArray.cxx
1 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
3 // 
4 //  This library is free software; you can redistribute it and/or 
5 //  modify it under the terms of the GNU Lesser General Public 
6 //  License as published by the Free Software Foundation; either 
7 //  version 2.1 of the License. 
8 // 
9 //  This library is distributed in the hope that it will be useful, 
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 //  Lesser General Public License for more details. 
13 // 
14 //  You should have received a copy of the GNU Lesser General Public 
15 //  License along with this library; if not, write to the Free Software 
16 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
17 // 
18 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
19 //
20 //
21 //
22 //  File   : testUSkyLineArray.cxx
23 //  Module : MED
24
25 using namespace std;
26 #include <cstdlib>
27 #include "utilities.h"
28 #include "MEDMEM_SkyLineArray.hxx"
29 using namespace MEDMEM;
30
31 int main (int argc, char ** argv)
32 {
33
34   int NumberOfCell = 3 ; // 1 triangle,1 quadrangle,1 triangle
35   int Size = 10 ;        // 10 nodes
36
37   int * index = new int[NumberOfCell+1];
38   index[0]=1;
39   index[1]=4;
40   index[2]=8;
41   index[3]=11;
42
43   int * value = new int[Size];
44   value[0]=1; // first
45   value[1]=2;
46   value[2]=5;
47   value[3]=2; // second
48   value[4]=3;
49   value[5]=5;
50   value[6]=6;
51   value[7]=3; // thirst
52   value[8]=4;
53   value[9]=6;
54
55   MEDSKYLINEARRAY * myArray = new MEDSKYLINEARRAY(NumberOfCell,Size,index,value) ;
56
57   const int * ArrayIndex ;
58   try
59   {
60         ArrayIndex = myArray->getIndex() ;
61   }
62   catch ( const std::exception &e )
63   {
64         cout << "----------------" << endl;
65         cout << "pb avec getIndex" << endl;
66         cout << "----------------" << endl;
67         MESSAGE( "catched exception : " << e.what() ) ;
68         return EXIT_FAILURE ;
69   }
70   catch (...)
71   {
72         cout << "----------------" << endl;
73         cout << "pb avec getIndex" << endl;
74         cout << "----------------" << endl;
75         return EXIT_FAILURE ;
76   }
77
78   const int * ArrayValue ;
79   try
80   {
81         ArrayValue  = myArray->getValue() ;
82   }
83   catch ( const std::exception &e )
84   {
85         cout << "----------------" << endl;
86         cout << "pb avec getValue" << endl;
87         cout << "----------------" << endl;
88         MESSAGE( "catched exception : " << e.what() ) ;
89         return EXIT_FAILURE ;
90   }
91   catch (...)
92   {
93         cout << "----------------" << endl;
94         cout << "pb avec getValue" << endl;
95         cout << "----------------" << endl;
96         return EXIT_FAILURE ;
97   }
98
99
100   try
101   {
102         ASSERT(myArray->getNumberOf()==NumberOfCell);
103         cout << myArray->getNumberOf() << endl;
104   }
105   catch ( const std::exception &e )
106   {
107         cout << "-------------------" << endl;
108         cout << "pb avec getNumberOf" << endl;
109         cout << "-------------------" << endl;
110         MESSAGE( "catched exception : " << e.what() ) ;
111         return EXIT_FAILURE ;
112   }
113   catch (...)
114   {
115         cout << "-------------------" << endl;
116         cout << "pb avec getNumberOf" << endl;
117         cout << "-------------------" << endl;
118         return EXIT_FAILURE ;
119   }
120
121   try
122   {
123         ASSERT(myArray->getLength()==Size);
124         cout << myArray->getLength() << endl; 
125   }
126   catch ( const std::exception &e )
127   {
128         cout << "-------------------" << endl;
129         cout << "pb avec getLength" << endl;
130         cout << "-------------------" << endl;
131         MESSAGE( "catched exception : " << e.what() ) ;
132         return EXIT_FAILURE ;
133   }
134   catch (...)
135   {
136         cout << "-------------------" << endl;
137         cout << "pb avec getLength" << endl;
138         cout << "-------------------" << endl;
139         return EXIT_FAILURE ;
140   }
141
142   cout << "Show all :" << endl ;
143   for (int i=1; i< NumberOfCell+1 ; i++) 
144   {
145     const int * cell;
146     try
147     {
148         cell = myArray->getI(i) ;
149     }
150     catch ( const std::exception &e )
151     {
152         cout << "-----------------------------" << endl;
153         cout << "pb avec getI, valeur de i : " << i << endl;
154         cout << "-----------------------------" << endl;
155         MESSAGE( "catched exception : " << e.what() ) ;
156         return EXIT_FAILURE ;
157     }
158     catch (...)
159     {
160         cout << "-------------------" << endl;
161         cout << "pb avec getI, valeur de i : " << i << endl;
162         cout << "-------------------" << endl;
163         return EXIT_FAILURE ;
164     }
165
166     int numberof;
167     try
168     {
169         numberof= myArray->getNumberOfI(i) ;
170         ASSERT(numberof==index[i]-index[i-1]);
171     }
172     catch ( const std::exception &e )
173     {
174         cout << "----------------------------------" << endl;
175         cout << "pb avec getNumberOfI, valeur de i : " << i << endl;
176         cout << "----------------------------------" << endl;
177         MESSAGE( "catched exception : " << e.what() ) ;
178         return EXIT_FAILURE ;
179     }
180     catch (...)
181     {
182         cout << "----------------------------------" << endl;
183         cout << "pb avec getNumberOfI, valeur de i : " << i << endl;
184         cout << "----------------------------------" << endl;
185         return EXIT_FAILURE ;
186     }
187
188     cout << " - " ;
189     for (int j=0;j<numberof;j++)
190     {
191         cout << cell[j] << " " ;
192         try
193         {
194                 int verif=myArray->getIJ(i,j+1);
195                 if (verif != cell[j])
196                 {
197                         cout << "----------------------------------" << endl;
198                         cout << " incoherence dans les valeurs :   " << endl;
199                         cout << " cell[" << j << "] : " << cell[j] << endl;
200                         cout << " getIJ(" << i <<"," << j << ") : " << verif << endl;
201                         cout << "----------------------------------" << endl;
202                         return EXIT_FAILURE ;
203                 }
204         }
205         catch ( const std::exception &e )
206         {
207                 cout << "----------------------------------" << endl;
208                 cout << "pb avec getIJ, valeurs de i / j : " << i << " " << j<< endl;
209                 cout << "----------------------------------" << endl;
210                 MESSAGE( "catched exception : " << e.what() ) ;
211                 return EXIT_FAILURE ;
212         }
213         catch (...)
214         {
215                 cout << "----------------------------------" << endl;
216                 cout << "pb avec getIJ, valeurs de i / j : " << i << " " << j<< endl;
217                 cout << "----------------------------------" << endl;
218                 return EXIT_FAILURE ;
219         }
220     }
221     cout << endl ;
222   }
223
224   delete[] index ;
225   delete[] value ;
226
227   delete myArray;
228   MESSAGE("FIN normale du traitement");
229   return EXIT_SUCCESS ;
230
231
232 /*
233   MEDSKYLINEARRAY( const MEDSKYLINEARRAY &myArray );
234   void setMEDSKYLINEARRAY( const med_int count, const med_int length, med_int* index , med_int* value ) ;
235
236   
237 */
238 }