qemu/virtio-pci: remove unnecessary check
[qemu/aliguori-queue.git] / check-qstring.c
blobea4dfd03c75e7c0a5eee6bafde9ff7befc74ae0b
1 /*
2 * QString unit-tests.
4 * Copyright (C) 2009 Red Hat Inc.
6 * Authors:
7 * Luiz Capitulino <lcapitulino@redhat.com>
8 */
9 #include <check.h>
11 #include "qstring.h"
12 #include "qemu-common.h"
15 * Public Interface test-cases
17 * (with some violations to access 'private' data)
20 START_TEST(qstring_from_str_test)
22 QString *qstring;
23 const char *str = "QEMU";
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);
31 // destroy doesn't exit yet
32 qemu_free(qstring->string);
33 qemu_free(qstring);
35 END_TEST
37 START_TEST(qstring_destroy_test)
39 QString *qstring = qstring_from_str("destroy test");
40 QDECREF(qstring);
42 END_TEST
44 START_TEST(qstring_get_str_test)
46 QString *qstring;
47 const char *ret_str;
48 const char *str = "QEMU/KVM";
50 qstring = qstring_from_str(str);
51 ret_str = qstring_get_str(qstring);
52 fail_unless(strcmp(ret_str, str) == 0);
54 QDECREF(qstring);
56 END_TEST
58 START_TEST(qobject_to_qstring_test)
60 QString *qstring;
62 qstring = qstring_from_str("foo");
63 fail_unless(qobject_to_qstring(QOBJECT(qstring)) == qstring);
65 QDECREF(qstring);
67 END_TEST
69 static Suite *qstring_suite(void)
71 Suite *s;
72 TCase *qstring_public_tcase;
74 s = suite_create("QString test-suite");
76 qstring_public_tcase = tcase_create("Public Interface");
77 suite_add_tcase(s, qstring_public_tcase);
78 tcase_add_test(qstring_public_tcase, qstring_from_str_test);
79 tcase_add_test(qstring_public_tcase, qstring_destroy_test);
80 tcase_add_test(qstring_public_tcase, qstring_get_str_test);
81 tcase_add_test(qstring_public_tcase, qobject_to_qstring_test);
83 return s;
86 int main(void)
88 int nf;
89 Suite *s;
90 SRunner *sr;
92 s = qstring_suite();
93 sr = srunner_create(s);
95 srunner_run_all(sr, CK_NORMAL);
96 nf = srunner_ntests_failed(sr);
97 srunner_free(sr);
99 return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;