@@ -756,4 +756,47 @@ void DpCatalogTester::test_ProcessFileInvalidDir() {
756756 this ->component .shutdown ();
757757}
758758
759+ void DpCatalogTester::test_MalformedFile () {
760+
761+ // 1. Setup paths and corrupted data
762+ Fw::FileNameString stateFile (" DpState.dat" );
763+
764+ BYTE buffer[sizeof (FwIndexType) + DpRecord::SERIALIZED_SIZE];
765+ memset (buffer, 0xFF , sizeof (buffer)); // Force deserialization failure
766+
767+ // 2. Write the malformed data to disk
768+ Os::File f;
769+ ASSERT_EQ (Os::File::OP_OK, f.open (stateFile.toChar (), Os::File::OPEN_CREATE, Os::FileInterface::OVERWRITE));
770+
771+ FwSizeType writeSize = sizeof (buffer);
772+ ASSERT_EQ (Os::File::OP_OK, f.write (buffer, writeSize));
773+ f.close ();
774+
775+ // 3. Configure the Component
776+ Fw::MallocAllocator mockAllocator;
777+ Fw::FileNameString dirs[DP_MAX_DIRECTORIES];
778+ this ->component .configure (dirs, 0 , stateFile, 0 , mockAllocator);
779+
780+ // 4. Dispatch the BUILD_CATALOG command
781+ this ->sendCmd_BUILD_CATALOG (0 , 0 );
782+ this ->component .doDispatch ();
783+
784+ // 5. Command should generate event instead of ASSERT
785+ ASSERT_CMD_RESPONSE_SIZE (1 );
786+ // ASSERT_CMD_RESPONSE(0, DpCatalogComponentBase::OPCODE_BUILD_CATALOG, 0, Fw::CmdResponse::EXECUTION_ERROR);
787+
788+ // High-priority warning event should be caught by this test
789+ ASSERT_EVENTS_SIZE (2 );
790+ ASSERT_EVENTS_FileCorruptedDataError_SIZE (1 );
791+ ASSERT_EVENTS_FileCorruptedDataError (
792+ 0 ,
793+ stateFile.toChar (),
794+ static_cast <I32>(Fw::FW_DESERIALIZE_FORMAT_ERROR)
795+ );
796+
797+ // 6. Cleanup
798+ Os::FileSystem::removeFile (stateFile.toChar ());
799+ this ->component .shutdown ();
800+ }
801+
759802} // namespace Svc
0 commit comments