remove exec-all.h inclusion from cpu.h
[qemu.git] / check-qstring.c
blobc9bafc26b3285a2c9a56826fe0b1984266c4630c
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 <check.h>
14 #include "qstring.h"
15 #include "qemu-common.h"
18 * Public Interface test-cases
20 * (with some violations to access 'private' data)
23 START_TEST(qstring_from_str_test)
25 QString *qstring;
26 const char *str = "QEMU";
28 qstring = qstring_from_str(str);
29 fail_unless(qstring != NULL);
30 fail_unless(qstring->base.refcnt == 1);
31 fail_unless(strcmp(str, qstring->string) == 0);
32 fail_unless(qobject_type(QOBJECT(qstring)) == QTYPE_QSTRING);
34 // destroy doesn't exit yet
35 qemu_free(qstring->string);
36 qemu_free(qstring);
38 END_TEST
40 START_TEST(qstring_destroy_test)
42 QString *qstring = qstring_from_str("destroy test");
43 QDECREF(qstring);
45 END_TEST
47 START_TEST(qstring_get_str_test)
49 QString *qstring;
50 const char *ret_str;
51 const char *str = "QEMU/KVM";
53 qstring = qstring_from_str(str);
54 ret_str = qstring_get_str(qstring);
55 fail_unless(strcmp(ret_str, str) == 0);
57 QDECREF(qstring);
59 END_TEST
61 START_TEST(qstring_append_chr_test)
63 int i;
64 QString *qstring;
65 const char *str = "qstring append char unit-test";
67 qstring = qstring_new();
69 for (i = 0; str[i]; i++)
70 qstring_append_chr(qstring, str[i]);
72 fail_unless(strcmp(str, qstring_get_str(qstring)) == 0);
73 QDECREF(qstring);
75 END_TEST
77 START_TEST(qstring_from_substr_test)
79 QString *qs;
81 qs = qstring_from_substr("virtualization", 3, 9);
82 fail_unless(qs != NULL);
83 fail_unless(strcmp(qstring_get_str(qs), "tualiza") == 0);
85 QDECREF(qs);
87 END_TEST
90 START_TEST(qobject_to_qstring_test)
92 QString *qstring;
94 qstring = qstring_from_str("foo");
95 fail_unless(qobject_to_qstring(QOBJECT(qstring)) == qstring);
97 QDECREF(qstring);
99 END_TEST
101 static Suite *qstring_suite(void)
103 Suite *s;
104 TCase *qstring_public_tcase;
106 s = suite_create("QString test-suite");
108 qstring_public_tcase = tcase_create("Public Interface");
109 suite_add_tcase(s, qstring_public_tcase);
110 tcase_add_test(qstring_public_tcase, qstring_from_str_test);
111 tcase_add_test(qstring_public_tcase, qstring_destroy_test);
112 tcase_add_test(qstring_public_tcase, qstring_get_str_test);
113 tcase_add_test(qstring_public_tcase, qstring_append_chr_test);
114 tcase_add_test(qstring_public_tcase, qstring_from_substr_test);
115 tcase_add_test(qstring_public_tcase, qobject_to_qstring_test);
117 return s;
120 int main(void)
122 int nf;
123 Suite *s;
124 SRunner *sr;
126 s = qstring_suite();
127 sr = srunner_create(s);
129 srunner_run_all(sr, CK_NORMAL);
130 nf = srunner_ntests_failed(sr);
131 srunner_free(sr);
133 return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;