forked from dart-archive/dart-protoc-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwire_format_test.dart
executable file
·79 lines (62 loc) · 2.48 KB
/
wire_format_test.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env dart
// Copyright (c) 2013, 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.
library wire_format_test;
import 'package:protobuf/protobuf.dart';
import 'package:test/test.dart';
import '../out/protos/google/protobuf/unittest.pb.dart';
import 'test_util.dart';
void main() {
test('testSerialization', () {
assertAllFieldsSet(
new TestAllTypes.fromBuffer(getAllSet().writeToBuffer()));
});
test('testSerializationPacked', () {
assertPackedFieldsSet(
new TestPackedTypes.fromBuffer(getPackedSet().writeToBuffer()));
});
test('testSerializeExtensions', () {
assertAllFieldsSet(
new TestAllTypes.fromBuffer(getAllExtensionsSet().writeToBuffer()));
});
test('testSerializePackedExtensions', () {
expect(getPackedExtensionsSet().writeToBuffer(),
getPackedSet().writeToBuffer());
});
test('testParseExtensions', () {
// TestAllTypes and TestAllExtensions should have compatible wire formats,
// so if we serialize a TestAllTypes then parse it as TestAllExtensions
// it should work.
List<int> rawBytes = getAllSet().writeToBuffer();
ExtensionRegistry registry = getExtensionRegistry();
assertAllExtensionsSet(
new TestAllExtensions.fromBuffer(rawBytes, registry));
});
test('testParsePackedExtensions', () {
// Ensure that packed extensions can be properly parsed.
List<int> rawBytes = getPackedExtensionsSet().writeToBuffer();
ExtensionRegistry registry = getExtensionRegistry();
assertPackedExtensionsSet(
new TestPackedExtensions.fromBuffer(rawBytes, registry));
});
test('testExtensionsSerialized', () {
expect(getAllExtensionsSet().writeToBuffer(), getAllSet().writeToBuffer());
});
test('testParseMultipleExtensionRanges', () {
// Make sure we can parse a message that contains multiple extensions
// ranges.
TestFieldOrderings source = new TestFieldOrderings()
..myInt = make64(1)
..myString = 'foo'
..myFloat = 1.0
..setExtension(Unittest.myExtensionInt, 23)
..setExtension(Unittest.myExtensionString, 'bar');
ExtensionRegistry registry = new ExtensionRegistry()
..add(Unittest.myExtensionInt)
..add(Unittest.myExtensionString);
TestFieldOrderings dest =
new TestFieldOrderings.fromBuffer(source.writeToBuffer(), registry);
expect(dest, source);
});
}