Skip to content

Commit bc51298

Browse files
authored
[tizen_package_manager] Add integration tests and fix icon path handling (#1055)
1 parent 5620c44 commit bc51298

4 files changed

Lines changed: 146 additions & 2 deletions

File tree

packages/tizen_package_manager/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 0.4.3
2+
3+
* Return a null icon path (instead of an empty string) when a package has no
4+
icon, and ignore `package_info_get_icon` failures since the icon is optional.
5+
* Add 12 integration test cases.
6+
17
## 0.4.2
28

39
* Remove Ecore API.

packages/tizen_package_manager/example/integration_test/tizen_package_manager_test.dart

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
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 'dart:async';
6+
7+
import 'package:flutter/services.dart';
58
import 'package:flutter_test/flutter_test.dart';
69
import 'package:integration_test/integration_test.dart';
710
import 'package:tizen_package_manager/tizen_package_manager.dart';
@@ -37,4 +40,134 @@ void main() {
3740
final List<PackageInfo> infos = await PackageManager.getPackagesInfo();
3841
expect(infos.isNotEmpty, true);
3942
});
43+
44+
group('PackageInfo fields', () {
45+
testWidgets('iconPath is null or a non-empty string', (
46+
WidgetTester tester,
47+
) async {
48+
final PackageInfo info =
49+
await PackageManager.getPackageInfo(currentPackageId);
50+
expect(info.iconPath, anyOf(isNull, isNotEmpty));
51+
});
52+
});
53+
54+
group('PackageSizeInfo fields', () {
55+
testWidgets('all size fields are non-negative', (
56+
WidgetTester tester,
57+
) async {
58+
final PackageSizeInfo info =
59+
await PackageManager.getPackageSizeInfo(currentPackageId);
60+
expect(info.dataSize, greaterThanOrEqualTo(0));
61+
expect(info.cacheSize, greaterThanOrEqualTo(0));
62+
expect(info.appSize, greaterThanOrEqualTo(0));
63+
expect(info.externalDataSize, greaterThanOrEqualTo(0));
64+
expect(info.externalCacheSize, greaterThanOrEqualTo(0));
65+
expect(info.externalAppSize, greaterThanOrEqualTo(0));
66+
});
67+
});
68+
69+
group('getPackagesInfo list items', () {
70+
testWidgets('each PackageInfo item has valid field values', (
71+
WidgetTester tester,
72+
) async {
73+
final List<PackageInfo> infos = await PackageManager.getPackagesInfo();
74+
expect(infos, isNotEmpty);
75+
for (final PackageInfo info in infos) {
76+
// Field types are already guaranteed by PackageInfo.fromMap (it casts
77+
// each field), so only the value-level expectations are asserted here.
78+
expect(info.packageId, isNotEmpty);
79+
expect(info.version, isNotEmpty);
80+
expect(info.iconPath, anyOf(isNull, isNotEmpty));
81+
}
82+
});
83+
84+
testWidgets('getPackagesInfo contains current package', (
85+
WidgetTester tester,
86+
) async {
87+
final List<PackageInfo> infos = await PackageManager.getPackagesInfo();
88+
final Iterable<String> ids = infos.map((PackageInfo i) => i.packageId);
89+
expect(ids, contains(currentPackageId));
90+
});
91+
});
92+
93+
group('getPackageInfo error paths', () {
94+
testWidgets('throws ArgumentError for empty packageId', (
95+
WidgetTester tester,
96+
) async {
97+
await expectLater(
98+
PackageManager.getPackageInfo(''),
99+
throwsArgumentError,
100+
);
101+
});
102+
103+
testWidgets('throws PlatformException for invalid packageId', (
104+
WidgetTester tester,
105+
) async {
106+
await expectLater(
107+
PackageManager.getPackageInfo('invalid.package.id.that.does.not.exist'),
108+
throwsA(isA<PlatformException>()),
109+
);
110+
});
111+
});
112+
113+
group('getPackageSizeInfo error paths', () {
114+
testWidgets('throws ArgumentError for empty packageId', (
115+
WidgetTester tester,
116+
) async {
117+
await expectLater(
118+
PackageManager.getPackageSizeInfo(''),
119+
throwsArgumentError,
120+
);
121+
});
122+
123+
// NOTE: The Tizen package_manager_get_package_size_info API does not
124+
// return an error for a non-existent package ID; it silently returns
125+
// zero-valued size info. This is a platform limitation, so no
126+
// PlatformException test is included here.
127+
});
128+
129+
group('install error paths', () {
130+
testWidgets('throws ArgumentError for empty packagePath', (
131+
WidgetTester tester,
132+
) async {
133+
await expectLater(PackageManager.install(''), throwsArgumentError);
134+
});
135+
});
136+
137+
group('uninstall error paths', () {
138+
testWidgets('throws ArgumentError for empty packageId', (
139+
WidgetTester tester,
140+
) async {
141+
await expectLater(PackageManager.uninstall(''), throwsArgumentError);
142+
});
143+
});
144+
145+
// These only verify that subscribing to and cancelling the stream does not
146+
// throw. Actually exercising an event requires installing/uninstalling/
147+
// updating a real package on the device, which is out of scope here.
148+
group('event streams', () {
149+
testWidgets('can subscribe to onInstallProgressChanged and cancel', (
150+
WidgetTester tester,
151+
) async {
152+
final StreamSubscription<PackageEvent> subscription =
153+
PackageManager.onInstallProgressChanged.listen(null);
154+
await subscription.cancel();
155+
});
156+
157+
testWidgets('can subscribe to onUninstallProgressChanged and cancel', (
158+
WidgetTester tester,
159+
) async {
160+
final StreamSubscription<PackageEvent> subscription =
161+
PackageManager.onUninstallProgressChanged.listen(null);
162+
await subscription.cancel();
163+
});
164+
165+
testWidgets('can subscribe to onUpdateProgressChanged and cancel', (
166+
WidgetTester tester,
167+
) async {
168+
final StreamSubscription<PackageEvent> subscription =
169+
PackageManager.onUpdateProgressChanged.listen(null);
170+
await subscription.cancel();
171+
});
172+
});
40173
}

packages/tizen_package_manager/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: tizen_package_manager
22
description: Tizen package manager APIs. Used to get information about packages installed on a Tizen device.
33
homepage: https://github.com/flutter-tizen/plugins
44
repository: https://github.com/flutter-tizen/plugins/tree/master/packages/tizen_package_manager
5-
version: 0.4.2
5+
version: 0.4.3
66

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

packages/tizen_package_manager/tizen/src/tizen_package_manager.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,15 @@ std::optional<PackageInfo> TizenPackageManager::GetPackageData(
110110
result.type = type;
111111
free(type);
112112

113+
// The icon path is optional: a package may have no icon, so a failure here is
114+
// not treated as fatal. Only use the value when the call succeeds and the
115+
// path is non-empty.
113116
char *icon_path = nullptr;
114117
ret = package_info_get_icon(handle, &icon_path);
115-
if (icon_path) {
118+
if (ret == PACKAGE_MANAGER_ERROR_NONE && icon_path && icon_path[0] != '\0') {
116119
result.icon_path = icon_path;
120+
}
121+
if (icon_path) {
117122
free(icon_path);
118123
}
119124

0 commit comments

Comments
 (0)