VersionTest.cpp 2.5 KB

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