Commit 799678f0 authored by Danny Tuppeny's avatar Danny Tuppeny Committed by Danny Tuppeny

Add some tests around device+ini parsing

parent 4c67885b
...@@ -81,12 +81,12 @@ void extractEmulatorAvdInfo(String text, List<AndroidEmulator> emulators) { ...@@ -81,12 +81,12 @@ void extractEmulatorAvdInfo(String text, List<AndroidEmulator> emulators) {
AndroidEmulator _createEmulator(String id) { AndroidEmulator _createEmulator(String id) {
id = id.trim(); id = id.trim();
final File iniFile = fs.file(fs.path.join(getAvdPath(), '$id.ini')); final File iniFile = fs.file(fs.path.join(getAvdPath(), '$id.ini'));
final Map<String, String> ini = _parseIniLines(iniFile.readAsLinesSync()); final Map<String, String> ini = parseIniLines(iniFile.readAsLinesSync());
if (ini['path'] != null) { if (ini['path'] != null) {
final File configFile = fs.file(fs.path.join(ini['path'], 'config.ini')); final File configFile = fs.file(fs.path.join(ini['path'], 'config.ini'));
if (configFile.existsSync()) { if (configFile.existsSync()) {
final Map<String, String> properties = _parseIniLines(configFile.readAsLinesSync()); final Map<String, String> properties = parseIniLines(configFile.readAsLinesSync());
return new AndroidEmulator(id, properties); return new AndroidEmulator(id, properties);
} }
} }
...@@ -94,9 +94,8 @@ AndroidEmulator _createEmulator(String id) { ...@@ -94,9 +94,8 @@ AndroidEmulator _createEmulator(String id) {
return new AndroidEmulator(id); return new AndroidEmulator(id);
} }
// TODO: Tests
@visibleForTesting @visibleForTesting
Map<String, String> _parseIniLines(List<String> contents) { Map<String, String> parseIniLines(List<String> contents) {
final Map<String, String> results = <String, String>{}; final Map<String, String> results = <String, String>{};
final Iterable<List<String>> properties = contents final Iterable<List<String>> properties = contents
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter_tools/src/android/android_emulator.dart';
import 'package:test/test.dart';
import '../src/context.dart';
void main() {
group('android_emulator', () {
testUsingContext('flags emulators without config', () {
const String emulatorID = '1234';
final AndroidEmulator emulator = new AndroidEmulator(emulatorID);
expect(emulator.id, emulatorID);
expect(emulator.hasConfig, false);
});
testUsingContext('flags emulators with config', () {
const String emulatorID = '1234';
final AndroidEmulator emulator =
new AndroidEmulator(emulatorID, <String, String>{'name': 'test'});
expect(emulator.id, emulatorID);
expect(emulator.hasConfig, true);
});
testUsingContext('stores expected metadata', () {
const String emulatorID = '1234';
const String name = 'My Test Name';
const String manufacturer = 'Me';
const String label = 'The best one';
final Map<String, String> properties = <String, String>{
'hw.device.name': name,
'hw.device.manufacturer': manufacturer,
'avd.ini.displayname': label
};
final AndroidEmulator emulator =
new AndroidEmulator(emulatorID, properties);
expect(emulator.id, emulatorID);
expect(emulator.name, name);
expect(emulator.manufacturer, manufacturer);
expect(emulator.label, label);
});
testUsingContext('parses ini files', () {
const String iniFile = '''
hw.device.name=My Test Name
#hw.device.name=Bad Name
hw.device.manufacturer=Me
avd.ini.displayname = dispName
''';
final Map<String, String> results = parseIniLines(iniFile.split('\n'));
expect(results['hw.device.name'], 'My Test Name');
expect(results['hw.device.manufacturer'], 'Me');
expect(results['avd.ini.displayname'], 'dispName');
});
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment