Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2015, the Fletch project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Fletch project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
| 4 | 4 |
| 5 import 'package:expect/expect.dart'; | 5 import 'package:expect/expect.dart'; |
| 6 import 'package:mdns/src/constants.dart'; | |
| 6 import 'package:mdns/src/packet.dart'; | 7 import 'package:mdns/src/packet.dart'; |
| 7 | 8 |
| 8 main() { | 9 main() { |
| 9 testValidPackages(); | 10 testValidPackages(); |
| 10 testBadPackages(); | 11 testBadPackages(); |
| 11 testHexDumpList(); | 12 testHexDumpList(); |
| 13 testPTRRData(); | |
| 14 testSRVRData(); | |
| 12 } | 15 } |
| 13 | 16 |
| 14 testValidPackages() { | 17 testValidPackages() { |
| 15 var result; | 18 var result; |
| 16 result = decodeMDnsResponse(package1); | 19 result = decodeMDnsResponse(package1); |
| 17 Expect.equals(1, result.length); | 20 Expect.equals(1, result.length); |
| 18 Expect.equals('raspberrypi.local', result[0].name); | 21 Expect.equals('raspberrypi.local', result[0].name); |
| 19 Expect.equals('192.168.1.191', result[0].address.address); | 22 Expect.equals('192.168.1.191', result[0].address.address); |
| 20 | 23 |
| 21 result = decodeMDnsResponse(package2); | 24 result = decodeMDnsResponse(package2); |
| 22 Expect.equals(2, result.length); | 25 Expect.equals(2, result.length); |
| 23 Expect.equals('raspberrypi.local', result[0].name); | 26 Expect.equals('raspberrypi.local', result[0].name); |
| 24 Expect.equals('192.168.1.191', result[0].address.address); | 27 Expect.equals('192.168.1.191', result[0].address.address); |
| 25 Expect.equals('raspberrypi.local', result[1].name); | 28 Expect.equals('raspberrypi.local', result[1].name); |
| 26 Expect.equals('169.254.95.83', result[1].address.address); | 29 Expect.equals('169.254.95.83', result[1].address.address); |
| 27 | 30 |
| 28 result = decodeMDnsResponse(package3); | 31 result = decodeMDnsResponse(package3); |
| 29 Expect.equals(8, result.length); | 32 Expect.equals(8, result.length); |
| 30 Expect.equals(""" | 33 Expect.equals(""" |
| 31 RR 16 [0] | 34 RR 16 [0] |
|
karlklose
2015/11/12 10:37:06
These tests already test PTR, SRV, and TXT decodin
| |
| 32 RR 12 raspberrypi._udisks-ssh._tcp.local | 35 RR 12 raspberrypi._udisks-ssh._tcp.local |
| 33 RR 33 raspberrypi.local | 36 RR 33 raspberrypi.local |
| 34 RR 16 [0] | 37 RR 16 [0] |
| 35 RR 12 _udisks-ssh._tcp.local | 38 RR 12 _udisks-ssh._tcp.local |
| 36 RR 12 raspberrypi [b8:27:eb:03:92:4b]._workstation._tcp.local | 39 RR 12 raspberrypi [b8:27:eb:03:92:4b]._workstation._tcp.local |
| 37 RR 33 raspberrypi.local | 40 RR 33 raspberrypi.local |
| 38 RR 12 _workstation._tcp.local""", | 41 RR 12 _workstation._tcp.local""", |
| 39 result.join('\n')); | 42 result.join('\n')); |
| 40 | 43 |
| 41 result = decodeMDnsResponse(packagePtrResponse); | 44 result = decodeMDnsResponse(packagePtrResponse); |
| 42 Expect.equals(6, result.length); | 45 Expect.equals(6, result.length); |
| 43 Expect.equals(""" | 46 Expect.equals(""" |
| 44 RR 12 fletch-agent on raspberrypi._fletch_agent._tcp.local | 47 RR 12 fletch-agent on raspberrypi._fletch_agent._tcp.local |
| 45 RR 16 [0] | 48 RR 16 [0] |
| 46 RR 33 raspberrypi.local | 49 RR 33 raspberrypi.local |
| 47 RR 28 [254, 128, 0, 0, 0, 0, 0, 0, 186, 39, 235, 255, 254, 105, 110, 58] | 50 RR 28 [254, 128, 0, 0, 0, 0, 0, 0, 186, 39, 235, 255, 254, 105, 110, 58] |
| 48 RR 1 InternetAddress('192.168.1.1', IP_V4) | 51 RR 1 InternetAddress('192.168.1.1', IP_V4) |
| 49 RR 1 InternetAddress('169.254.167.172', IP_V4)""", | 52 RR 1 InternetAddress('169.254.167.172', IP_V4)""", |
| 50 result.join('\n')); | 53 result.join('\n')); |
| 51 } | 54 } |
| 52 | 55 |
| 53 testBadPackages() { | 56 testBadPackages() { |
| 54 for (var p in [package1, package2, package3]) { | 57 for (var p in [package1, package2, package3]) { |
| 55 for (int i = 0; i < p.length; i++) { | 58 for (int i = 0; i < p.length; i++) { |
| 56 decodeMDnsResponse(p.sublist(0, i)); | 59 decodeMDnsResponse(p.sublist(0, i)); |
| 57 } | 60 } |
| 58 } | 61 } |
| 59 } | 62 } |
| 60 | 63 |
| 64 testPTRRData() { | |
| 65 Expect.equals( | |
| 66 'sgjesse-macbookpro2 [78:31:c1:b8:55:38]._workstation._tcp.local', | |
| 67 readFQDN(ptrRData)); | |
| 68 print(readFQDN(ptrRData2)); | |
| 69 Expect.equals('fletch-agent._fletch_agent._tcp.local', readFQDN(ptrRData2)); | |
| 70 } | |
| 71 | |
| 72 testSRVRData() { | |
| 73 Expect.equals('fletch.local', readFQDN(srvRData, srvHeaderSize)); | |
| 74 } | |
| 75 | |
| 61 testHexDumpList() { | 76 testHexDumpList() { |
| 62 // Call hexDumpList to get rid of hint. | 77 // Call hexDumpList to get rid of hint. |
| 63 formatHexStream(""); | 78 formatHexStream(""); |
| 64 hexDumpList([]); | 79 hexDumpList([]); |
| 65 } | 80 } |
| 66 | 81 |
| 67 // One address. | 82 // One address. |
| 68 var package1 = [ | 83 var package1 = [ |
| 69 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, 0x00, 0x01, | 84 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, 0x00, 0x01, |
| 70 0x00, 0x00, 0x00, 0x00, 0x0b, 0x72, 0x61, 0x73, | 85 0x00, 0x00, 0x00, 0x00, 0x0b, 0x72, 0x61, 0x73, |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 137 0x69, 0xc0, 0x1f, 0xc0, 0x6d, 0x00, 0x1c, 0x80, | 152 0x69, 0xc0, 0x1f, 0xc0, 0x6d, 0x00, 0x1c, 0x80, |
| 138 0x01, 0x00, 0x00, 0x00, 0x78, 0x00, 0x10, 0xfe, | 153 0x01, 0x00, 0x00, 0x00, 0x78, 0x00, 0x10, 0xfe, |
| 139 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xba, | 154 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xba, |
| 140 0x27, 0xeb, 0xff, 0xfe, 0x69, 0x6e, 0x3a, 0xc0, | 155 0x27, 0xeb, 0xff, 0xfe, 0x69, 0x6e, 0x3a, 0xc0, |
| 141 0x6d, 0x00, 0x01, 0x80, 0x01, 0x00, 0x00, 0x00, | 156 0x6d, 0x00, 0x01, 0x80, 0x01, 0x00, 0x00, 0x00, |
| 142 0x78, 0x00, 0x04, 0xc0, 0xa8, 0x01, 0x01, 0xc0, | 157 0x78, 0x00, 0x04, 0xc0, 0xa8, 0x01, 0x01, 0xc0, |
| 143 0x6d, 0x00, 0x01, 0x80, 0x01, 0x00, 0x00, 0x00, | 158 0x6d, 0x00, 0x01, 0x80, 0x01, 0x00, 0x00, 0x00, |
| 144 0x78, 0x00, 0x04, 0xa9, 0xfe, 0xa7, 0xac | 159 0x78, 0x00, 0x04, 0xa9, 0xfe, 0xa7, 0xac |
| 145 ]; | 160 ]; |
| 146 | 161 |
| 162 var ptrRData = <int>[ | |
| 163 0x27, 0x73, 0x67, 0x6a, 0x65, 0x73, 0x73, 0x65, | |
| 164 0x2d, 0x6d, 0x61, 0x63, 0x62, 0x6f, 0x6f, 0x6b, | |
| 165 0x70, 0x72, 0x6f, 0x32, 0x20, 0x5b, 0x37, 0x38, | |
| 166 0x3a, 0x33, 0x31, 0x3a, 0x63, 0x31, 0x3a, 0x62, | |
| 167 0x38, 0x3a, 0x35, 0x35, 0x3a, 0x33, 0x38, 0x5d, | |
| 168 0x0c, 0x5f, 0x77, 0x6f, 0x72, 0x6b, 0x73, 0x74, | |
| 169 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x04, 0x5f, 0x74, | |
| 170 0x63, 0x70, 0x05, 0x6c, 0x6f, 0x63, 0x61, 0x6c, | |
| 171 0x00 | |
| 172 ]; | |
| 173 | |
| 174 var ptrRData2 = <int>[ | |
| 175 0x0c, 0x66, 0x6c, 0x65, 0x74, 0x63, 0x68, 0x2d, | |
| 176 0x61, 0x67, 0x65, 0x6e, 0x74, 0x0d, 0x5f, 0x66, | |
| 177 0x6c, 0x65, 0x74, 0x63, 0x68, 0x5f, 0x61, 0x67, | |
| 178 0x65, 0x6e, 0x74, 0x04, 0x5f, 0x74, 0x63, 0x70, | |
| 179 0x05, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x00 | |
| 180 ]; | |
| 181 | |
| 182 var srvRData = <int> [ | |
| 183 0x00, 0x00, 0x00, 0x00, 0x2f, 0x59, 0x06, 0x66, | |
| 184 0x6c, 0x65, 0x74, 0x63, 0x68, 0x05, 0x6c, 0x6f, | |
| 185 0x63, 0x61, 0x6c, 0x00 | |
| 186 ]; | |
| 187 | |
| 147 // Support code to generate the hex-lists above from | 188 // Support code to generate the hex-lists above from |
| 148 // a hex-stream. | 189 // a hex-stream. |
| 149 void formatHexStream(String hexStream) { | 190 void formatHexStream(String hexStream) { |
| 150 var s = ''; | 191 var s = ''; |
| 151 for (int i = 0; i < hexStream.length / 2; i++) { | 192 for (int i = 0; i < hexStream.length / 2; i++) { |
| 152 if (s.length != 0) s += ', '; | 193 if (s.length != 0) s += ', '; |
| 153 s += '0x'; | 194 s += '0x'; |
| 154 var x = hexStream.substring(i * 2, i * 2 + 2); | 195 var x = hexStream.substring(i * 2, i * 2 + 2); |
| 155 s += x; | 196 s += x; |
| 156 if (((i + 1) % 8) == 0) { | 197 if (((i + 1) % 8) == 0) { |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 172 if (x.length == 1) s += '0'; | 213 if (x.length == 1) s += '0'; |
| 173 s += x; | 214 s += x; |
| 174 if (((i + 1) % 8) == 0) { | 215 if (((i + 1) % 8) == 0) { |
| 175 s += ','; | 216 s += ','; |
| 176 print(s); | 217 print(s); |
| 177 s = ''; | 218 s = ''; |
| 178 } | 219 } |
| 179 } | 220 } |
| 180 if (s.length != 0) print(s); | 221 if (s.length != 0) print(s); |
| 181 } | 222 } |
| OLD | NEW |