/[escript]/trunk/escript/test/SharedDataTestCase.cpp
ViewVC logotype

Diff of /trunk/escript/test/SharedDataTestCase.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3596 by jfenwick, Thu Jan 28 02:03:15 2010 UTC revision 3597 by caltinay, Thu Sep 15 06:03:17 2011 UTC
# Line 12  Line 12 
12    
13  // The purpose of these tests is to check for unwanted sharing of between Data objects  // The purpose of these tests is to check for unwanted sharing of between Data objects
14    
   
15  #include "SharedDataTestCase.h"  #include "SharedDataTestCase.h"
16  #include "escript/Data.h"  #include "escript/Data.h"
17  #include "escript/EscriptParams.h"  #include "escript/EscriptParams.h"
18    
19    #include <cppunit/TestCaller.h>
20  #include <iostream>  #include <iostream>
21    
22  using namespace escript;  using namespace escript;
23  using namespace std;  using namespace std;
24  using namespace CppUnitTest;  using namespace CppUnit;
25  using namespace escript::DataTypes;  using namespace escript::DataTypes;
26    
27  void SharedDataTestCase::setUp()  // Create a data, involve it in a lazy expression. Then modify the original
28  {  // and see if the value of the lazy is affected.
29    //  #define TESTEQOP(OP) { Data d((double)42,DataTypes::scalarShape); Data L=d.delay(); L-=Data((double)42,DataTypes::scalarShape); d OP Data(2,DataTypes::scalarShape); CPPUNIT_ASSERT(L.Lsup()<0.001);}
   // This is called before each test is run  
 }  
   
 void SharedDataTestCase::tearDown()  
 {  
   //  
   // This is called after each test has been run  
 }  
   
 // Create a data, involve it in a lazy expression. Then modify the original and see if the value of the lazy is affected.  
 #define TESTEQOP(OP) { Data d((double)42,DataTypes::scalarShape); Data L=d.delay(); L-=Data((double)42,DataTypes::scalarShape); d OP Data(2,DataTypes::scalarShape); assert(L.Lsup()<0.001);}  
30    
31  // Test if the copy constructor shares a DataAbstract with its originator  // Test if the copy constructor shares a DataAbstract with its originator
32  void SharedDataTestCase::testEQ()  void SharedDataTestCase::testEQ()
# Line 60  void SharedDataTestCase::testCC() Line 49  void SharedDataTestCase::testCC()
49    Data shared(d);    Data shared(d);
50    d+=Data(20,DataTypes::scalarShape);    d+=Data(20,DataTypes::scalarShape);
51    shared-=Data(42,DataTypes::scalarShape);    shared-=Data(42,DataTypes::scalarShape);
52    assert(shared.Lsup()<0.001);    CPPUNIT_ASSERT(shared.Lsup()<0.001);
53  }  }
54    
55  // Test for shared data caused by using = operator  // Test for shared data caused by using = operator
# Line 71  void SharedDataTestCase::testAssign() Line 60  void SharedDataTestCase::testAssign()
60    Data shared=d;    Data shared=d;
61    d+=Data(20,DataTypes::scalarShape);    d+=Data(20,DataTypes::scalarShape);
62    shared-=Data(42,DataTypes::scalarShape);    shared-=Data(42,DataTypes::scalarShape);
63    assert(shared.Lsup()<0.001);    CPPUNIT_ASSERT(shared.Lsup()<0.001);
64  }  }
65    
66  void SharedDataTestCase::testSetToZero()  void SharedDataTestCase::testSetToZero()
# Line 80  void SharedDataTestCase::testSetToZero() Line 69  void SharedDataTestCase::testSetToZero()
69    Data L=d.delay();    Data L=d.delay();
70    L-=Data((double)42,DataTypes::scalarShape);    L-=Data((double)42,DataTypes::scalarShape);
71    d.setToZero();    d.setToZero();
72    assert(L.Lsup()<0.001);    CPPUNIT_ASSERT(L.Lsup()<0.001);
73  }  }
74    
75  void SharedDataTestCase::testSetTaggedValueFromCPP()  void SharedDataTestCase::testSetTaggedValueFromCPP()
# Line 94  void SharedDataTestCase::testSetTaggedVa Line 83  void SharedDataTestCase::testSetTaggedVa
83    // at this point, d should have a tag and L should not    // at this point, d should have a tag and L should not
84    // unfortunately its a little tricky to find out what tags a Data object has so I'll use strings    // unfortunately its a little tricky to find out what tags a Data object has so I'll use strings
85    string s=L.toString();    string s=L.toString();
86    assert(s.find("Tag(1)")==string::npos);       // if the tag shows up we have shared data    CPPUNIT_ASSERT(s.find("Tag(1)")==string::npos);       // if the tag shows up we have shared data
87  }  }
88    
89  void SharedDataTestCase::testGetDataAtOffset()  void SharedDataTestCase::testGetDataAtOffset()
# Line 104  void SharedDataTestCase::testGetDataAtOf Line 93  void SharedDataTestCase::testGetDataAtOf
93    // now change the data directly    // now change the data directly
94    d.requireWrite();    d.requireWrite();
95    d.getDataAtOffsetRW(0)=17;    d.getDataAtOffsetRW(0)=17;
96    assert(L.getDataAtOffsetRO(0)==42);    CPPUNIT_ASSERT(L.getDataAtOffsetRO(0)==42);
97  }  }
98    
99  void SharedDataTestCase::testGetDataPoint()  void SharedDataTestCase::testGetDataPoint()
# Line 114  void SharedDataTestCase::testGetDataPoin Line 103  void SharedDataTestCase::testGetDataPoin
103    // now change the data directly    // now change the data directly
104    d.requireWrite();    d.requireWrite();
105    d.getDataPointRW(0,0)=17;    d.getDataPointRW(0,0)=17;
106    assert(L.getDataPointRO(0,0)==42);    CPPUNIT_ASSERT(L.getDataPointRO(0,0)==42);
107  }  }
108    
109  void SharedDataTestCase::testGetSampleRW()  void SharedDataTestCase::testGetSampleRW()
# Line 122  void SharedDataTestCase::testGetSampleRW Line 111  void SharedDataTestCase::testGetSampleRW
111    Data d((double)42,DataTypes::scalarShape);    Data d((double)42,DataTypes::scalarShape);
112    Data L=d.delay();    Data L=d.delay();
113    // now change the data directly    // now change the data directly
114    try    CPPUNIT_ASSERT_THROW(*d.getSampleDataRW(0)=17, DataException);
   {  
     *d.getSampleDataRW(0)=17;  
     assert(false);          // should have thrown  
   } catch (DataException e)  
   {  
   }  
