Salome HOME
Final version of the V2_2_0 in the main trunk of the CVS tree.
[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 #include <cstdlib>
26 #include "utilities.h"
27 #include "MEDMEM_SkyLineArray.hxx"
28
29 using namespace std;
30 using namespace MEDMEM;
31
32 int main (int argc, char ** argv)
33 {
34
35   int NumberOfCell = 3 ; // 1 triangle,1 quadrangle,1 triangle
36   int Size = 10 ;        // 10 nodes
37
38   int * index = new int[NumberOfCell+1];
39   index[0]=1;
40   index[1]=4;
41   index[2]=8;
42   index[3]=11;
43
44   int * value = new int[Size];
45   value[0]=1; // first
46   value[1]=2;
47   value[2]=5;
48   value[3]=2; // second
49   value[4]=3;
50   value[5]=5;
51   value[6]=6;
52   value[7]=3; // thirst
53   value[8]=4;
54   value[9]=6;
55
56   MEDSKYLINEARRAY * myArray = new MEDSKYLINEARRAY(NumberOfCell,Size,index,value) ;
57
58   const int * ArrayIndex ;
59   try
60   {
61         ArrayIndex = myArray->getIndex() ;
62   }
63   catch ( const std::exception &e )
64   {
65         cout << "----------------" << endl;
66         cout << "pb avec getIndex" << endl;
67         cout << "----------------" << endl;
68         MESSAGE( "catched exception : " << e.what() ) ;
69         return EXIT_FAILURE ;
70   }
71   catch (...)
72   {
73         cout << "----------------" << endl;
74         cout << "pb avec getIndex" << endl;
75         cout << "----------------" << endl;
76         return EXIT_FAILURE ;
77   }
78
79   const int * ArrayValue ;
80   try
81   {
82         ArrayValue  = myArray->getValue() ;
83   }
84   catch ( const std::exception &e )
85   {
86         cout << "----------------" << endl;
87         cout << "pb avec getValue" << endl;
88         cout << "----------------" << endl;
89         MESSAGE( "catched exception : " << e.what() ) ;
90         return EXIT_FAILURE ;
91   }
92   catch (...)
93   {
94         cout << "----------------" << endl;
95         cout << "pb avec getValue" << endl;
96         cout << "----------------" << endl;
97         return EXIT_FAILURE ;
98   }
99
100
101   try
102   {
103         ASSERT(myArray->getNumberOf()==NumberOfCell);
104         cout << myArray->getNumberOf() << endl;
105   }
106   catch ( const std::exception &e )
107   {
108         cout << "-------------------" << endl;
109         cout << "pb avec getNumberOf" << endl;
110         cout << "-------------------" << endl;
111         MESSAGE( "catched exception : " << e.what() ) ;
112         return EXIT_FAILURE ;
113   }
114   catch (...)
115   {
116         cout << "-------------------" << endl;
117         cout << "pb avec getNumberOf" << endl;
118         cout << "-------------------" << endl;
119         return EXIT_FAILURE ;
120   }
121
122   try
123   {
124         ASSERT(myArray->getLength()==Size);
125         cout << myArray->getLength() << endl; 
126   }
127   catch ( const std::exception &e )
128   {
129         cout << "-------------------" << endl;
130         cout << "pb avec getLength" << endl;
131         cout << "-------------------" << endl;
132         MESSAGE( "catched exception : " << e.what() ) ;
133         return EXIT_FAILURE ;
134   }
135   catch (...)
136   {
137         cout << "-------------------" << endl;
138         cout << "pb avec getLength" << endl;
139         cout << "-------------------" << endl;
140         return EXIT_FAILURE ;
141   }
142
143   cout << "Show all :" << endl ;
144   for (int i=1; i< NumberOfCell+1 ; i++) 
145   {
146     const int * cell;
147     try
148     {
149         cell = myArray->getI(i) ;
150     }
151     catch ( const std::exception &e )
152     {
153         cout << "-----------------------------" << endl;
154         cout << "pb avec getI, valeur de i : " << i << endl;
155         cout << "-----------------------------" << endl;
156         MESSAGE( "catched exception : " << e.what() ) ;
157         return EXIT_FAILURE ;
158     }
159     catch (...)
160     {
161         cout << "-------------------" << endl;
162         cout << "pb avec getI, valeur de i : " << i << endl;
163         cout << "-------------------" << endl;
164         return EXIT_FAILURE ;
165     }
166
167     int numberof;
168     try
169     {
170         numberof= myArray->getNumberOfI(i) ;
171         ASSERT(numberof==index[i]-index[i-1]);
172     }
173     catch ( const std::exception &e )
174     {
175         cout << "----------------------------------" << endl;
176         cout << "pb avec getNumberOfI, valeur de i : " << i << endl;
177         cout << "----------------------------------" << endl;
178         MESSAGE( "catched exception : " << e.what() ) ;
179         return EXIT_FAILURE ;
180     }
181     catch (...)
182     {
183         cout << "----------------------------------" << endl;
184         cout << "pb avec getNumberOfI, valeur de i : " << i << endl;
185         cout << "----------------------------------" << endl;
186         return EXIT_FAILURE ;
187     }
188
189     cout << " - " ;
190     for (int j=0;j<numberof;j++)
191     {
192         cout << cell[j] << " " ;
193         try
194         {
195                 int verif=myArray->getIJ(i,j+1);
196                 if (verif != cell[j])
197                 {
198                         cout << "----------------------------------" << endl;
199                         cout << " incoherence dans les valeurs :   " << endl;
200                         cout << " cell[" << j << "] : " << cell[j] << endl;
201                         cout << " getIJ(" << i <<"," << j << ") : " << verif << endl;
202                         cout << "----------------------------------" << endl;
203                         return EXIT_FAILURE ;
204                 }
205         }
206         catch ( const std::exception &e )
207         {
208                 cout << "----------------------------------" << endl;
209                 cout << "pb avec getIJ, valeurs de i / j : " << i << " " << j<< endl;
210                 cout << "----------------------------------" << endl;
211                 MESSAGE( "catched exception : " << e.what() ) ;
212                 return EXIT_FAILURE ;
213         }
214         catch (...)
215         {
216                 cout << "----------------------------------" << endl;
217                 cout << "pb avec getIJ, valeurs de i / j : " << i << " " << j<< endl;
218                 cout << "----------------------------------" << endl;
219                 return EXIT_FAILURE ;
220         }
221     }
222     cout << endl ;
223   }
224
225   delete[] index ;
226   delete[] value ;
227
228   delete myArray;
229   MESSAGE("FIN normale du traitement");
230   return EXIT_SUCCESS ;
231
232
233 /*
234   MEDSKYLINEARRAY( const MEDSKYLINEARRAY &myArray );
235   void setMEDSKYLINEARRAY( const med_int count, const med_int length, med_int* index , med_int* value ) ;
236
237   
238 */
239 }