VersionTest.cpp 2.3 KB

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