00001
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 #include <UnitTest++.h>
00036 #include "sense_endian.h"
00037 #include "discovery_service.h"
00038
00039
00040 SUITE(DiscoveryTests)
00041 {
00042 TEST(endian_test) {
00043 int test_in = 5;
00044 int test_out;
00045 uint8_t bytes[sizeof(int)];
00046
00047 network_order(bytes, test_in);
00048 host_order((uint32_t*)&test_out, bytes, 4, 0, 1);
00049 CHECK_EQUAL(test_in, test_out);
00050
00051 test_in = -5;
00052 network_order(bytes, test_in);
00053 host_order((uint32_t*)&test_out, bytes, 4, 0, 1);
00054 CHECK_EQUAL(test_in, test_out);
00055
00056 test_in = 83886080;
00057 network_order(bytes, test_in);
00058 host_order((uint32_t*)&test_out, bytes, 4, 0, 1);
00059 CHECK_EQUAL(test_in, test_out);
00060
00061 network_order(bytes, test_in);
00062 host_order((uint32_t*)&test_out, bytes, 4, 1, 1);
00063 CHECK(test_in != test_out);
00064 CHECK_EQUAL(test_out, 5);
00065 }
00066
00067
00068 TEST(announce_test) {
00069 unsigned char hdr[DISCOVERY_HEADER_SIZE], msg[ANNOUNCE_SIZE];
00070 DiscoverHeader dh;
00071 DiscoverMessage dm;
00072 Announce a;
00073
00074 memset(hdr, 0, DISCOVERY_HEADER_SIZE);
00075 memset(msg, 0, ANNOUNCE_SIZE);
00076 a.nodeIdent = 11;
00077 a.hLevel = 3;
00078 announceHeader(hdr);
00079 loadAnnounce(msg, &a);
00080 CHECK(parseDiscoverHeader(&dh, hdr) == 0);
00081 CHECK(parseDiscoverMessage(&dm, &dh, msg) == 0);
00082
00083 CHECK_EQUAL(a.nodeIdent, dm.nodeIdent);
00084 CHECK_EQUAL(a.hLevel, dm.hLevel);
00085 }
00086
00087
00088 TEST(report_test) {
00089 unsigned char hdr[DISCOVERY_HEADER_SIZE], msg[REPORT_SIZE];
00090 DiscoverHeader dh;
00091 DiscoverMessage dm;
00092 Report r;
00093
00094 memset(hdr, 0, DISCOVERY_HEADER_SIZE);
00095 memset(msg, 0, REPORT_SIZE);
00096 r.nodeIdent = 1928;
00097 r.hLevel = 7;
00098 r.cType = 0x23;
00099 reportHeader(hdr);
00100 loadReport(msg, &r);
00101 CHECK(parseDiscoverHeader(&dh, hdr) == 0);
00102 CHECK(parseDiscoverMessage(&dm, &dh, msg) == 0);
00103
00104 CHECK_EQUAL(r.nodeIdent, dm.nodeIdent);
00105 CHECK_EQUAL(r.hLevel, dm.hLevel);
00106 CHECK_EQUAL(r.cType, dm.cType);
00107 }
00108
00109
00110 TEST(require_test) {
00111 unsigned char hdr[DISCOVERY_HEADER_SIZE], msg[REQUIRE_SIZE];
00112 DiscoverHeader dh;
00113 DiscoverMessage dm;
00114 Require r;
00115
00116 memset(hdr, 0, DISCOVERY_HEADER_SIZE);
00117 memset(msg, 0, REQUIRE_SIZE);
00118 r.nodeIdent = 928;
00119 r.hLevel = 7;
00120 r.cType = 0x17;
00121 r.targetIdent = 1023;
00122 requireHeader(hdr);
00123 loadRequire(msg, &r);
00124 CHECK(parseDiscoverHeader(&dh, hdr) == 0);
00125 CHECK(parseDiscoverMessage(&dm, &dh, msg) == 0);
00126
00127 CHECK_EQUAL(r.nodeIdent, dm.nodeIdent);
00128 CHECK_EQUAL(r.hLevel, dm.hLevel);
00129 CHECK_EQUAL(r.cType, dm.cType);
00130 CHECK_EQUAL(r.targetIdent, dm.targetIdent);
00131 }
00132
00133
00134 TEST(share_test) {
00135 unsigned char hdr[DISCOVERY_HEADER_SIZE], msg[REPORT_SIZE + 10];
00136 DiscoverHeader dh;
00137 DiscoverMessage dm;
00138 Share s;
00139 char *ior = (char*)"dummy_ior";
00140
00141 memset(hdr, 0, DISCOVERY_HEADER_SIZE);
00142 memset(msg, 0, REPORT_SIZE + 10);
00143 s.nodeIdent = 2038461;
00144 s.hLevel = 10;
00145 s.cType = 0x02;
00146 memcpy(s.ior, ior, strlen(ior));
00147 shareHeader(hdr, &s);
00148 loadShare(msg, &s);
00149 CHECK(parseDiscoverHeader(&dh, hdr) == 0);
00150 CHECK(parseDiscoverMessage(&dm, &dh, msg) == 0);
00151
00152 CHECK_EQUAL(s.nodeIdent, dm.nodeIdent);
00153 CHECK_EQUAL(s.hLevel, dm.hLevel);
00154 CHECK_EQUAL(s.cType, dm.cType);
00155 CHECK_ARRAY_EQUAL(s.ior, dm.ior, strlen((char*)s.ior));
00156 }
00157 }