Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/med.git] / src / MEDMEMCppTest / MEDMEMTest_MedVersion.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 #include "MEDMEMTest.hxx"
23 #include <cppunit/TestAssert.h>
24
25 #include <cstdlib>
26 #include <exception>
27
28 #include <MEDMEM_MedVersion.hxx>
29 #include "MEDMEM_Compatibility21_22.hxx"
30
31 using namespace std;
32 using namespace MEDMEM;
33 using namespace MED_EN;
34
35 /*!
36  *  Check methods (not in spec), defined in MEDMEM_MedVersion.hxx:
37  *  (+) MED_EN::medFileVersion getMedFileVersion(const string & fileName) throw (MEDEXCEPTION);
38  *  (+) int getMedAccessMode(MED_EN::med_mode_acces mode,
39  *                               MED_EN::medFileVersion medVersion) throw (MEDEXCEPTION);
40  */
41
42 void MEDMEMTest::testMedVersion()
43 {
44   string filename = getenv("MED_ROOT_DIR");
45   filename += "/share/salome/resources/med/pointe.med";
46   string notExistFileName = "anyfile";
47   medFileVersion myFileVersion;
48   medFileVersion myEmptyFileVersion;
49
50   // Test - getMedFileVersion
51   CPPUNIT_ASSERT_THROW(getMedFileVersion(notExistFileName),MEDEXCEPTION);
52
53   try
54   {
55     myFileVersion = getMedFileVersion(filename);
56     CPPUNIT_ASSERT(myFileVersion == V21);
57   }
58   catch(MEDEXCEPTION &e)
59   {
60     CPPUNIT_FAIL(e.what());
61   }
62   catch(...)
63   {
64     CPPUNIT_FAIL("Unknown exception");
65   }
66
67   //Test - getMedAccessMode
68   CPPUNIT_ASSERT_THROW(getMedAccessMode(RDWR,myEmptyFileVersion),MEDEXCEPTION);
69
70   try
71   {
72     CPPUNIT_ASSERT_EQUAL(med_2_1::MED_ECRI/*REMP*/,
73                          (med_2_1::med_mode_acces)getMedAccessMode(RDWR,myFileVersion));
74   }
75   catch(MEDEXCEPTION &e)
76   {
77     CPPUNIT_FAIL(e.what());
78   }
79   catch(...)
80   {
81     CPPUNIT_FAIL("Unknown exception");
82   }
83 }