source: source/ariba/utility/serialization/TestSerialization.cpp@ 5718

Last change on this file since 5718 was 3690, checked in by mies, 15 years ago

Merged 20090512-mies-connectors changes r3472:r3689 into trunk.

File size: 3.3 KB
Line 
1// [License]
2// The Ariba-Underlay Copyright
3//
4// Copyright (c) 2008-2009, Institute of Telematics, UniversitÀt Karlsruhe (TH)
5//
6// Institute of Telematics
7// UniversitÀt Karlsruhe (TH)
8// Zirkel 2, 76128 Karlsruhe
9// Germany
10//
11// Redistribution and use in source and binary forms, with or without
12// modification, are permitted provided that the following conditions are
13// met:
14//
15// 1. Redistributions of source code must retain the above copyright
16// notice, this list of conditions and the following disclaimer.
17// 2. Redistributions in binary form must reproduce the above copyright
18// notice, this list of conditions and the following disclaimer in the
19// documentation and/or other materials provided with the distribution.
20//
21// THIS SOFTWARE IS PROVIDED BY THE INSTITUTE OF TELEMATICS ``AS IS'' AND
22// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ARIBA PROJECT OR
25// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32//
33// The views and conclusions contained in the software and documentation
34// are those of the authors and should not be interpreted as representing
35// official policies, either expressed or implied, of the Institute of
36// Telematics.
37// [License]
38
39#include "Data.hpp"
40#include "DataStream.hpp"
41#include "Serialization.hpp"
42
43using_serialization;
44
45class Aclass: public VSerializeable { VSERIALIZEABLE;
46public:
47 uint32_t x;
48 uint8_t y;
49 int8_t z;
50 bool b;
51 char* text;
52 std::string str;
53 std::vector<uint8_t> v;
54 Aclass* vclass;
55 bool vcls;
56
57 Aclass(bool vcls = false) {
58 text = new char[80];
59 strcpy(text, "Hallo!");
60 str = "std::string:)";
61 x = 0x01020304;
62 y = 0xF;
63 z = -2;
64 b = 0;
65 this->vcls = vcls;
66 v.push_back(0xA0);
67 v.push_back(0xB0);
68 v.push_back(0xC0);
69 v.push_back(0xD0);
70 if (vcls) vclass = new Aclass();
71 else vclass = NULL;
72 }
73
74 void clean() {
75 text = NULL;
76 str = "";
77 x = 0;
78 y = 0;
79 b = 1;
80 z = 0;
81 v.clear();
82 vclass = NULL;
83 }
84
85 void view(bool ret = true) {
86 printf("obj=[%08X, %1X, %d, %d, '%s', '%s' ", x, y, z, b, text, str.c_str());
87 for (size_t i = 0; i < v.size(); i++)
88 printf("%02X ", v[i]);
89 if (vclass != NULL) vclass->view(false);
90 printf("]");
91 if (ret) printf("\n");
92 }
93};
94
95sznBeginDefault( Aclass, X ){
96 X && x && b && I(y,6) && T(text) && T(str) && A(v,4) && I(z) && vcls;
97 if (vcls) X && VO(vclass);
98}sznEnd()
99
100vsznDefault( Aclass );
101
102int main() {
103 using namespace std;
104
105 Aclass a(true);
106 Data data = data_serialize(a);
107 a.view();
108 cout << "length=" << data_length(a) / 8 << endl;
109 cout << "data=" << data << endl;
110
111 Aclass b(true);
112 b.clean();
113 b.view();
114 data_deserialize(b, data);
115 b.view();
116
117 VSerializeable *c = &b;
118 cout << "length=" << data_length(c) / 8 << endl;
119 cout << "data=" << (data = data_serialize(c)) << endl;
120 Aclass d;
121 d.clean();
122 data_deserialize(&d, data);
123 d.view();
124 cout << "--- test successful." << endl;
125
126 return 0;
127}
128
129
Note: See TracBrowser for help on using the repository browser.