From 7dd8e78ae04b1e0a9d7a2e504b822f97d5593b82 Mon Sep 17 00:00:00 2001 From: Gammasoft Date: Sat, 2 Nov 2024 20:47:47 +0100 Subject: [PATCH] Review xtd::io::file_load_exception --- src/xtd.core/CMakeLists.txt | 1 + .../include/xtd/io/file_load_exception.h | 68 +++-- .../src/xtd/io/file_load_exception.cpp | 49 ++++ .../io/tests/file_load_exception_tests.cpp | 244 +++++++++++++++++- 4 files changed, 335 insertions(+), 27 deletions(-) create mode 100644 src/xtd.core/src/xtd/io/file_load_exception.cpp diff --git a/src/xtd.core/CMakeLists.txt b/src/xtd.core/CMakeLists.txt index 54600fb8c37..918aa9a0fa7 100644 --- a/src/xtd.core/CMakeLists.txt +++ b/src/xtd.core/CMakeLists.txt @@ -1114,6 +1114,7 @@ add_sources( src/xtd/io/directory_not_found_exception.cpp src/xtd/io/file.cpp src/xtd/io/file_info.cpp + src/xtd/io/file_load_exception.cpp src/xtd/io/file_not_found_exception.cpp src/xtd/io/file_system_info.cpp src/xtd/io/drive_info.cpp diff --git a/src/xtd.core/include/xtd/io/file_load_exception.h b/src/xtd.core/include/xtd/io/file_load_exception.h index 4efd65f7730..7cac6bc307a 100644 --- a/src/xtd.core/include/xtd/io/file_load_exception.h +++ b/src/xtd.core/include/xtd/io/file_load_exception.h @@ -32,67 +32,87 @@ namespace xtd { /// @name Public Constructors /// @{ - /// @brief Create a new instance of class file_load_exception + /// @brief Create a new instance of class xtd::io::file_load_exception /// @param stack_frame (optional) Contains current stack frame about member name, file path and line number in the file where the exception is occurred. Typically xtd::diagnostics::stack_frame::current(). /// @remarks Message is set with the default message associate to the exception. - explicit file_load_exception(const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) : io_exception(default_message(), stack_frame) {} - /// @brief Create a new instance of class file_load_exception + explicit file_load_exception(const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()); + /// @brief Create a new instance of class xtd::io::file_load_exception /// @param message Message string associate to the exception. /// @param stack_frame (optional) Contains current stack frame about member name, file path and line number in the file where the exception is occurred. Typically xtd::diagnostics::stack_frame::current(). - explicit file_load_exception(const xtd::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) : io_exception(message, stack_frame) {} - /// @brief Create a new instance of class file_load_exception + explicit file_load_exception(const xtd::optional& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()); + /// @brief Create a new instance of class xtd::io::file_load_exception + /// @param message Message string associate to the exception. + /// @param inner_exception The exception that is the cause of the current exception. + /// @param stack_frame (optional) Contains current stack frame about member name, file path and line number in the file where the exception is occurred. Typically xtd::diagnostics::stack_frame::current(). + template + file_load_exception(const xtd::optional& message, const exception_t& inner_exception, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) : io_exception(message, inner_exception, stack_frame) {error_code(h_result::make_error_code(h_result::COR_E_FILELOAD));} + + /// @brief Create a new instance of class xtd::io::file_load_exception /// @param message Message string associate to the exception. /// @param error Error code associate to the exception. /// @param stack_frame (optional) Contains current stack frame about member name, file path and line number in the file where the exception is occurred. Typically xtd::diagnostics::stack_frame::current(). - explicit file_load_exception(const xtd::string& message, const std::error_code& error, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) : io_exception(message, error, stack_frame) {} - /// @brief Create a new instance of class file_load_exception + /// @deprecated Use xtd::io::file_load_exception (const xtd::string& message, const xtd::diagnostics::stack_frame& stack_frame) and manually set the property xtd::exception::error_code - Will be removed in version 0.4.0. + [[deprecated("Use xtd::io::file_load_exception (const xtd::string& message, const xtd::diagnostics::stack_frame& stack_frame) and manually set the property xtd::exception::error_code - Will be removed in version 0.4.0.")]] + explicit file_load_exception(const xtd::string& message, const std::error_code& error, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()); + /// @brief Create a new instance of class xtd::io::file_load_exception /// @param message Message string associate to the exception. /// @param help_link Help link string associate to the exception. /// @param stack_frame (optional) Contains current stack frame about member name, file path and line number in the file where the exception is occurred. Typically xtd::diagnostics::stack_frame::current(). - explicit file_load_exception(const xtd::string& message, const xtd::string& help_link, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) : io_exception(message, help_link, stack_frame) {} - /// @brief Create a new instance of class file_load_exception + /// @deprecated Use xtd::io::file_load_exception (const xtd::string& message, const xtd::diagnostics::stack_frame& stack_frame) and manually set the property xtd::exception::help_link - Will be removed in version 0.4.0. + [[deprecated("Use xtd::io::file_load_exception (const xtd::string& message, const xtd::diagnostics::stack_frame& stack_frame) and manually set the property xtd::exception::help_link - Will be removed in version 0.4.0.")]] + explicit file_load_exception(const xtd::string& message, const xtd::string& help_link, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()); + /// @brief Create a new instance of class xtd::io::file_load_exception /// @param message Message string associate to the exception. /// @param error Error code associate to the exception. /// @param help_link Help link string associate to the exception. - explicit file_load_exception(const xtd::string& message, const std::error_code& error, const xtd::string& help_link, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) : io_exception(message, error, help_link, stack_frame) {} - /// @brief Create a new instance of class file_load_exception + /// @param stack_frame (optional) Contains current stack frame about member name, file path and line number in the file where the exception is occurred. Typically xtd::diagnostics::stack_frame::current(). + /// @deprecated Use xtd::io::file_load_exception (const xtd::string& message, const xtd::diagnostics::stack_frame& stack_frame) and manually set the properties xtd::exception::error_code and xtd::exception::help_link - Will be removed in version 0.4.0. + [[deprecated("Use xtd::io::file_load_exception (const xtd::string& message, const xtd::diagnostics::stack_frame& stack_frame) and manually set the properties xtd::exception::error_code and xtd::exception::help_link - Will be removed in version 0.4.0.")]] + explicit file_load_exception(const xtd::string& message, const std::error_code& error, const xtd::string& help_link, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()); + /// @brief Create a new instance of class xtd::io::file_load_exception /// @param inner_exception The exception that is the cause of the current exception. /// @param stack_frame (optional) Contains current stack frame about member name, file path and line number in the file where the exception is occurred. Typically xtd::diagnostics::stack_frame::current(). /// @remarks Message is set with the default message associate to the exception. - explicit file_load_exception(const std::exception& inner_exception, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) : io_exception(default_message(), inner_exception, stack_frame) {} - /// @brief Create a new instance of class file_load_exception + /// @deprecated Use xtd::io::file_load_exception (const xtd::string& message, const exception_t& inner_exception, const xtd::diagnostics::stack_frame& stack_frame) - Will be removed in version 0.4.0. + [[deprecated("Use xtd::io::file_load_exception (const xtd::string& message, const exception_t& inner_exception, const xtd::diagnostics::stack_frame& stack_frame) - Will be removed in version 0.4.0.")]] + explicit file_load_exception(const std::exception& inner_exception, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()); + /// @brief Create a new instance of class xtd::io::file_load_exception /// @param message Message string associate to the exception. /// @param inner_exception The exception that is the cause of the current exception. /// @param stack_frame (optional) Contains current stack frame about member name, file path and line number in the file where the exception is occurred. Typically xtd::diagnostics::stack_frame::current(). - explicit file_load_exception(const xtd::string& message, const std::exception& inner_exception, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) : io_exception(message, inner_exception, stack_frame) {} - /// @brief Create a new instance of class file_load_exception + /// @deprecated Use xtd::io::file_load_exception (const xtd::string& message, const exception_t& inner_exception, const xtd::diagnostics::stack_frame& stack_frame) - Will be removed in version 0.4.0. + [[deprecated("Use xtd::io::file_load_exception (const xtd::string& message, const exception_t& inner_exception, const xtd::diagnostics::stack_frame& stack_frame) - Will be removed in version 0.4.0.")]] + explicit file_load_exception(const xtd::string& message, const std::exception& inner_exception, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()); + /// @brief Create a new instance of class xtd::io::file_load_exception /// @param message Message string associate to the exception. /// @param inner_exception The exception that is the cause of the current exception. /// @param error Error code associate to the exception. /// @param stack_frame (optional) Contains current stack frame about member name, file path and line number in the file where the exception is occurred. Typically xtd::diagnostics::stack_frame::current(). - explicit file_load_exception(const xtd::string& message, const std::exception& inner_exception, const std::error_code& error, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) : io_exception(message, inner_exception, error, stack_frame) {} - /// @brief Create a new instance of class file_load_exception + /// @deprecated Use xtd::io::file_load_exception (const xtd::string& message, const exception_t& inner_exception, const xtd::diagnostics::stack_frame& stack_frame) and manually set the property xtd::exception::error_code - Will be removed in version 0.4.0. + [[deprecated("Use xtd::io::file_load_exception (const xtd::string& message, const exception_t& inner_exception, const xtd::diagnostics::stack_frame& stack_frame) and manually set the property xtd::exception::error_code - Will be removed in version 0.4.0.")]] + explicit file_load_exception(const xtd::string& message, const std::exception& inner_exception, const std::error_code& error, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()); + /// @brief Create a new instance of class xtd::io::file_load_exception /// @param message Message string associate to the exception. /// @param inner_exception The exception that is the cause of the current exception. /// @param help_link Help link string associate to the exception. /// @param stack_frame (optional) Contains current stack frame about member name, file path and line number in the file where the exception is occurred. Typically xtd::diagnostics::stack_frame::current(). - explicit file_load_exception(const xtd::string& message, const std::exception& inner_exception, const xtd::string& help_link, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) : io_exception(message, inner_exception, help_link, stack_frame) {} - /// @brief Create a new instance of class file_load_exception + /// @deprecated Use xtd::io::file_load_exception (const xtd::string& message, const exception_t& inner_exception, const xtd::diagnostics::stack_frame& stack_frame) and manually set the property xtd::exception::help_link - Will be removed in version 0.4.0. + [[deprecated("Use xtd::io::file_load_exception (const xtd::string& message, const exception_t& inner_exception, const xtd::diagnostics::stack_frame& stack_frame) and manually set the property xtd::exception::help_link - Will be removed in version 0.4.0.")]] + explicit file_load_exception(const xtd::string& message, const std::exception& inner_exception, const xtd::string& help_link, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()); + /// @brief Create a new instance of class xtd::io::file_load_exception /// @param message Message string associate to the exception. /// @param inner_exception The exception that is the cause of the current exception. /// @param error Error code associate to the exception. /// @param help_link Help link string associate to the exception. /// @param stack_frame (optional) Contains current stack frame about member name, file path and line number in the file where the exception is occurred. Typically xtd::diagnostics::stack_frame::current(). - explicit file_load_exception(const xtd::string& message, const std::exception& inner_exception, const std::error_code& error, const xtd::string& help_link, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()) : io_exception(message, inner_exception, error, help_link, stack_frame) {} + /// @deprecated Use xtd::io::file_load_exception (const xtd::string& message, const exception_t& inner_exception, const xtd::diagnostics::stack_frame& stack_frame) and manually set the properties xtd::exception::error_code and xtd::exception::help_link - Will be removed in version 0.4.0. + [[deprecated("Use xtd::io::file_load_exception (const xtd::string& message, const exception_t& inner_exception, const xtd::diagnostics::stack_frame& stack_frame) and manually set the properties xtd::exception::error_code and xtd::exception::help_link - Will be removed in version 0.4.0.")]] + explicit file_load_exception(const xtd::string& message, const std::exception& inner_exception, const std::error_code& error, const xtd::string& help_link, const xtd::diagnostics::stack_frame&stack_frame = null); /// @} - /// @cond file_load_exception(const file_load_exception&) = default; file_load_exception& operator =(const file_load_exception&) = default; /// @endcond - - private: - const char* default_message() const noexcept {return "Could not load the specified file."_t;} }; } } diff --git a/src/xtd.core/src/xtd/io/file_load_exception.cpp b/src/xtd.core/src/xtd/io/file_load_exception.cpp new file mode 100644 index 00000000000..b229112dd3f --- /dev/null +++ b/src/xtd.core/src/xtd/io/file_load_exception.cpp @@ -0,0 +1,49 @@ +#include "../../../include/xtd/io/file_load_exception.h" + +using namespace xtd; +using namespace xtd::diagnostics; +using namespace xtd::io; + +file_load_exception::file_load_exception(const stack_frame& stack_frame) : io_exception(stack_frame) { + error_code(h_result::make_error_code(h_result::COR_E_FILELOAD)); +} + +file_load_exception::file_load_exception(const optional& message, const stack_frame& stack_frame) : io_exception(message, stack_frame) { + error_code(h_result::make_error_code(h_result::COR_E_FILELOAD)); +} + +file_load_exception::file_load_exception(const string& message, const std::error_code& error, const stack_frame& stack_frame) : io_exception(message, stack_frame) { + error_code(error); +} + +file_load_exception::file_load_exception(const string& message, const string& help_link, const stack_frame& stack_frame) : io_exception(message, stack_frame) { + error_code(h_result::make_error_code(h_result::COR_E_FILELOAD)); + this->help_link(help_link); +} + +file_load_exception::file_load_exception(const string& message, const std::error_code& error, const string& help_link, const stack_frame& stack_frame) : io_exception(message, stack_frame) { + error_code(error); + this->help_link(help_link); +} + +file_load_exception::file_load_exception(const std::exception& inner_exception, const stack_frame& stack_frame) : io_exception(stack_frame) { + error_code(h_result::make_error_code(h_result::COR_E_FILELOAD)); +} + +file_load_exception::file_load_exception(const string& message, const std::exception& inner_exception, const stack_frame& stack_frame) : io_exception(message, stack_frame) { + error_code(h_result::make_error_code(h_result::COR_E_FILELOAD)); +} + +file_load_exception::file_load_exception(const string& message, const std::exception& inner_exception, const std::error_code& error, const stack_frame& stack_frame) : io_exception(message, stack_frame) { + error_code(error); +} + +file_load_exception::file_load_exception(const string& message, const std::exception& inner_exception, const string& help_link, const stack_frame& stack_frame) : io_exception(message, stack_frame) { + error_code(h_result::make_error_code(h_result::COR_E_FILELOAD)); + this->help_link(help_link); +} + +file_load_exception::file_load_exception(const string& message, const std::exception& inner_exception, const std::error_code& error, const string& help_link, const xtd::diagnostics::stack_frame& stack_frame) : io_exception(message, stack_frame) { + error_code(error); + this->help_link(help_link); +} diff --git a/tests/xtd.core.unit_tests/src/xtd/io/tests/file_load_exception_tests.cpp b/tests/xtd.core.unit_tests/src/xtd/io/tests/file_load_exception_tests.cpp index 4686faccbc6..6ea842430f0 100644 --- a/tests/xtd.core.unit_tests/src/xtd/io/tests/file_load_exception_tests.cpp +++ b/tests/xtd.core.unit_tests/src/xtd/io/tests/file_load_exception_tests.cpp @@ -1,10 +1,17 @@ #include +#include +#include +#include +#include +#include #include +#include #include #include using namespace xtd; using namespace xtd::io; +using namespace xtd::reflection; using namespace xtd::tunit; namespace xtd::io::tests { @@ -13,13 +20,244 @@ namespace xtd::io::tests { inline static std::locale previous_locale; static void test_initialize_(test_initialize) { previous_locale = std::locale::global(std::locale("en_US.UTF-8")); - stack_trace_enabled = system_exception::enable_stack_trace(); - system_exception::enable_stack_trace(false); + stack_trace_enabled = file_load_exception::enable_stack_trace(); + file_load_exception::enable_stack_trace(false); } static void test_cleanup_(test_cleanup) { std::locale::global(previous_locale); - system_exception::enable_stack_trace(stack_trace_enabled); + file_load_exception::enable_stack_trace(stack_trace_enabled); + } + + void test_method_(default_constructor) { + auto e = file_load_exception {}; + assert::are_equal("xtd::io::file_load_exception", e.get_type().full_name()); + assert::is_empty(e.help_link()); + assert::are_equal(h_result::COR_E_FILELOAD, e.h_result()); + assert::are_equal(h_result::h_result_category(), e.error_code().category()); + assert::are_equal(e.h_result(), e.error_code().value()); + assert::is_null(e.inner_exception()); + assert::are_equal("Could not load the specified file.", e.message()); + assert::are_equal(path::get_file_name(assembly::get_executing_assembly().location()), e.source()); + assert::is_not_empty(e.stack_trace()); + assert::is_not_empty(e.get_last_stack_frame().get_file_name()); + assert::is_not_zero(e.get_last_stack_frame().get_file_line_number()); + assert::is_not_empty(e.get_last_stack_frame().get_method()); + string_assert::starts_with("xtd::io::file_load_exception : Could not load the specified file.", e.to_string()); + assert::are_equal("Could not load the specified file.", e.what()); + } + + void test_method_(default_constructor_with_stack_frame) { + auto stack_frame = xtd::diagnostics::stack_frame::current(); + auto e = file_load_exception {stack_frame}; + assert::are_equal("xtd::io::file_load_exception", e.get_type().full_name()); + assert::is_empty(e.help_link()); + assert::are_equal(h_result::COR_E_FILELOAD, e.h_result()); + assert::are_equal(h_result::h_result_category(), e.error_code().category()); + assert::are_equal(e.h_result(), e.error_code().value()); + assert::is_null(e.inner_exception()); + assert::are_equal("Could not load the specified file.", e.message()); + assert::are_equal(path::get_file_name(assembly::get_executing_assembly().location()), e.source()); + assert::are_equal(stack_frame.to_string(), e.stack_trace()); + assert::are_equal(stack_frame.get_file_name(), e.get_last_stack_frame().get_file_name()); + assert::are_equal(stack_frame.get_file_line_number(), e.get_last_stack_frame().get_file_line_number()); + assert::are_equal(stack_frame.get_method(), e.get_last_stack_frame().get_method()); + assert::are_equal("xtd::io::file_load_exception : Could not load the specified file." + environment::new_line() + stack_frame.to_string(), e.to_string()); + assert::are_equal("Could not load the specified file.", e.what()); + } + + void test_method_(constructor_with_nullopt_message) { + auto e = file_load_exception {nullopt}; + assert::are_equal("xtd::io::file_load_exception", e.get_type().full_name()); + assert::is_empty(e.help_link()); + assert::are_equal(h_result::COR_E_FILELOAD, e.h_result()); + assert::are_equal(h_result::h_result_category(), e.error_code().category()); + assert::are_equal(e.h_result(), e.error_code().value()); + assert::is_null(e.inner_exception()); + assert::are_equal("Could not load the specified file.", e.message()); + assert::are_equal(path::get_file_name(assembly::get_executing_assembly().location()), e.source()); + assert::is_not_empty(e.stack_trace()); + assert::is_not_empty(e.get_last_stack_frame().get_file_name()); + assert::is_not_zero(e.get_last_stack_frame().get_file_line_number()); + assert::is_not_empty(e.get_last_stack_frame().get_method()); + string_assert::starts_with("xtd::io::file_load_exception : Could not load the specified file.", e.to_string()); + assert::are_equal("Could not load the specified file.", e.what()); + } + + void test_method_(constructor_with_nullopt_message_and_stack_frame) { + auto stack_frame = xtd::diagnostics::stack_frame::current(); + auto e = file_load_exception {nullopt, stack_frame}; + assert::are_equal("xtd::io::file_load_exception", e.get_type().full_name()); + assert::is_empty(e.help_link()); + assert::are_equal(h_result::COR_E_FILELOAD, e.h_result()); + assert::are_equal(h_result::h_result_category(), e.error_code().category()); + assert::are_equal(e.h_result(), e.error_code().value()); + assert::is_null(e.inner_exception()); + assert::are_equal("Could not load the specified file.", e.message()); + assert::are_equal(path::get_file_name(assembly::get_executing_assembly().location()), e.source()); + assert::are_equal(stack_frame.to_string(), e.stack_trace()); + assert::are_equal(stack_frame.get_file_name(), e.get_last_stack_frame().get_file_name()); + assert::are_equal(stack_frame.get_file_line_number(), e.get_last_stack_frame().get_file_line_number()); + assert::are_equal(stack_frame.get_method(), e.get_last_stack_frame().get_method()); + string_assert::starts_with("xtd::io::file_load_exception : Could not load the specified file." + environment::new_line() + stack_frame.to_string(), e.to_string()); + assert::are_equal("Could not load the specified file.", e.what()); + } + + void test_method_(constructor_with_empty_message) { + auto e = file_load_exception {""}; + assert::are_equal("xtd::io::file_load_exception", e.get_type().full_name()); + assert::is_empty(e.help_link()); + assert::are_equal(h_result::COR_E_FILELOAD, e.h_result()); + assert::are_equal(h_result::h_result_category(), e.error_code().category()); + assert::are_equal(e.h_result(), e.error_code().value()); + assert::is_null(e.inner_exception()); + assert::is_empty(e.message()); + assert::are_equal(path::get_file_name(assembly::get_executing_assembly().location()), e.source()); + assert::is_not_empty(e.stack_trace()); + assert::is_not_empty(e.get_last_stack_frame().get_file_name()); + assert::is_not_zero(e.get_last_stack_frame().get_file_line_number()); + assert::is_not_empty(e.get_last_stack_frame().get_method()); + string_assert::starts_with("xtd::io::file_load_exception", e.to_string()); + assert::are_equal("xtd::io::file_load_exception", e.what()); + } + + void test_method_(constructor_with_message_empty_and_stack_frame) { + auto stack_frame = xtd::diagnostics::stack_frame::current(); + auto e = file_load_exception {"", stack_frame}; + assert::are_equal("xtd::io::file_load_exception", e.get_type().full_name()); + assert::is_empty(e.help_link()); + assert::are_equal(h_result::COR_E_FILELOAD, e.h_result()); + assert::are_equal(h_result::h_result_category(), e.error_code().category()); + assert::are_equal(e.h_result(), e.error_code().value()); + assert::is_null(e.inner_exception()); + assert::is_empty(e.message()); + assert::are_equal(path::get_file_name(assembly::get_executing_assembly().location()), e.source()); + assert::are_equal(stack_frame.to_string(), e.stack_trace()); + assert::are_equal(stack_frame.get_file_name(), e.get_last_stack_frame().get_file_name()); + assert::are_equal(stack_frame.get_file_line_number(), e.get_last_stack_frame().get_file_line_number()); + assert::are_equal(stack_frame.get_method(), e.get_last_stack_frame().get_method()); + assert::are_equal("xtd::io::file_load_exception" + environment::new_line() + stack_frame.to_string(), e.to_string()); + assert::are_equal("xtd::io::file_load_exception", e.what()); + } + + void test_method_(constructor_with_message) { + auto e = file_load_exception {"Test excpetion message."}; + assert::are_equal("xtd::io::file_load_exception", e.get_type().full_name()); + assert::is_empty(e.help_link()); + assert::are_equal(h_result::COR_E_FILELOAD, e.h_result()); + assert::are_equal(h_result::h_result_category(), e.error_code().category()); + assert::are_equal(e.h_result(), e.error_code().value()); + assert::is_null(e.inner_exception()); + assert::are_equal("Test excpetion message.", e.message()); + assert::are_equal(path::get_file_name(assembly::get_executing_assembly().location()), e.source()); + assert::is_not_empty(e.stack_trace()); + assert::is_not_empty(e.get_last_stack_frame().get_file_name()); + assert::is_not_zero(e.get_last_stack_frame().get_file_line_number()); + assert::is_not_empty(e.get_last_stack_frame().get_method()); + string_assert::starts_with("xtd::io::file_load_exception : Test excpetion message.", e.to_string()); + assert::are_equal("Test excpetion message.", e.what()); + } + + void test_method_(constructor_with_message_and_stack_frame) { + auto stack_frame = xtd::diagnostics::stack_frame::current(); + auto e = file_load_exception {"Test excpetion message.", stack_frame}; + assert::are_equal("xtd::io::file_load_exception", e.get_type().full_name()); + assert::is_empty(e.help_link()); + assert::are_equal(h_result::COR_E_FILELOAD, e.h_result()); + assert::are_equal(h_result::h_result_category(), e.error_code().category()); + assert::are_equal(e.h_result(), e.error_code().value()); + assert::is_null(e.inner_exception()); + assert::are_equal("Test excpetion message.", e.message()); + assert::are_equal(path::get_file_name(assembly::get_executing_assembly().location()), e.source()); + assert::are_equal(stack_frame.to_string(), e.stack_trace()); + assert::are_equal(stack_frame.get_file_name(), e.get_last_stack_frame().get_file_name()); + assert::are_equal(stack_frame.get_file_line_number(), e.get_last_stack_frame().get_file_line_number()); + assert::are_equal(stack_frame.get_method(), e.get_last_stack_frame().get_method()); + assert::are_equal("xtd::io::file_load_exception : Test excpetion message." + environment::new_line() + stack_frame.to_string(), e.to_string()); + assert::are_equal("Test excpetion message.", e.what()); + } + + void test_method_(constructor_with_nullopt_message_and_inner_exception) { + auto inner_exception = argument_exception {}; + auto e = file_load_exception {nullopt, inner_exception}; + assert::are_equal("xtd::io::file_load_exception", e.get_type().full_name()); + assert::is_empty(e.help_link()); + assert::are_equal(h_result::COR_E_FILELOAD, e.h_result()); + assert::are_equal(h_result::h_result_category(), e.error_code().category()); + assert::are_equal(e.h_result(), e.error_code().value()); + assert::is_not_null(e.inner_exception()); + assert::is_instance_of(e.inner_exception().value().get()); + assert::are_equal("Could not load the specified file.", e.message()); + assert::are_equal(path::get_file_name(assembly::get_executing_assembly().location()), e.source()); + assert::is_not_empty(e.stack_trace()); + assert::is_not_empty(e.get_last_stack_frame().get_file_name()); + assert::is_not_zero(e.get_last_stack_frame().get_file_line_number()); + assert::is_not_empty(e.get_last_stack_frame().get_method()); + string_assert::starts_with("xtd::io::file_load_exception : Could not load the specified file.", e.to_string()); + assert::are_equal("Could not load the specified file.", e.what()); + } + + void test_method_(constructor_with_nullopt_message_and_stack_frame_inner_exception) { + auto inner_exception = argument_exception {}; + auto stack_frame = xtd::diagnostics::stack_frame::current(); + auto e = file_load_exception {nullopt, inner_exception, stack_frame}; + assert::are_equal("xtd::io::file_load_exception", e.get_type().full_name()); + assert::is_empty(e.help_link()); + assert::are_equal(h_result::COR_E_FILELOAD, e.h_result()); + assert::are_equal(h_result::h_result_category(), e.error_code().category()); + assert::are_equal(e.h_result(), e.error_code().value()); + assert::is_not_null(e.inner_exception()); + assert::is_instance_of(e.inner_exception().value().get()); + assert::are_equal("Could not load the specified file.", e.message()); + assert::are_equal(path::get_file_name(assembly::get_executing_assembly().location()), e.source()); + assert::are_equal(stack_frame.to_string(), e.stack_trace()); + assert::are_equal(stack_frame.get_file_name(), e.get_last_stack_frame().get_file_name()); + assert::are_equal(stack_frame.get_file_line_number(), e.get_last_stack_frame().get_file_line_number()); + assert::are_equal(stack_frame.get_method(), e.get_last_stack_frame().get_method()); + assert::are_equal("xtd::io::file_load_exception : Could not load the specified file." + environment::new_line() + stack_frame.to_string(), e.to_string()); + assert::are_equal("Could not load the specified file.", e.what()); + } + + void test_method_(constructor_with_message_and_inner_exception) { + auto inner_exception = argument_exception {}; + auto e = file_load_exception {"Test excpetion message.", inner_exception}; + assert::is_empty(e.help_link()); + assert::are_equal(h_result::COR_E_FILELOAD, e.h_result()); + assert::are_equal(h_result::h_result_category(), e.error_code().category()); + assert::are_equal(e.h_result(), e.error_code().value()); + assert::is_not_null(e.inner_exception()); + assert::is_instance_of(e.inner_exception().value().get()); + assert::are_equal(inner_exception.to_string(), e.inner_exception().value().get().to_string()); + assert::are_equal("Test excpetion message.", e.message()); + assert::are_equal(path::get_file_name(assembly::get_executing_assembly().location()), e.source()); + assert::is_not_empty(e.stack_trace()); + assert::is_not_empty(e.get_last_stack_frame().get_file_name()); + assert::is_not_zero(e.get_last_stack_frame().get_file_line_number()); + assert::is_not_empty(e.get_last_stack_frame().get_method()); + string_assert::starts_with("xtd::io::file_load_exception : Test excpetion message.", e.to_string()); + assert::are_equal("Test excpetion message.", e.what()); + } + + void test_method_(constructor_with_message_inner_exception_and_stack_frame) { + auto inner_exception = argument_exception {}; + auto stack_frame = xtd::diagnostics::stack_frame::current(); + auto e = file_load_exception {"Test excpetion message.", inner_exception, stack_frame}; + assert::are_equal("xtd::io::file_load_exception", e.get_type().full_name()); + assert::is_empty(e.help_link()); + assert::are_equal(h_result::COR_E_FILELOAD, e.h_result()); + assert::are_equal(h_result::h_result_category(), e.error_code().category()); + assert::are_equal(e.h_result(), e.error_code().value()); + assert::is_not_null(e.inner_exception()); + assert::is_instance_of(e.inner_exception().value().get()); + assert::are_equal(inner_exception.to_string(), e.inner_exception().value().get().to_string()); + assert::are_equal("Test excpetion message.", e.message()); + assert::are_equal(path::get_file_name(assembly::get_executing_assembly().location()), e.source()); + assert::are_equal(stack_frame.to_string(), e.stack_trace()); + assert::are_equal(stack_frame.get_file_name(), e.get_last_stack_frame().get_file_name()); + assert::are_equal(stack_frame.get_file_line_number(), e.get_last_stack_frame().get_file_line_number()); + assert::are_equal(stack_frame.get_method(), e.get_last_stack_frame().get_method()); + string_assert::starts_with("xtd::io::file_load_exception : Test excpetion message." + environment::new_line() + stack_frame.to_string(), e.to_string()); + assert::are_equal("Test excpetion message.", e.what()); } }; }