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 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
|
/*
* Copyright (C) 2009-2012, 2014 Red Hat, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Authors:
* Daniel P. Berrange <berrange@redhat.com>
*/
#include <config.h>
#include <stdlib.h>
#include <osinfo/osinfo.h>
#include <check.h>
START_TEST(test_basic)
{
OsinfoOs *os = osinfo_os_new("pony");
fail_unless(OSINFO_IS_OS(os), "Os is a os object");
fail_unless(g_strcmp0(osinfo_entity_get_id(OSINFO_ENTITY(os)), "pony") == 0, "Os ID was pony");
g_object_unref(os);
}
END_TEST
START_TEST(test_devices)
{
OsinfoOs *os = osinfo_os_new("awesome");
OsinfoDevice *dev1 = osinfo_device_new("e1000");
OsinfoDevice *dev2 = osinfo_device_new("rtl8139");
OsinfoDeviceLink *link1 = osinfo_os_add_device(os, dev1);
osinfo_entity_add_param(OSINFO_ENTITY(link1), "device", "pci-e1000");
OsinfoDeviceLink *link2 = osinfo_os_add_device(os, dev2);
osinfo_entity_add_param(OSINFO_ENTITY(link2), "device", "pci-8139");
OsinfoDeviceList *devices = osinfo_os_get_devices(os, NULL);
fail_unless(osinfo_list_get_length(OSINFO_LIST(devices)) == 2, "Os has two devices");
fail_unless(osinfo_list_get_nth(OSINFO_LIST(devices), 0) == OSINFO_ENTITY(dev1), "Got device 1");
fail_unless(osinfo_list_get_nth(OSINFO_LIST(devices), 1) == OSINFO_ENTITY(dev2), "Got device 2");
g_object_unref(devices);
g_object_unref(dev1);
g_object_unref(dev2);
g_object_unref(os);
}
END_TEST
START_TEST(test_loader)
{
OsinfoLoader *loader;
OsinfoDb *db;
OsinfoOs *os;
GError *error = NULL;
const char *str;
loader = osinfo_loader_new();
osinfo_loader_process_path(loader, SRCDIR "/test/dbdata", &error);
fail_unless(error == NULL, error ? error->message:"none");
db = osinfo_loader_get_db(loader);
os = osinfo_db_get_os(db, "http://libosinfo.org/test/os/test1");
fail_unless(os != NULL, "could not find OS 'test1'");
str = osinfo_product_get_short_id(OSINFO_PRODUCT(os));
fail_unless(g_strcmp0(str, "test1") == 0, "wrong OS short-id");
str = osinfo_product_get_name(OSINFO_PRODUCT(os));
fail_unless(g_strcmp0(str, "Test 1") == 0, "wrong OS name");
str = osinfo_product_get_version(OSINFO_PRODUCT(os));
fail_unless(g_strcmp0(str, "unknown") == 0, "wrong OS version");
str = osinfo_product_get_vendor(OSINFO_PRODUCT(os));
fail_unless(g_strcmp0(str, "libosinfo.org") == 0, "wrong OS vendor");
str = osinfo_os_get_family(os);
fail_unless(g_strcmp0(str, "test") == 0, "wrong OS family");
fail_unless(osinfo_os_get_release_status(os) == OSINFO_RELEASE_STATUS_PRERELEASE,
"OS should be a pre-release");
os = osinfo_db_get_os(db, "http://libosinfo.org/test/os/test2");
fail_unless(os != NULL, "could not find OS 'test2'");
str = osinfo_product_get_short_id(OSINFO_PRODUCT(os));
fail_unless(g_strcmp0(str, "test2") == 0, "wrong OS short-id");
str = osinfo_product_get_name(OSINFO_PRODUCT(os));
fail_unless(str == NULL, "wrong OS name");
str = osinfo_product_get_version(OSINFO_PRODUCT(os));
fail_unless(str == NULL, "wrong OS version");
str = osinfo_product_get_vendor(OSINFO_PRODUCT(os));
fail_unless(str == NULL, "wrong OS vendor");
str = osinfo_os_get_family(os);
fail_unless(str == NULL, "wrong OS family");
fail_unless(osinfo_os_get_release_status(os) == OSINFO_RELEASE_STATUS_RELEASED,
"OS should be a released one");
os = osinfo_db_get_os(db, "http://libosinfo.org/test/os/test3");
fail_unless(os != NULL, "could not find OS 'test3'");
str = osinfo_product_get_short_id(OSINFO_PRODUCT(os));
fail_unless(g_strcmp0(str, "test3") == 0, "wrong OS short-id");
fail_unless(osinfo_os_get_release_status(os) == OSINFO_RELEASE_STATUS_RELEASED,
"OS should be a released one");
os = osinfo_db_get_os(db, "http://libosinfo.org/test/os/test4");
fail_unless(os != NULL, "could not find OS 'test4'");
str = osinfo_product_get_short_id(OSINFO_PRODUCT(os));
fail_unless(g_strcmp0(str, "test4") == 0, "wrong OS short-id");
fail_unless(osinfo_os_get_release_status(os) == OSINFO_RELEASE_STATUS_SNAPSHOT,
"OS should be a snapshot");
os = osinfo_db_get_os(db, "http://libosinfo.org/test/os/test5");
fail_unless(os != NULL, "could not find OS 'test5'");
str = osinfo_product_get_short_id(OSINFO_PRODUCT(os));
fail_unless(g_strcmp0(str, "test5") == 0, "wrong OS short-id");
/* 'test5' OS intentionnally contains an invalid release status */
g_test_expect_message(NULL, G_LOG_LEVEL_CRITICAL,
"*(osinfo_entity_get_param_value_enum): should not be reached*");
fail_unless(osinfo_os_get_release_status(os) == OSINFO_RELEASE_STATUS_RELEASED,
"OS should be a released one");
g_object_unref(loader);
}
END_TEST
START_TEST(test_devices_filter)
{
OsinfoOs *os = osinfo_os_new("awesome");
OsinfoDevice *dev1 = osinfo_device_new("e1000");
OsinfoDevice *dev2 = osinfo_device_new("sb16");
OsinfoFilter *filter = osinfo_filter_new();
osinfo_entity_add_param(OSINFO_ENTITY(dev1), "class", "network");
osinfo_entity_add_param(OSINFO_ENTITY(dev2), "class", "audio");
OsinfoDeviceLink *link1 = osinfo_os_add_device(os, dev1);
osinfo_entity_add_param(OSINFO_ENTITY(link1), "driver", "pci-e1000");
OsinfoDeviceLink *link2 = osinfo_os_add_device(os, dev2);
osinfo_entity_add_param(OSINFO_ENTITY(link2), "driver", "isa-sb16");
osinfo_filter_add_constraint(filter, "class", "network");
OsinfoDeviceList *devices = osinfo_os_get_devices(os, filter);
fail_unless(osinfo_list_get_length(OSINFO_LIST(devices)) == 1, "Os has one devices");
OsinfoEntity *ent = osinfo_list_get_nth(OSINFO_LIST(devices), 0);
fail_unless(OSINFO_IS_DEVICE(ent), "entity is a device");
fail_unless(OSINFO_DEVICE(ent) == dev1, "device is e1000");
g_object_unref(devices);
g_object_unref(filter);
g_object_unref(dev1);
g_object_unref(dev2);
g_object_unref(os);
}
END_TEST
START_TEST(test_device_driver)
{
OsinfoOs *os = osinfo_os_new("awesome");
OsinfoDevice *dev1 = osinfo_device_new("e1000");
OsinfoDevice *dev2 = osinfo_device_new("rtl8139");
OsinfoFilter *filter = osinfo_filter_new();
osinfo_entity_add_param(OSINFO_ENTITY(dev1), "class", "network");
osinfo_entity_add_param(OSINFO_ENTITY(dev2), "class", "network");
OsinfoDeviceLink *link1 = osinfo_os_add_device(os, dev1);
osinfo_entity_add_param(OSINFO_ENTITY(link1), "driver", "pci-e1000");
OsinfoDeviceLink *link2 = osinfo_os_add_device(os, dev2);
osinfo_entity_add_param(OSINFO_ENTITY(link2), "driver", "pci-8139");
osinfo_filter_add_constraint(filter, "class", "network");
osinfo_filter_clear_constraints(filter);
osinfo_filter_add_constraint(filter, "class", "audio");
g_object_unref(filter);
g_object_unref(dev1);
g_object_unref(dev2);
g_object_unref(os);
}
END_TEST
static Suite *
os_suite(void)
{
Suite *s = suite_create("Os");
TCase *tc = tcase_create("Core");
tcase_add_test(tc, test_basic);
tcase_add_test(tc, test_loader);
tcase_add_test(tc, test_devices);
tcase_add_test(tc, test_devices_filter);
tcase_add_test(tc, test_device_driver);
suite_add_tcase(s, tc);
return s;
}
int main(void)
{
int number_failed;
Suite *s = os_suite();
SRunner *sr = srunner_create(s);
/* Make sure we catch unexpected g_warning() */
g_log_set_always_fatal(G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING);
/* Upfront so we don't confuse valgrind */
osinfo_platform_get_type();
osinfo_device_get_type();
osinfo_os_get_type();
osinfo_oslist_get_type();
osinfo_devicelist_get_type();
osinfo_filter_get_type();
srunner_run_all(sr, CK_ENV);
number_failed = srunner_ntests_failed(sr);
srunner_free(sr);
return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}
/*
* Local variables:
* indent-tabs-mode: nil
* c-indent-level: 4
* c-basic-offset: 4
* End:
*/
|