Ejemplo n.º 1
0
    def _create_update_build_xml_setup(self):
        build_environment = android.BuildEnvironment(
            android.BuildEnvironment.build_defaults())
        build_environment.sdk_home = ''

        build_environment._find_best_android_sdk = (
            lambda unused_android, unused_min_sdk, unused_target_sdk: 10)

        project_directory = build_environment.get_project_directory()
        buildxml_filename = os.path.join(project_directory, 'build.xml')

        manifest = android.AndroidManifest(None)
        manifest.path = os.path.join(project_directory, 'AndroidManifest.xml')
        manifest._parse(
            FileMock(
                '<manifest '
                '  xmlns:android="http://schemas.android.com/apk/res/android"\n'
                '  package="com.google.fpl.libfplutil_test">\n'
                '  <uses-sdk android:minSdkVersion="1"/>\n'
                '  <application>\n'
                '    <activity android:name="android.app.NativeActivity">\n'
                '      <meta-data android:name="android.app.lib_name"\n'
                '                 android:value="test"/>\n'
                '    </activity>\n'
                '  </application>\n'
                '</manifest>'))

        __builtin__.open = FileMockFactory(
            self, ('<?xml version="1.0" encoding="UTF-8"?>\n'
                   '<project name="libfplutil_test" default="help">\n'
                   '</project>\n'))

        return build_environment, manifest, buildxml_filename
Ejemplo n.º 2
0
 def test_clean_libraries(self):
     d = android.BuildEnvironment.build_defaults()
     b = android.BuildEnvironment(d)
     b.clean = True
     m = common_test.RunCommandMock(self)
     b.run_subprocess = m
     ndk_build = os.path.join(b.ndk_home, 'ndk-build')
     l = 'libfoo'
     lpath = os.path.abspath(os.path.join(b.project_directory, l))
     expect = [
         ndk_build, '-j' + str(platform.mac_ver()[0] and 1 or b.cpu_count),
         '-C', lpath, 'clean'
     ]
     m.expect(expect)
     b.build_android_libraries([l])
     b.verbose = True
     expect.append('V=1')
     m.expect(expect)
     b.build_android_libraries([l])
     expect.append('NDK_OUT=%s' % lpath)
     m.expect(expect)
     b.build_android_libraries([l], output=l)
     b.make_flags = '-DFOO -DBAR -DBAZ'
     flaglist = ['-DFOO', '-DBAR', '-DBAZ']
     expect += flaglist
     m.expect(expect)
     b.build_android_libraries([l], output=l)
     common._find_executable = self.find_executable
     b.ndk_home = '/dev/null'
     with self.assertRaises(common.ToolPathError):
         b.build_android_libraries([l], output=l)
         b._parse(f)
Ejemplo n.º 3
0
 def test_get_apk_filenames_debug(self):
     build_environment = android.BuildEnvironment(
         android.BuildEnvironment.build_defaults())
     build_environment.ant_target = 'debug'
     signed_apk, unsigned_apk = build_environment.get_apk_filenames(
         'libfplutil_example')
     expected_apk = os.path.join(os.getcwd(), 'bin',
                                 'libfplutil_example-debug.apk')
     self.assertEquals(expected_apk, unsigned_apk)
     self.assertEquals(expected_apk, signed_apk)
Ejemplo n.º 4
0
 def test_get_apk_filenames(self):
     build_environment = android.BuildEnvironment(
         android.BuildEnvironment.build_defaults())
     signed_apk, unsigned_apk = build_environment.get_apk_filenames(
         'libfplutil_example')
     self.assertEquals(
         os.path.join(os.getcwd(), 'bin',
                      'libfplutil_example-release-unsigned.apk'),
         unsigned_apk)
     self.assertEquals(
         os.path.join(os.getcwd(), 'bin', 'libfplutil_example.apk'),
         signed_apk)
Ejemplo n.º 5
0
    def test_run_android_apk(self):
        os.path.exists = lambda unused_filename: True
        __builtin__.open = FileMockFactory(
            self, '<manifest '
            '  xmlns:android="http://schemas.android.com/apk/res/android"\n'
            '  package="com.google.fpl.libfplutil_test">\n'
            '  <uses-sdk android:minSdkVersion="1"/>\n'
            '  <application>\n'
            '    <activity android:name="android.app.NativeActivity">\n'
            '      <meta-data android:name="android.app.lib_name"\n'
            '                 android:value="test"/>\n'
            '    </activity>\n'
            '  </application>\n'
            '</manifest>')
        build_environment = android.BuildEnvironment(
            android.BuildEnvironment.build_defaults())

        expected_logoutput = ('Random log output\n'
                              'Some other log output\n'
                              'Another application log output.\n')
        logoutput = expected_logoutput + (
            'Displayed com.google.fpl.libfplutil_test/'
            'android.app.NativeActivity\n'
            'Line noise\n')

        # Configure the set of expected commands executed by run_android_apk.
        os.path.exists = lambda unused_filename: True
        build_environment.sdk_home = 'sdk_home'
        adb_path = build_environment._find_binary(android.BuildEnvironment.ADB)
        run_command_mock = common_test.RunCommandMockList([
            common_test.RunCommandMock(
                self,
                args='%s devices -l' % adb_path,
                stdout=(
                    'List of devices attached\n'
                    '123456\tdevice\tusb:2-3.4\tproduct:razor\tmodel:Nexus_7\t'
                    'device:flo\n')),
            common_test.RunCommandMock(self,
                                       args='%s -s 123456 logcat -c' %
                                       adb_path),
            common_test.RunCommandMock(
                self,
                args=('%s -s 123456 shell am start -S -n '
                      'com.google.fpl.libfplutil_test/'
                      'android.app.NativeActivity' % adb_path))
        ])
        build_environment.run_subprocess = run_command_mock

        subprocess.Popen = SubprocessMockStdOut(
            self, args=[adb_path, '-s', '123456', 'logcat'], stdout=logoutput)
        self.assertEquals(
            expected_logoutput,
            build_environment.run_android_apk(adb_device='123456'))
