Skip to content

Commit

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

void test_method_(constructor_with_nullopt_message) {
auto e = system_exception {nullopt};
assert::are_equal("xtd::system_exception", e.get_type().full_name(), csf_);
assert::is_empty(e.help_link(), csf_);
assert::are_equal(h_result::COR_E_SYSTEM, 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("System error.", 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::system_exception : System error.", e.to_string(), csf_);
assert::are_equal("System error.", e.what(), csf_);
}

void test_method_(constructor_with_nullopt_message_and_stack_frame) {
auto stack_frame = current_stack_frame_;
auto e = system_exception {nullopt, stack_frame};
assert::are_equal("xtd::system_exception", e.get_type().full_name(), csf_);
assert::is_empty(e.help_link(), csf_);
assert::are_equal(h_result::COR_E_SYSTEM, 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("System error.", 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::system_exception : System error." + environment::new_line() + stack_frame.to_string(), e.to_string(), csf_);
assert::are_equal("System error.", e.what(), csf_);
}

void test_method_(constructor_with_empty_message) {
auto e = system_exception {""};
assert::are_equal("xtd::system_exception", e.get_type().full_name(), csf_);
Expand Down Expand Up @@ -138,6 +175,47 @@ namespace xtd::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 = system_exception {nullopt, inner_exception};
assert::are_equal("xtd::system_exception", e.get_type().full_name(), csf_);
assert::is_empty(e.help_link(), csf_);
assert::are_equal(h_result::COR_E_SYSTEM, 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("System error.", 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::system_exception : System error.", e.to_string(), csf_);
assert::are_equal("System error.", 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 = system_exception {nullopt, inner_exception, stack_frame};
assert::are_equal("xtd::system_exception", e.get_type().full_name(), csf_);
assert::is_empty(e.help_link(), csf_);
assert::are_equal(h_result::COR_E_SYSTEM, 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("System error.", 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::system_exception : System error." + environment::new_line() + stack_frame.to_string(), e.to_string(), csf_);
assert::are_equal("System error.", e.what(), csf_);
}

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

0 comments on commit 9c28bfc

Please sign in to comment.