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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3597 - (show annotations)
Thu Sep 15 06:03:17 2011 UTC (7 years, 7 months ago) by caltinay
File size: 4739 byte(s)
Switching to external cppunit:
-removed tools/CppUnitTest
-updated scons script and files
-updated tests to changed API
-updated readme

Bumped scons options file version to 201. Additions:
-cppunit*
-boomeramg*
-vsl_random


1 /*******************************************************
2 *
3 * Copyright (c) 2003-2010 by University of Queensland
4 * Earth Systems Science Computational Center (ESSCC)
5 * http://www.uq.edu.au/esscc
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Open Software License version 3.0
9 * http://www.opensource.org/licenses/osl-3.0.php
10 *
11 *******************************************************/
12
13 // The purpose of these tests is to check for unwanted sharing of between Data objects
14
15 #include "SharedDataTestCase.h"
16 #include "escript/Data.h"
17 #include "escript/EscriptParams.h"
18
19 #include <cppunit/TestCaller.h>
20 #include <iostream>
21
22 using namespace escript;
23 using namespace std;
24 using namespace CppUnit;
25 using namespace escript::DataTypes;
26
27 // 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);}
30
31 // Test if the copy constructor shares a DataAbstract with its originator
32 void SharedDataTestCase::testEQ()
33 {
34 cout << endl << "Testing +=" << flush;
35 TESTEQOP(+=)
36 cout << "\tOK" << endl << "Testing -=";
37 TESTEQOP(-=)
38 cout << "\tOK" << endl << "Testing *=";
39 TESTEQOP(*=)
40 cout << "\tOK" << endl << "Testing /=";
41 TESTEQOP(/=)
42 }
43
44 // Test for shared data caused by using a copy constructor
45 void SharedDataTestCase::testCC()
46 {
47 cout << endl;
48 Data d(42, DataTypes::scalarShape);
49 Data shared(d);
50 d+=Data(20,DataTypes::scalarShape);
51 shared-=Data(42,DataTypes::scalarShape);
52 CPPUNIT_ASSERT(shared.Lsup()<0.001);
53 }
54
55 // Test for shared data caused by using = operator
56 void SharedDataTestCase::testAssign()
57 {
58 cout << endl;
59 Data d(42, DataTypes::scalarShape);
60 Data shared=d;
61 d+=Data(20,DataTypes::scalarShape);
62 shared-=Data(42,DataTypes::scalarShape);
63 CPPUNIT_ASSERT(shared.Lsup()<0.001);
64 }
65
66 void SharedDataTestCase::testSetToZero()
67 {
68 Data d((double)42,DataTypes::scalarShape);
69 Data L=d.delay();
70 L-=Data((double)42,DataTypes::scalarShape);
71 d.setToZero();
72 CPPUNIT_ASSERT(L.Lsup()<0.001);
73 }
74
75 void SharedDataTestCase::testSetTaggedValueFromCPP()
76 {
77 Data d((double)42,DataTypes::scalarShape);
78 d.tag();
79 Data L=d.delay();
80 ValueType v(1,17);
81 d.setTaggedValueFromCPP(1,DataTypes::scalarShape,v);
82 L.resolve();
83 // 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
85 string s=L.toString();
86 CPPUNIT_ASSERT(s.find("Tag(1)")==string::npos); // if the tag shows up we have shared data
87 }
88
89 void SharedDataTestCase::testGetDataAtOffset()
90 {
91 Data d((double)42,DataTypes::scalarShape);
92 Data L=d.delay();
93 // now change the data directly
94 d.requireWrite();
95 d.getDataAtOffsetRW(0)=17;
96 CPPUNIT_ASSERT(L.getDataAtOffsetRO(0)==42);
97 }
98
99 void SharedDataTestCase::testGetDataPoint()
100 {
101 Data d((double)42,DataTypes::scalarShape);
102 Data L=d.delay();
103 // now change the data directly
104 d.requireWrite();
105 d.getDataPointRW(0,0)=17;
106 CPPUNIT_ASSERT(L.getDataPointRO(0,0)==42);
107 }
108
109 void SharedDataTestCase::testGetSampleRW()
110 {
111 Data d((double)42,DataTypes::scalarShape);
112 Data L=d.delay();
113 // now change the data directly
114 CPPUNIT_ASSERT_THROW(*d.getSampleDataRW(0)=17, DataException);
115 // Now try again properly
116 d.requireWrite();
117 *d.getSampleDataRW(0)=17;
118 L.resolve();
119 CPPUNIT_ASSERT(*L.getSampleDataRO(0)==42);
120 }
121
122 TestSuite* SharedDataTestCase::suite()
123 {
124 // create the suite of tests to perform.
125 TestSuite *testSuite = new TestSuite("SharedDataTestCase");
126
127 testSuite->addTest(new TestCaller<SharedDataTestCase>(
128 "Arithmetic Assignment operators",&SharedDataTestCase::testEQ));
129 testSuite->addTest(new TestCaller<SharedDataTestCase>(
130 "Copy Constructor",&SharedDataTestCase::testCC));
131 testSuite->addTest(new TestCaller<SharedDataTestCase>(
132 "Assignment operator",&SharedDataTestCase::testAssign));
133 testSuite->addTest(new TestCaller<SharedDataTestCase>(
134 "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;
144 }
145

  ViewVC Help
Powered by ViewVC 1.1.26