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
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #include "TestSerialization.h"
00040 #include "Data.hpp"
00041 #include "DataStream.hpp"
00042 #include "Serialization.hpp"
00043
00044 using_serialization;
00045
00046 class Aclass: public VSerializeable { VSERIALIZEABLE;
00047 public:
00048 uint32_t x;
00049 uint8_t y;
00050 int8_t z;
00051 bool b;
00052 char* text;
00053 std::string str;
00054 std::vector<uint8_t> v;
00055 Aclass* vclass;
00056 bool vcls;
00057 uint8_t* static_array;
00058
00059 Aclass(bool vcls = false) {
00060 text = new char[80];
00061 static_array = new uint8_t[20];
00062 for (size_t i=0; i<20; i++) static_array[i] = i;
00063 strcpy(text, "Hallo!");
00064 str = "std::string:)";
00065 x = 0x01020304;
00066 y = 0xF;
00067 z = -2;
00068 b = 0;
00069 this->vcls = vcls;
00070 v.push_back(0xA0);
00071 v.push_back(0xB0);
00072 v.push_back(0xC0);
00073 v.push_back(0xD0);
00074 if (vcls) vclass = new Aclass();
00075 else vclass = NULL;
00076 }
00077
00078 void clean() {
00079 text = NULL;
00080 str = "";
00081 x = 0;
00082 y = 0;
00083 b = 1;
00084 z = 0;
00085 v.clear();
00086 vclass = NULL;
00087 }
00088
00089 void view(bool ret = true) {
00090 printf("obj=[%08X, %1X, %d, %d, '%s', '%s' ", x, y, z, b, text, str.c_str());
00091 for (size_t i = 0; i < v.size(); i++)
00092 printf("%02X ", v[i]);
00093 if (vclass != NULL) vclass->view(false);
00094 printf("]");
00095 if (ret) printf("\n");
00096 }
00097 };
00098
00099 sznBeginDefault( Aclass, X ){
00100 double xpos;
00101 X && x && b && I(y,6) && T(text) && T(str) && A(v,4) && I(z) && vcls;
00102 X && static_A(static_array,20);
00103 X && static_A( (uint8_t*)&xpos, 8 );
00104 if (vcls) X && VO(vclass);
00105 }sznEnd()
00106
00107 vsznDefault( Aclass );
00108
00109 int test_serialization() {
00110 using namespace std;
00111
00112 Aclass a(true);
00113 Data data = data_serialize(a);
00114 a.view();
00115 cout << "length=" << data_length(a) / 8 << endl;
00116 cout << "data=" << data << endl;
00117
00118 Aclass b(true);
00119 b.clean();
00120 b.view();
00121 data_deserialize(b, data);
00122 b.view();
00123
00124 VSerializeable *c = &b;
00125 cout << "length=" << data_length(c) / 8 << endl;
00126 cout << "data=" << (data = data_serialize(c)) << endl;
00127 Aclass d;
00128 d.clean();
00129 data_deserialize(&d, data);
00130 d.view();
00131 cout << "--- test successful." << endl;
00132
00133 return 0;
00134 }
00135
00136