libqos: Use explicit QTestState for ahci operations
[qemu.git] / tests / check-qstring.c
blob112ec08967fea95802ce2ab982b1066ad9a6f7ab
1 /*
2 * QString unit-tests.
4 * Copyright (C) 2009 Red Hat Inc.
6 * Authors:
7 * Luiz Capitulino <lcapitulino@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"
14 #include "qapi/qmp/qstring.h"
15 #include "qemu-common.h"
18 * Public Interface test-cases
20 * (with some violations to access 'private' data)
23 static void qstring_from_str_test(void)
25 QString *qstring;
26 const char *str = "QEMU";
28 qstring = qstring_from_str(str);
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);
34 QDECREF(qstring);
37 static void qstring_get_str_test(void)
39 QString *qstring;
40 const char *ret_str;
41 const char *str = "QEMU/KVM";
43 qstring = qstring_from_str(str);
44 ret_str = qstring_get_str(qstring);
45 g_assert(strcmp(ret_str, str) == 0);
47 QDECREF(qstring);
50 static void qstring_append_chr_test(void)
52 int i;
53 QString *qstring;
54 const char *str = "qstring append char unit-test";
56 qstring = qstring_new();
58 for (i = 0; str[i]; i++)
59 qstring_append_chr(qstring, str[i]);
61 g_assert(strcmp(str, qstring_get_str(qstring)) == 0);
62 QDECREF(qstring);
65 static void qstring_from_substr_test(void)
67 QString *qs;
69 qs = qstring_from_substr("virtualization", 3, 9);
70 g_assert(qs != NULL);
71 g_assert(strcmp(qstring_get_str(qs), "tualiza") == 0);
73 QDECREF(qs);
77 static void qobject_to_qstring_test(void)
79 QString *qstring;
81 qstring = qstring_from_str("foo");
82 g_assert(qobject_to_qstring(QOBJECT(qstring)) == qstring);
84 QDECREF(qstring);
87 int main(int argc, char **argv)
89 g_test_init(&argc, &argv, NULL);
91 g_test_add_func("/public/from_str", qstring_from_str_test);
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);
97 return g_test_run();