Skip to content

Commit

Permalink
Add io_exception unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gammasoft71 committed Oct 14, 2024
1 parent cc79153 commit 5b1f9b1
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions tests/xtd.core.unit_tests/src/xtd/io/tests/io_exception_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,43 @@ namespace xtd::io::tests {
assert::are_equal("I/O error occurred.", e.what(), csf_);
}

void test_method_(constructor_with_nullopt_message) {
auto e = io_exception {nullopt};
assert::are_equal("xtd::io::io_exception", e.get_type().full_name(), csf_);
assert::is_empty(e.help_link(), csf_);
assert::are_equal(h_result::COR_E_IO, e.h_result(), csf_);
assert::are_equal(h_result::h_result_category(), e.error_code().category(), csf_);
assert::are_equal(e.h_result(), e.error_code().value(), csf_);
assert::is_null(e.inner_exception(), csf_);
assert::are_equal("I/O error occurred.", e.message(), csf_);
assert::are_equal(path::get_file_name(assembly::get_executing_assembly().location()), e.source(), csf_);
assert::is_empty(e.stack_trace(), csf_);
assert::is_empty(e.get_last_stack_frame().get_file_name(), csf_);
assert::are_equal(0u, e.get_last_stack_frame().get_file_line_number(), csf_);
assert::is_empty(e.get_last_stack_frame().get_method(), csf_);
assert::are_equal("xtd::io::io_exception : I/O error occurred.", e.to_string(), csf_);
assert::are_equal("I/O error occurred.", e.what(), csf_);
}

void test_method_(constructor_with_nullopt_message_and_stack_frame) {
auto stack_frame = current_stack_frame_;
auto e = io_exception {nullopt, stack_frame};
assert::are_equal("xtd::io::io_exception", e.get_type().full_name(), csf_);
assert::is_empty(e.help_link(), csf_);
assert::are_equal(h_result::COR_E_IO, e.h_result(), csf_);
assert::are_equal(h_result::h_result_category(), e.error_code().category(), csf_);
assert::are_equal(e.h_result(), e.error_code().value(), csf_);
assert::is_null(e.inner_exception(), csf_);
assert::are_equal("I/O error occurred.", e.message(), csf_);
assert::are_equal(path::get_file_name(assembly::get_executing_assembly().location()), e.source(), csf_);
assert::are_equal(stack_frame.to_string(), e.stack_trace(), csf_);
assert::are_equal(stack_frame.get_file_name(), e.get_last_stack_frame().get_file_name(), csf_);
assert::are_equal(stack_frame.get_file_line_number(), e.get_last_stack_frame().get_file_line_number(), csf_);
assert::are_equal(stack_frame.get_method(), e.get_last_stack_frame().get_method(), csf_);
assert::are_equal("xtd::io::io_exception : I/O error occurred." + environment::new_line() + stack_frame.to_string(), e.to_string(), csf_);
assert::are_equal("I/O error occurred.", e.what(), csf_);
}

void test_method_(constructor_with_empty_message) {
auto e = io_exception {""};
assert::are_equal("xtd::io::io_exception", e.get_type().full_name(), csf_);
Expand Down Expand Up @@ -138,6 +175,47 @@ namespace xtd::io::tests {
assert::are_equal("Test excpetion message.", e.what(), csf_);
}

void test_method_(constructor_with_nullopt_message_and_inner_exception) {
auto inner_exception = argument_exception {};
auto e = io_exception {nullopt, inner_exception};
assert::are_equal("xtd::io::io_exception", e.get_type().full_name(), csf_);
assert::is_empty(e.help_link(), csf_);
assert::are_equal(h_result::COR_E_IO, e.h_result(), csf_);
assert::are_equal(h_result::h_result_category(), e.error_code().category(), csf_);
assert::are_equal(e.h_result(), e.error_code().value(), csf_);
assert::is_not_null(e.inner_exception(), csf_);
assert::is_instance_of<xtd::argument_exception>(e.inner_exception().value().get(), csf_);
assert::are_equal("I/O error occurred.", e.message(), csf_);
assert::are_equal(path::get_file_name(assembly::get_executing_assembly().location()), e.source(), csf_);
assert::is_empty(e.stack_trace(), csf_);
assert::is_empty(e.get_last_stack_frame().get_file_name(), csf_);
assert::are_equal(0u, e.get_last_stack_frame().get_file_line_number(), csf_);
assert::is_empty(e.get_last_stack_frame().get_method(), csf_);
assert::are_equal("xtd::io::io_exception : I/O error occurred.", e.to_string(), csf_);
assert::are_equal("I/O error occurred.", e.what(), csf_);
}

void test_method_(constructor_with_nullopt_message_and_stack_frame_inner_exception) {
auto inner_exception = argument_exception {};
auto stack_frame = current_stack_frame_;
auto e = io_exception {nullopt, inner_exception, stack_frame};
assert::are_equal("xtd::io::io_exception", e.get_type().full_name(), csf_);
assert::is_empty(e.help_link(), csf_);
assert::are_equal(h_result::COR_E_IO, e.h_result(), csf_);
assert::are_equal(h_result::h_result_category(), e.error_code().category(), csf_);
assert::are_equal(e.h_result(), e.error_code().value(), csf_);
assert::is_not_null(e.inner_exception(), csf_);
assert::is_instance_of<xtd::argument_exception>(e.inner_exception().value().get(), csf_);
assert::are_equal("I/O error occurred.", e.message(), csf_);
assert::are_equal(path::get_file_name(assembly::get_executing_assembly().location()), e.source(), csf_);
assert::are_equal(stack_frame.to_string(), e.stack_trace(), csf_);
assert::are_equal(stack_frame.get_file_name(), e.get_last_stack_frame().get_file_name(), csf_);
assert::are_equal(stack_frame.get_file_line_number(), e.get_last_stack_frame().get_file_line_number(), csf_);
assert::are_equal(stack_frame.get_method(), e.get_last_stack_frame().get_method(), csf_);
assert::are_equal("xtd::io::io_exception : I/O error occurred." + environment::new_line() + stack_frame.to_string(), e.to_string(), csf_);
assert::are_equal("I/O error occurred.", e.what(), csf_);
}

void test_method_(constructor_with_message_and_inner_exception) {
auto inner_exception = argument_exception {};
auto e = io_exception {"Test excpetion message.", inner_exception};
Expand Down

0 comments on commit 5b1f9b1

Please sign in to comment.