|
1 /* |
|
2 * Copyright 2004-2006 Intel Corporation |
|
3 * |
|
4 * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 * you may not use this file except in compliance with the License. |
|
6 * You may obtain a copy of the License at |
|
7 * |
|
8 * http://www.apache.org/licenses/LICENSE-2.0 |
|
9 * |
|
10 * Unless required by applicable law or agreed to in writing, software |
|
11 * distributed under the License is distributed on an "AS IS" BASIS, |
|
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 * See the License for the specific language governing permissions and |
|
14 * limitations under the License. |
|
15 */ |
|
16 |
|
17 #ifdef HAVE_CONFIG_H |
|
18 # include <dtn-config.h> |
|
19 #endif |
|
20 |
|
21 #include <stdio.h> |
|
22 #include <oasys/debug/Log.h> |
|
23 #include <oasys/serialize/MarshalSerialize.h> |
|
24 #include "bundling/Bundle.h" |
|
25 |
|
26 using namespace dtn; |
|
27 using namespace oasys; |
|
28 |
|
29 int |
|
30 main(int argc, const char** argv) |
|
31 { |
|
32 Log::init(); |
|
33 |
|
34 Bundle b, b2; |
|
35 b.bundleid_ = 100; |
|
36 ASSERT(!b.source_.valid()); |
|
37 ASSERT(!b2.source_.valid()); |
|
38 |
|
39 b.source_.assign("bundles://internet/tcp://foo"); |
|
40 ASSERT(b.source_.valid()); |
|
41 ASSERT(b.source_.region().compare("internet") == 0); |
|
42 ASSERT(b.source_.admin().compare("tcp://foo") == 0); |
|
43 |
|
44 MarshalSize s; |
|
45 if (s.action(&b) != 0) { |
|
46 logf("/test", LOG_ERR, "error in marshal sizing"); |
|
47 exit(1); |
|
48 } |
|
49 |
|
50 size_t sz = s.size(); |
|
51 logf("/test", LOG_INFO, "marshalled size is %zu", sz); |
|
52 |
|
53 u_char* buf = (u_char*)malloc(sz); |
|
54 |
|
55 Marshal m(buf, sz); |
|
56 if (m.action(&b) != 0) { |
|
57 logf("/test", LOG_ERR, "error in marshalling"); |
|
58 exit(1); |
|
59 } |
|
60 |
|
61 Unmarshal u(buf, sz); |
|
62 if (u.action(&b2) != 0) { |
|
63 logf("/test", LOG_ERR, "error in unmarshalling"); |
|
64 exit(1); |
|
65 } |
|
66 |
|
67 if (b.bundleid_ != b2.bundleid_) { |
|
68 logf("/test", LOG_ERR, "error: bundle id mismatch"); |
|
69 exit(1); |
|
70 } |
|
71 |
|
72 if (!b2.source_.valid()) { |
|
73 logf("/test", LOG_ERR, "error: b2 source not valid"); |
|
74 exit(1); |
|
75 } |
|
76 |
|
77 |
|
78 #define COMPARE(x) \ |
|
79 if (b.source_.x().compare(b2.source_.x()) != 0) { \ |
|
80 logf("/test", LOG_ERR, "error: mismatch of %s: %s != %s", \ |
|
81 #x, b.source_.x().c_str(), b2.source_.x().c_str()); \ |
|
82 } |
|
83 |
|
84 COMPARE(eid); |
|
85 COMPARE(region); |
|
86 COMPARE(admin); |
|
87 |
|
88 logf("/test", LOG_INFO, "simple marshal test passed"); |
|
89 } |