xtd - Reference Guide  0.1.0
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
Loading...
Searching...
No Matches
Static Public Member Functions | List of all members
xtd::tunit::file_valid Class Referencefinal

#include <file_valid.h>

Definition

The file_valid class contains a collection of static methods that implement the most file assertions used in xtd::tUnit.

Namespace
xtd::tunit
Library
xtd.tunit
Examples
This example show how to used some methods :
#include <xtd/xtd.tunit>
#include <stdexcept>
using namespace xtd::tunit;
namespace unit_tests {
// The class test must be declared with test_class_ helper.
class test_class_(test) {
public:
void test_method_(test_case1) {
assert::is_true(true);
}
void test_method_(test_case2) {
assert::is_false(true);
}
void test_method_(test_case3) {
assert::does_not_throw([] {throw std::range_error("error");});
}
};
}
int main() {
return console_unit_test().run();
}
// This code can produce the following output:
//
// Start 3 tests from 1 test case
// Run tests:
// SUCCEED test.test_case1 (0 ms total)
// FAILED test.test_case2 (0 ms total)
// Expected: false
// But was: true
// Stack Trace: in | --OMITTED-- |/assert.cpp:14
// FAILED test.test_case3 (0 ms total)
// Expected: No Exception to be thrown
// But was: <std::range_error>
// Stack Trace: in | --OMITTED-- |/assert.cpp:18
//
// Test results:
// SUCCEED 1 test.
// FAILED 2 tests.
// End 3 tests from 1 test case ran. (0 ms total)
The console_unit_test class is console unit test interface.
Definition: console_unit_test.h:23
int run()
Runs all tests in this UnitTest object and prints the result.
Definition: unit_test.h:44
The tunit namespace contains a unit test library.
Definition: abort_error.h:11

Inherits xtd::tunit::base_assert.

Static Public Member Functions

template<typename Char >
static void are_equal (const std::basic_istream< Char > &expected, const std::basic_istream< Char > &actual)
 Validate that two files are equal.
 
template<typename Char >
static void are_equal (const std::basic_istream< Char > &expected, const std::basic_istream< Char > &actual, const std::string &message)
 Validate that two files are equal.
 
template<typename Char >
static void are_equal (const std::basic_istream< Char > &expected, const std::basic_istream< Char > &actual, const std::string &message, const xtd::diagnostics::stack_frame &stack_frame)
 Validate that two files are equal.
 
template<typename Char >
static void are_equal (const std::basic_istream< Char > &expected, const std::basic_istream< Char > &actual, const xtd::diagnostics::stack_frame &stack_frame)
 Validate that two files are equal.
 
template<typename Char >
static void are_equal (const std::basic_string< Char > &expected, const std::basic_string< Char > &actual)
 Validate that two files are equal.
 
template<typename Char >
static void are_equal (const std::basic_string< Char > &expected, const std::basic_string< Char > &actual, const std::string &message)
 Validate that two files are equal.
 
template<typename Char >
static void are_equal (const std::basic_string< Char > &expected, const std::basic_string< Char > &actual, const std::string &message, const xtd::diagnostics::stack_frame &stack_frame)
 Validate that two files are equal.
 
template<typename Char >
static void are_equal (const std::basic_string< Char > &expected, const std::basic_string< Char > &actual, const xtd::diagnostics::stack_frame &stack_frame)
 Validate that two files are equal.
 
template<typename Char >
static void are_not_equal (const std::basic_istream< Char > &expected, const std::basic_istream< Char > &actual)
 Validate that two files are not equal.
 
template<typename Char >
static void are_not_equal (const std::basic_istream< Char > &expected, const std::basic_istream< Char > &actual, const std::string &message)
 Validate that two files are not equal.
 
template<typename Char >
static void are_not_equal (const std::basic_istream< Char > &expected, const std::basic_istream< Char > &actual, const std::string &message, const xtd::diagnostics::stack_frame &stack_frame)
 Validate that two files are not equal.
 
