From 437c7c5a3a4db1c6fbf026ddaad8ef132f73876e Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Mon, 3 Jun 2013 22:05:52 +0000 Subject: [PATCH] fixed bug in DELETE reported by laurin.wissmeier@web.de 2013-06-01 git-svn-id: svn://136.177.114.72/svn_GW/IPhreeqc/trunk@7755 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- unit/TestIPhreeqc.cpp | 49 ++++++++++++++++++++++++++++++++++ unit/TestIPhreeqc.h | 4 +++ unit/TestIPhreeqcLib.cpp | 57 ++++++++++++++++++++++++++++++++++++++++ unit/TestIPhreeqcLib.h | 2 ++ 4 files changed, 112 insertions(+) diff --git a/unit/TestIPhreeqc.cpp b/unit/TestIPhreeqc.cpp index b664d96a..23d727eb 100644 --- a/unit/TestIPhreeqc.cpp +++ b/unit/TestIPhreeqc.cpp @@ -3417,4 +3417,53 @@ void TestIPhreeqc::TestCErrorReporter(void) //printf("\ntime = %g\n", double(t - t0)); } +void TestIPhreeqc::TestDelete(void) +{ + const char input[] = + "SOLUTION 1 # definition of intial condition 1\n" + "COPY cell 1 7405 # copy cell 1 to placeholder cell with index larger than the number of cells in the model domain\n" + "END\n" + "DELETE # delete initial condition 1 to allow for a redefinition of all reactions\n" + "-cell 1\n" + "END\n" + "# define other initial conditions and copy to another placeholder cell\n" + "\n" + "COPY cell 7405 1 # copy back from placeholder cell to domain cell 1\n" + "END\n" + "MIX 1 # mix according to initial moisture content\n" + " 1 0.25\n" + "END\n" + "RUN_CELLS\n" + "-cells 1\n" + "-start_time 0\n" + "-time_step 0\n" + "DELETE # remove mix reaction in subsequent runs\n" + "-mix 1\n" + "END\n" + "RUN_CELLS\n" + "-cells 1\n"; + IPhreeqc obj; + + char OUTPUT_FILE[80]; + sprintf(OUTPUT_FILE, "phreeqc.%lu.out", (unsigned long)obj.Index); + + if (::FileExists(OUTPUT_FILE)) + { + CPPUNIT_ASSERT(::DeleteFile(OUTPUT_FILE)); + } + CPPUNIT_ASSERT_EQUAL(false, ::FileExists(OUTPUT_FILE)); + CPPUNIT_ASSERT_EQUAL(0, obj.LoadDatabase("phreeqc.dat")); + obj.SetOutputFileOn(0); + obj.SetErrorFileOn(0); + obj.SetLogFileOn(0); + obj.SetSelectedOutputFileOn(0); + obj.SetDumpFileOn(0); + CPPUNIT_ASSERT_EQUAL(false, ::FileExists(OUTPUT_FILE)); + CPPUNIT_ASSERT_EQUAL(0, obj.RunString(input)); + CPPUNIT_ASSERT_EQUAL(false, ::FileExists(OUTPUT_FILE)); + if (::FileExists(OUTPUT_FILE)) + { + CPPUNIT_ASSERT(::DeleteFile(OUTPUT_FILE)); + } +} diff --git a/unit/TestIPhreeqc.h b/unit/TestIPhreeqc.h index 33c730b5..932490f5 100644 --- a/unit/TestIPhreeqc.h +++ b/unit/TestIPhreeqc.h @@ -63,6 +63,8 @@ class TestIPhreeqc : public CppUnit::TestFixture CPPUNIT_TEST( TestLongUser_Punch ); CPPUNIT_TEST( TestBasicSURF ); CPPUNIT_TEST( TestCErrorReporter ); + CPPUNIT_TEST( TestDelete ); + CPPUNIT_TEST_SUITE_END(); public: @@ -126,6 +128,8 @@ public: void TestLongUser_Punch(void); void TestBasicSURF(void); void TestCErrorReporter(void); + void TestDelete(void); + protected: void TestFileOnOff(const char* FILENAME, bool output_file_on, bool error_file_on, bool log_file_on, bool selected_output_file_on, bool dump_file_on); diff --git a/unit/TestIPhreeqcLib.cpp b/unit/TestIPhreeqcLib.cpp index 4609e460..e997a4a9 100644 --- a/unit/TestIPhreeqcLib.cpp +++ b/unit/TestIPhreeqcLib.cpp @@ -3908,3 +3908,60 @@ void TestIPhreeqcLib::TestIEEE(void) // COMMENT: {1/18/2013 6:34:57 PM} CPPUNIT_ASSERT_EQUAL(IPQ_OK, ::DestroyIPhreeqc(n)); // COMMENT: {1/18/2013 6:34:57 PM} } } + +void TestIPhreeqcLib::TestDelete(void) +{ + const char input[] = + "SOLUTION 1 # definition of intial condition 1\n" + "COPY cell 1 7405 # copy cell 1 to placeholder cell with index larger than the number of cells in the model domain\n" + "END\n" + "DELETE # delete initial condition 1 to allow for a redefinition of all reactions\n" + "-cell 1\n" + "END\n" + "# define other initial conditions and copy to another placeholder cell\n" + "\n" + "COPY cell 7405 1 # copy back from placeholder cell to domain cell 1\n" + "END\n" + "MIX 1 # mix according to initial moisture content\n" + " 1 0.25\n" + "END\n" + "RUN_CELLS\n" + "-cells 1\n" + "-start_time 0\n" + "-time_step 0\n" + "DELETE # remove mix reaction in subsequent runs\n" + "-mix 1\n" + "END\n" + "RUN_CELLS\n" + "-cells 1\n"; + + int n = ::CreateIPhreeqc(); + CPPUNIT_ASSERT(n >= 0); + + char OUTPUT_FILE[80]; + sprintf(OUTPUT_FILE, "phreeqc.%d.out", n); + + if (::FileExists(OUTPUT_FILE)) + { + CPPUNIT_ASSERT(::DeleteFile(OUTPUT_FILE)); + } + CPPUNIT_ASSERT_EQUAL(false, ::FileExists(OUTPUT_FILE)); + + CPPUNIT_ASSERT_EQUAL(0, ::LoadDatabase(n, "phreeqc.dat")); + ::SetOutputFileOn(n, 0); + ::SetErrorFileOn(n, 0); + ::SetLogFileOn(n, 0); + ::SetSelectedOutputFileOn(n, 0); + ::SetDumpFileOn(n, 0); + CPPUNIT_ASSERT_EQUAL(false, ::FileExists(OUTPUT_FILE)); + CPPUNIT_ASSERT_EQUAL(0, ::RunString(n, input)); + CPPUNIT_ASSERT_EQUAL(false, ::FileExists(OUTPUT_FILE)); + if (n >= 0) + { + CPPUNIT_ASSERT_EQUAL(IPQ_OK, ::DestroyIPhreeqc(n)); + } + if (::FileExists(OUTPUT_FILE)) + { + CPPUNIT_ASSERT(::DeleteFile(OUTPUT_FILE)); + } +} diff --git a/unit/TestIPhreeqcLib.h b/unit/TestIPhreeqcLib.h index 8da6c2db..589b7214 100644 --- a/unit/TestIPhreeqcLib.h +++ b/unit/TestIPhreeqcLib.h @@ -70,6 +70,7 @@ class TestIPhreeqcLib : public CppUnit::TestFixture CPPUNIT_TEST( TestLongUser_Punch ); CPPUNIT_TEST( TestBasicSURF ); CPPUNIT_TEST( TestIEEE ); + CPPUNIT_TEST( TestDelete ); CPPUNIT_TEST_SUITE_END(); public: @@ -140,6 +141,7 @@ public: void TestLongUser_Punch(void); void TestBasicSURF(void); void TestIEEE(void); + void TestDelete(void); protected: void TestFileOnOff(const char* FILENAME, int output_file_on, int error_file_on, int log_file_on, int selected_output_file_on, int dump_file_on);