check_money.3.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Check: a unit test framework for C
  3. * Copyright (C) 2001, 2002 Arien Malec
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2.1 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, write to the
  17. * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
  18. * MA 02110-1301, USA.
  19. */
  20. #include <stdlib.h>
  21. #include <check.h>
  22. #include "../src/money.h"
  23. START_TEST(test_money_create)
  24. {
  25. Money *m;
  26. m = money_create(5, "USD");
  27. ck_assert_int_eq(money_amount(m), 5);
  28. ck_assert_str_eq(money_currency(m), "USD");
  29. money_free(m);
  30. }
  31. END_TEST
  32. Suite * money_suite(void)
  33. {
  34. Suite *s;
  35. TCase *tc_core;
  36. s = suite_create("Money");
  37. /* Core test case */
  38. tc_core = tcase_create("Core");
  39. tcase_add_test(tc_core, test_money_create);
  40. suite_add_tcase(s, tc_core);
  41. return s;
  42. }
  43. int main(void)
  44. {
  45. int number_failed;
  46. Suite *s;
  47. SRunner *sr;
  48. s = money_suite();
  49. sr = srunner_create(s);
  50. srunner_run_all(sr, CK_NORMAL);
  51. number_failed = srunner_ntests_failed(sr);
  52. srunner_free(sr);
  53. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  54. }