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 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
|
#include "UniversalIntegerTest.hh"
#include "tyvis/UniversalInteger.hh"
#include "tyvis/EnumerationType.hh"
#include <warped/SerializedInstance.h>
#include <clutils/StringUtilities.h>
int
UniversalIntegerTest::getDefaultValue(){
static int defaultValue = 3;
return defaultValue;
}
void
UniversalIntegerTest::setUp(){
toTest = new UniversalInteger( getDefaultValue() );
}
void
UniversalIntegerTest::tearDown(){
delete toTest;
}
void
UniversalIntegerTest::testGetUniversalKind(){
CPPUNIT_ASSERT( toTest->getUniversalKind() == VHDLData::UNIVERSAL_INTEGER );
}
void
UniversalIntegerTest::testGetLength(){
CPPUNIT_ASSERT( toTest->length() == 1 );
}
void
UniversalIntegerTest::testPrint(){
ostringstream printStream;
toTest->print( printStream );
CPPUNIT_ASSERT( printStream.str() == intToString( getDefaultValue() ));
}
void
UniversalIntegerTest::testEqual(){
UniversalInteger a(10);
UniversalInteger b(10);
CPPUNIT_ASSERT( a == b );
CPPUNIT_ASSERT( a.vhdlEqual(b) == EnumerationType::getEnumerationTrue() );
}
void
UniversalIntegerTest::testNotEqual(){
UniversalInteger a(10);
UniversalInteger b(11);
CPPUNIT_ASSERT( a != b );
}
void
UniversalIntegerTest::testGreater(){
UniversalInteger a(10);
UniversalInteger b(11);
CPPUNIT_ASSERT( b > a );
}
void
UniversalIntegerTest::testGreaterEqual(){
UniversalInteger a(10);
UniversalInteger b(11);
UniversalInteger c(11);
CPPUNIT_ASSERT( b >= a );
CPPUNIT_ASSERT( b >= c );
}
void
UniversalIntegerTest::testLess(){
UniversalInteger a(10);
UniversalInteger b(11);
CPPUNIT_ASSERT( a < b );
}
void
UniversalIntegerTest::testLessEqual(){
UniversalInteger a(10);
UniversalInteger b(11);
UniversalInteger c(11);
CPPUNIT_ASSERT( a <= c );
CPPUNIT_ASSERT( b <= c );
}
void
UniversalIntegerTest::testPlus(){
const UniversalInteger minusTwo( -2 );
const UniversalInteger zero(0);
const UniversalInteger two(2);
const UniversalInteger four(4);
CPPUNIT_ASSERT( two.vhdlPlus(two) == four );
CPPUNIT_ASSERT( two.vhdlPlus(minusTwo) == zero );
CPPUNIT_ASSERT( four.vhdlPlus(minusTwo) == two );
}
void
UniversalIntegerTest::testMinus(){
const UniversalInteger minusTwo(-2);
const UniversalInteger zero(0);
const UniversalInteger two(2);
const UniversalInteger four(4);
const UniversalInteger six(6);
CPPUNIT_ASSERT( two.vhdlMinus(two) == zero );
CPPUNIT_ASSERT( two.vhdlMinus(minusTwo) == four );
CPPUNIT_ASSERT( four.vhdlMinus(minusTwo) == six );
CPPUNIT_ASSERT( four.vhdlMinus(two) == two );
}
void
UniversalIntegerTest::testMultiply(){
const UniversalInteger minusTwo(-2);
const UniversalInteger zero(0);
const UniversalInteger two(2);
const UniversalInteger four(4);
const UniversalInteger six(6);
CPPUNIT_ASSERT( two.vhdlMultiply( two ) == four );
CPPUNIT_ASSERT( minusTwo.vhdlMultiply( minusTwo ) == four );
CPPUNIT_ASSERT( two.vhdlMultiply( minusTwo ) == UniversalInteger( -4 ) );
CPPUNIT_ASSERT( zero.vhdlMultiply( minusTwo ) == zero );
}
void
UniversalIntegerTest::testDivide(){
const UniversalInteger minusTwo(-2);
const UniversalInteger zero(0);
const UniversalInteger one(1);
const UniversalInteger two(2);
const UniversalInteger four(4);
CPPUNIT_ASSERT( four.vhdlDivide( one ) == four );
CPPUNIT_ASSERT( four.vhdlDivide( one ) == UniversalInteger( 4 ) );
CPPUNIT_ASSERT( four.vhdlDivide( two ) == two );
CPPUNIT_ASSERT( four.vhdlDivide( four ) == one );
CPPUNIT_ASSERT( zero.vhdlDivide( four ) == zero );
}
void
UniversalIntegerTest::testClone(){
UniversalInteger *cloned = dynamic_cast<UniversalInteger *>(toTest->clone());
CPPUNIT_ASSERT( cloned != 0 );
CPPUNIT_ASSERT( cloned != toTest );
CPPUNIT_ASSERT( *cloned == *toTest );
delete cloned;
}
void
UniversalIntegerTest::testSerialization(){
SerializedInstance *serialized = static_cast<Serializable *>(toTest)->serialize();
CPPUNIT_ASSERT( serialized->getDataType() == toTest->getDataType() );
UniversalInteger *deserialized = dynamic_cast<UniversalInteger *>( serialized->deserialize() );
CPPUNIT_ASSERT( deserialized != 0 );
CPPUNIT_ASSERT( deserialized != toTest );
CPPUNIT_ASSERT( *deserialized == *toTest );
delete deserialized;
}
|