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