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