static void gvir_config_domain_set_property(GObject *object,
                                            guint prop_id,
                                            const GValue *value,
                                            GParamSpec *pspec)
{
    GVirConfigDomain *domain = GVIR_CONFIG_DOMAIN(object);

    switch (prop_id) {
    case PROP_NAME:
        gvir_config_domain_set_name(domain, g_value_get_string(value));
        break;
    case PROP_TITLE:
        gvir_config_domain_set_title(domain, g_value_get_string(value));
        break;
    case PROP_DESCRIPTION:
        gvir_config_domain_set_description(domain, g_value_get_string(value));
        break;
    case PROP_MEMORY:
        gvir_config_domain_set_memory(domain, g_value_get_uint64(value));
        break;
    case PROP_VCPU:
        gvir_config_domain_set_vcpus(domain, g_value_get_uint64(value));
        break;
    case PROP_FEATURES:
        gvir_config_domain_set_features(domain, g_value_get_boxed(value));
        break;
    default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
    }
}
Beispiel #2
0
static void test_domain(void)
{
    GVirConfigDomain *domain;
    const char *features[] = { "foo", "bar", "baz", NULL };
    GStrv feat;
    unsigned int i;

    domain = gvir_config_domain_new();
    g_assert(domain != NULL);

    gvir_config_domain_set_virt_type(domain, GVIR_CONFIG_DOMAIN_VIRT_KVM);
    g_assert_cmpint(gvir_config_domain_get_virt_type(domain), ==, GVIR_CONFIG_DOMAIN_VIRT_KVM);

    gvir_config_domain_set_name(domain, "foo");
    g_assert_cmpstr(gvir_config_domain_get_name(domain), ==, "foo");

    gvir_config_domain_set_memory(domain, 1234);
    g_assert_cmpint(gvir_config_domain_get_memory(domain), ==, 1234);
    gvir_config_domain_set_vcpus(domain, 3);
    g_assert_cmpint(gvir_config_domain_get_vcpus(domain), ==, 3);

    gvir_config_domain_set_features(domain, (const GStrv)features);
    feat = gvir_config_domain_get_features(domain);
    for (i = 0; features[i] != NULL; i++) {
        g_assert(feat[i] != NULL);
        g_assert_cmpstr(feat[i], ==, features[i]);
    }
    g_strfreev(feat);

    gvir_config_domain_set_lifecycle(domain,
                                     GVIR_CONFIG_DOMAIN_LIFECYCLE_ON_POWEROFF,
                                     GVIR_CONFIG_DOMAIN_LIFECYCLE_RESTART);

    gvir_config_domain_set_custom_xml(domain, "<foo/>", "ns", "http://foo", NULL);
    gvir_config_domain_set_custom_xml(domain, "<foo/>", "nsbar", "http://bar", NULL);
    gvir_config_domain_set_custom_xml(domain, "<foo/>", "ns", "http://bar", NULL);
    gvir_config_domain_set_custom_xml(domain, "<bar/>", "ns", "http://foo", NULL);

    g_assert_cmpstr_free1(gvir_config_domain_get_custom_xml(domain, "http://foo"), ==, "<ns:bar xmlns:ns=\"http://foo\"/>");
    g_assert_cmpstr_free1(gvir_config_domain_get_custom_xml(domain, "http://bar"), ==, "<ns:foo xmlns:ns=\"http://bar\"/>");

    check_xml(domain, "gconfig-domain.xml");

    g_object_unref(G_OBJECT(domain));
}