template<typename Char >
static void are_not_equal (const std::basic_istream< Char > &expected, const std::basic_istream< Char > &actual, const xtd::diagnostics::stack_frame &stack_frame)
 Validate that two files are not equal.
 
template<typename Char >
static void are_not_equal (const std::basic_string< Char > &expected, const std::basic_string< Char > &actual)
 Validate that two files are not equal.
 
template<typename Char >
static void are_not_equal (const std::basic_string< Char > &expected, const std::basic_string< Char > &actual, const std::string &message)
 Validate that two files are not equal.
 
template<typename Char >
static void are_not_equal (const std::basic_string< Char > &expected, const std::basic_string< Char > &actual, const std::string &message, const xtd::diagnostics::stack_frame &stack_frame)
 Validate that two files are not equal.
 
template<typename Char >
static void are_not_equal (const std::basic_string< Char > &expected, const std::basic_string< Char > &actual, const xtd::diagnostics::stack_frame &stack_frame)
 Validate that two files are not equal.
 
template<typename Char >
static void does_not_exist (const std::basic_string< Char > &file)
 Validate that file not exists.
 
template<typename Char >
static void does_not_exist (const std::basic_string< Char > &file, const std::string &message)
 Validate that file not exists.
 
template<typename Char >
static void does_not_exist (const std::basic_string< Char > &file, const std::string &message, const xtd::diagnostics::stack_frame &stack_frame)
 Validate that file not exists.
 
template<typename Char >
static void does_not_exist (const std::basic_string< Char > &file, const xtd::diagnostics::stack_frame &stack_frame)
 Validate that file not exists.
 
template<typename Char >
static void exists (const std::basic_string< Char > &file)
 Validate that file exists.
 
template<typename Char >
static void exists (const std::basic_string< Char > &file, const std::string &message)
 Validate that file exists.
 
template<typename Char >
static void exists (const std::basic_string< Char > &file, const std::string &message, const xtd::diagnostics::stack_frame &stack_frame)
 Validate that file exists.
 
template<typename Char >
static void exists (const std::basic_string< Char > &file, const xtd::diagnostics::stack_frame &stack_frame)
 Validate that file exists.
 

Member Function Documentation

◆ are_equal() [1/8]

template<typename Char >
static void xtd::tunit::file_valid::are_equal ( const std::basic_istream< Char > &  expected,
const std::basic_istream< Char > &  actual 
)
inlinestatic

Validate that two files are equal.

Parameters
expectedthe expected value.
actualthe actual value.
Examples
std::stringstream s1;
s1 << "Test";
s1.seekg(0, std::ios::beg);
std::stringstream s2;
s2 << "Test";
s2.seekg(0, std::ios::beg);
s2 << "Test2";
s2.seekg(0, std::ios::beg);
xtd::tunit::file_valid::are_equal(s2, s1); // test fails
static void are_equal(const std::basic_istream< Char > &expected, const std::basic_istream< Char > &actual)
Validate that two files are equal.
Definition: file_valid.h:44

◆ are_equal() [2/8]

template<typename Char >
static void xtd::tunit::file_valid::are_equal ( const std::basic_istream< Char > &  expected,
const std::basic_istream< Char > &  actual,
const std::string &  message 
)
inlinestatic

Validate that two files are equal.

Parameters
expectedthe expected value.
actualthe actual value.
messageA user message to display if the assertion fails. This message can be seen in the unit test results.
Examples
std::stringstream s1;
s1 << "Test";
s1.seekg(0, std::ios::beg);
std::stringstream s2;
s2 << "Test";
s2.seekg(0, std::ios::beg);
xtd::tunit::file_valid::are_equal(s2, s1, "User message..."); // test ok.
s2 << "Test2";
s2.seekg(0, std::ios::beg);
xtd::tunit::file_valid::are_equal(s2, s1, "User message..."); // test fails

◆ are_equal() [3/8]

template<typename Char >
static void xtd::tunit::file_valid::are_equal ( const std::basic_istream< Char > &  expected,
const std::basic_istream< Char > &  actual,
const std::string &  message,
const xtd::diagnostics::stack_frame stack_frame 
)
inlinestatic

