@@ -38,6 +38,22 @@ using namespace api;
3838namespace
3939{
4040
41+ // ! \brief
42+ // ! Mock object for state restore unit tests.
43+ // !
44+ // ! DESCRIPTION:\n
45+ // ! CDataSearcher that returns an empty stream.
46+ // !
47+ class CEmptySearcher : public ml ::core::CDataSearcher
48+ {
49+ public:
50+ // ! Do a search that results in an empty input stream.
51+ virtual TIStreamP search (size_t /* currentDocNum*/ , size_t /* limit*/ )
52+ {
53+ return TIStreamP (new std::istringstream ());
54+ }
55+ };
56+
4157class CTestOutputHandler : public COutputHandler
4258{
4359 public:
@@ -325,6 +341,23 @@ void CFieldDataTyperTest::testHandleControlMessages(void)
325341 output.find (" [{\" flush\" :{\" id\" :\" 7\" ,\" last_finalized_bucket_end\" :0}}" ));
326342}
327343
344+ void CFieldDataTyperTest::testRestoreStateFailsWithEmptyState (void )
345+ {
346+ model::CLimits limits;
347+ CFieldConfig config;
348+ CPPUNIT_ASSERT (config.initFromFile (" testfiles/new_persist_categorization.conf" ));
349+
350+ std::ostringstream outputStrm;
351+ CNullOutput nullOutput;
352+ core::CJsonOutputStreamWrapper wrappedOutputStream (outputStrm);
353+ CJsonOutputWriter writer (" job" , wrappedOutputStream);
354+ CFieldDataTyper typer (" job" , config, limits, nullOutput, writer, nullptr );
355+
356+ core_t ::TTime completeToTime (0 );
357+ CEmptySearcher restoreSearcher;
358+ CPPUNIT_ASSERT (typer.restoreState (restoreSearcher, completeToTime) == false );
359+ }
360+
328361CppUnit::Test* CFieldDataTyperTest::suite ()
329362{
330363 CppUnit::TestSuite *suiteOfTests = new CppUnit::TestSuite (" CFieldDataTyperTest" );
@@ -341,6 +374,9 @@ CppUnit::Test* CFieldDataTyperTest::suite()
341374 suiteOfTests->addTest ( new CppUnit::TestCaller<CFieldDataTyperTest>(
342375 " CFieldDataTyperTest::testHandleControlMessages" ,
343376 &CFieldDataTyperTest::testHandleControlMessages) );
377+ suiteOfTests->addTest ( new CppUnit::TestCaller<CFieldDataTyperTest>(
378+ " CFieldDataTyperTest::testRestoreStateFailsWithEmptyState" ,
379+ &CFieldDataTyperTest::testRestoreStateFailsWithEmptyState) );
344380 return suiteOfTests;
345381}
346382
0 commit comments