Fixed left shift operator error and null pointer error for R UBSAN check;

Added INVERSE_CL1MP guard to cl1mp.cpp;
Added test for ex10


git-svn-id: svn://136.177.114.72/svn_GW/IPhreeqc/trunk@9084 1feff8c3-07ed-0310-ac33-dd36852eb9cd
This commit is contained in:
Scott R Charlton 2014-12-03 05:19:35 +00:00
parent 680b33c5ae
commit dc93c84f92
2 changed files with 144 additions and 0 deletions

View File

@ -4496,3 +4496,145 @@ void TestIPhreeqc::TestPBasicStopThrow(void)
obj.SetOutputFileOn(true);
CPPUNIT_ASSERT_EQUAL( 5, obj.RunAccumulated() );
}
void TestIPhreeqc::TestEx10(void)
{
const char input[] =
"TITLE Example 10.--Solid solution of strontianite and aragonite.\n"
"PHASES\n"
" Strontianite\n"
" SrCO3 = CO3-2 + Sr+2\n"
" log_k -9.271\n"
" Aragonite\n"
" CaCO3 = CO3-2 + Ca+2\n"
" log_k -8.336\n"
"END\n"
"SOLID_SOLUTIONS 1\n"
" Ca(x)Sr(1-x)CO3 \n"
" -comp1 Aragonite 0 \n"
" -comp2 Strontianite 0 \n"
" -Gugg_nondim 3.43 -1.82\n"
"END\n"
"SOLUTION 1\n"
" -units mmol/kgw\n"
" pH 5.93 charge\n"
" Ca 3.932\n"
" C 7.864\n"
"EQUILIBRIUM_PHASES 1\n"
" CO2(g) -0.01265 10\n"
" Aragonite\n"
"SAVE solution 1\n"
"END\n"
"#\n"
"# Total of 0.00001 to 0.005 moles of SrCO3 added\n"
"#\n"
"USE solution 1\n"
"USE solid_solution 1\n"
"REACTION 1\n"
" SrCO3 1.0\n"
" .005 in 500 steps \n"
"PRINT\n"
" -reset false\n"
" -echo true\n"
" -user_print true\n"
"USER_PRINT\n"
"-start\n"
" 10 sum = (S_S(\"Strontianite\") + S_S(\"Aragonite\"))\n"
" 20 if sum = 0 THEN GOTO 110\n"
" 30 xb = S_S(\"Strontianite\")/sum\n"
" 40 xc = S_S(\"Aragonite\")/sum\n"
" 50 PRINT \"Simulation number: \", SIM_NO\n"
" 60 PRINT \"Reaction step number: \", STEP_NO\n"
" 70 PRINT \"SrCO3 added: \", RXN\n"
" 80 PRINT \"Log Sigma pi: \", LOG10 (ACT(\"CO3-2\") * (ACT(\"Ca+2\") + ACT(\"Sr+2\")))\n"
" 90 PRINT \"XAragonite: \", xc\n"
" 100 PRINT \"XStrontianite: \", xb\n"
" 110 PRINT \"XCa: \", TOT(\"Ca\")/(TOT(\"Ca\") + TOT(\"Sr\"))\n"
" 120 PRINT \"XSr: \", TOT(\"Sr\")/(TOT(\"Ca\") + TOT(\"Sr\"))\n"
" 130 PRINT \"Misc 1: \", MISC1(\"Ca(x)Sr(1-x)CO3\")\n"
" 140 PRINT \"Misc 2: \", MISC2(\"Ca(x)Sr(1-x)CO3\")\n"
"-end\n"
"SELECTED_OUTPUT\n"
" -file ex10.sel\n"
" -reset false\n"
" -reaction true\n"
"USER_PUNCH\n"
"-head lg_SigmaPi X_Arag X_Stront X_Ca_aq X_Sr_aq mol_Misc1 mol_Misc2 \\n"
" mol_Arag mol_Stront\n"
"-start\n"
" 10 sum = (S_S(\"Strontianite\") + S_S(\"Aragonite\"))\n"
" 20 if sum = 0 THEN GOTO 60\n"
" 30 xb = S_S(\"Strontianite\")/(S_S(\"Strontianite\") + S_S(\"Aragonite\"))\n"
" 40 xc = S_S(\"Aragonite\")/(S_S(\"Strontianite\") + S_S(\"Aragonite\"))\n"
" 50 REM Sigma Pi\n"
" 60 PUNCH LOG10(ACT(\"CO3-2\") * (ACT(\"Ca+2\") + ACT(\"Sr+2\")))\n"
" 70 PUNCH xc # Mole fraction aragonite\n"
" 80 PUNCH xb # Mole fraction strontianite\n"
" 90 PUNCH TOT(\"Ca\")/(TOT(\"Ca\") + TOT(\"Sr\")) # Mole aqueous calcium\n"
" 100 PUNCH TOT(\"Sr\")/(TOT(\"Ca\") + TOT(\"Sr\")) # Mole aqueous strontium\n"
" 110 x1 = MISC1(\"Ca(x)Sr(1-x)CO3\")\n"
" 120 x2 = MISC2(\"Ca(x)Sr(1-x)CO3\")\n"
" 130 if (xb < x1 OR xb > x2) THEN GOTO 250\n"
" 140 nc = S_S(\"Aragonite\")\n"
" 150 nb = S_S(\"Strontianite\")\n"
" 160 mol2 = ((x1 - 1)/x1)*nb + nc\n"
" 170 mol2 = mol2 / ( ((x1 -1)/x1)*x2 + (1 - x2))\n"
" 180 mol1 = (nb - mol2*x2)/x1\n"
" 190 REM # Moles of misc. end members if in gap\n"
" 200 PUNCH mol1\n"
" 210 PUNCH mol2\n"
" 220 GOTO 300\n"
" 250 REM # Moles of misc. end members if not in gap\n"
" 260 PUNCH 1e-10\n"
" 270 PUNCH 1e-10\n"
" 300 PUNCH S_S(\"Aragonite\") # Moles aragonite\n"
" 310 PUNCH S_S(\"Strontianite\") # Moles Strontianite\n"
"-end\n"
"USER_GRAPH Example 10\n"
" -headings x_Aragonite x_Srontianite\n"
" -chart_title \"Aragonite-Strontianite Solid Solution\"\n"
" -axis_titles \"Log(SrCO3 added, in moles)\" \"Log(Mole fraction of component)\"\n"
" -axis_scale x_axis -5 1 1 1\n"
" -axis_scale y_axis -5 0.1 1 1\n"
" -connect_simulations true\n"
" -start\n"
" 10 sum = (S_S(\"Strontianite\") + S_S(\"Aragonite\"))\n"
" 20 IF sum = 0 THEN GOTO 70\n"
" 30 xb = S_S(\"Strontianite\")/ sum\n"
" 40 xc = S_S(\"Aragonite\")/ sum\n"
" 50 PLOT_XY LOG10(RXN), LOG10(xc), line_w = 2, symbol_size = 0\n"
" 60 PLOT_XY LOG10(RXN), LOG10(xb), line_w = 2, symbol_size = 0\n"
" 70 rem\n"
" -end\n"
"END \n"
"#\n"
"# Total of 0.005 to 0.1 moles of SrCO3 added\n"
"#\n"
"USE solution 1\n"
"USE solid_solution 1\n"
"REACTION 1\n"
" SrCO3 1.0\n"
" .1 in 20 steps \n"
"END \n"
"#\n"
"# Total of 0.1 to 10 moles of SrCO3 added\n"
"#\n"
"USE solution 1\n"
"USE solid_solution 1\n"
"REACTION 1\n"
" SrCO3 1.0\n"
" 10.0 in 100 steps \n"
"END \n";
IPhreeqc obj;
CPPUNIT_ASSERT_EQUAL(0, obj.LoadDatabase("phreeqc.dat"));
CPPUNIT_ASSERT_EQUAL(VR_OK, obj.AccumulateLine("solution 12"));
CPPUNIT_ASSERT_EQUAL(VR_OK, obj.AccumulateLine("solution 13"));
for (int i = 0; i < 10; ++i)
{
CPPUNIT_ASSERT_EQUAL(0, obj.RunString(input));
const char expected[] = "";
CPPUNIT_ASSERT_EQUAL( std::string(expected), obj.GetAccumulatedLines() );
}
}

View File

@ -86,6 +86,7 @@ class TestIPhreeqc : public CppUnit::TestFixture
CPPUNIT_TEST( TestGetAccumulatedLinesAfterRunFile );
CPPUNIT_TEST( TestGetAccumulatedLinesAfterRunString );
CPPUNIT_TEST( TestPBasicStopThrow );
CPPUNIT_TEST( TestEx10 );
CPPUNIT_TEST_SUITE_END();
public:
@ -172,6 +173,7 @@ public:
void TestGetAccumulatedLinesAfterRunFile(void);
void TestGetAccumulatedLinesAfterRunString(void);
void TestPBasicStopThrow(void);
void TestEx10(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);