check_version.c 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * This file is part of the libsigrok project.
  3. *
  4. * Copyright (C) 2013 Uwe Hermann <uwe@hermann-uwe.de>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include <stdlib.h>
  21. #include <check.h>
  22. #include "../libsigrok.h"
  23. #include "lib.h"
  24. /*
  25. * Check the version number API calls and macros.
  26. *
  27. * The numbers returned by the sr_*_version*get() calls must match the
  28. * respective SR_*_VERSION* macro values, must be >= 0, and must not be
  29. * unreasonably high (> 20), otherwise something is probably wrong.
  30. */
  31. START_TEST(test_version_numbers)
  32. {
  33. int ver;
  34. ver = sr_package_version_major_get();
  35. fail_unless(ver == SR_PACKAGE_VERSION_MAJOR);
  36. fail_unless(ver >= 0 && ver <= 20);
  37. ver = sr_package_version_minor_get();
  38. fail_unless(ver == SR_PACKAGE_VERSION_MINOR);
  39. fail_unless(ver >= 0 && ver <= 20);
  40. ver = sr_package_version_micro_get();
  41. fail_unless(ver == SR_PACKAGE_VERSION_MICRO);
  42. fail_unless(ver >= 0 && ver <= 20);
  43. ver = sr_lib_version_current_get();
  44. fail_unless(ver == SR_LIB_VERSION_CURRENT);
  45. fail_unless(ver >= 0 && ver <= 20);
  46. ver = sr_lib_version_revision_get();
  47. fail_unless(ver == SR_LIB_VERSION_REVISION);
  48. fail_unless(ver >= 0 && ver <= 20);
  49. ver = sr_lib_version_age_get();
  50. fail_unless(ver == SR_LIB_VERSION_AGE);
  51. fail_unless(ver >= 0 && ver <= 20);
  52. }
  53. END_TEST
  54. /*
  55. * Check the version number API calls and macros.
  56. *
  57. * The string representations of the package/lib version must match the
  58. * version numbers, the string lengths must be >= 5 (e.g. "0.1.0"), and
  59. * the strings length must be <= 20 characters, otherwise something is
  60. * probably wrong.
  61. */
  62. START_TEST(test_version_strings)
  63. {
  64. const char *str;
  65. str = sr_package_version_string_get();
  66. fail_unless(str != NULL);
  67. fail_unless(strlen(str) >= 5 && strlen(str) <= 20);
  68. str = sr_lib_version_string_get();
  69. fail_unless(str != NULL);
  70. fail_unless(strlen(str) >= 5 && strlen(str) <= 20);
  71. }
  72. END_TEST
  73. Suite *suite_version(void)
  74. {
  75. Suite *s;
  76. TCase *tc;
  77. s = suite_create("version");
  78. tc = tcase_create("version");
  79. tcase_add_test(tc, test_version_numbers);
  80. tcase_add_test(tc, test_version_strings);
  81. suite_add_tcase(s, tc);
  82. return s;
  83. }