Validate that two files are equal.

Parameters
expectedthe expected value.
actualthe actual value.
messageA user message to display if the assertion fails. This message can be seen in the unit test results.
stack_frameContains information about current file and current line.
Examples
std::stringstream s1;
s1 << "Test";
s1.seekg(0, std::ios::beg);
std::stringstream s2;
s2 << "Test";
s2.seekg(0, std::ios::beg);
xtd::tunit::file_valid::are_equal(s2, s1, "User message...", csf_); // test ok.
s2 << "Test2";
s2.seekg(0, std::ios::beg);
xtd::tunit::file_valid::are_equal(s2, s1, "User message...", csf_); // test fails
#define csf_
Provides information about the current stack frame.
Definition: stack_frame.h:213

◆ are_equal() [4/8]

template<typename Char >
static void xtd::tunit::file_valid::are_equal ( const std::basic_istream< Char > &  expected,
const std::basic_istream< Char > &  actual,
const xtd::diagnostics::stack_frame stack_frame 
)
inlinestatic

Validate that two files are equal.

Parameters
expectedthe expected value.
actualthe actual value.
stack_frameContains information about current file and current line.
Examples
std::stringstream s1;
s1 << "Test";
s1.seekg(0, std::ios::beg);
std::stringstream s2;
s2 << "Test";
s2.seekg(0, std::ios::beg);
s2 << "Test2";
s2.seekg(0, std::ios::beg);
xtd::tunit::file_valid::are_equal(s2, s1, csf_); // test fails

◆ are_equal() [5/8]

template<typename Char >
static void xtd::tunit::file_valid::are_equal ( const std::basic_string< Char > &  expected,
const std::basic_string< Char > &  actual 
)
inlinestatic

Validate that two files are equal.

Parameters
expectedthe expected value.
actualthe actual value.
Examples
std::stringstream s1;
s1 << "Test";
s1.seekg(0, std::ios::beg);
std::stringstream s2;
s2 << "Test";
s2.seekg(0, std::ios::beg);
s2 << "Test2";
s2.seekg(0, std::ios::beg);
xtd::tunit::file_valid::are_equal(s2, s1); // test fails

◆ are_equal() [6/8]

template<typename Char >
static void xtd::tunit::file_valid::are_equal ( const std::basic_string< Char > &  expected,
const std::basic_string< Char > &  actual,
const std::string &  message 
)
inlinestatic

Validate that two files are equal.

Parameters
expectedthe expected value.
actualthe actual value.
messageA user message to display if the assertion fails. This message can be seen in the unit test results.
Examples
std::stringstream s1;
s1 << "Test";
s1.seekg(0, std::ios::beg);
std::stringstream s2;
s2 << "Test";
s2.seekg(0, std::ios::beg);
xtd::tunit::file_valid::are_equal(s2, s1, "User message..."); // test ok.
s2 << "Test2";
s2.seekg(0, std::ios::beg);
xtd::tunit::file_valid::are_equal(s2, s1, "User message..."); // test fails

◆ are_equal() [7/8]

template<typename Char >
static void xtd::tunit::file_valid::are_equal ( const std::basic_string< Char > &  expected,
const std::basic_string< Char > &  actual,
const std::string &  message,
const xtd::diagnostics::stack_frame stack_frame 
)
inlinestatic

Validate that two files are equal.

Parameters
expectedthe expected value.
actualthe actual value.
messageA user message to display if the assertion fails. This message can be seen in the unit test results.
stack_frameContains information about current file and current line.
Examples
std::stringstream s1;
s1 << "Test";
s1.seekg(0, std::ios::beg);
std::stringstream s2;
s2 << "Test";
s2.seekg(0, std::ios::beg);
xtd::tunit::file_valid::are_equal(s2, s1, "User message...", csf_); // test ok.
s2 << "Test2";
s2.seekg(0, std::ios::beg);
xtd::tunit::file_valid::are_equal(s2, s1, "User message...", csf_); // test fails

◆ are_equal() [8/8]

