linux-user: Support for restarting system calls for OpenRISC targets
[qemu.git] / tests / check-qstring.c
1 /*
2 * QString unit-tests.
3 *
4 * Copyright (C) 2009 Red Hat Inc.
5 *
6 * Authors:
7 * Luiz Capitulino <lcapitulino@redhat.com>
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.
11 */
12 #include "qemu/osdep.h"
13 #include <glib.h>
14
15 #include "qapi/qmp/qstring.h"
16 #include "qemu-common.h"
17
18 /*
19 * Public Interface test-cases
20 *
21 * (with some violations to access 'private' data)
22 */
23
24 static void qstring_from_str_test(void)
25 {
26 QString *qstring;
27 const char *str = "QEMU";
28
29 qstring = qstring_from_str(str);
30 g_assert(qstring != NULL);
31 g_assert(qstring->base.refcnt == 1);
32 g_assert(strcmp(str, qstring->string) == 0);
33 g_assert(qobject_type(QOBJECT(qstring)) == QTYPE_QSTRING);
34
35 // destroy doesn't exit yet
36 g_free(qstring->string);
37 g_free(qstring);
38 }
39
40 static void qstring_destroy_test(void)
41 {
42 QString *qstring = qstring_from_str("destroy test");
43 QDECREF(qstring);
44 }
45
46 static void qstring_get_str_test(void)
47 {
48 QString *qstring;
49 const char *ret_str;
50 const char *str = "QEMU/KVM";
51
52 qstring = qstring_from_str(str);
53 ret_str = qstring_get_str(qstring);
54 g_assert(strcmp(ret_str, str) == 0);
55
56 QDECREF(qstring);
57 }
58
59 static void qstring_append_chr_test(void)
60 {
61 int i;
62 QString *qstring;
63 const char *str = "qstring append char unit-test";
64
65 qstring = qstring_new();
66
67 for (i = 0; str[i]; i++)
68 qstring_append_chr(qstring, str[i]);
69
70 g_assert(strcmp(str, qstring_get_str(qstring)) == 0);
71 QDECREF(qstring);
72 }
73
74 static void qstring_from_substr_test(void)
75 {
76 QString *qs;
77
78 qs = qstring_from_substr("virtualization", 3, 9);
79 g_assert(qs != NULL);
80 g_assert(strcmp(qstring_get_str(qs), "tualiza") == 0);
81
82 QDECREF(qs);
83 }
84
85
86 static void qobject_to_qstring_test(void)
87 {
88 QString *qstring;
89
90 qstring = qstring_from_str("foo");
91 g_assert(qobject_to_qstring(QOBJECT(qstring)) == qstring);
92
93 QDECREF(qstring);
94 }
95
96 int main(int argc, char **argv)
97 {
98 g_test_init(&argc, &argv, NULL);
99
100 g_test_add_func("/public/from_str", qstring_from_str_test);
101 g_test_add_func("/public/destroy", qstring_destroy_test);
102 g_test_add_func("/public/get_str", qstring_get_str_test);
103 g_test_add_func("/public/append_chr", qstring_append_chr_test);
104 g_test_add_func("/public/from_substr", qstring_from_substr_test);
105 g_test_add_func("/public/to_qstring", qobject_to_qstring_test);
106
107 return g_test_run();
108 }