blob: 6404ac8df6013b4c1afaad8c70cf04dcb82bf961 [file] [log] [blame]
Anthony Liguori9c9efb62009-11-11 10:36:51 -06001/*
2 * QFloat unit-tests.
3 *
Anthony Liguori9c9efb62009-11-11 10:36:51 -06004 * Copyright IBM, Corp. 2009
5 *
6 * Authors:
7 * Anthony Liguori <aliguori@us.ibm.com>
8 *
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.
11 *
12 */
Anthony Liguoria9e1c282012-01-10 13:10:45 -060013#include <glib.h>
Anthony Liguori9c9efb62009-11-11 10:36:51 -060014
Paolo Bonzini7b1b5d12012-12-17 18:19:43 +010015#include "qapi/qmp/qfloat.h"
Anthony Liguori9c9efb62009-11-11 10:36:51 -060016#include "qemu-common.h"
17
18/*
19 * Public Interface test-cases
20 *
21 * (with some violations to access 'private' data)
22 */
23
Anthony Liguoria9e1c282012-01-10 13:10:45 -060024static void qfloat_from_double_test(void)
Anthony Liguori9c9efb62009-11-11 10:36:51 -060025{
26 QFloat *qf;
27 const double value = -42.23423;
28
29 qf = qfloat_from_double(value);
Anthony Liguoria9e1c282012-01-10 13:10:45 -060030 g_assert(qf != NULL);
31 g_assert(qf->value == value);
32 g_assert(qf->base.refcnt == 1);
33 g_assert(qobject_type(QOBJECT(qf)) == QTYPE_QFLOAT);
Anthony Liguori9c9efb62009-11-11 10:36:51 -060034
35 // destroy doesn't exit yet
Anthony Liguori7267c092011-08-20 22:09:37 -050036 g_free(qf);
Anthony Liguori9c9efb62009-11-11 10:36:51 -060037}
Anthony Liguori9c9efb62009-11-11 10:36:51 -060038
Anthony Liguoria9e1c282012-01-10 13:10:45 -060039static void qfloat_destroy_test(void)
Anthony Liguori9c9efb62009-11-11 10:36:51 -060040{
41 QFloat *qf = qfloat_from_double(0.0);
42 QDECREF(qf);
43}
Anthony Liguori9c9efb62009-11-11 10:36:51 -060044
Anthony Liguoria9e1c282012-01-10 13:10:45 -060045int main(int argc, char **argv)
Anthony Liguori9c9efb62009-11-11 10:36:51 -060046{
Anthony Liguoria9e1c282012-01-10 13:10:45 -060047 g_test_init(&argc, &argv, NULL);
Anthony Liguori9c9efb62009-11-11 10:36:51 -060048
Anthony Liguoria9e1c282012-01-10 13:10:45 -060049 g_test_add_func("/public/from_double", qfloat_from_double_test);
50 g_test_add_func("/public/destroy", qfloat_destroy_test);
Anthony Liguori9c9efb62009-11-11 10:36:51 -060051
Anthony Liguoria9e1c282012-01-10 13:10:45 -060052 return g_test_run();
Anthony Liguori9c9efb62009-11-11 10:36:51 -060053}