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