Anthony Liguori | 9c9efb6 | 2009-11-11 10:36:51 -0600 | [diff] [blame] | 1 | /* |
| 2 | * QFloat unit-tests. |
| 3 | * |
Anthony Liguori | 9c9efb6 | 2009-11-11 10:36:51 -0600 | [diff] [blame] | 4 | * 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 Liguori | a9e1c28 | 2012-01-10 13:10:45 -0600 | [diff] [blame] | 13 | #include <glib.h> |
Anthony Liguori | 9c9efb6 | 2009-11-11 10:36:51 -0600 | [diff] [blame] | 14 | |
Paolo Bonzini | 7b1b5d1 | 2012-12-17 18:19:43 +0100 | [diff] [blame] | 15 | #include "qapi/qmp/qfloat.h" |
Anthony Liguori | 9c9efb6 | 2009-11-11 10:36:51 -0600 | [diff] [blame] | 16 | #include "qemu-common.h" |
| 17 | |
| 18 | /* |
| 19 | * Public Interface test-cases |
| 20 | * |
| 21 | * (with some violations to access 'private' data) |
| 22 | */ |
| 23 | |
Anthony Liguori | a9e1c28 | 2012-01-10 13:10:45 -0600 | [diff] [blame] | 24 | static void qfloat_from_double_test(void) |
Anthony Liguori | 9c9efb6 | 2009-11-11 10:36:51 -0600 | [diff] [blame] | 25 | { |
| 26 | QFloat *qf; |
| 27 | const double value = -42.23423; |
| 28 | |
| 29 | qf = qfloat_from_double(value); |
Anthony Liguori | a9e1c28 | 2012-01-10 13:10:45 -0600 | [diff] [blame] | 30 | 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 Liguori | 9c9efb6 | 2009-11-11 10:36:51 -0600 | [diff] [blame] | 34 | |
| 35 | // destroy doesn't exit yet |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 36 | g_free(qf); |
Anthony Liguori | 9c9efb6 | 2009-11-11 10:36:51 -0600 | [diff] [blame] | 37 | } |
Anthony Liguori | 9c9efb6 | 2009-11-11 10:36:51 -0600 | [diff] [blame] | 38 | |
Anthony Liguori | a9e1c28 | 2012-01-10 13:10:45 -0600 | [diff] [blame] | 39 | static void qfloat_destroy_test(void) |
Anthony Liguori | 9c9efb6 | 2009-11-11 10:36:51 -0600 | [diff] [blame] | 40 | { |
| 41 | QFloat *qf = qfloat_from_double(0.0); |
| 42 | QDECREF(qf); |
| 43 | } |
Anthony Liguori | 9c9efb6 | 2009-11-11 10:36:51 -0600 | [diff] [blame] | 44 | |
Anthony Liguori | a9e1c28 | 2012-01-10 13:10:45 -0600 | [diff] [blame] | 45 | int main(int argc, char **argv) |
Anthony Liguori | 9c9efb6 | 2009-11-11 10:36:51 -0600 | [diff] [blame] | 46 | { |
Anthony Liguori | a9e1c28 | 2012-01-10 13:10:45 -0600 | [diff] [blame] | 47 | g_test_init(&argc, &argv, NULL); |
Anthony Liguori | 9c9efb6 | 2009-11-11 10:36:51 -0600 | [diff] [blame] | 48 | |
Anthony Liguori | a9e1c28 | 2012-01-10 13:10:45 -0600 | [diff] [blame] | 49 | g_test_add_func("/public/from_double", qfloat_from_double_test); |
| 50 | g_test_add_func("/public/destroy", qfloat_destroy_test); |
Anthony Liguori | 9c9efb6 | 2009-11-11 10:36:51 -0600 | [diff] [blame] | 51 | |
Anthony Liguori | a9e1c28 | 2012-01-10 13:10:45 -0600 | [diff] [blame] | 52 | return g_test_run(); |
Anthony Liguori | 9c9efb6 | 2009-11-11 10:36:51 -0600 | [diff] [blame] | 53 | } |