|
1 /* |
|
2 * Copyright 2005-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 <string> |
|
23 #include <vector> |
|
24 |
|
25 #include <oasys/util/UnitTest.h> |
|
26 #include "bundling/GbofId.h" |
|
27 |
|
28 using namespace dtn; |
|
29 using namespace oasys; |
|
30 |
|
31 DECLARE_TEST(Equality) { |
|
32 EndpointID _source[] = { |
|
33 EndpointID("dtn://test-a.dtn"), |
|
34 EndpointID("dtn://test-b.dtn"), |
|
35 EndpointID("") |
|
36 }; |
|
37 |
|
38 u_int32_t _secs[] = { 1234, 5678, 0 }; |
|
39 u_int32_t _seqno[] = { 1111, 2222, 0 }; |
|
40 u_int32_t _off[] = { 1000, 2000, 0 }; |
|
41 u_int32_t _length[] = { 5000, 3000, 0 }; |
|
42 |
|
43 std::vector<GbofId> others; |
|
44 others.push_back(GbofId(EndpointID("dtn:none"), BundleTimestamp(0, 0), 0, 0, 0)); |
|
45 |
|
46 // first set of tests ignore fragment components since non-fragment |
|
47 for (EndpointID* source = &_source[0]; source != &_source[2]; source++) |
|
48 for (u_int32_t* secs = &_secs[0]; secs != &_secs[2]; secs++) |
|
49 for (u_int32_t* seqno = &_seqno[0]; seqno != &_seqno[2]; seqno++) |
|
50 { |
|
51 GbofId gbofid_a(*source, BundleTimestamp(*secs, *seqno), false, 0, 0); |
|
52 GbofId gbofid_b(*source, BundleTimestamp(*secs, *seqno), false, 999, 999); |
|
53 |
|
54 log_always_p("/test", "checking %s", gbofid_a.str().c_str()); |
|
55 CHECK(gbofid_a == gbofid_b); |
|
56 CHECK(! (gbofid_a < gbofid_b)); |
|
57 CHECK(! (gbofid_b < gbofid_a)); |
|
58 |
|
59 for (std::vector<GbofId>::iterator i = others.begin(); i != others.end(); ++i) { |
|
60 log_always_p("/test", "checking %s vs %s", gbofid_a.str().c_str(), i->str().c_str()); |
|
61 CHECK(!(gbofid_a == *i)); |
|
62 CHECK((gbofid_a < *i) || (*i < gbofid_a)); |
|
63 } |
|
64 |
|
65 others.push_back(gbofid_a); |
|
66 } |
|
67 |
|
68 // repeat with the fragmentation parts |
|
69 for (EndpointID* source = &_source[0]; source != &_source[2]; source++) |
|
70 for (u_int32_t* secs = &_secs[0]; secs != &_secs[2]; secs++) |
|
71 for (u_int32_t* seqno = &_seqno[0]; seqno != &_seqno[2]; seqno++) |
|
72 for (u_int32_t* off = &_off[0]; off != &_off[2]; off++) |
|
73 for (u_int32_t* length = &_length[0]; length != &_length[2]; length++) |
|
74 { |
|
75 GbofId gbofid_a(*source, BundleTimestamp(*secs, *seqno), true, *off, *length); |
|
76 GbofId gbofid_b(*source, BundleTimestamp(*secs, *seqno), true, *off, *length); |
|
77 |
|
78 log_always_p("/test", "checking %s", gbofid_a.str().c_str()); |
|
79 CHECK(gbofid_a == gbofid_b); |
|
80 CHECK(! (gbofid_a < gbofid_b)); |
|
81 CHECK(! (gbofid_b < gbofid_a)); |
|
82 |
|
83 for (std::vector<GbofId>::iterator i = others.begin(); i != others.end(); ++i) { |
|
84 log_always_p("/test", "checking %s vs %s", gbofid_a.str().c_str(), i->str().c_str()); |
|
85 CHECK(!(gbofid_a == *i)); |
|
86 CHECK((gbofid_a < *i) || (*i < gbofid_a)); |
|
87 } |
|
88 |
|
89 others.push_back(gbofid_a); |
|
90 } |
|
91 |
|
92 return UNIT_TEST_PASSED; |
|
93 } |
|
94 |
|
95 DECLARE_TESTER(GbofIDTest) { |
|
96 ADD_TEST(Equality); |
|
97 } |
|
98 |
|
99 DECLARE_TEST_FILE(GbofIDTest, "gbofid test"); |