void pk_task_list_test (EggTest *test) { PkConnection *connection; PkTaskList *tlist; PkClient *client; gboolean ret; GError *error = NULL; if (!egg_test_start (test, "PkTaskList")) return; /* check to see if there is a daemon running */ connection = pk_connection_new (); ret = pk_connection_valid (connection); g_object_unref (connection); if (!ret) { egg_warning ("daemon is not running, skipping tests"); goto out; } /************************************************************/ egg_test_title (test, "get client"); tlist = pk_task_list_new (); egg_test_assert (test, tlist != NULL); g_signal_connect (tlist, "finished", G_CALLBACK (pk_task_list_test_finished_cb), test); /************************************************************/ egg_test_title (test, "search for power"); client = pk_client_new (); ret = pk_client_search_name (client, PK_FILTER_ENUM_NONE, "power", &error); if (!ret) { egg_test_failed (test, "failed: %s", error->message); g_error_free (error); } egg_test_loop_wait (test, 5000); egg_test_success (test, NULL); /************************************************************/ egg_test_title (test, "we finished?"); if (finished) egg_test_success (test, NULL); else egg_test_failed (test, "not finished"); g_object_unref (tlist); g_object_unref (client); out: egg_test_end (test); }
void egg_test_progress_bar (EggTest *test) { PkProgressBar *self; if (!egg_test_start (test, "PkProgressBar")) return; /************************************************************/ egg_test_title (test, "get an instance"); self = pk_progress_bar_new (); if (self != NULL) egg_test_success (test, NULL); else egg_test_failed (test, NULL); g_object_unref (self); egg_test_end (test); }
void egg_color_test (gpointer data) { guint8 r, g, b; guint32 color; EggTest *test = (EggTest *) data; if (egg_test_start (test, "EggColor") == FALSE) { return; } /************************************************************/ egg_test_title (test, "get red"); egg_color_to_rgb (0xff0000, &r, &g, &b); if (r == 255 && g == 0 && b == 0) { egg_test_success (test, "got red"); } else { egg_test_failed (test, "could not get red (%i, %i, %i)", r, g, b); } /************************************************************/ egg_test_title (test, "get green"); egg_color_to_rgb (0x00ff00, &r, &g, &b); if (r == 0 && g == 255 && b == 0) { egg_test_success (test, "got green"); } else { egg_test_failed (test, "could not get green (%i, %i, %i)", r, g, b); } /************************************************************/ egg_test_title (test, "get blue"); egg_color_to_rgb (0x0000ff, &r, &g, &b); if (r == 0 && g == 0 && b == 255) { egg_test_success (test, "got blue"); } else { egg_test_failed (test, "could not get blue (%i, %i, %i)", r, g, b); } /************************************************************/ egg_test_title (test, "get black"); egg_color_to_rgb (0x000000, &r, &g, &b); if (r == 0 && g == 0 && b == 0) { egg_test_success (test, "got black"); } else { egg_test_failed (test, "could not get black (%i, %i, %i)", r, g, b); } /************************************************************/ egg_test_title (test, "get white"); egg_color_to_rgb (0xffffff, &r, &g, &b); if (r == 255 && g == 255 && b == 255) { egg_test_success (test, "got white"); } else { egg_test_failed (test, "could not get white (%i, %i, %i)", r, g, b); } /************************************************************/ egg_test_title (test, "set red"); color = egg_color_from_rgb (0xff, 0x00, 0x00); if (color == 0xff0000) { egg_test_success (test, "set red"); } else { egg_test_failed (test, "could not set red (%i)", color); } /************************************************************/ egg_test_title (test, "set green"); color = egg_color_from_rgb (0x00, 0xff, 0x00); if (color == 0x00ff00) { egg_test_success (test, "set green"); } else { egg_test_failed (test, "could not set green (%i)", color); } /************************************************************/ egg_test_title (test, "set blue"); color = egg_color_from_rgb (0x00, 0x00, 0xff); if (color == 0x0000ff) { egg_test_success (test, "set blue"); } else { egg_test_failed (test, "could not set blue (%i)", color); } /************************************************************/ egg_test_title (test, "set white"); color = egg_color_from_rgb (0xff, 0xff, 0xff); if (color == 0xffffff) { egg_test_success (test, "set white"); } else { egg_test_failed (test, "could not set white (%i)", color); } egg_test_end (test); }
void gpm_dpms_test (gpointer data) { GpmDpms *dpms; gboolean ret; GError *error = NULL; EggTest *test = (EggTest *) data; if (!egg_test_start (test, "GpmDpms")) return; /************************************************************/ egg_test_title (test, "get object"); dpms = gpm_dpms_new (); if (dpms != NULL) egg_test_success (test, NULL); else egg_test_failed (test, "got no object"); /************************************************************/ egg_test_title (test, "set on"); ret = gpm_dpms_set_mode (dpms, GPM_DPMS_MODE_ON, &error); if (ret) egg_test_success (test, NULL); else egg_test_failed (test, "failed: %s", error->message); g_usleep (2*1000*1000); /************************************************************/ egg_test_title (test, "set STANDBY"); ret = gpm_dpms_set_mode (dpms, GPM_DPMS_MODE_STANDBY, &error); if (ret) egg_test_success (test, NULL); else egg_test_failed (test, "failed: %s", error->message); g_usleep (2*1000*1000); /************************************************************/ egg_test_title (test, "set SUSPEND"); ret = gpm_dpms_set_mode (dpms, GPM_DPMS_MODE_SUSPEND, &error); if (ret) egg_test_success (test, NULL); else egg_test_failed (test, "failed: %s", error->message); g_usleep (2*1000*1000); /************************************************************/ egg_test_title (test, "set OFF"); ret = gpm_dpms_set_mode (dpms, GPM_DPMS_MODE_OFF, &error); if (ret) egg_test_success (test, NULL); else egg_test_failed (test, "failed: %s", error->message); g_usleep (2*1000*1000); /************************************************************/ egg_test_title (test, "set on"); ret = gpm_dpms_set_mode (dpms, GPM_DPMS_MODE_ON, &error); if (ret) egg_test_success (test, NULL); else egg_test_failed (test, "failed: %s", error->message); g_usleep (2*1000*1000); g_object_unref (dpms); egg_test_end (test); }
void egg_string_test (EggTest *test) { gboolean ret; gchar *text_safe; const gchar *temp; guint length; gint value; guint uvalue; gchar **id1; gchar **id2; if (!egg_test_start (test, "EggString")) return; /************************************************************ **************** String array equal ****************** ************************************************************/ egg_test_title (test, "egg_strvequal same argument"); id1 = g_strsplit ("the quick brown fox", " ", 0); if (egg_strvequal (id1, id1)) egg_test_success (test, NULL); else egg_test_failed (test, "incorrect ret when both same"); g_strfreev (id1); /************************************************************/ egg_test_title (test, "egg_strvequal same"); id1 = g_strsplit ("the quick brown fox", " ", 0); id2 = g_strsplit ("the quick brown fox", " ", 0); if (egg_strvequal (id1, id2)) egg_test_success (test, NULL); else egg_test_failed (test, "incorrect ret when both same"); g_strfreev (id1); g_strfreev (id2); /************************************************************/ egg_test_title (test, "egg_strvequal different lengths"); id1 = g_strsplit ("the quick brown", " ", 0); id2 = g_strsplit ("the quick brown fox", " ", 0); if (!egg_strvequal (id1, id2)) egg_test_success (test, NULL); else egg_test_failed (test, "incorrect ret when both same"); g_strfreev (id1); g_strfreev (id2); /************************************************************/ egg_test_title (test, "egg_strvequal different"); id1 = g_strsplit ("the quick brown fox", " ", 0); id2 = g_strsplit ("richard hughes maintainer dude", " ", 0); if (!egg_strvequal (id1, id2)) egg_test_success (test, NULL); else egg_test_failed (test, "same when different"); g_strfreev (id1); g_strfreev (id2); /************************************************************ **************** Zero ****************** ************************************************************/ temp = NULL; egg_test_title (test, "test strzero (null)"); ret = egg_strzero (NULL); if (ret) egg_test_success (test, NULL); else egg_test_failed (test, "failed null"); /************************************************************/ egg_test_title (test, "test strzero (null first char)"); ret = egg_strzero (""); if (ret) egg_test_success (test, NULL); else egg_test_failed (test, "failed null"); /************************************************************/ egg_test_title (test, "test strzero (long string)"); ret = egg_strzero ("Richard"); if (!ret) egg_test_success (test, NULL); else egg_test_failed (test, "zero length word!"); /************************************************************/ egg_test_title (test, "id strcmp pass"); ret = (g_strcmp0 ("moo;0.0.1;i386;fedora", "moo;0.0.1;i386;fedora") == 0); egg_test_assert (test, ret); /************************************************************/ egg_test_title (test, "id strcmp fail"); ret = (g_strcmp0 ("moo;0.0.1;i386;fedora", "moo;0.0.2;i386;fedora") == 0); egg_test_assert (test, !ret); /************************************************************ **************** strlen ****************** ************************************************************/ egg_test_title (test, "strlen bigger"); length = egg_strlen ("123456789", 20); if (length == 9) egg_test_success (test, NULL); else egg_test_failed (test, "failed the strlen %i", length); /************************************************************/ egg_test_title (test, "strlen smaller"); length = egg_strlen ("123456789", 5); if (length == 5) egg_test_success (test, NULL); else egg_test_failed (test, "failed the strlen %i", length); /************************************************************/ egg_test_title (test, "strlen correct"); length = egg_strlen ("123456789", 9); if (length == 9) egg_test_success (test, NULL); else egg_test_failed (test, "failed the strlen %i", length); /************************************************************ **************** Replace ****************** ************************************************************/ egg_test_title (test, "replace start"); text_safe = egg_strreplace ("richard\nhughes", "r", "e"); if (g_strcmp0 (text_safe, "eichaed\nhughes") == 0) egg_test_success (test, NULL); else egg_test_failed (test, "failed the replace '%s'", text_safe); g_free (text_safe); /************************************************************/ egg_test_title (test, "replace none"); text_safe = egg_strreplace ("richard\nhughes", "dave", "e"); if (g_strcmp0 (text_safe, "richard\nhughes") == 0) egg_test_success (test, NULL); else egg_test_failed (test, "failed the replace '%s'", text_safe); g_free (text_safe); /************************************************************/ egg_test_title (test, "replace end"); text_safe = egg_strreplace ("richard\nhughes", "s", "e"); if (g_strcmp0 (text_safe, "richard\nhughee") == 0) egg_test_success (test, NULL); else egg_test_failed (test, "failed the replace '%s'", text_safe); g_free (text_safe); /************************************************************/ egg_test_title (test, "replace unicode"); text_safe = egg_strreplace ("richard\n- hughes", "\n- ", "\n• "); if (g_strcmp0 (text_safe, "richard\n• hughes") == 0) egg_test_success (test, NULL); else egg_test_failed (test, "failed the replace '%s'", text_safe); g_free (text_safe); /************************************************************ ************** Convert numbers **************** ************************************************************/ egg_test_title (test, "convert valid number"); ret = egg_strtoint ("234", &value); if (ret && value == 234) egg_test_success (test, NULL); else egg_test_failed (test, "value is %i", value); /************************************************************/ egg_test_title (test, "convert negative valid number"); ret = egg_strtoint ("-234", &value); if (ret && value == -234) egg_test_success (test, NULL); else egg_test_failed (test, "value is %i", value); /************************************************************/ egg_test_title (test, "don't convert invalid number"); ret = egg_strtoint ("dave", &value); if (!ret) egg_test_success (test, NULL); else egg_test_failed (test, "value is %i", value); /************************************************************/ egg_test_title (test, "convert NULL to a number"); ret = egg_strtouint (NULL, &uvalue); if (!ret) egg_test_success (test, NULL); else egg_test_failed (test, "value is %i", uvalue); /************************************************************/ egg_test_title (test, "convert valid uint number"); ret = egg_strtouint ("234", &uvalue); if (ret && uvalue == 234) egg_test_success (test, NULL); else egg_test_failed (test, "value is %i", uvalue); /************************************************************/ egg_test_title (test, "convert invalid uint number"); ret = egg_strtouint ("-234", &uvalue); if (ret == FALSE) egg_test_success (test, NULL); else egg_test_failed (test, "value is %i", uvalue); egg_test_end (test); }
void egg_precision_test (gpointer data) { guint value; EggTest *test = (EggTest *) data; if (!egg_test_start (test, "EggPrecision")) return; /************************************************************/ egg_test_title (test, "limit precision down 0,10"); value = egg_precision_round_down (0, 10); if (value == 0) { egg_test_success (test, "got %i", value); } else { egg_test_failed (test, "precision incorrect (%i)", value); } /************************************************************/ egg_test_title (test, "limit precision down 4,10"); value = egg_precision_round_down (4, 10); if (value == 0) { egg_test_success (test, "got %i", value); } else { egg_test_failed (test, "precision incorrect (%i)", value); } /************************************************************/ egg_test_title (test, "limit precision down 11,10"); value = egg_precision_round_down (11, 10); if (value == 10) { egg_test_success (test, "got %i", value); } else { egg_test_failed (test, "precision incorrect (%i)", value); } /************************************************************/ egg_test_title (test, "limit precision down 201,2"); value = egg_precision_round_down (201, 2); if (value == 200) { egg_test_success (test, "got %i", value); } else { egg_test_failed (test, "precision incorrect (%i)", value); } /************************************************************/ egg_test_title (test, "limit precision down 100,10"); value = egg_precision_round_down (100, 10); if (value == 100) { egg_test_success (test, "got %i", value); } else { egg_test_failed (test, "precision incorrect (%i)", value); } /************************************************************/ egg_test_title (test, "limit precision up 0,10"); value = egg_precision_round_up (0, 10); if (value == 0) { egg_test_success (test, "got %i", value); } else { egg_test_failed (test, "precision incorrect (%i)", value); } /************************************************************/ egg_test_title (test, "limit precision up 4,10"); value = egg_precision_round_up (4, 10); if (value == 10) { egg_test_success (test, "got %i", value); } else { egg_test_failed (test, "precision incorrect (%i)", value); } /************************************************************/ egg_test_title (test, "limit precision up 11,10"); value = egg_precision_round_up (11, 10); if (value == 20) { egg_test_success (test, "got %i", value); } else { egg_test_failed (test, "precision incorrect (%i)", value); } /************************************************************/ egg_test_title (test, "limit precision up 201,2"); value = egg_precision_round_up (201, 2); if (value == 202) { egg_test_success (test, "got %i", value); } else { egg_test_failed (test, "precision incorrect (%i)", value); } /************************************************************/ egg_test_title (test, "limit precision up 100,10"); value = egg_precision_round_up (100, 10); if (value == 100) { egg_test_success (test, "got %i", value); } else { egg_test_failed (test, "precision incorrect (%i)", value); } egg_test_end (test); }
void pk_bitfield_test (gpointer user_data) { EggTest *test = (EggTest *) user_data; gchar *text; PkBitfield filter; gint value; PkBitfield values; if (!egg_test_start (test, "PkBitfield")) return; /************************************************************/ egg_test_title (test, "check we can convert filter bitfield to text (none)"); text = pk_filter_bitfield_to_text (pk_bitfield_value (PK_FILTER_ENUM_NONE)); if (g_strcmp0 (text, "none") == 0) egg_test_success (test, NULL); else egg_test_failed (test, "text was %s", text); g_free (text); /************************************************************/ egg_test_title (test, "check we can invert a bit 1 -> 0"); values = pk_bitfield_value (PK_FILTER_ENUM_NOT_DEVELOPMENT) | pk_bitfield_value (PK_FILTER_ENUM_NOT_NEWEST); pk_bitfield_invert (values, PK_FILTER_ENUM_NOT_DEVELOPMENT); if (values == pk_bitfield_value (PK_FILTER_ENUM_NOT_NEWEST)) egg_test_success (test, NULL); else egg_test_failed (test, "values were %" PK_BITFIELD_FORMAT, values); /************************************************************/ egg_test_title (test, "check we can invert a bit 0 -> 1"); values = 0; pk_bitfield_invert (values, PK_FILTER_ENUM_NOT_DEVELOPMENT); if (values == pk_bitfield_value (PK_FILTER_ENUM_NOT_DEVELOPMENT)) egg_test_success (test, NULL); else egg_test_failed (test, "values were %" PK_BITFIELD_FORMAT, values); /************************************************************/ egg_test_title (test, "check we can convert filter bitfield to text (single)"); text = pk_filter_bitfield_to_text (pk_bitfield_value (PK_FILTER_ENUM_NOT_DEVELOPMENT)); if (g_strcmp0 (text, "~devel") == 0) egg_test_success (test, NULL); else egg_test_failed (test, "text was %s", text); g_free (text); /************************************************************/ egg_test_title (test, "check we can convert filter bitfield to text (plural)"); text = pk_filter_bitfield_to_text (pk_bitfield_value (PK_FILTER_ENUM_NOT_DEVELOPMENT) | pk_bitfield_value (PK_FILTER_ENUM_GUI) | pk_bitfield_value (PK_FILTER_ENUM_NEWEST)); if (g_strcmp0 (text, "~devel;gui;newest") == 0) egg_test_success (test, NULL); else egg_test_failed (test, "text was %s", text); g_free (text); /************************************************************/ egg_test_title (test, "check we can convert filter text to bitfield (none)"); filter = pk_filter_bitfield_from_text ("none"); if (filter == pk_bitfield_value (PK_FILTER_ENUM_NONE)) egg_test_success (test, NULL); else egg_test_failed (test, "filter was %" PK_BITFIELD_FORMAT, filter); /************************************************************/ egg_test_title (test, "check we can convert filter text to bitfield (single)"); filter = pk_filter_bitfield_from_text ("~devel"); if (filter == pk_bitfield_value (PK_FILTER_ENUM_NOT_DEVELOPMENT)) egg_test_success (test, NULL); else egg_test_failed (test, "filter was %" PK_BITFIELD_FORMAT, filter); /************************************************************/ egg_test_title (test, "check we can convert filter text to bitfield (plural)"); filter = pk_filter_bitfield_from_text ("~devel;gui;newest"); if (filter == (pk_bitfield_value (PK_FILTER_ENUM_NOT_DEVELOPMENT) | pk_bitfield_value (PK_FILTER_ENUM_GUI) | pk_bitfield_value (PK_FILTER_ENUM_NEWEST))) egg_test_success (test, NULL); else egg_test_failed (test, "filter was %" PK_BITFIELD_FORMAT, filter); /************************************************************/ egg_test_title (test, "check we can add / remove bitfield"); filter = pk_bitfield_value (PK_FILTER_ENUM_NOT_DEVELOPMENT) | pk_bitfield_value (PK_FILTER_ENUM_GUI) | pk_bitfield_value (PK_FILTER_ENUM_NEWEST); pk_bitfield_add (filter, PK_FILTER_ENUM_NOT_FREE); pk_bitfield_remove (filter, PK_FILTER_ENUM_NOT_DEVELOPMENT); text = pk_filter_bitfield_to_text (filter); if (g_strcmp0 (text, "gui;~free;newest") == 0) egg_test_success (test, NULL); else egg_test_failed (test, "text was %s", text); g_free (text); /************************************************************/ egg_test_title (test, "check we can test enum presence"); filter = pk_bitfield_value (PK_FILTER_ENUM_NOT_DEVELOPMENT) | pk_bitfield_value (PK_FILTER_ENUM_GUI) | pk_bitfield_value (PK_FILTER_ENUM_NEWEST); if (pk_bitfield_contain (filter, PK_FILTER_ENUM_NOT_DEVELOPMENT)) egg_test_success (test, NULL); else egg_test_failed (test, "wrong boolean"); /************************************************************/ egg_test_title (test, "check we can test enum false-presence"); if (!pk_bitfield_contain (filter, PK_FILTER_ENUM_FREE)) egg_test_success (test, NULL); else egg_test_failed (test, "wrong boolean"); /************************************************************/ egg_test_title (test, "check we can add / remove bitfield to nothing"); filter = pk_bitfield_value (PK_FILTER_ENUM_NOT_DEVELOPMENT); pk_bitfield_remove (filter, PK_FILTER_ENUM_NOT_DEVELOPMENT); text = pk_filter_bitfield_to_text (filter); if (g_strcmp0 (text, "none") == 0) egg_test_success (test, NULL); else egg_test_failed (test, "text was %s", text); g_free (text); /************************************************************/ egg_test_title (test, "role bitfield from enums (unknown)"); values = pk_bitfield_from_enums (PK_ROLE_ENUM_UNKNOWN, -1); if (values == pk_bitfield_value (PK_ROLE_ENUM_UNKNOWN)) egg_test_success (test, NULL); else egg_test_failed (test, "returned bitfield %" PK_BITFIELD_FORMAT, values); /************************************************************/ egg_test_title (test, "role bitfield from enums (random)"); values = pk_bitfield_from_enums (PK_ROLE_ENUM_SEARCH_GROUP, PK_ROLE_ENUM_SEARCH_DETAILS, -1); if (values == (pk_bitfield_value (PK_ROLE_ENUM_SEARCH_DETAILS) | pk_bitfield_value (PK_ROLE_ENUM_SEARCH_GROUP))) egg_test_success (test, NULL); else egg_test_failed (test, "returned bitfield %" PK_BITFIELD_FORMAT, values); /************************************************************/ egg_test_title (test, "group bitfield from enums (unknown)"); values = pk_bitfield_from_enums (PK_GROUP_ENUM_UNKNOWN, -1); if (values == pk_bitfield_value (PK_GROUP_ENUM_UNKNOWN)) egg_test_success (test, NULL); else egg_test_failed (test, "returned bitfield %" PK_BITFIELD_FORMAT, values); /************************************************************/ egg_test_title (test, "group bitfield from enums (random)"); values = pk_bitfield_from_enums (PK_GROUP_ENUM_ACCESSIBILITY, -1); if (values == (pk_bitfield_value (PK_GROUP_ENUM_ACCESSIBILITY))) egg_test_success (test, NULL); else egg_test_failed (test, "returned bitfield %" PK_BITFIELD_FORMAT, values); /************************************************************/ egg_test_title (test, "group bitfield to text (unknown)"); values = pk_bitfield_from_enums (PK_GROUP_ENUM_UNKNOWN, -1); text = pk_group_bitfield_to_text (values); if (g_strcmp0 (text, "unknown") == 0) egg_test_success (test, NULL); else egg_test_failed (test, "returned bitfield text %s (%" PK_BITFIELD_FORMAT ")", text, values); g_free (text); /************************************************************/ egg_test_title (test, "group bitfield to text (first and last)"); values = pk_bitfield_from_enums (PK_GROUP_ENUM_ACCESSIBILITY, PK_GROUP_ENUM_UNKNOWN, -1); text = pk_group_bitfield_to_text (values); if (g_strcmp0 (text, "unknown;accessibility") == 0) egg_test_success (test, NULL); else egg_test_failed (test, "returned bitfield text %s (%" PK_BITFIELD_FORMAT ")", text, values); g_free (text); /************************************************************/ egg_test_title (test, "group bitfield to text (random)"); values = pk_bitfield_from_enums (PK_GROUP_ENUM_UNKNOWN, PK_GROUP_ENUM_REPOS, -1); text = pk_group_bitfield_to_text (values); if (g_strcmp0 (text, "unknown;repos") == 0) egg_test_success (test, NULL); else egg_test_failed (test, "returned bitfield text %s (%" PK_BITFIELD_FORMAT ")", text, values); g_free (text); /************************************************************/ egg_test_title (test, "priority check missing"); values = pk_bitfield_value (PK_ROLE_ENUM_SEARCH_DETAILS) | pk_bitfield_value (PK_ROLE_ENUM_SEARCH_GROUP); value = pk_bitfield_contain_priority (values, PK_ROLE_ENUM_SEARCH_FILE, -1); if (value == -1) egg_test_success (test, NULL); else egg_test_failed (test, "returned priority %i when should be missing", value); /************************************************************/ egg_test_title (test, "priority check first"); value = pk_bitfield_contain_priority (values, PK_ROLE_ENUM_SEARCH_GROUP, -1); if (value == PK_ROLE_ENUM_SEARCH_GROUP) egg_test_success (test, NULL); else egg_test_failed (test, "returned wrong value; %i", value); /************************************************************/ egg_test_title (test, "priority check second, correct"); value = pk_bitfield_contain_priority (values, PK_ROLE_ENUM_SEARCH_FILE, PK_ROLE_ENUM_SEARCH_GROUP, -1); if (value == PK_ROLE_ENUM_SEARCH_GROUP) egg_test_success (test, NULL); else egg_test_failed (test, "returned wrong value; %i", value); egg_test_end (test); }
void gpk_common_test (gpointer data) { gchar *text; EggTest *test = (EggTest *) data; if (!egg_test_start (test, "GpkCommon")) return; /************************************************************ **************** time text ************** ************************************************************/ egg_test_title (test, "time zero"); text = gpk_time_to_localised_string (0); if (text != NULL && strcmp (text, "Now") == 0) egg_test_success (test, NULL); else egg_test_failed (test, "failed, got %s", text); g_free (text); /************************************************************/ egg_test_title (test, "time 1s"); text = gpk_time_to_localised_string (1); if (text != NULL && strcmp (text, "1 second") == 0) egg_test_success (test, NULL); else egg_test_failed (test, "failed, got %s", text); g_free (text); /************************************************************/ egg_test_title (test, "time 1m"); text = gpk_time_to_localised_string (1*60); if (text != NULL && strcmp (text, "1 minute") == 0) egg_test_success (test, NULL); else egg_test_failed (test, "failed, got %s", text); g_free (text); /************************************************************/ egg_test_title (test, "time 1h"); text = gpk_time_to_localised_string (1*60*60); if (text != NULL && strcmp (text, "1 hour") == 0) egg_test_success (test, NULL); else egg_test_failed (test, "failed, got %s", text); g_free (text); /************************************************************/ egg_test_title (test, "time 30s"); text = gpk_time_to_localised_string (30); if (text != NULL && strcmp (text, "30 seconds") == 0) egg_test_success (test, NULL); else egg_test_failed (test, "failed, got %s", text); g_free (text); /************************************************************/ egg_test_title (test, "time 30m"); text = gpk_time_to_localised_string (30*60); if (text != NULL && strcmp (text, "30 minutes") == 0) egg_test_success (test, NULL); else egg_test_failed (test, "failed, got %s", text); g_free (text); /************************************************************/ egg_test_title (test, "time 30m1s"); text = gpk_time_to_localised_string (30*60+1); if (text != NULL && strcmp (text, "30 minutes 1 second") == 0) egg_test_success (test, NULL); else egg_test_failed (test, "failed, got %s", text); g_free (text); /************************************************************/ egg_test_title (test, "time 30m10s"); text = gpk_time_to_localised_string (30*60+10); if (text != NULL && strcmp (text, "30 minutes 10 seconds") == 0) egg_test_success (test, NULL); else egg_test_failed (test, "failed, got %s", text); g_free (text); /************************************************************/ egg_test_title (test, "imprecise time 1s"); text = gpk_time_to_imprecise_string (1); if (text != NULL && strcmp (text, "1 second") == 0) egg_test_success (test, NULL); else egg_test_failed (test, "failed, got %s", text); g_free (text); /************************************************************/ egg_test_title (test, "imprecise time 30m"); text = gpk_time_to_imprecise_string (30*60); if (text != NULL && strcmp (text, "30 minutes") == 0) egg_test_success (test, NULL); else egg_test_failed (test, "failed, got %s", text); g_free (text); /************************************************************/ egg_test_title (test, "imprecise time 30m10s"); text = gpk_time_to_imprecise_string (30*60+10); if (text != NULL && strcmp (text, "30 minutes") == 0) egg_test_success (test, NULL); else egg_test_failed (test, "failed, got %s", text); g_free (text); /************************************************************ **************** package name text ************** ************************************************************/ egg_test_title (test, "package id pretty valid package id, no summary"); text = gpk_package_id_format_twoline ("simon;0.0.1;i386;data", NULL); if (text != NULL && strcmp (text, "simon-0.0.1 (i386)") == 0) egg_test_success (test, NULL); else egg_test_failed (test, "failed, got %s", text); g_free (text); /************************************************************/ egg_test_title (test, "package id pretty valid package id, no summary 2"); text = gpk_package_id_format_twoline ("simon;0.0.1;;data", NULL); if (text != NULL && strcmp (text, "simon-0.0.1") == 0) egg_test_success (test, NULL); else egg_test_failed (test, "failed, got %s", text); g_free (text); /************************************************************/ egg_test_title (test, "package id pretty valid package id, no summary 3"); text = gpk_package_id_format_twoline ("simon;;;data", NULL); if (text != NULL && strcmp (text, "simon") == 0) egg_test_success (test, NULL); else egg_test_failed (test, "failed, got %s", text); g_free (text); /************************************************************/ egg_test_title (test, "package id pretty valid package id, no summary 4"); text = gpk_package_id_format_twoline ("simon;0.0.1;;data", "dude"); if (text != NULL && strcmp (text, "<b>dude</b>\nsimon-0.0.1") == 0) egg_test_success (test, NULL); else egg_test_failed (test, "failed, got %s", text); g_free (text); egg_test_end (test); }
void gpm_phone_test (gpointer data) { GpmPhone *phone; guint value; gboolean ret; EggTest *test = (EggTest *) data; if (egg_test_start (test, "GpmPhone") == FALSE) return; /************************************************************/ egg_test_title (test, "make sure we get a non null phone"); phone = gpm_phone_new (); if (phone != NULL) egg_test_success (test, "got GpmPhone"); else egg_test_failed (test, "could not get GpmPhone"); /* connect signals */ g_signal_connect (phone, "device-refresh", G_CALLBACK (phone_device_refresh_cb), GUINT_TO_POINTER(44)); /************************************************************/ egg_test_title (test, "make sure we got a connection"); if (phone->priv->proxy != NULL) { egg_test_success (test, "got connection"); } else { /* skip this part of the test */ egg_test_success (test, "could not get a connection!"); goto out; } /************************************************************/ egg_test_title (test, "coldplug the data"); ret = gpm_phone_coldplug (phone); if (ret) { egg_test_success (test, "coldplug okay"); } else { egg_test_failed (test, "could not coldplug"); } egg_test_mainloop_wait (500); /************************************************************/ egg_test_title (test, "got refresh"); if (test_got_refresh) { egg_test_success (test, NULL); } else { egg_test_failed (test, "did not get refresh"); } /************************************************************/ egg_test_title (test, "check the connected phones"); value = gpm_phone_get_num_batteries (phone); if (value == 1) { egg_test_success (test, "connected phone"); } else { egg_test_failed (test, "not connected with %i (phone not connected?)", value); } /************************************************************/ egg_test_title (test, "check the present value"); ret = gpm_phone_get_present (phone, 0); if (ret) { egg_test_success (test, "we are here!"); } else { egg_test_failed (test, "not here..."); } /************************************************************/ egg_test_title (test, "check the percentage"); value = gpm_phone_get_percentage (phone, 0); if (value != 0) { egg_test_success (test, "percentage is %i", phone->priv->percentage); } else { egg_test_failed (test, "could not get value"); } /************************************************************/ egg_test_title (test, "check the ac value"); ret = gpm_phone_get_on_ac (phone, 0); if (!ret) { egg_test_success (test, "not charging, correct"); } else { egg_test_failed (test, "charging?"); } out: g_object_unref (phone); egg_test_end (test); }
void pk_package_id_test (EggTest *test) { gboolean ret; gchar *text; const gchar *temp; PkPackageId *id; PkPackageId *id2; gchar **array; if (!egg_test_start (test, "PkPackageId")) return; /************************************************************ **************** id ****************** ************************************************************/ egg_test_title (test, "id build valid"); text = pk_package_id_build ("moo", "0.0.1", "i386", "fedora"); if (g_strcmp0 (text, "moo;0.0.1;i386;fedora") == 0) egg_test_success (test, NULL); else egg_test_failed (test, NULL); g_free (text); egg_test_title (test, "id build partial"); text = pk_package_id_build ("moo", NULL, NULL, NULL); if (g_strcmp0 (text, "moo;;;") == 0) egg_test_success (test, NULL); else egg_test_failed (test, "got '%s', expected '%s'", text, "moo;;;"); g_free (text); egg_test_title (test, "pid equal pass (same)"); ret = pk_package_id_equal_strings ("moo;0.0.1;i386;fedora", "moo;0.0.1;i386;fedora"); egg_test_assert (test, ret); /************************************************************/ egg_test_title (test, "pid equal pass (different)"); ret = pk_package_id_equal_strings ("moo;0.0.1;i386;fedora", "moo;0.0.1;i386;data"); egg_test_assert (test, ret); /************************************************************/ egg_test_title (test, "get an id object"); id = pk_package_id_new (); egg_test_assert (test, id != NULL); /************************************************************/ egg_test_title (test, "test id freeing early"); ret = pk_package_id_free (id); egg_test_assert (test, ret); /************************************************************/ egg_test_title (test, "parse incorrect package_id from string (empty)"); temp = ""; id = pk_package_id_new_from_string (temp); if (id == NULL) egg_test_success (test, NULL); else egg_test_failed (test, "passed an invalid string '%s'", temp); /************************************************************/ egg_test_title (test, "parse incorrect package_id from string (not enough)"); temp = "moo;0.0.1;i386"; id = pk_package_id_new_from_string (temp); if (id == NULL) egg_test_success (test, NULL); else egg_test_failed (test, "passed an invalid string '%s'", temp); /************************************************************/ egg_test_title (test, "parse package_id from string"); id = pk_package_id_new_from_string ("moo;0.0.1;i386;fedora"); if (id != NULL && g_strcmp0 (id->name, "moo") == 0 && g_strcmp0 (id->arch, "i386") == 0 && g_strcmp0 (id->data, "fedora") == 0 && g_strcmp0 (id->version, "0.0.1") == 0) egg_test_success (test, NULL); else egg_test_failed (test, NULL); /************************************************************/ egg_test_title (test, "test copying"); id2 = pk_package_id_copy (id); if (id2 != NULL) egg_test_success (test, NULL); else egg_test_failed (test, NULL); /************************************************************/ egg_test_title (test, "test id building with valid data"); text = pk_package_id_to_string (id2); if (g_strcmp0 (text, "moo;0.0.1;i386;fedora") == 0) egg_test_success (test, NULL); else egg_test_failed (test, "package_id is '%s'", text); g_free (text); pk_package_id_free (id); pk_package_id_free (id2); /************************************************************/ egg_test_title (test, "test id building with partial data"); id = pk_package_id_new_from_string ("moo;;;"); text = pk_package_id_to_string (id); if (g_strcmp0 (text, "moo;;;") == 0) egg_test_success (test, NULL); else egg_test_failed (test, "package_id is '%s', should be '%s'", text, "moo;;;"); g_free (text); pk_package_id_free (id); /************************************************************/ egg_test_title (test, "parse short package_id from string"); id = pk_package_id_new_from_string ("moo;0.0.1;;"); if (id != NULL && (g_strcmp0 (id->name, "moo") == 0) && (g_strcmp0 (id->version, "0.0.1") == 0) && id->data == NULL && id->arch == NULL) egg_test_success (test, NULL); else egg_test_failed (test, NULL); pk_package_id_free (id); egg_test_title (test, "id equal pass (same)"); ret = pk_strcmp_sections ("moo;0.0.1;i386;fedora", "moo;0.0.1;i386;fedora", 4, 3); egg_test_assert (test, ret); egg_test_title (test, "id equal pass (parts==match)"); ret = pk_strcmp_sections ("moo;0.0.1;i386;fedora", "moo;0.0.1;i386;fedora", 4, 4); egg_test_assert (test, ret); egg_test_title (test, "id equal pass (different)"); ret = pk_strcmp_sections ("moo;0.0.1;i386;fedora", "moo;0.0.1;i386;data", 4, 3); egg_test_assert (test, ret); egg_test_title (test, "id equal fail1"); ret = pk_strcmp_sections ("moo;0.0.1;i386;fedora", "moo;0.0.2;x64;fedora", 4, 3); egg_test_assert (test, !ret); egg_test_title (test, "id equal fail2"); ret = pk_strcmp_sections ("moo;0.0.1;i386;fedora", "gnome;0.0.2;i386;fedora", 4, 3); egg_test_assert (test, !ret); egg_test_title (test, "id equal fail3"); ret = pk_strcmp_sections ("moo;0.0.1;i386;fedora", "moo;0.0.3;i386;fedora", 4, 3); egg_test_assert (test, !ret); egg_test_title (test, "id equal fail (match too high)"); ret = pk_strcmp_sections ("moo;0.0.1;i386;fedora", "moo;0.0.3;i386;fedora", 4, 5); egg_test_assert (test, !ret); /************************************************************ **************** splitting **************** ************************************************************/ egg_test_title (test, "test pass 1"); array = pk_strsplit ("foo", 1); if (array != NULL && g_strcmp0 (array[0], "foo") == 0) egg_test_success (test, NULL); else egg_test_failed (test, "got %s", array[0]); g_strfreev (array); /************************************************************/ egg_test_title (test, "test pass 2"); array = pk_strsplit ("foo;moo", 2); if (array != NULL && g_strcmp0 (array[0], "foo") == 0 && g_strcmp0 (array[1], "moo") == 0) egg_test_success (test, NULL); else egg_test_failed (test, "got %s, %s", array[0], array[1]); g_strfreev (array); /************************************************************/ egg_test_title (test, "test pass 3"); array = pk_strsplit ("foo;moo;bar", 3); if (array != NULL && g_strcmp0 (array[0], "foo") == 0 && g_strcmp0 (array[1], "moo") == 0 && g_strcmp0 (array[2], "bar") == 0) egg_test_success (test, NULL); else egg_test_failed (test, "got %s, %s, %s, %s", array[0], array[1], array[2], array[3]); g_strfreev (array); /************************************************************/ egg_test_title (test, "test on real packageid"); array = pk_strsplit ("kde-i18n-csb;4:3.5.8~pre20071001-0ubuntu1;all;", 4); if (array != NULL && g_strcmp0 (array[0], "kde-i18n-csb") == 0 && g_strcmp0 (array[1], "4:3.5.8~pre20071001-0ubuntu1") == 0 && g_strcmp0 (array[2], "all") == 0 && g_strcmp0 (array[3], "") == 0) egg_test_success (test, NULL); else egg_test_failed (test, "got %s, %s, %s, %s", array[0], array[1], array[2], array[3]); g_strfreev (array); /************************************************************/ egg_test_title (test, "test on short packageid"); array = pk_strsplit ("kde-i18n-csb;4:3.5.8~pre20071001-0ubuntu1;;", 4); if (array != NULL && g_strcmp0 (array[0], "kde-i18n-csb") == 0 && g_strcmp0 (array[1], "4:3.5.8~pre20071001-0ubuntu1") == 0 && g_strcmp0 (array[2], "") == 0 && g_strcmp0 (array[3], "") == 0) egg_test_success (test, NULL); else egg_test_failed (test, "got %s, %s, %s, %s", array[0], array[1], array[2], array[3]); g_strfreev (array); /************************************************************/ egg_test_title (test, "test fail under"); array = pk_strsplit ("foo;moo", 1); egg_test_assert (test, array == NULL); /************************************************************/ egg_test_title (test, "test fail over"); array = pk_strsplit ("foo;moo", 3); egg_test_assert (test, array == NULL); /************************************************************/ egg_test_title (test, "test fail missing first"); array = pk_strsplit (";moo", 2); egg_test_assert (test, array == NULL); egg_test_end (test); }