template<typename Char >
static void xtd::tunit::file_valid::are_equal ( const std::basic_string< Char > &  expected,
const std::basic_string< Char > &  actual,
const xtd::diagnostics::stack_frame stack_frame 
)
inlinestatic

Validate that two files are equal.

Parameters
expectedthe expected value.
actualthe actual value.
stack_frameContains information about current file and current line.
Examples
std::stringstream s1;
s1 << "Test";
s1.seekg(0, std::ios::beg);
std::stringstream s2;
s2 << "Test";
s2.seekg(0, std::ios::beg);
s2 << "Test2";
s2.seekg(0, std::ios::beg);
xtd::tunit::file_valid::are_equal(s2, s1, csf_); // test fails

◆ are_not_equal() [1/8]

template<typename Char >
static void xtd::tunit::file_valid::are_not_equal ( const std::basic_istream< Char > &  expected,
const std::basic_istream< Char > &  actual 
)
inlinestatic

Validate that two files are not equal.

Parameters
expectedthe expected value.
actualthe actual value.
Examples
std::stringstream s1;
s1 << "Test";
s1.seekg(0, std::ios::beg);
std::stringstream s2;
s2 << "Test2";
s2.seekg(0, std::ios::beg);
s2 << "Test";
s2.seekg(0, std::ios::beg);
static void are_not_equal(const std::basic_istream< Char > &expected, const std::basic_istream< Char > &actual)
Validate that two files are not equal.
Definition: file_valid.h:237

◆ are_not_equal() [2/8]

template<typename Char >
static void xtd::tunit::file_valid::are_not_equal ( const std::basic_istream< Char > &  expected,
const std::basic_istream< Char > &  actual,
const std::string &  message 
)
inlinestatic

Validate that two files are not equal.

Parameters
expectedthe expected value.
actualthe actual value.
messageA user message to display if the assertion fails. This message can be seen in the unit test results.
Examples
std::stringstream s1;
s1 << "Test";
s1.seekg(0, std::ios::beg);
std::stringstream s2;
s2 << "Test2";
s2.seekg(0, std::ios::beg);
xtd::tunit::file_valid::are_not_equal(s2, s1, "User message..."); // test ok.
s2 << "Test";
s2.seekg(0, std::ios::beg);
xtd::tunit::file_valid::are_not_equal(s2, s1, "User message..."); // test fails

◆ are_not_equal() [3/8]

template<typename Char >
static void xtd::tunit::file_valid::are_not_equal ( const std::basic_istream< Char > &  expected,
const std::basic_istream< Char > &  actual,
const std::string &  message,
const xtd::diagnostics::stack_frame stack_frame 
)
inlinestatic

Validate that two files are not equal.

Parameters
expectedthe expected value.
actualthe actual value.
messageA user message to display if the assertion fails. This message can be seen in the unit test results.
stack_frameContains information about current file and current line.
Examples
std::stringstream s1;
s1 << "Test";
s1.seekg(0, std::ios::beg);
std::stringstream s2;
s2 << "Test2";
s2.seekg(0, std::ios::beg);
xtd::tunit::file_valid::are_not_equal(s2, s1, "User message...", csf_); // test ok.
s2 << "Test";
s2.seekg(0, std::ios::beg);
xtd::tunit::file_valid::are_not_equal(s2, s1, "User message...", csf_); // test fails

◆ are_not_equal() [4/8]

template<typename Char >
static void xtd::tunit::file_valid::are_not_equal ( const std::basic_istream< Char > &  expected,
const std::basic_istream< Char > &  actual,
const xtd::diagnostics::stack_frame stack_frame 
)
inlinestatic

Validate that two files are not equal.

Parameters
expectedthe expected value.
actualthe actual value.
stack_frameContains information about current file and current line.
Examples
std::stringstream s1;
s1 << "Test";
s1.seekg(0, std::ios::beg);
std::stringstream s2;
s2 << "Test2";
s2.seekg(0, std::ios::beg);
s2 << "Test";
s2.seekg(0, std::ios::beg);

◆ are_not_equal() [5/8]

