2013-12-20 21:14:40 +00:00
|
|
|
/*
|
|
|
|
* QOM interface test.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013 Red Hat Inc.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Igor Mammedov <imammedo@redhat.com>
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
|
|
|
|
* See the COPYING.LIB file in the top-level directory.
|
|
|
|
*/
|
2016-02-08 18:08:51 +00:00
|
|
|
#include "qemu/osdep.h"
|
2013-12-20 21:14:40 +00:00
|
|
|
|
|
|
|
#include "qom/object.h"
|
|
|
|
#include "qemu/module.h"
|
|
|
|
|
|
|
|
|
|
|
|
#define TYPE_TEST_IF "test-interface"
|
2020-09-03 20:43:22 +00:00
|
|
|
typedef struct TestIfClass TestIfClass;
|
2020-08-31 21:07:33 +00:00
|
|
|
DECLARE_CLASS_CHECKERS(TestIfClass, TEST_IF,
|
|
|
|
TYPE_TEST_IF)
|
2013-12-20 21:14:40 +00:00
|
|
|
#define TEST_IF(obj) \
|
|
|
|
INTERFACE_CHECK(TestIf, (obj), TYPE_TEST_IF)
|
|
|
|
|
2018-12-04 14:20:06 +00:00
|
|
|
typedef struct TestIf TestIf;
|
2013-12-20 21:14:40 +00:00
|
|
|
|
2020-09-03 20:43:22 +00:00
|
|
|
struct TestIfClass {
|
2013-12-20 21:14:40 +00:00
|
|
|
InterfaceClass parent_class;
|
|
|
|
|
|
|
|
uint32_t test;
|
2020-09-03 20:43:22 +00:00
|
|
|
};
|
2013-12-20 21:14:40 +00:00
|
|
|
|
|
|
|
static const TypeInfo test_if_info = {
|
|
|
|
.name = TYPE_TEST_IF,
|
|
|
|
.parent = TYPE_INTERFACE,
|
|
|
|
.class_size = sizeof(TestIfClass),
|
|
|
|
};
|
|
|
|
|
|
|
|
#define PATTERN 0xFAFBFCFD
|
|
|
|
|
|
|
|
static void test_class_init(ObjectClass *oc, void *data)
|
|
|
|
{
|
|
|
|
TestIfClass *tc = TEST_IF_CLASS(oc);
|
|
|
|
|
|
|
|
g_assert(tc);
|
|
|
|
tc->test = PATTERN;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define TYPE_DIRECT_IMPL "direct-impl"
|
|
|
|
|
|
|
|
static const TypeInfo direct_impl_info = {
|
|
|
|
.name = TYPE_DIRECT_IMPL,
|
|
|
|
.parent = TYPE_OBJECT,
|
|
|
|
.class_init = test_class_init,
|
|
|
|
.interfaces = (InterfaceInfo[]) {
|
|
|
|
{ TYPE_TEST_IF },
|
|
|
|
{ }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#define TYPE_INTERMEDIATE_IMPL "intermediate-impl"
|
|
|
|
|
|
|
|
static const TypeInfo intermediate_impl_info = {
|
|
|
|
.name = TYPE_INTERMEDIATE_IMPL,
|
|
|
|
.parent = TYPE_DIRECT_IMPL,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void test_interface_impl(const char *type)
|
|
|
|
{
|
|
|
|
Object *obj = object_new(type);
|
|
|
|
TestIf *iobj = TEST_IF(obj);
|
|
|
|
TestIfClass *ioc = TEST_IF_GET_CLASS(iobj);
|
|
|
|
|
|
|
|
g_assert(iobj);
|
|
|
|
g_assert(ioc->test == PATTERN);
|
2016-07-07 19:30:32 +00:00
|
|
|
object_unref(obj);
|
2013-12-20 21:14:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void interface_direct_test(void)
|
|
|
|
{
|
|
|
|
test_interface_impl(TYPE_DIRECT_IMPL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void interface_intermediate_test(void)
|
|
|
|
{
|
|
|
|
test_interface_impl(TYPE_INTERMEDIATE_IMPL);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
g_test_init(&argc, &argv, NULL);
|
|
|
|
|
|
|
|
module_call_init(MODULE_INIT_QOM);
|
|
|
|
type_register_static(&test_if_info);
|
|
|
|
type_register_static(&direct_impl_info);
|
|
|
|
type_register_static(&intermediate_impl_info);
|
|
|
|
|
|
|
|
g_test_add_func("/qom/interface/direct_impl", interface_direct_test);
|
|
|
|
g_test_add_func("/qom/interface/intermediate_impl",
|
|
|
|
interface_intermediate_test);
|
|
|
|
|
|
|
|
return g_test_run();
|
|
|
|
}
|