VersionTest.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-09-28
  6. * Changed: 2023-02-03
  7. *
  8. * */
  9. #include <gtest/gtest.h>
  10. #include <ls-std/ls-std-core.hpp>
  11. using namespace ls::std::core;
  12. namespace
  13. {
  14. class VersionTest : public ::testing::Test
  15. {
  16. protected:
  17. VersionTest() = default;
  18. ~VersionTest() override = default;
  19. void SetUp() override
  20. {}
  21. void TearDown() override
  22. {}
  23. };
  24. // implementation
  25. TEST_F(VersionTest, marshal)
  26. {
  27. Version version{2020, 2, 0};
  28. ASSERT_STREQ("2020.2.0", version.marshal().c_str());
  29. }
  30. TEST_F(VersionTest, unmarshal)
  31. {
  32. Version version{0, 0, 0};
  33. version.unmarshal("2020.2.13");
  34. ASSERT_EQ(2020, version.getMajorVersion());
  35. ASSERT_EQ(2, version.getMinorVersion());
  36. ASSERT_EQ(13, version.getPatchVersion());
  37. }
  38. // other functionality
  39. TEST_F(VersionTest, getMajorVersion)
  40. {
  41. Version version{13, 2, 4};
  42. ASSERT_EQ(13, version.getMajorVersion());
  43. }
  44. TEST_F(VersionTest, getMinorVersion)
  45. {
  46. Version version{13, 2, 4};
  47. ASSERT_EQ(2, version.getMinorVersion());
  48. }
  49. TEST_F(VersionTest, getPatchVersion)
  50. {
  51. Version version{13, 2, 4};
  52. ASSERT_EQ(4, version.getPatchVersion());
  53. }
  54. TEST_F(VersionTest, isValid)
  55. {
  56. ASSERT_TRUE(Version::isValid("2020.1.2"));
  57. ASSERT_TRUE(Version::isValid("2.5.1"));
  58. }
  59. TEST_F(VersionTest, isValid_emptyString)
  60. {
  61. ASSERT_FALSE(Version::isValid(""));
  62. }
  63. TEST_F(VersionTest, isValid_noValidVersionString)
  64. {
  65. ASSERT_FALSE(Version::isValid("v2020.1.2"));
  66. ASSERT_FALSE(Version::isValid("2.5"));
  67. ASSERT_FALSE(Version::isValid("2020"));
  68. ASSERT_FALSE(Version::isValid("blaaaa"));
  69. }
  70. TEST_F(VersionTest, setMajorVersion)
  71. {
  72. Version version{13, 2, 4};
  73. ASSERT_EQ(13, version.getMajorVersion());
  74. version.setMajorVersion(14);
  75. ASSERT_EQ(14, version.getMajorVersion());
  76. }
  77. TEST_F(VersionTest, setMinorVersion)
  78. {
  79. Version version{13, 2, 4};
  80. ASSERT_EQ(2, version.getMinorVersion());
  81. version.setMinorVersion(3);
  82. ASSERT_EQ(3, version.getMinorVersion());
  83. }
  84. TEST_F(VersionTest, setPatchVersion)
  85. {
  86. Version version{13, 2, 4};
  87. ASSERT_EQ(4, version.getPatchVersion());
  88. version.setPatchVersion(5);
  89. ASSERT_EQ(5, version.getPatchVersion());
  90. }
  91. }