Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions dev/integration_tests/windows_startup_test/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// found in the LICENSE file.

import 'dart:async';
import 'dart:typed_data';
import 'dart:ui' as ui;

import 'package:flutter_driver/driver_extension.dart';
Expand Down Expand Up @@ -44,6 +45,18 @@ void main() async {
return (app == system)
? 'success'
: 'error: app dark mode ($app) does not match system dark mode ($system)';
} else if (message == 'verifyStringConversion') {
// Use a test string that contains code points that fit in both 8 and 16 bits.
// The code points are passed a list of integers through the method channel,
// which will use the UTF16 to UTF8 utility function to convert them to a
// std::string, which should equate to the original expected string.
// TODO(schectman): Remove trailing null from returned string
const String expected = 'ABCℵ\x00';
final Int32List codePoints = Int32List.fromList(expected.codeUnits);
final String converted = await testStringConversion(codePoints);
return (converted == expected)
? 'success'
: 'error: conversion of UTF16 string to UTF8 failed, expected "${expected.codeUnits}" but got "${converted.codeUnits}"';
}

throw 'Unrecognized message: $message';
Expand Down
12 changes: 12 additions & 0 deletions dev/integration_tests/windows_startup_test/lib/windows.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:typed_data';

import 'package:flutter/services.dart';

const MethodChannel _kMethodChannel =
Expand Down Expand Up @@ -36,3 +38,13 @@ Future<bool> isSystemDarkModeEnabled() async {

return enabled;
}

/// Test conversion of a UTF16 string to UTF8 using the app template utils.
Future<String> testStringConversion(Int32List twoByteCodes) async {
final String? converted = await _kMethodChannel.invokeMethod<String?>('convertString', twoByteCodes);
if (converted == null) {
throw 'Method channel unavailable.';
}

return converted;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,13 @@ void main() {

await driver.close();
}, timeout: Timeout.none);

test('Windows app template can convert string from UTF16 to UTF8', () async {
final FlutterDriver driver = await FlutterDriver.connect(printCommunication: true);
final String result = await driver.requestData('verifyStringConversion');

expect(result, equals('success'));

await driver.close();
}, timeout: Timeout.none);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <flutter/standard_method_codec.h>

#include "flutter/generated_plugin_registrant.h"
#include "utils.h"

/// Window attribute that enables dark mode window decorations.
///
Expand Down Expand Up @@ -106,6 +107,15 @@ bool FlutterWindow::OnCreate() {
} else {
result->Error("error", "Received status " + status);
}
} else if (method == "convertString") {
const flutter::EncodableValue* argument = call.arguments();
const std::vector<int32_t> code_points = std::get<std::vector<int32_t>>(*argument);
std::vector<wchar_t> wide_str;
for (int32_t code_point : code_points) {
wide_str.push_back((wchar_t)(code_point));
}
const std::string string = Utf8FromUtf16(wide_str.data());
result->Success(string);
} else {
result->NotImplemented();
}
Expand Down