1
0

version_tests.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include <cctype>
  2. #include <cpr/cpr.h>
  3. #include <cstddef>
  4. #include <gtest/gtest.h>
  5. #include <string>
  6. TEST(VersionTests, StringVersionExists) {
  7. #ifndef CPR_VERSION
  8. EXPECT_TRUE(false);
  9. #endif // CPR_VERSION
  10. }
  11. TEST(VersionTests, StringVersionValid) {
  12. EXPECT_TRUE(CPR_VERSION != nullptr);
  13. std::string version = CPR_VERSION;
  14. // Check if the version string is: '\d+\.\d+\.\d+'
  15. bool digit = true;
  16. size_t dotCount = 0;
  17. for (size_t i = 0; i < version.size(); i++) {
  18. if (i == 0) {
  19. EXPECT_TRUE(std::isdigit(version[i]));
  20. } else if (digit) {
  21. if (version[i] == '.') {
  22. digit = false;
  23. dotCount++;
  24. continue;
  25. }
  26. }
  27. EXPECT_TRUE(std::isdigit(version[i]));
  28. digit = true;
  29. }
  30. EXPECT_EQ(dotCount, 2);
  31. }
  32. TEST(VersionTests, VersionMajorExists) {
  33. #ifndef CPR_VERSION_MAJOR
  34. EXPECT_TRUE(false);
  35. #endif // CPR_VERSION_MAJOR
  36. }
  37. TEST(VersionTests, VersionMinorExists) {
  38. #ifndef CPR_VERSION_MINOR
  39. EXPECT_TRUE(false);
  40. #endif // CPR_VERSION_MINOR
  41. }
  42. TEST(VersionTests, VersionPatchExists) {
  43. #ifndef CPR_VERSION_PATCH
  44. EXPECT_TRUE(false);
  45. #endif // CPR_VERSION_PATCH
  46. }
  47. TEST(VersionTests, VersionNumExists) {
  48. #ifndef CPR_VERSION_NUM
  49. EXPECT_TRUE(false);
  50. #endif // CPR_VERSION_NUM
  51. }
  52. int main(int argc, char** argv) {
  53. ::testing::InitGoogleTest(&argc, argv);
  54. return RUN_ALL_TESTS();
  55. }