summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorArjun Roy <arroy@redhat.com>2010-07-01 08:43:10 -0700
committerArjun Roy <arroy@redhat.com>2010-07-01 08:43:10 -0700
commitcc731ae23bd0039e22ead619eebbed1ccd76dd9e (patch)
tree0871329006b13c86fc699a18c0a06bcfb2443762 /test
parent47e03e683f9d70feca8f249291f70e82cf4960fb (diff)
Moved over API to use glib/gobject.
API definitions have changed, though functionality remains identical. Added new features to list classes. TODO: Extensive testing. Codebase compiles and simplest test of creating/destroying DB works, but more is required.
Diffstat (limited to 'test')
-rw-r--r--test/sample.c168
-rw-r--r--test/test-filter.c167
-rw-r--r--test/test-get_devices.c201
-rw-r--r--test/test-get_os.c159
-rw-r--r--test/test-manipulate_devices.c136
-rw-r--r--test/test-manipulate_hypervisor.c146
-rw-r--r--test/test-manipulate_library.c75
-rw-r--r--test/test-manipulate_os.c168
-rw-r--r--test/test-set_hypervisor.c157
-rw-r--r--test/test-skeleton.c75
-rw-r--r--test/tests16
11 files changed, 71 insertions, 1397 deletions
diff --git a/test/sample.c b/test/sample.c
deleted file mode 100644
index 11ed2a3..0000000
--- a/test/sample.c
+++ /dev/null
@@ -1,168 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <assert.h>
-#include <libosinfo.h>
-
-int main(int argc, char** argv)
-{
- int i, ret, count, err;
- osi_lib_t lib;
- osi_filter_t filter;
- osi_os_t rhel, os;
- osi_os_list_t results, more_results;
- char* os_id;
- char* data_dir;
-
- if (argc != 2) {
- printf("Need to specify data dir.\n");
- exit(1);
- }
-
- data_dir = argv[1];
-
- lib = osi_get_lib_handle(&err, data_dir);
- if (err != 0) {
- printf("Error: Could not get lib handle.\n");
- exit(1);
- }
-
- ret = osi_set_lib_param(lib, "libvirt-version", "3.4");
- if (ret != 0) {
- printf("Error: Could not set libvirt version!\n");
- exit(1);
- }
-
- ret = osi_set_lib_hypervisor(lib, "http://qemu.org/qemu-kvm-0.11.0");
- if (ret != 0) {
- printf("Error: Could not set hypervisor!\n");
- exit(1);
- }
-
- ret = osi_init_lib(lib);
- if (ret != 0) {
- printf("Error: Could not set initialize libosinfo!\n");
- exit(1);
- }
-
- filter = osi_get_filter(lib, &err);
- if (err != 0) {
- printf("Error: Could not get filter!\n");
- exit(1);
- }
-
- ret = osi_add_filter_constraint(filter, "short-id", "fedora11");
- if (ret != 0) {
- printf("Error: Could not set constraint!\n");
- exit(1);
- }
-
- results = osi_get_os_list(lib, filter, &err);
- if (err != 0) {
- printf("Bad result list!\n");
- exit(1);
- }
-
- if (osi_os_list_length(results) == 0) {
- printf("No results. Quitting...\n");
- exit(0);
- }
- else if (osi_os_list_length(results) > 1) {
- printf("Failed sanity check. 'short-id' should be unique...\n");
- exit(1);
- }
-
- rhel = osi_get_os_by_index(results, 0, &err);
- if (err != 0) {
- printf("Couldn't get os!\n");
- exit(1);
- }
-
- // Now that we have a handle to rhel5.4, we can free the results list
- // that we used to get to it. The handle to the single os is still
- // valid though, and we use it for the next step
- ret = osi_free_os_list(results); // Done with that list so get rid of it
- if (ret != 0) {
- printf("Error freeing os list!\n");
- exit(1);
- }
-
- // We shall reuse the filter
- ret = osi_clear_all_constraints(filter);
- if (ret != 0) {
- printf("Error clearing constraints!\n");
- exit(1);
- }
-
- if (osi_add_filter_constraint(filter, "vendor", "Fedora Project") != 0) {
- printf("Error adding constraints!\n");
- exit(1);
- }
-
- more_results = osi_get_os_list(lib, filter, &err);
- if (err != 0) {
- printf("Bad result list!\n");
- exit(1);
- }
-
- // For each os:
- count = osi_os_list_length(more_results);
- for (i = 0; i < count; i++) {
- int j, num;
- os = osi_get_os_by_index(more_results, i, &err);
- if (err != 0) {
- printf("Couldn't get os!\n");
- exit(1);
- }
- char* osname = osi_get_os_property_first_value(os, "name", &err);
- if (err != 0) {
- printf("Couldn't get property!\n");
- exit(1);
- }
- printf ("osname: %s\n", osname);
-
- osi_device_list_t audio_devices = osi_os_devices(os, "audio", NULL, &err);
- num = osi_devices_list_length(audio_devices);
- os_id = osi_get_os_id(os, &err);
-
- // For each audio device:
- for (j = 0; j < num; j++) {
- osi_device_t device = osi_get_device_by_index(audio_devices, j, &err);
- printf("Audio device for %s:\n", os_id);
- printf("\tBus Type: %s Vendor: %s Product: %s\n",
- osi_get_device_property_value(device, "bus-type", &err),
- osi_get_device_property_value(device, "vendor", &err),
- osi_get_device_property_value(device, "product", &err));
- printf("\tDriver is: %s\n", osi_get_device_driver(device, "audio", os, &err));
- }
-
- // And free the os id string and list of audio devices for this distro
- free(os_id);
- ret = osi_free_devices_list(audio_devices);
- if (ret != 0) {
- printf("Error freeing devices list!\n");
- exit(1);
- }
- }
-
- ret = osi_free_os_list(more_results); // Done with that list
- if (ret != 0) {
- printf("Error freeing distro list!\n");
- exit(1);
- }
-
- ret = osi_free_filter(filter); // Done with the filter
- if (ret != 0) {
- printf("Error freeing filter!\n");
- exit(1);
- }
-
- ret = osi_close_lib(lib);
- if (ret != 0) {
- printf("Error cleaning up library handle!\n");
- exit(1);
- }
-
- printf("Done.\n");
- return 0;
-}
diff --git a/test/test-filter.c b/test/test-filter.c
deleted file mode 100644
index 55eb2fd..0000000
--- a/test/test-filter.c
+++ /dev/null
@@ -1,167 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <assert.h>
-#include <libosinfo.h>
-
-int main(int argc, char** argv)
-{
- int ret, len, err;
- osi_lib_t lib;
- osi_filter_t filter;
- osi_os_t os, os_check;
- char** filter_properties;
- char* value, * os_id, * os_check_id;
- char* data_dir;
-
- assert ( argc == 2 );
- data_dir = argv[1];
-
- printf("Starting test-filter...\n");
- printf("Checking to see if we got library handle...\n");
- lib = osi_get_lib_handle(&err, data_dir);
- assert ( err == 0 );
-
- /* Initializing library */
- printf("Initializing library...\n");
- ret = osi_init_lib(lib);
- assert ( ret == 0 );
-
- /* Ensure that freeing an uninitialized filter is invalid */
- printf("Checking that freeing unitialized filter is invalid...\n");
- memset (&filter, sizeof filter, 0);
- ret = osi_free_filter(filter);
- assert ( ret != 0 );
-
- /* Get the filter */
- printf("Getting filter...\n");
- filter = osi_get_filter(lib, &err);
- assert ( err == 0 );
-
- /* Add bad filter constraints */
- printf("Adding bad constraints...\n");
- ret = osi_add_filter_constraint(filter, "", "0x1274");
- assert ( ret != 0 );
- ret = osi_add_filter_constraint(filter, "vendor", "");
- assert ( ret != 0 );
- ret = osi_add_filter_constraint(filter, NULL, "0x1274");
- assert ( ret != 0 );
- ret = osi_add_filter_constraint(filter, "vendor", NULL);
- assert ( ret != 0 );
-
- /* Add constraints */
- printf("Adding constraints...\n");
- ret = osi_add_filter_constraint(filter, "vendor", "0x1274");
- assert ( ret == 0 );
- ret = osi_add_filter_constraint(filter, "vendor", "0x1274");
- assert ( ret == 0 );
- ret = osi_add_filter_constraint(filter, "bus-type", "pci");
- assert ( ret == 0 );
-
- /* Check that the appropriate constraints were set */
- printf("Double checking that constraints are good...\n");
- filter_properties = osi_get_filter_constraint_keys(filter, &len, &err);
- assert ( err == 0 );
- assert ( len == 2 );
- assert ( filter_properties != NULL );
- assert ( strcmp(filter_properties[0], "vendor") == 0 );
- assert ( strcmp(filter_properties[1], "bus-type") == 0 );
- free(filter_properties[0]);
- free(filter_properties[1]);
- free(filter_properties);
-
- value = osi_get_filter_constraint_value(filter, "vendor", &err);
- assert ( err == 0 );
- assert ( value != NULL );
- assert ( strcmp(value, "0x1274") == 0 );
- free(value);
-
- value = osi_get_filter_constraint_value(filter, "bus-type", &err);
- assert ( err == 0 );
- assert ( value != NULL );
- assert ( strcmp(value, "pci") == 0 );
- free(value);
-
- /* Test adding a relationship constraint with a bad os parameter */
- printf("Test adding a relationship constraint with a bad os parameter...\n");
- ret = osi_add_relation_constraint(filter, DERIVES_FROM, os);
- assert ( ret != 0 );
-
- /* Get an OS by id so we can add relationship filters as well */
- printf("Getting an os object to test adding relationship filter...\n");
- os = osi_get_os_by_id(lib, "http://fedoraproject.org/fedora-11", &err);
- assert ( err == 0 );
-
- /* Add a relationship constraint with this os */
- printf("Test adding a relationship constraint with a valid os parameter...\n");
- ret = osi_add_relation_constraint(filter, DERIVES_FROM, os);
- assert ( ret == 0 );
-
- /* Check the relationship constraint we didn't add */
- printf("Testing an unadded relationship constraint...\n");
- os_check = osi_get_relationship_constraint_value(filter, CLONES, &err);
- assert ( err == 0 );
- assert ( os_check == NULL );
-
- /* Check the relationship constraint we added */
- printf("Testing relationship constraints...\n");
- os_check = osi_get_relationship_constraint_value(filter, DERIVES_FROM, &err);
- assert ( err == 0 );
-
- os_id = osi_get_os_id(os, &err);
- assert ( err == 0 );
- assert ( os_id != NULL );
-
- os_check_id = osi_get_os_id(os_check, &err);
- assert ( err == 0 );
- assert ( os_check_id != NULL );
-
- assert ( strcmp(os_id, os_check_id) == 0 );
- free(os_id);
- free(os_check_id);
-
- /* Clear constraints */
- printf("Clearing non-existent constraint...\n");
- ret = osi_clear_filter_constraint(filter, "bad-param");
- assert ( ret != 0 );
-
- /* Clear filter constraint and check */
- printf("Clearing filter constraint...\n");
- ret = osi_clear_filter_constraint(filter, "vendor");
- assert ( ret == 0 );
- value = osi_get_filter_constraint_value(filter, "vendor", &err);
- assert ( err == 0 );
- assert ( value == NULL );
-
- /* Clear relationship constraint and check */
- printf("Clearing relationship constraint...\n");
- ret = osi_clear_relation_constraint(filter, DERIVES_FROM);
- assert ( ret == 0 );
- os_check = osi_get_relationship_constraint_value(filter, DERIVES_FROM, &err);
- assert ( err == 0 );
- assert ( os_check == NULL );
-
- /* Clear all remaining constraints and check */
- printf("Clearing all remaining relationship constraints...\n");
- ret = osi_clear_all_constraints(filter);
- assert ( ret == 0 );
- value = osi_get_filter_constraint_value(filter, "bus-type", &err);
- assert ( err == 0 );
- assert ( value == NULL );
- ret = osi_clear_filter_constraint(filter, "bus-type");
- assert ( ret != 0 );
-
- /* Free the filter */
- printf("Freeing filter...\n");
- ret = osi_free_filter(filter);
- assert ( ret == 0 );
-
- /* Close library */
- printf("Closing library...\n");
- ret = osi_close_lib(lib);
- assert ( ret == 0 );
-
- printf("test-filter succeeded.\n");
- return 0;
-}
diff --git a/test/test-get_devices.c b/test/test-get_devices.c
deleted file mode 100644
index ac00ee6..0000000
--- a/test/test-get_devices.c
+++ /dev/null
@@ -1,201 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <assert.h>
-#include <libosinfo.h>
-
-int main(int argc, char** argv)
-{
- int ret, err, len;
- osi_lib_t lib;
- osi_hypervisor_t hv;
- osi_device_list_t all_audio_devices, subset_audio_devices;
- osi_device_t audio_device;
- osi_os_t os;
- osi_filter_t filter;
- char* value;
- char* data_dir;
-
- assert ( argc == 2 );
- data_dir = argv[1];
-
- printf("Starting test-get_devices...\n");
- printf("Checking to see if we got library handle...\n");
- lib = osi_get_lib_handle(&err, data_dir);
- assert ( err == 0 );
-
- /* Set hypervisor for library */
- printf("Setting hypervisor...\n");
- ret = osi_set_lib_hypervisor(lib, "http://qemu.org/qemu-kvm-0.11.0");
- assert ( ret == 0 );
-
- /* Initializing library */
- printf("Initializing library...\n");
- ret = osi_init_lib(lib);
- assert ( ret == 0 );
-
- /* Get handle to hypervisor */
- printf("Getting handle to hypervisor...\n");
- hv = osi_get_lib_hypervisor(lib, &err);
- assert ( err == 0 );
-
- /* Get all devices in the audio section for the hypervisor */
- printf("Getting all devices in the audio section...\n");
- all_audio_devices = osi_hypervisor_devices(hv, "audio", NULL, &err);
- assert ( err == 0 );
-
- /* Check that we have the expected number of devices */
- printf("Checking number of audio devices...\n");
- len = osi_devices_list_length(all_audio_devices);
- assert ( len == 3 );
-
- /* Check each device */
- printf("Checking first (out of three) audio devices...\n");
- audio_device = osi_get_device_by_index(all_audio_devices, 0, &err);
- assert ( err == 0 );
- value = osi_device_id(audio_device, &err);
- assert ( err == 0 );
- assert ( strcmp("http://pci-ids.ucw.cz/read/PC/1002/4382", value) == 0 );
- free(value);
- ret = osi_cleanup_handle(audio_device);
- assert ( ret == 0 );
-
- printf("Checking second (out of three) audio devices...\n");
- audio_device = osi_get_device_by_index(all_audio_devices, 1, &err);
- assert ( err == 0 );
- value = osi_device_id(audio_device, &err);
- assert ( err == 0 );
- assert ( strcmp("http://pci-ids.ucw.cz/read/PC/1274/5000", value) == 0 );
- free(value);
- ret = osi_cleanup_handle(audio_device);
- assert ( ret == 0 );
-
- printf("Checking third (out of three) audio devices...\n");
- audio_device = osi_get_device_by_index(all_audio_devices, 2, &err);
- assert ( osi_is_error(audio_device) == 0 );
- value = osi_device_id(audio_device, &err);
- assert ( err == 0 );
- assert ( strcmp("http://pci-ids.ucw.cz/read/PC/1274/1371/80864541", value) == 0 );
- free(value);
- ret = osi_cleanup_handle(audio_device);
- assert ( ret == 0 );
-
- /* Done with the devices list from hypervisor, get rid of it */
- printf("Done with audio devices list from hypervisor, cleaning it up...\n");
- ret = osi_free_devices_list(all_audio_devices);
- assert ( ret == 0 );
-
- /* Get an OS by id so we can check <os,hv> device properties */
- printf("Getting an os object to test more device methods...\n");
- os = osi_get_os_by_id(lib, "http://fedoraproject.org/fedora-11", &err);
- assert ( err == 0 );
-
- /* Get all audio devices for supported by the os, for the given hv */
- printf("Getting all supported audio devices for given <os, hv>...\n");
- all_audio_devices = osi_os_devices(os, "audio", NULL, &err);
- assert ( err == 0 );
-
- /* Check each device */
- printf("Checking first (out of three) audio devices for <os,hv>...\n");
- audio_device = osi_get_device_by_index(all_audio_devices, 0, &err);
- assert ( err == 0 );
- value = osi_device_id(audio_device, &err);
- assert ( err == 0 );
- assert ( strcmp("http://pci-ids.ucw.cz/read/PC/1274/5000", value) == 0 );
- free(value);
- ret = osi_cleanup_handle(audio_device);
- assert ( ret == 0 );
-
- printf("Checking second (out of three) audio devices for <os,hv>...\n");
- audio_device = osi_get_device_by_index(all_audio_devices, 1, &err);
- assert ( err == 0 );
- value = osi_device_id(audio_device, &err);
- assert ( err == 0 );
- assert ( strcmp("http://pci-ids.ucw.cz/read/PC/1002/4382", value) == 0 );
- free(value);
- ret = osi_cleanup_handle(audio_device);
- assert ( ret == 0 );
-
- printf("Checking third (out of three) audio devices for <os,hv>...\n");
- audio_device = osi_get_device_by_index(all_audio_devices, 2, &err);
- assert ( err == 0 );
- value = osi_device_id(audio_device, &err);
- assert ( err == 0 );
- assert ( strcmp("http://pci-ids.ucw.cz/read/PC/1274/1371/80864541", value) == 0 );
- free(value);
- ret = osi_cleanup_handle(audio_device);
- assert ( ret == 0 );
-
- /* Done with the devices list from <os,hv>, get rid of it */
- printf("Done with audio devices list from <os,hv>, cleaning it up...\n");
- ret = osi_free_devices_list(all_audio_devices);
- assert ( ret == 0 );
-
- /* Set up a filter to get a reduced list of devices */
- filter = osi_get_filter(lib, &err);
- assert ( err == 0 );
- ret = osi_add_filter_constraint(filter, "vendor", "0x1274");
- assert ( ret == 0 );
-
- /* Now get all audio devices that match a given property/value */
- printf("Now getting all audio devices for <os,hv> for given property...\n");
- subset_audio_devices = osi_os_devices(os, "audio", filter, &err);
- assert ( err == 0 );
-
- /* Check each device */
- printf("Checking first (out of two) audio devices for <os,hv, property>...\n");
- audio_device = osi_get_device_by_index(subset_audio_devices, 0, &err);
- assert ( err == 0 );
- value = osi_device_id(audio_device, &err);
- assert ( err == 0 );
- assert ( strcmp("http://pci-ids.ucw.cz/read/PC/1274/5000", value) == 0 );
- free(value);
- ret = osi_cleanup_handle(audio_device);
- assert ( ret == 0 );
-
- printf("Checking second (out of two) audio devices for <os,hv, property>...\n");
- audio_device = osi_get_device_by_index(subset_audio_devices, 1, &err);
- assert ( err == 0 );
- value = osi_device_id(audio_device, &err);
- assert ( err == 0 );
- assert ( strcmp("http://pci-ids.ucw.cz/read/PC/1274/1371/80864541", value) == 0 );
- free(value);
- ret = osi_cleanup_handle(audio_device);
- assert ( ret == 0 );
-
- /* Done with the devices list from <os,hv, property>, get rid of it */
- printf("Done with audio devices list from <os,hv>, cleaning it up...\n");
- ret = osi_free_devices_list(subset_audio_devices);
- assert ( ret == 0 );
-
- /* Finally, check the preferred audio device for <os,hv> */
- audio_device = osi_get_preferred_device(os, "audio", filter, &err);
- assert ( err == 0 );
- value = osi_device_id(audio_device, &err);
- assert ( err == 0 );
- assert ( strcmp("http://pci-ids.ucw.cz/read/PC/1274/5000", value) == 0 );
- free(value);
- ret = osi_cleanup_handle(audio_device);
- assert ( ret == 0 );
-
- /* Get rid of filter */
- ret = osi_free_filter(filter);
- assert ( ret == 0 );
-
- /* Get rid of os handle */
- ret = osi_cleanup_handle(os);
- assert ( ret == 0 );
-
- /* Get rid of hv handle */
- ret = osi_cleanup_handle(hv);
- assert ( ret == 0 );
-
- /* Close library */
- printf("Closing library...\n");
- ret = osi_close_lib(lib);
- assert ( ret == 0 );
-
- printf("test-get_devices succeeded.\n");
- return 0;
-}
diff --git a/test/test-get_os.c b/test/test-get_os.c
deleted file mode 100644
index 83d6acd..0000000
--- a/test/test-get_os.c
+++ /dev/null
@@ -1,159 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <assert.h>
-#include <libosinfo.h>
-
-int main(int argc, char** argv)
-{
- int ret, err;
- osi_lib_t lib;
- osi_os_t os;
- osi_os_list_t os_list;
- osi_filter_t filter;
- char* value;
- char* data_dir;
-
- assert ( argc == 2 );
- data_dir = argv[1];
-
- printf("Starting test-get_os...\n");
- printf("Checking to see if we got library handle...\n");
- lib = osi_get_lib_handle(&err, data_dir);
- assert ( err == 0 );
-
- /* Initializing library */
- printf("Initializing library...\n");
- ret = osi_init_lib(lib);
- assert ( ret == 0 );
-
- /* First get all the OS objects that we know about */
- printf("Get list with all operating systems...\n");
- filter = NULL;
- os_list = osi_get_os_list(lib, filter, &err);
- assert ( err == 0 );
- assert ( osi_os_list_length(os_list) == 3 );
-
- printf("Verify that the expected operating systems are present...\n");
- os = osi_get_os_by_index(os_list, 0, &err);
- assert ( err == 0 );
- value = osi_get_os_id(os, &err);
- assert ( err == 0 );
- assert ( value != NULL );
- assert ( strcmp(value, "http://fedoraproject.org/fedora-11") == 0 );
- free(value);
- ret = osi_cleanup_handle(os);
- assert ( ret == 0 );
-
- os = osi_get_os_by_index(os_list, 1, &err);
- assert ( err == 0 );
- value = osi_get_os_id(os, &err);
- assert ( err == 0 );
- assert ( value != NULL );
- assert ( strcmp(value, "http://fedoraproject.org/fedora-10") == 0 );
- free(value);
- ret = osi_cleanup_handle(os);
- assert ( ret == 0 );
-
- os = osi_get_os_by_index(os_list, 2, &err);
- assert ( err == 0 );
- value = osi_get_os_id(os, &err);
- assert ( err == 0 );
- assert ( value != NULL );
- assert ( strcmp(value, "http://software.opensuse.org/112") == 0 );
- free(value);
- ret = osi_cleanup_handle(os);
- assert ( ret == 0 );
-
- /* Freeing os list */
- printf("Done with this list, freeing...\n");
- ret = osi_free_os_list(os_list);
- assert ( ret == 0 );
-
- /* Now test with filter */
- printf("Testing os list filtering...\n");
- filter = osi_get_filter(lib, &err);
- assert ( err == 0 );
- ret = osi_add_filter_constraint(filter, "vendor", "Fedora Project");
- assert ( ret == 0 );
-
- os_list = osi_get_os_list(lib, filter, &err);
- assert ( err == 0 );
- assert ( osi_os_list_length(os_list) == 2 );
-
- printf("Verify that the expected operating systems are present...\n");
- os = osi_get_os_by_index(os_list, 0, &err);
- assert ( err == 0 );
- value = osi_get_os_id(os, &err);
- assert ( err == 0 );
- assert ( value != NULL );
- assert ( strcmp(value, "http://fedoraproject.org/fedora-11") == 0 );
- free(value);
- ret = osi_cleanup_handle(os);
- assert ( ret == 0 );
-
- os = osi_get_os_by_index(os_list, 1, &err);
- assert ( err == 0 );
- value = osi_get_os_id(os, &err);
- assert ( err == 0 );
- assert ( value != NULL );
- assert ( strcmp(value, "http://fedoraproject.org/fedora-10") == 0 );
- free(value);
- ret = osi_cleanup_handle(os);
- assert ( ret == 0 );
-
- /* Freeing os list */
- printf("Done with this list, freeing...\n");
- ret = osi_free_os_list(os_list);
- assert ( ret == 0 );
-
-
- /* Get an OS by id so we can check relationship filtering */
- printf("Getting an os object to test more os/filter methods...\n");
- os = osi_get_os_by_id(lib, "http://fedoraproject.org/fedora-10", &err);
- assert ( err == 0 );
-
- /* Use Fedora10 os reference to find operating systems that upgrade it */
- printf("Testing filtering based on os relationships...\n");
- ret = osi_clear_all_constraints(filter);
- assert ( ret == 0 );
- ret = osi_add_relation_constraint(filter, UPGRADES, os);
- assert ( ret == 0 );
-
- /* Done with F10 reference so clear it */
- ret = osi_cleanup_handle(os);
- assert ( ret == 0 );
-
- /* Get the filtered by relationships os list */
- os_list = osi_get_os_list(lib, filter, &err);
- assert ( err == 0 );
- assert ( osi_os_list_length(os_list) == 1 );
-
- /* Free filter */
- ret = osi_free_filter(filter);
- assert ( ret == 0 );
-
- printf("Verify that the expected operating systems are present...\n");
- os = osi_get_os_by_index(os_list, 0, &err);
- value = osi_get_os_id(os, &err);
- assert ( err == 0 );
- assert ( value != NULL );
- assert ( strcmp(value, "http://fedoraproject.org/fedora-11") == 0 );
- free(value);
- ret = osi_cleanup_handle(os);
- assert ( ret == 0 );
-
- /* Freeing os list */
- printf("Done with this list, freeing...\n");
- ret = osi_free_os_list(os_list);
- assert ( ret == 0 );
-
- /* Close library */
- printf("Closing library...\n");
- ret = osi_close_lib(lib);
- assert ( ret == 0 );
-
- printf("test-get_os succeeded.\n");
- return 0;
-}
diff --git a/test/test-manipulate_devices.c b/test/test-manipulate_devices.c
deleted file mode 100644
index 3b19b0c..0000000
--- a/test/test-manipulate_devices.c
+++ /dev/null
@@ -1,136 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <assert.h>
-#include <libosinfo.h>
-
-int main(int argc, char** argv)
-{
- int ret, err, len;
- osi_lib_t lib;
- osi_device_t device;
- osi_os_t f10, f11;
- char** all_properties;
- char** all_values;
- char* value;
- char* f10_driver, * f11_driver;
- char* data_dir;
-
- assert ( argc == 2 );
- data_dir = argv[1];
-
- printf("Starting test-get_os...\n");
- printf("Checking to see if we got library handle...\n");
- lib = osi_get_lib_handle(&err, data_dir);
- assert ( err == 0 );
-
- /* Initializing library */
- printf("Initializing library...\n");
- ret = osi_init_lib(lib);
- assert ( ret == 0 );
-
- /* Get device by ID */
- printf("Acquiring device handle...\n");
- device = osi_get_device_by_id(lib, "http://pci-ids.ucw.cz/read/PC/1274/5000", &err);
- assert ( err == 0 );
-
- /* Check that ID is sane */
- printf("Double checking device id...\n");
- value = osi_device_id(device, &err);
- assert ( err == 0 );
- assert ( value != NULL );
- assert ( strcmp(value, "http://pci-ids.ucw.cz/read/PC/1274/5000") == 0 );
- free(value);
-
- /* Get an OS by id so we can check device driver */
- printf("Getting an os object to test device driver property...\n");
- f10 = osi_get_os_by_id(lib, "http://fedoraproject.org/fedora-10", &err);
- assert ( err == 0 );
- f11 = osi_get_os_by_id(lib, "http://fedoraproject.org/fedora-11", &err);
- assert ( err == 0 );
-
- /* Check all defined properties for device */
- printf("Checking all defined properties for device...\n");
- all_properties = osi_get_all_device_property_keys(device, &len, &err);
- assert ( err == 0 );
- assert ( len == 5 );
- assert ( all_properties != NULL );
-
- assert( strcmp("class", all_properties[0]) == 0 );
- assert( strcmp("bus-type", all_properties[1]) == 0 );
- assert( strcmp("vendor", all_properties[2]) == 0 );
- assert( strcmp("product", all_properties[3]) == 0 );
- assert( strcmp("name", all_properties[4]) == 0 );
-
- free(all_properties[0]);
- free(all_properties[1]);
- free(all_properties[2]);
- free(all_properties[3]);
- free(all_properties[4]);
- free(all_properties);
-
- /* Check multiple valued properties */
- printf("Checking properties with multiple values...\n");
- all_values = osi_get_device_property_all_values(device, "name", &len, &err);
- assert ( err == 0 );
- assert ( len == 2 );
- assert ( all_values != NULL );
- assert ( strcmp("ES1370", all_values[0]) == 0 );
- assert ( strcmp("es1370", all_values[1]) == 0 );
- free(all_values[0]);
- free(all_values[1]);
- free(all_values);
-
- value = osi_get_device_property_value(device, "name", &err);
- assert ( err == 0 );
- assert ( value != NULL );
- assert ( strcmp("ES1370", value) == 0 );
- free(value);
-
- /* Check single valued property */
- printf("Checking single valued property...\n");
- value = osi_get_device_property_value(device, "bus-type", &err);
- assert ( err == 0 );
- assert ( value != NULL );
- assert ( strcmp("pci", value) == 0 );
- free(value);
-
- all_values = osi_get_device_property_all_values(device, "bus-type", &len, &err);
- assert ( err == 0 );
- assert ( len == 1 );
- assert ( all_values != NULL );
- assert ( strcmp("pci", all_values[0]) == 0 );
- free(all_values[0]);
- free(all_values);
-
- /* Test device driver */
- printf("Test device drivers...\n");
- f10_driver = osi_get_device_driver(device, "audio", f10, &err);
- assert ( err == 0 );
- assert ( f10_driver != NULL);
- assert ( strcmp(f10_driver, "ac97") == 0 );
- free(f10_driver);
-
- f11_driver = osi_get_device_driver(device, "audio", f11, &err);
- assert ( err == 0 );
- assert ( f11_driver != NULL);
- assert ( strcmp(f11_driver, "ac97+") == 0 );
- free(f11_driver);
-
- /* Dispose of device and os handles */
- ret = osi_cleanup_handle(device);
- assert ( ret == 0 );
- ret = osi_cleanup_handle(f10);
- assert ( ret == 0 );
- ret = osi_cleanup_handle(f11);
- assert ( ret == 0 );
-
- /* Close library */
- printf("Closing library...\n");
- ret = osi_close_lib(lib);
- assert ( ret == 0 );
-
- printf("test-manipulate_devices succeeded.\n");
- return 0;
-}
diff --git a/test/test-manipulate_hypervisor.c b/test/test-manipulate_hypervisor.c
deleted file mode 100644
index 23c11aa..0000000
--- a/test/test-manipulate_hypervisor.c
+++ /dev/null
@@ -1,146 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <assert.h>
-#include <libosinfo.h>
-
-int main(int argc, char** argv)
-{
- int i, ret, num, err;
- osi_lib_t lib;
- osi_hypervisor_t hv;
- char** hv_all_properties;
- char** hv_all_values;
- char** hv_dev_sections;
- char* value;
- char* data_dir;
-
- assert ( argc == 2 );
- data_dir = argv[1];
-
- printf("Starting test...\n");
- printf("Checking to see if we got library handle...\n");
- lib = osi_get_lib_handle(&err, data_dir);
- assert ( err == 0 );
-
- /* Set hypervisors for libraries */
- printf("Setting hypervisor...\n");
- ret = osi_set_lib_hypervisor(lib, "http://qemu.org/qemu-kvm-0.11.0");
- assert ( ret == 0 );
-
- /* Initializing library */
- printf("Initializing library...\n");
- ret = osi_init_lib(lib);
- assert ( ret == 0 );
-
- /* Get handle to hypervisor */
- hv = osi_get_lib_hypervisor(lib, &err);
- assert ( err == 0 );
-
- /* Get all properties for the hypervisor. */
- hv_all_properties = osi_get_hv_all_property_keys(hv, &num, &err);
- assert ( err == 0 );
- assert ( num == 3 ); /* We control the test data */
- assert ( hv_all_properties != NULL );
-
- /* Check that name, version and updates-version properties are defined */
- printf("Checking for name property...\n");
- assert ( strcmp(hv_all_properties[0], "name") == 0 ||
- strcmp(hv_all_properties[1], "name") == 0 ||
- strcmp(hv_all_properties[2], "name") == 0 );
- printf("Checking for version property...\n");
- assert ( strcmp(hv_all_properties[0], "version") == 0 ||
- strcmp(hv_all_properties[1], "version") == 0 ||
- strcmp(hv_all_properties[2], "version") == 0 );
- printf("Checking for updates-version property...\n");
- assert ( strcmp(hv_all_properties[0], "updates-version") == 0 ||
- strcmp(hv_all_properties[1], "updates-version") == 0 ||
- strcmp(hv_all_properties[2], "updates-version") == 0 );
-
- free(hv_all_properties[0]);
- free(hv_all_properties[1]);
- free(hv_all_properties[2]);
- free(hv_all_properties);
-
- /* Now we check the first value for each property */
- printf("Checking value for name with first value...\n");
- value = osi_get_hv_property_first_value(hv, "name", &err);
- assert ( err == 0 );
- assert ( value != NULL );
- assert ( strcmp("KVM", value) == 0 );
- free(value);
-
- printf("Checking value for version with first value...\n");
- value = osi_get_hv_property_first_value(hv, "version", &err);
- assert ( err == 0 );
- assert ( value != NULL );
- assert ( strcmp("0.11.0", value) == 0 );
- free(value);
-
- printf("Checking value for updates-version with first value...\n");
- value = osi_get_hv_property_first_value(hv, "updates-version", &err);
- assert ( err == 0 );
- assert ( value != NULL );
- assert ( strcmp("0.10.0", value) == 0 );
- free(value);
-
- /* Now check all values for each property */
- printf("Checking all values for name...\n");
- hv_all_values = osi_get_hv_property_all_values(hv, "name", &num, &err);
- assert ( err == 0 );
- assert ( num == 1 );
- assert ( hv_all_values != NULL );
- assert ( strcmp(hv_all_values[0], "KVM") == 0 );
- for (i = 0; i < num; i++)
- free(hv_all_values[i]);
- free(hv_all_values);
-
- printf("Checking all values for version...\n");
- hv_all_values = osi_get_hv_property_all_values(hv, "version", &num, &err);
- assert ( err == 0 );
- assert ( num == 1 );
- assert ( hv_all_values != NULL );
- assert ( strcmp(hv_all_values[0], "0.11.0") == 0 );
- for (i = 0; i < num; i++)
- free(hv_all_values[i]);
- free(hv_all_values);
-
- printf("Checking all values for updates-version...\n");
- hv_all_values = osi_get_hv_property_all_values(hv, "updates-version", &num, &err);
- assert ( err == 0 );
- assert ( num == 3 );
- assert ( hv_all_values != NULL );
- assert ( strcmp(hv_all_values[0], "0.10.0") == 0 );
- assert ( strcmp(hv_all_values[1], "0.9.0") == 0 );
- assert ( strcmp(hv_all_values[2], "0.8.0") == 0 );
- for (i = 0; i < num; i++)
- free(hv_all_values[i]);
- free(hv_all_values);
-
- /* Checking device sections */
- printf("Checking defined device sections...\n");
- hv_dev_sections = osi_get_hv_device_types(hv, &num, &err);
- assert ( err == 0 );
- assert ( num == 2 );
- assert ( hv_dev_sections != NULL );
- assert ( strcmp(hv_dev_sections[0], "audio") == 0 ||
- strcmp(hv_dev_sections[1], "audio") == 0 );
- assert ( strcmp(hv_dev_sections[0], "network") == 0 ||
- strcmp(hv_dev_sections[1], "network") == 0 );
- for (i = 0; i < num; i++)
- free(hv_dev_sections[i]);
- free(hv_dev_sections);
-
- /* Dispose of hv handle */
- ret = osi_cleanup_handle(hv);
- assert ( ret == 0 );
-
- /* Close library */
- printf("Closing library...\n");
- ret = osi_close_lib(lib);
- assert ( ret == 0 );
-
- printf("test-single_hv_manipulate succeeded.\n");
- return 0;
-}
diff --git a/test/test-manipulate_library.c b/test/test-manipulate_library.c
deleted file mode 100644
index e588aba..0000000
--- a/test/test-manipulate_library.c
+++ /dev/null
@@ -1,75 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <assert.h>
-#include <libosinfo.h>
-
-int main(int argc, char** argv)
-{
- int ret, err;
- char* lv_version;
- char* lv_recheck;
- char* bad_param;
- osi_lib_t lib;
- char* data_dir;
-
- assert ( argc == 2 );
- data_dir = argv[1];
-
- printf("Starting test-initlib...\n");
- printf("Checking to see if we got library handle...\n");
- lib = osi_get_lib_handle(&err, data_dir);
- assert ( err == 0 );
-
- /* Setting a parameter */
- printf("Setting parameter...\n");
- ret = osi_set_lib_param(lib, "libvirt-version", "0.6.2");
- assert ( ret == 0 );
-
- /* Getting a parameter that has been set */
- printf("Getting parameter...\n");
- lv_version = osi_get_lib_param(lib, "libvirt-version", &err);
- assert ( err == 0 );
- assert ( lv_version != NULL );
- assert ( strcmp(lv_version, "0.6.2") == 0 );
-
- /* Getting parameter that has not been set */
- printf("Getting bad parameter...\n");
- bad_param = osi_get_lib_param(lib, "bad-param", &err);
- assert ( err == 0 );
- assert ( bad_param == NULL );
-
- /* Initializing library */
- printf("Initializing library...\n");
- ret = osi_init_lib(lib);
- assert ( ret == 0 );
-
- /* Try setting already set parameter after init */
- printf("Try setting parameter after init...\n");
- ret = osi_set_lib_param(lib, "libvirt-version", "0.6.2");
- assert ( ret == -EBUSY );
-
- /* Try setting new parameter after init */
- printf("Try setting parameter after init...\n");
- ret = osi_set_lib_param(lib, "new-param", "new-value");
- assert ( ret == -EBUSY );
-
- /* Double check set parameter */
- printf("Rechecking parameter...\n");
- lv_recheck = osi_get_lib_param(lib, "libvirt-version", &err);
- assert ( err == 0 );
- assert ( lv_recheck != NULL );
- assert ( strcmp(lv_recheck, "0.6.2") == 0 );
- assert ( strcmp(lv_recheck, lv_version) == 0 );
- free(lv_version);
- free(lv_recheck);
-
- /* Close library */
- printf("Closing library...\n");
- ret = osi_close_lib(lib);
- assert ( ret == 0 );
-
- printf("test-initlib succeeded.\n");
- return 0;
-}
diff --git a/test/test-manipulate_os.c b/test/test-manipulate_os.c
deleted file mode 100644
index 5bcbc69..0000000
--- a/test/test-manipulate_os.c
+++ /dev/null
@@ -1,168 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <assert.h>
-#include <libosinfo.h>
-
-int main(int argc, char** argv)
-{
- int i, ret, len, err, num;
- osi_lib_t lib;
- osi_os_t os, related_os;
- osi_os_list_t os_list;
- char* value;
- char** all_properties;
- char** all_values;
- char** unique_values;
- char* data_dir;
-
- assert ( argc == 2 );
- data_dir = argv[1];
-
- printf("Starting test-get_os...\n");
- printf("Checking to see if we got library handle...\n");
- lib = osi_get_lib_handle(&err, data_dir);
- assert ( err == 0 );
-
- /* Initializing library */
- printf("Initializing library...\n");
- ret = osi_init_lib(lib);
- assert ( ret == 0 );
-
- /* Get OS Handle */
- printf("Acquiring os handle...\n");
- os = osi_get_os_by_id(lib, "http://fedoraproject.org/fedora-11", &err);
- assert ( err == 0 );
-
- /* Verify handle has correct id */
- printf("Verifying os id...\n");
- value = osi_get_os_id(os, &err);
- assert ( err == 0 );
- assert ( value != NULL );
- assert ( strcmp("http://fedoraproject.org/fedora-11", value) == 0 );
- free(value);
-
- /* Check set properties for this os */
- printf("Checking set properties for os...\n");
- all_properties = osi_get_all_os_property_keys(os, &num, &err);
- assert ( err == 0 );
- assert ( num == 3 );
- assert ( all_properties != NULL );
- assert ( strcmp(all_properties[0], "short-id") == 0 );
- assert ( strcmp(all_properties[1], "name") == 0 );
- assert ( strcmp(all_properties[2], "vendor") == 0 );
-
- /* Free the properties, we're done with them */
- free(all_properties[0]);
- free(all_properties[1]);
- free(all_properties[2]);
- free(all_properties);
-
- /* Check multiple valued property */
- printf("Checking multiple valued property...\n");
- all_values = osi_get_os_property_all_values(os, "vendor", &len, &err);
- assert ( err == 0 );
- assert ( len == 2 );
- assert ( all_values != NULL );
- assert ( strcmp(all_values[0], "Fedora Project") == 0 );
- assert ( strcmp(all_values[1], "Red Hat") == 0 );
- free(all_values[0]);
- free(all_values[1]);
- free(all_values);
-
- value = osi_get_os_property_first_value(os, "vendor", &err);
- assert ( err == 0 );
- assert ( value != NULL );
- assert ( strcmp(value, "Fedora Project") == 0 );
- free(value);
-
- /* Check single valued property */
- printf("Checking single valued property...\n");
- value = osi_get_os_property_first_value(os, "short-id", &err);
- assert ( err == 0 );
- assert ( value != NULL );
- assert ( strcmp(value, "fedora11") == 0 );
- free(value);
-
- all_values = osi_get_os_property_all_values(os, "short-id", &len, &err);
- assert ( err == 0 );
- assert ( len == 1 );
- assert ( all_values != NULL );
- assert ( strcmp(all_values[0], "fedora11") == 0 );
- free(all_values[0]);
- free(all_values);
-
- /* Check unique values across all os objects for given property */
- printf("Checking unique values for given properties");
- unique_values = osi_unique_property_values(lib, "vendor", &len, &err);
- assert ( err == 0 );
- assert ( len == 3 );
- assert ( unique_values != NULL );
- for (i = 0; i < len; i++) {
- assert (
- strcmp("Fedora Project", unique_values[i]) == 0 ||
- strcmp("OpenSuse Project", unique_values[i]) == 0 ||
- strcmp("Red Hat", unique_values[i]) == 0
- );
- }
- free(unique_values[0]);
- free(unique_values[1]);
- free(unique_values[2]);
- free(unique_values);
-
- /* Check related OS */
- printf("Checking related os...\n");
- related_os = osi_get_related_os(os, DERIVES_FROM, &err);
- assert ( err == -EINVAL );
- assert ( !related_os );
-
- related_os = osi_get_related_os(os, UPGRADES, &err);
- assert ( err == 0 );
- assert ( related_os );
-
- value = osi_get_os_id(related_os, &err);
- assert ( err == 0 );
- assert ( value != NULL );
- assert ( strcmp(value, "http://fedoraproject.org/fedora-10") == 0 );
- free(value);
-
- ret = osi_cleanup_handle(related_os);
- assert ( ret == 0 );
-
- printf("Checking unique relationship values...\n");
- os_list = osi_unique_relationship_values(lib, CLONES, &err);
- assert ( err == 0 );
- len = osi_os_list_length(os_list);
- assert ( len == 0 );
- ret = osi_free_os_list(os_list);
- assert ( ret == 0 );
-
- os_list = osi_unique_relationship_values(lib, UPGRADES, &err);
- assert ( err == 0 );
- len = osi_os_list_length(os_list);
- assert ( len == 1 );
- related_os = osi_get_os_by_index(os_list, 0, &err);
- assert ( err == 0 );
- value = osi_get_os_id(related_os, &err);
- assert ( err == 0 );
- assert ( value != NULL );
- assert ( strcmp(value, "http://fedoraproject.org/fedora-11") == 0 );
- free(value);
- ret = osi_free_os_list(os_list);
- assert ( ret == 0 );
-
- /* Dispose of os handles */
- ret = osi_cleanup_handle(os);
- assert ( ret == 0 );
- ret = osi_cleanup_handle(related_os);
- assert ( ret == 0 );
-
- /* Close library */
- printf("Closing library...\n");
- ret = osi_close_lib(lib);
- assert ( ret == 0 );
-
- printf("test-manipulate_os succeeded.\n");
- return 0;
-}
diff --git a/test/test-set_hypervisor.c b/test/test-set_hypervisor.c
deleted file mode 100644
index d7fec9a..0000000
--- a/test/test-set_hypervisor.c
+++ /dev/null
@@ -1,157 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <assert.h>
-#include <libosinfo.h>
-
-#define KVM "http://qemu.org/qemu-kvm-0.11.0"
-#define XEN "http://bits.xensource.com/oss-xen/release/3.4.1"
-
-int main(int argc, char** argv)
-{
- int ret, num, err;
- char** hypervisor_rdfs;
- char * hv_one_rdf, * hv_two_rdf;
- osi_lib_t lib_hv_one, lib_hv_two, lib_hv_default;
- osi_hypervisor_t hv_one, hv_two, hv_test;
- char* data_dir;
-
- assert ( argc == 2 );
- data_dir = argv[1];
-
- printf("Starting test-hypervisor...\n");
- printf("Get library handles...\n");
- lib_hv_one = osi_get_lib_handle(&err, data_dir);
- assert ( err == 0 );
-
- lib_hv_two = osi_get_lib_handle(&err, data_dir);
- assert ( err == 0 );
-
- lib_hv_default = osi_get_lib_handle(&err, data_dir);
- assert ( err == 0 );
-
- /* Get a list of the hypervisor rdfs */
- printf("Getting list of hypervisor rdfs...\n");
- hypervisor_rdfs = osi_get_all_hypervisor_ids(lib_hv_one, &num, &err);
- assert ( err == 0 );
- assert ( num == 2 ); /* Only two defined in the dummy data */
- assert ( hypervisor_rdfs != NULL );
- ret = (strcmp(KVM, hypervisor_rdfs[0]) == 0) ||
- (strcmp(XEN, hypervisor_rdfs[0] == 0));
- assert ( ret == 1 );
- if (strcmp(KVM, hypervisor_rdfs[0]) == 0)
- assert ( strcmp (XEN, hypervisor_rdfs[1]) == 0 );
- else
- assert ( strcmp (KVM, hypervisor_rdfs[1]) == 0);
-
- /* Check bad inputs to setting hypervisors */
- printf("Check that setting hypervisor fails for bad input...\n");
- ret = osi_set_lib_hypervisor(lib_hv_one, "bad_param");
- assert ( ret == -EINVAL );
- ret = osi_set_lib_hypervisor(lib_hv_two, "another_bad_param");
- assert ( ret == -EINVAL );
-
- /* Set hypervisors for libraries */
- printf("Setting hypervisors for library instances...\n");
- ret = osi_set_lib_hypervisor(lib_hv_one, hypervisor_rdfs[0]);
- assert ( ret == 0 );
- ret = osi_set_lib_hypervisor(lib_hv_two, hypervisor_rdfs[1]);
- assert ( ret == 0 );
-
- /* Get handles to the hypervisors for each library instance */
- printf("Check that the hypervisors were set correctly...\n");
- hv_one = osi_get_lib_hypervisor(lib_hv_one, &err);
- assert ( err == 0 );
- hv_one_rdf = osi_get_hv_id(hv_one, &err);
- assert ( err == 0 );
- assert ( hv_one_rdf != NULL );
- assert ( strcmp(hypervisor_rdfs[0], hv_one_rdf) == 0 );
- free(hv_one_rdf);
-
- hv_two = osi_get_lib_hypervisor(lib_hv_two, &err);
- assert ( err == 0 );
- hv_two_rdf = osi_get_hv_id(hv_two, &err);
- assert ( err == 0 );
- assert ( hv_two_rdf != NULL );
- assert ( strcmp(hypervisor_rdfs[1], hv_two_rdf) == 0 );
- free(hv_two_rdf);
-
- /* Check that the default hypervisor is set if we don't specify one */
- printf("Check that hypervisor set to default if no value given...\n");
- hv_test = osi_get_lib_hypervisor(lib_hv_default, &err);
- assert ( err == 0 );
- assert ( hv_test == NULL );
-
- /* Check that specifying NULL chooses the default HV */
- printf("Check that default hypervisor can be chosen...\n");
- ret = osi_set_lib_hypervisor(lib_hv_one, NULL);
- assert ( ret == 0 );
- hv_test = osi_get_lib_hypervisor(lib_hv_one, &err);
- assert ( err == 0 );
- assert ( hv_test == NULL );
-
- /* And that we can, yet again, switch back */
- printf("Test switching hypervisors yet again...\n");
- ret = osi_set_lib_hypervisor(lib_hv_one, hypervisor_rdfs[0]);
- assert ( ret == 0 );
- hv_test = osi_get_lib_hypervisor(lib_hv_one, &err);
- assert ( err == 0 );
- assert ( hv_test != NULL );
- hv_one_rdf = osi_get_hv_id(hv_test, &err);
- assert ( err == 0 );
- assert ( hv_one_rdf != NULL );
- assert ( strcmp(hypervisor_rdfs[0], hv_one_rdf) == 0 );
- free(hv_one_rdf);
-
- /* Initializing library */
- printf("Initializing libraries...\n");
- ret = osi_init_lib(lib_hv_one);
- assert ( ret == 0 );
- ret = osi_init_lib(lib_hv_two);
- assert ( ret == 0 );
- ret = osi_init_lib(lib_hv_default);
- assert ( ret == 0 );
-
- /* Verify that we cannot change the HVs now */
- printf("Checking that hv is fixed after library init...\n");
- ret = osi_set_lib_hypervisor(lib_hv_one, hypervisor_rdfs[0]);
- assert ( ret == -EBUSY );
- ret = osi_set_lib_hypervisor(lib_hv_two, hypervisor_rdfs[1]);
- assert ( ret == -EBUSY );
- ret = osi_set_lib_hypervisor(lib_hv_default, NULL);
- assert ( ret == -EBUSY );
-
- /* Verify that hv hasn't changed as a result of the above attempt */
- hv_one_rdf = osi_get_hv_id(hv_one, &err);
- assert ( err == 0 );
- assert ( hv_one_rdf != NULL );
- assert ( strcmp(hypervisor_rdfs[0], hv_one_rdf) == 0 );
- free(hv_one_rdf);
-
- hv_two_rdf = osi_get_hv_id(hv_two, &err);
- assert ( err == 0 );
- assert ( hv_two_rdf != NULL );
- assert ( strcmp(hypervisor_rdfs[1], hv_two_rdf) == 0 );
- free(hv_two_rdf);
-
- /* Put refs that we got */
- osi_cleanup_handle(hv_one);
- osi_cleanup_handle(hv_two);
- osi_cleanup_handle(hv_test);
-
- /* Close library */
- printf("Closing libraries...\n");
- ret = osi_close_lib(lib_hv_one);
- assert ( ret == 0 );
- ret = osi_close_lib(lib_hv_two);
- assert ( ret == 0 );
- ret = osi_close_lib(lib_hv_default);
- assert ( ret == 0 );
-
- free(hypervisor_rdfs[0]);
- free(hypervisor_rdfs[1]);
- free(hypervisor_rdfs);
- printf("test-hypervisor succeeded.\n");
- return 0;
-}
diff --git a/test/test-skeleton.c b/test/test-skeleton.c
index 4b153ad..24541f5 100644
--- a/test/test-skeleton.c
+++ b/test/test-skeleton.c
@@ -2,32 +2,67 @@
#include <stdlib.h>
#include <errno.h>
#include <assert.h>
-#include <libosinfo.h>
-int main(int argc, char** argv)
+#include <glib-object.h>
+#include <osinfo.h>
+
+int
+main (int argc, char *argv[])
{
- int ret, err;
- osi_lib_t lib;
- char* data_dir;
+ int ret;
+ g_type_init();
+
+ /* Create our object */
+ OsinfoDb *db = g_object_new (OSINFO_TYPE_DB, "backing-dir",
+ "./data", NULL);
+
+ // Read in data
+ ret = osinfoInitializeDb(db, NULL);
+ if (ret != 0) {
+ printf("Error initializing db! %d\n", ret);
+ exit(1);
+ }
+
+ gchar *backing_dir;
+ gchar *libvirt_ver;
+
+ g_object_get(G_OBJECT(db), "backing-dir", &backing_dir,
+ "libvirt-ver", &libvirt_ver,
+ NULL);
+
+
+ printf("Backing dir : %s Libvirt ver: %s\n", backing_dir, libvirt_ver);
+ g_free(backing_dir);
+ g_free(libvirt_ver);
+
+ // Now set libvirt-ver and test
+ GValue val = { 0, };
+ g_value_init (&val, G_TYPE_STRING);
+ g_value_set_string(&val, "2.4");
- assert ( argc == 2 );
- data_dir = argv[1];
+ g_object_set_property (G_OBJECT (db), "libvirt-ver", &val);
+ g_value_unset(&val);
- printf("Starting test...\n");
- printf("Checking to see if we got library handle...\n");
- lib = osi_get_lib_handle(&err, data_dir);
- assert ( err == 0 );
+ g_object_get(G_OBJECT(db), "backing-dir", &backing_dir,
+ "libvirt-ver", &libvirt_ver,
+ NULL);
+ printf("Backing dir : %s Libvirt ver: %s\n", backing_dir, libvirt_ver);
+ g_free(backing_dir);
+ g_free(libvirt_ver);
- /* Initializing library */
- printf("Initializing library...\n");
- ret = osi_init_lib(lib);
- assert ( ret == 0 );
+ // Now try settomg backing-dir and test
+ g_value_init (&val, G_TYPE_STRING);
+ g_value_set_string(&val, "/evil/dir/");
- /* Close library */
- printf("Closing library...\n");
- ret = osi_close_lib(lib);
- assert ( ret == 0 );
+ g_object_set_property (G_OBJECT (db), "backing-dir", &val);
+ g_value_unset(&val);
- printf("test succeeded.\n");
+ g_object_get(G_OBJECT(db), "backing-dir", &backing_dir,
+ "libvirt-ver", &libvirt_ver,
+ NULL);
+ printf("Backing dir : %s Libvirt ver: %s\n", backing_dir, libvirt_ver);
+ g_free(backing_dir);
+ g_free(libvirt_ver);
+ g_object_unref(db);
return 0;
}
diff --git a/test/tests b/test/tests
new file mode 100644
index 0000000..c95c54a
--- /dev/null
+++ b/test/tests
@@ -0,0 +1,16 @@
+Tests
+
+1. Create and destroy DB
+2. Get single OS, single device, single hypervisor
+ Treat all as entity
+ Get id, params, value for param, all values for param
+8. Given OS, HV, get device driver. Also NULL HV, and also case with no driver. (no HV info, or HV info and no support)
+
+3. Filter self-test
+4. Get list of OS, Dev, HV filtered
+5. Get two filtered lists, do list operations
+
+6. Get unique values for OS, Dev, HV, and list of OS by relationships
+7. Get hypervisor device types, and devices per type, with and without filter
+9. Get preferred device for OS and all devices for OS given HV/not HV.
+10. Get related OSes.