template<typename Char >
static void xtd::tunit::file_valid::are_not_equal ( const std::basic_string< Char > &  expected,
const std::basic_string< Char > &  actual 
)
inlinestatic

Validate that two files are not equal.

Parameters
expectedthe expected value.
actualthe actual value.
Examples
std::stringstream s1;
s1 << "Test";
s1.seekg(0, std::ios::beg);
std::stringstream s2;
s2 << "Test2";
s2.seekg(0, std::ios::beg);
s2 << "Test";
s2.seekg(0, std::ios::beg);

◆ are_not_equal() [6/8]

template<typename Char >
static void xtd::tunit::file_valid::are_not_equal ( const std::basic_string< Char > &  expected,
const std::basic_string< Char > &  actual,
const std::string &  message 
)
inlinestatic

Validate that two files are not equal.

Parameters
expectedthe expected value.
actualthe actual value.
messageA user message to display if the assertion fails. This message can be seen in the unit test results.
Examples
std::stringstream s1;
s1 << "Test";
s1.seekg(0, std::ios::beg);
std::stringstream s2;
s2 << "Test2";
s2.seekg(0, std::ios::beg);
xtd::tunit::file_valid::are_not_equal(s2, s1, "User message..."); // test ok.
s2 << "Test";
s2.seekg(0, std::ios::beg);
xtd::tunit::file_valid::are_not_equal(s2, s1, "User message..."); // test fails

◆ are_not_equal() [7/8]

template<typename Char >
static void xtd::tunit::file_valid::are_not_equal ( const std::basic_string< Char > &  expected,
const std::basic_string< Char > &  actual,
const std::string &  message,
const xtd::diagnostics::stack_frame stack_frame 
)
inlinestatic

Validate that two files are not equal.

Parameters
expectedthe expected value.
actualthe actual value.
messageA user message to display if the assertion fails. This message can be seen in the unit test results.
stack_frameContains information about current file and current line.
Examples
std::stringstream s1;
s1 << "Test";
s1.seekg(0, std::ios::beg);
std::stringstream s2;
s2 << "Test2";
s2.seekg(0, std::ios::beg);
xtd::tunit::file_valid::are_not_equal(s2, s1, "User message...", csf_); // test ok.
s2 << "Test";
s2.seekg(0, std::ios::beg);
xtd::tunit::file_valid::are_not_equal(s2, s1, "User message...", csf_); // test fails

◆ are_not_equal() [8/8]

template<typename Char >
static void xtd::tunit::file_valid::are_not_equal ( const std::basic_string< Char > &  expected,
const std::basic_string< Char > &  actual,
const xtd::diagnostics::stack_frame stack_frame 
)
inlinestatic

Validate that two files are not equal.

Parameters
expectedthe expected value.
actualthe actual value.
stack_frameContains information about current file and current line.
Examples
std::stringstream s1;
s1 << "Test";
s1.seekg(0, std::ios::beg);
std::stringstream s2;
s2 << "Test2";
s2.seekg(0, std::ios::beg);
s2 << "Test";
s2.seekg(0, std::ios::beg);

◆ does_not_exist() [1/4]

template<typename Char >
static void xtd::tunit::file_valid::does_not_exist ( const std::basic_string< Char > &  file)
inlinestatic

Validate that file not exists.

Parameters
expectedthe expected value.
actualthe actual value.
Examples
std::ifstream f1("Test1.txt");
f1.close();
xtd::tunit::file_valid::does_not_exist("Test2.txt"); // test ok.
xtd::tunit::file_valid::does_not_exist("Test1.txt"); // test fails
static void does_not_exist(const std::basic_string< Char > &file)
Validate that file not exists.
Definition: file_valid.h:497
@ f1
The F1 key.

◆ does_not_exist() [2/4]

template<typename Char >
static void xtd::tunit::file_valid::does_not_exist ( const std::basic_string< Char > &  file,
const std::string &  message 
)
inlinestatic

Validate that file not exists.

