@@ -7,15 +7,33 @@ import 'dart:io';
77import 'package:flutter_test/flutter_test.dart' ;
88import 'package:path_provider_platform_interface/path_provider_platform_interface.dart' ;
99import '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;
1012
1113// A fake VersionInfoQuerier that just returns preset responses.
1214class FakeVersionInfoQuerier implements VersionInfoQuerier {
13- FakeVersionInfoQuerier (this .responses);
15+ FakeVersionInfoQuerier (
16+ this .responses, {
17+ this .language = languageEn,
18+ this .encoding = encodingUnicode,
19+ });
1420
21+ final String language;
22+ final String encoding;
1523 final Map <String , String > responses;
1624
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+ }
1937}
2038
2139void main () {
@@ -40,12 +58,26 @@ void main() {
4058 expect (path, endsWith (r'flutter_tester' ));
4159 }, skip: ! Platform .isWindows);
4260
43- test ('getApplicationSupportPath with full version info' , () async {
61+ test ('getApplicationSupportPath with full version info in CP1252 ' , () async {
4462 final PathProviderWindows pathProvider = PathProviderWindows ();
4563 pathProvider.versionInfoQuerier = FakeVersionInfoQuerier (< String , String > {
4664 'CompanyName' : 'A Company' ,
4765 '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);
4981 final String ? path = await pathProvider.getApplicationSupportPath ();
5082 expect (path, isNotNull);
5183 if (path != null ) {
@@ -54,6 +86,21 @@ void main() {
5486 }
5587 }, skip: ! Platform .isWindows);
5688
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+
57104 test ('getApplicationSupportPath with missing company' , () async {
58105 final PathProviderWindows pathProvider = PathProviderWindows ();
59106 pathProvider.versionInfoQuerier = FakeVersionInfoQuerier (< String , String > {
0 commit comments