Skip to content
13 changes: 7 additions & 6 deletions FppTestProject/FppTest/struct/NonPrimitiveTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,9 @@ TEST_F(NonPrimitiveTest, ToString) {
NonPrimitive s(testString, testEnum, testArray, testArray, testStruct, testStruct, testU32Arr, testStructArr);
std::stringstream buf1, buf2;

buf1 << s;
Fw::StringTemplate<1024> str;
s.toString(str);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is better for testing s.toString, but now it doesn't test the << method of s at all. Can we keep both tests here (the truncated and non-truncated versions)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the test to explicitly verify both the truncated operator<< behavior and the non-truncated toString() output using the larger buffer

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Can you apply the same change to PrimitiveTest? The two cases (PrimitiveTest, NonPrimitiveTest) should operate in the same way.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! I've updated PrimitiveTest to follow the exact same two-case testing pattern, verifying both the truncated operator<< output and the full toString() output.

buf1 << str;

buf2 << "( "
<< "mString = " << testString << ", "
Expand All @@ -293,12 +295,11 @@ TEST_F(NonPrimitiveTest, ToString) {
<< "mStruct = " << testStruct << ", "
<< "mAliasStruct = " << testStruct << ", "
<< "mU32Arr = [ " << testU32Arr[0] << ", " << testU32Arr[1] << ", " << testU32Arr[2] << " ], "
<< "mStructArr = [ " << testStructArr[0] << ", " << testStructArr[1] << ", " << testStructArr[2] << " ] "
<< " )";

// Truncate string output
Fw::String s2(buf2.str().c_str());
<< "mStructArr = [ " << testStructArr[0] << ", " << testStructArr[1] << ", " << testStructArr[2] << " ]"
<< ")";
Comment thread
karan9617 marked this conversation as resolved.
Outdated
Comment thread
bocchino marked this conversation as resolved.
Outdated

// Use a large buffer capacity to prevent string truncation
Fw::StringTemplate<1024> s2(buf2.str().c_str());
ASSERT_STREQ(buf1.str().c_str(), s2.toChar());
}

Expand Down
2 changes: 1 addition & 1 deletion FppTestProject/FppTest/struct/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// Instantiate string tests for structs
using StringTestImplementations =
::testing::Types<Fw::StringTemplate<80>, Fw::StringTemplate<50>, Fw::StringTemplate<60> >;
INSTANTIATE_TYPED_TEST_SUITE_P(Struct, StringTest, StringTestImplementations);
INSTANTIATE_TYPED_TEST_SUITE_P(Struct, StringTest, StringTestImplementations, );
Comment thread
bocchino marked this conversation as resolved.
Outdated

int main(int argc, char* argv[]) {
::testing::InitGoogleTest(&argc, argv);
Expand Down