VersionTest.cpp 2.3 KB

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