Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(773)

Side by Side Diff: pkg/mdns/test/decode_test.dart

Issue 1426863003: Add a mDNS package (Closed) Base URL: git@github.com:dart-lang/fletch.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
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 file.
4
5 import 'package:expect/expect.dart';
6 import 'package:mdns/src/packet.dart';
7
8 main() {
9 testValidPackages();
10 testBadPackages();
11 }
12
13 testValidPackages() {
14 var result;
15 result = decodeMDNSResponse(package1);
16 Expect.equals(1, result.length);
17 Expect.equals('raspberrypi.local', result[0].name);
18 Expect.equals('192.168.1.191', result[0].address.address);
19
20 result = decodeMDNSResponse(package2);
21 Expect.equals(2, result.length);
22 Expect.equals('raspberrypi.local', result[0].name);
23 Expect.equals('192.168.1.191', result[0].address.address);
24 Expect.equals('raspberrypi.local', result[1].name);
25 Expect.equals('169.254.95.83', result[1].address.address);
26
27 // This packet has no IPv4 address.
28 result = decodeMDNSResponse(package3);
29 Expect.equals(0, result.length);
30 }
31
32 testBadPackages() {
33 for (var p in [package1, package2, package3]) {
34 for (int i = 0; i < p.length; i++) {
35 decodeMDNSResponse(p.sublist(0, i));
36 }
37 }
38 }
39
40 // One address.
41 var package1 = [
42 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, 0x00, 0x01,
43 0x00, 0x00, 0x00, 0x00, 0x0b, 0x72, 0x61, 0x73,
44 0x70, 0x62, 0x65, 0x72, 0x72, 0x79, 0x70, 0x69,
45 0x05, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x00, 0x00,
46 0x01, 0x80, 0x01, 0x00, 0x00, 0x00, 0x78, 0x00,
47 0x04, 0xc0, 0xa8, 0x01, 0xbf];
48
49 // Two addresses.
50 var package2 = [
51 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, 0x00, 0x02,
52 0x00, 0x00, 0x00, 0x00, 0x0b, 0x72, 0x61, 0x73,
53 0x70, 0x62, 0x65, 0x72, 0x72, 0x79, 0x70, 0x69,
54 0x05, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x00, 0x00,
55 0x01, 0x80, 0x01, 0x00, 0x00, 0x00, 0x78, 0x00,
56 0x04, 0xc0, 0xa8, 0x01, 0xbf, 0xc0, 0x0c, 0x00,
57 0x01, 0x80, 0x01, 0x00, 0x00, 0x00, 0x78, 0x00,
58 0x04, 0xa9, 0xfe, 0x5f, 0x53];
59
60 // Seven mixed answers.
61 var package3 = [
62 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, 0x00, 0x08,
63 0x00, 0x00, 0x00, 0x00, 0x1f, 0x72, 0x61, 0x73,
64 0x70, 0x62, 0x65, 0x72, 0x72, 0x79, 0x70, 0x69,
65 0x20, 0x5b, 0x62, 0x38, 0x3a, 0x32, 0x37, 0x3a,
66 0x65, 0x62, 0x3a, 0x30, 0x33, 0x3a, 0x39, 0x32,
67 0x3a, 0x34, 0x62, 0x5d, 0x0c, 0x5f, 0x77, 0x6f,
68 0x72, 0x6b, 0x73, 0x74, 0x61, 0x74, 0x69, 0x6f,
69 0x6e, 0x04, 0x5f, 0x74, 0x63, 0x70, 0x05, 0x6c,
70 0x6f, 0x63, 0x61, 0x6c, 0x00, 0x00, 0x10, 0x80,
71 0x01, 0x00, 0x00, 0x11, 0x94, 0x00, 0x01, 0x00,
72 0x0b, 0x5f, 0x75, 0x64, 0x69, 0x73, 0x6b, 0x73,
73 0x2d, 0x73, 0x73, 0x68, 0xc0, 0x39, 0x00, 0x0c,
74 0x00, 0x01, 0x00, 0x00, 0x11, 0x94, 0x00, 0x0e,
75 0x0b, 0x72, 0x61, 0x73, 0x70, 0x62, 0x65, 0x72,
76 0x72, 0x79, 0x70, 0x69, 0xc0, 0x50, 0xc0, 0x68,
77 0x00, 0x21, 0x80, 0x01, 0x00, 0x00, 0x00, 0x78,
78 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16,
79 0x0b, 0x72, 0x61, 0x73, 0x70, 0x62, 0x65, 0x72,
80 0x72, 0x79, 0x70, 0x69, 0xc0, 0x3e, 0xc0, 0x68,
81 0x00, 0x10, 0x80, 0x01, 0x00, 0x00, 0x11, 0x94,
82 0x00, 0x01, 0x00, 0x09, 0x5f, 0x73, 0x65, 0x72,
83 0x76, 0x69, 0x63, 0x65, 0x73, 0x07, 0x5f, 0x64,
84 0x6e, 0x73, 0x2d, 0x73, 0x64, 0x04, 0x5f, 0x75,
85 0x64, 0x70, 0xc0, 0x3e, 0x00, 0x0c, 0x00, 0x01,
86 0x00, 0x00, 0x11, 0x94, 0x00, 0x02, 0xc0, 0x50,
87 0xc0, 0x2c, 0x00, 0x0c, 0x00, 0x01, 0x00, 0x00,
88 0x11, 0x94, 0x00, 0x02, 0xc0, 0x0c, 0xc0, 0x0c,
89 0x00, 0x21, 0x80, 0x01, 0x00, 0x00, 0x00, 0x78,
90 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09,
91 0xc0, 0x88, 0xc0, 0xa3, 0x00, 0x0c, 0x00, 0x01,
92 0x00, 0x00, 0x11, 0x94, 0x00, 0x02, 0xc0, 0x2c];
93
94 // Support code for generating the hex-lists above.
95 void hexDumpList(List package) {
96 var s = '';
97 for (int i = 0; i < package.length; i++) {
98 if (s.length != 0) s += ', ';
99 s += '0x';
100 var x = package[i].toRadixString(16);
101 if (x.length == 1) s += '0';
102 s += x;
103 if (((i + 1) % 8) == 0) {
104 s += ',';
105 print(s);
106 s = '';
107 }
108 }
109 if (s.length != 0) print(s);
110 }
111
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698