vmsvga: don't process more than 1024 fifo commands at once
[qemu/kevin.git] / tests / check-qom-interface.c
blob09354deb703e65f0bcf4fe7364be0980bddd7f6e
1 /*
2 * QOM interface test.
4 * Copyright (C) 2013 Red Hat Inc.
6 * Authors:
7 * Igor Mammedov <imammedo@redhat.com>
9 * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
10 * See the COPYING.LIB file in the top-level directory.
12 #include "qemu/osdep.h"
13 #include <glib.h>
15 #include "qom/object.h"
16 #include "qemu/module.h"
19 #define TYPE_TEST_IF "test-interface"
20 #define TEST_IF_CLASS(klass) \
21 OBJECT_CLASS_CHECK(TestIfClass, (klass), TYPE_TEST_IF)
22 #define TEST_IF_GET_CLASS(obj) \
23 OBJECT_GET_CLASS(TestIfClass, (obj), TYPE_TEST_IF)
24 #define TEST_IF(obj) \
25 INTERFACE_CHECK(TestIf, (obj), TYPE_TEST_IF)
27 typedef struct TestIf {
28 Object parent_obj;
29 } TestIf;
31 typedef struct TestIfClass {
32 InterfaceClass parent_class;
34 uint32_t test;
35 } TestIfClass;
37 static const TypeInfo test_if_info = {
38 .name = TYPE_TEST_IF,
39 .parent = TYPE_INTERFACE,
40 .class_size = sizeof(TestIfClass),
43 #define PATTERN 0xFAFBFCFD
45 static void test_class_init(ObjectClass *oc, void *data)
47 TestIfClass *tc = TEST_IF_CLASS(oc);
49 g_assert(tc);
50 tc->test = PATTERN;
53 #define TYPE_DIRECT_IMPL "direct-impl"
55 static const TypeInfo direct_impl_info = {
56 .name = TYPE_DIRECT_IMPL,
57 .parent = TYPE_OBJECT,
58 .class_init = test_class_init,
59 .interfaces = (InterfaceInfo[]) {
60 { TYPE_TEST_IF },
61 { }
65 #define TYPE_INTERMEDIATE_IMPL "intermediate-impl"
67 static const TypeInfo intermediate_impl_info = {
68 .name = TYPE_INTERMEDIATE_IMPL,
69 .parent = TYPE_DIRECT_IMPL,
72 static void test_interface_impl(const char *type)
74 Object *obj = object_new(type);
75 TestIf *iobj = TEST_IF(obj);
76 TestIfClass *ioc = TEST_IF_GET_CLASS(iobj);
78 g_assert(iobj);
79 g_assert(ioc->test == PATTERN);
82 static void interface_direct_test(void)
84 test_interface_impl(TYPE_DIRECT_IMPL);
87 static void interface_intermediate_test(void)
89 test_interface_impl(TYPE_INTERMEDIATE_IMPL);
92 int main(int argc, char **argv)
94 g_test_init(&argc, &argv, NULL);
96 module_call_init(MODULE_INIT_QOM);
97 type_register_static(&test_if_info);
98 type_register_static(&direct_impl_info);
99 type_register_static(&intermediate_impl_info);
101 g_test_add_func("/qom/interface/direct_impl", interface_direct_test);
102 g_test_add_func("/qom/interface/intermediate_impl",
103 interface_intermediate_test);
105 return g_test_run();