From 54b0add41462c4aacc1cb0d63e54a871111278ed Mon Sep 17 00:00:00 2001 From: Gammasoft Date: Fri, 1 Nov 2024 12:03:08 +0100 Subject: [PATCH] Rvue xtd::io::path_too_long_exception exception class --- src/xtd.core/CMakeLists.txt | 3 +- .../include/xtd/io/path_too_long_exception.h | 67 +++-- .../src/xtd/io/path_too_long_exception.cpp | 49 ++++ .../tests/path_too_long_exception_tests.cpp | 244 +++++++++++++++++- 4 files changed, 336 insertions(+), 27 deletions(-) create mode 100644 src/xtd.core/src/xtd/io/path_too_long_exception.cpp diff --git a/src/xtd.core/CMakeLists.txt b/src/xtd.core/CMakeLists.txt index 1b0b95ad932..54600fb8c37 100644 --- a/src/xtd.core/CMakeLists.txt +++ b/src/xtd.core/CMakeLists.txt @@ -1111,16 +1111,17 @@ add_sources( src/xtd/io/binary_writer.cpp src/xtd/io/directory.cpp src/xtd/io/directory_info.cpp + src/xtd/io/directory_not_found_exception.cpp src/xtd/io/file.cpp src/xtd/io/file_info.cpp src/xtd/io/file_not_found_exception.cpp src/xtd/io/file_system_info.cpp - src/xtd/io/directory_not_found_exception.cpp src/xtd/io/drive_info.cpp src/xtd/io/drive_not_found_exception.cpp src/xtd/io/end_of_stream_exception.cpp src/xtd/io/io_exception.cpp src/xtd/io/path.cpp + src/xtd/io/path_too_long_exception.cpp src/xtd/io/stream_reader.cpp src/xtd/io/stream_writer.cpp src/xtd/io/string_reader.cpp diff --git a/src/xtd.core/include/xtd/io/path_too_long_exception.h b/src/xtd.core/include/xtd/io/path_too_long_exception.h index a203c7c1b26..b261a43f0a8 100644 --- a/src/xtd.core/include/xtd/io/path_too_long_exception.h +++ b/src/xtd.core/include/xtd/io/path_too_long_exception.h @@ -32,66 +32,87 @@ namespace xtd { /// @name Public Constructors /// @{ - /// @brief Create a new instance of class path_too_long_exception + /// @brief Create a new instance of class xtd::io::path_too_long_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 path_too_long_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 path_too_long_exception + explicit path_too_long_exception(const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current()); + /// @brief Create a new instance of class xtd::io::path_too_long_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 path_too_long_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 path_too_long_exception + explicit path_too_long_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::path_too_long_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 + path_too_long_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_PATHTOOLONG));} + + /// @brief Create a new instance of class xtd::io::path_too_long_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 path_too_long_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 path_too_long_exception + /// @deprecated Use xtd::io::path_too_long_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::path_too_long_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 path_too_long_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::path_too_long_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 path_too_long_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 path_too_long_exception + /// @deprecated Use xtd::io::path_too_long_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::path_too_long_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 path_too_long_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::path_too_long_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 path_too_long_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 path_too_long_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::path_too_long_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::path_too_long_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 path_too_long_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::path_too_long_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 path_too_long_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 path_too_long_exception + /// @deprecated Use xtd::io::path_too_long_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::path_too_long_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 path_too_long_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::path_too_long_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 path_too_long_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 path_too_long_exception + /// @deprecated Use xtd::io::path_too_long_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::path_too_long_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 path_too_long_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::path_too_long_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 path_too_long_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 path_too_long_exception + /// @deprecated Use xtd::io::path_too_long_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::path_too_long_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 path_too_long_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::path_too_long_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 path_too_long_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 path_too_long_exception + /// @deprecated Use xtd::io::path_too_long_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::path_too_long_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 path_too_long_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::path_too_long_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 path_too_long_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::path_too_long_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::path_too_long_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 path_too_long_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 path_too_long_exception(const path_too_long_exception&) = default; path_too_long_exception& operator =(const path_too_long_exception&) = default; /// @endcond - - private: - const char* default_message() const noexcept {return "The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters."_t;} }; } } diff --git a/src/xtd.core/src/xtd/io/path_too_long_exception.cpp b/src/xtd.core/src/xtd/io/path_too_long_exception.cpp new file mode 100644 index 00000000000..6f66f9c6a49 --- /dev/null +++ b/src/xtd.core/src/xtd/io/path_too_long_exception.cpp @@ -0,0 +1,49 @@ +#include "../../../include/xtd/io/path_too_long_exception.h" + +using namespace xtd; +using namespace xtd::diagnostics; +using namespace xtd::io; + +path_too_long_exception::path_too_long_exception(const stack_frame& stack_frame) : io_exception(stack_frame) { + error_code(h_result::make_error_code(h_result::COR_E_PATHTOOLONG)); +} + +path_too_long_exception::path_too_long_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_PATHTOOLONG)); +} + +path_too_long_exception::path_too_long_exception(const string& message, const std::error_code& error, const stack_frame& stack_frame) : io_exception(message, stack_frame) { + error_code(error); +} + +path_too_long_exception::path_too_long_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_PATHTOOLONG)); + this->help_link(help_link); +} + +path_too_long_exception::path_too_long_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); +} + +path_too_long_exception::path_too_long_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_PATHTOOLONG)); +} + +path_too_long_exception::path_too_long_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_PATHTOOLONG)); +} + +path_too_long_exception::path_too_long_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); +} + +path_too_long_exception::path_too_long_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_PATHTOOLONG)); + this->help_link(help_link); +} + +path_too_long_exception::path_too_long_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/path_too_long_exception_tests.cpp b/tests/xtd.core.unit_tests/src/xtd/io/tests/path_too_long_exception_tests.cpp index 75c721eec8f..b86143dbb35 100644 --- a/tests/xtd.core.unit_tests/src/xtd/io/tests/path_too_long_exception_tests.cpp +++ b/tests/xtd.core.unit_tests/src/xtd/io/tests/path_too_long_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 = path_too_long_exception::enable_stack_trace(); + path_too_long_exception::enable_stack_trace(false); } static void test_cleanup_(test_cleanup) { std::locale::global(previous_locale); - system_exception::enable_stack_trace(stack_trace_enabled); + path_too_long_exception::enable_stack_trace(stack_trace_enabled); + } + + void test_method_(default_constructor) { + auto e = path_too_long_exception {}; + assert::are_equal("xtd::io::path_too_long_exception", e.get_type().full_name()); + assert::is_empty(e.help_link()); + assert::are_equal(h_result::COR_E_PATHTOOLONG, 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("The specified file name or path is too long, or a component of the specified path is too long.", 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::path_too_long_exception : The specified file name or path is too long, or a component of the specified path is too long.", e.to_string()); + assert::are_equal("The specified file name or path is too long, or a component of the specified path is too long.", e.what()); + } + + void test_method_(default_constructor_with_stack_frame) { + auto stack_frame = xtd::diagnostics::stack_frame::current(); + auto e = path_too_long_exception {stack_frame}; + assert::are_equal("xtd::io::path_too_long_exception", e.get_type().full_name()); + assert::is_empty(e.help_link()); + assert::are_equal(h_result::COR_E_PATHTOOLONG, 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("The specified file name or path is too long, or a component of the specified path is too long.", 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::path_too_long_exception : The specified file name or path is too long, or a component of the specified path is too long." + environment::new_line() + stack_frame.to_string(), e.to_string()); + assert::are_equal("The specified file name or path is too long, or a component of the specified path is too long.", e.what()); + } + + void test_method_(constructor_with_nullopt_message) { + auto e = path_too_long_exception {nullopt}; + assert::are_equal("xtd::io::path_too_long_exception", e.get_type().full_name()); + assert::is_empty(e.help_link()); + assert::are_equal(h_result::COR_E_PATHTOOLONG, 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("The specified file name or path is too long, or a component of the specified path is too long.", 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::path_too_long_exception : The specified file name or path is too long, or a component of the specified path is too long.", e.to_string()); + assert::are_equal("The specified file name or path is too long, or a component of the specified path is too long.", e.what()); + } + + void test_method_(constructor_with_nullopt_message_and_stack_frame) { + auto stack_frame = xtd::diagnostics::stack_frame::current(); + auto e = path_too_long_exception {nullopt, stack_frame}; + assert::are_equal("xtd::io::path_too_long_exception", e.get_type().full_name()); + assert::is_empty(e.help_link()); + assert::are_equal(h_result::COR_E_PATHTOOLONG, 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("The specified file name or path is too long, or a component of the specified path is too long.", 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::path_too_long_exception : The specified file name or path is too long, or a component of the specified path is too long." + environment::new_line() + stack_frame.to_string(), e.to_string()); + assert::are_equal("The specified file name or path is too long, or a component of the specified path is too long.", e.what()); + } + + void test_method_(constructor_with_empty_message) { + auto e = path_too_long_exception {""}; + assert::are_equal("xtd::io::path_too_long_exception", e.get_type().full_name()); + assert::is_empty(e.help_link()); + assert::are_equal(h_result::COR_E_PATHTOOLONG, 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::path_too_long_exception", e.to_string()); + assert::are_equal("xtd::io::path_too_long_exception", e.what()); + } + + void test_method_(constructor_with_message_empty_and_stack_frame) { + auto stack_frame = xtd::diagnostics::stack_frame::current(); + auto e = path_too_long_exception {"", stack_frame}; + assert::are_equal("xtd::io::path_too_long_exception", e.get_type().full_name()); + assert::is_empty(e.help_link()); + assert::are_equal(h_result::COR_E_PATHTOOLONG, 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::path_too_long_exception" + environment::new_line() + stack_frame.to_string(), e.to_string()); + assert::are_equal("xtd::io::path_too_long_exception", e.what()); + } + + void test_method_(constructor_with_message) { + auto e = path_too_long_exception {"Test excpetion message."}; + assert::are_equal("xtd::io::path_too_long_exception", e.get_type().full_name()); + assert::is_empty(e.help_link()); + assert::are_equal(h_result::COR_E_PATHTOOLONG, 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::path_too_long_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 = path_too_long_exception {"Test excpetion message.", stack_frame}; + assert::are_equal("xtd::io::path_too_long_exception", e.get_type().full_name()); + assert::is_empty(e.help_link()); + assert::are_equal(h_result::COR_E_PATHTOOLONG, 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::path_too_long_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 = path_too_long_exception {nullopt, inner_exception}; + assert::are_equal("xtd::io::path_too_long_exception", e.get_type().full_name()); + assert::is_empty(e.help_link()); + assert::are_equal(h_result::COR_E_PATHTOOLONG, 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("The specified file name or path is too long, or a component of the specified path is too long.", 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::path_too_long_exception : The specified file name or path is too long, or a component of the specified path is too long.", e.to_string()); + assert::are_equal("The specified file name or path is too long, or a component of the specified path is too long.", 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 = path_too_long_exception {nullopt, inner_exception, stack_frame}; + assert::are_equal("xtd::io::path_too_long_exception", e.get_type().full_name()); + assert::is_empty(e.help_link()); + assert::are_equal(h_result::COR_E_PATHTOOLONG, 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("The specified file name or path is too long, or a component of the specified path is too long.", 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::path_too_long_exception : The specified file name or path is too long, or a component of the specified path is too long." + environment::new_line() + stack_frame.to_string(), e.to_string()); + assert::are_equal("The specified file name or path is too long, or a component of the specified path is too long.", e.what()); + } + + void test_method_(constructor_with_message_and_inner_exception) { + auto inner_exception = argument_exception {}; + auto e = path_too_long_exception {"Test excpetion message.", inner_exception}; + assert::is_empty(e.help_link()); + assert::are_equal(h_result::COR_E_PATHTOOLONG, 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::path_too_long_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 = path_too_long_exception {"Test excpetion message.", inner_exception, stack_frame}; + assert::are_equal("xtd::io::path_too_long_exception", e.get_type().full_name()); + assert::is_empty(e.help_link()); + assert::are_equal(h_result::COR_E_PATHTOOLONG, 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::path_too_long_exception : Test excpetion message." + environment::new_line() + stack_frame.to_string(), e.to_string()); + assert::are_equal("Test excpetion message.", e.what()); } }; }