You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CIdentifierTest.hpp 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. ///-------------------------------------------------------------------------------------------------
  2. ///
  3. /// \file CIdentifierTest.hpp
  4. /// \brief Test Definitions for OpenViBE Identifier Class.
  5. /// \author Thibaut Monseigne (Inria).
  6. /// \version 1.0.
  7. /// \date 23/06/2020.
  8. /// \copyright <a href="https://choosealicense.com/licenses/agpl-3.0/">GNU Affero General Public License v3.0</a>.
  9. ///
  10. ///-------------------------------------------------------------------------------------------------
  11. #pragma once
  12. #include <gtest/gtest.h>
  13. #include <openvibe/CIdentifier.hpp>
  14. #include "utils.hpp"
  15. //---------------------------------------------------------------------------------------------------
  16. TEST(CIdentifier_Tests, constructors)
  17. {
  18. OpenViBE::CIdentifier id1, id2(10), id3(-1), id4(10, 10), id5("false string"), id6("(0x00000000, 0x0000000A)");
  19. const uint64_t undef = std::numeric_limits<uint64_t>::max();
  20. EXPECT_EQ(id1.id(), undef) << ErrorMsg("Default Constructor", id1.id(), undef);
  21. EXPECT_EQ(id2.id(), 10) << ErrorMsg("Integer Constructor", id2.id(), 10);
  22. EXPECT_EQ(id3.id(), undef) << ErrorMsg("Negative value Constructor", id3.id(), undef);
  23. EXPECT_EQ(id4.id(), 42949672970) << ErrorMsg("Double ID Constructor", id4.id(), 42949672970); // 10 * 2^32 + 10
  24. EXPECT_EQ(id5.id(), undef) << ErrorMsg("False string Constructor", id5.id(), undef);
  25. EXPECT_EQ(id6.id(), 10) << ErrorMsg("String Constructor", id6.id(), 10);
  26. }
  27. //---------------------------------------------------------------------------------------------------
  28. //---------------------------------------------------------------------------------------------------
  29. TEST(CIdentifier_Tests, operators)
  30. {
  31. OpenViBE::CIdentifier id(10);
  32. const OpenViBE::CIdentifier id2(10);
  33. const uint64_t undef = std::numeric_limits<uint64_t>::max();
  34. id = 0;
  35. EXPECT_EQ(id.id(), 0) << ErrorMsg("Assignement operator with unsigned", id.id(), 0);
  36. id = OpenViBE::CIdentifier::undefined();
  37. EXPECT_EQ(id.id(), undef) << ErrorMsg("Assignement operator with CIdentifier", id.id(), undef);
  38. ++id; // No change if undef
  39. EXPECT_EQ(id.id(), undef) << ErrorMsg("++ operator with undefined Identifier", id.id(), undef);
  40. --id; // No change if undef
  41. EXPECT_EQ(id.id(), undef) << ErrorMsg("-- operator with undefined Identifier", id.id(), undef);
  42. id = 0;
  43. --id; // 0 became max - 1
  44. EXPECT_EQ(id.id(), undef - 1) << ErrorMsg("-- operator with Identifier 0", id.id(), undef - 1);
  45. ++id; // max - 1 became 0
  46. EXPECT_EQ(id.id(), 0) << ErrorMsg("++ operator with Identifier 0", id.id(), undef - 1);
  47. id = 0;
  48. EXPECT_TRUE(id<=id && id>=id && id < id2 && id2 > id) << ErrorMsg("Comparison Operator", id.id(), id2.id());
  49. std::stringstream ss;
  50. ss << id;
  51. EXPECT_EQ(ss.str(), "(0x00000000, 0x00000000)") << ErrorMsg("ostream operator", ss.str(), "(0x00000000, 0x00000000)");
  52. }
  53. //---------------------------------------------------------------------------------------------------