File: UniversalRealTest.cc

package info (click to toggle)
tyvis 20031216-4
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,024 kB
  • ctags: 2,985
  • sloc: cpp: 22,881; sh: 8,372; makefile: 353
file content (109 lines) | stat: -rw-r--r-- 2,293 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include "UniversalRealTest.hh"
#include "tyvis/UniversalReal.hh"
#include <warped/SerializedInstance.h>
#include <clutils/StringUtilities.h>

double
UniversalRealTest::getDefaultValue(){
  static double defaultValue = 5.55;
  return defaultValue;
}

void 
UniversalRealTest::setUp(){
  toTest = new UniversalReal( getDefaultValue() );
}

void 
UniversalRealTest::tearDown(){
  delete toTest;
}

void
UniversalRealTest::testGetUniversalKind(){
  CPPUNIT_ASSERT( toTest->getUniversalKind() == VHDLData::UNIVERSAL_REAL );
}

void
UniversalRealTest::testGetLength(){
  CPPUNIT_ASSERT( toTest->length() == 1 );
}

void
UniversalRealTest::testPrint(){
  ostringstream printStream;
  toTest->print( printStream );
  CPPUNIT_ASSERT( printStream.str() == doubleToString( getDefaultValue() ));
}

void
UniversalRealTest::testEqual(){
  UniversalReal a(10);
  UniversalReal b(10);
  
  CPPUNIT_ASSERT( a == b );
}

void
UniversalRealTest::testNotEqual(){
  UniversalReal a(10);
  UniversalReal b(11);
  
  CPPUNIT_ASSERT( a != b );
}

void
UniversalRealTest::testGreater(){
  UniversalReal a(10);
  UniversalReal b(11);
  
  CPPUNIT_ASSERT( b > a );
}

void
UniversalRealTest::testGreaterEqual(){
  UniversalReal a(10);
  UniversalReal b(11);
  UniversalReal c(11);
  
  CPPUNIT_ASSERT( b >= a );
  CPPUNIT_ASSERT( b >= c );
}

void
UniversalRealTest::testLess(){
  UniversalReal a(10);
  UniversalReal b(11);
  
  CPPUNIT_ASSERT( a < b );
}

void
UniversalRealTest::testLessEqual(){
  UniversalReal a(10);
  UniversalReal b(11);
  UniversalReal c(11);
  
  CPPUNIT_ASSERT( a <= c );
  CPPUNIT_ASSERT( b <= c );
}

void
UniversalRealTest::testClone(){
  UniversalReal *cloned = dynamic_cast<UniversalReal *>(toTest->clone());
  CPPUNIT_ASSERT( cloned != 0 );
  CPPUNIT_ASSERT( cloned != toTest );
  CPPUNIT_ASSERT( *cloned = *toTest );
  delete cloned;
}

void
UniversalRealTest::testSerialization(){
  SerializedInstance *serialized = static_cast<Serializable *>(toTest)->serialize();
  CPPUNIT_ASSERT( serialized->getDataType() == toTest->getDataType() );
  UniversalReal *deserialized = dynamic_cast<UniversalReal *>( serialized->deserialize() );
  CPPUNIT_ASSERT( deserialized != 0 );
  CPPUNIT_ASSERT( deserialized != toTest );
  CPPUNIT_ASSERT( *deserialized = *toTest );
  delete deserialized;
}