1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include "MEDMEMTest.hxx"
23 #include "MEDMEM_PointerOf.hxx"
24 #include "MEDMEM_define.hxx"
26 #include <cppunit/TestAssert.h>
31 // use this define to enable lines, execution of which leads to Segmentation Fault
32 //#define ENABLE_FAULTS
34 // use this define to enable CPPUNIT asserts and fails, showing bugs
35 //#define ENABLE_FORCED_FAILURES
38 using namespace MEDMEM;
41 * Check methods (12), defined in MEDMEM_PointerOf.hxx:
42 * template <typename T> class PointerOf {
45 * (+) PointerOf(const int &size);
46 * (+) PointerOf(const T *pointer);
47 * (+) PointerOf(const int &size, const T *pointer);
48 * (+) PointerOf(const PointerOf<T> & pointerOf);
49 * (NOT COMPILABLE!!!) PointerOf(const int &size, const PointerOf<T> & pointerOf);
51 * (+) operator const T*() const;
52 * (+) void set(const int &size);
53 * (+) void set(const T *pointer);
54 * (+) void set(const int &size, const T *pointer);
55 * (+) void setShallowAndOwnership(const T *pointer);
56 * (+) PointerOf<T>& operator=(const PointerOf<T> &pointer);
60 void MEDMEMTest::testPointerOf()
68 CPPUNIT_ASSERT((int *)P == NULL);
70 catch ( const std::exception &e )
72 CPPUNIT_FAIL(e.what());
78 CPPUNIT_ASSERT((int *)P == NULL);
80 catch ( const std::exception &e )
82 CPPUNIT_FAIL(e.what());
88 CPPUNIT_ASSERT((int *)P != NULL);
90 catch ( const std::exception &e )
92 CPPUNIT_FAIL(e.what());
95 for (int i=0; i < size; i++)
100 PointerOf<int> P2(10);
103 for (int i=0; i < size; i++)
108 int * p=new int [size];
109 for (int i=0; i < size; i++)
115 PointerOf<int> P3(p);
117 for (int i=0; i < size; i++)
119 CPPUNIT_ASSERT_EQUAL(P2[i],P3[i]);
122 const PointerOf<int> P4(p);
123 for (int i=0; i < size; i++)
125 CPPUNIT_ASSERT_EQUAL(P4[i],p[i]);
128 const PointerOf<int> P5(P4);
129 CPPUNIT_ASSERT((const int*)P5 != NULL);
131 const PointerOf<int> P7(10, p);
134 //#ifdef ENABLE_COMPILATION_ERRORS
135 //PointerOf<int> PP1 (10, p);
136 //PointerOf<int> PP2 (10, PP1);
138 //#ifdef ENABLE_FORCED_FAILURES
139 //CPPUNIT_FAIL("Can not create: PointerOf(const int &size, const PointerOf<T> & pointerOf)");
143 //CPPUNIT_ASSERT_THROW(P3.set(0, p),MEDEXCEPTION);
144 CPPUNIT_ASSERT_NO_THROW(P3.set(0, p));
146 P.setShallowAndOwnership( p );
147 for (int i=0; i < size; i++)
149 CPPUNIT_ASSERT_EQUAL(P[i],p[i]);
152 //delete [] p; not needed - P already owns p and will delete it when the scope is over