fixed empty string bugs and added tests

git-svn-id: svn://136.177.114.72/svn_GW/IPhreeqc/branches/class@4168 1feff8c3-07ed-0310-ac33-dd36852eb9cd
This commit is contained in:
Scott R Charlton 2010-03-18 04:39:55 +00:00
parent cbcfbb6392
commit 0ec28bc18a
2 changed files with 15 additions and 2 deletions

View File

@ -1752,9 +1752,10 @@ int IPhreeqc::GetDumpLineCount(void)const
const char* IPhreeqc::GetDumpLine(int n)
{
static const char empty[] = "";
if (n < 0 || n >= this->GetDumpLineCount())
{
return 0;
return empty;
}
return this->DumpLines[n].c_str();
}
@ -1766,9 +1767,10 @@ int IPhreeqc::GetErrorLineCount(void)const
const char* IPhreeqc::GetErrorLine(int n)
{
static const char empty[] = "";
if (n < 0 || n >= this->GetErrorLineCount())
{
return 0;
return empty;
}
return this->ErrorLines[n].c_str();
}

View File

@ -1680,4 +1680,15 @@ TestInterface::TestGetDumpLine()
CPPUNIT_ASSERT_EQUAL( std::string(" -gammas"), std::string(::GetDumpLine(line++)) );
#endif
// remaining lines should be empty
CPPUNIT_ASSERT_EQUAL( std::string(""), std::string(::GetDumpLine(line++)) );
CPPUNIT_ASSERT_EQUAL( std::string(""), std::string(::GetDumpLine(line++)) );
CPPUNIT_ASSERT_EQUAL( std::string(""), std::string(::GetDumpLine(line++)) );
CPPUNIT_ASSERT_EQUAL( std::string(""), std::string(::GetDumpLine(line++)) );
// negative lines should be empty
CPPUNIT_ASSERT_EQUAL( std::string(""), std::string(::GetDumpLine(-1)) );
CPPUNIT_ASSERT_EQUAL( std::string(""), std::string(::GetDumpLine(-2)) );
CPPUNIT_ASSERT_EQUAL( std::string(""), std::string(::GetDumpLine(-3)) );
CPPUNIT_ASSERT_EQUAL( std::string(""), std::string(::GetDumpLine(-4)) );
}