2 * Copyright (C) 2015 Red Hat, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see
16 * <http://www.gnu.org/licenses/>.
18 * Author: Daniel P. Berrange <berrange@redhat.com>
23 #include "qom/object.h"
24 #include "qemu/module.h"
27 #define TYPE_DUMMY "qemu-dummy"
29 typedef struct DummyObject DummyObject
;
30 typedef struct DummyObjectClass DummyObjectClass
;
32 #define DUMMY_OBJECT(obj) \
33 OBJECT_CHECK(DummyObject, (obj), TYPE_DUMMY)
42 struct DummyObjectClass
{
43 ObjectClass parent_class
;
47 static void dummy_set_bv(Object
*obj
,
51 DummyObject
*dobj
= DUMMY_OBJECT(obj
);
56 static bool dummy_get_bv(Object
*obj
,
59 DummyObject
*dobj
= DUMMY_OBJECT(obj
);
65 static void dummy_set_sv(Object
*obj
,
69 DummyObject
*dobj
= DUMMY_OBJECT(obj
);
72 dobj
->sv
= g_strdup(value
);
75 static char *dummy_get_sv(Object
*obj
,
78 DummyObject
*dobj
= DUMMY_OBJECT(obj
);
80 return g_strdup(dobj
->sv
);
84 static void dummy_init(Object
*obj
)
86 object_property_add_bool(obj
, "bv",
90 object_property_add_str(obj
, "sv",
96 static void dummy_finalize(Object
*obj
)
98 DummyObject
*dobj
= DUMMY_OBJECT(obj
);
104 static const TypeInfo dummy_info
= {
106 .parent
= TYPE_OBJECT
,
107 .instance_size
= sizeof(DummyObject
),
108 .instance_init
= dummy_init
,
109 .instance_finalize
= dummy_finalize
,
110 .class_size
= sizeof(DummyObjectClass
),
113 static void test_dummy_createv(void)
116 Object
*parent
= object_get_objects_root();
117 DummyObject
*dobj
= DUMMY_OBJECT(
118 object_new_with_props(TYPE_DUMMY
,
123 "sv", "Hiss hiss hiss",
126 g_assert(err
== NULL
);
127 g_assert_cmpstr(dobj
->sv
, ==, "Hiss hiss hiss");
128 g_assert(dobj
->bv
== true);
130 g_assert(object_resolve_path_component(parent
, "dummy0")
133 object_unparent(OBJECT(dobj
));
137 static Object
*new_helper(Error
**errp
,
144 va_start(vargs
, parent
);
145 obj
= object_new_with_propv(TYPE_DUMMY
,
154 static void test_dummy_createlist(void)
157 Object
*parent
= object_get_objects_root();
158 DummyObject
*dobj
= DUMMY_OBJECT(
162 "sv", "Hiss hiss hiss",
165 g_assert(err
== NULL
);
166 g_assert_cmpstr(dobj
->sv
, ==, "Hiss hiss hiss");
167 g_assert(dobj
->bv
== true);
169 g_assert(object_resolve_path_component(parent
, "dummy0")
172 object_unparent(OBJECT(dobj
));
175 int main(int argc
, char **argv
)
177 g_test_init(&argc
, &argv
, NULL
);
179 module_call_init(MODULE_INIT_QOM
);
180 type_register_static(&dummy_info
);
182 g_test_add_func("/qom/proplist/createlist", test_dummy_createlist
);
183 g_test_add_func("/qom/proplist/createv", test_dummy_createv
);