Tribool.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #include "Test.h"
  2. #include "Tribool.h"
  3. #include <Logging.h>
  4. #include <ios>
  5. #include <sstream>
  6. namespace Utilities {
  7. namespace Test {
  8. void TestUtilTribool()
  9. {
  10. Tribool::Tribool x;
  11. std::stringstream ss;
  12. std::ostringstream out;
  13. ss.str("");
  14. out.str(std::string());
  15. x = false;
  16. out << x;
  17. ss << "Output false (noboolalpha): " << out.str() << std::endl;
  18. Logging::Log(Logging::Severity::Info, ss.str());
  19. ss.str("");
  20. out.str(std::string());
  21. x = true;
  22. out << x;
  23. ss << "Output true (noboolalpha): " << out.str() << std::endl;
  24. Logging::Log(Logging::Severity::Info, ss.str());
  25. ss.str("");
  26. out.str(std::string());
  27. x = Tribool::Tribool::Indeterminate;
  28. out << x;
  29. ss << "Output indeterminate (noboolalpha): " << out.str() << std::endl;
  30. Logging::Log(Logging::Severity::Info, ss.str());
  31. ss.str("");
  32. out.str(std::string());
  33. out << Tribool::Tribool::Indeterminate;
  34. ss << "Output indeterminate (noboolalpha): " << out.str() << std::endl;
  35. Logging::Log(Logging::Severity::Info, ss.str());
  36. ss.str("");
  37. out.str(std::string());
  38. x = false;
  39. out << std::boolalpha << x;
  40. ss << "Output false (boolalpha): " << out.str() << std::endl;
  41. Logging::Log(Logging::Severity::Info, ss.str());
  42. ss.str("");
  43. out.str(std::string());
  44. x = true;
  45. out << std::boolalpha << x;
  46. ss << "Output true (boolalpha): " << out.str() << std::endl;
  47. Logging::Log(Logging::Severity::Info, ss.str());
  48. ss.str("");
  49. out.str(std::string());
  50. x = Tribool::Tribool::Indeterminate;
  51. out << std::boolalpha << x;
  52. ss << "Output indeterminate (boolalpha - default name): " << out.str() << std::endl;
  53. Logging::Log(Logging::Severity::Info, ss.str());
  54. ss.str("");
  55. out.str(std::string());
  56. out << std::boolalpha << Tribool::Tribool::Indeterminate;
  57. ss << "Output indeterminate (boolalpha - default name): " << out.str() << std::endl;
  58. Logging::Log(Logging::Severity::Info, ss.str());
  59. ss.str("");
  60. ss << "----------------------------------" << std::endl;
  61. Logging::Log(Logging::Severity::Info, ss.str());
  62. ss.str("");
  63. Tribool::Tribool b;
  64. ss << "Tribool::Tribool b = " << std::boolalpha << b << std::endl;
  65. Logging::Log(Logging::Severity::Info, ss.str());
  66. b = true;
  67. b = false;
  68. b = Tribool::Tribool::Indeterminate;
  69. ss.str("");
  70. if (b)
  71. ss << "indeterminate = true" << std::endl;
  72. else if (!b)
  73. ss << "indeterminate = false" << std::endl;
  74. else
  75. ss << "indeterminate = indeterminate" << std::endl;
  76. Logging::Log(Logging::Severity::Info, ss.str());
  77. ss.setf(std::ios::boolalpha);
  78. ss.str("");
  79. Tribool::Tribool b1 = true;
  80. ss << "true || indeterminate = " << (b1 || Tribool::Tribool::Indeterminate) << std::endl;
  81. ss << "true && indeterminate = " << (b1 && Tribool::Tribool::Indeterminate) << std::endl;
  82. Logging::Log(Logging::Severity::Info, ss.str());
  83. ss.str("");
  84. Tribool::Tribool b2 = false;
  85. ss << "false || indeterminate = " << (b2 || Tribool::Tribool::Indeterminate) << std::endl;
  86. ss << "false && indeterminate = " << (b2 && Tribool::Tribool::Indeterminate) << std::endl;
  87. Logging::Log(Logging::Severity::Info, ss.str());
  88. ss.str("");
  89. Tribool::Tribool b3 = Tribool::Tribool::Indeterminate;
  90. ss << "indeterminate || indeterminate = " << (b3 || b3) << std::endl;
  91. ss << "indeterminate && indeterminate = " << (b3 && b3) << std::endl;
  92. Logging::Log(Logging::Severity::Info, ss.str());
  93. }
  94. bool TestTribool()
  95. {
  96. std::stringstream ss;
  97. ss << "----------------------------------" << std::endl;
  98. ss << "| Test::Tribool |" << std::endl;
  99. ss << "----------------------------------" << std::endl;
  100. Logging::Log(Logging::Severity::Info, ss.str());
  101. TestUtilTribool();
  102. ss.str("");
  103. ss << "==================================" << std::endl << std::endl;
  104. Logging::Log(Logging::Severity::Info, ss.str());
  105. return true;
  106. }
  107. } // namespace Test
  108. } // namespace Utilities