00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "fennel/common/CommonPreamble.h"
00026 #include "fennel/tuple/TupleDescriptor.h"
00027 #include "fennel/tuple/TupleData.h"
00028 #include "fennel/tuple/TupleAccessor.h"
00029 #include "fennel/tuple/TuplePrinter.h"
00030 #include "fennel/tuple/AttributeAccessor.h"
00031 #include "fennel/tuple/StandardTypeDescriptor.h"
00032 #include "fennel/common/TraceSource.h"
00033
00034 #include <boost/scoped_array.hpp>
00035 #include <boost/test/unit_test_suite.hpp>
00036 #include <limits>
00037 #include <iostream.h>
00038
00039 using namespace fennel;
00040
00041 int const bufferlen = 8;
00042 int const num = 5;
00043
00044 void
00045 tupleFiddle()
00046 {
00047 bool isNullable = true;
00048 int i;
00049
00050 TupleDescriptor tupleDesc;
00051 tupleDesc.clear();
00052
00053
00054 StandardTypeDescriptorFactory typeFactory;
00055 for (i = 0; i < num; i++) {
00056 StoredTypeDescriptor const &typeDesc =
00057 typeFactory.newDataType(STANDARD_TYPE_VARCHAR);
00058 tupleDesc.push_back(
00059 TupleAttributeDescriptor(
00060 typeDesc,
00061 isNullable,
00062 bufferlen));
00063 }
00064 for (i = 0; i < num; i++) {
00065 StoredTypeDescriptor const &typeDesc =
00066 typeFactory.newDataType(STANDARD_TYPE_INT_32);
00067 tupleDesc.push_back(TupleAttributeDescriptor(typeDesc, isNullable));
00068 }
00069 for (i = 0; i < num; i++) {
00070 StoredTypeDescriptor const &typeDesc =
00071 typeFactory.newDataType(STANDARD_TYPE_UINT_8);
00072 tupleDesc.push_back(TupleAttributeDescriptor(typeDesc, isNullable));
00073 }
00074 for (i = 0; i < num; i++) {
00075 StoredTypeDescriptor const &typeDesc =
00076 typeFactory.newDataType(STANDARD_TYPE_REAL);
00077 tupleDesc.push_back(TupleAttributeDescriptor(typeDesc, isNullable));
00078 }
00079
00080
00081
00082
00083
00084
00085
00086 TupleAccessor tupleAccessorFixed;
00087 tupleAccessorFixed.compute(tupleDesc, TUPLE_FORMAT_ALL_FIXED);
00088
00089
00090 boost::scoped_array<FixedBuffer>
00091 pTupleBufFixed(new FixedBuffer[tupleAccessorFixed.getMaxByteCount()]);
00092
00093
00094 tupleAccessorFixed.setCurrentTupleBuf(pTupleBufFixed.get(), false);
00095
00096
00097 TupleData tupleDataFixed(tupleDesc);
00098
00099
00100
00101 tupleAccessorFixed.unmarshal(tupleDataFixed);
00102
00103 TupleData::iterator itr = tupleDataFixed.begin();
00104
00105 TupleDatum pDatum;
00106 PBuffer pData;
00107
00108 for (i = 0; i < num; i++, itr++) {
00109 char buf[bufferlen * 10];
00110 sprintf(buf,"%d-A-%d-B-%d-C-", i, i, i);
00111 strncpy(
00112 (reinterpret_cast<char *>(const_cast<PBuffer>(itr->pData))),
00113 buf, bufferlen);
00114 }
00115 for (i = 0; i < num; i++, itr++) {
00116
00117 pDatum = *itr;
00118 pData = const_cast<PBuffer>(pDatum.pData);
00119 *(reinterpret_cast<int32_t *>(pData)) = i;
00120 }
00121 for (i = 0; i < num; i++, itr++) {
00122
00123 *(reinterpret_cast<uint8_t *>(const_cast<PBuffer>(itr->pData))) = i;
00124 }
00125 for (i = 0; i < num; i++, itr++) {
00126 *(reinterpret_cast<float *>(const_cast<PBuffer>(itr->pData))) = i * 0.5;
00127 }
00128
00129
00130 TuplePrinter tuplePrinter;
00131 tuplePrinter.print(cout, tupleDesc, tupleDataFixed);
00132 cout << endl;
00133
00134
00135 TupleData tupleDataNullable = tupleDataFixed;
00136
00137
00138 for (i = 1; i <= 3; i++) {
00139 tupleDataNullable[(i*num)-1].pData = NULL;
00140 }
00141
00142
00143 tuplePrinter.print(cout, tupleDesc, tupleDataNullable);
00144 cout << endl;
00145
00146
00147 tupleDataNullable[1].pData = tupleDataNullable[0].pData;
00148
00149
00150 tupleDataNullable[2].pData = (tupleDataNullable[0].pData + 1);
00151
00152
00153 tuplePrinter.print(cout, tupleDesc, tupleDataNullable);
00154 cout << endl;
00155
00156 }
00157
00158 int
00159 main(int argc, char *argv[])
00160 {
00161 tupleFiddle();
00162 return 0;
00163 }
00164
00165 boost::unit_test_framework::test_suite *init_unit_test_suite(int,char **)
00166 {
00167 return NULL;
00168 }
00169
00170