[gnome-software/gnome-3-22] Warn and limit the progress set on a GsApp
- From: Kalev Lember <klember src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/gnome-3-22] Warn and limit the progress set on a GsApp
- Date: Tue, 7 Mar 2017 16:31:23 +0000 (UTC)
commit dd0876404729a92fc9828096c6a4a5f248714ba6
Author: Joaquim Rocha <jrocha endlessm com>
Date: Wed Jan 18 16:30:37 2017 +0100
Warn and limit the progress set on a GsApp
If the progress being set is greater than 100 a warning should be
returned and the value be limited to 100.
src/gs-app.c | 6 ++++++
src/gs-self-test.c | 8 ++++++++
2 files changed, 14 insertions(+), 0 deletions(-)
---
diff --git a/src/gs-app.c b/src/gs-app.c
index 08fec9e..75dfcdb 100644
--- a/src/gs-app.c
+++ b/src/gs-app.c
@@ -891,6 +891,12 @@ gs_app_set_progress (GsApp *app, guint percentage)
g_return_if_fail (GS_IS_APP (app));
if (app->progress == percentage)
return;
+ if (percentage > 100) {
+ g_warning ("Cannot set '%u' as the progress for app '%s'. "
+ "Setting the maximum allowed value instead: 100.",
+ percentage, gs_app_get_unique_id (app));
+ percentage = 100;
+ }
app->progress = percentage;
gs_app_queue_notify (app, "progress");
}
diff --git a/src/gs-self-test.c b/src/gs-self-test.c
index 728122a..571e50b 100644
--- a/src/gs-self-test.c
+++ b/src/gs-self-test.c
@@ -405,6 +405,14 @@ gs_app_func (void)
/* correctly parse URL */
gs_app_set_origin_hostname (app, "https://mirrors.fedoraproject.org/metalink");
g_assert_cmpstr (gs_app_get_origin_hostname (app), ==, "fedoraproject.org");
+
+ /* check setting the progress */
+ gs_app_set_progress (app, 42);
+ g_assert_cmpuint (gs_app_get_progress (app), ==, 42);
+ g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
+ "Cannot set*as the progress for app*");
+ gs_app_set_progress (app, 142);
+ g_assert_cmpuint (gs_app_get_progress (app), ==, 100);
}
static guint _status_changed_cnt = 0;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]