@@ -29,6 +29,22 @@ using namespace api;
2929namespace
3030{
3131
32+ // ! \brief
33+ // ! Mock object for state restore unit tests.
34+ // !
35+ // ! DESCRIPTION:\n
36+ // ! CDataSearcher that returns an empty stream.
37+ // !
38+ class CEmptySearcher : public ml ::core::CDataSearcher
39+ {
40+ public:
41+ // ! Do a search that results in an empty input stream.
42+ virtual TIStreamP search (size_t /* currentDocNum*/ , size_t /* limit*/ )
43+ {
44+ return TIStreamP (new std::istringstream ());
45+ }
46+ };
47+
3248class CTestOutputHandler : public COutputHandler
3349{
3450 public:
@@ -316,6 +332,23 @@ void CFieldDataTyperTest::testHandleControlMessages(void)
316332 output.find (" [{\" flush\" :{\" id\" :\" 7\" ,\" last_finalized_bucket_end\" :0}}" ));
317333}
318334
335+ void CFieldDataTyperTest::testRestoreStateFailsWithEmptyState (void )
336+ {
337+ model::CLimits limits;
338+ CFieldConfig config;
339+ CPPUNIT_ASSERT (config.initFromFile (" testfiles/new_persist_categorization.conf" ));
340+
341+ std::ostringstream outputStrm;
342+ CNullOutput nullOutput;
343+ core::CJsonOutputStreamWrapper wrappedOutputStream (outputStrm);
344+ CJsonOutputWriter writer (" job" , wrappedOutputStream);
345+ CFieldDataTyper typer (" job" , config, limits, nullOutput, writer, nullptr );
346+
347+ core_t ::TTime completeToTime (0 );
348+ CEmptySearcher restoreSearcher;
349+ CPPUNIT_ASSERT (typer.restoreState (restoreSearcher, completeToTime) == false );
350+ }
351+
319352CppUnit::Test* CFieldDataTyperTest::suite ()
320353{
321354 CppUnit::TestSuite *suiteOfTests = new CppUnit::TestSuite (" CFieldDataTyperTest" );
@@ -332,6 +365,9 @@ CppUnit::Test* CFieldDataTyperTest::suite()
332365 suiteOfTests->addTest ( new CppUnit::TestCaller<CFieldDataTyperTest>(
333366 " CFieldDataTyperTest::testHandleControlMessages" ,
334367 &CFieldDataTyperTest::testHandleControlMessages) );
368+ suiteOfTests->addTest ( new CppUnit::TestCaller<CFieldDataTyperTest>(
369+ " CFieldDataTyperTest::testRestoreStateFailsWithEmptyState" ,
370+ &CFieldDataTyperTest::testRestoreStateFailsWithEmptyState) );
335371 return suiteOfTests;
336372}
337373
0 commit comments