LRAUV  revA
Universal_Test.h
Go to the documentation of this file.
1 
9 #ifndef _UNIVERSAL_TEST_H_
10 #define _UNIVERSAL_TEST_H_
11 
13 #include "data/Point3D.h"
16 #include "data/I3D.h"
17 
18 #include <cxxtest/TestSuite.h>
19 
21 {
22 public:
23 
25  PubUniversalBlobURI( const char* fullURI, const Unit& unit,
26  BlobType blobType, unsigned short dimension1 = 0,
27  unsigned short dimension2 = 0, unsigned short dimension3 = 0 )
28  : UniversalBlobURI( fullURI, unit, blobType, dimension1, dimension2, dimension3 )
29  {}
30 
31 };
32 
33 
34 class TinyCube: public I3D<float>
35 {
36 public:
37 
38  TinyCube( float f000 = 0, float f001 = 0, float f010 = 0, float f011 = 0,
39  float f100 = 0, float f101 = 0, float f110 = 0, float f111 = 0 )
40  : value_( I3D<float>::New3D( 2, 2, 2 ) )
41  {
42  value_[0][0][0] = f000;
43  value_[0][0][1] = f001;
44  value_[0][1][0] = f010;
45  value_[0][1][1] = f011;
46  value_[1][0][0] = f100;
47  value_[1][0][1] = f101;
48  value_[1][1][0] = f110;
49  value_[1][1][1] = f111;
50  }
51 
52  virtual ~TinyCube() {};
53 
54  virtual float*** getPtr3d()
55  {
56  return value_;
57  }
58 
59  virtual float** getPtr2d()
60  {
61  return value_[0];
62  }
63 
64  virtual float* getPtr1d()
65  {
66  return value_[0][0];
67  }
68 
69  virtual int getM() const
70  {
71  return 2;
72  }
73 
74  virtual int getN() const
75  {
76  return 2;
77  }
78 
79  virtual int getO() const
80  {
81  return 2;
82  }
83 
84  float** operator[]( int index )
85  {
86  return value_[index];
87  };
88 
89 protected:
90 
91  float*** value_;
92 
93 };
94 
100 class Universal_Test : public CxxTest::TestSuite
101 {
102 public:
103 
106  {
107  TestAsyncComponent testComponent( "Blob_TestComponent" );
108  PubUniversalBlobURI velocitycityURI( "velocitycity", Units::METER_PER_SECOND, BLOB_FLOAT64LE, 3 );
109 
110  UniversalBlobWriter* bw = testComponent.newUniversalBlobWriter( velocitycityURI );
111  UniversalBlobReader* br = testComponent.newUniversalBlobReader( velocitycityURI );
112 
113  double u = .75, v = .65, w = sqrt( 1 - u * u - v * v ); // Overall speed in 1 m/s
114  Point3D velocityInMPS( u, v, w );
116  TS_ASSERT( bw->write1DClass( Units::METER_PER_SECOND, velocityInMPS ) );
117 
118  // Test readability
119  TS_ASSERT( br->isActive() );
120 
121  //Test reading as a BlobValue
122  bool success = false;
123  BlobValue bv = br->readBlob( success );
124  TS_ASSERT_EQUALS( bv.getByteLength(), 3 * sizeof( double ) )
125  TS_ASSERT( success );
126  TS_ASSERT_DELTA( ( ( double* )bv.getBytes() )[0], velocityInMPS.getU(), 0.01 );
127  TS_ASSERT_DELTA( ( ( double* )bv.getBytes() )[1], velocityInMPS.getV(), 0.01 );
128  TS_ASSERT_DELTA( ( ( double* )bv.getBytes() )[2], velocityInMPS.getW(), 0.01 );
129 
130  // Test reading the fixed size and unit conversion to base
131  Point3D velocityInMPH = velocityInMPS * 2.23694;
132  Point3D velocityOut;
133  TS_ASSERT_EQUALS( br->read1DClass( Units::MILE_PER_HOUR, velocityOut ), 3 );
134  TS_ASSERT_DELTA( velocityOut.getU(), velocityInMPH.getU(), 0.01 );
135  TS_ASSERT_DELTA( velocityOut.getV(), velocityInMPH.getV(), 0.01 );
136  TS_ASSERT_DELTA( velocityOut.getW(), velocityInMPH.getW(), 0.01 );
137  }
138 
141  {
142  TestAsyncComponent testComponent( "Blob_TestComponent" );
143  PubUniversalBlobURI radials3D( "radials3D", Units::METER_PER_SECOND, BLOB_FLOAT32LE, 2, 2, 2 );
144 
145  UniversalBlobWriter* bw = testComponent.newUniversalBlobWriter( radials3D );
146  UniversalBlobReader* br = testComponent.newUniversalBlobReader( radials3D );
147 
148  TinyCube radialsInMPS( 0.000, 0.001, 0.010, 0.011, 0.100, 0.101, 0.110, 0.111 );
149  bw->setAccuracy( Units::METER_PER_SECOND, 0.0001 );
150  TS_ASSERT( bw->write3DClass( Units::METER_PER_SECOND, radialsInMPS ) );
151 
152  // Test readability
153  TS_ASSERT( br->isActive() );
154 
155  //Test reading as a BlobValue
156  bool success = false;
157  BlobValue bv = br->readBlob( success );
158  TS_ASSERT_EQUALS( bv.getByteLength(), 2 * 2 * 2 * sizeof( float ) )
159  TS_ASSERT( success );
160  for( int i = 0; i < 2; ++i )
161  {
162  for( int j = 0; j < 2; ++j )
163  {
164  for( int k = 0; k < 2; ++k )
165  {
166  TS_ASSERT_DELTA( ( ( float* )bv.getBytes() )[i * 4 + j * 2 + k],
167  radialsInMPS[i][j][k], 0.0001 );
168  }
169  }
170  }
171 
172  // Test reading the fixed size and unit conversion to base
173  TinyCube radialsOut;
174  TS_ASSERT_EQUALS( br->read3DClass( Units::MILE_PER_HOUR, radialsOut ), 2 * 2 * 2 );
175  for( int i = 0; i < 2; ++i )
176  {
177  for( int j = 0; j < 2; ++j )
178  {
179  for( int k = 0; k < 2; ++k )
180  {
181  TS_ASSERT_DELTA( radialsOut[i][j][k],
182  radialsInMPS[i][j][k] * 2.23694, 0.0001 );
183  }
184  }
185  }
186  }
187 
188 };
189 
190 #endif // _BLOB_TEST_H
virtual float ** getPtr2d()
Definition: Universal_Test.h:59
int read1DClass(const Unit &unit, I1D< T > &i1d)
Definition: BlobReader.h:70
Contains the AsyncComponent class definition.
virtual bool setAccuracy(const Unit &unit, const float value)
Set accuracy function.
Definition: UniversalDataWriter.cpp:51
size_t getByteLength()
Definition: BlobValue.h:222
void * getBytes()
Definition: BlobValue.h:227
UniversalBlobReader * newUniversalBlobReader(const UniversalBlobURI &universalURI)
Definition: Component.cpp:622
Definition: I3D.h:18
Definition: UniversalURI.h:519
virtual int getO() const
Definition: Universal_Test.h:79
Unit tests for the BlobValue, BlobReader, and BlobWriter classes.
Definition: Universal_Test.h:100
BlobValue readBlob(bool &success)
Definition: BlobReader.h:45
virtual int getM() const
Definition: Universal_Test.h:69
Definition: BlobType.h:33
double getW() const
Definition: Point3D.h:86
float ** operator[](int index)
Definition: Universal_Test.h:84
Contains the Point3D class definition.
static const BaseUnit METER_PER_SECOND
Definition: Units.h:86
virtual float * getPtr1d()
Definition: Universal_Test.h:64
PubUniversalBlobURI(const char *fullURI, const Unit &unit, BlobType blobType, unsigned short dimension1=0, unsigned short dimension2=0, unsigned short dimension3=0)
Exposed Constructor for use by static initializers.
Definition: Universal_Test.h:25
Definition: UniversalDataReader.h:74
Wraps three double precision (8-byte) floating point numbers.
Definition: Point3D.h:28
float *** value_
Definition: Universal_Test.h:87
Contains the DataReader class definition.
static const Unit MILE_PER_HOUR
Definition: Units.h:189
UniversalBlobWriter * newUniversalBlobWriter(const UniversalBlobURI &universalURI, const Unit &accuracyUnit=Units::NONE, const float accuracy=DataElement::NO_ACCURACY, Logger::TimePrecisionType timePrecision=Logger::TIME_PRECISION_MILLIS)
Definition: Component.cpp:629
BlobType
Definition: BlobType.h:13
virtual ~TinyCube()
Definition: Universal_Test.h:52
Wraps a StrValue as an arbitrary collection of binary values, with units.
Definition: BlobValue.h:26
static float *** New3D(int m, int n, int o, bool extra=false)
Definition: I3D.h:33
bool isActive(void)
Definition: DataReader.cpp:74
Definition: UniversalDataWriter.h:55
Definition: BlobType.h:35
double getU() const
Definition: Point3D.h:66
bool write3DClass(const Unit &unit, I3D< T > &i3d, const Timestamp &timestamp=Timestamp::NOT_SET_TIME)
Writes data from the class that implements as I3D a binary blob ElementURI used to declare this DataW...
Definition: BlobWriter.h:183
virtual int getN() const
Definition: Universal_Test.h:74
Definition: Universal_Test.h:20
Contains the DataWriter class definition.
bool write1DClass(const Unit &unit, I1D< T > &i1d, const Timestamp &timestamp=Timestamp::NOT_SET_TIME)
Writes data from the class that implements as I1D a binary blob ElementURI used to declare this DataW...
Definition: BlobWriter.h:77
double getV() const
Definition: Point3D.h:76
void test1DUniversalBlobReadWrite(void)
Test 1D Read & Write.
Definition: Universal_Test.h:105
void test3DUniversalBlobReadWrite(void)
Test 3D Read & Write.
Definition: Universal_Test.h:140
virtual float *** getPtr3d()
Definition: Universal_Test.h:54
int read3DClass(const Unit &unit, I3D< T > &i3d)
Definition: BlobReader.h:167
Definition: Universal_Test.h:34
Dummy implementation of AsyncComponent for testing purposes.
Definition: TestAsyncComponent.h:19
Code that represents an engineering unit.
Definition: Unit.h:24
TinyCube(float f000=0, float f001=0, float f010=0, float f011=0, float f100=0, float f101=0, float f110=0, float f111=0)
Definition: Universal_Test.h:38