migration: move some declarations to migration.h
[qemu/mdroth.git] / check-qint.c
blobf3b031698c4021612ba051ed1a61a501d7ed3683
1 /*
2 * QInt 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 "qint.h"
15 #include "qemu-common.h"
18 * Public Interface test-cases
20 * (with some violations to access 'private' data)
23 START_TEST(qint_from_int_test)
25 QInt *qi;
26 const int value = -42;
28 qi = qint_from_int(value);
29 fail_unless(qi != NULL);
30 fail_unless(qi->value == value);
31 fail_unless(qi->base.refcnt == 1);
32 fail_unless(qobject_type(QOBJECT(qi)) == QTYPE_QINT);
34 // destroy doesn't exit yet
35 qemu_free(qi);
37 END_TEST
39 START_TEST(qint_destroy_test)
41 QInt *qi = qint_from_int(0);
42 QDECREF(qi);
44 END_TEST
46 START_TEST(qint_from_int64_test)
48 QInt *qi;
49 const int64_t value = 0x1234567890abcdefLL;
51 qi = qint_from_int(value);
52 fail_unless((int64_t) qi->value == value);
54 QDECREF(qi);
56 END_TEST
58 START_TEST(qint_get_int_test)
60 QInt *qi;
61 const int value = 123456;
63 qi = qint_from_int(value);
64 fail_unless(qint_get_int(qi) == value);
66 QDECREF(qi);
68 END_TEST
70 START_TEST(qobject_to_qint_test)
72 QInt *qi;
74 qi = qint_from_int(0);
75 fail_unless(qobject_to_qint(QOBJECT(qi)) == qi);
77 QDECREF(qi);
79 END_TEST
81 static Suite *qint_suite(void)
83 Suite *s;
84 TCase *qint_public_tcase;
86 s = suite_create("QInt test-suite");
88 qint_public_tcase = tcase_create("Public Interface");
89 suite_add_tcase(s, qint_public_tcase);
90 tcase_add_test(qint_public_tcase, qint_from_int_test);
91 tcase_add_test(qint_public_tcase, qint_destroy_test);
92 tcase_add_test(qint_public_tcase, qint_from_int64_test);
93 tcase_add_test(qint_public_tcase, qint_get_int_test);
94 tcase_add_test(qint_public_tcase, qobject_to_qint_test);
96 return s;
99 int main(void)
101 int nf;
102 Suite *s;
103 SRunner *sr;
105 s = qint_suite();
106 sr = srunner_create(s);
108 srunner_run_all(sr, CK_NORMAL);
109 nf = srunner_ntests_failed(sr);
110 srunner_free(sr);
112 return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;