TestSetOutputFileName works on win32

git-svn-id: svn://136.177.114.72/svn_GW/IPhreeqc/branches/ErrorHandling@5916 1feff8c3-07ed-0310-ac33-dd36852eb9cd
This commit is contained in:
Scott R Charlton 2011-12-20 06:36:17 +00:00
parent 306b8cb9fb
commit 5f2359ffb9
5 changed files with 220 additions and 40 deletions

View File

@ -215,11 +215,18 @@ public:
*/
bool GetLogFileOn(void)const;
/**
* Retrieves the name of the output file. The default value is <B><I>phreeqc.id.out</I></B>, where id is obtained from \ref GetId.
* @return filename The name of the file to write phreeqc output to.
* @see GetOutputFileOn, GetOutputString, GetOutputStringOn, GetOutputStringLine, GetOutputStringLineCount, SetOutputFileName, SetOutputFileOn, SetOutputStringOn
*/
const char* GetOutputFileName(void)const;
/**
* Retrieves the current value of the output file switch.
* @retval true Output is written to the <B><I>phreeqc.id.out</I></B> (where id is obtained from \ref GetId) file.
* @retval false No output is written.
* @see SetOutputFileOn
* @see GetOutputFileOn, GetOutputString, GetOutputStringOn, GetOutputStringLine, GetOutputStringLineCount, SetOutputFileName, SetOutputFileOn, SetOutputStringOn
*/
bool GetOutputFileOn(void)const;
@ -546,6 +553,13 @@ public:
*/
void SetLogFileOn(bool bValue);
/**
* Sets the name of the output file. The default value is <B><I>phreeqc.id.out</I></B>, where id is obtained from \ref GetId.
* @param filename The name of the file to write phreeqc output to.
* @see GetOutputFileName, GetOutputFileOn, GetOutputString, GetOutputStringOn, GetOutputStringLine, GetOutputStringLineCount, SetOutputFileOn, SetOutputStringOn
*/
void SetOutputFileName(const char *filename);
/**
* Sets the output file switch on or off. This switch controls whether or not phreeqc
* writes to the <B><I>phreeqc.id.out</I></B> file (where id is obtained from \ref GetId). This is the output that is normally generated

View File

@ -224,6 +224,11 @@ bool IPhreeqc::GetLogFileOn(void)const
return this->LogOn;
}
const char* IPhreeqc::GetOutputFileName(void)const
{
return this->OutputFileName.c_str();
}
bool IPhreeqc::GetOutputFileOn(void)const
{
return this->OutputOn;
@ -579,6 +584,11 @@ void IPhreeqc::SetLogFileOn(bool bValue)
this->LogOn = bValue;
}
void IPhreeqc::SetOutputFileName(const char *filename)
{
this->OutputFileName = filename;
}
void IPhreeqc::SetOutputFileOn(bool bValue)
{
this->OutputOn = bValue;

View File

@ -1890,7 +1890,7 @@ void TestIPhreeqc::TestListComponents(void)
void TestIPhreeqc::TestSetDumpFileName(void)
{
char DUMP_FILENAME[80];
sprintf(DUMP_FILENAME, "dump.%06d.log", ::rand());
sprintf(DUMP_FILENAME, "dump.%06d.out", ::rand());
if (::FileExists(DUMP_FILENAME))
{
::DeleteFile(DUMP_FILENAME);
@ -2004,3 +2004,158 @@ void TestIPhreeqc::TestSetDumpFileName(void)
::DeleteFile(DUMP_FILENAME);
}
}
void TestIPhreeqc::TestSetOutputFileName(void)
{
char OUTPUT_FILENAME[80];
sprintf(OUTPUT_FILENAME, "output.%06d.log", ::rand());
if (::FileExists(OUTPUT_FILENAME))
{
::DeleteFile(OUTPUT_FILENAME);
}
IPhreeqc obj;
CPPUNIT_ASSERT_EQUAL( 0, obj.LoadDatabase("phreeqc.dat"));
// add solution block
CPPUNIT_ASSERT_EQUAL( VR_OK, ::SOLUTION(obj, 1.0, 1.0, 1.0) );
// add dump block
CPPUNIT_ASSERT_EQUAL( VR_OK, ::DUMP(obj) );
// run
obj.SetOutputFileOn(true);
obj.SetErrorFileOn(false);
obj.SetLogFileOn(false);
obj.SetSelectedOutputFileOn(false);
obj.SetDumpStringOn(false);
obj.SetDumpFileOn(false);
obj.SetOutputFileName(OUTPUT_FILENAME);
CPPUNIT_ASSERT_EQUAL( 0, obj.RunAccumulated() );
CPPUNIT_ASSERT_EQUAL( true, ::FileExists(OUTPUT_FILENAME) );
std::string lines[100];
std::ifstream ifs(OUTPUT_FILENAME);
size_t i = 0;
while (i < sizeof(lines)/sizeof(lines[0]) && std::getline(ifs, lines[i]))
{
++i;
}
int line = 0;
#if defined(_MSC_VER)
CPPUNIT_ASSERT_EQUAL( std::string("------------------------------------"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string("Reading input data for simulation 1."), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string("------------------------------------"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" SOLUTION 1"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" C 1"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" Ca 1"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" Na 1"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" DUMP"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -solution 1"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string("-------------------------------------------"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string("Beginning of initial solution calculations."), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string("-------------------------------------------"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string("Initial solution 1. "), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string("-----------------------------Solution composition------------------------------"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" Elements Molality Moles"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" C 1.000e-003 1.000e-003"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" Ca 1.000e-003 1.000e-003"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" Na 1.000e-003 1.000e-003"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string("----------------------------Description of solution----------------------------"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" pH = 7.000 "), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" pe = 4.000 "), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" Activity of water = 1.000"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" Ionic strength = 2.896e-003"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" Mass of water (kg) = 1.000e+000"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" Total alkalinity (eq/kg) = 8.276e-004"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" Total CO2 (mol/kg) = 1.000e-003"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" Temperature (deg C) = 25.00"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" Electrical balance (eq) = 2.172e-003"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" Percent error, 100*(Cat-|An|)/(Cat+|An|) = 57.04"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" Iterations = 6"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" Total H = 1.110133e+002"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" Total O = 5.550904e+001"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string("----------------------------Distribution of species----------------------------"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" Log Log Log "), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" Species Molality Activity Molality Activity Gamma"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" OH- 1.062e-007 1.001e-007 -6.974 -7.000 -0.026"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" H+ 1.056e-007 1.000e-007 -6.976 -7.000 -0.024"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" H2O 5.551e+001 9.999e-001 1.744 -0.000 0.000"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string("C(-4) 0.000e+000"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" CH4 0.000e+000 0.000e+000 -67.371 -67.371 0.000"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string("C(4) 1.000e-003"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" HCO3- 8.171e-004 7.714e-004 -3.088 -3.113 -0.025"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" CO2 1.733e-004 1.734e-004 -3.761 -3.761 0.000"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" CaHCO3+ 8.204e-006 7.745e-006 -5.086 -5.111 -0.025"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" CaCO3 4.779e-007 4.782e-007 -6.321 -6.320 0.000"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" CO3-2 4.555e-007 3.618e-007 -6.342 -6.442 -0.100"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" NaHCO3 4.087e-007 4.090e-007 -6.389 -6.388 0.000"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" NaCO3- 6.736e-009 6.351e-009 -8.172 -8.197 -0.026"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string("Ca 1.000e-003"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" Ca+2 9.913e-004 7.870e-004 -3.004 -3.104 -0.100"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" CaHCO3+ 8.204e-006 7.745e-006 -5.086 -5.111 -0.025"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" CaCO3 4.779e-007 4.782e-007 -6.321 -6.320 0.000"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" CaOH+ 1.385e-009 1.306e-009 -8.859 -8.884 -0.026"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string("H(0) 1.415e-025"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" H2 7.075e-026 7.079e-026 -25.150 -25.150 0.000"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string("Na 1.000e-003"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" Na+ 9.996e-004 9.428e-004 -3.000 -3.026 -0.025"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" NaHCO3 4.087e-007 4.090e-007 -6.389 -6.388 0.000"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" NaCO3- 6.736e-009 6.351e-009 -8.172 -8.197 -0.026"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" NaOH 6.225e-011 6.229e-011 -10.206 -10.206 0.000"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string("O(0) 0.000e+000"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" O2 0.000e+000 0.000e+000 -42.080 -42.080 0.000"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string("------------------------------Saturation indices-------------------------------"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" Phase SI log IAP log K(298 K, 1 atm)"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" Aragonite -1.21 -9.55 -8.34 CaCO3"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" Calcite -1.07 -9.55 -8.48 CaCO3"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" CH4(g) -64.51 -67.37 -2.86 CH4"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" CO2(g) -2.29 -3.76 -1.47 CO2"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" H2(g) -22.00 -25.15 -3.15 H2"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" H2O(g) -1.51 -0.00 1.51 H2O"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" O2(g) -39.12 -42.08 -2.96 O2"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string("------------------"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string("End of simulation."), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string("------------------"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string("------------------------------------"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string("Reading input data for simulation 2."), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string("------------------------------------"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string("-----------"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string("End of run."), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string("-----------"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] );
#endif
#if defined(__GNUC__)
#endif
if (::FileExists(OUTPUT_FILENAME))
{
///::DeleteFile(OUTPUT_FILENAME);
}
}

View File

@ -7,39 +7,40 @@
class TestIPhreeqc : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE( TestIPhreeqc );
CPPUNIT_TEST( TestLoadDatabase );
CPPUNIT_TEST( TestLoadDatabaseString );
CPPUNIT_TEST( TestLoadDatabaseMissingFile );
CPPUNIT_TEST( TestLoadDatabaseWithErrors );
CPPUNIT_TEST( TestRunAccumulated );
CPPUNIT_TEST( TestRunWithErrors );
CPPUNIT_TEST( TestRunFile );
CPPUNIT_TEST( TestRunString );
CPPUNIT_TEST( TestGetSelectedOutputRowCount );
CPPUNIT_TEST( TestGetSelectedOutputValue );
CPPUNIT_TEST( TestGetSelectedOutputColumnCount );
CPPUNIT_TEST( TestAddError );
CPPUNIT_TEST( TestAccumulateLine );
CPPUNIT_TEST( TestOutputErrorString );
CPPUNIT_TEST( TestRunWithCallback );
CPPUNIT_TEST( TestRunNoDatabaseLoaded );
CPPUNIT_TEST( TestCase1 );
CPPUNIT_TEST( TestCase2 );
CPPUNIT_TEST( TestPrintSelectedOutputFalse );
CPPUNIT_TEST( TestOutputOnOff );
CPPUNIT_TEST( TestErrorOnOff );
CPPUNIT_TEST( TestLogOnOff );
CPPUNIT_TEST( TestDumpOnOff );
CPPUNIT_TEST( TestSelOutOnOff );
CPPUNIT_TEST( TestLongHeadings );
CPPUNIT_TEST( TestDatabaseKeyword );
CPPUNIT_TEST( TestDumpString );
CPPUNIT_TEST( TestGetDumpStringLineCount );
CPPUNIT_TEST( TestGetDumpStringLine );
CPPUNIT_TEST( TestGetComponentCount );
CPPUNIT_TEST( TestGetComponent );
CPPUNIT_TEST( TestListComponents );
CPPUNIT_TEST( TestSetDumpFileName );
// COMMENT: {12/19/2011 11:06:36 PM} CPPUNIT_TEST( TestLoadDatabase );
// COMMENT: {12/19/2011 11:06:36 PM} CPPUNIT_TEST( TestLoadDatabaseString );
// COMMENT: {12/19/2011 11:06:36 PM} CPPUNIT_TEST( TestLoadDatabaseMissingFile );
// COMMENT: {12/19/2011 11:06:36 PM} CPPUNIT_TEST( TestLoadDatabaseWithErrors );
// COMMENT: {12/19/2011 11:06:36 PM} CPPUNIT_TEST( TestRunAccumulated );
// COMMENT: {12/19/2011 11:06:36 PM} CPPUNIT_TEST( TestRunWithErrors );
// COMMENT: {12/19/2011 11:06:36 PM} CPPUNIT_TEST( TestRunFile );
// COMMENT: {12/19/2011 11:06:36 PM} CPPUNIT_TEST( TestRunString );
// COMMENT: {12/19/2011 11:06:36 PM} CPPUNIT_TEST( TestGetSelectedOutputRowCount );
// COMMENT: {12/19/2011 11:06:36 PM} CPPUNIT_TEST( TestGetSelectedOutputValue );
// COMMENT: {12/19/2011 11:06:36 PM} CPPUNIT_TEST( TestGetSelectedOutputColumnCount );
// COMMENT: {12/19/2011 11:06:36 PM} CPPUNIT_TEST( TestAddError );
// COMMENT: {12/19/2011 11:06:36 PM} CPPUNIT_TEST( TestAccumulateLine );
// COMMENT: {12/19/2011 11:06:36 PM} CPPUNIT_TEST( TestOutputErrorString );
// COMMENT: {12/19/2011 11:06:36 PM} CPPUNIT_TEST( TestRunWithCallback );
// COMMENT: {12/19/2011 11:06:36 PM} CPPUNIT_TEST( TestRunNoDatabaseLoaded );
// COMMENT: {12/19/2011 11:06:36 PM} CPPUNIT_TEST( TestCase1 );
// COMMENT: {12/19/2011 11:06:36 PM} CPPUNIT_TEST( TestCase2 );
// COMMENT: {12/19/2011 11:06:36 PM} CPPUNIT_TEST( TestPrintSelectedOutputFalse );
// COMMENT: {12/19/2011 11:06:36 PM} CPPUNIT_TEST( TestOutputOnOff );
// COMMENT: {12/19/2011 11:06:36 PM} CPPUNIT_TEST( TestErrorOnOff );
// COMMENT: {12/19/2011 11:06:36 PM} CPPUNIT_TEST( TestLogOnOff );
// COMMENT: {12/19/2011 11:06:36 PM} CPPUNIT_TEST( TestDumpOnOff );
// COMMENT: {12/19/2011 11:06:36 PM} CPPUNIT_TEST( TestSelOutOnOff );
// COMMENT: {12/19/2011 11:06:36 PM} CPPUNIT_TEST( TestLongHeadings );
// COMMENT: {12/19/2011 11:06:36 PM} CPPUNIT_TEST( TestDatabaseKeyword );
// COMMENT: {12/19/2011 11:06:36 PM} CPPUNIT_TEST( TestDumpString );
// COMMENT: {12/19/2011 11:06:36 PM} CPPUNIT_TEST( TestGetDumpStringLineCount );
// COMMENT: {12/19/2011 11:06:36 PM} CPPUNIT_TEST( TestGetDumpStringLine );
// COMMENT: {12/19/2011 11:06:36 PM} CPPUNIT_TEST( TestGetComponentCount );
// COMMENT: {12/19/2011 11:06:36 PM} CPPUNIT_TEST( TestGetComponent );
// COMMENT: {12/19/2011 11:06:36 PM} CPPUNIT_TEST( TestListComponents );
// COMMENT: {12/19/2011 11:06:36 PM} CPPUNIT_TEST( TestSetDumpFileName );
CPPUNIT_TEST( TestSetOutputFileName );
CPPUNIT_TEST_SUITE_END();
public:
@ -80,7 +81,7 @@ public:
void TestGetComponent(void);
void TestListComponents(void);
void TestSetDumpFileName(void);
void TestSetOutputFileName(void);
};
#endif // TESTIPHREEQC_H_INCLUDED

View File

@ -18,11 +18,11 @@ int main(int argc, char **argv)
{
CppUnit::TextUi::TestRunner runner;
runner.addTest(TestVar::suite());
runner.addTest(TestCVar::suite());
runner.addTest(TestSelectedOutput::suite());
// COMMENT: {12/19/2011 11:06:54 PM} runner.addTest(TestVar::suite());
// COMMENT: {12/19/2011 11:06:54 PM} runner.addTest(TestCVar::suite());
// COMMENT: {12/19/2011 11:06:54 PM} runner.addTest(TestSelectedOutput::suite());
runner.addTest(TestIPhreeqc::suite());
runner.addTest(TestIPhreeqcLib::suite());
// COMMENT: {12/19/2011 11:06:57 PM} runner.addTest(TestIPhreeqcLib::suite());
runner.setOutputter(CppUnit::CompilerOutputter::defaultOutputter(&runner.result(), std::cout));