@@ -38,6 +38,7 @@ void main() {
38
38
1.0
39
39
]));
40
40
});
41
+
41
42
test ('with mipmaps' , () async {
42
43
final BitmapDescriptor descriptor =
43
44
await BitmapDescriptor .createFromAsset (
@@ -54,6 +55,7 @@ void main() {
54
55
1.0
55
56
]));
56
57
});
58
+
57
59
test ('with size and without mipmaps' , () async {
58
60
final double devicePixelRatio = WidgetsBinding
59
61
.instance.platformDispatcher.views.first.devicePixelRatio;
@@ -142,12 +144,63 @@ void main() {
142
144
}, skip: ! kIsWeb);
143
145
});
144
146
147
+ group ('fromBytes constructor' , () {
148
+ test ('with empty byte array, throws assertion error' , () {
149
+ expect (() {
150
+ BitmapDescriptor .fromBytes (Uint8List .fromList (< int > []));
151
+ }, throwsAssertionError);
152
+ });
153
+
154
+ test ('with bytes' , () {
155
+ final BitmapDescriptor descriptor = BitmapDescriptor .fromBytes (
156
+ Uint8List .fromList (< int > [1 , 2 , 3 ]),
157
+ );
158
+ expect (descriptor, isA <BitmapDescriptor >());
159
+ expect (
160
+ descriptor.toJson (),
161
+ equals (< Object > [
162
+ 'fromBytes' ,
163
+ < int > [1 , 2 , 3 ],
164
+ ]));
165
+ });
166
+
167
+ test ('with size, not on the web, size is ignored' , () {
168
+ final BitmapDescriptor descriptor = BitmapDescriptor .fromBytes (
169
+ Uint8List .fromList (< int > [1 , 2 , 3 ]),
170
+ size: const Size (40 , 20 ),
171
+ );
172
+
173
+ expect (
174
+ descriptor.toJson (),
175
+ equals (< Object > [
176
+ 'fromBytes' ,
177
+ < int > [1 , 2 , 3 ],
178
+ ]));
179
+ }, skip: kIsWeb);
180
+
181
+ test ('with size, on the web, size is preserved' , () {
182
+ final BitmapDescriptor descriptor = BitmapDescriptor .fromBytes (
183
+ Uint8List .fromList (< int > [1 , 2 , 3 ]),
184
+ size: const Size (40 , 20 ),
185
+ );
186
+
187
+ expect (
188
+ descriptor.toJson (),
189
+ equals (< Object > [
190
+ 'fromBytes' ,
191
+ < int > [1 , 2 , 3 ],
192
+ < int > [40 , 20 ],
193
+ ]));
194
+ }, skip: ! kIsWeb);
195
+ });
196
+
145
197
group ('fromJson validation' , () {
146
198
group ('type validation' , () {
147
199
test ('correct type' , () {
148
200
expect (BitmapDescriptor .fromJson (< dynamic > ['defaultMarker' ]),
149
201
isA <BitmapDescriptor >());
150
202
});
203
+
151
204
test ('wrong type' , () {
152
205
expect (() {
153
206
BitmapDescriptor .fromJson (< dynamic > ['bogusType' ]);
@@ -159,15 +212,18 @@ void main() {
159
212
expect (BitmapDescriptor .fromJson (< dynamic > ['defaultMarker' ]),
160
213
isA <BitmapDescriptor >());
161
214
});
215
+
162
216
test ('hue is number' , () {
163
217
expect (BitmapDescriptor .fromJson (< dynamic > ['defaultMarker' , 158 ]),
164
218
isA <BitmapDescriptor >());
165
219
});
220
+
166
221
test ('hue is not number' , () {
167
222
expect (() {
168
223
BitmapDescriptor .fromJson (< dynamic > ['defaultMarker' , 'nope' ]);
169
224
}, throwsAssertionError);
170
225
});
226
+
171
227
test ('hue is out of range' , () {
172
228
expect (() {
173
229
BitmapDescriptor .fromJson (< dynamic > ['defaultMarker' , - 1 ]);
@@ -186,6 +242,7 @@ void main() {
186
242
]),
187
243
isA <BitmapDescriptor >());
188
244
});
245
+
189
246
test ('without bytes' , () {
190
247
expect (() {
191
248
BitmapDescriptor .fromJson (< dynamic > ['fromBytes' , null ]);
@@ -202,6 +259,7 @@ void main() {
202
259
< dynamic > ['fromAsset' , 'some/path.png' ]),
203
260
isA <BitmapDescriptor >());
204
261
});
262
+
205
263
test ('name cannot be null or empty' , () {
206
264
expect (() {
207
265
BitmapDescriptor .fromJson (< dynamic > ['fromAsset' , null ]);
@@ -210,12 +268,14 @@ void main() {
210
268
BitmapDescriptor .fromJson (< dynamic > ['fromAsset' , '' ]);
211
269
}, throwsAssertionError);
212
270
});
271
+
213
272
test ('package is passed' , () {
214
273
expect (
215
274
BitmapDescriptor .fromJson (
216
275
< dynamic > ['fromAsset' , 'some/path.png' , 'some_package' ]),
217
276
isA <BitmapDescriptor >());
218
277
});
278
+
219
279
test ('package cannot be null or empty' , () {
220
280
expect (() {
221
281
BitmapDescriptor .fromJson (
@@ -262,6 +322,7 @@ void main() {
262
322
BitmapDescriptor .fromJson (< dynamic > ['fromAssetImage' , '' , 1.0 ]);
263
323
}, throwsAssertionError);
264
324
});
325
+
265
326
test ('dpi must be number' , () {
266
327
expect (() {
267
328
BitmapDescriptor .fromJson (
@@ -272,6 +333,7 @@ void main() {
272
333
< dynamic > ['fromAssetImage' , 'some/path.png' , 'one' ]);
273
334
}, throwsAssertionError);
274
335
});
336
+
275
337
test ('with optional [width, height] List' , () {
276
338
expect (
277
339
BitmapDescriptor .fromJson (< dynamic > [
@@ -282,6 +344,7 @@ void main() {
282
344
]),
283
345
isA <BitmapDescriptor >());
284
346
});
347
+
285
348
test (
286
349
'optional [width, height] List cannot be null or not contain 2 elements' ,
287
350
() {
@@ -303,6 +366,124 @@ void main() {
303
366
}, throwsAssertionError);
304
367
});
305
368
});
369
+
370
+ group ('bytes' , () {
371
+ test ('with bytes' , () {
372
+ expect (
373
+ BitmapDescriptor .fromJson (< dynamic > [
374
+ 'bytes' ,
375
+ Uint8List .fromList (< int > [1 , 2 , 3 ]),
376
+ 'auto' ,
377
+ 3.0 ,
378
+ ]),
379
+ isA <BitmapDescriptor >());
380
+ });
381
+
382
+ test ('without bytes' , () {
383
+ expect (() {
384
+ BitmapDescriptor .fromJson (< dynamic > ['bytes' , null , 'auto' , 3.0 ]);
385
+ }, throwsAssertionError);
386
+ expect (() {
387
+ BitmapDescriptor .fromJson (
388
+ < dynamic > ['bytes' , < dynamic > [], 'auto' , 3.0 ]);
389
+ }, throwsAssertionError);
390
+ });
391
+
392
+ test (
393
+ 'optional [width, height] List cannot be null or not contain 2 elements' ,
394
+ () {
395
+ expect (() {
396
+ BitmapDescriptor .fromJson (
397
+ < dynamic > ['bytes' , < dynamic > [], 'auto' , 3.0 , null ]);
398
+ }, throwsAssertionError);
399
+ expect (() {
400
+ BitmapDescriptor .fromJson (
401
+ < dynamic > ['bytes' , < dynamic > [], 'auto' , 3.0 , < dynamic > []]);
402
+ }, throwsAssertionError);
403
+ expect (() {
404
+ BitmapDescriptor .fromJson (< dynamic > [
405
+ 'bytes' ,
406
+ < dynamic > [],
407
+ 'auto' ,
408
+ 3.0 ,
409
+ < dynamic > [640 , 480 , 1024 ]
410
+ ]);
411
+ }, throwsAssertionError);
412
+ });
413
+ });
414
+
415
+ group ('asset' , () {
416
+ test ('name and dpi passed' , () {
417
+ expect (
418
+ BitmapDescriptor .fromJson (
419
+ < dynamic > ['asset' , 'some/path.png' , 'auto' , 1.0 ]),
420
+ isA <BitmapDescriptor >());
421
+ });
422
+
423
+ test ('name cannot be null or empty' , () {
424
+ expect (() {
425
+ BitmapDescriptor .fromJson (< dynamic > ['asset' , null , 'auto' , 1.0 ]);
426
+ }, throwsAssertionError);
427
+ expect (() {
428
+ BitmapDescriptor .fromJson (< dynamic > ['asset' , '' , 'auto' , 1.0 ]);
429
+ }, throwsAssertionError);
430
+ });
431
+
432
+ test ('dpi must be number' , () {
433
+ expect (() {
434
+ BitmapDescriptor .fromJson (
435
+ < dynamic > ['asset' , 'auto' , 'some/path.png' , null ]);
436
+ }, throwsAssertionError);
437
+ expect (() {
438
+ BitmapDescriptor .fromJson (
439
+ < dynamic > ['asset' , 'auto' , 'some/path.png' , 'one' ]);
440
+ }, throwsAssertionError);
441
+ });
442
+
443
+ test ('with optional [width, height] List' , () {
444
+ expect (
445
+ BitmapDescriptor .fromJson (< dynamic > [
446
+ 'asset' ,
447
+ 'some/path.png' ,
448
+ 'auto' ,
449
+ 1.0 ,
450
+ < dynamic > [640 , 480 ]
451
+ ]),
452
+ isA <BitmapDescriptor >());
453
+ });
454
+
455
+ test (
456
+ 'optional [width, height] List cannot be null or not contain 2 elements' ,
457
+ () {
458
+ expect (() {
459
+ BitmapDescriptor .fromJson (< dynamic > [
460
+ 'fromAssetImage' ,
461
+ 'some/path.png' ,
462
+ 'auto' ,
463
+ 1.0 ,
464
+ null
465
+ ]);
466
+ }, throwsAssertionError);
467
+ expect (() {
468
+ BitmapDescriptor .fromJson (< dynamic > [
469
+ 'fromAssetImage' ,
470
+ 'some/path.png' ,
471
+ 'auto' ,
472
+ 1.0 ,
473
+ < dynamic > []
474
+ ]);
475
+ }, throwsAssertionError);
476
+ expect (() {
477
+ BitmapDescriptor .fromJson (< dynamic > [
478
+ 'asset' ,
479
+ 'some/path.png' ,
480
+ 'auto' ,
481
+ 1.0 ,
482
+ < dynamic > [640 , 480 , 1024 ]
483
+ ]);
484
+ }, throwsAssertionError);
485
+ });
486
+ });
306
487
});
307
488
});
308
489
}
0 commit comments