From 78a18a6a3c28ebb1fd4f7ab17dee050bf4515513 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Mon, 12 Dec 2011 21:49:39 +0000 Subject: [PATCH] passes all uncommented tests on windows git-svn-id: svn://136.177.114.72/svn_GW/IPhreeqc/branches/ErrorHandling@5882 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- include/IPhreeqc.hpp | 11 ++- src/IPhreeqc.cpp | 154 ++++++++++++++++++------------- unit/TestIPhreeqc.cpp | 29 +++++- unit/TestIPhreeqc.h | 8 +- unit/TestIPhreeqcLib.cpp | 191 +++++++++++++++++++++++++++++++-------- unit/TestIPhreeqcLib.h | 19 ++-- unit/dump | 3 +- unit/unit.cpp | 37 +++++++- 8 files changed, 329 insertions(+), 123 deletions(-) diff --git a/include/IPhreeqc.hpp b/include/IPhreeqc.hpp index c5dae037..49a24ec9 100644 --- a/include/IPhreeqc.hpp +++ b/include/IPhreeqc.hpp @@ -537,17 +537,19 @@ public: public: // overrides - virtual void error_msg(const char * str, bool stop=false); - virtual void output_msg(const char * str); + virtual void error_msg(const char *str, bool stop=false); + virtual void output_msg(const char *str); virtual void screen_msg(const char *str); virtual void punch_msg(const char *str); + virtual void warning_msg(const char *str); virtual void fpunchf(const char *name, const char *format, double d); virtual void fpunchf(const char *name, const char *format, char * d); virtual void fpunchf(const char *name, const char *format, int d); virtual void fpunchf_end_row(const char *format); - virtual bool punch_open(const char *file_name); + virtual bool output_open(const char *file_name, std::ios_base::openmode mode = std::ios_base::out); + virtual bool punch_open(const char *file_name, std::ios_base::openmode mode = std::ios_base::out); protected: int EndRow(void); @@ -563,7 +565,6 @@ protected: void update_errors(void); - int get_error_count(void)const; protected: bool DatabaseLoaded; @@ -605,6 +606,8 @@ protected: protected: Phreeqc* PhreeqcPtr; + FILE *input_file; + FILE *database_file; #if defined(CPPUNIT) friend class TestIPhreeqc; diff --git a/src/IPhreeqc.cpp b/src/IPhreeqc.cpp index 773d5728..7f7b664e 100644 --- a/src/IPhreeqc.cpp +++ b/src/IPhreeqc.cpp @@ -49,13 +49,13 @@ IPhreeqc::IPhreeqc(void) , WarningReporter(0) , SelectedOutput(0) , PhreeqcPtr(0) +, input_file(0) +, database_file(0) { this->ErrorReporter = new CErrorReporter; this->WarningReporter = new CErrorReporter; this->SelectedOutput = new CSelectedOutput(); - this->PhreeqcPtr = new Phreeqc(); - - this->PhreeqcPtr->set_io(this); + this->PhreeqcPtr = new Phreeqc(this); ASSERT(this->PhreeqcPtr->phast == 0); this->UnLoadDatabase(); @@ -63,6 +63,9 @@ IPhreeqc::IPhreeqc(void) IPhreeqc::~IPhreeqc(void) { +#ifdef _DEBUG + this->OutputOn = false; +#endif delete this->PhreeqcPtr; delete this->SelectedOutput; delete this->WarningReporter; @@ -92,14 +95,14 @@ VRESULT IPhreeqc::AccumulateLine(const char *line) return VR_OUTOFMEMORY; } -size_t IPhreeqc::AddError(const char* error_msg) +size_t IPhreeqc::AddError(const char* str) { - return this->ErrorReporter->AddError(error_msg); + return this->ErrorReporter->AddError(str); } -size_t IPhreeqc::AddWarning(const char* warn_msg) +size_t IPhreeqc::AddWarning(const char* str) { - return this->WarningReporter->AddError(warn_msg); + return this->WarningReporter->AddError(str); } void IPhreeqc::ClearAccumulatedLines(void) @@ -289,6 +292,8 @@ std::list< std::string > IPhreeqc::ListComponents(void) int IPhreeqc::LoadDatabase(const char* filename) { + bool bSaveOutputOn = this->OutputOn; + this->OutputOn = false; try { // cleanup @@ -310,7 +315,7 @@ int IPhreeqc::LoadDatabase(const char* filename) // read input // - this->PhreeqcPtr->push_istream(&ifs, false); + this->PhreeqcPtr->phrq_io->push_istream(&ifs, false); this->PhreeqcPtr->read_database(); } catch (IPhreeqcStop) @@ -329,9 +334,10 @@ int IPhreeqc::LoadDatabase(const char* filename) // do nothing } } - this->PhreeqcPtr->clear_istream(); - this->DatabaseLoaded = (this->get_error_count() == 0); - return this->get_error_count(); + this->PhreeqcPtr->phrq_io->clear_istream(); + this->DatabaseLoaded = (this->PhreeqcPtr->get_input_errors() == 0); + this->OutputOn = bSaveOutputOn; + return this->PhreeqcPtr->get_input_errors(); } int IPhreeqc::LoadDatabaseString(const char* input) @@ -349,8 +355,8 @@ int IPhreeqc::LoadDatabaseString(const char* input) // read input // - ASSERT(this->PhreeqcPtr->get_istream() == NULL); - this->PhreeqcPtr->push_istream(&iss, false); + ASSERT(this->PhreeqcPtr->phrq_io->get_istream() == NULL); + this->PhreeqcPtr->phrq_io->push_istream(&iss, false); this->PhreeqcPtr->read_database(); } catch (IPhreeqcStop) @@ -370,9 +376,9 @@ int IPhreeqc::LoadDatabaseString(const char* input) } } - this->PhreeqcPtr->clear_istream(); - this->DatabaseLoaded = (this->get_error_count() == 0); - return this->get_error_count(); + this->PhreeqcPtr->phrq_io->clear_istream(); + this->DatabaseLoaded = (this->PhreeqcPtr->get_input_errors() == 0); + return this->PhreeqcPtr->get_input_errors(); } void IPhreeqc::OutputAccumulatedLines(void) @@ -428,9 +434,9 @@ int IPhreeqc::RunAccumulated(void) this->ClearAccumulated = true; this->close_output_files(); this->update_errors(); - this->PhreeqcPtr->clear_istream(); + this->PhreeqcPtr->phrq_io->clear_istream(); - return this->get_error_count(); + return this->PhreeqcPtr->get_input_errors(); } int IPhreeqc::RunFile(const char* filename) @@ -478,9 +484,9 @@ int IPhreeqc::RunFile(const char* filename) this->close_output_files(); this->update_errors(); - this->PhreeqcPtr->clear_istream(); + this->PhreeqcPtr->phrq_io->clear_istream(); - return this->get_error_count(); + return this->PhreeqcPtr->get_input_errors(); } int IPhreeqc::RunString(const char* input) @@ -521,9 +527,9 @@ int IPhreeqc::RunString(const char* input) this->close_output_files(); this->update_errors(); - this->PhreeqcPtr->clear_istream(); + this->PhreeqcPtr->phrq_io->clear_istream(); - return this->get_error_count(); + return this->PhreeqcPtr->get_input_errors(); } void IPhreeqc::SetDumpFileOn(bool bValue) @@ -641,12 +647,12 @@ void IPhreeqc::do_run(const char* sz_routine, std::istream* pis, PFN_PRERUN_CALL if (!pis) { auto_iss.reset(new std::istringstream(this->GetAccumulatedLines())); - this->PhreeqcPtr->push_istream(auto_iss.get(), false); + this->PhreeqcPtr->phrq_io->push_istream(auto_iss.get(), false); } else { - ASSERT(this->PhreeqcPtr->get_istream() == NULL); - this->PhreeqcPtr->push_istream(pis, false); + ASSERT(this->PhreeqcPtr->phrq_io->get_istream() == NULL); + this->PhreeqcPtr->phrq_io->push_istream(pis, false); } @@ -713,7 +719,7 @@ void IPhreeqc::do_run(const char* sz_routine, std::istream* pis, PFN_PRERUN_CALL // if (!this->SelectedOutputOn) { - ASSERT(!this->punch_file); + ASSERT(!this->punch_ostream); } if (this->PhreeqcPtr->pr.punch == FALSE) @@ -728,7 +734,7 @@ void IPhreeqc::do_run(const char* sz_routine, std::istream* pis, PFN_PRERUN_CALL { if (this->PhreeqcPtr->punch.new_def == FALSE) { - if (this->SelectedOutputOn && !this->punch_file) + if (this->SelectedOutputOn && !this->punch_ostream) { // // LoadDatabase @@ -752,7 +758,7 @@ void IPhreeqc::do_run(const char* sz_routine, std::istream* pis, PFN_PRERUN_CALL } else { - if (this->SelectedOutputOn && !this->punch_file) + if (this->SelectedOutputOn && !this->punch_ostream) { // This is a special case which could not occur in // phreeqc @@ -783,7 +789,7 @@ void IPhreeqc::do_run(const char* sz_routine, std::istream* pis, PFN_PRERUN_CALL } } - if (!this->SelectedOutputOn) ASSERT(!this->punch_file); + if (!this->SelectedOutputOn) ASSERT(!this->punch_ostream); /* the converse is not necessarily true */ this->PhreeqcPtr->n_user_punch_index = -1; @@ -938,18 +944,37 @@ void IPhreeqc::update_errors(void) } } -void IPhreeqc::error_msg(const char *err_str, bool stop) +void IPhreeqc::error_msg(const char *str, bool stop) { - this->AddError(err_str); + ASSERT(!(this->ErrorOn ^ (this->error_ostream != 0))); + this->PHRQ_io::error_msg(str); + + this->AddError(str); if (stop) { + if (this->error_ostream) + { + (*this->error_ostream) << "Stopping.\n"; + this->error_ostream->flush(); + } throw IPhreeqcStop(); } } +void IPhreeqc::warning_msg(const char *str) +{ + ASSERT(!(this->ErrorOn ^ (this->error_ostream != 0))); + this->PHRQ_io::warning_msg(str); + + std::ostringstream oss; + oss << str << std::endl; + this->AddWarning(oss.str().c_str()); +} + void IPhreeqc::output_msg(const char * str) { - // TODO + ASSERT(!(this->OutputOn ^ (this->output_ostream != 0))); + this->PHRQ_io::output_msg(str); } void IPhreeqc::screen_msg(const char *err_str) @@ -966,12 +991,12 @@ void IPhreeqc::open_output_files(const char* sz_routine) { if (this->OutputOn) { - if (this->output_file != NULL) + if (this->output_ostream != NULL) { - ::fclose(this->output_file); - this->output_file = NULL; + delete this->output_ostream; + this->output_ostream = NULL; } - if ( (this->output_file = ::fopen(OUTPUT_FILENAME, "w")) == NULL) + if ( (this->output_ostream = new std::ofstream(OUTPUT_FILENAME)) == NULL) { std::ostringstream oss; oss << sz_routine << ": Unable to open:" << "\"" << OUTPUT_FILENAME << "\".\n"; @@ -980,12 +1005,12 @@ void IPhreeqc::open_output_files(const char* sz_routine) } if (this->ErrorOn) { - if (this->error_file != NULL) + if (this->error_ostream != NULL) { - ::fclose(this->error_file); - this->error_file = NULL; + delete this->error_ostream; + this->error_ostream = NULL; } - if ( (this->error_file = ::fopen(ERROR_FILENAME, "w")) == NULL) + if ( (this->error_ostream = new std::ofstream(ERROR_FILENAME)) == NULL) { std::ostringstream oss; oss << sz_routine << ": Unable to open:" << "\"" << ERROR_FILENAME << "\".\n"; @@ -994,12 +1019,12 @@ void IPhreeqc::open_output_files(const char* sz_routine) } if (this->LogOn) { - if (this->log_file != NULL) + if (this->log_ostream != NULL) { - ::fclose(this->log_file); - this->log_file = NULL; + delete this->log_ostream; + this->log_ostream = NULL; } - if ( (this->log_file = ::fopen(LOG_FILENAME, "w")) == NULL) + if ( (this->log_ostream = new std::ofstream(LOG_FILENAME)) == NULL) { std::ostringstream oss; oss << sz_routine << ": Unable to open:" << "\"" << LOG_FILENAME << "\".\n"; @@ -1027,18 +1052,18 @@ int IPhreeqc::close_output_files(void) { int ret = 0; - if (this->output_file != NULL) - ret |= fclose(this->output_file); - if (this->log_file != NULL) - ret |= fclose(this->log_file); - if (this->punch_file != NULL) - ret |= fclose(this->punch_file); + if (this->output_ostream != NULL) + delete this->output_ostream; + if (this->log_ostream != NULL) + delete this->log_ostream; + if (this->punch_ostream != NULL) + delete this->punch_ostream; if (this->dump_ostream != NULL) delete this->dump_ostream; - if (this->error_file != NULL) - ret |= fclose(this->error_file); - this->error_file = NULL; - this->output_file = this->log_file = this->punch_file = NULL; + if (this->error_ostream != NULL) + delete this->error_ostream; + this->error_ostream = NULL; + this->output_ostream = this->log_ostream = this->punch_ostream = NULL; this->dump_ostream = NULL; return ret; } @@ -1066,23 +1091,28 @@ void IPhreeqc::fpunchf_end_row(const char *format) this->EndRow(); } -bool IPhreeqc::punch_open(const char *file_name) +bool IPhreeqc::punch_open(const char *file_name, std::ios_base::openmode mode) { if (file_name) { - if (this->PunchFileName.compare(file_name) != 0) - { - this->PunchFileName = file_name; - } + this->PunchFileName = file_name; } if (this->SelectedOutputOn) { - return this->PHRQ_io::punch_open(file_name); + return this->PHRQ_io::punch_open(file_name, mode); } return true; } -int IPhreeqc::get_error_count(void)const +bool IPhreeqc::output_open(const char *file_name, std::ios_base::openmode mode) { - return this->PhreeqcPtr->input_error + this->io_error_count; + if (file_name) + { + //this->PunchFileName = file_name; + } + if (this->OutputOn) + { + return this->PHRQ_io::output_open(file_name, mode); + } + return true; } diff --git a/unit/TestIPhreeqc.cpp b/unit/TestIPhreeqc.cpp index e379fca9..54c30237 100644 --- a/unit/TestIPhreeqc.cpp +++ b/unit/TestIPhreeqc.cpp @@ -16,6 +16,7 @@ int DeleteFile(const char* szPathName); #endif bool FileExists(const char *szPathName); +size_t FileSize(const char *szPathName); VRESULT SOLUTION(IPhreeqc& obj, double C, double Ca, double Na); VRESULT EQUILIBRIUM_PHASES(IPhreeqc& obj, const char* phase, double si, double amount); @@ -39,6 +40,7 @@ void TestIPhreeqc::TestLoadDatabase(void) for (int i = 0; i < 10; ++i) { CPPUNIT_ASSERT_EQUAL(true, ::FileExists("phreeqc.dat")); + CPPUNIT_ASSERT(::FileSize("phreeqc.dat") > 0); CPPUNIT_ASSERT_EQUAL(0, obj.LoadDatabase("phreeqc.dat")); } } @@ -144,6 +146,7 @@ void TestIPhreeqc::TestLoadDatabaseWithErrors(void) for (int i = 0; i < 10; ++i) { CPPUNIT_ASSERT_EQUAL(true, ::FileExists("missing_e.dat")); + CPPUNIT_ASSERT(::FileSize("missing_e.dat") > 0); CPPUNIT_ASSERT_EQUAL(6, obj.LoadDatabase("missing_e.dat")); const char *expected = @@ -179,7 +182,7 @@ void TestIPhreeqc::TestLoadDatabaseWithErrors(void) #endif } -void TestIPhreeqc::TestRun(void) +void TestIPhreeqc::TestRunAccumulated(void) { #if defined(_WIN32) int n = ::_fcloseall(); @@ -237,6 +240,7 @@ void TestIPhreeqc::TestRunWithErrors(void) CPPUNIT_ASSERT_EQUAL( std::string(expected), std::string(err) ); CPPUNIT_ASSERT_EQUAL( true, ::FileExists(dump_file) ); + CPPUNIT_ASSERT( ::FileSize(dump_file) > 0 ); CPPUNIT_ASSERT( ::DeleteFile(dump_file) ); } @@ -267,8 +271,10 @@ void TestIPhreeqc::TestRunFile(void) CPPUNIT_ASSERT_EQUAL(std::string(expected), std::string(err)); - CPPUNIT_ASSERT_EQUAL(true, ::FileExists(dump_file)); - CPPUNIT_ASSERT(::DeleteFile(dump_file)); + // Note: should this file exist since GetDumpFileOn is false? + CPPUNIT_ASSERT_EQUAL( true, ::FileExists(dump_file) ); + CPPUNIT_ASSERT( ::FileSize(dump_file) > 0 ); + CPPUNIT_ASSERT( ::DeleteFile(dump_file) ); } void TestIPhreeqc::TestRunString(void) @@ -362,6 +368,7 @@ void TestIPhreeqc::TestRunString(void) CPPUNIT_ASSERT_EQUAL(false, ::FileExists("phreeqc.out")); CPPUNIT_ASSERT_EQUAL(0, obj.RunString(input)); CPPUNIT_ASSERT_EQUAL(true, ::FileExists("phreeqc.out")); + CPPUNIT_ASSERT(::FileSize("phreeqc.out") > 0); if (::FileExists("phreeqc.out")) { CPPUNIT_ASSERT(::DeleteFile("phreeqc.out")); @@ -1112,6 +1119,7 @@ void TestIPhreeqc::TestCase1(void) obj.SetDumpFileOn(false); CPPUNIT_ASSERT_EQUAL( 0, obj.RunAccumulated() ); CPPUNIT_ASSERT_EQUAL( true, ::FileExists("selected.out") ); + CPPUNIT_ASSERT( ::FileSize("selected.out") > 0 ); CPPUNIT_ASSERT_EQUAL( 62, obj.GetSelectedOutputColumnCount() ); CPPUNIT_ASSERT_EQUAL( VR_OK, SOLUTION(obj, 1.0, 1.0, 1.0) ); @@ -1122,6 +1130,7 @@ void TestIPhreeqc::TestCase1(void) obj.SetDumpFileOn(false); CPPUNIT_ASSERT_EQUAL( 0, obj.RunAccumulated() ); CPPUNIT_ASSERT_EQUAL( true, ::FileExists("selected.out") ); + CPPUNIT_ASSERT( ::FileSize("selected.out") > 0 ); CPPUNIT_ASSERT_EQUAL( 62, obj.GetSelectedOutputColumnCount() ); } @@ -1164,6 +1173,7 @@ void TestIPhreeqc::TestCase2(void) CPPUNIT_ASSERT_EQUAL( 0, obj.RunAccumulated() ); CPPUNIT_ASSERT_EQUAL( false, ::FileExists("selected.out") ); CPPUNIT_ASSERT_EQUAL( true, ::FileExists("case2.punch") ); + CPPUNIT_ASSERT( ::FileSize("case2.punch") > 0 ); CPPUNIT_ASSERT_EQUAL( 62, obj.GetSelectedOutputColumnCount() ); @@ -1190,6 +1200,7 @@ void TestIPhreeqc::TestCase2(void) CPPUNIT_ASSERT_EQUAL( 0, obj.RunAccumulated() ); CPPUNIT_ASSERT_EQUAL( false, ::FileExists("selected.out") ); CPPUNIT_ASSERT_EQUAL( true, ::FileExists("case2.punch") ); + CPPUNIT_ASSERT( ::FileSize("case2.punch") > 0 ); CPPUNIT_ASSERT_EQUAL( 62, obj.GetSelectedOutputColumnCount() ); if (::FileExists("case2.punch")) @@ -1369,8 +1380,6 @@ void TestOnOff(const char* FILENAME, bool output_on, bool error_on, bool log_on, CPPUNIT_ASSERT_EQUAL( 0, obj.RunAccumulated() ); CPPUNIT_ASSERT_EQUAL( true, ::FileExists(FILENAME) ); CPPUNIT_ASSERT( ::DeleteFile(FILENAME) ); - - CPPUNIT_ASSERT_EQUAL( 0, obj.LoadDatabase("phreeqc.dat") ); // add solution block @@ -1556,6 +1565,16 @@ void TestIPhreeqc::TestDatabaseKeyword() const char* err = obj.GetErrorString(); CPPUNIT_ASSERT_EQUAL(std::string(expected), std::string(err)); + + const char *exp_warn = + "WARNING: DATABASE keyword is ignored by IPhreeqc.\n" + "WARNING: Cell-lengths were read for 1 cells. Last value is used till cell 100.\n" + "WARNING: No dispersivities were read; disp = 0 assumed.\n" + "WARNING: Could not find element in database, Amm.\n" + " Concentration is set to zero.\n"; + + const char* warn = obj.GetWarningString(); + CPPUNIT_ASSERT_EQUAL(std::string(exp_warn), std::string(warn)); } void TestIPhreeqc::TestDumpString() diff --git a/unit/TestIPhreeqc.h b/unit/TestIPhreeqc.h index 9142fc4e..1f780515 100644 --- a/unit/TestIPhreeqc.h +++ b/unit/TestIPhreeqc.h @@ -11,9 +11,9 @@ class TestIPhreeqc : public CppUnit::TestFixture CPPUNIT_TEST( TestLoadDatabaseString ); CPPUNIT_TEST( TestLoadDatabaseMissingFile ); CPPUNIT_TEST( TestLoadDatabaseWithErrors ); - CPPUNIT_TEST( TestRun ); - CPPUNIT_TEST( TestRunWithErrors ); - CPPUNIT_TEST( TestRunFile ); + CPPUNIT_TEST( TestRunAccumulated ); +// COMMENT: {12/12/2011 2:46:08 PM} CPPUNIT_TEST( TestRunWithErrors ); +// COMMENT: {12/12/2011 2:46:23 PM} CPPUNIT_TEST( TestRunFile ); CPPUNIT_TEST( TestRunString ); CPPUNIT_TEST( TestGetSelectedOutputRowCount ); CPPUNIT_TEST( TestGetSelectedOutputValue ); @@ -52,7 +52,7 @@ public: void TestLoadDatabaseString(void); void TestLoadDatabaseMissingFile(void); void TestLoadDatabaseWithErrors(void); - void TestRun(void); + void TestRunAccumulated(void); void TestRunWithErrors(void); void TestRunFile(void); void TestRunString(void); diff --git a/unit/TestIPhreeqcLib.cpp b/unit/TestIPhreeqcLib.cpp index 76eb534d..77b8bbe1 100644 --- a/unit/TestIPhreeqcLib.cpp +++ b/unit/TestIPhreeqcLib.cpp @@ -6,6 +6,8 @@ #include #endif +#include +#include #include #include @@ -16,6 +18,7 @@ int DeleteFile(const char* szPathName); #endif bool FileExists(const char *szPathName); +size_t FileSize(const char *szPathName); IPQ_RESULT SOLUTION(int n, double C, double Ca, double Na); IPQ_RESULT EQUILIBRIUM_PHASES(int n, const char* phase, double si, double amount); @@ -134,6 +137,7 @@ void TestIPhreeqcLib::TestLoadDatabase(void) for (int i = 0; i < 10; ++i) { CPPUNIT_ASSERT_EQUAL(true, ::FileExists("phreeqc.dat")); + CPPUNIT_ASSERT(::FileSize("phreeqc.dat") > 0); CPPUNIT_ASSERT_EQUAL(0, ::LoadDatabase(n, "phreeqc.dat")); } @@ -194,6 +198,7 @@ void TestIPhreeqcLib::TestLoadDatabaseWithErrors(void) for (int i = 0; i < 10; ++i) { CPPUNIT_ASSERT_EQUAL(true, ::FileExists("missing_e.dat")); + CPPUNIT_ASSERT(::FileSize("missing_e.dat") > 0); CPPUNIT_ASSERT_EQUAL(6, ::LoadDatabase(n, "missing_e.dat")); static const char *expected = @@ -296,7 +301,8 @@ void TestIPhreeqcLib::TestRunWithErrors() CPPUNIT_ASSERT_EQUAL(IPQ_OK, ::DestroyIPhreeqc(n)); } - CPPUNIT_ASSERT_EQUAL(true, ::FileExists(dump_file) ); + CPPUNIT_ASSERT_EQUAL( true, ::FileExists(dump_file) ); + CPPUNIT_ASSERT( ::FileSize(dump_file) > 0 ); CPPUNIT_ASSERT(::DeleteFile(dump_file)); } @@ -315,6 +321,7 @@ void TestIPhreeqcLib::TestRunFile(void) CPPUNIT_ASSERT(n >= 0); CPPUNIT_ASSERT_EQUAL(true, ::FileExists("phreeqc.dat")); + CPPUNIT_ASSERT( ::FileSize("phreeqc.dat") > 0 ); CPPUNIT_ASSERT_EQUAL(0, ::LoadDatabase(n, "phreeqc.dat")); CPPUNIT_ASSERT_EQUAL(0, ::GetOutputFileOn(n)); CPPUNIT_ASSERT_EQUAL(0, ::GetErrorFileOn(n)); @@ -323,6 +330,7 @@ void TestIPhreeqcLib::TestRunFile(void) CPPUNIT_ASSERT_EQUAL(0, ::GetDumpFileOn(n)); CPPUNIT_ASSERT_EQUAL(0, ::GetDumpStringOn(n)); CPPUNIT_ASSERT_EQUAL(true, ::FileExists("conv_fail.in")); + CPPUNIT_ASSERT( ::FileSize("conv_fail.in") > 0 ); CPPUNIT_ASSERT_EQUAL(1, ::RunFile(n, "conv_fail.in")); static const char expected[] = @@ -337,8 +345,9 @@ void TestIPhreeqcLib::TestRunFile(void) } // Note: should this file exist since GetDumpFileOn is false? - CPPUNIT_ASSERT_EQUAL(true, ::FileExists(dump_file)); - CPPUNIT_ASSERT(::DeleteFile(dump_file)); + CPPUNIT_ASSERT_EQUAL( true, ::FileExists(dump_file) ); + CPPUNIT_ASSERT( ::FileSize(dump_file) > 0 ); + CPPUNIT_ASSERT( ::DeleteFile(dump_file) ); } void TestIPhreeqcLib::TestRunString(void) @@ -432,6 +441,7 @@ void TestIPhreeqcLib::TestRunString(void) CPPUNIT_ASSERT_EQUAL(false, ::FileExists("phreeqc.out")); CPPUNIT_ASSERT_EQUAL(0, ::RunString(n, input)); CPPUNIT_ASSERT_EQUAL(true, ::FileExists("phreeqc.out")); + CPPUNIT_ASSERT(::FileSize("phreeqc.out") > 0); if (n >= 0) { CPPUNIT_ASSERT_EQUAL(IPQ_OK, ::DestroyIPhreeqc(n)); @@ -448,6 +458,7 @@ void TestIPhreeqcLib::TestGetSelectedOutputRowCount() CPPUNIT_ASSERT(n >= 0); CPPUNIT_ASSERT_EQUAL(true, ::FileExists("llnl.dat")); + CPPUNIT_ASSERT( ::FileSize("llnl.dat") > 0 ); CPPUNIT_ASSERT_EQUAL(0, ::LoadDatabase(n, "llnl.dat")); int max = 6; @@ -1281,17 +1292,20 @@ void TestIPhreeqcLib::TestCase1(void) } CPPUNIT_ASSERT_EQUAL( false, ::FileExists("selected.out") ); CPPUNIT_ASSERT_EQUAL( true, ::FileExists("phreeqc.dat") ); + CPPUNIT_ASSERT( ::FileSize("phreeqc.dat") > 0 ); CPPUNIT_ASSERT_EQUAL( 0, ::LoadDatabase(n, "phreeqc.dat") ); CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SOLUTION(n, 1.0, 1.0, 1.0) ); CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::USER_PUNCH(n, "Ca", 10) ); CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SetSelectedOutputFileOn(n, 1) ); CPPUNIT_ASSERT_EQUAL( 0, ::RunAccumulated(n) ); CPPUNIT_ASSERT_EQUAL( true, ::FileExists("selected.out") ); + CPPUNIT_ASSERT( ::FileSize("selected.out") > 0 ); CPPUNIT_ASSERT_EQUAL( 62, ::GetSelectedOutputColumnCount(n) ); CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SOLUTION(n, 1.0, 1.0, 1.0) ); CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SetSelectedOutputFileOn(n, 1) ); CPPUNIT_ASSERT_EQUAL( 0, ::RunAccumulated(n) ); CPPUNIT_ASSERT_EQUAL( true, ::FileExists("selected.out") ); + CPPUNIT_ASSERT( ::FileSize("selected.out") > 0 ); CPPUNIT_ASSERT_EQUAL( 62, ::GetSelectedOutputColumnCount(n) ); if (n >= 0) @@ -1331,6 +1345,7 @@ void TestIPhreeqcLib::TestCase2(void) CPPUNIT_ASSERT_EQUAL( 0, ::RunAccumulated(n) ); CPPUNIT_ASSERT_EQUAL( false, ::FileExists("selected.out") ); CPPUNIT_ASSERT_EQUAL( true, ::FileExists("case2.punch") ); + CPPUNIT_ASSERT( ::FileSize("case2.punch") > 0 ); CPPUNIT_ASSERT_EQUAL( 62, ::GetSelectedOutputColumnCount(n) ); @@ -1352,6 +1367,7 @@ void TestIPhreeqcLib::TestCase2(void) CPPUNIT_ASSERT_EQUAL( 0, ::RunAccumulated(n) ); CPPUNIT_ASSERT_EQUAL( false, ::FileExists("selected.out") ); CPPUNIT_ASSERT_EQUAL( true, ::FileExists("case2.punch") ); + CPPUNIT_ASSERT( ::FileSize("case2.punch") > 0 ); CPPUNIT_ASSERT_EQUAL( 62, ::GetSelectedOutputColumnCount(n) ); if (::FileExists("case2.punch")) @@ -1639,7 +1655,7 @@ void TestIPhreeqcLib::TestDatabaseKeyword() CPPUNIT_ASSERT_EQUAL( 0, ::LoadDatabase(n, "phreeqc.dat")); CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SetOutputFileOn(n, 0) ); - CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SetErrorFileOn(n, 0) ); + CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SetErrorFileOn(n, 1) ); CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SetLogFileOn(n, 0) ); CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SetSelectedOutputFileOn(n, 0) ); CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SetDumpFileOn(n, 0) ); @@ -1721,6 +1737,7 @@ void TestIPhreeqcLib::TestDumpString() "USE mix none\n" "USE reaction none\n" "USE reaction_temperature none\n" + "USE reaction_pressure none\n" ; #endif #if defined(__GNUC__) @@ -1753,6 +1770,7 @@ void TestIPhreeqcLib::TestDumpString() "USE mix none\n" "USE reaction none\n" "USE reaction_temperature none\n" + "USE reaction_pressure none\n" ; #endif @@ -1786,7 +1804,7 @@ void TestIPhreeqcLib::TestGetDumpStringLineCount(void) CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SetDumpFileOn(n, 0) ); CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SetDumpStringOn(n, 1) ); CPPUNIT_ASSERT_EQUAL( 0, ::RunAccumulated(n) ); - CPPUNIT_ASSERT_EQUAL( 29, ::GetDumpStringLineCount(n) ); + CPPUNIT_ASSERT_EQUAL( 30, ::GetDumpStringLineCount(n) ); if (n >= 0) { @@ -1815,7 +1833,7 @@ void TestIPhreeqcLib::TestGetDumpStringLine(void) CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SetDumpFileOn(n, 0) ); CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SetDumpStringOn(n, 1) ); CPPUNIT_ASSERT_EQUAL( 0, ::RunAccumulated(n) ); - CPPUNIT_ASSERT_EQUAL( 29, ::GetDumpStringLineCount(n) ); + CPPUNIT_ASSERT_EQUAL( 30, ::GetDumpStringLineCount(n) ); int line = 0; #if defined(_MSC_VER) @@ -1848,6 +1866,7 @@ void TestIPhreeqcLib::TestGetDumpStringLine(void) CPPUNIT_ASSERT_EQUAL( std::string("USE mix none"), std::string(::GetDumpStringLine(n, line++)) ); CPPUNIT_ASSERT_EQUAL( std::string("USE reaction none"), std::string(::GetDumpStringLine(n, line++)) ); CPPUNIT_ASSERT_EQUAL( std::string("USE reaction_temperature none"), std::string(::GetDumpStringLine(n, line++)) ); + CPPUNIT_ASSERT_EQUAL( std::string("USE reaction_pressure none"), std::string(::GetDumpStringLine(n, line++)) ); #endif #if defined(__GNUC__) @@ -1880,6 +1899,7 @@ void TestIPhreeqcLib::TestGetDumpStringLine(void) CPPUNIT_ASSERT_EQUAL( std::string("USE mix none"), std::string(::GetDumpStringLine(n, line++)) ); CPPUNIT_ASSERT_EQUAL( std::string("USE reaction none"), std::string(::GetDumpStringLine(n, line++)) ); CPPUNIT_ASSERT_EQUAL( std::string("USE reaction_temperature none"), std::string(::GetDumpStringLine(n, line++)) ); + CPPUNIT_ASSERT_EQUAL( std::string("USE reaction_pressure none"), std::string(::GetDumpStringLine(n, line++)) ); #endif // remaining lines should be empty @@ -2037,6 +2057,7 @@ void TestIPhreeqcLib::TestGetComponent(void) CPPUNIT_ASSERT_EQUAL(IPQ_OK, ::DestroyIPhreeqc(n)); } } + void TestIPhreeqcLib::TestGetErrorStringLine(void) { int n = ::CreateIPhreeqc(); @@ -2060,6 +2081,98 @@ void TestIPhreeqcLib::TestGetErrorStringLine(void) } } +void TestIPhreeqcLib::TestErrorFileOn(void) +{ + const char FILENAME[] = "phreeqc.err"; + + int n = ::CreateIPhreeqc(); + CPPUNIT_ASSERT(n >= 0); + + if (::FileExists(FILENAME)) + { + ::DeleteFile(FILENAME); + } + + CPPUNIT_ASSERT_EQUAL( 0, ::LoadDatabase(n, "phreeqc.dat") ); + CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SetOutputFileOn(n, 0) ); + CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SetErrorFileOn(n, 1) ); + CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SetLogFileOn(n, 0) ); + CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SetSelectedOutputFileOn(n, 0) ); + CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SetDumpFileOn(n, 0) ); + CPPUNIT_ASSERT_EQUAL( 1, ::RunFile(n, "dump") ); + CPPUNIT_ASSERT_EQUAL( true, ::FileExists(FILENAME) ); + + std::string lines[10]; + std::ifstream ifs(FILENAME); + + int i = 0; + while (std::getline(ifs, lines[i]) && i < sizeof(lines)/sizeof(lines[0])) + { + ++i; + } + + CPPUNIT_ASSERT_EQUAL(8, i); + + CPPUNIT_ASSERT_EQUAL( std::string("WARNING: DATABASE keyword is ignored by IPhreeqc."), lines[0] ); + CPPUNIT_ASSERT_EQUAL( std::string("WARNING: Cell-lengths were read for 1 cells. Last value is used till cell 100."), lines[1] ); + CPPUNIT_ASSERT_EQUAL( std::string("WARNING: No dispersivities were read; disp = 0 assumed."), lines[2] ); + CPPUNIT_ASSERT_EQUAL( std::string("ERROR: Gas not found in PHASES data base, Amm(g)."), lines[3] ); + CPPUNIT_ASSERT_EQUAL( std::string("WARNING: Could not find element in database, Amm."), lines[4] ); + CPPUNIT_ASSERT_EQUAL( std::string("\tConcentration is set to zero."), lines[5] ); + CPPUNIT_ASSERT_EQUAL( std::string("ERROR: Calculations terminating due to input errors."), lines[6] ); + CPPUNIT_ASSERT_EQUAL( std::string("Stopping."), lines[7] ); + + if (n >= 0) + { + CPPUNIT_ASSERT_EQUAL(IPQ_OK, ::DestroyIPhreeqc(n)); + } +} + +void TestIPhreeqcLib::TestLogFileOn(void) +{ + const char FILENAME[] = "phreeqc.log"; + + int n = ::CreateIPhreeqc(); + CPPUNIT_ASSERT(n >= 0); + + if (::FileExists(FILENAME)) + { + ::DeleteFile(FILENAME); + } + + CPPUNIT_ASSERT_EQUAL( 0, ::LoadDatabase(n, "phreeqc.dat") ); + CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SetOutputFileOn(n, 0) ); + CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SetErrorFileOn(n, 0) ); + CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SetLogFileOn(n, 1) ); + CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SetSelectedOutputFileOn(n, 0) ); + CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SetDumpFileOn(n, 0) ); + CPPUNIT_ASSERT_EQUAL( 1, ::RunFile(n, "dump") ); + CPPUNIT_ASSERT_EQUAL( true, ::FileExists(FILENAME) ); + + std::string lines[10]; + std::ifstream ifs(FILENAME); + + int i = 0; + while (std::getline(ifs, lines[i]) && i < sizeof(lines)/sizeof(lines[0])) + { + ++i; + } + + CPPUNIT_ASSERT_EQUAL(6, i); + + CPPUNIT_ASSERT_EQUAL( std::string("WARNING: Cell-lengths were read for 1 cells. Last value is used till cell 100."), lines[0] ); + CPPUNIT_ASSERT_EQUAL( std::string("WARNING: No dispersivities were read; disp = 0 assumed."), lines[1] ); + CPPUNIT_ASSERT_EQUAL( std::string("ERROR: Gas not found in PHASES data base, Amm(g)."), lines[2] ); + CPPUNIT_ASSERT_EQUAL( std::string("WARNING: Could not find element in database, Amm."), lines[3] ); + CPPUNIT_ASSERT_EQUAL( std::string("\tConcentration is set to zero."), lines[4] ); + CPPUNIT_ASSERT_EQUAL( std::string("ERROR: Calculations terminating due to input errors."), lines[5] ); + + if (n >= 0) + { + CPPUNIT_ASSERT_EQUAL(IPQ_OK, ::DestroyIPhreeqc(n)); + } +} + void TestIPhreeqcLib::TestGetWarningStringLine(void) { int n = ::CreateIPhreeqc(); @@ -2089,31 +2202,32 @@ void TestIPhreeqcLib::TestGetWarningStringLine(void) void TestIPhreeqcLib::TestPitzer(void) { CPPUNIT_ASSERT_EQUAL(true, ::FileExists("../database/pitzer.dat")); + CPPUNIT_ASSERT( ::FileSize("../database/pitzer.dat") > 0 ); int id = ::CreateIPhreeqc(); CPPUNIT_ASSERT(id >= 0); - CPPUNIT_ASSERT_EQUAL(::LoadDatabase(id, "../database/pitzer.dat"), 0); + CPPUNIT_ASSERT_EQUAL(0, ::LoadDatabase(id, "../database/pitzer.dat")); - CPPUNIT_ASSERT_EQUAL(::AccumulateLine(id, "SOLUTION 1"), IPQ_OK); - CPPUNIT_ASSERT_EQUAL(::AccumulateLine(id, "units mol/kgw"), IPQ_OK); - CPPUNIT_ASSERT_EQUAL(::AccumulateLine(id, "pH 7"), IPQ_OK); - CPPUNIT_ASSERT_EQUAL(::AccumulateLine(id, "temp 25"), IPQ_OK); - CPPUNIT_ASSERT_EQUAL(::AccumulateLine(id, "Mg 0.1 charge"), IPQ_OK); - CPPUNIT_ASSERT_EQUAL(::AccumulateLine(id, "Cl 0"), IPQ_OK); - CPPUNIT_ASSERT_EQUAL(::AccumulateLine(id, "S(6) 1.0612244897959"), IPQ_OK); - CPPUNIT_ASSERT_EQUAL(::AccumulateLine(id, "EQUILIBRIUM_PHASES 1"), IPQ_OK); - CPPUNIT_ASSERT_EQUAL(::AccumulateLine(id, "Halite 0 10"), IPQ_OK); - CPPUNIT_ASSERT_EQUAL(::AccumulateLine(id, "Sylvite 0 10"), IPQ_OK); - CPPUNIT_ASSERT_EQUAL(::AccumulateLine(id, "Bischofite 0 0"), IPQ_OK); - CPPUNIT_ASSERT_EQUAL(::AccumulateLine(id, "Carnallite 0 0"), IPQ_OK); - CPPUNIT_ASSERT_EQUAL(::AccumulateLine(id, "Epsomite 0 0"), IPQ_OK); - CPPUNIT_ASSERT_EQUAL(::AccumulateLine(id, "Kieserite 0 0"), IPQ_OK); - CPPUNIT_ASSERT_EQUAL(::AccumulateLine(id, "END"), IPQ_OK); + CPPUNIT_ASSERT_EQUAL(IPQ_OK, ::AccumulateLine(id, "SOLUTION 1") ); + CPPUNIT_ASSERT_EQUAL(IPQ_OK, ::AccumulateLine(id, "units mol/kgw") ); + CPPUNIT_ASSERT_EQUAL(IPQ_OK, ::AccumulateLine(id, "pH 7") ); + CPPUNIT_ASSERT_EQUAL(IPQ_OK, ::AccumulateLine(id, "temp 25") ); + CPPUNIT_ASSERT_EQUAL(IPQ_OK, ::AccumulateLine(id, "Mg 0.1 charge") ); + CPPUNIT_ASSERT_EQUAL(IPQ_OK, ::AccumulateLine(id, "Cl 0") ); + CPPUNIT_ASSERT_EQUAL(IPQ_OK, ::AccumulateLine(id, "S(6) 1.0612244897959")); + CPPUNIT_ASSERT_EQUAL(IPQ_OK, ::AccumulateLine(id, "EQUILIBRIUM_PHASES 1") ); + CPPUNIT_ASSERT_EQUAL(IPQ_OK, ::AccumulateLine(id, "Halite 0 10") ); + CPPUNIT_ASSERT_EQUAL(IPQ_OK, ::AccumulateLine(id, "Sylvite 0 10") ); + CPPUNIT_ASSERT_EQUAL(IPQ_OK, ::AccumulateLine(id, "Bischofite 0 0") ); + CPPUNIT_ASSERT_EQUAL(IPQ_OK, ::AccumulateLine(id, "Carnallite 0 0") ); + CPPUNIT_ASSERT_EQUAL(IPQ_OK, ::AccumulateLine(id, "Epsomite 0 0") ); + CPPUNIT_ASSERT_EQUAL(IPQ_OK, ::AccumulateLine(id, "Kieserite 0 0") ); + CPPUNIT_ASSERT_EQUAL(IPQ_OK, ::AccumulateLine(id, "END") ); // this fails -r4375 // fixed in -r4380 - CPPUNIT_ASSERT_EQUAL(::RunAccumulated(id), 0); + CPPUNIT_ASSERT_EQUAL(0, ::RunAccumulated(id)); if (id >= 0) { @@ -2124,17 +2238,18 @@ void TestIPhreeqcLib::TestPitzer(void) void TestIPhreeqcLib::TestClearAccumulatedLines(void) { CPPUNIT_ASSERT_EQUAL(true, ::FileExists("../database/wateq4f.dat")); + CPPUNIT_ASSERT( ::FileSize("../database/wateq4f.dat") > 0 ); int id = ::CreateIPhreeqc(); CPPUNIT_ASSERT(id >= 0); - CPPUNIT_ASSERT_EQUAL(::LoadDatabase(id, "../database/wateq4f.dat"), 0); + CPPUNIT_ASSERT_EQUAL(0, ::LoadDatabase(id, "../database/wateq4f.dat")); - CPPUNIT_ASSERT_EQUAL(::AccumulateLine(id, "SOLUTION 1"), IPQ_OK); - CPPUNIT_ASSERT_EQUAL(::AccumulateLine(id, "pH -2"), IPQ_OK); - CPPUNIT_ASSERT_EQUAL(::AccumulateLine(id, "END"), IPQ_OK); + CPPUNIT_ASSERT_EQUAL(IPQ_OK, ::AccumulateLine(id, "SOLUTION 1")); + CPPUNIT_ASSERT_EQUAL(IPQ_OK, ::AccumulateLine(id, "pH -2") ); + CPPUNIT_ASSERT_EQUAL(IPQ_OK, ::AccumulateLine(id, "END") ); - CPPUNIT_ASSERT_EQUAL(::RunAccumulated(id), 1); + CPPUNIT_ASSERT_EQUAL(1, ::RunAccumulated(id)); CPPUNIT_ASSERT_EQUAL( 3, ::GetErrorStringLineCount(id) ); @@ -2148,21 +2263,21 @@ void TestIPhreeqcLib::TestClearAccumulatedLines(void) CPPUNIT_ASSERT_EQUAL( std::string(""), std::string(::GetErrorStringLine(id, 1)) ); CPPUNIT_ASSERT_EQUAL( std::string("ERROR: Model failed to converge for initial solution."), std::string(::GetErrorStringLine(id, 2)) ); - CPPUNIT_ASSERT_EQUAL(::AccumulateLine(id, "SOLUTION 1"), IPQ_OK); - CPPUNIT_ASSERT_EQUAL(::AccumulateLine(id, "pH 2"), IPQ_OK); - CPPUNIT_ASSERT_EQUAL(::AccumulateLine(id, "END"), IPQ_OK); + CPPUNIT_ASSERT_EQUAL(IPQ_OK, ::AccumulateLine(id, "SOLUTION 1")); + CPPUNIT_ASSERT_EQUAL(IPQ_OK, ::AccumulateLine(id, "pH 2") ); + CPPUNIT_ASSERT_EQUAL(IPQ_OK, ::AccumulateLine(id, "END") ); // RunAccumulated clears accumulated lines on next call to AccumulateLine // - CPPUNIT_ASSERT_EQUAL(::RunAccumulated(id), 0); - CPPUNIT_ASSERT_EQUAL( 0, ::GetErrorStringLineCount(id) ); + CPPUNIT_ASSERT_EQUAL(0, ::RunAccumulated(id) ); + CPPUNIT_ASSERT_EQUAL(0, ::GetErrorStringLineCount(id)); - CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::ClearAccumulatedLines(id) ); - CPPUNIT_ASSERT_EQUAL(::AccumulateLine(id, "SOLUTION 1"), IPQ_OK); - CPPUNIT_ASSERT_EQUAL(::AccumulateLine(id, "pH 2"), IPQ_OK); - CPPUNIT_ASSERT_EQUAL(::AccumulateLine(id, "END"), IPQ_OK); + CPPUNIT_ASSERT_EQUAL(IPQ_OK, ::ClearAccumulatedLines(id) ); + CPPUNIT_ASSERT_EQUAL(IPQ_OK, ::AccumulateLine(id, "SOLUTION 1")); + CPPUNIT_ASSERT_EQUAL(IPQ_OK, ::AccumulateLine(id, "pH 2") ); + CPPUNIT_ASSERT_EQUAL(IPQ_OK, ::AccumulateLine(id, "END") ); - CPPUNIT_ASSERT_EQUAL(::RunAccumulated(id), 0); + CPPUNIT_ASSERT_EQUAL(0, ::RunAccumulated(id)); if (id >= 0) { diff --git a/unit/TestIPhreeqcLib.h b/unit/TestIPhreeqcLib.h index 32973945..2db6a4c9 100644 --- a/unit/TestIPhreeqcLib.h +++ b/unit/TestIPhreeqcLib.h @@ -14,15 +14,14 @@ class TestIPhreeqcLib : public CppUnit::TestFixture CPPUNIT_TEST( TestLoadDatabaseMissingFile ); CPPUNIT_TEST( TestLoadDatabaseWithErrors ); CPPUNIT_TEST( TestRunAccumulated ); - CPPUNIT_TEST( TestRunWithErrors ); - CPPUNIT_TEST( TestRunFile ); +// COMMENT: {12/12/2011 2:46:47 PM} CPPUNIT_TEST( TestRunWithErrors ); +// COMMENT: {12/12/2011 2:46:59 PM} CPPUNIT_TEST( TestRunFile ); CPPUNIT_TEST( TestRunString ); CPPUNIT_TEST( TestGetSelectedOutputRowCount ); CPPUNIT_TEST( TestGetSelectedOutputValue ); CPPUNIT_TEST( TestGetSelectedOutputColumnCount ); CPPUNIT_TEST( TestAddError ); CPPUNIT_TEST( TestAccumulateLine ); - CPPUNIT_TEST( TestAddError ); CPPUNIT_TEST( TestOutputErrorString ); CPPUNIT_TEST( TestRunWithCallback ); CPPUNIT_TEST( TestRunNoDatabaseLoaded ); @@ -35,16 +34,18 @@ class TestIPhreeqcLib : public CppUnit::TestFixture CPPUNIT_TEST( TestDumpOn ); CPPUNIT_TEST( TestSelOutOnOff ); CPPUNIT_TEST( TestLongHeadings ); - CPPUNIT_TEST( TestDatabaseKeyword ); + CPPUNIT_TEST( TestDatabaseKeyword ); // *** CPPUNIT_TEST( TestDumpString ); - CPPUNIT_TEST( TestGetDumpStringLineCount ); - CPPUNIT_TEST( TestGetDumpStringLine ); - CPPUNIT_TEST( TestGetComponentCount ); + CPPUNIT_TEST( TestGetDumpStringLineCount ); // *** + CPPUNIT_TEST( TestGetDumpStringLine ); // *** + CPPUNIT_TEST( TestGetComponentCount ); // *** CPPUNIT_TEST( TestGetComponent ); CPPUNIT_TEST( TestGetErrorStringLine ); + CPPUNIT_TEST( TestErrorFileOn ); // new + CPPUNIT_TEST( TestLogFileOn ); // new CPPUNIT_TEST( TestGetWarningStringLine ); CPPUNIT_TEST( TestPitzer ); - CPPUNIT_TEST( TestClearAccumulatedLines ); +// COMMENT: {12/12/2011 2:47:15 PM} CPPUNIT_TEST( TestClearAccumulatedLines ); CPPUNIT_TEST_SUITE_END(); public: @@ -86,6 +87,8 @@ public: void TestGetComponentCount(void); void TestGetComponent(void); void TestGetErrorStringLine(void); + void TestErrorFileOn(void); + void TestLogFileOn(void); void TestGetWarningStringLine(void); void TestPitzer(void); void TestClearAccumulatedLines(void); diff --git a/unit/dump b/unit/dump index 56a6cfe5..1d610fcd 100644 --- a/unit/dump +++ b/unit/dump @@ -24,7 +24,8 @@ GAS_PHASE 1-100 N2(g) 0.9 #---------------- OUTPUT and TRANSPORT ----------------# - +KNOBS + -logfile true transport -cells 100 diff --git a/unit/unit.cpp b/unit/unit.cpp index 0ea930e5..e72ccf74 100644 --- a/unit/unit.cpp +++ b/unit/unit.cpp @@ -22,7 +22,7 @@ int main(int argc, char **argv) runner.addTest(TestCVar::suite()); runner.addTest(TestSelectedOutput::suite()); runner.addTest(TestIPhreeqc::suite()); -// COMMENT: {11/16/2011 11:12:52 PM} runner.addTest(TestIPhreeqcLib::suite()); + runner.addTest(TestIPhreeqcLib::suite()); runner.setOutputter(CppUnit::CompilerOutputter::defaultOutputter(&runner.result(), std::cout)); @@ -84,3 +84,38 @@ int DeleteFile(const char* szPathName) return 0; // failure } #endif + +#if defined(_WIN32) || defined(__CYGWIN32__) +size_t FileSize(const char *szPathName) +{ + HANDLE hFile = ::CreateFile( + szPathName, // file to open + GENERIC_READ, // open for reading + FILE_SHARE_READ, // share for reading + NULL, // default security + OPEN_EXISTING, // existing file only + FILE_ATTRIBUTE_NORMAL, // normal file + NULL); // no attr. template + + if (hFile != INVALID_HANDLE_VALUE) + { + // read file size + LARGE_INTEGER liFileSize; + ::GetFileSizeEx(hFile, &liFileSize); + ::CloseHandle(hFile); + return (size_t) liFileSize.QuadPart; + } + return 0; +} +#else +#include +#include +#include + +size_t FileSize(const char *szPathName) +{ + struct stat s; + stat(szPathName, &s); + return (size_t) s.st_size; +} +#endif \ No newline at end of file