Back to index

salome-med  6.5.0
testUPointerOf.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 //  File   : testUPointerOf.cxx
00021 //  Module : MED
00022 //
00023 #include "MEDMEM_Utilities.hxx"
00024 #include "MEDMEM_PointerOf.hxx"
00025 #include "MEDMEM_Exception.hxx"
00026 
00027 using namespace std;
00028 using namespace MEDMEM;
00029 
00030 
00031 int main (int argc, char ** argv) 
00032 {
00033   cout << "PointerOf Test" << endl ;
00034   cout << "--------------" << endl;
00035 
00036   const int size=10;
00037   PointerOf<int> P;
00038 
00039   // Creation d'un PointerOf de int
00040   // et vérification de la methode set en essayant avec 
00041   // une taille nulle, négative puis positive
00042   try
00043   {
00044         P.set(0);
00045         ASSERT_MED((int *)P == NULL);
00046   }
00047   catch ( const std::exception &e )
00048   {
00049         cout << "-------------------------" << endl;
00050         cout << " pb avec set(taille = 0) " << endl;
00051         cout << "-------------------------" << endl;
00052         MESSAGE_MED( "catched exception : " << e.what() ) ;
00053         return EXIT_FAILURE ;
00054   }
00055 
00056   try
00057   {
00058         P.set(-1 * size);
00059         ASSERT_MED((int *)P == NULL);
00060   }
00061   catch ( const std::exception &e )
00062   {
00063         cout << "---------------------" << endl;
00064         cout << " pb avec set(taille) " << endl;
00065         cout << "---------------------" << endl;
00066         MESSAGE_MED( "catched exception : " << e.what() ) ;
00067         return EXIT_FAILURE ;
00068   }
00069 
00070   try
00071   {
00072         P.set(size);
00073         ASSERT_MED((int *)P != NULL);
00074   }
00075   catch ( const std::exception &e )
00076   {
00077         cout << "---------------------" << endl;
00078         cout << " pb avec set(taille) " << endl;
00079         cout << "---------------------" << endl;
00080         MESSAGE_MED( "catched exception : " << e.what() ) ;
00081         return EXIT_FAILURE ;
00082   }
00083   for (int i=0; i < size; i++)
00084   {
00085         P[i]=i;
00086   }
00087 
00088   PointerOf<int> P2(10);
00089 
00090   P2=P;
00091   for (int i=0; i < size; i++)
00092   {
00093         SCRUTE_MED(P2[i]);
00094   }
00095 
00096   int * p=new int [size];
00097   for (int i=0; i < size; i++)
00098   {
00099         p[i]=i*10;
00100   }
00101   
00102   P2.set(p);
00103   PointerOf<int> P3(p);
00104 
00105   for (int i=0; i < size; i++)
00106   {
00107         SCRUTE_MED(P2[i]);
00108         SCRUTE_MED(P3[i]);
00109   }
00110 
00111   const PointerOf<int> P4(p);
00112   const PointerOf<int> P5(P4);
00113   delete [] p;
00114   
00115 }