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

// 1. Test operator<< output (truncates to default Fw::String capacity)
buf1 << s;

// 2. Test s.toString() output (uses full buffer capacity)
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.


// Build the expected full string representation
buf2 << "( "
<< "mString = " << testString << ", "
<< "mEnum = " << testEnum << ", "
Expand All @@ -293,13 +299,16 @@ TEST_F(NonPrimitiveTest, ToString) {
<< "mStruct = " << testStruct << ", "
<< "mAliasStruct = " << testStruct << ", "
<< "mU32Arr = [ " << testU32Arr[0] << ", " << testU32Arr[1] << ", " << testU32Arr[2] << " ], "
<< "mStructArr = [ " << testStructArr[0] << ", " << testStructArr[1] << ", " << testStructArr[2] << " ] "
<< " )";
<< "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

// Truncate string output
Fw::String s2(buf2.str().c_str());
// Verify truncated operator<< output against standard Fw::String
Fw::String sTruncated(buf2.str().c_str());
ASSERT_STREQ(buf1.str().c_str(), sTruncated.toChar());

ASSERT_STREQ(buf1.str().c_str(), s2.toChar());
// Verify full s.toString() output against large capacity buffer
Fw::StringTemplate<1024> sFull(buf2.str().c_str());
ASSERT_STREQ(str.toChar(), sFull.toChar());
}

} // namespace Struct
Expand Down
Loading