Ejemplo n.º 6
0
    def test_adb_device_to_string(self):
        build_environment = android.BuildEnvironment(
            android.BuildEnvironment.build_defaults())
        device = android.AdbDevice(
            '06d8bd43 device usb:2-3.3 product:razor model:Nexus_7 device:flo')
        self.assertEquals('06d8bd43',
                          build_environment.get_adb_device_name(device))

        build_environment.verbose = True
        self.assertEquals(
            'device:flo model:Nexus_7 product:razor serial:06d8bd43 '
            'type:device usb:2-3.3',
            build_environment.get_adb_device_name(device))
Ejemplo n.º 7
0
 def test_check_adb_devices_no_devices(self):
     build_environment = android.BuildEnvironment(
         android.BuildEnvironment.build_defaults())
     build_environment.sdk_home = 'sdk_home'
     os.path.exists = lambda unused_filename: True
     build_environment.run_subprocess = common_test.RunCommandMock(
         self,
         args='%s devices -l' %
         (build_environment._find_binary(android.BuildEnvironment.ADB)),
         stdout='List of devices attached\n\n',
         shell=True)
     with self.assertRaises(common.AdbError):
         build_environment.check_adb_devices()
Ejemplo n.º 8
0
 def test_check_adb_devices_one_device(self):
     build_environment = android.BuildEnvironment(
         android.BuildEnvironment.build_defaults())
     build_environment.sdk_home = 'sdk_home'
     os.path.exists = lambda unused_filename: True
     build_environment.run_subprocess = common_test.RunCommandMock(
         self,
         args='%s devices -l' %
         (build_environment._find_binary(android.BuildEnvironment.ADB)),
         stdout=('List of devices attached\n'
                 '06d8bd43               device usb:2-3.3 product:razor '
                 'model:Nexus_7 device:flo\n'),
         shell=True)
     device = build_environment.check_adb_devices()
     self.assertEquals('06d8bd43', device.serial)
Ejemplo n.º 9
0
 def test_check_adb_devices_specified_device_found(self):
     build_environment = android.BuildEnvironment(
         android.BuildEnvironment.build_defaults())
     build_environment.sdk_home = 'sdk_home'
     os.path.exists = lambda unused_filename: True
     build_environment.run_subprocess = common_test.RunCommandMock(
         self,
         args='%s devices -l' %
         (build_environment._find_binary(android.BuildEnvironment.ADB)),
         stdout=('List of devices attached\n'
                 '06d8bd43               device usb:2-3.3 product:razor '
                 'model:Nexus_7 device:flo\n'
                 '98aaffe123             device usb:2-3.3 product:fishy '
                 'model:Nexus_55 device:jelly\n'),
         shell=True)
     build_environment.check_adb_devices('98aaffe123')
Ejemplo n.º 10
0
 def test_init(self):
     d = android.BuildEnvironment.build_defaults()
     b = android.BuildEnvironment(d)
     # Verify that the Android ones are set.
     self.assertEqual(b.ndk_home, d[android._NDK_HOME])
     self.assertEqual(b.sdk_home, d[android._SDK_HOME])
     self.assertEqual(b.ant_path, d[android._ANT_PATH])
     self.assertEqual(b.ant_flags, d[android._ANT_FLAGS])
     self.assertEqual(b.ant_target, d[android._ANT_TARGET])
     self.assertEqual(b.apk_keystore, d[android._APK_KEYSTORE])
     self.assertEqual(b.apk_passfile, d[android._APK_PASSFILE])
     self.assertEqual(b.apk_keyalias, d[android._APK_KEYALIAS])
     self.assertEqual(b.sign_apk, d[android._SIGN_APK])
     # Verify that a mandatory superclass one gets set.
     self.assertEqual(b.project_directory, d[common._PROJECT_DIR])
     # Verify that the Linux ones do not get set.
     self.assertNotIn(linux._CMAKE_FLAGS, vars(b))
     self.assertNotIn(linux._CMAKE_PATH, vars(b))
