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

Unified 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: Addressed review comments Created 5 years, 2 months 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 side-by-side diff with in-line comments
Download patch
Index: pkg/mdns/test/decode_test.dart
diff --git a/pkg/mdns/test/decode_test.dart b/pkg/mdns/test/decode_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..905a2319e6ea9d71d37d386836481c752ef7627b
--- /dev/null
+++ b/pkg/mdns/test/decode_test.dart
@@ -0,0 +1,111 @@
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'package:expect/expect.dart';
+import 'package:mdns/src/packet.dart';
+
+main() {
+ testValidPackages();
+ testBadPackages();
+}
+
+testValidPackages() {
+ var result;
+ result = decodeMDnsResponse(package1);
+ Expect.equals(1, result.length);
+ Expect.equals('raspberrypi.local', result[0].name);
+ Expect.equals('192.168.1.191', result[0].address.address);
+
+ result = decodeMDnsResponse(package2);
+ Expect.equals(2, result.length);
+ Expect.equals('raspberrypi.local', result[0].name);
+ Expect.equals('192.168.1.191', result[0].address.address);
+ Expect.equals('raspberrypi.local', result[1].name);
+ Expect.equals('169.254.95.83', result[1].address.address);
+
+ // This packet has no IPv4 address.
+ result = decodeMDnsResponse(package3);
+ Expect.equals(0, result.length);
+}
+
+testBadPackages() {
+ for (var p in [package1, package2, package3]) {
+ for (int i = 0; i < p.length; i++) {
+ decodeMDnsResponse(p.sublist(0, i));
+ }
+ }
+}
+
+// One address.
+var package1 = [
+ 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, 0x00, 0x01,
+ 0x00, 0x00, 0x00, 0x00, 0x0b, 0x72, 0x61, 0x73,
+ 0x70, 0x62, 0x65, 0x72, 0x72, 0x79, 0x70, 0x69,
+ 0x05, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x00, 0x00,
+ 0x01, 0x80, 0x01, 0x00, 0x00, 0x00, 0x78, 0x00,
+ 0x04, 0xc0, 0xa8, 0x01, 0xbf];
+
+// Two addresses.
+var package2 = [
+ 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, 0x00, 0x02,
+ 0x00, 0x00, 0x00, 0x00, 0x0b, 0x72, 0x61, 0x73,
+ 0x70, 0x62, 0x65, 0x72, 0x72, 0x79, 0x70, 0x69,
+ 0x05, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x00, 0x00,
+ 0x01, 0x80, 0x01, 0x00, 0x00, 0x00, 0x78, 0x00,
+ 0x04, 0xc0, 0xa8, 0x01, 0xbf, 0xc0, 0x0c, 0x00,
+ 0x01, 0x80, 0x01, 0x00, 0x00, 0x00, 0x78, 0x00,
+ 0x04, 0xa9, 0xfe, 0x5f, 0x53];
+
+// Seven mixed answers.
+var package3 = [
+ 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, 0x00, 0x08,
+ 0x00, 0x00, 0x00, 0x00, 0x1f, 0x72, 0x61, 0x73,
+ 0x70, 0x62, 0x65, 0x72, 0x72, 0x79, 0x70, 0x69,
+ 0x20, 0x5b, 0x62, 0x38, 0x3a, 0x32, 0x37, 0x3a,
+ 0x65, 0x62, 0x3a, 0x30, 0x33, 0x3a, 0x39, 0x32,
+ 0x3a, 0x34, 0x62, 0x5d, 0x0c, 0x5f, 0x77, 0x6f,
+ 0x72, 0x6b, 0x73, 0x74, 0x61, 0x74, 0x69, 0x6f,
+ 0x6e, 0x04, 0x5f, 0x74, 0x63, 0x70, 0x05, 0x6c,
+ 0x6f, 0x63, 0x61, 0x6c, 0x00, 0x00, 0x10, 0x80,
+ 0x01, 0x00, 0x00, 0x11, 0x94, 0x00, 0x01, 0x00,
+ 0x0b, 0x5f, 0x75, 0x64, 0x69, 0x73, 0x6b, 0x73,
+ 0x2d, 0x73, 0x73, 0x68, 0xc0, 0x39, 0x00, 0x0c,
+ 0x00, 0x01, 0x00, 0x00, 0x11, 0x94, 0x00, 0x0e,
+ 0x0b, 0x72, 0x61, 0x73, 0x70, 0x62, 0x65, 0x72,
+ 0x72, 0x79, 0x70, 0x69, 0xc0, 0x50, 0xc0, 0x68,
+ 0x00, 0x21, 0x80, 0x01, 0x00, 0x00, 0x00, 0x78,
+ 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16,
+ 0x0b, 0x72, 0x61, 0x73, 0x70, 0x62, 0x65, 0x72,
+ 0x72, 0x79, 0x70, 0x69, 0xc0, 0x3e, 0xc0, 0x68,
+ 0x00, 0x10, 0x80, 0x01, 0x00, 0x00, 0x11, 0x94,
+ 0x00, 0x01, 0x00, 0x09, 0x5f, 0x73, 0x65, 0x72,
+ 0x76, 0x69, 0x63, 0x65, 0x73, 0x07, 0x5f, 0x64,
+ 0x6e, 0x73, 0x2d, 0x73, 0x64, 0x04, 0x5f, 0x75,
+ 0x64, 0x70, 0xc0, 0x3e, 0x00, 0x0c, 0x00, 0x01,
+ 0x00, 0x00, 0x11, 0x94, 0x00, 0x02, 0xc0, 0x50,
+ 0xc0, 0x2c, 0x00, 0x0c, 0x00, 0x01, 0x00, 0x00,
+ 0x11, 0x94, 0x00, 0x02, 0xc0, 0x0c, 0xc0, 0x0c,
+ 0x00, 0x21, 0x80, 0x01, 0x00, 0x00, 0x00, 0x78,
+ 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09,
+ 0xc0, 0x88, 0xc0, 0xa3, 0x00, 0x0c, 0x00, 0x01,
+ 0x00, 0x00, 0x11, 0x94, 0x00, 0x02, 0xc0, 0x2c];
+
+// Support code for generating the hex-lists above.
+void hexDumpList(List package) {
+ var s = '';
+ for (int i = 0; i < package.length; i++) {
+ if (s.length != 0) s += ', ';
+ s += '0x';
+ var x = package[i].toRadixString(16);
+ if (x.length == 1) s += '0';
+ s += x;
+ if (((i + 1) % 8) == 0) {
+ s += ',';
+ print(s);
+ s = '';
+ }
+ }
+ if (s.length != 0) print(s);
+}
+

Powered by Google App Engine
This is Rietveld 408576698