Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset error state after testing expected errors #251

Merged
merged 1 commit into from
May 18, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions test/test_string_array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "gtest/gtest.h"

#include "./allocator_testing_utils.h"
#include "rcutils/error_handling.h"
#include "rcutils/types/string_array.h"

#ifdef _WIN32
Expand All @@ -35,7 +36,9 @@ TEST(test_string_array, boot_string_array) {
ASSERT_EQ(RCUTILS_RET_OK, ret);

EXPECT_EQ(RCUTILS_RET_INVALID_ARGUMENT, rcutils_string_array_init(&sa0, 2, NULL));
rcutils_reset_error();
EXPECT_EQ(RCUTILS_RET_BAD_ALLOC, rcutils_string_array_init(&sa0, 2, &failing_allocator));
rcutils_reset_error();

rcutils_string_array_t sa1 = rcutils_get_zero_initialized_string_array();
ret = rcutils_string_array_init(&sa1, 3, &allocator);
Expand All @@ -55,6 +58,7 @@ TEST(test_string_array, boot_string_array) {
ASSERT_EQ(RCUTILS_RET_OK, rcutils_string_array_init(&sa3, 3, &allocator));
sa3.allocator.allocate = NULL;
ASSERT_EQ(RCUTILS_RET_INVALID_ARGUMENT, rcutils_string_array_fini(&sa3));
rcutils_reset_error();
sa3.allocator = allocator;
ASSERT_EQ(RCUTILS_RET_OK, rcutils_string_array_fini(&sa3));
}
Expand Down Expand Up @@ -98,9 +102,13 @@ TEST(test_string_array, string_array_cmp) {

// Test failure cases
EXPECT_EQ(RCUTILS_RET_INVALID_ARGUMENT, rcutils_string_array_cmp(NULL, &sa0, &res));
rcutils_reset_error();
EXPECT_EQ(RCUTILS_RET_INVALID_ARGUMENT, rcutils_string_array_cmp(&sa0, NULL, &res));
rcutils_reset_error();
EXPECT_EQ(RCUTILS_RET_INVALID_ARGUMENT, rcutils_string_array_cmp(&sa0, &sa1, NULL));
rcutils_reset_error();
EXPECT_EQ(RCUTILS_RET_ERROR, rcutils_string_array_cmp(&sa0, &incomplete_string_array, &res));
rcutils_reset_error();

// Test success cases
EXPECT_EQ(RCUTILS_RET_OK, rcutils_string_array_cmp(&sa0, &sa1, &res));
Expand Down