VersionTest.cpp 2.4 KB

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