root / check-qfloat.c @ 124964b5
History | View | Annotate | Download (1.5 kB)
1 | 9c9efb6b | Anthony Liguori | /*
|
---|---|---|---|
2 | 9c9efb6b | Anthony Liguori | * QFloat unit-tests.
|
3 | 9c9efb6b | Anthony Liguori | *
|
4 | 9c9efb6b | Anthony Liguori | * Copyright IBM, Corp. 2009
|
5 | 9c9efb6b | Anthony Liguori | *
|
6 | 9c9efb6b | Anthony Liguori | * Authors:
|
7 | 9c9efb6b | Anthony Liguori | * Anthony Liguori <aliguori@us.ibm.com>
|
8 | 9c9efb6b | Anthony Liguori | *
|
9 | 9c9efb6b | Anthony Liguori | * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
|
10 | 9c9efb6b | Anthony Liguori | * See the COPYING.LIB file in the top-level directory.
|
11 | 9c9efb6b | Anthony Liguori | *
|
12 | 9c9efb6b | Anthony Liguori | */
|
13 | 9c9efb6b | Anthony Liguori | #include <check.h> |
14 | 9c9efb6b | Anthony Liguori | |
15 | 9c9efb6b | Anthony Liguori | #include "qfloat.h" |
16 | 9c9efb6b | Anthony Liguori | #include "qemu-common.h" |
17 | 9c9efb6b | Anthony Liguori | |
18 | 9c9efb6b | Anthony Liguori | /*
|
19 | 9c9efb6b | Anthony Liguori | * Public Interface test-cases
|
20 | 9c9efb6b | Anthony Liguori | *
|
21 | 9c9efb6b | Anthony Liguori | * (with some violations to access 'private' data)
|
22 | 9c9efb6b | Anthony Liguori | */
|
23 | 9c9efb6b | Anthony Liguori | |
24 | 9c9efb6b | Anthony Liguori | START_TEST(qfloat_from_double_test) |
25 | 9c9efb6b | Anthony Liguori | { |
26 | 9c9efb6b | Anthony Liguori | QFloat *qf; |
27 | 9c9efb6b | Anthony Liguori | const double value = -42.23423; |
28 | 9c9efb6b | Anthony Liguori | |
29 | 9c9efb6b | Anthony Liguori | qf = qfloat_from_double(value); |
30 | 9c9efb6b | Anthony Liguori | fail_unless(qf != NULL);
|
31 | 9c9efb6b | Anthony Liguori | fail_unless(qf->value == value); |
32 | 9c9efb6b | Anthony Liguori | fail_unless(qf->base.refcnt == 1);
|
33 | 9c9efb6b | Anthony Liguori | fail_unless(qobject_type(QOBJECT(qf)) == QTYPE_QFLOAT); |
34 | 9c9efb6b | Anthony Liguori | |
35 | 9c9efb6b | Anthony Liguori | // destroy doesn't exit yet
|
36 | 9c9efb6b | Anthony Liguori | qemu_free(qf); |
37 | 9c9efb6b | Anthony Liguori | } |
38 | 9c9efb6b | Anthony Liguori | END_TEST |
39 | 9c9efb6b | Anthony Liguori | |
40 | 9c9efb6b | Anthony Liguori | START_TEST(qfloat_destroy_test) |
41 | 9c9efb6b | Anthony Liguori | { |
42 | 9c9efb6b | Anthony Liguori | QFloat *qf = qfloat_from_double(0.0); |
43 | 9c9efb6b | Anthony Liguori | QDECREF(qf); |
44 | 9c9efb6b | Anthony Liguori | } |
45 | 9c9efb6b | Anthony Liguori | END_TEST |
46 | 9c9efb6b | Anthony Liguori | |
47 | 9c9efb6b | Anthony Liguori | static Suite *qfloat_suite(void) |
48 | 9c9efb6b | Anthony Liguori | { |
49 | 9c9efb6b | Anthony Liguori | Suite *s; |
50 | 9c9efb6b | Anthony Liguori | TCase *qfloat_public_tcase; |
51 | 9c9efb6b | Anthony Liguori | |
52 | 9c9efb6b | Anthony Liguori | s = suite_create("QFloat test-suite");
|
53 | 9c9efb6b | Anthony Liguori | |
54 | 9c9efb6b | Anthony Liguori | qfloat_public_tcase = tcase_create("Public Interface");
|
55 | 9c9efb6b | Anthony Liguori | suite_add_tcase(s, qfloat_public_tcase); |
56 | 9c9efb6b | Anthony Liguori | tcase_add_test(qfloat_public_tcase, qfloat_from_double_test); |
57 | 9c9efb6b | Anthony Liguori | tcase_add_test(qfloat_public_tcase, qfloat_destroy_test); |
58 | 9c9efb6b | Anthony Liguori | |
59 | 9c9efb6b | Anthony Liguori | return s;
|
60 | 9c9efb6b | Anthony Liguori | } |
61 | 9c9efb6b | Anthony Liguori | |
62 | 9c9efb6b | Anthony Liguori | int main(void) |
63 | 9c9efb6b | Anthony Liguori | { |
64 | 9c9efb6b | Anthony Liguori | int nf;
|
65 | 9c9efb6b | Anthony Liguori | Suite *s; |
66 | 9c9efb6b | Anthony Liguori | SRunner *sr; |
67 | 9c9efb6b | Anthony Liguori | |
68 | 9c9efb6b | Anthony Liguori | s = qfloat_suite(); |
69 | 9c9efb6b | Anthony Liguori | sr = srunner_create(s); |
70 | 9c9efb6b | Anthony Liguori | |
71 | 9c9efb6b | Anthony Liguori | srunner_run_all(sr, CK_NORMAL); |
72 | 9c9efb6b | Anthony Liguori | nf = srunner_ntests_failed(sr); |
73 | 9c9efb6b | Anthony Liguori | srunner_free(sr); |
74 | 9c9efb6b | Anthony Liguori | |
75 | 9c9efb6b | Anthony Liguori | return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE; |
76 | 9c9efb6b | Anthony Liguori | } |