Ejemplo n.º 11
0
 def test_check_adb_devices_multiple_devices(self):
     build_environment = android.BuildEnvironment(
         android.BuildEnvironment.build_defaults())
     build_environment.sdk_home = 'sdk_home'
     os.path.exists = lambda unused_filename: True
     build_environment.run_subprocess = common_test.RunCommandMock(
         self,
         args='%s devices -l' %
         (build_environment._find_binary(android.BuildEnvironment.ADB)),
         stdout=('Stuff to ignore\n'
                 'More stuff to ignore\n'
                 'List of devices attached\n'
                 '06d8bd43               device usb:2-3.3 product:razor '
                 'model:Nexus_7 device:flo\n'
                 '98aaffe123             device usb:2-3.3 product:fishy '
                 'model:Nexus_55 device:jelly\n'),
         shell=True)
     with self.assertRaises(common.AdbError):
         build_environment.check_adb_devices()
Ejemplo n.º 12
0
 def test_list_installed_packages(self):
     build_environment = android.BuildEnvironment(
         android.BuildEnvironment.build_defaults())
     build_environment.sdk_home = 'sdk_home'
     os.path.exists = lambda unused_filename: True
     adb_path = build_environment._find_binary(android.BuildEnvironment.ADB)
     build_environment.run_subprocess = common_test.RunCommandMock(
         self,
         args='%s -s 06d8bd43 shell pm list packages' % adb_path,
         stdout=('package:com.google.earth\n'
                 'junk\n'
                 'package:com.google.android.gsf\n'
                 'package:com.android.keyguard\n'
                 'nothing useful\n'))
     expected = [
         'com.google.earth', 'com.google.android.gsf',
         'com.android.keyguard'
     ]
     self.assertListEqual(
         expected, build_environment.list_installed_packages('06d8bd43'))
Ejemplo n.º 13
0
 def test_manifest_parse(self):
     os.path.exists = lambda unused_filename: True
     __builtin__.open = FileMockFactory(
         self, '<manifest '
         '  xmlns:android="http://schemas.android.com/apk/res/android"\n'
         '  package="com.google.fpl.libfplutil_test">\n'
         '  <uses-sdk android:minSdkVersion="1"/>\n'
         '  <application>\n'
         '    <activity android:name="android.app.NativeActivity">\n'
         '      <meta-data android:name="android.app.lib_name"\n'
         '                 android:value="test"/>\n'
         '    </activity>\n'
         '  </application>\n'
         '</manifest>')
     manifest = android.BuildEnvironment(
         android.BuildEnvironment.build_defaults()).parse_manifest()
     # Restore default file behavior for the correct display of exceptions.
     __builtin__.open = self.file_open
     self.assertEqual(manifest.min_sdk, 1)
     self.assertEqual(manifest.target_sdk, manifest.min_sdk)
Ejemplo n.º 14
0
 def test_find_android_sdk(self):
     d = android.BuildEnvironment.build_defaults()
     b = android.BuildEnvironment(d)
     m = common_test.RunCommandMock(self)
     b.run_subprocess = m
     expect = ['android', 'list', 'target', '--compact']
     m.expect(expect)
     m.returns('android-3\n'
               'android-5\n'
               'meaningless\n'
               'android-10\n'
               'android-L\n')
     got = b._find_best_android_sdk('android', 1, 5)
     self.assertEqual(got, 'android-5')
     got = b._find_best_android_sdk('android', 5, 15)
     self.assertEqual(got, 'android-10')
     got = b._find_best_android_sdk('android', 1, 2)
     self.assertEqual(got, 'android-10')
     with self.assertRaises(common.ConfigurationError):
         b._find_best_android_sdk('android', 11, 20)
     m.returns('android-10\n' 'android-15\n' 'android-7\n')
     got = b._find_best_android_sdk('android', 5, 15)
     self.assertEqual(got, 'android-15')
Ejemplo n.º 15
0
 def test_get_adb_device_argument_no_device(self):
     build_environment = android.BuildEnvironment(
         android.BuildEnvironment.build_defaults())
     self.assertEquals('', build_environment.get_adb_device_argument())
Ejemplo n.º 16
0
 def test_get_adb_device_argument(self):
     build_environment = android.BuildEnvironment(
         android.BuildEnvironment.build_defaults())
     self.assertEquals(
         '-s 06d8bd43',
         build_environment.get_adb_device_argument('06d8bd43'))
Ejemplo n.º 17
0
 def test_get_android_manifest_path(self):
     build_environment = android.BuildEnvironment(
         android.BuildEnvironment.build_defaults())
     self.assertEquals(os.path.join(os.getcwd(), 'AndroidManifest.xml'),
                       build_environment.get_manifest_path())
Ejemplo n.º 18
0
 def _find_projects_test_setup(self):
     build_environment = android.BuildEnvironment(
         android.BuildEnvironment.build_defaults())
     walk_mock = OsWalkMock(self)
     os.walk = walk_mock.walk
     return (build_environment, walk_mock)