android_emulator_test.dart 3 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5
// 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';
6
import 'package:flutter_tools/src/device.dart';
7

8 9
import '../../src/common.dart';
import '../../src/context.dart';
10 11 12 13 14

void main() {
  group('android_emulator', () {
    testUsingContext('flags emulators without config', () {
      const String emulatorID = '1234';
15
      final AndroidEmulator emulator = AndroidEmulator(emulatorID);
16 17 18 19 20 21
      expect(emulator.id, emulatorID);
      expect(emulator.hasConfig, false);
    });
    testUsingContext('flags emulators with config', () {
      const String emulatorID = '1234';
      final AndroidEmulator emulator =
22
          AndroidEmulator(emulatorID, <String, String>{'name': 'test'});
23 24 25
      expect(emulator.id, emulatorID);
      expect(emulator.hasConfig, true);
    });
26
    testUsingContext('reads expected metadata', () {
27 28
      const String emulatorID = '1234';
      const String manufacturer = 'Me';
29
      const String displayName = 'The best one';
30 31
      final Map<String, String> properties = <String, String>{
        'hw.device.manufacturer': manufacturer,
32
        'avd.ini.displayname': displayName,
33 34
      };
      final AndroidEmulator emulator =
35
          AndroidEmulator(emulatorID, properties);
36
      expect(emulator.id, emulatorID);
37
      expect(emulator.name, displayName);
38
      expect(emulator.manufacturer, manufacturer);
39 40
      expect(emulator.category, Category.mobile);
      expect(emulator.platformType, PlatformType.android);
41
    });
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
    testUsingContext('prefers displayname for name', () {
      const String emulatorID = '1234';
      const String displayName = 'The best one';
      final Map<String, String> properties = <String, String>{
        'avd.ini.displayname': displayName,
      };
      final AndroidEmulator emulator =
          AndroidEmulator(emulatorID, properties);
      expect(emulator.name, displayName);
    });
    testUsingContext('uses cleaned up ID if no displayname is set', () {
      // Android Studio uses the ID with underscores replaced with spaces
      // for the name if displayname is not set so we do the same.
      const String emulatorID = 'This_is_my_ID';
      final Map<String, String> properties = <String, String>{
        'avd.ini.notadisplayname': 'this is not a display name',
      };
      final AndroidEmulator emulator =
          AndroidEmulator(emulatorID, properties);
      expect(emulator.name, 'This is my ID');
    });
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
    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');
    });
  });
}