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 package sensix.test;
00036
00037 import junit.framework.*;
00038 import sensix.*;
00039 import sensix.discovery.*;
00040 import sensix.sensing.*;
00041
00042
00043 public class DiscoveryTest extends TestCase
00044 {
00045 public void testEndian() {
00046 int test = 5;
00047 assertEquals(test, DiscoveryService.b2i(DiscoveryService.i2b(test)));
00048 test = 83886080;
00049 assertEquals(test, DiscoveryService.b2i(DiscoveryService.i2b(test)));
00050 if (test == DiscoveryService.b2i_le(DiscoveryService.i2b(test)))
00051 fail("LittleEndian conversion should not equal a BigEndian value");
00052 }
00053
00054 public void testAnnounce() {
00055 int hdr_size = DiscoveryService.HEADER_SIZE;
00056 byte[] hdr, body;
00057 DiscoverMessage dm = null;
00058
00059 Announce a = new Announce(11, (byte)3);
00060 hdr = DiscoveryService.announceHeader();
00061 body = DiscoveryService.loadAnnounce(a);
00062 try {
00063 DiscoverMessageHeader dh = new DiscoverMessageHeader(hdr);
00064 dm = new DiscoverMessage(dh, body);
00065 } catch (DiscoverMessageException dme) {
00066 fail("Discover Message exception: " + dme.toString());
00067 }
00068 assertEquals(a.nodeIdent, dm.nodeIdent);
00069 assertEquals(a.hLevel, dm.hLevel);
00070 }
00071
00072 public void testReport() {
00073 int hdr_size = DiscoveryService.HEADER_SIZE;
00074 byte[] hdr, body;
00075 DiscoverMessage dm = null;
00076
00077 Report r = new Report(1928, (byte)7, (byte)0x23);
00078 hdr = DiscoveryService.reportHeader();
00079 body = DiscoveryService.loadReport(r);
00080 try {
00081 DiscoverMessageHeader dh = new DiscoverMessageHeader(hdr);
00082 dm = new DiscoverMessage(dh, body);
00083 } catch (DiscoverMessageException dme) {
00084 fail("Discover Message exception: " + dme.toString());
00085 }
00086 assertEquals(r.nodeIdent, dm.nodeIdent);
00087 assertEquals(r.hLevel, dm.hLevel);
00088 assertEquals(r.cType, dm.cType);
00089 }
00090 }