EMMA Coverage Report (generated Tue Dec 18 20:38:46 CET 2007)
[all classes][cz.vutbr.feec.packets.rsi]

## COVERAGE SUMMARY FOR SOURCE FILE [AddressBlockTest.java]

name | class, % | method, % | block, % | line, %
--- | --- | --- | --- | ---
AddressBlockTest.java | 100% (1/1) | 100% (4/4) | 94% (587/627) | 97% (79,9/82)

### COVERAGE BREAKDOWN BY CLASS AND METHOD

name | class, % | method, % | block, % | line, %
--- | --- | --- | --- | ---
class AddressBlockTest | 100% (1/1) | 100% (4/4) | 94% (587/627) | 97% (79,9/82)
test1 (int, AddressBlock, AddressBlock): void |  | 100% (1/1) | 92% (79/86) | 97% (11,6/12)
testDNS (int): void |  | 100% (1/1) | 92% (311/338) | 97% (45,5/47)
testAll (): void |  | 100% (1/1) | 97% (190/196) | 99% (20,8/21)
AddressBlockTest (): void |  | 100% (1/1) | 100% (7/7) | 100% (2/2)

1 | package cz.vutbr.feec.packets.rsi;
2 |
3 | import junit.framework.Assert;
4 |
5 | import org.junit.Test;
6 |
7 | import cz.vutbr.feec.packets.PacketException;
8 | import cz.vutbr.feec.packets.PacketGenerateException;
9 | import cz.vutbr.feec.packets.PacketParseException;
10 | import cz.vutbr.feec.packets.rsi.AddressBlock.Type;
11 |
12 | public class AddressBlockTest extends SubReportBlock {
13 | byte[] buf = new byte[100];
14 | // generate
15 | // read
16 | public void test1(int offset, AddressBlock g, AddressBlock r) throws PacketException {
17 | g.setPort(1111);
18 |
19 | Assert.assertTrue(g.getPort() == 1111);
20 | int pktLen = g.generate(buf, offset);
21 |
22 | int res = r.parse(buf, 0, pktLen);
23 | Assert.assertTrue(res == pktLen);
24 | res = r.parse(buf, 0, pktLen);
25 | Assert.assertTrue(res == pktLen);
26 | Assert.assertTrue(r.getPort() == g.getPort());
27 | Assert.assertTrue(r.getLength() == g.getLength());
28 | Assert.assertTrue(r.getType() == g.getType());
29 | Assert.assertTrue(g.getAddress()[0] == r.getAddress()[0]);
30 | }
31 |
32 | @Test
33 | public void testAll() throws PacketException {
34 | AddressBlock g;
35 | AddressBlock r;
36 | r = new AddressBlock(Type.IPv4);
37 | byte addr4[] = { 1, 2, 3, 4 };
38 | g = new AddressBlock(Type.IPv4);
39 | g.setAddress(addr4);
40 | Assert.assertTrue(g.getLength() == 8);
41 | Assert.assertTrue(g.getType() == 0);
42 | test1(0, g, r);
43 | test1(5, g, r);
44 |
45 | byte addr6[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
46 | g = new AddressBlock(Type.IPv6);
47 | g.setAddress(addr6);
48 | Assert.assertTrue(g.getLength() == 16+4);
49 | Assert.assertTrue(g.getType() == 1);
50 | r = new AddressBlock(Type.IPv6);
51 | test1(0, g, r);
52 | Assert.assertTrue(g.getAddress()[0] == r.getAddress()[0]);
53 | test1(5, g, r);
54 | Assert.assertTrue(g.getAddress()[0] == r.getAddress()[0]);
55 |
56 | testDNS(0);
57 | testDNS(5);
58 | }
59 |
60 | public void testDNS(int offset) throws PacketParseException, PacketGenerateException {
61 | AddressBlock g = new AddressBlock(Type.DNS);
62 | g.setPort(1555);
63 | Assert.assertTrue(g.getType() == 2);
64 | byte[] addr = "a".getBytes();
65 | g.setAddress(addr);
66 | Assert.assertTrue(g.getLength() == 8);
67 | int pktLen = g.generate(buf, offset);
68 | AddressBlock r = new AddressBlock(Type.DNS);
69 | r.parse(buf, offset, pktLen);
70 | Assert.assertTrue(g.getPort() == r.getPort());
71 | Assert.assertTrue(g.getLength() == r.getLength());
72 | Assert.assertTrue(g.getAddress()[0] == (int)'a');
73 | Assert.assertTrue(g.getAddress()[1] == 0);
74 |
75 | addr = "ab".getBytes();
76 | g.setAddress(addr);
77 | Assert.assertTrue(g.getLength() == 8);
78 | pktLen = g.generate(buf, offset);
79 | r.parse(buf, offset, pktLen);
80 | Assert.assertTrue(g.getPort() == r.getPort());
81 | Assert.assertTrue(g.getLength() == r.getLength());
82 | Assert.assertTrue(g.getAddress()[0] == (int)'a');
83 | Assert.assertTrue(g.getAddress()[1] == (int)'b');
84 | Assert.assertTrue(g.getAddress()[2] == 0);
85 |
86 | addr = "abc".getBytes();
87 | g.setAddress(addr);
88 | Assert.assertTrue(g.getLength() == 8);
89 | pktLen = g.generate(buf, offset);
90 | r.parse(buf, offset, pktLen);
91 | Assert.assertTrue(g.getPort() == r.getPort());
92 | Assert.assertTrue(g.getLength() == r.getLength());
93 | Assert.assertTrue(g.getAddress()[0] == (int)'a');
94 | Assert.assertTrue(g.getAddress()[1] == (int)'b');
95 | Assert.assertTrue(g.getAddress()[2] == (int)'c');
96 | Assert.assertTrue(g.getAddress()[3] == 0);
97 |
98 | addr = "abcd".getBytes();
99 | g.setAddress(addr);
100 | Assert.assertTrue(g.getLength() == 12);
101 | pktLen = g.generate(buf, offset);
102 | r.parse(buf, offset, pktLen);
103 | Assert.assertTrue(g.getPort() == r.getPort());
104 | Assert.assertTrue(g.getLength() == r.getLength());
105 | Assert.assertTrue(g.getAddress()[0] == (int)'a');
106 | Assert.assertTrue(g.getAddress()[1] == (int)'b');
107 | Assert.assertTrue(g.getAddress()[2] == (int)'c');
108 | Assert.assertTrue(g.getAddress()[3] == (int)'d');
109 | Assert.assertTrue(g.getAddress()[4] == 0);
110 | }
111 | }

[all classes][cz.vutbr.feec.packets.rsi]
EMMA 2.0.5312 EclEmma Fix 1 (C) Vladimir Roubtsov