00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "fennel/common/CommonPreamble.h"
00025 #include "fennel/test/TestBase.h"
00026 #include "fennel/tuple/StandardTypeDescriptor.h"
00027 #include "fennel/common/TraceSource.h"
00028
00029 #include <boost/test/test_tools.hpp>
00030 #include <boost/scoped_array.hpp>
00031 #include <string>
00032 #include <limits>
00033
00034 using namespace fennel;
00035
00036 class StandardTypeTest : virtual public TestBase, public TraceSource
00037 {
00038 void testStandardTypeToString();
00039 void testStandardTypeIsNative();
00040 void testStandardTypeIsNativeNotBool();
00041 void testStandardTypeIsIntegralNative();
00042 void testStandardTypeIsExact();
00043 void testStandardTypeIsApprox();
00044 void testStandardTypeIsArray();
00045 void testStandardTypeIsVariableLenArray();
00046 void testStandardTypeIsFixedLenArray();
00047 void testStandardTypeIsTextArray();
00048 void testStandardTypeIsBinaryArray();
00049
00050 public:
00051 explicit StandardTypeTest()
00052 : TraceSource(shared_from_this(),"StandardTypeTest")
00053 {
00054 FENNEL_UNIT_TEST_CASE(StandardTypeTest, testStandardTypeToString);
00055 FENNEL_UNIT_TEST_CASE(StandardTypeTest, testStandardTypeIsNative);
00056 FENNEL_UNIT_TEST_CASE(
00057 StandardTypeTest, testStandardTypeIsNativeNotBool);
00058 FENNEL_UNIT_TEST_CASE(
00059 StandardTypeTest, testStandardTypeIsIntegralNative);
00060 FENNEL_UNIT_TEST_CASE(StandardTypeTest, testStandardTypeIsExact);
00061 FENNEL_UNIT_TEST_CASE(StandardTypeTest, testStandardTypeIsApprox);
00062 FENNEL_UNIT_TEST_CASE(StandardTypeTest, testStandardTypeIsArray);
00063 FENNEL_UNIT_TEST_CASE(
00064 StandardTypeTest, testStandardTypeIsVariableLenArray);
00065 FENNEL_UNIT_TEST_CASE(
00066 StandardTypeTest, testStandardTypeIsFixedLenArray);
00067 FENNEL_UNIT_TEST_CASE(StandardTypeTest, testStandardTypeIsTextArray);
00068 FENNEL_UNIT_TEST_CASE(StandardTypeTest, testStandardTypeIsBinaryArray);
00069 }
00070
00071 virtual ~StandardTypeTest()
00072 {
00073 }
00074 };
00075
00076 void StandardTypeTest::testStandardTypeToString()
00077 {
00078 int i;
00079 StandardTypeDescriptorOrdinal v, x;
00080 std::string concat;
00081 const char* str;
00082
00083 BOOST_REQUIRE(STANDARD_TYPE_MIN < STANDARD_TYPE_END);
00084 BOOST_REQUIRE(STANDARD_TYPE_MIN <= STANDARD_TYPE_INT_8);
00085 BOOST_REQUIRE(STANDARD_TYPE_END > STANDARD_TYPE_VARBINARY);
00086
00087 for (i = STANDARD_TYPE_MIN; i < STANDARD_TYPE_END; i++) {
00088 v = StandardTypeDescriptorOrdinal(i);
00089 str = StandardTypeDescriptor::toString(v);
00090 x = StandardTypeDescriptor::fromString(str);
00091 BOOST_CHECK_EQUAL (x, v);
00092 BOOST_MESSAGE(v << " -> " << str << " -> " << x);
00093 concat += str;
00094 }
00095 BOOST_MESSAGE("concat: |" << concat << "|");
00096 BOOST_CHECK(!(concat.compare("s1u1s2u2s4u4s8u8bordcvcbvbUvU")));
00097
00098 for (i = STANDARD_TYPE_VARBINARY; i >= STANDARD_TYPE_INT_8; i--) {
00099 v = StandardTypeDescriptorOrdinal(i);
00100 str = StandardTypeDescriptor::toString(v);
00101 x = StandardTypeDescriptor::fromString(str);
00102 BOOST_CHECK_EQUAL(x, v);
00103 }
00104 }
00105
00106 void StandardTypeTest::testStandardTypeIsNative()
00107 {
00108 BOOST_REQUIRE(STANDARD_TYPE_MIN < STANDARD_TYPE_END);
00109 BOOST_REQUIRE(STANDARD_TYPE_MIN <= STANDARD_TYPE_INT_8);
00110 BOOST_REQUIRE(STANDARD_TYPE_END > STANDARD_TYPE_VARBINARY);
00111
00112 int i;
00113 StandardTypeDescriptorOrdinal v;
00114
00115 for (i = STANDARD_TYPE_MIN; i < STANDARD_TYPE_END; i++) {
00116 BOOST_MESSAGE("isNative " << i);
00117 v = StandardTypeDescriptorOrdinal(i);
00118 if (v == STANDARD_TYPE_CHAR ||
00119 v == STANDARD_TYPE_VARCHAR ||
00120 v == STANDARD_TYPE_BINARY ||
00121 v == STANDARD_TYPE_VARBINARY ||
00122 v == STANDARD_TYPE_UNICODE_CHAR ||
00123 v == STANDARD_TYPE_UNICODE_VARCHAR) {
00124 BOOST_CHECK_EQUAL(StandardTypeDescriptor::isNative(v), false);
00125 } else {
00126 BOOST_CHECK_EQUAL(StandardTypeDescriptor::isNative(v), true);
00127 }
00128 }
00129 }
00130
00131 void StandardTypeTest::testStandardTypeIsNativeNotBool()
00132 {
00133 BOOST_REQUIRE(STANDARD_TYPE_MIN < STANDARD_TYPE_END);
00134 BOOST_REQUIRE(STANDARD_TYPE_MIN <= STANDARD_TYPE_INT_8);
00135 BOOST_REQUIRE(STANDARD_TYPE_END > STANDARD_TYPE_VARBINARY);
00136
00137 int i;
00138 StandardTypeDescriptorOrdinal v;
00139
00140 for (i = STANDARD_TYPE_MIN; i < STANDARD_TYPE_END; i++) {
00141 BOOST_MESSAGE("isNativeNotBool " << i);
00142 v = StandardTypeDescriptorOrdinal(i);
00143 if (v == STANDARD_TYPE_BOOL ||
00144 v == STANDARD_TYPE_CHAR ||
00145 v == STANDARD_TYPE_VARCHAR ||
00146 v == STANDARD_TYPE_BINARY ||
00147 v == STANDARD_TYPE_VARBINARY ||
00148 v == STANDARD_TYPE_UNICODE_CHAR ||
00149 v == STANDARD_TYPE_UNICODE_VARCHAR)
00150 {
00151 BOOST_CHECK_EQUAL(
00152 StandardTypeDescriptor::isNativeNotBool(v),
00153 false);
00154 } else {
00155 BOOST_CHECK_EQUAL(
00156 StandardTypeDescriptor::isNativeNotBool(v),
00157 true);
00158 }
00159 }
00160 }
00161
00162 void StandardTypeTest::testStandardTypeIsIntegralNative()
00163 {
00164 BOOST_REQUIRE(STANDARD_TYPE_MIN < STANDARD_TYPE_END);
00165 BOOST_REQUIRE(STANDARD_TYPE_MIN <= STANDARD_TYPE_INT_8);
00166 BOOST_REQUIRE(STANDARD_TYPE_END > STANDARD_TYPE_VARBINARY);
00167
00168 int i;
00169 StandardTypeDescriptorOrdinal v;
00170
00171 for (i = STANDARD_TYPE_MIN; i < STANDARD_TYPE_END; i++) {
00172 BOOST_MESSAGE("isIntegralNative " << i);
00173 v = StandardTypeDescriptorOrdinal(i);
00174 if (v == STANDARD_TYPE_REAL ||
00175 v == STANDARD_TYPE_DOUBLE ||
00176 v == STANDARD_TYPE_CHAR ||
00177 v == STANDARD_TYPE_VARCHAR ||
00178 v == STANDARD_TYPE_BINARY ||
00179 v == STANDARD_TYPE_VARBINARY ||
00180 v == STANDARD_TYPE_UNICODE_CHAR ||
00181 v == STANDARD_TYPE_UNICODE_VARCHAR)
00182 {
00183 BOOST_CHECK_EQUAL(
00184 StandardTypeDescriptor::isIntegralNative(v),
00185 false);
00186 } else {
00187 BOOST_CHECK_EQUAL(
00188 StandardTypeDescriptor::isIntegralNative(v),
00189 true);
00190 }
00191 }
00192 }
00193
00194 void StandardTypeTest::testStandardTypeIsExact()
00195 {
00196 BOOST_REQUIRE(STANDARD_TYPE_MIN < STANDARD_TYPE_END);
00197 BOOST_REQUIRE(STANDARD_TYPE_MIN <= STANDARD_TYPE_INT_8);
00198 BOOST_REQUIRE(STANDARD_TYPE_END > STANDARD_TYPE_VARBINARY);
00199
00200 int i;
00201 StandardTypeDescriptorOrdinal v;
00202
00203 for (i = STANDARD_TYPE_MIN; i < STANDARD_TYPE_END; i++) {
00204 v = StandardTypeDescriptorOrdinal(i);
00205 BOOST_MESSAGE("isExact " << i << " " << StandardTypeDescriptor::isExact(v));
00206 if (v == STANDARD_TYPE_BOOL ||
00207 v == STANDARD_TYPE_REAL ||
00208 v == STANDARD_TYPE_DOUBLE ||
00209 v == STANDARD_TYPE_CHAR ||
00210 v == STANDARD_TYPE_VARCHAR ||
00211 v == STANDARD_TYPE_BINARY ||
00212 v == STANDARD_TYPE_VARBINARY ||
00213 v == STANDARD_TYPE_UNICODE_CHAR ||
00214 v == STANDARD_TYPE_UNICODE_VARCHAR) {
00215 BOOST_CHECK_EQUAL(StandardTypeDescriptor::isExact(v), false);
00216 } else {
00217 BOOST_CHECK_EQUAL(StandardTypeDescriptor::isExact(v), true);
00218 }
00219 }
00220 }
00221
00222 void StandardTypeTest::testStandardTypeIsApprox()
00223 {
00224 BOOST_REQUIRE(STANDARD_TYPE_MIN < STANDARD_TYPE_END);
00225 BOOST_REQUIRE(STANDARD_TYPE_MIN <= STANDARD_TYPE_INT_8);
00226 BOOST_REQUIRE(STANDARD_TYPE_END > STANDARD_TYPE_VARBINARY);
00227
00228 int i;
00229 StandardTypeDescriptorOrdinal v;
00230
00231 for (i = STANDARD_TYPE_MIN; i < STANDARD_TYPE_END; i++) {
00232 BOOST_MESSAGE("isApprox " << i);
00233 v = StandardTypeDescriptorOrdinal(i);
00234 if (v == STANDARD_TYPE_REAL ||
00235 v == STANDARD_TYPE_DOUBLE) {
00236 BOOST_CHECK_EQUAL(StandardTypeDescriptor::isApprox(v), true);
00237 } else {
00238 BOOST_CHECK_EQUAL(StandardTypeDescriptor::isApprox(v), false);
00239 }
00240 }
00241 }
00242
00243
00244 void StandardTypeTest::testStandardTypeIsArray()
00245 {
00246 BOOST_REQUIRE(STANDARD_TYPE_MIN < STANDARD_TYPE_END);
00247 BOOST_REQUIRE(STANDARD_TYPE_MIN <= STANDARD_TYPE_INT_8);
00248 BOOST_REQUIRE(STANDARD_TYPE_END > STANDARD_TYPE_VARBINARY);
00249
00250 int i;
00251 StandardTypeDescriptorOrdinal v;
00252
00253 for (i = STANDARD_TYPE_MIN; i < STANDARD_TYPE_END; i++) {
00254 BOOST_MESSAGE("isArray " << i);
00255 v = StandardTypeDescriptorOrdinal(i);
00256 if (v == STANDARD_TYPE_CHAR ||
00257 v == STANDARD_TYPE_VARCHAR ||
00258 v == STANDARD_TYPE_BINARY ||
00259 v == STANDARD_TYPE_VARBINARY ||
00260 v == STANDARD_TYPE_UNICODE_CHAR ||
00261 v == STANDARD_TYPE_UNICODE_VARCHAR) {
00262 BOOST_CHECK_EQUAL(StandardTypeDescriptor::isArray(v), true);
00263 } else {
00264 BOOST_CHECK_EQUAL(StandardTypeDescriptor::isArray(v), false);
00265 }
00266 }
00267 }
00268
00269 void StandardTypeTest::testStandardTypeIsVariableLenArray()
00270 {
00271 BOOST_REQUIRE(STANDARD_TYPE_MIN < STANDARD_TYPE_END);
00272
00273 int i;
00274 StandardTypeDescriptorOrdinal v;
00275
00276 for (i = STANDARD_TYPE_MIN; i < STANDARD_TYPE_END; i++) {
00277 BOOST_MESSAGE("isVariableLenArray " << i);
00278 v = StandardTypeDescriptorOrdinal(i);
00279 if (v == STANDARD_TYPE_VARCHAR ||
00280 v == STANDARD_TYPE_VARBINARY ||
00281 v == STANDARD_TYPE_UNICODE_VARCHAR) {
00282 BOOST_CHECK_EQUAL(
00283 StandardTypeDescriptor::isVariableLenArray(v), true);
00284 } else {
00285 BOOST_CHECK_EQUAL(
00286 StandardTypeDescriptor::isVariableLenArray(v), false);
00287 }
00288 }
00289 }
00290
00291 void StandardTypeTest::testStandardTypeIsFixedLenArray()
00292 {
00293 BOOST_REQUIRE(STANDARD_TYPE_MIN < STANDARD_TYPE_END);
00294
00295 int i;
00296 StandardTypeDescriptorOrdinal v;
00297
00298 for (i = STANDARD_TYPE_MIN; i < STANDARD_TYPE_END; i++) {
00299 BOOST_MESSAGE("isFixedLenArray " << i);
00300 v = StandardTypeDescriptorOrdinal(i);
00301 if (v == STANDARD_TYPE_CHAR ||
00302 v == STANDARD_TYPE_BINARY ||
00303 v == STANDARD_TYPE_UNICODE_CHAR)
00304 {
00305 BOOST_CHECK_EQUAL(
00306 StandardTypeDescriptor::isFixedLenArray(v),
00307 true);
00308 } else {
00309 BOOST_CHECK_EQUAL(
00310 StandardTypeDescriptor::isFixedLenArray(v),
00311 false);
00312 }
00313 }
00314 }
00315
00316 void StandardTypeTest::testStandardTypeIsTextArray()
00317 {
00318 BOOST_REQUIRE(STANDARD_TYPE_MIN < STANDARD_TYPE_END);
00319
00320 int i;
00321 StandardTypeDescriptorOrdinal v;
00322
00323 for (i = STANDARD_TYPE_MIN; i < STANDARD_TYPE_END; i++) {
00324 BOOST_MESSAGE("isTextArray " << i);
00325 v = StandardTypeDescriptorOrdinal(i);
00326 if (v == STANDARD_TYPE_CHAR ||
00327 v == STANDARD_TYPE_VARCHAR ||
00328 v == STANDARD_TYPE_UNICODE_CHAR ||
00329 v == STANDARD_TYPE_UNICODE_VARCHAR) {
00330 BOOST_CHECK_EQUAL(StandardTypeDescriptor::isTextArray(v), true);
00331 } else {
00332 BOOST_CHECK_EQUAL(StandardTypeDescriptor::isTextArray(v), false);
00333 }
00334 }
00335 }
00336
00337 void StandardTypeTest::testStandardTypeIsBinaryArray()
00338 {
00339 BOOST_REQUIRE(STANDARD_TYPE_MIN < STANDARD_TYPE_END);
00340
00341 int i;
00342 StandardTypeDescriptorOrdinal v;
00343
00344 for (i = STANDARD_TYPE_MIN; i < STANDARD_TYPE_END; i++) {
00345 BOOST_MESSAGE("isBinaryArray " << i);
00346 v = StandardTypeDescriptorOrdinal(i);
00347 if (v == STANDARD_TYPE_VARBINARY ||
00348 v == STANDARD_TYPE_BINARY) {
00349 BOOST_CHECK_EQUAL(StandardTypeDescriptor::isBinaryArray(v), true);
00350 } else {
00351 BOOST_CHECK_EQUAL(StandardTypeDescriptor::isBinaryArray(v), false);
00352 }
00353 }
00354 }
00355
00356
00357
00358 FENNEL_UNIT_TEST_SUITE(StandardTypeTest);
00359
00360