root / check-qstring.c @ 9f107513
History | View | Annotate | Download (2.7 kB)
1 |
/*
|
---|---|
2 |
* QString unit-tests.
|
3 |
*
|
4 |
* Copyright (C) 2009 Red Hat Inc.
|
5 |
*
|
6 |
* Authors:
|
7 |
* Luiz Capitulino <lcapitulino@redhat.com>
|
8 |
*/
|
9 |
#include <check.h> |
10 |
|
11 |
#include "qstring.h" |
12 |
#include "qemu-common.h" |
13 |
|
14 |
/*
|
15 |
* Public Interface test-cases
|
16 |
*
|
17 |
* (with some violations to access 'private' data)
|
18 |
*/
|
19 |
|
20 |
START_TEST(qstring_from_str_test) |
21 |
{ |
22 |
QString *qstring; |
23 |
const char *str = "QEMU"; |
24 |
|
25 |
qstring = qstring_from_str(str); |
26 |
fail_unless(qstring != NULL);
|
27 |
fail_unless(qstring->base.refcnt == 1);
|
28 |
fail_unless(strcmp(str, qstring->string) == 0);
|
29 |
fail_unless(qobject_type(QOBJECT(qstring)) == QTYPE_QSTRING); |
30 |
|
31 |
// destroy doesn't exit yet
|
32 |
qemu_free(qstring->string); |
33 |
qemu_free(qstring); |
34 |
} |
35 |
END_TEST |
36 |
|
37 |
START_TEST(qstring_destroy_test) |
38 |
{ |
39 |
QString *qstring = qstring_from_str("destroy test");
|
40 |
QDECREF(qstring); |
41 |
} |
42 |
END_TEST |
43 |
|
44 |
START_TEST(qstring_get_str_test) |
45 |
{ |
46 |
QString *qstring; |
47 |
const char *ret_str; |
48 |
const char *str = "QEMU/KVM"; |
49 |
|
50 |
qstring = qstring_from_str(str); |
51 |
ret_str = qstring_get_str(qstring); |
52 |
fail_unless(strcmp(ret_str, str) == 0);
|
53 |
|
54 |
QDECREF(qstring); |
55 |
} |
56 |
END_TEST |
57 |
|
58 |
START_TEST(qstring_append_chr_test) |
59 |
{ |
60 |
int i;
|
61 |
QString *qstring; |
62 |
const char *str = "qstring append char unit-test"; |
63 |
|
64 |
qstring = qstring_new(); |
65 |
|
66 |
for (i = 0; str[i]; i++) |
67 |
qstring_append_chr(qstring, str[i]); |
68 |
|
69 |
fail_unless(strcmp(str, qstring_get_str(qstring)) == 0);
|
70 |
QDECREF(qstring); |
71 |
} |
72 |
END_TEST |
73 |
|
74 |
START_TEST(qstring_from_substr_test) |
75 |
{ |
76 |
QString *qs; |
77 |
|
78 |
qs = qstring_from_substr("virtualization", 3, 9); |
79 |
fail_unless(qs != NULL);
|
80 |
fail_unless(strcmp(qstring_get_str(qs), "tualiza") == 0); |
81 |
|
82 |
QDECREF(qs); |
83 |
} |
84 |
END_TEST |
85 |
|
86 |
|
87 |
START_TEST(qobject_to_qstring_test) |
88 |
{ |
89 |
QString *qstring; |
90 |
|
91 |
qstring = qstring_from_str("foo");
|
92 |
fail_unless(qobject_to_qstring(QOBJECT(qstring)) == qstring); |
93 |
|
94 |
QDECREF(qstring); |
95 |
} |
96 |
END_TEST |
97 |
|
98 |
static Suite *qstring_suite(void) |
99 |
{ |
100 |
Suite *s; |
101 |
TCase *qstring_public_tcase; |
102 |
|
103 |
s = suite_create("QString test-suite");
|
104 |
|
105 |
qstring_public_tcase = tcase_create("Public Interface");
|
106 |
suite_add_tcase(s, qstring_public_tcase); |
107 |
tcase_add_test(qstring_public_tcase, qstring_from_str_test); |
108 |
tcase_add_test(qstring_public_tcase, qstring_destroy_test); |
109 |
tcase_add_test(qstring_public_tcase, qstring_get_str_test); |
110 |
tcase_add_test(qstring_public_tcase, qstring_append_chr_test); |
111 |
tcase_add_test(qstring_public_tcase, qstring_from_substr_test); |
112 |
tcase_add_test(qstring_public_tcase, qobject_to_qstring_test); |
113 |
|
114 |
return s;
|
115 |
} |
116 |
|
117 |
int main(void) |
118 |
{ |
119 |
int nf;
|
120 |
Suite *s; |
121 |
SRunner *sr; |
122 |
|
123 |
s = qstring_suite(); |
124 |
sr = srunner_create(s); |
125 |
|
126 |
srunner_run_all(sr, CK_NORMAL); |
127 |
nf = srunner_ntests_failed(sr); |
128 |
srunner_free(sr); |
129 |
|
130 |
return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE; |
131 |
} |