xtd - Reference Guide  0.1.1
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
base_assert.h
Go to the documentation of this file.
1 #pragma once
5 
6 #include "../tunit_export.h"
7 #include "__demangle.h"
8 #include "__tunit_join__items.h"
9 #include "abort_error.h"
10 #include "assert_error.h"
12 #include "ignore_error.h"
14 
16 namespace xtd {
18  namespace tunit {
26  public:
28  base_assert() = delete;
30 
37 
45  static void abort(const xtd::diagnostics::stack_frame& stack_frame) {abort("", stack_frame);}
46 
53  static void abort(const std::string& message) {abort(message, xtd::diagnostics::stack_frame::empty());}
54 
62  static void abort(const std::string& message, const xtd::diagnostics::stack_frame& stack_frame);
63 
71 
79  static void fail(const xtd::diagnostics::stack_frame& stack_frame) {fail("", stack_frame);}
80 
88  static void fail(const std::string& message) {fail(message, xtd::diagnostics::stack_frame::empty());}
89 
98  static void fail(const std::string& message, const xtd::diagnostics::stack_frame& stack_frame) {
99  base_assert::fail("", "", message, stack_frame);
100  }
101 
108 
116  static void ignore(const xtd::diagnostics::stack_frame& stack_frame) {ignore("", stack_frame);}
117 
124  static void ignore(const std::string& message) {ignore(message, xtd::diagnostics::stack_frame::empty());}
125 
133  static void ignore(const std::string& message, const xtd::diagnostics::stack_frame& stack_frame);
134 
140  static void succeed() {succeed("", csf_);}
141 
148  static void succeed(const xtd::diagnostics::stack_frame& stack_frame) {succeed("", stack_frame);}
149 
156  static void succeed(const std::string& message) {succeed(message, csf_);}
157 
165  static void succeed(const std::string& message, const xtd::diagnostics::stack_frame& stack_frame);
166 
167  protected:
168  static void fail(const std::string& actual, const std::string& expected, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame);
169 
170  static void error();
171 
172  static void error(const std::string& actual, const std::string& expected, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame);
173 
174  template <typename value_t>
175  static std::string to_string(const value_t& value) {return __tunit_to_string(value);}
176 
177  template <typename value_t>
178  static std::string to_string(const value_t* value) {return __tunit_to_string(value);}
179 
180  template<typename collection_t>
181  static std::string join_items(const collection_t& collection) {return __tunit_join__items(collection);}
182 
183  static std::string join_items(const std::string& str) {return __tunit_join__items(str);}
184  };
185  }
186 }
Contains xtd::tunit::abort_error exception.
Contains xtd::tunit::assert_error exception.
Provides information about a xtd::diagnostics::stack_frame, which represents a function call on the c...
Definition: stack_frame.h:29
static stack_frame empty() noexcept
Return an empty stack frame.
The base class for assert.
Definition: base_assert.h:25
static void abort()
Abort current test. This is used by the other Assert functions.
Definition: base_assert.h:36
static void fail(const std::string &message)
Throws an xtd::tunit::assertion_error exception. This is used by the other Assert functions.
Definition: base_assert.h:88
static void abort(const std::string &message)
Abort current test. This is used by the other Assert functions.
Definition: base_assert.h:53
static void fail(const std::string &message, const xtd::diagnostics::stack_frame &stack_frame)
Throws an xtd::tunit::assertion_error exception. This is used by the other Assert functions.
Definition: base_assert.h:98
static void ignore()
Ignore current test. This is used by the other Assert functions.
Definition: base_assert.h:107
static void ignore(const std::string &message)
Ignore current test. This is used by the other Assert functions.
Definition: base_assert.h:124
static void succeed(const xtd::diagnostics::stack_frame &stack_frame)
Generates a success with a generic message. This is used by the other Assert functions.
Definition: base_assert.h:148
static void abort(const xtd::diagnostics::stack_frame &stack_frame)
Abort current test. This is used by the other Assert functions.
Definition: base_assert.h:45
static void ignore(const xtd::diagnostics::stack_frame &stack_frame)
Ignore current test. This is used by the other Assert functions.
Definition: base_assert.h:116
static void ignore(const std::string &message, const xtd::diagnostics::stack_frame &stack_frame)
Ignore current test. This is used by the other Assert functions.
static void succeed(const std::string &message, const xtd::diagnostics::stack_frame &stack_frame)
Generates a success with a generic message. This is used by the other Assert functions.
static void abort(const std::string &message, const xtd::diagnostics::stack_frame &stack_frame)
Abort current test. This is used by the other Assert functions.
static void fail()
Throws an xtd::tunit::assertion_error exception. This is used by the other Assert functions.
Definition: base_assert.h:70
static void succeed(const std::string &message)
Generates a success with a generic message. This is used by the other Assert functions.
Definition: base_assert.h:156
static void fail(const xtd::diagnostics::stack_frame &stack_frame)
Throws an xtd::tunit::assertion_error exception. This is used by the other Assert functions.
Definition: base_assert.h:79
static void succeed()
Generates a success with a generic message. This is used by the other Assert functions.
Definition: base_assert.h:140
Contains std::basic_ostream<char_t, char_traits_t>& operator<<(std::basic_ostream<char_t,...
#define tunit_export_
Define shared library export.
Definition: tunit_export.h:13
#define csf_
Provides information about the current stack frame.
Definition: stack_frame.h:213
std::string to_string(const value_t &value, const std::string &fmt, const std::locale &loc)
Convert a specified value into a string with specified format and locale.
Definition: to_string.h:37
Contains xtd::tunit::ignore_error exception.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition: system_report.h:17
Contains xtd::diagnostics::stack_frame class.