diff --git a/FppTestProject/FppTest/struct/NonPrimitiveTest.cpp b/FppTestProject/FppTest/struct/NonPrimitiveTest.cpp index 1690199bf9e..a2aaabec35d 100644 --- a/FppTestProject/FppTest/struct/NonPrimitiveTest.cpp +++ b/FppTestProject/FppTest/struct/NonPrimitiveTest.cpp @@ -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); + + // Build the expected full string representation buf2 << "( " << "mString = " << testString << ", " << "mEnum = " << testEnum << ", " @@ -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] << " ]" << " )"; - // 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 diff --git a/FppTestProject/FppTest/struct/PrimitiveTest.cpp b/FppTestProject/FppTest/struct/PrimitiveTest.cpp index 40be917afbb..8455de59353 100644 --- a/FppTestProject/FppTest/struct/PrimitiveTest.cpp +++ b/FppTestProject/FppTest/struct/PrimitiveTest.cpp @@ -197,15 +197,27 @@ TYPED_TEST_P(PrimitiveTest, ToString) { TypeParam s(this->testBool, this->testU32, this->testI16, this->testF64); 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); + + // Build the expected string representation buf2 << "( " << "mBool = " << this->testBool << ", " << "mU32 = " << this->testU32 << ", " << "mI16 = " << this->testI16 << ", " << "mF64 = " << std::fixed << this->testF64 << " )"; - ASSERT_STREQ(buf1.str().c_str(), buf2.str().c_str()); + // Verify operator<< output against standard Fw::String + Fw::String sTruncated(buf2.str().c_str()); + ASSERT_STREQ(buf1.str().c_str(), sTruncated.toChar()); + + // Verify full s.toString() output against large capacity buffer + Fw::StringTemplate<1024> sFull(buf2.str().c_str()); + ASSERT_STREQ(str.toChar(), sFull.toChar()); } REGISTER_TYPED_TEST_SUITE_P(PrimitiveTest,