]> git.proxmox.com Git - mirror_qemu.git/blame - tests/check-qstring.c
qemu-option: restrict qemu_opts_set to merge-lists QemuOpts
[mirror_qemu.git] / tests / check-qstring.c
CommitLineData
5de65a07
LC
1/*
2 * QString unit-tests.
3 *
4 * Copyright (C) 2009 Red Hat Inc.
5 *
6 * Authors:
7 * Luiz Capitulino <lcapitulino@redhat.com>
41836a9f
LC
8 *
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.
5de65a07 11 */
681c28a3 12#include "qemu/osdep.h"
5de65a07 13
7b1b5d19 14#include "qapi/qmp/qstring.h"
5de65a07
LC
15#include "qemu-common.h"
16
17/*
18 * Public Interface test-cases
19 *
20 * (with some violations to access 'private' data)
21 */
22
0ac7cc2a 23static void qstring_from_str_test(void)
5de65a07
LC
24{
25 QString *qstring;
26 const char *str = "QEMU";
27
28 qstring = qstring_from_str(str);
0ac7cc2a
AL
29 g_assert(qstring != NULL);
30 g_assert(qstring->base.refcnt == 1);
31 g_assert(strcmp(str, qstring->string) == 0);
32 g_assert(qobject_type(QOBJECT(qstring)) == QTYPE_QSTRING);
5de65a07 33
cb3e7f08 34 qobject_unref(qstring);
5de65a07 35}
5de65a07 36
0ac7cc2a 37static void qstring_get_str_test(void)
5de65a07
LC
38{
39 QString *qstring;
40 const char *ret_str;
41 const char *str = "QEMU/KVM";
42
43 qstring = qstring_from_str(str);
44 ret_str = qstring_get_str(qstring);
0ac7cc2a 45 g_assert(strcmp(ret_str, str) == 0);
5de65a07 46
cb3e7f08 47 qobject_unref(qstring);
5de65a07 48}
5de65a07 49
0ac7cc2a 50static void qstring_append_chr_test(void)
f08932c8
LC
51{
52 int i;
53 QString *qstring;
54 const char *str = "qstring append char unit-test";
55
56 qstring = qstring_new();
57
58 for (i = 0; str[i]; i++)
59 qstring_append_chr(qstring, str[i]);
60
0ac7cc2a 61 g_assert(strcmp(str, qstring_get_str(qstring)) == 0);
cb3e7f08 62 qobject_unref(qstring);
f08932c8 63}
f08932c8 64
0ac7cc2a 65static void qstring_from_substr_test(void)
64084a03
LC
66{
67 QString *qs;
68
ba891d68 69 qs = qstring_from_substr("virtualization", 3, 10);
0ac7cc2a
AL
70 g_assert(qs != NULL);
71 g_assert(strcmp(qstring_get_str(qs), "tualiza") == 0);
64084a03 72
cb3e7f08 73 qobject_unref(qs);
64084a03 74}
64084a03
LC
75
76
0ac7cc2a 77static void qobject_to_qstring_test(void)
5de65a07
LC
78{
79 QString *qstring;
80
81 qstring = qstring_from_str("foo");
7dc847eb 82 g_assert(qobject_to(QString, QOBJECT(qstring)) == qstring);
5de65a07 83
cb3e7f08 84 qobject_unref(qstring);
5de65a07 85}
5de65a07 86
0ac7cc2a 87int main(int argc, char **argv)
5de65a07 88{
0ac7cc2a 89 g_test_init(&argc, &argv, NULL);
5de65a07 90
0ac7cc2a 91 g_test_add_func("/public/from_str", qstring_from_str_test);
0ac7cc2a
AL
92 g_test_add_func("/public/get_str", qstring_get_str_test);
93 g_test_add_func("/public/append_chr", qstring_append_chr_test);
94 g_test_add_func("/public/from_substr", qstring_from_substr_test);
95 g_test_add_func("/public/to_qstring", qobject_to_qstring_test);
5de65a07 96
0ac7cc2a 97 return g_test_run();
5de65a07 98}