2009-08-28 20:27:29 +02:00
|
|
|
/*
|
|
|
|
* QInt unit-tests.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Red Hat Inc.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Luiz Capitulino <lcapitulino@redhat.com>
|
2010-05-12 21:34:42 +02:00
|
|
|
*
|
|
|
|
* 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.
|
2009-08-28 20:27:29 +02:00
|
|
|
*/
|
2016-02-08 19:08:51 +01:00
|
|
|
#include "qemu/osdep.h"
|
2009-08-28 20:27:29 +02:00
|
|
|
|
2012-12-17 18:19:43 +01:00
|
|
|
#include "qapi/qmp/qint.h"
|
2009-08-28 20:27:29 +02:00
|
|
|
#include "qemu-common.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Public Interface test-cases
|
|
|
|
*
|
|
|
|
* (with some violations to access 'private' data)
|
|
|
|
*/
|
|
|
|
|
2012-01-10 20:10:46 +01:00
|
|
|
static void qint_from_int_test(void)
|
2009-08-28 20:27:29 +02:00
|
|
|
{
|
|
|
|
QInt *qi;
|
|
|
|
const int value = -42;
|
|
|
|
|
|
|
|
qi = qint_from_int(value);
|
2012-01-10 20:10:46 +01:00
|
|
|
g_assert(qi != NULL);
|
|
|
|
g_assert(qi->value == value);
|
|
|
|
g_assert(qi->base.refcnt == 1);
|
|
|
|
g_assert(qobject_type(QOBJECT(qi)) == QTYPE_QINT);
|
2009-08-28 20:27:29 +02:00
|
|
|
|
|
|
|
// destroy doesn't exit yet
|
2011-08-21 05:09:37 +02:00
|
|
|
g_free(qi);
|
2009-08-28 20:27:29 +02:00
|
|
|
}
|
|
|
|
|
2012-01-10 20:10:46 +01:00
|
|
|
static void qint_destroy_test(void)
|
2009-08-28 20:27:29 +02:00
|
|
|
{
|
|
|
|
QInt *qi = qint_from_int(0);
|
|
|
|
QDECREF(qi);
|
|
|
|
}
|
|
|
|
|
2012-01-10 20:10:46 +01:00
|
|
|
static void qint_from_int64_test(void)
|
2009-08-28 20:27:29 +02:00
|
|
|
{
|
|
|
|
QInt *qi;
|
2009-09-08 11:53:37 +02:00
|
|
|
const int64_t value = 0x1234567890abcdefLL;
|
2009-08-28 20:27:29 +02:00
|
|
|
|
|
|
|
qi = qint_from_int(value);
|
2012-01-10 20:10:46 +01:00
|
|
|
g_assert((int64_t) qi->value == value);
|
2009-08-28 20:27:29 +02:00
|
|
|
|
|
|
|
QDECREF(qi);
|
|
|
|
}
|
|
|
|
|
2012-01-10 20:10:46 +01:00
|
|
|
static void qint_get_int_test(void)
|
2009-08-28 20:27:29 +02:00
|
|
|
{
|
|
|
|
QInt *qi;
|
|
|
|
const int value = 123456;
|
|
|
|
|
|
|
|
qi = qint_from_int(value);
|
2012-01-10 20:10:46 +01:00
|
|
|
g_assert(qint_get_int(qi) == value);
|
2009-08-28 20:27:29 +02:00
|
|
|
|
|
|
|
QDECREF(qi);
|
|
|
|
}
|
|
|
|
|
2012-01-10 20:10:46 +01:00
|
|
|
static void qobject_to_qint_test(void)
|
2009-08-28 20:27:29 +02:00
|
|
|
{
|
|
|
|
QInt *qi;
|
|
|
|
|
|
|
|
qi = qint_from_int(0);
|
2012-01-10 20:10:46 +01:00
|
|
|
g_assert(qobject_to_qint(QOBJECT(qi)) == qi);
|
2009-08-28 20:27:29 +02:00
|
|
|
|
|
|
|
QDECREF(qi);
|
|
|
|
}
|
|
|
|
|
2012-01-10 20:10:46 +01:00
|
|
|
int main(int argc, char **argv)
|
2009-08-28 20:27:29 +02:00
|
|
|
{
|
2012-01-10 20:10:46 +01:00
|
|
|
g_test_init(&argc, &argv, NULL);
|
2009-08-28 20:27:29 +02:00
|
|
|
|
2012-01-10 20:10:46 +01:00
|
|
|
g_test_add_func("/public/from_int", qint_from_int_test);
|
|
|
|
g_test_add_func("/public/destroy", qint_destroy_test);
|
|
|
|
g_test_add_func("/public/from_int64", qint_from_int64_test);
|
|
|
|
g_test_add_func("/public/get_int", qint_get_int_test);
|
|
|
|
g_test_add_func("/public/to_qint", qobject_to_qint_test);
|
2009-08-28 20:27:29 +02:00
|
|
|
|
2012-01-10 20:10:46 +01:00
|
|
|
return g_test_run();
|
2009-08-28 20:27:29 +02:00
|
|
|
}
|