aboutsummaryrefslogtreecommitdiff
path: root/check-qfloat.c
blob: 3344057b3b179b30db982c2ee55b12cfb4dca3b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
 * QFloat unit-tests.
 *
 * Copyright IBM, Corp. 2009
 *
 * Authors:
 *  Anthony Liguori   <aliguori@us.ibm.com>
 *
 * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
 * See the COPYING.LIB file in the top-level directory.
 *
 */
#include <check.h>

#include "qfloat.h"
#include "qemu-common.h"

/*
 * Public Interface test-cases
 *
 * (with some violations to access 'private' data)
 */

START_TEST(qfloat_from_double_test)
{
    QFloat *qf;
    const double value = -42.23423;

    qf = qfloat_from_double(value);
    fail_unless(qf != NULL);
    fail_unless(qf->value == value);
    fail_unless(qf->base.refcnt == 1);
    fail_unless(qobject_type(QOBJECT(qf)) == QTYPE_QFLOAT);

    // destroy doesn't exit yet
    g_free(qf);
}
END_TEST

START_TEST(qfloat_destroy_test)
{
    QFloat *qf = qfloat_from_double(0.0);
    QDECREF(qf);
}
END_TEST

static Suite *qfloat_suite(void)
{
    Suite *s;
    TCase *qfloat_public_tcase;

    s = suite_create("QFloat test-suite");

    qfloat_public_tcase = tcase_create("Public Interface");
    suite_add_tcase(s, qfloat_public_tcase);
    tcase_add_test(qfloat_public_tcase, qfloat_from_double_test);
    tcase_add_test(qfloat_public_tcase, qfloat_destroy_test);

    return s;
}

int main(void)
{
    int nf;
    Suite *s;
    SRunner *sr;

    s = qfloat_suite();
    sr = srunner_create(s);

    srunner_run_all(sr, CK_NORMAL);
    nf = srunner_ntests_failed(sr);
    srunner_free(sr);

    return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}