1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
|
/*
* Copyright © 2020 Zander Brown
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
* Author: Zander Brown <zbrown@gnome.org>
*/
#include "search/search-source.c"
#include "stubs/bad-instance.h"
static void
test_phosh_search_source_new (void)
{
g_autoptr (PhoshSearchSource) source = NULL;
g_autoptr (GAppInfo) info = NULL;
info = G_APP_INFO (g_desktop_app_info_new ("demo.app.Second.desktop"));
g_assert_nonnull (info);
source = phosh_search_source_new ("test", info);
g_assert_nonnull (source);
g_assert_cmpstr (phosh_search_source_get_id (source), ==, "test");
g_assert_true (phosh_search_source_get_app_info (source) == info);
}
static void
test_phosh_search_source_refs (void)
{
PhoshSearchSource *source;
PhoshSearchSource *source_ref;
source = phosh_search_source_new ("test", NULL);
g_assert_nonnull (source);
source_ref = phosh_search_source_ref (source);
g_assert_true (source == source_ref);
phosh_search_source_unref (source);
g_clear_pointer (&source, phosh_search_source_unref);
g_assert_null (source);
NULL_INSTANCE_CALL (phosh_search_source_ref, "self != NULL");
NULL_INSTANCE_CALL (phosh_search_source_unref, "self != NULL");
}
static void
test_phosh_search_source_boxed (void)
{
PhoshSearchSource *source;
PhoshSearchSource *source_ref;
source = phosh_search_source_new ("test", NULL);
g_assert_nonnull (source);
source_ref = g_boxed_copy (PHOSH_TYPE_SEARCH_SOURCE, source);
g_assert_true (source == source_ref);
g_boxed_free (PHOSH_TYPE_SEARCH_SOURCE, source_ref);
g_clear_pointer (&source, phosh_search_source_unref);
g_assert_null (source);
}
static void
test_phosh_search_source_null_instance (void)
{
g_autoptr (PhoshSearchSource) source = NULL;
NULL_INSTANCE_CALL_RETURN (phosh_search_source_get_id, "self != NULL", NULL);
NULL_INSTANCE_CALL_RETURN (phosh_search_source_get_app_info, "self != NULL", NULL);
}
static void
test_phosh_search_source_serialise (void)
{
g_autoptr (PhoshSearchSource) source = NULL;
g_autoptr (GAppInfo) info = NULL;
g_autoptr (GVariant) variant = NULL;
g_autofree char *id = NULL;
g_autofree char *app_info_id = NULL;
g_autoptr (GAppInfo) app_info = NULL;
guint position;
info = G_APP_INFO (g_desktop_app_info_new ("demo.app.Second.desktop"));
g_assert_nonnull (info);
source = phosh_search_source_new ("test", info);
g_assert_nonnull (source);
phosh_search_source_set_position (source, 42);
variant = phosh_search_source_serialise (source);
g_assert_nonnull (source);
g_assert_true (g_variant_is_of_type (variant, G_VARIANT_TYPE_TUPLE));
g_assert_true (g_variant_is_of_type (variant, G_VARIANT_TYPE ("(ssu)")));
g_variant_get (variant, "(ssu)", &id, &app_info_id, &position);
g_assert_cmpstr (id, ==, "test");
g_assert_cmpstr (app_info_id, ==, "demo.app.Second.desktop");
g_assert_cmpuint (position, ==, 42);
}
static void
test_phosh_search_source_deserialise (void)
{
g_autoptr (PhoshSearchSource) source = NULL;
g_autoptr (GVariant) src = NULL;
GAppInfo *info = NULL;
src = g_variant_new ("(ssu)", "test", "demo.app.Second.desktop", 42);
g_assert_nonnull (src);
source = phosh_search_source_deserialise (src);
g_assert_nonnull (source);
g_assert_cmpstr (phosh_search_source_get_id (source), ==, "test");
info = phosh_search_source_get_app_info (source);
g_assert_cmpstr (g_app_info_get_id (info), ==, "demo.app.Second.desktop");
g_assert_cmpuint (phosh_search_source_get_position (source), ==, 42);
}
int
main (int argc, char **argv)
{
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/phosh/search-source/new",
test_phosh_search_source_new);
g_test_add_func ("/phosh/search-source/refs",
test_phosh_search_source_refs);
g_test_add_func ("/phosh/search-source/boxed",
test_phosh_search_source_boxed);
g_test_add_func ("/phosh/search-source/null-instance",
test_phosh_search_source_null_instance);
g_test_add_func ("/phosh/search-source/serialise",
test_phosh_search_source_serialise);
g_test_add_func ("/phosh/search-source/deserialise",
test_phosh_search_source_deserialise);
return g_test_run ();
}
|