Skip to content

Commit

Permalink
clang-tidy....
Browse files Browse the repository at this point in the history
  • Loading branch information
KerstinKeller committed Sep 25, 2024
1 parent d200eab commit 3ab8237
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
3 changes: 1 addition & 2 deletions ecal/core/src/serialization/ecal_serialize_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,7 @@ namespace eCAL
if (*arg == nullptr) return false;

auto* tgt_list = static_cast<Util::CExpandingVector<std::string>*>(*arg);
tgt_list->push_back();
auto& tgt_string = tgt_list->back();
auto& tgt_string = tgt_list->push_back();

size_t len = stream->bytes_left;
tgt_string.resize(len);
Expand Down
5 changes: 1 addition & 4 deletions ecal/core/src/util/expanding_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,9 @@ namespace eCAL

private:
std::vector<T> data;
size_t internal_size; // Track size separately
size_t internal_size{ 0 }; // Track size separately

public:
// Constructor
CExpandingVector() : internal_size(0) {}

// Access to the internal size
size_t size() const {
return internal_size;
Expand Down
26 changes: 14 additions & 12 deletions ecal/tests/cpp/util_test/src/expanding_vector_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ class CExpandingVectorTest : public ::testing::Test {
}
};

using core_cpp_util_expanding_vector = CExpandingVectorTest;

// Test push_back and size functionality
TEST_F(CExpandingVectorTest, PushBackAndSize) {
TEST_F(core_cpp_util_expanding_vector, PushBackAndSize) {
EXPECT_EQ(vec.size(), 3); // Size should be 3 after pushing 3 elements

vec.push_back(MyElement(4));
Expand All @@ -51,7 +53,7 @@ TEST_F(CExpandingVectorTest, PushBackAndSize) {
}

// Test clear functionality
TEST_F(CExpandingVectorTest, ClearElements) {
TEST_F(core_cpp_util_expanding_vector, ClearElements) {
vec.clear(); // Call clear, which should reset individual elements

EXPECT_EQ(vec.size(), 0); // Internal size should be reset to 0
Expand All @@ -67,7 +69,7 @@ TEST_F(CExpandingVectorTest, ClearElements) {
}

// Test resize functionality
TEST_F(CExpandingVectorTest, ResizeVector) {
TEST_F(core_cpp_util_expanding_vector, ResizeVector) {
vec.resize(5);
EXPECT_EQ(vec.size(), 5); // Size should be 5 after resizing

Expand All @@ -83,7 +85,7 @@ TEST_F(CExpandingVectorTest, ResizeVector) {
}

// Test operator[] without bounds checking
TEST_F(CExpandingVectorTest, OperatorAccess) {
TEST_F(core_cpp_util_expanding_vector, OperatorAccess) {
EXPECT_NO_THROW(vec[1]); // Access valid index without throwing exception
EXPECT_EQ(vec[1].value, 2); // Element at index 1 should have value 2

Expand All @@ -95,15 +97,15 @@ TEST_F(CExpandingVectorTest, OperatorAccess) {
}

// Test at() function with bounds checking
TEST_F(CExpandingVectorTest, AtFunction) {
TEST_F(core_cpp_util_expanding_vector, AtFunction) {
EXPECT_NO_THROW(vec.at(0));
EXPECT_EQ(vec.at(0).value, 1);

EXPECT_THROW(vec.at(10), std::out_of_range); // Out of bounds access should throw
}

// Test begin() and end() iterator functions
TEST_F(CExpandingVectorTest, Iterators) {
TEST_F(core_cpp_util_expanding_vector, Iterators) {
auto it = vec.begin();
EXPECT_EQ(it->value, 1); // First element should have value 1
++it;
Expand All @@ -117,7 +119,7 @@ TEST_F(CExpandingVectorTest, Iterators) {
}

// Test const_iterator functionality
TEST_F(CExpandingVectorTest, ConstIterator) {
TEST_F(core_cpp_util_expanding_vector, ConstIterator) {
const CExpandingVector<MyElement> constVec = vec;

CExpandingVector<MyElement>::const_iterator it = constVec.begin();
Expand All @@ -133,15 +135,15 @@ TEST_F(CExpandingVectorTest, ConstIterator) {
}

// Test empty() function
TEST_F(CExpandingVectorTest, EmptyFunction) {
TEST_F(core_cpp_util_expanding_vector, EmptyFunction) {
EXPECT_FALSE(vec.empty()); // Should not be empty initially

vec.clear();
EXPECT_TRUE(vec.empty()); // Should be empty after clear is called
}

// Test capacity and full_size functions
TEST_F(CExpandingVectorTest, FullSize) {
TEST_F(core_cpp_util_expanding_vector, FullSize) {
EXPECT_EQ(vec.full_size(), 3); // Full size is the size of the underlying vector

vec.push_back(MyElement(4));
Expand All @@ -152,15 +154,15 @@ TEST_F(CExpandingVectorTest, FullSize) {
}


TEST_F(CExpandingVectorTest, Front) {
TEST_F(core_cpp_util_expanding_vector, Front) {
EXPECT_EQ(vec.front().value, 1); // The first element should have value 1

vec.front().value = 10; // Modify the first element
EXPECT_EQ(vec.front().value, 10); // Check if the modification worked
}

// Test back function
TEST_F(CExpandingVectorTest, Back) {
TEST_F(core_cpp_util_expanding_vector, Back) {
EXPECT_EQ(vec.back().value, 3); // The last element should have value 3

vec.back().value = 20; // Modify the last element
Expand All @@ -172,7 +174,7 @@ TEST_F(CExpandingVectorTest, Back) {
}

// Test front and back with an empty vector (should throw an exception)
TEST_F(CExpandingVectorTest, FrontAndBackEmptyVector) {
TEST_F(core_cpp_util_expanding_vector, FrontAndBackEmptyVector) {
CExpandingVector<MyElement> emptyVec;

EXPECT_THROW(emptyVec.front(), std::out_of_range); // Should throw because vector is empty
Expand Down

0 comments on commit 3ab8237

Please sign in to comment.