version.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <config.h>
  20. #include <stdlib.h>
  21. #include <check.h>
  22. #include <libsigrok/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 neither be
  58. * NULL nor empty, and the length shall be within an expected range.
  59. *
  60. * The lower limit assumes:
  61. * - A version text consists of three parts (major, minor, micro),
  62. * like "0.1.0".
  63. * - Three numbers with at least one digit, and their separators,
  64. * result in a minimum length of 5.
  65. *
  66. * The upper limit assumes:
  67. * - The major, minor, and micro parts won't contain more than two
  68. * digits each (this is an arbitrary choice).
  69. * - An optional "-git-<hash>" suffix might follow. While git(1)
  70. * defaults to 7 hex digits for abbreviated hashes, projects of
  71. * larger scale might recommend to use more digits to avoid
  72. * potential ambiguity (e.g. Linux recommends core.abbrev=12).
  73. * Again, this is an arbitrary choice.
  74. */
  75. START_TEST(test_version_strings)
  76. {
  77. const char *str;
  78. const size_t len_min = 5;
  79. const size_t len_max = 2 + 1 + 2 + 1 + 2 + 5 + 12;
  80. str = sr_package_version_string_get();
  81. fail_unless(str != NULL);
  82. fail_unless(strlen(str) >= len_min);
  83. fail_unless(strlen(str) <= len_max);
  84. str = sr_lib_version_string_get();
  85. fail_unless(str != NULL);
  86. fail_unless(strlen(str) >= len_min);
  87. fail_unless(strlen(str) <= len_max);
  88. }
  89. END_TEST
  90. Suite *suite_version(void)
  91. {
  92. Suite *s;
  93. TCase *tc;
  94. s = suite_create("version");
  95. tc = tcase_create("version");
  96. tcase_add_test(tc, test_version_numbers);
  97. tcase_add_test(tc, test_version_strings);
  98. suite_add_tcase(s, tc);
  99. return s;
  100. }