9
3

char_definitions.hpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * Copyright Andrey Semashev 2007 - 2015.
  3. * Distributed under the Boost Software License, Version 1.0.
  4. * (See accompanying file LICENSE_1_0.txt or copy at
  5. * http://www.boost.org/LICENSE_1_0.txt)
  6. */
  7. /*!
  8. * \file char_definitions.hpp
  9. * \author Andrey Semashev
  10. * \date 24.01.2009
  11. *
  12. * \brief This header contains common type definitions for character type dependent tests.
  13. */
  14. #ifndef BOOST_LOG_TESTS_CHAR_DEFINITIONS_HPP_INCLUDED_
  15. #define BOOST_LOG_TESTS_CHAR_DEFINITIONS_HPP_INCLUDED_
  16. #include <string>
  17. #include <iostream>
  18. #include <boost/mpl/vector.hpp>
  19. namespace mpl = boost::mpl;
  20. typedef mpl::vector<
  21. #ifdef BOOST_LOG_USE_CHAR
  22. char
  23. #endif
  24. #if defined(BOOST_LOG_USE_CHAR) && defined(BOOST_LOG_USE_WCHAR_T)
  25. ,
  26. #endif
  27. #ifdef BOOST_LOG_USE_WCHAR_T
  28. wchar_t
  29. #endif
  30. >::type char_types;
  31. template< typename >
  32. struct test_data;
  33. #ifdef BOOST_LOG_USE_CHAR
  34. template< >
  35. struct test_data< char >
  36. {
  37. static const char* abc() { return "abc"; }
  38. static const char* ABC() { return "ABC"; }
  39. static const char* some_test_string() { return "some test string"; }
  40. static const char* zero_to_five() { return "012345"; }
  41. static const char* def() { return "def"; }
  42. static const char* aaa() { return "aaa"; }
  43. static const char* abcd() { return "abcd"; }
  44. static const char* zz() { return "zz"; }
  45. static const char* abcdefg0123456789() { return "abcdefg0123456789"; }
  46. static const char* attr1() { return "attr1"; }
  47. static const char* attr2() { return "attr2"; }
  48. static const char* attr3() { return "attr3"; }
  49. static const char* attr4() { return "attr4"; }
  50. static const char* int_format1() { return "%08d"; }
  51. static const char* fp_format1() { return "%06.3f"; }
  52. };
  53. //! The function compares two strings and prints them if they are not equal
  54. inline bool equal_strings(std::string const& left, std::string const& right)
  55. {
  56. if (left != right)
  57. {
  58. std::cout << "Left: \"" << left << "\"\nRight: \"" << right << "\"" << std::endl;
  59. return false;
  60. }
  61. else
  62. return true;
  63. }
  64. #endif // BOOST_LOG_USE_CHAR
  65. #ifdef BOOST_LOG_USE_WCHAR_T
  66. template< >
  67. struct test_data< wchar_t >
  68. {
  69. static const wchar_t* abc() { return L"abc"; }
  70. static const wchar_t* ABC() { return L"ABC"; }
  71. static const wchar_t* some_test_string() { return L"some test string"; }
  72. static const wchar_t* zero_to_five() { return L"012345"; }
  73. static const wchar_t* def() { return L"def"; }
  74. static const wchar_t* aaa() { return L"aaa"; }
  75. static const wchar_t* abcd() { return L"abcd"; }
  76. static const wchar_t* zz() { return L"zz"; }
  77. static const wchar_t* abcdefg0123456789() { return L"abcdefg0123456789"; }
  78. static const char* attr1() { return "attr1"; }
  79. static const char* attr2() { return "attr2"; }
  80. static const char* attr3() { return "attr3"; }
  81. static const char* attr4() { return "attr4"; }
  82. static const wchar_t* int_format1() { return L"%08d"; }
  83. static const wchar_t* fp_format1() { return L"%06.3f"; }
  84. };
  85. //! The function compares two strings and prints them if they are not equal
  86. inline bool equal_strings(std::wstring const& left, std::wstring const& right)
  87. {
  88. if (left != right)
  89. {
  90. std::wcout << L"Left: \"" << left << L"\"\nRight: \"" << right << L"\"" << std::endl;
  91. return false;
  92. }
  93. else
  94. return true;
  95. }
  96. #endif // BOOST_LOG_USE_WCHAR_T
  97. #endif // BOOST_LOG_TESTS_CHAR_DEFINITIONS_HPP_INCLUDED_