[gnome-software] Warn and limit the progress set on a GsApp
- From: Joaquim Manuel Pereira Rocha <jrocha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Warn and limit the progress set on a GsApp
- Date: Thu, 19 Jan 2017 10:04:52 +0000 (UTC)
commit 456dd347486f438cf0d9391bc9027930424254d4
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 9d37229..9a09ec8 100644
--- a/src/gs-app.c
+++ b/src/gs-app.c
@@ -897,6 +897,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 36a9de9..3383066 100644
--- a/src/gs-self-test.c
+++ b/src/gs-self-test.c
@@ -419,6 +419,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]