@@ -7,15 +7,33 @@ import 'dart:io';
7
7
import 'package:flutter_test/flutter_test.dart' ;
8
8
import 'package:path_provider_platform_interface/path_provider_platform_interface.dart' ;
9
9
import 'package:path_provider_windows/path_provider_windows.dart' ;
10
+ import 'package:path_provider_windows/src/path_provider_windows_real.dart'
11
+ show languageEn, encodingCP1252, encodingUnicode;
10
12
11
13
// A fake VersionInfoQuerier that just returns preset responses.
12
14
class FakeVersionInfoQuerier implements VersionInfoQuerier {
13
- FakeVersionInfoQuerier (this .responses);
15
+ FakeVersionInfoQuerier (
16
+ this .responses, {
17
+ this .language = languageEn,
18
+ this .encoding = encodingUnicode,
19
+ });
14
20
21
+ final String language;
22
+ final String encoding;
15
23
final Map <String , String > responses;
16
24
17
- String ? getStringValue (Pointer <Uint8 >? versionInfo, String key) =>
18
- responses[key];
25
+ String ? getStringValue (
26
+ Pointer <Uint8 >? versionInfo,
27
+ String key, {
28
+ required String language,
29
+ required String encoding,
30
+ }) {
31
+ if (language == this .language && encoding == this .encoding) {
32
+ return responses[key];
33
+ } else {
34
+ return null ;
35
+ }
36
+ }
19
37
}
20
38
21
39
void main () {
@@ -40,12 +58,26 @@ void main() {
40
58
expect (path, endsWith (r'flutter_tester' ));
41
59
}, skip: ! Platform .isWindows);
42
60
43
- test ('getApplicationSupportPath with full version info' , () async {
61
+ test ('getApplicationSupportPath with full version info in CP1252 ' , () async {
44
62
final PathProviderWindows pathProvider = PathProviderWindows ();
45
63
pathProvider.versionInfoQuerier = FakeVersionInfoQuerier (< String , String > {
46
64
'CompanyName' : 'A Company' ,
47
65
'ProductName' : 'Amazing App' ,
48
- });
66
+ }, language: languageEn, encoding: encodingCP1252);
67
+ final String ? path = await pathProvider.getApplicationSupportPath ();
68
+ expect (path, isNotNull);
69
+ if (path != null ) {
70
+ expect (path, endsWith (r'AppData\Roaming\A Company\Amazing App' ));
71
+ expect (Directory (path).existsSync (), isTrue);
72
+ }
73
+ }, skip: ! Platform .isWindows);
74
+
75
+ test ('getApplicationSupportPath with full version info in Unicode' , () async {
76
+ final PathProviderWindows pathProvider = PathProviderWindows ();
77
+ pathProvider.versionInfoQuerier = FakeVersionInfoQuerier (< String , String > {
78
+ 'CompanyName' : 'A Company' ,
79
+ 'ProductName' : 'Amazing App' ,
80
+ }, language: languageEn, encoding: encodingUnicode);
49
81
final String ? path = await pathProvider.getApplicationSupportPath ();
50
82
expect (path, isNotNull);
51
83
if (path != null ) {
@@ -54,6 +86,21 @@ void main() {
54
86
}
55
87
}, skip: ! Platform .isWindows);
56
88
89
+ test (
90
+ 'getApplicationSupportPath with full version info in Unsupported Encoding' ,
91
+ () async {
92
+ final PathProviderWindows pathProvider = PathProviderWindows ();
93
+ pathProvider.versionInfoQuerier = FakeVersionInfoQuerier (< String , String > {
94
+ 'CompanyName' : 'A Company' ,
95
+ 'ProductName' : 'Amazing App' ,
96
+ }, language: '0000' , encoding: '0000' );
97
+ final String ? path = await pathProvider.getApplicationSupportPath ();
98
+ expect (path, contains (r'C:\' ));
99
+ expect (path, contains (r'AppData' ));
100
+ // The last path component should be the executable name.
101
+ expect (path, endsWith (r'flutter_tester' ));
102
+ }, skip: ! Platform .isWindows);
103
+
57
104
test ('getApplicationSupportPath with missing company' , () async {
58
105
final PathProviderWindows pathProvider = PathProviderWindows ();
59
106
pathProvider.versionInfoQuerier = FakeVersionInfoQuerier (< String , String > {
0 commit comments