115    // Now try again properly    // Now try again properly
116    d.requireWrite();    d.requireWrite();
117    *d.getSampleDataRW(0)=17;    *d.getSampleDataRW(0)=17;
118    L.resolve();    L.resolve();
119    assert(*L.getSampleDataRO(0)==42);    CPPUNIT_ASSERT(*L.getSampleDataRO(0)==42);
120  }  }
121    
122  TestSuite* SharedDataTestCase::suite ()  TestSuite* SharedDataTestCase::suite()
123  {  {
   //  
124    // create the suite of tests to perform.    // create the suite of tests to perform.
125    TestSuite *testSuite = new TestSuite ("SharedDataTestCase");    TestSuite *testSuite = new TestSuite("SharedDataTestCase");
126    
127    testSuite->addTest (new TestCaller< SharedDataTestCase>("Arithmetic Assignment operators",&SharedDataTestCase::testEQ));    testSuite->addTest(new TestCaller<SharedDataTestCase>(
128    testSuite->addTest (new TestCaller< SharedDataTestCase>("Copy Constructor",&SharedDataTestCase::testCC));                "Arithmetic Assignment operators",&SharedDataTestCase::testEQ));
129    testSuite->addTest (new TestCaller< SharedDataTestCase>("Assignment operator",&SharedDataTestCase::testAssign));    testSuite->addTest(new TestCaller<SharedDataTestCase>(
130    testSuite->addTest (new TestCaller< SharedDataTestCase>("setToZero",&SharedDataTestCase::testSetToZero));                "Copy Constructor",&SharedDataTestCase::testCC));
131    testSuite->addTest (new TestCaller< SharedDataTestCase>("setTaggedValueFromCPP",&SharedDataTestCase::testSetTaggedValueFromCPP));    testSuite->addTest(new TestCaller<SharedDataTestCase>(
132    testSuite->addTest (new TestCaller< SharedDataTestCase>("getDataAtOffset",&SharedDataTestCase::testGetDataAtOffset));                "Assignment operator",&SharedDataTestCase::testAssign));
133    testSuite->addTest (new TestCaller< SharedDataTestCase>("getDataPoint",&SharedDataTestCase::testGetDataPoint));    testSuite->addTest(new TestCaller<SharedDataTestCase>(
134    testSuite->addTest (new TestCaller< SharedDataTestCase>("getSampleRW",&SharedDataTestCase::testGetSampleRW));                "setToZero",&SharedDataTestCase::testSetToZero));
135      testSuite->addTest(new TestCaller<SharedDataTestCase>(
136                  "setTaggedValueFromCPP",&SharedDataTestCase::testSetTaggedValueFromCPP));
137      testSuite->addTest(new TestCaller<SharedDataTestCase>(
138                  "getDataAtOffset",&SharedDataTestCase::testGetDataAtOffset));
139      testSuite->addTest(new TestCaller<SharedDataTestCase>(
140                  "getDataPoint",&SharedDataTestCase::testGetDataPoint));
141      testSuite->addTest(new TestCaller<SharedDataTestCase>(
142                  "getSampleRW",&SharedDataTestCase::testGetSampleRW));
143    return testSuite;    return testSuite;
144  }  }
145    

Legend:
Removed from v.3596  
changed lines
  Added in v.3597

  ViewVC Help
Powered by ViewVC 1.1.26