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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2222 - (hide annotations)
Tue Jan 20 04:52:39 2009 UTC (10 years, 10 months ago) by jfenwick
Original Path: branches/arrexp_2137_win_merge/escript/test/SharedDataTestCase.cpp
File size: 4733 byte(s)
Saving work
1 jfenwick 2212 /*******************************************************
2     *
3     * Copyright (c) 2003-2008 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    
16     #include "SharedDataTestCase.h"
17     #include "escript/Data.h"
18     #include "escript/EscriptParams.h"
19    
20     #include <iostream>
21    
22     using namespace escript;
23     using namespace std;
24     using namespace CppUnitTest;
25     using namespace escript::DataTypes;
26    
27     void SharedDataTestCase::setUp()
28     {
29     //
30     // This is called before each test is run
31     }
32    
33     void SharedDataTestCase::tearDown()
34     {
35     //
36     // This is called after each test has been run
37     }
38    
39     // Create a data, involve it in a lazy expression. Then modify the original and see if the value of the lazy is affected.
40     #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);}
41    
42     // Test if the copy constructor shares a DataAbstract with its originator
43     void SharedDataTestCase::testEQ()
44     {
45     cout << endl << "Testing +=" << flush;
46     TESTEQOP(+=)
47     cout << "\tOK" << endl << "Testing -=";
48     TESTEQOP(-=)
49     cout << "\tOK" << endl << "Testing *=";
50     TESTEQOP(*=)
51     cout << "\tOK" << endl << "Testing /=";
52     TESTEQOP(/=)
53     }
54    
55     // Test for shared data caused by using a copy constructor
56     void SharedDataTestCase::testCC()
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     assert(shared.Lsup()<0.001);
64     }
65    
66     // Test for shared data caused by using = operator
67     void SharedDataTestCase::testAssign()
68     {
69     cout << endl;
70     Data d(42, DataTypes::scalarShape);
71     Data shared=d;
72     d+=Data(20,DataTypes::scalarShape);
73     shared-=Data(42,DataTypes::scalarShape);
74     assert(shared.Lsup()<0.001);
75     }
76    
77     void SharedDataTestCase::testSetToZero()
78     {
79     Data d((double)42,DataTypes::scalarShape);
80     Data L=d.delay();
81     L-=Data((double)42,DataTypes::scalarShape);
82     d.setToZero();
83     assert(L.Lsup()<0.001);
84     }
85    
86     void SharedDataTestCase::testSetTaggedValueFromCPP()
87     {
88     Data d((double)42,DataTypes::scalarShape);
89     d.tag();
90     Data L=d.delay();
91     ValueType v(1,17);
92     d.setTaggedValueFromCPP(1,DataTypes::scalarShape,v);
93     L.resolve();
94     // at this point, d should have a tag and L should not
95     // unfortunately its a little tricky to find out what tags a Data object has so I'll use strings
96     string s=L.toString();
97     assert(s.find("Tag(1)")==string::npos); // if the tag shows up we have shared data
98     }
99    
100     void SharedDataTestCase::testGetDataAtOffset()
101     {
102     Data d((double)42,DataTypes::scalarShape);
103     Data L=d.delay();
104     // now change the data directly
105     d.getDataAtOffset(0)=17;
106     assert(L.getDataAtOffset(0)==42);
107     }
108    
109     void SharedDataTestCase::testGetDataPoint()
110     {
111     Data d((double)42,DataTypes::scalarShape);
112     Data L=d.delay();
113     // now change the data directly
114     d.getDataPoint(0,0)=17;
115     assert(L.getDataPoint(0,0)==42);
116     }
117    
118     void SharedDataTestCase::testGetSampleRW()
119     {
120     Data d((double)42,DataTypes::scalarShape);
121     Data L=d.delay();
122     // now change the data directly
123 jfenwick 2222 try
124     {
125     *d.getSampleDataRW(0)=17;
126     assert(false); // should have thrown
127     } catch (DataException e)
128     {
129     }
130     // Now try again properly
131     d.requireWrite();
132 jfenwick 2212 *d.getSampleDataRW(0)=17;
133     L.resolve();
134     assert(*L.getSampleDataRO(0)==42);
135     }
136    
137     TestSuite* SharedDataTestCase::suite ()
138     {
139     //
140     // create the suite of tests to perform.
141     TestSuite *testSuite = new TestSuite ("SharedDataTestCase");
142    
143     testSuite->addTest (new TestCaller< SharedDataTestCase>("Arithmetic Assignment operators",&SharedDataTestCase::testEQ));
144     testSuite->addTest (new TestCaller< SharedDataTestCase>("Copy Constructor",&SharedDataTestCase::testCC));
145     testSuite->addTest (new TestCaller< SharedDataTestCase>("Assignment operator",&SharedDataTestCase::testAssign));
146     testSuite->addTest (new TestCaller< SharedDataTestCase>("setToZero",&SharedDataTestCase::testSetToZero));
147     testSuite->addTest (new TestCaller< SharedDataTestCase>("setTaggedValueFromCPP",&SharedDataTestCase::testSetTaggedValueFromCPP));
148     testSuite->addTest (new TestCaller< SharedDataTestCase>("getDataAtOffset",&SharedDataTestCase::testGetDataAtOffset));
149     testSuite->addTest (new TestCaller< SharedDataTestCase>("getDataPoint",&SharedDataTestCase::testGetDataPoint));
150     testSuite->addTest (new TestCaller< SharedDataTestCase>("getSampleRW",&SharedDataTestCase::testGetSampleRW));
151     return testSuite;
152     }

  ViewVC Help
Powered by ViewVC 1.1.26