Skip to content

Commit 62e2337

Browse files
authored
[tizen_app_manager] Add integration tests (#1049)
1 parent add03cc commit 62e2337

5 files changed

Lines changed: 79 additions & 3 deletions

File tree

packages/tizen_app_manager/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 0.2.5
2+
3+
* Fix memory leak in `AppRunningContext.packageId` by freeing the native string
4+
returned by `app_context_get_package_id`.
5+
* Add 9 integration test cases.
6+
17
## 0.2.4
28

39
* Update code format.

packages/tizen_app_manager/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ To use this package, add `tizen_app_manager` as a dependency in your `pubspec.ya
1010

1111
```yaml
1212
dependencies:
13-
tizen_app_manager: ^0.2.4
13+
tizen_app_manager: ^0.2.5
1414
```
1515
1616
### Retrieving current app info

packages/tizen_app_manager/example/integration_test/tizen_app_manager_test.dart

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
import 'package:flutter/services.dart';
56
import 'package:flutter_test/flutter_test.dart';
67
import 'package:integration_test/integration_test.dart';
78
import 'package:tizen_app_manager/tizen_app_manager.dart';
@@ -35,4 +36,70 @@ void main() {
3536
expect(context.processId, isPositive);
3637
expect(context.isTerminated, isFalse);
3738
});
39+
40+
group('AppManager', () {
41+
group('getInstalledApps', () {
42+
testWidgets('returns non-empty list', (WidgetTester _) async {
43+
final List<AppInfo> apps = await AppManager.getInstalledApps();
44+
expect(apps, isNotEmpty);
45+
});
46+
47+
testWidgets('includes the current app', (WidgetTester _) async {
48+
final String appId = await AppManager.currentAppId;
49+
final List<AppInfo> apps = await AppManager.getInstalledApps();
50+
expect(apps.any((AppInfo app) => app.appId == appId), isTrue);
51+
});
52+
});
53+
54+
group('isRunning', () {
55+
testWidgets('returns true for running app', (WidgetTester _) async {
56+
final String appId = await AppManager.currentAppId;
57+
expect(await AppManager.isRunning(appId), isTrue);
58+
});
59+
60+
testWidgets('returns false for non-running app', (WidgetTester _) async {
61+
expect(
62+
await AppManager.isRunning('org.tizen.nonexistent'),
63+
isFalse,
64+
);
65+
});
66+
67+
testWidgets('throws ArgumentError for empty appId',
68+
(WidgetTester _) async {
69+
await expectLater(AppManager.isRunning(''), throwsArgumentError);
70+
});
71+
});
72+
73+
group('getAppInfo', () {
74+
testWidgets('returns all AppInfo fields', (WidgetTester _) async {
75+
final String appId = await AppManager.currentAppId;
76+
final AppInfo appInfo = await AppManager.getAppInfo(appId);
77+
expect(appInfo.appId, appId);
78+
expect(appInfo.executablePath, isNotEmpty);
79+
expect(appInfo.sharedResourcePath, isNotEmpty);
80+
});
81+
82+
testWidgets('throws ArgumentError for empty appId',
83+
(WidgetTester _) async {
84+
await expectLater(AppManager.getAppInfo(''), throwsArgumentError);
85+
});
86+
});
87+
});
88+
89+
group('AppRunningContext', () {
90+
testWidgets('packageId matches current app', (WidgetTester _) async {
91+
final String appId = await AppManager.currentAppId;
92+
final AppRunningContext context = AppRunningContext(appId: appId);
93+
expect(context.packageId, 'org.tizen.tizen_app_manager_example');
94+
});
95+
96+
testWidgets('throws PlatformException for non-running appId', (
97+
WidgetTester _,
98+
) async {
99+
expect(
100+
() => AppRunningContext(appId: 'org.tizen.nonexistent'),
101+
throwsA(isA<PlatformException>()),
102+
);
103+
});
104+
});
38105
}

packages/tizen_app_manager/lib/src/app_context.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ class AppContext {
7373
if (ret != 0) {
7474
_throwPlatformException(ret);
7575
}
76-
return packageId.value.toDartString();
76+
final Pointer<Char> pkgId = packageId.value;
77+
final String result = pkgId.toDartString();
78+
malloc.free(pkgId);
79+
return result;
7780
});
7881
}
7982

packages/tizen_app_manager/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: tizen_app_manager
22
description: Tizen application manager APIs. Used to get app info and app running context on a Tizen device.
33
homepage: https://github.com/flutter-tizen/plugins
44
repository: https://github.com/flutter-tizen/plugins/tree/master/packages/tizen_app_manager
5-
version: 0.2.4
5+
version: 0.2.5
66

77
environment:
88
sdk: ">=3.1.0 <4.0.0"

0 commit comments

Comments
 (0)