@@ -184,4 +184,229 @@ void main() {
184184 print ('size = ${result .size } (decoded by ${result .decoder .decoderName })' );
185185 });
186186 });
187+
188+ group ('Test async methods' , () {
189+ test ('Test getSizeAsync with gif' , () async {
190+ final file = File ('../../example/asset/dialog.gif' );
191+ final input = FileInput (file);
192+ final asyncInput = AsyncImageInput .input (input);
193+
194+ final size = await ImageSizeGetter .getSizeAsync (asyncInput);
195+ expect (size, Size (688 , 1326 ));
196+ });
197+
198+ test ('Test getSizeAsync with jpeg' , () async {
199+ final file = File ('../../example/asset/IMG_20180908_080245.jpg' );
200+ final input = FileInput (file);
201+ final asyncInput = AsyncImageInput .input (input);
202+
203+ final size = await ImageSizeGetter .getSizeAsync (asyncInput);
204+ expect (size, Size (4032 , 3024 ));
205+ });
206+
207+ test ('Test getSizeAsync with non-standard jpeg' , () async {
208+ final file = File ('../../example/asset/test.MP.jpg' );
209+ final input = FileInput (file);
210+ final asyncInput = AsyncImageInput .input (input);
211+
212+ final size = await ImageSizeGetter .getSizeAsync (asyncInput);
213+ expect (size, Size (3840 , 2160 , needRotate: true ));
214+ });
215+
216+ test ('Test getSizeAsync with png' , () async {
217+ final file = File ('../../example/asset/ic_launcher.png' );
218+ final input = FileInput (file);
219+ final asyncInput = AsyncImageInput .input (input);
220+
221+ final size = await ImageSizeGetter .getSizeAsync (asyncInput);
222+ expect (size, Size (96 , 96 ));
223+ });
224+
225+ test ('Test getSizeAsync with webp' , () async {
226+ final file = File ('../../example/asset/demo.webp' );
227+ final input = FileInput (file);
228+ final asyncInput = AsyncImageInput .input (input);
229+
230+ final size = await ImageSizeGetter .getSizeAsync (asyncInput);
231+ expect (size, Size (988 , 466 ));
232+ });
233+
234+ test ('Test getSizeAsync with webp extended format' , () async {
235+ final file = File ('../../example/asset/demo_extended.webp' );
236+ final input = FileInput (file);
237+ final asyncInput = AsyncImageInput .input (input);
238+
239+ final size = await ImageSizeGetter .getSizeAsync (asyncInput);
240+ expect (size, Size (988 , 466 ));
241+ });
242+
243+ test ('Test getSizeAsync with webp lossless format' , () async {
244+ final file = File ('../../example/asset/demo_lossless.webp' );
245+ final input = FileInput (file);
246+ final asyncInput = AsyncImageInput .input (input);
247+
248+ final size = await ImageSizeGetter .getSizeAsync (asyncInput);
249+ expect (size, Size (988 , 466 ));
250+ });
251+
252+ test ('Test getSizeAsync with bmp' , () async {
253+ final file = File ('../../example/asset/demo.bmp' );
254+ final input = FileInput (file);
255+ final asyncInput = AsyncImageInput .input (input);
256+
257+ final size = await ImageSizeGetter .getSizeAsync (asyncInput);
258+ expect (size, Size (256 , 256 ));
259+ });
260+
261+ test ('Test getSizeAsync with orientation jpeg' , () async {
262+ final file = File ('../../example/asset/have_orientation_exif_3.jpg' );
263+ final input = FileInput (file);
264+ final asyncInput = AsyncImageInput .input (input);
265+
266+ final size = await ImageSizeGetter .getSizeAsync (asyncInput);
267+ expect (size, Size (533 , 799 ));
268+
269+ final file2 = File ('../../example/asset/have_orientation_exif_6.jpg' );
270+ final input2 = FileInput (file2);
271+ final asyncInput2 = AsyncImageInput .input (input2);
272+
273+ final size2 = await ImageSizeGetter .getSizeAsync (asyncInput2);
274+ expect (size2, Size (3264 , 2448 , needRotate: true ));
275+ });
276+
277+ test ('Test getSizeResultAsync with gif' , () async {
278+ final file = File ('../../example/asset/dialog.gif' );
279+ final input = FileInput (file);
280+ final asyncInput = AsyncImageInput .input (input);
281+
282+ final result = await ImageSizeGetter .getSizeResultAsync (asyncInput);
283+ expect (result.size, Size (688 , 1326 ));
284+ expect (result.decoder.decoderName, 'gif' );
285+ });
286+
287+ test ('Test getSizeResultAsync with jpeg' , () async {
288+ final file = File ('../../example/asset/IMG_20180908_080245.jpg' );
289+ final input = FileInput (file);
290+ final asyncInput = AsyncImageInput .input (input);
291+
292+ final result = await ImageSizeGetter .getSizeResultAsync (asyncInput);
293+ expect (result.size, Size (4032 , 3024 ));
294+ expect (result.decoder.decoderName, 'jpeg' );
295+ });
296+
297+ test ('Test getSizeResultAsync with png' , () async {
298+ final file = File ('../../example/asset/ic_launcher.png' );
299+ final input = FileInput (file);
300+ final asyncInput = AsyncImageInput .input (input);
301+
302+ final result = await ImageSizeGetter .getSizeResultAsync (asyncInput);
303+ expect (result.size, Size (96 , 96 ));
304+ expect (result.decoder.decoderName, 'png' );
305+ });
306+
307+ test ('Test getSizeResultAsync with webp' , () async {
308+ final file = File ('../../example/asset/demo.webp' );
309+ final input = FileInput (file);
310+ final asyncInput = AsyncImageInput .input (input);
311+
312+ final result = await ImageSizeGetter .getSizeResultAsync (asyncInput);
313+ expect (result.size, Size (988 , 466 ));
314+ expect (result.decoder.decoderName, 'webp' );
315+ });
316+
317+ test ('Test getSizeResultAsync with bmp' , () async {
318+ final file = File ('../../example/asset/demo.bmp' );
319+ final input = FileInput (file);
320+ final asyncInput = AsyncImageInput .input (input);
321+
322+ final result = await ImageSizeGetter .getSizeResultAsync (asyncInput);
323+ expect (result.size, Size (256 , 256 ));
324+ expect (result.decoder.decoderName, 'bmp' );
325+ });
326+
327+ test ('Test getSizeAsync with non-existent file' , () async {
328+ final file = File ('../../example/asset/non_existent.jpg' );
329+ final input = FileInput (file);
330+ final asyncInput = AsyncImageInput .input (input);
331+
332+ expect (
333+ () async => await ImageSizeGetter .getSizeAsync (asyncInput),
334+ throwsA (isA <StateError >()),
335+ );
336+ });
337+
338+ test ('Test getSizeResultAsync with non-existent file' , () async {
339+ final file = File ('../../example/asset/non_existent.jpg' );
340+ final input = FileInput (file);
341+ final asyncInput = AsyncImageInput .input (input);
342+
343+ expect (
344+ () async => await ImageSizeGetter .getSizeResultAsync (asyncInput),
345+ throwsA (isA <StateError >()),
346+ );
347+ });
348+
349+ test ('Test getSizeAsync with unsupported format' , () async {
350+ // Create a temporary file with unsupported content
351+ final tempFile = File ('../../example/asset/temp_unsupported.txt' );
352+ await tempFile.writeAsString ('This is not an image file' );
353+
354+ try {
355+ final input = FileInput (tempFile);
356+ final asyncInput = AsyncImageInput .input (input);
357+
358+ expect (
359+ () async => await ImageSizeGetter .getSizeAsync (asyncInput),
360+ throwsA (isA <UnsupportedError >()),
361+ );
362+ } finally {
363+ // Clean up
364+ if (await tempFile.exists ()) {
365+ await tempFile.delete ();
366+ }
367+ }
368+ });
369+
370+ test ('Test getSizeResultAsync with unsupported format' , () async {
371+ // Create a temporary file with unsupported content
372+ final tempFile = File ('../../example/asset/temp_unsupported2.txt' );
373+ await tempFile.writeAsString ('This is not an image file' );
374+
375+ try {
376+ final input = FileInput (tempFile);
377+ final asyncInput = AsyncImageInput .input (input);
378+
379+ expect (
380+ () async => await ImageSizeGetter .getSizeResultAsync (asyncInput),
381+ throwsA (isA <UnsupportedError >()),
382+ );
383+ } finally {
384+ // Clean up
385+ if (await tempFile.exists ()) {
386+ await tempFile.delete ();
387+ }
388+ }
389+ });
390+
391+ test ('Test getSizeAsync with memory input via AsyncImageInput' , () async {
392+ final file = File ('../../example/asset/ic_launcher.png' );
393+ final bytes = await file.readAsBytes ();
394+ final memoryInput = MemoryInput (bytes);
395+ final asyncInput = AsyncImageInput .input (memoryInput);
396+
397+ final size = await ImageSizeGetter .getSizeAsync (asyncInput);
398+ expect (size, Size (96 , 96 ));
399+ });
400+
401+ test ('Test getSizeResultAsync with memory input via AsyncImageInput' , () async {
402+ final file = File ('../../example/asset/ic_launcher.png' );
403+ final bytes = await file.readAsBytes ();
404+ final memoryInput = MemoryInput (bytes);
405+ final asyncInput = AsyncImageInput .input (memoryInput);
406+
407+ final result = await ImageSizeGetter .getSizeResultAsync (asyncInput);
408+ expect (result.size, Size (96 , 96 ));
409+ expect (result.decoder.decoderName, 'png' );
410+ });
411+ });
187412}
0 commit comments