4 * Copyright (C) 2009 Red Hat Inc.
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.
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
)
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
);
40 START_TEST(qstring_destroy_test
)
42 QString
*qstring
= qstring_from_str("destroy test");
47 START_TEST(qstring_get_str_test
)
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);
61 START_TEST(qstring_append_chr_test
)
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);
77 START_TEST(qstring_from_substr_test
)
81 qs
= qstring_from_substr("virtualization", 3, 9);
82 fail_unless(qs
!= NULL
);
83 fail_unless(strcmp(qstring_get_str(qs
), "tualiza") == 0);
90 START_TEST(qobject_to_qstring_test
)
94 qstring
= qstring_from_str("foo");
95 fail_unless(qobject_to_qstring(QOBJECT(qstring
)) == qstring
);
101 static Suite
*qstring_suite(void)
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
);
127 sr
= srunner_create(s
);
129 srunner_run_all(sr
, CK_NORMAL
);
130 nf
= srunner_ntests_failed(sr
);
133 return (nf
== 0) ? EXIT_SUCCESS
: EXIT_FAILURE
;