mirror of
https://github.com/qemu/qemu.git
synced 2024-12-14 15:03:33 +08:00
61e8a92364
* QTest cleanups and test cases for PCI NICs * NAND fix for "info qtree" * Cleanup and extension of QOM machine tests * IndustryPack test cases and conversion to QOM realize * I2C cleanups * Cleanups of legacy qdev properties -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) iQIcBAABAgAGBQJTAooJAAoJEPou0S0+fgE/SuQQALW3zvra4ZLRAQV0e8kFoyj1 vVtmLkDhnCe4cYfxxfOX91NA0rH1ts2EO1+UcnaCHJlptNWfA+8qJW69XgYpHE3c DKQlKPL/9pV5ywY5uUw/t1UJHg2BfrLBDDM4lP+vrpwiQYq4kp24JffnhfY3l9MA 9qdkXu1HrlWoLRVGnMyGDXI8cb+5bTL+FEc6UuHl3P89/gj5BV+LDWn0QOFbAkxq 4wk+Xh6sHKcfOdq6vMCNGlTjlJnpbY43D1a8+q6hFGG8JBlpne7Oer7bse9k4uTK q/CzyNzC0lnjjcULpa4ptRlycH0ruD9DPY7Lco9XqYd3l/c9742PmTEqN5TZseKD XD7+hwT1tk7W8rihm8KETCP6sKlXz4w8tJiWe6IT3zwRzvXIolxxK93heQuaX73Z HFDmvTPVLUiWF8ftKTyWZM3w+jsbSH0QSrMCIHKJrPTRWTKphx0DUP74lWjNsvGs FFBjpAgrflLihxiuRrcLmekGn0xCTjhQWIo2GoiWTgLSEHNQQQUNO+15/kcU/vlI hh3DJpiBKeSnUapHHL0OEK6ryeHoG95akiRjImwWVthNLk4KEuWtlhFPYBtulO5A PA02trE4Ah769effX0ZYdNl23KbW4VxpZ8VZv+kp7RTrDKxw551HoEFJ5ja0nkvB O1CfsE7x0GH/Rbi/Hxhu =KRcc -----END PGP SIGNATURE----- Merge remote-tracking branch 'remotes/afaerber/tags/qom-devices-for-peter' into staging QOM infrastructure fixes and device conversions * QTest cleanups and test cases for PCI NICs * NAND fix for "info qtree" * Cleanup and extension of QOM machine tests * IndustryPack test cases and conversion to QOM realize * I2C cleanups * Cleanups of legacy qdev properties # gpg: Signature made Mon 17 Feb 2014 22:15:37 GMT using RSA key ID 3E7E013F # gpg: Good signature from "Andreas Färber <afaerber@suse.de>" # gpg: aka "Andreas Färber <afaerber@suse.com>" * remotes/afaerber/tags/qom-devices-for-peter: (49 commits) qtest: Include system headers before user headers qapi: Refine human printing of sizes qdev: Use QAPI type names for properties qdev: Add enum property types to QAPI schema block: Handle "rechs" and "large" translation options qdev: Remove hex8/32/64 property types qdev: Remove most legacy printers qdev: Use human mode in "info qtree" qapi: Add human mode to StringOutputVisitor qdev: Inline qdev_prop_parse() qdev: Legacy properties are just strings qdev: Legacy properties are now read-only qdev: Remove legacy parsers for hex8/32/64 qdev: Sizes are now parsed by StringInputVisitor qapi: Add size parser to StringInputVisitor qtest: Don't segfault with invalid -qtest option ipack: Move IndustryPack out of hw/char/ ipoctal232: QOM parent field cleanup ipack: QOM parent field cleanup for IPackDevice ipack: QOM parent field cleanup for IPackBus ... Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
190 lines
5.3 KiB
C
190 lines
5.3 KiB
C
/*
|
|
* String Output Visitor unit-tests.
|
|
*
|
|
* Copyright (C) 2012 Red Hat Inc.
|
|
*
|
|
* Authors:
|
|
* Paolo Bonzini <pbonzini@redhat.com> (based on test-qmp-output-visitor)
|
|
*
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
* See the COPYING file in the top-level directory.
|
|
*/
|
|
|
|
#include <glib.h>
|
|
|
|
#include "qemu-common.h"
|
|
#include "qapi/string-output-visitor.h"
|
|
#include "test-qapi-types.h"
|
|
#include "test-qapi-visit.h"
|
|
#include "qapi/qmp/types.h"
|
|
|
|
typedef struct TestOutputVisitorData {
|
|
StringOutputVisitor *sov;
|
|
Visitor *ov;
|
|
} TestOutputVisitorData;
|
|
|
|
static void visitor_output_setup(TestOutputVisitorData *data,
|
|
const void *unused)
|
|
{
|
|
data->sov = string_output_visitor_new(false);
|
|
g_assert(data->sov != NULL);
|
|
|
|
data->ov = string_output_get_visitor(data->sov);
|
|
g_assert(data->ov != NULL);
|
|
}
|
|
|
|
static void visitor_output_teardown(TestOutputVisitorData *data,
|
|
const void *unused)
|
|
{
|
|
string_output_visitor_cleanup(data->sov);
|
|
data->sov = NULL;
|
|
data->ov = NULL;
|
|
}
|
|
|
|
static void test_visitor_out_int(TestOutputVisitorData *data,
|
|
const void *unused)
|
|
{
|
|
int64_t value = -42;
|
|
Error *errp = NULL;
|
|
char *str;
|
|
|
|
visit_type_int(data->ov, &value, NULL, &errp);
|
|
g_assert(!errp);
|
|
|
|
str = string_output_get_string(data->sov);
|
|
g_assert(str != NULL);
|
|
g_assert_cmpstr(str, ==, "-42");
|
|
g_free(str);
|
|
}
|
|
|
|
static void test_visitor_out_bool(TestOutputVisitorData *data,
|
|
const void *unused)
|
|
{
|
|
Error *errp = NULL;
|
|
bool value = true;
|
|
char *str;
|
|
|
|
visit_type_bool(data->ov, &value, NULL, &errp);
|
|
g_assert(!errp);
|
|
|
|
str = string_output_get_string(data->sov);
|
|
g_assert(str != NULL);
|
|
g_assert_cmpstr(str, ==, "true");
|
|
g_free(str);
|
|
}
|
|
|
|
static void test_visitor_out_number(TestOutputVisitorData *data,
|
|
const void *unused)
|
|
{
|
|
double value = 3.14;
|
|
Error *errp = NULL;
|
|
char *str;
|
|
|
|
visit_type_number(data->ov, &value, NULL, &errp);
|
|
g_assert(!errp);
|
|
|
|
str = string_output_get_string(data->sov);
|
|
g_assert(str != NULL);
|
|
g_assert_cmpstr(str, ==, "3.140000");
|
|
g_free(str);
|
|
}
|
|
|
|
static void test_visitor_out_string(TestOutputVisitorData *data,
|
|
const void *unused)
|
|
{
|
|
char *string = (char *) "Q E M U";
|
|
Error *errp = NULL;
|
|
char *str;
|
|
|
|
visit_type_str(data->ov, &string, NULL, &errp);
|
|
g_assert(!errp);
|
|
|
|
str = string_output_get_string(data->sov);
|
|
g_assert(str != NULL);
|
|
g_assert_cmpstr(str, ==, string);
|
|
g_free(str);
|
|
}
|
|
|
|
static void test_visitor_out_no_string(TestOutputVisitorData *data,
|
|
const void *unused)
|
|
{
|
|
char *string = NULL;
|
|
Error *errp = NULL;
|
|
char *str;
|
|
|
|
/* A null string should return "" */
|
|
visit_type_str(data->ov, &string, NULL, &errp);
|
|
g_assert(!errp);
|
|
|
|
str = string_output_get_string(data->sov);
|
|
g_assert(str != NULL);
|
|
g_assert_cmpstr(str, ==, "");
|
|
g_free(str);
|
|
}
|
|
|
|
static void test_visitor_out_enum(TestOutputVisitorData *data,
|
|
const void *unused)
|
|
{
|
|
Error *errp = NULL;
|
|
char *str;
|
|
EnumOne i;
|
|
|
|
for (i = 0; i < ENUM_ONE_MAX; i++) {
|
|
visit_type_EnumOne(data->ov, &i, "unused", &errp);
|
|
g_assert(!errp);
|
|
|
|
str = string_output_get_string(data->sov);
|
|
g_assert(str != NULL);
|
|
g_assert_cmpstr(str, ==, EnumOne_lookup[i]);
|
|
g_free(str);
|
|
}
|
|
}
|
|
|
|
static void test_visitor_out_enum_errors(TestOutputVisitorData *data,
|
|
const void *unused)
|
|
{
|
|
EnumOne i, bad_values[] = { ENUM_ONE_MAX, -1 };
|
|
Error *errp;
|
|
|
|
for (i = 0; i < ARRAY_SIZE(bad_values) ; i++) {
|
|
errp = NULL;
|
|
visit_type_EnumOne(data->ov, &bad_values[i], "unused", &errp);
|
|
g_assert(errp);
|
|
error_free(errp);
|
|
}
|
|
}
|
|
|
|
static void output_visitor_test_add(const char *testpath,
|
|
TestOutputVisitorData *data,
|
|
void (*test_func)(TestOutputVisitorData *data, const void *user_data))
|
|
{
|
|
g_test_add(testpath, TestOutputVisitorData, data, visitor_output_setup,
|
|
test_func, visitor_output_teardown);
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
TestOutputVisitorData out_visitor_data;
|
|
|
|
g_test_init(&argc, &argv, NULL);
|
|
|
|
output_visitor_test_add("/string-visitor/output/int",
|
|
&out_visitor_data, test_visitor_out_int);
|
|
output_visitor_test_add("/string-visitor/output/bool",
|
|
&out_visitor_data, test_visitor_out_bool);
|
|
output_visitor_test_add("/string-visitor/output/number",
|
|
&out_visitor_data, test_visitor_out_number);
|
|
output_visitor_test_add("/string-visitor/output/string",
|
|
&out_visitor_data, test_visitor_out_string);
|
|
output_visitor_test_add("/string-visitor/output/no-string",
|
|
&out_visitor_data, test_visitor_out_no_string);
|
|
output_visitor_test_add("/string-visitor/output/enum",
|
|
&out_visitor_data, test_visitor_out_enum);
|
|
output_visitor_test_add("/string-visitor/output/enum-errors",
|
|
&out_visitor_data, test_visitor_out_enum_errors);
|
|
|
|
g_test_run();
|
|
|
|
return 0;
|
|
}
|