• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
15 #ifndef BOOST_LOG_TESTS_CHAR_DEFINITIONS_HPP_INCLUDED_
16 #define BOOST_LOG_TESTS_CHAR_DEFINITIONS_HPP_INCLUDED_
17 
18 #include <string>
19 #include <iostream>
20 #include <boost/mpl/vector.hpp>
21 
22 namespace mpl = boost::mpl;
23 
24 typedef mpl::vector<
25 #ifdef BOOST_LOG_USE_CHAR
26     char
27 #endif
28 #if defined(BOOST_LOG_USE_CHAR) && defined(BOOST_LOG_USE_WCHAR_T)
29     ,
30 #endif
31 #ifdef BOOST_LOG_USE_WCHAR_T
32     wchar_t
33 #endif
34 >::type char_types;
35 
36 template< typename >
37 struct test_data;
38 
39 
40 #ifdef BOOST_LOG_USE_CHAR
41 
42 template< >
43 struct test_data< char >
44 {
abctest_data45     static const char* abc() { return "abc"; }
ABCtest_data46     static const char* ABC() { return "ABC"; }
some_test_stringtest_data47     static const char* some_test_string() { return "some test string"; }
zero_to_fivetest_data48     static const char* zero_to_five() { return "012345"; }
deftest_data49     static const char* def() { return "def"; }
aaatest_data50     static const char* aaa() { return "aaa"; }
abcdtest_data51     static const char* abcd() { return "abcd"; }
zztest_data52     static const char* zz() { return "zz"; }
abcdefg0123456789test_data53     static const char* abcdefg0123456789() { return "abcdefg0123456789"; }
54 
attr1test_data55     static const char* attr1() { return "attr1"; }
attr2test_data56     static const char* attr2() { return "attr2"; }
attr3test_data57     static const char* attr3() { return "attr3"; }
attr4test_data58     static const char* attr4() { return "attr4"; }
59 
int_format1test_data60     static const char* int_format1() { return "%08d"; }
fp_format1test_data61     static const char* fp_format1() { return "%06.3f"; }
62 };
63 
64 //! The function compares two strings and prints them if they are not equal
equal_strings(std::string const & left,std::string const & right)65 inline bool equal_strings(std::string const& left, std::string const& right)
66 {
67     if (left != right)
68     {
69         std::cout << "Left:  \"" << left << "\"\nRight: \"" << right << "\"" << std::endl;
70         return false;
71     }
72     else
73         return true;
74 }
75 
76 #endif // BOOST_LOG_USE_CHAR
77 
78 #ifdef BOOST_LOG_USE_WCHAR_T
79 
80 template< >
81 struct test_data< wchar_t >
82 {
abctest_data83     static const wchar_t* abc() { return L"abc"; }
ABCtest_data84     static const wchar_t* ABC() { return L"ABC"; }
some_test_stringtest_data85     static const wchar_t* some_test_string() { return L"some test string"; }
zero_to_fivetest_data86     static const wchar_t* zero_to_five() { return L"012345"; }
deftest_data87     static const wchar_t* def() { return L"def"; }
aaatest_data88     static const wchar_t* aaa() { return L"aaa"; }
abcdtest_data89     static const wchar_t* abcd() { return L"abcd"; }
zztest_data90     static const wchar_t* zz() { return L"zz"; }
abcdefg0123456789test_data91     static const wchar_t* abcdefg0123456789() { return L"abcdefg0123456789"; }
92 
attr1test_data93     static const char* attr1() { return "attr1"; }
attr2test_data94     static const char* attr2() { return "attr2"; }
attr3test_data95     static const char* attr3() { return "attr3"; }
attr4test_data96     static const char* attr4() { return "attr4"; }
97 
int_format1test_data98     static const wchar_t* int_format1() { return L"%08d"; }
fp_format1test_data99     static const wchar_t* fp_format1() { return L"%06.3f"; }
100 };
101 
102 //! The function compares two strings and prints them if they are not equal
equal_strings(std::wstring const & left,std::wstring const & right)103 inline bool equal_strings(std::wstring const& left, std::wstring const& right)
104 {
105     if (left != right)
106     {
107         std::wcout << L"Left:  \"" << left << L"\"\nRight: \"" << right << L"\"" << std::endl;
108         return false;
109     }
110     else
111         return true;
112 }
113 
114 #endif // BOOST_LOG_USE_WCHAR_T
115 
116 #endif // BOOST_LOG_TESTS_CHAR_DEFINITIONS_HPP_INCLUDED_
117