xtd 0.2.0
Loading...
Searching...
No Matches
file_assert.h
Go to the documentation of this file.
1
4#pragma once
5#include "directory_assert.h"
6
8namespace xtd {
10 namespace tunit {
23 class tunit_export_ file_assert final : private base_assert {
24 public:
26 file_assert() = delete;
28
30
50 template<typename char_t>
51 static void are_equal(const std::basic_istream<char_t>& expected, const std::basic_istream<char_t>& actual, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {are_equal(expected, actual, xtd::string::empty_string, stack_frame);}
71 template<typename char_t>
72 static void are_equal(const std::basic_istream<char_t>& expected, const std::basic_istream<char_t>& actual, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {
73 std::basic_istream<char_t> if_expected(expected.rdbuf());
74 std::basic_istream<char_t> if_actual(actual.rdbuf());
75
76 if_expected.seekg(0, std::ios::end);
77 if_actual.seekg(0, std::ios::end);
78 size_t size_expected = static_cast<size_t>(if_expected.tellg());
79 size_t size_actual = static_cast<size_t>(if_actual.tellg());
80 if (size_expected != size_actual) {
81 fail("istream length " + to_string(size_expected), to_string(size_actual), message, stack_frame);
82 return;
83 }
84
85 if_expected.seekg(0, std::ios::beg);
86 if_actual.seekg(0, std::ios::beg);
87 for (size_t offset = 0; offset < size_actual; ++offset) {
88 char_t value_expected = static_cast<char_t>(if_expected.get());
89 char_t value_actual = static_cast<char_t>(if_actual.get());
90 if (value_expected != value_actual) {
91 fail("istream at offset " + to_string(offset) + " value " + to_string(value_expected), to_string(value_actual), message, stack_frame);
92 return;
93 }
94 }
95 assert::succeed(message, stack_frame);
96 }
115 template<typename char_t>
116 static void are_equal(const xtd::basic_string<char_t>& expected, const xtd::basic_string<char_t>& actual, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {are_equal(expected, actual, xtd::string::empty_string, stack_frame);}
136 template<typename char_t>
137 static void are_equal(const xtd::basic_string<char_t>& expected, const xtd::basic_string<char_t>& actual, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {are_equal(std::basic_ifstream<char_t>(expected), std::basic_ifstream<char_t>(actual), message, stack_frame);}
138
140 template<typename char_t>
141 static void are_equal(const xtd::basic_string<char_t>& expected, const char_t* actual, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {are_equal(expected, actual, xtd::string::empty_string, stack_frame);}
142 template<typename char_t>
143 static void are_equal(const xtd::basic_string<char_t>& expected, const char_t* actual, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {are_equal(std::basic_ifstream<char_t>(expected), std::basic_ifstream<char_t>(actual), message, stack_frame);}
144 template<typename char_t>
145 static void are_equal(const char_t* expected, const xtd::basic_string<char_t>& actual, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {are_equal(expected, actual, xtd::string::empty_string, stack_frame);}
146 template<typename char_t>
147 static void are_equal(const char_t* expected, const xtd::basic_string<char_t>& actual, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {are_equal(std::basic_ifstream<char_t>(expected), std::basic_ifstream<char_t>(actual), message, stack_frame);}
148 template<typename char_t>
149 static void are_equal(const char_t* expected, const char_t* actual, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {are_equal(expected, actual, xtd::string::empty_string, stack_frame);}
150 template<typename char_t>
151 static void are_equal(const char_t* expected, const char_t* actual, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {are_equal(std::basic_ifstream<char_t>(expected), std::basic_ifstream<char_t>(actual), message, stack_frame);}
153
172 template<typename char_t>
173 static void are_not_equal(const std::basic_istream<char_t>& expected, const std::basic_istream<char_t>& actual, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {are_not_equal(expected, actual, xtd::string::empty_string, stack_frame);}
193 template<typename char_t>
194 static void are_not_equal(const std::basic_istream<char_t>& expected, const std::basic_istream<char_t>& actual, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {
195 std::basic_istream<char_t> if_expected(expected.rdbuf());
196 std::basic_istream<char_t> if_actual(actual.rdbuf());
197
198 if_expected.seekg(0, std::ios::end);
199 if_actual.seekg(0, std::ios::end);
200 size_t size_expected = static_cast<size_t>(if_expected.tellg());
201 size_t size_actual = static_cast<size_t>(if_actual.tellg());
202 if (size_expected != size_actual) {
203 assert::succeed(message, stack_frame);
204 return;
205 }
206
207 if_expected.seekg(0, std::ios::beg);
208 if_actual.seekg(0, std::ios::beg);
209 for (size_t offset = 0; offset < size_actual; ++offset) {
210 char_t value_expected = static_cast<char_t>(if_expected.get());
211 char_t value_actual = static_cast<char_t>(if_actual.get());
212 if (value_expected != value_actual) {
213 assert::succeed(message, stack_frame);
214 return;
215 }
216 }
217 fail("not equal <" + typeof_(expected).full_name() + ">", "<" + typeof_(expected).full_name() + ">", message, stack_frame);
218 }
237 template<typename char_t>
258 template<typename char_t>
259 static void are_not_equal(const xtd::basic_string<char_t>& expected, const xtd::basic_string<char_t>& actual, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {are_not_equal(std::basic_ifstream<char_t>(expected), std::basic_ifstream<char_t>(actual), message, stack_frame);}
260
262 template<typename char_t>
263 static void are_not_equal(const xtd::basic_string<char_t>& expected, const char_t* actual, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {are_not_equal(expected, actual, xtd::string::empty_string, stack_frame);}
264 template<typename char_t>
265 static void are_not_equal(const xtd::basic_string<char_t>& expected, const char_t* actual, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {are_not_equal(std::basic_ifstream<char_t>(expected), std::basic_ifstream<char_t>(actual), message, stack_frame);}
266 template<typename char_t>
267 static void are_not_equal(const char_t* expected, const xtd::basic_string<char_t>& actual, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {are_not_equal(expected, actual, xtd::string::empty_string, stack_frame);}
268 template<typename char_t>
269 static void are_not_equal(const char_t* expected, const xtd::basic_string<char_t>& actual, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {are_not_equal(std::basic_ifstream<char_t>(expected), std::basic_ifstream<char_t>(actual), message, stack_frame);}
270 template<typename char_t>
271 static void are_not_equal(const char_t* expected, const char_t* actual, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {are_not_equal(expected, actual, xtd::string::empty_string, stack_frame);}
272 template<typename char_t>
273 static void are_not_equal(const char_t* expected, const char_t* actual, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {are_not_equal(std::basic_ifstream<char_t>(expected), std::basic_ifstream<char_t>(actual), message, stack_frame);}
275
288 template<typename char_t>
303 template<typename char_t>
304 static void does_not_exist(const xtd::basic_string<char_t>& file, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {
305 auto is = std::basic_ifstream<char_t>(file);
306 if (is.good() == true) {
307 is.close();
308 fail("not file exists", to_string(file), message, stack_frame);
309 } else
310 assert::succeed(message, stack_frame);
311 }
312
314 template<typename char_t>
315 static void does_not_exist(const char_t* file, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {does_not_exist(file, xtd::string::empty_string, stack_frame);}
316 template<typename char_t>
317 static void does_not_exist(const char_t* file, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {does_not_exist(xtd::basic_string<char_t>(file), message, stack_frame);}
319
332 template<typename char_t>
347 template<typename char_t>
348 static void exists(const xtd::basic_string<char_t>& file, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {
349 auto is = std::basic_ifstream<char_t>(file);
350 if (is.good() == false)
351 fail("file exists", to_string(file), message, stack_frame);
352 else {
353 is.close();
354 assert::succeed(message, stack_frame);
355 }
356 }
357
359 template<typename char_t>
360 static void exists(const char_t* file, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {exists(file, xtd::string::empty_string, stack_frame);}
361 template<typename char_t>
362 static void exists(const char_t* file, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) {exists(xtd::basic_string<char_t>(file), message, stack_frame);}
365 };
366 }
367}
Represents text as a sequence of character units.
Definition basic_string.h:79
static const basic_string empty_string
Represents the empty basic_string.
Definition basic_string.h:124
Provides information about a xtd::diagnostics::stack_frame, which represents a function call on the c...
Definition stack_frame.h:47
static stack_frame current(const xtd::source_location &value=xtd::source_location::current()) noexcept
Crates a new xtd::diagnostics::stack_frame object corresponding to the location of the call site.
The base class for assert.
Definition base_assert.h:29
The file_assert class contains a collection of static methods that implement the most file assertions...
Definition file_assert.h:23
static void does_not_exist(const xtd::basic_string< char_t > &file, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Asserts that file not exists.
Definition file_assert.h:289
static void are_not_equal(const std::basic_istream< char_t > &expected, const std::basic_istream< char_t > &actual, const std::string &message, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Asserts that two files are not equal.
Definition file_assert.h:194
static void are_equal(const xtd::basic_string< char_t > &expected, const xtd::basic_string< char_t > &actual, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Asserts that two files are equal.
Definition file_assert.h:116
static void are_not_equal(const std::basic_istream< char_t > &expected, const std::basic_istream< char_t > &actual, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Asserts that two files are not equal.
Definition file_assert.h:173
static void does_not_exist(const xtd::basic_string< char_t > &file, const std::string &message, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Asserts that file not exists.
Definition file_assert.h:304
static void are_not_equal(const xtd::basic_string< char_t > &expected, const xtd::basic_string< char_t > &actual, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Asserts that two files are not equal.
Definition file_assert.h:238
static void are_equal(const std::basic_istream< char_t > &expected, const std::basic_istream< char_t > &actual, const std::string &message, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Asserts that two files are equal.
Definition file_assert.h:72
static void exists(const xtd::basic_string< char_t > &file, const std::string &message, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Asserts that file exists.
Definition file_assert.h:348
static void are_equal(const std::basic_istream< char_t > &expected, const std::basic_istream< char_t > &actual, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Asserts that two files are equal.
Definition file_assert.h:51
static void exists(const xtd::basic_string< char_t > &file, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Asserts that file exists.
Definition file_assert.h:333
static void are_equal(const xtd::basic_string< char_t > &expected, const xtd::basic_string< char_t > &actual, const std::string &message, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Asserts that two files are equal.
Definition file_assert.h:137
static void are_not_equal(const xtd::basic_string< char_t > &expected, const xtd::basic_string< char_t > &actual, const std::string &message, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Asserts that two files are not equal.
Definition file_assert.h:259
Contains xtd::tunit::directory_assert class.
#define tunit_export_
Define shared library export.
Definition tunit_export.h:13
#define typeof_
Used to obtain the type object of a specified type or object.
Definition typeof.h:45
bool is(std::any value)
Checks if the result of an expression is compatible with a given type.
Definition is.h:365
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:41
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10