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

COVERAGE SUMMARY FOR SOURCE FILE [AddressBlock.java]

nameclass, %method, %block, %line, %
AddressBlock.java100% (2/2)86%  (12/14)73%  (363/497)80%  (60,6/76)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class AddressBlock100% (1/1)90%  (9/10)70%  (308/437)79%  (57,8/73)
toString (): String 0%   (0/1)0%   (0/22)0%   (0/3)
parse (byte [], int, int): int 100% (1/1)61%  (94/154)71%  (16,3/23)
setAddress (byte []): void 100% (1/1)71%  (68/96)74%  (10,4/14)
generate (byte [], int): int 100% (1/1)80%  (59/74)87%  (12,2/14)
<static initializer> 100% (1/1)88%  (7/8)87%  (0,9/1)
$SWITCH_TABLE$cz$vutbr$feec$packets$rsi$AddressBlock$Type (): int [] 100% (1/1)91%  (31/34)91%  (0,9/1)
AddressBlock (AddressBlock$Type): void 100% (1/1)100% (39/39)100% (14/14)
getAddress (): byte [] 100% (1/1)100% (3/3)100% (1/1)
getPort (): int 100% (1/1)100% (3/3)100% (1/1)
setPort (int): void 100% (1/1)100% (4/4)100% (2/2)
     
class AddressBlock$Type100% (1/1)75%  (3/4)92%  (55/60)92%  (2,8/3)
valueOf (String): AddressBlock$Type 0%   (0/1)0%   (0/5)0%   (0/1)
<static initializer> 100% (1/1)100% (34/34)100% (2/2)
AddressBlock$Type (String, int): void 100% (1/1)100% (5/5)100% (1/1)
values (): AddressBlock$Type [] 100% (1/1)100% (16/16)100% (1/1)

1package cz.vutbr.feec.packets.rsi;
2 
3import cz.vutbr.feec.packets.PacketGenerateException;
4import cz.vutbr.feec.packets.PacketParseException;
5import cz.vutbr.feec.packets.PacketUtils;
6import org.apache.commons.lang.builder.ToStringBuilder;
7 
8public class AddressBlock extends SubReportBlock {
9        private int port = -1;
10        private byte[] address;
11 
12        public enum Type {
13                IPv4, IPv6, DNS
14        }
15 
16        public AddressBlock(Type type) {
17                switch (type) {
18                case IPv4:
19                        this.setType(0);
20                        this.length = 4 + 4;
21                        this.address = new byte[4];
22                        break;
23                case IPv6:
24                        this.setType(1);
25                        this.length = 4 + 16;
26                        this.address = new byte[16];
27                        break;
28                case DNS:
29                        this.setType(2);
30                        this.length = 4 + 4;
31                        break;
32                }
33        }
34 
35        @Override
36        public int generate(byte[] array, int offset)
37                        throws PacketGenerateException {
38                assert this.getType() == ipv4Address || this.getType() == ipv6Address
39                                || this.getType() == dnsUnicastFeedback;
40                int len = super.generate(array, offset);
41                PacketUtils.setOctet2(array, offset+2, this.port);
42                if (this.getType() == ipv6Address) {
43                        len += 2 + 4 * 4;
44                        System.arraycopy(this.address, 0, array, 4 + offset, 4 * 4);
45                } else if (this.getType() == ipv4Address) {
46                        len += 2 + 4;
47                        System.arraycopy(array, offset + 4, this.address, 0, 4);
48                } else {
49                        System.arraycopy(this.address, 0, array, 4 + offset,
50                                        this.address.length);
51                        len = this.length;
52                }
53                return len;
54        }
55 
56        @Override
57        public int parse(byte[] array, int offset, int packetlength)
58                        throws PacketParseException {
59                int len = super.parse(array, offset, packetlength);
60                assert this.getType() == ipv4Address || this.getType() == ipv6Address
61                                || this.getType() == dnsUnicastFeedback;
62                assert this.length == 8 || this.length == 4 + 16;
63 
64                this.port = PacketUtils.getOctet2(array, offset + 2);
65                len += 2;
66                if (this.getType() == ipv4Address) {
67                        assert this.getType() == ipv4Address;
68                        if (array.length < offset + 4 + 4) {
69                                throw new PacketParseException("Received packet is too short.");
70                        }
71                        // IPv4
72                        System.arraycopy(array, 4 + offset, this.address, 0, 4);
73                        return len + 4;
74                } else if (this.getType() == ipv6Address) {
75                        if (array.length < offset + 4 + 16) {
76                                throw new PacketParseException("Received packet is too short.");
77                        }
78                        assert this.getType() == ipv6Address;
79                        // IPv6
80                        System.arraycopy(array, 4 + offset, this.address, 0, 4 * 4);
81                        return len + 4 * 4;
82                } else {
83                        assert this.getType() == dnsUnicastFeedback;
84                        this.address = new byte[packetlength - 4];
85                        System.arraycopy(array, 4 + offset, this.address, 0,
86                                        packetlength - 4);
87                        return packetlength - 4;
88                }
89        }
90 
91        public void setAddress(byte[] addr) {
92                if (getType() == 0) {
93                        assert addr.length == 4;
94                        System.arraycopy(addr, 0, this.address, 0, 4);
95                } else if (getType() == 1) {
96                        assert addr.length == 16;
97                        System.arraycopy(addr, 0, this.address, 0, 16);
98                } else if (getType() == 2) {
99                        this.length = 4 + 4 * ((addr.length + 1 + 3) / 4);
100                        this.address = new byte[addr.length + 1];
101                        System.arraycopy(addr, 0, this.address, 0, addr.length);
102                        this.address[addr.length] = 0;
103                } else {
104                        throw new RuntimeException("Zatim neimlementovano pro typ: "
105                                        + getType());
106                }
107        }
108 
109        public int getPort() {
110                return port;
111        }
112 
113        public void setPort(int port) {
114                this.port = port;
115        }
116 
117        public byte[] getAddress() {
118                return address;
119        }
120 
121        /**
122         * @see java.lang.Object#toString()
123         */
124        public String toString() {
125                return new ToStringBuilder(this).append("port", this.port).append(
126                                "type", this.getType()).append("length", this.length).append(
127                                "address", this.address).toString();
128        }
129 
130}

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