-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
dart_tags_test.dart
171 lines (144 loc) · 4.35 KB
/
dart_tags_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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
@TestOn('vm')
import 'dart:io';
import 'package:dart_tags/dart_tags.dart';
import 'package:dart_tags/src/readers/id3v1.dart';
import 'package:dart_tags/src/readers/id3v2.dart';
import 'package:dart_tags/src/writers/id3v1.dart';
import 'package:dart_tags/src/writers/id3v2.dart';
import 'package:test/test.dart';
void main() {
File file1;
File file2;
setUp(() {
file1 = File('test/test_assets/id3v1.mp3');
file2 = File('test/test_assets/id3v24.mp3');
});
group('Writer Tests', () {
test('generate tag block v2.4', () async {
final tag = Tag()
..tags = {
'title': 'foo',
'artist': 'bar',
'album': 'baz',
'year': '2010',
'comment': 'lol it is a comment',
'track': '6',
'genre': 'Dream',
'custom': 'Just a tag',
'APIC': AttachedPicture()
..imageData = [
0x00,
0x01,
0x02,
0x03,
0x00,
0x01,
0x02,
0x03,
0x00,
0x01,
0x02,
0x03,
0x00,
0x01,
0x02,
0x03
]
..imageTypeCode = 0x03
..mime = 'image/jpeg'
..description = 'foo.jpg'
}
..type = 'ID3'
..version = '2.4';
final writer = ID3V2Writer();
final blocks = writer.write(await file1.readAsBytes(), tag);
final r = ID3V2Reader();
final f = await r.read(blocks);
expect(f.tags, equals(tag.tags));
});
test('generate tag block v1.1', () async {
final tag = Tag()
..tags = {
'title': 'foo',
'artist': 'bar',
'album': 'baz',
'year': '2010',
'comment': 'lol it is a comment',
'track': '6',
'genre': 'Dream'
}
..type = 'ID3'
..version = '1.1';
final writer = ID3V1Writer();
final blocks = writer.write(await file1.readAsBytes(), tag);
final r = ID3V1Reader();
final f = await r.read(blocks);
expect(f, equals(tag));
});
test('put blocks', () async {
final tag1 = Tag()
..tags = {
'title': 'foo',
'artist': 'bar',
'album': 'baz',
'year': '2010',
'comment': 'lol it is a comment',
'track': '6',
'genre': 'Dream'
}
..type = 'ID3'
..version = '1.1';
final tag2 = Tag()
..tags = {
'title': 'foo',
'artist': 'bar',
'album': 'baz',
'year': '2010',
'comment': 'lol it is a comment',
'track': '6',
'genre': 'Dream',
'Custom': 'Just tag'
}
..type = 'ID3'
..version = '2.4';
final _av = () async =>
[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00];
final foo = await TagProcessor().putTagsToByteArray(_av(), [tag1, tag2]);
final _fr = () async => foo;
final rdr1 = ID3V1Reader();
final t1 = await rdr1.read(_fr());
expect(t1.tags, equals(tag1.tags));
final rdr2 = ID3V2Reader();
final t2 = await rdr2.read(_fr());
expect(t2.tags, equals(tag2.tags));
});
});
group('Reader Tests', () {
test('Test with file 1.1', () async {
final foo = await TagProcessor()
.getTagsFromByteArray(file1.readAsBytes(), [TagType.id3v1]);
expect(foo.length, equals(1));
expect(foo[0].type, equals('ID3'));
expect(foo[0].version, equals('1.1'));
});
test('Test with file 2.4', () async {
final foo = await TagProcessor()
.getTagsFromByteArray(file2.readAsBytes(), [TagType.id3v2]);
expect(foo.length, equals(1));
expect(foo[0].type, equals('ID3'));
expect(foo[0].version, equals('2.4.0'));
});
test('Test on Failure', () async {
expect(
() async => await TagProcessor().getTagsFromByteArray(null),
throwsA(predicate<Exception>((e) =>
e is ParsingException &&
e.cause == ParsingException.byteArrayNull)));
expect(
() async => await TagProcessor().getTagsFromByteData(null),
throwsA(predicate<Exception>((e) =>
e is ParsingException &&
e.cause == ParsingException.byteDataNull)));
});
});
}