iutest  1.17.1.0
iutest_message.hpp
[詳解]
1 //======================================================================
2 //-----------------------------------------------------------------------
13 //-----------------------------------------------------------------------
14 //======================================================================
15 #ifndef INCG_IRIS_IUTEST_MESSAGE_HPP_0A05C876_F204_41F5_895F_F8454AB283B1_
16 #define INCG_IRIS_IUTEST_MESSAGE_HPP_0A05C876_F204_41F5_895F_F8454AB283B1_
17 
18 //======================================================================
19 // include
20 #include "../iutest_env.hpp"
21 #include "../iutest_printers.hpp"
22 
23 namespace iutest {
24 namespace detail
25 {
26 
27 //======================================================================
28 // declare
32 ::std::string FormatFileLocation(const char* file, int line);
36 ::std::string FormatCompilerIndependentFileLocation(const char* file, int line);
37 
38 //======================================================================
39 // class
43 class iuStreamMessage
44 {
45 public:
46  iuStreamMessage() {}
47  explicit iuStreamMessage(const char* message) : m_stream(message) {}
48  iuStreamMessage(const iuStreamMessage& rhs) : m_stream(rhs.GetString()) {}
49 
50 public:
51  ::std::string GetString() const { return m_stream.str(); }
52 public:
53  template<typename T>
54  iuStreamMessage& operator << (const T& value)
55  {
56 #if !defined(IUTEST_NO_ARGUMENT_DEPENDENT_LOOKUP)
57  m_stream << PrintToString(value);
58 #else
59  m_stream << value;
60 #endif
61  return *this;
62  }
63 
64 #if !defined(IUTEST_NO_ARGUMENT_DEPENDENT_LOOKUP)
65  template<typename T, size_t SIZE>
66  iuStreamMessage& operator << (const T(&value)[SIZE])
67  {
68  m_stream << PrintToString(value);
69  return *this;
70  }
71 #else
72  iuStreamMessage& operator << (bool b)
73  {
74  m_stream << (b ? "true" : "false");
75  return *this;
76  }
77 #endif
78 
79 #if IUTEST_HAS_IOMANIP
80  iuStreamMessage& operator << (iu_basic_iomanip val)
81  {
82  m_stream << val;
83  return *this;
84  }
85 #endif
86 
87 public:
91  void add_message(const char* str) { append(str); }
92 private:
93  void append(const char* str);
94 
95 private:
96  iuStreamMessage& operator = (const iuStreamMessage&);
97 
98 private:
99  iu_global_format_stringstream m_stream;
100 };
101 
102 inline iu_ostream& operator << (iu_ostream& os, const iuStreamMessage& msg)
103 {
104  return os << msg.GetString();
105 }
106 
110 class iuCodeMessage
111 {
112  ::std::string m_message;
113  const char* m_file;
114  int m_line;
115 public:
116  iuCodeMessage(const char* file, int line, const char* message)
117  : m_message(message)
118  , m_file(file ? file : kStrings::UnknownFile)
119  , m_line(line)
120  {}
121  iuCodeMessage(const char* file, int line, const iuStreamMessage& message)
122  : m_message(message.GetString())
123  , m_file(file ? file : kStrings::UnknownFile)
124  , m_line(line)
125  {}
126 public:
127  const char* message() const { return m_message.c_str(); }
128  const char* file_name() const IUTEST_CXX_NOEXCEPT_SPEC { return m_file; }
129  int line_number() const IUTEST_CXX_NOEXCEPT_SPEC { return m_line; }
130 
131 
132 public:
133  template<typename T>
134  iuCodeMessage& operator << (const T& value)
135  {
136  m_message += (iuStreamMessage() << value).GetString();
137  return *this;
138  }
139 
140 public:
144  void add_message(const ::std::string& str);
145 
146 public:
148  ::std::string make_message() const;
149  ::std::string make_newline_message() const
150  {
151  return make_message() + "\n";
152  }
153 };
154 
155 } // end of namespace detail
156 } // end of namespace iutest
157 
158 #if !IUTEST_HAS_LIB
159 # include "../impl/iutest_message.ipp"
160 #endif
161 
162 #endif // INCG_IRIS_IUTEST_MESSAGE_HPP_0A05C876_F204_41F5_895F_F8454AB283B1_
iutest_config.hpp
iris unit test config
iutest::PrintToString
std::string PrintToString(const T &v)
文字列化
Definition: iutest_printers.hpp:678
IUTEST_CXX_NOEXCEPT_SPEC
#define IUTEST_CXX_NOEXCEPT_SPEC
noexcept specification definition
Definition: iutest_compiler.hpp:734
iutest
iutest root namespace
Definition: iutest_charcode.hpp:31