[virt-tools-list] [RFC virt-viewer 09/12] util: Add some runtime testing of virt_viewer_compare_buildid()

Jonathon Jongsma jjongsma at redhat.com
Wed Jun 3 14:51:12 UTC 2015


On Tue, 2015-06-02 at 16:29 +0200, Christophe Fergeau wrote:
> ---
>  src/virt-viewer-file.c | 28 ++++++++++++++++++++++++++++
>  1 file changed, 28 insertions(+)
> 
> diff --git a/src/virt-viewer-file.c b/src/virt-viewer-file.c
> index 240a111..6865e04 100644
> --- a/src/virt-viewer-file.c
> +++ b/src/virt-viewer-file.c
> @@ -818,6 +818,34 @@ virt_viewer_file_fill_app(VirtViewerFile* self, VirtViewerApp *app, GError **err
>      g_return_val_if_fail(VIRT_VIEWER_IS_FILE(self), FALSE);
>      g_return_val_if_fail(VIRT_VIEWER_IS_APP(app), FALSE);
>  
> +    g_assert(virt_viewer_compare_buildid("1-1", "1-1") == 0);
> +    g_assert(virt_viewer_compare_buildid("1-1", "1-1.1") == -1);
> +    g_assert(virt_viewer_compare_buildid("1-1", "1-2") == -1);
> +    g_assert(virt_viewer_compare_buildid("1-3", "1-2") == 1);
> +    g_assert(virt_viewer_compare_buildid("2-3", "1-2") == 1);
> +    g_assert(virt_viewer_compare_buildid("2-3", "3-2") == -1);
> +    g_assert(virt_viewer_compare_buildid("2-3", "3-4") == -1);
> +    g_assert(virt_viewer_compare_buildid("4-3", "3-4") == 1);
> +
> +    g_assert(virt_viewer_compare_buildid("4-", "3-4") == 1);
> +    g_assert(virt_viewer_compare_buildid("4-3", "3-") == 1);
> +    g_assert(virt_viewer_compare_buildid("-3", "3-4") == -1);
> +    g_assert(virt_viewer_compare_buildid("4-3", "-4") == 1);
> +    g_assert(virt_viewer_compare_buildid("-3", "-4") == -1);
> +    g_assert(virt_viewer_compare_buildid("4", "3-4") == 1);
> +    g_assert(virt_viewer_compare_buildid("4-3", "3") == 1);
> +    g_assert(virt_viewer_compare_buildid("3", "3-4") == -1);
> +    g_assert(virt_viewer_compare_buildid("4-3", "4") == 1);
> +    g_assert(virt_viewer_compare_buildid("-3", "-4") == -1);
> +
> +#if 0
> +    /* These trigger runtime warnings */
> +    g_assert(virt_viewer_compare_buildid("-3", "-") == 1);
> +    g_assert(virt_viewer_compare_buildid("", "-") == 0);
> +    g_assert(virt_viewer_compare_buildid("", "") == 0);
> +    g_assert(virt_viewer_compare_buildid("", NULL) == 0);
> +    g_assert(virt_viewer_compare_buildid(NULL, NULL) == 0);
> +#endif
>      if (!virt_viewer_file_check_min_version(self, error)) {
>          return FALSE;
>      }


I don't like adding these tests to the actual code. Why don't you think
the previous test case you added was sufficient?

Jonathon




More information about the virt-tools-list mailing list