Parameters
expectedthe expected value.
actualthe actual value.
messageA user message to display if the assertion fails. This message can be seen in the unit test results.
Examples
std::ifstream f1("Test1.txt");
f1.close();
xtd::tunit::file_valid::does_not_exist("Test2.txt", "User message..."); // test ok.
xtd::tunit::file_valid::does_not_exist("Test1.txt", "User message..."); // test fails

◆ does_not_exist() [3/4]

template<typename Char >
static void xtd::tunit::file_valid::does_not_exist ( const std::basic_string< Char > &  file,
const std::string &  message,
const xtd::diagnostics::stack_frame stack_frame 
)
inlinestatic

Validate that file not exists.

Parameters
expectedthe expected value.
actualthe actual value.
messageA user message to display if the assertion fails. This message can be seen in the unit test results.
stack_frameContains information about current file and current line.
Examples
std::ifstream f1("Test1.txt");
f1.close();
xtd::tunit::file_valid::does_not_exist("Test2.txt" "User message...", csf_); // test ok.
xtd::tunit::file_valid::does_not_exist("Test1.txt", "User message...", csf_); // test fails

◆ does_not_exist() [4/4]

template<typename Char >
static void xtd::tunit::file_valid::does_not_exist ( const std::basic_string< Char > &  file,
const xtd::diagnostics::stack_frame stack_frame 
)
inlinestatic

Validate that file not exists.

Parameters
expectedthe expected value.
actualthe actual value.
stack_frameContains information about current file and current line.
Examples
std::ifstream f1("Test1.txt");
f1.close();
xtd::tunit::file_valid::does_not_exist("Test2.txt", csf_); // test ok.
xtd::tunit::file_valid::does_not_exist("Test1.txt", csf_); // test fails

◆ exists() [1/4]

template<typename Char >
static void xtd::tunit::file_valid::exists ( const std::basic_string< Char > &  file)
inlinestatic

Validate that file exists.

Parameters
expectedthe expected value.
actualthe actual value.
Examples
std::ifstream f1("Test1.txt");
f1.close();
xtd::tunit::file_valid::exists("Test1.txt"); // test ok.
xtd::tunit::file_valid::exists("Test2.txt"); // test fails
static void exists(const std::basic_string< Char > &file)
Validate that file exists.
Definition: file_valid.h:424

◆ exists() [2/4]

template<typename Char >
static void xtd::tunit::file_valid::exists ( const std::basic_string< Char > &  file,
const std::string &  message 
)
inlinestatic

Validate that file exists.

Parameters
expectedthe expected value.
actualthe actual value.
messageA user message to display if the assertion fails. This message can be seen in the unit test results.
Examples
std::ifstream f1("Test1.txt");
f1.close();
xtd::tunit::file_valid::exists("Test1.txt", "User message..."); // test ok.
xtd::tunit::file_valid::exists("Test2.txt", "User message..."); // test fails

◆ exists() [3/4]

template<typename Char >
static void xtd::tunit::file_valid::exists ( const std::basic_string< Char > &  file,
const std::string &  message,
const xtd::diagnostics::stack_frame stack_frame 
)
inlinestatic

Validate that file exists.

Parameters
expectedthe expected value.
actualthe actual value.
messageA user message to display if the assertion fails. This message can be seen in the unit test results.
stack_frameContains information about current file and current line.
Examples
std::ifstream f1("Test1.txt");
f1.close();
xtd::tunit::file_valid::exists("Test1.txt" "User message...", csf_); // test ok.
xtd::tunit::file_valid::exists("Test2.txt", "User message...", csf_); // test fails

◆ exists() [4/4]

template<typename Char >
static void xtd::tunit::file_valid::exists ( const std::basic_string< Char > &  file,
const xtd::diagnostics::stack_frame stack_frame 
)
inlinestatic

Validate that file exists.

Parameters
expectedthe expected value.
actualthe actual value.
stack_frameContains information about current file and current line.
Examples
std::ifstream f1("Test1.txt");
f1.close();
xtd::tunit::file_valid::exists("Test1.txt", csf_); // test ok.
xtd::tunit::file_valid::exists("Test2.txt", csf_); // test fails

The documentation for this class was generated from the following file: