LCOV - code coverage report
Current view: top level - Users/duwen/Documents/code/dio/dio/test - formdata_test.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 36 36 100.0 %
Date: 2021-11-28 14:37:50 Functions: 0 0 -

          Line data    Source code
       1             : // Copyright (c) 2014, the Dart project authors.  Please see the AUTHORS file
       2             : // for details. All rights reserved. Use of this source code is governed by a
       3             : // BSD-style license that can be found in the LICENSE file.
       4             : @TestOn('vm')
       5             : import 'dart:convert';
       6             : import 'dart:io';
       7             : import 'package:dio/dio.dart';
       8             : import 'package:test/test.dart';
       9             : 
      10           1 : void main() async {
      11           2 :   test('#test FormData', () async {
      12           2 :     var fm = FormData.fromMap({
      13             :       'name': 'wendux',
      14             :       'age': 25,
      15           2 :       'file': MultipartFile.fromString('hello world.', headers: {
      16           1 :         'test': <String>['a']
      17             :       }),
      18           1 :       'files': [
      19           2 :         await MultipartFile.fromFile(
      20             :           '../dio/test/_testfile',
      21             :           filename: '1.txt',
      22           1 :           headers: {
      23           1 :             'test': <String>['b']
      24             :           },
      25             :         ),
      26           1 :         MultipartFile.fromFileSync(
      27             :           '../dio/test/_testfile',
      28             :           filename: '2.txt',
      29           1 :           headers: {
      30           1 :             'test': <String>['c']
      31             :           },
      32             :         ),
      33             :       ]
      34             :     });
      35           2 :     var fmStr = await fm.readAsBytes();
      36           1 :     var f = File('../dio/test/_formdata');
      37           1 :     var content = f.readAsStringSync();
      38           2 :     content = content.replaceAll('--dio-boundary-3788753558', fm.boundary);
      39           1 :     var actual = utf8.decode(fmStr, allowMalformed: true);
      40             : 
      41           1 :     actual = actual.replaceAll('\r\n', '\n');
      42           1 :     content = content.replaceAll('\r\n', '\n');
      43             : 
      44           1 :     expect(actual, content);
      45           3 :     expect(fm.readAsBytes(), throwsA(const TypeMatcher<StateError>()));
      46             : 
      47           1 :     var fm1 = FormData();
      48           3 :     fm1.fields.add(MapEntry('name', 'wendux'));
      49           3 :     fm1.fields.add(MapEntry('age', '25'));
      50           3 :     fm1.files.add(MapEntry(
      51             :       'file',
      52           2 :       MultipartFile.fromString('hello world.', headers: {
      53           1 :         'test': <String>['a']
      54             :       }),
      55             :     ));
      56           3 :     fm1.files.add(MapEntry(
      57             :       'files',
      58           2 :       await MultipartFile.fromFile('../dio/test/_testfile',
      59             :           filename: '1.txt',
      60           1 :           headers: {
      61           1 :             'test': <String>['b']
      62             :           }),
      63             :     ));
      64           3 :     fm1.files.add(MapEntry(
      65             :       'files',
      66           2 :       await MultipartFile.fromFile('../dio/test/_testfile',
      67             :           filename: '2.txt',
      68           1 :           headers: {
      69           1 :             'test': <String>['c']
      70             :           }),
      71             :     ));
      72           3 :     assert(fmStr.length == fm1.length);
      73             :   });
      74             : }

Generated by: LCOV version 1.14