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
|
/*
* Copyright (C) 2013 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authored by Marco Trevisan (TreviƱo) <marco.trevisan@canonical.com>
*
*/
#include <stdlib.h>
#include <glib.h>
#include <glib-object.h>
#include <libbamf-private/bamf-private.h>
#include "bamf-view-private.h"
#define DATA_DIR TESTDIR "/data"
void ignore_fatal_errors (void);
static void
test_allocation (void)
{
BamfApplication *application;
/* Check it allocates */
application = g_object_new (BAMF_TYPE_APPLICATION, NULL);
g_assert (BAMF_IS_APPLICATION (application));
g_object_unref (application);
}
static void
test_favorite_invalid_desktop (void)
{
BamfApplication *application;
application = bamf_application_new_favorite (DATA_DIR"/invalid-type.desktop");
g_assert (!BAMF_IS_APPLICATION (application));
application = bamf_application_new_favorite (DATA_DIR"/not-existing-file.desktop");
g_assert (!BAMF_IS_APPLICATION (application));
ignore_fatal_errors ();
application = bamf_application_new_favorite (NULL);
g_assert (!BAMF_IS_APPLICATION (application));
}
static void
test_favorite_valid_desktop_file_system (void)
{
BamfApplication *application;
const gchar *desktop_file = DATA_DIR"/unity-control-center.desktop";
application = bamf_application_new_favorite (desktop_file);
g_assert_cmpstr (bamf_application_get_desktop_file (application), ==, desktop_file);
g_assert_cmpstr (bamf_view_get_name (BAMF_VIEW (application)), ==, "System Settings");
g_assert_cmpstr (bamf_view_get_icon (BAMF_VIEW (application)), ==, "preferences-system");
g_assert_cmpstr (bamf_application_get_application_type (application), ==, "system");
g_object_unref (application);
}
static void
test_favorite_full_name (void)
{
BamfApplication *application;
application = bamf_application_new_favorite (DATA_DIR"/full-name.desktop");
g_assert_cmpstr (bamf_view_get_name (BAMF_VIEW (application)), ==, "Full Application Name");
g_object_unref (application);
}
static void
test_favorite_no_icon (void)
{
BamfApplication *application;
application = bamf_application_new_favorite (DATA_DIR"/no-icon.desktop");
g_assert_cmpstr (bamf_view_get_icon (BAMF_VIEW (application)), ==, BAMF_APPLICATION_DEFAULT_ICON);
g_object_unref (application);
}
static void
test_favorite_mime_type_filled (void)
{
BamfApplication *application;
application = bamf_application_new_favorite (TESTDIR"/data/mime-types.desktop");
gchar** mimes = bamf_application_get_supported_mime_types (application);
g_assert_cmpuint (g_strv_length (mimes), ==, 7);
g_assert_cmpstr (mimes[0], ==, "text/plain");
g_assert_cmpstr (mimes[1], ==, "text/x-chdr");
g_assert_cmpstr (mimes[2], ==, "text/x-csrc");
g_assert_cmpstr (mimes[3], ==, "text/html");
g_assert_cmpstr (mimes[4], ==, "text/css");
g_assert_cmpstr (mimes[5], ==, "text/x-diff");
g_assert_cmpstr (mimes[6], ==, "application/xml");
g_assert_cmpstr (mimes[7], ==, NULL);
g_strfreev (mimes);
g_object_unref (application);
}
static void
test_favorite_mime_type_empty (void)
{
BamfApplication *application;
application = bamf_application_new_favorite (TESTDIR"/data/test-bamf-app.desktop");
gchar** mimes = bamf_application_get_supported_mime_types (application);
g_assert (!mimes);
g_object_unref (application);
}
void
test_application_create_suite (void)
{
#define DOMAIN "/Application"
g_test_add_func (DOMAIN"/Allocation", test_allocation);
g_test_add_func (DOMAIN"/Favorite/DesktopFile/Invalid", test_favorite_invalid_desktop);
g_test_add_func (DOMAIN"/Favorite/DesktopFile/Valid/System", test_favorite_valid_desktop_file_system);
g_test_add_func (DOMAIN"/Favorite/FullName", test_favorite_full_name);
g_test_add_func (DOMAIN"/Favorite/NoIcon", test_favorite_no_icon);
g_test_add_func (DOMAIN"/Favorite/MimeType/Filled", test_favorite_mime_type_filled);
g_test_add_func (DOMAIN"/Favorite/MimeType/Empty", test_favorite_mime_type_empty);
}
|