check-qfloat.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * QFloat unit-tests.
  3. *
  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. */
  13. #include <check.h>
  14. #include "qfloat.h"
  15. #include "qemu-common.h"
  16. /*
  17. * Public Interface test-cases
  18. *
  19. * (with some violations to access 'private' data)
  20. */
  21. START_TEST(qfloat_from_double_test)
  22. {
  23. QFloat *qf;
  24. const double value = -42.23423;
  25. qf = qfloat_from_double(value);
  26. fail_unless(qf != NULL);
  27. fail_unless(qf->value == value);
  28. fail_unless(qf->base.refcnt == 1);
  29. fail_unless(qobject_type(QOBJECT(qf)) == QTYPE_QFLOAT);
  30. // destroy doesn't exit yet
  31. qemu_free(qf);
  32. }
  33. END_TEST
  34. START_TEST(qfloat_destroy_test)
  35. {
  36. QFloat *qf = qfloat_from_double(0.0);
  37. QDECREF(qf);
  38. }
  39. END_TEST
  40. static Suite *qfloat_suite(void)
  41. {
  42. Suite *s;
  43. TCase *qfloat_public_tcase;
  44. s = suite_create("QFloat test-suite");
  45. qfloat_public_tcase = tcase_create("Public Interface");
  46. suite_add_tcase(s, qfloat_public_tcase);
  47. tcase_add_test(qfloat_public_tcase, qfloat_from_double_test);
  48. tcase_add_test(qfloat_public_tcase, qfloat_destroy_test);
  49. return s;
  50. }
  51. int main(void)
  52. {
  53. int nf;
  54. Suite *s;
  55. SRunner *sr;
  56. s = qfloat_suite();
  57. sr = srunner_create(s);
  58. srunner_run_all(sr, CK_NORMAL);
  59. nf = srunner_ntests_failed(sr);
  60. srunner_free(sr);
  61. return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  62. }