summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDaniel P. Berrange <berrange@redhat.com>2010-08-31 12:05:38 +0100
committerDaniel P. Berrange <berrange@redhat.com>2010-08-31 12:08:52 +0100
commit7a395674e3000d044de0af91da5d57965136cc72 (patch)
treec758421023d47443c3848e38f80c87d89aada234 /test
parentc43af5932df1d3bcbb32498e54df9bbdb044970e (diff)
Avoid directly exposing internal lists in OsinfoDb
Don't directly expose the OsinfoList objects used by the OsinfoDb class. Instead return a shallow copy of the lists. Add formal APIs for adding entities to the DB. * osinfo/osinfo_devicelist.c, osinfo/osinfo_devicelist.h, osinfo/osinfo_hypervisorlist.c, osinfo/osinfo_hypervisorlist.h, osinfo/osinfo_oslist.c, osinfo/osinfo_oslist.h: Add new constructor to copy an existing list * osinfo/osinfo_list.c, osinfo/osinfo_list.h: Add API to copy elements of an existing list * osinfo/osinfo_db.c, osinfo/osinfo_db.h: Shallow copy the lists before returning them. New APIs for adding entities to the DB. * test/test-list.c, test/test-db.c: Update for changed APIs
Diffstat (limited to 'test')
-rw-r--r--test/test-db.c109
-rw-r--r--test/test-list.c7
2 files changed, 63 insertions, 53 deletions
diff --git a/test/test-db.c b/test/test-db.c
index 92f08e0..d0c659c 100644
--- a/test/test-db.c
+++ b/test/test-db.c
@@ -20,11 +20,15 @@ START_TEST(test_device)
OsinfoDevice *dev2 = osinfo_device_new("dev2");
OsinfoDevice *dev3 = osinfo_device_new("dev3");
- OsinfoDeviceList *list = osinfo_db_get_device_list(db);
+ osinfo_db_add_device(db, dev1);
+ osinfo_db_add_device(db, dev2);
+ osinfo_db_add_device(db, dev3);
- osinfo_list_add(OSINFO_LIST(list), OSINFO_ENTITY(dev1));
- osinfo_list_add(OSINFO_LIST(list), OSINFO_ENTITY(dev2));
- osinfo_list_add(OSINFO_LIST(list), OSINFO_ENTITY(dev3));
+ OsinfoDeviceList *list = osinfo_db_get_device_list(db);
+ fail_unless(OSINFO_ENTITY(dev1) == osinfo_list_get_nth(OSINFO_LIST(list), 0), "Dev 1 is missing");
+ fail_unless(OSINFO_ENTITY(dev2) == osinfo_list_get_nth(OSINFO_LIST(list), 1), "Dev 2 is missing");
+ fail_unless(OSINFO_ENTITY(dev3) == osinfo_list_get_nth(OSINFO_LIST(list), 2), "Dev 3 is missing");
+ g_object_unref(list);
OsinfoDevice *dev = osinfo_db_get_device(db, "dev2");
fail_unless(dev != NULL, "Device is NULL");
@@ -41,23 +45,27 @@ END_TEST
START_TEST(test_hypervisor)
{
OsinfoDb *db = osinfo_db_new();
- OsinfoHypervisor *dev1 = osinfo_hypervisor_new("dev1");
- OsinfoHypervisor *dev2 = osinfo_hypervisor_new("dev2");
- OsinfoHypervisor *dev3 = osinfo_hypervisor_new("dev3");
+ OsinfoHypervisor *hv1 = osinfo_hypervisor_new("hv1");
+ OsinfoHypervisor *hv2 = osinfo_hypervisor_new("hv2");
+ OsinfoHypervisor *hv3 = osinfo_hypervisor_new("hv3");
- OsinfoHypervisorList *list = osinfo_db_get_hypervisor_list(db);
+ osinfo_db_add_hypervisor(db, hv1);
+ osinfo_db_add_hypervisor(db, hv2);
+ osinfo_db_add_hypervisor(db, hv3);
- osinfo_list_add(OSINFO_LIST(list), OSINFO_ENTITY(dev1));
- osinfo_list_add(OSINFO_LIST(list), OSINFO_ENTITY(dev2));
- osinfo_list_add(OSINFO_LIST(list), OSINFO_ENTITY(dev3));
+ OsinfoHypervisorList *list = osinfo_db_get_hypervisor_list(db);
+ fail_unless(OSINFO_ENTITY(hv1) == osinfo_list_get_nth(OSINFO_LIST(list), 0), "Hv 1 is missing");
+ fail_unless(OSINFO_ENTITY(hv2) == osinfo_list_get_nth(OSINFO_LIST(list), 1), "Hv 2 is missing");
+ fail_unless(OSINFO_ENTITY(hv3) == osinfo_list_get_nth(OSINFO_LIST(list), 2), "Hv 3 is missing");
+ g_object_unref(list);
- OsinfoHypervisor *dev = osinfo_db_get_hypervisor(db, "dev2");
- fail_unless(dev != NULL, "Hypervisor is NULL");
- fail_unless(dev == dev2, "Hypervisor was not dev2");
+ OsinfoHypervisor *hv = osinfo_db_get_hypervisor(db, "hv2");
+ fail_unless(hv != NULL, "Hypervisor is NULL");
+ fail_unless(hv == hv2, "Hypervisor was not hv2");
- g_object_unref(dev1);
- g_object_unref(dev2);
- g_object_unref(dev3);
+ g_object_unref(hv1);
+ g_object_unref(hv2);
+ g_object_unref(hv3);
g_object_unref(db);
}
END_TEST
@@ -66,23 +74,27 @@ END_TEST
START_TEST(test_os)
{
OsinfoDb *db = osinfo_db_new();
- OsinfoOs *dev1 = osinfo_os_new("dev1");
- OsinfoOs *dev2 = osinfo_os_new("dev2");
- OsinfoOs *dev3 = osinfo_os_new("dev3");
+ OsinfoOs *os1 = osinfo_os_new("os1");
+ OsinfoOs *os2 = osinfo_os_new("os2");
+ OsinfoOs *os3 = osinfo_os_new("os3");
- OsinfoOsList *list = osinfo_db_get_os_list(db);
+ osinfo_db_add_os(db, os1);
+ osinfo_db_add_os(db, os2);
+ osinfo_db_add_os(db, os3);
- osinfo_list_add(OSINFO_LIST(list), OSINFO_ENTITY(dev1));
- osinfo_list_add(OSINFO_LIST(list), OSINFO_ENTITY(dev2));
- osinfo_list_add(OSINFO_LIST(list), OSINFO_ENTITY(dev3));
+ OsinfoOsList *list = osinfo_db_get_os_list(db);
+ fail_unless(OSINFO_ENTITY(os1) == osinfo_list_get_nth(OSINFO_LIST(list), 0), "Os 1 is missing");
+ fail_unless(OSINFO_ENTITY(os2) == osinfo_list_get_nth(OSINFO_LIST(list), 1), "Os 2 is missing");
+ fail_unless(OSINFO_ENTITY(os3) == osinfo_list_get_nth(OSINFO_LIST(list), 2), "Os 3 is missing");
+ g_object_unref(list);
- OsinfoOs *dev = osinfo_db_get_os(db, "dev2");
- fail_unless(dev != NULL, "Os is NULL");
- fail_unless(dev == dev2, "Os was not dev2");
+ OsinfoOs *os = osinfo_db_get_os(db, "os2");
+ fail_unless(os != NULL, "Os is NULL");
+ fail_unless(os == os2, "Os was not os2");
- g_object_unref(dev1);
- g_object_unref(dev2);
- g_object_unref(dev3);
+ g_object_unref(os1);
+ g_object_unref(os2);
+ g_object_unref(os3);
g_object_unref(db);
}
END_TEST
@@ -102,11 +114,9 @@ START_TEST(test_prop_device)
osinfo_entity_add_param(OSINFO_ENTITY(dev3), "class", "display");
osinfo_entity_add_param(OSINFO_ENTITY(dev3), "fruit", "apple");
- OsinfoDeviceList *list = osinfo_db_get_device_list(db);
-
- osinfo_list_add(OSINFO_LIST(list), OSINFO_ENTITY(dev1));
- osinfo_list_add(OSINFO_LIST(list), OSINFO_ENTITY(dev2));
- osinfo_list_add(OSINFO_LIST(list), OSINFO_ENTITY(dev3));
+ osinfo_db_add_device(db, dev1);
+ osinfo_db_add_device(db, dev2);
+ osinfo_db_add_device(db, dev3);
GList *uniq = osinfo_db_unique_values_for_property_in_dev(db, "class");
GList *tmp = uniq;
@@ -157,11 +167,9 @@ START_TEST(test_prop_hypervisor)
osinfo_entity_add_param(OSINFO_ENTITY(hv3), "vendor", "dog");
osinfo_entity_add_param(OSINFO_ENTITY(hv3), "arch", "x86");
- OsinfoHypervisorList *list = osinfo_db_get_hypervisor_list(db);
-
- osinfo_list_add(OSINFO_LIST(list), OSINFO_ENTITY(hv1));
- osinfo_list_add(OSINFO_LIST(list), OSINFO_ENTITY(hv2));
- osinfo_list_add(OSINFO_LIST(list), OSINFO_ENTITY(hv3));
+ osinfo_db_add_hypervisor(db, hv1);
+ osinfo_db_add_hypervisor(db, hv2);
+ osinfo_db_add_hypervisor(db, hv3);
GList *uniq = osinfo_db_unique_values_for_property_in_hv(db, "vendor");
GList *tmp = uniq;
@@ -208,12 +216,9 @@ START_TEST(test_prop_os)
osinfo_entity_add_param(OSINFO_ENTITY(os3), "vendor", "dog");
osinfo_entity_add_param(OSINFO_ENTITY(os3), "arch", "x86");
-
- OsinfoOsList *list = osinfo_db_get_os_list(db);
-
- osinfo_list_add(OSINFO_LIST(list), OSINFO_ENTITY(os1));
- osinfo_list_add(OSINFO_LIST(list), OSINFO_ENTITY(os2));
- osinfo_list_add(OSINFO_LIST(list), OSINFO_ENTITY(os3));
+ osinfo_db_add_os(db, os1);
+ osinfo_db_add_os(db, os2);
+ osinfo_db_add_os(db, os3);
GList *uniq = osinfo_db_unique_values_for_property_in_os(db, "vendor");
GList *tmp = uniq;
@@ -257,13 +262,11 @@ START_TEST(test_rel_os)
OsinfoOs *os4 = osinfo_os_new("os4");
OsinfoOs *os5 = osinfo_os_new("os5");
- OsinfoOsList *list = osinfo_db_get_os_list(db);
-
- osinfo_list_add(OSINFO_LIST(list), OSINFO_ENTITY(os1));
- osinfo_list_add(OSINFO_LIST(list), OSINFO_ENTITY(os2));
- osinfo_list_add(OSINFO_LIST(list), OSINFO_ENTITY(os3));
- osinfo_list_add(OSINFO_LIST(list), OSINFO_ENTITY(os4));
- osinfo_list_add(OSINFO_LIST(list), OSINFO_ENTITY(os5));
+ osinfo_db_add_os(db, os1);
+ osinfo_db_add_os(db, os2);
+ osinfo_db_add_os(db, os3);
+ osinfo_db_add_os(db, os4);
+ osinfo_db_add_os(db, os5);
osinfo_os_add_related_os(os1, OSINFO_OS_RELATIONSHIP_DERIVES_FROM, os2);
osinfo_os_add_related_os(os1, OSINFO_OS_RELATIONSHIP_DERIVES_FROM, os3);
diff --git a/test/test-list.c b/test/test-list.c
index d90440d..68e0eba 100644
--- a/test/test-list.c
+++ b/test/test-list.c
@@ -53,6 +53,13 @@ START_TEST(test_basic)
fail_unless(osinfo_list_get_length(list) == 0, "List was not empty");
fail_unless(osinfo_list_find_by_id(list, "wibble") == NULL, "List was not empty");
+ GType type;
+ g_object_get(list, "element-type", &type, NULL);
+ fail_unless(type == OSINFO_TYPE_ENTITY, "Type is not entity");
+
+ type = osinfo_list_get_element_type(list);
+ fail_unless(type == OSINFO_TYPE_ENTITY, "Type is not entity");
+
g_object_unref(list);
}
END_TEST