From 745917b89d968bcb0291cf76e0b88659a8f7c013 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Thu, 18 Mar 2010 23:57:42 +0000 Subject: [PATCH] moved list_components from class_main.cpp to Phreeqc.cpp git-svn-id: svn://136.177.114.72/svn_GW/IPhreeqc/branches/class@4173 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- include/IPhreeqc.h | 34 +++++++++++++++++++++++ src/IPhreeqc.cpp | 32 ++++++++++++++++++++++ src/IPhreeqc.hpp | 2 ++ unit/TestInterface.cpp | 52 +++++++++++++++++++++++++++++++++++ unit/TestInterface.h | 62 ++++++++++++++++++++++-------------------- 5 files changed, 153 insertions(+), 29 deletions(-) diff --git a/include/IPhreeqc.h b/include/IPhreeqc.h index 62a97305..84699f04 100644 --- a/include/IPhreeqc.h +++ b/include/IPhreeqc.h @@ -3,6 +3,7 @@ #include "IPhreeqcCallbacks.h" /* PFN_PRERUN_CALLBACK, PFN_POSTRUN_CALLBACK, PFN_CATCH_CALLBACK */ #include "Var.h" /* VRESULT */ +#include #if defined(__cplusplus) extern "C" { @@ -551,6 +552,39 @@ int GetErrorLineCount(void); */ const char* GetErrorLine(int n); +/** + * TODO + * @par Fortran90 Interface: + * @htmlonly + * + *
+ *  FUNCTION GetErrorLineCount
+ *    INTEGER :: GetErrorLineCount
+ *  END FUNCTION GetErrorLineCount
+ *  
+ *
+ * @endhtmlonly + */ +int GetComponentCount(void); + +/** + * TODO + * @par Fortran90 Interface: + * @htmlonly + * + *
+ *  FUNCTION GetErrorLineCount
+ *    INTEGER :: GetErrorLineCount
+ *  END FUNCTION GetErrorLineCount
+ *  
+ *
+ * @endhtmlonly + */ +const char* GetComponent(int n); + + + + #if defined(WIN32) void DebugOutputLines(void); #endif diff --git a/src/IPhreeqc.cpp b/src/IPhreeqc.cpp index c5bfc231..ca5d6c97 100644 --- a/src/IPhreeqc.cpp +++ b/src/IPhreeqc.cpp @@ -180,6 +180,32 @@ GetErrorLine(int n) return IPhreeqc::LibraryInstance()->GetErrorLine(n); } +int +GetComponentCount(void) +{ + return (int)IPhreeqc::LibraryInstance()->ListComponents().size(); +} + +const char* +GetComponent(int n) +{ + static const char empty[] = ""; + static std::string comp; + std::list< std::string > comps = IPhreeqc::LibraryInstance()->ListComponents(); + if (n < 0 || n >= (int)comps.size()) + { + return empty; + } + std::list< std::string >::iterator it = comps.begin(); + for(int i = 0; i < n; ++i) + { + ++it; + } + comp = (*it); + return comp.c_str(); +} + + IPhreeqc::IPhreeqc(void) : Phreeqc() , ErrorReporter(0) @@ -1787,3 +1813,9 @@ void IPhreeqc::update_errors(void) this->ErrorLines.push_back(line); } } +std::list< std::string > IPhreeqc::ListComponents(void) +{ + std::list< std::string > comps; + this->list_components(comps); + return comps; +} diff --git a/src/IPhreeqc.hpp b/src/IPhreeqc.hpp index 9a69857d..c6f10570 100644 --- a/src/IPhreeqc.hpp +++ b/src/IPhreeqc.hpp @@ -35,6 +35,8 @@ public: int GetErrorLineCount(void)const; const char* GetErrorLine(int n); + std::list< std::string > ListComponents(void); + VRESULT AccumulateLine(const char *line); void SetDumpOn(bool bValue); diff --git a/unit/TestInterface.cpp b/unit/TestInterface.cpp index d1d02729..496d7a21 100644 --- a/unit/TestInterface.cpp +++ b/unit/TestInterface.cpp @@ -1692,3 +1692,55 @@ TestInterface::TestGetDumpLine() CPPUNIT_ASSERT_EQUAL( std::string(""), std::string(::GetDumpLine(-3)) ); CPPUNIT_ASSERT_EQUAL( std::string(""), std::string(::GetDumpLine(-4)) ); } + +void +TestInterface::TestGetComponentCount(void) +{ + CPPUNIT_ASSERT_EQUAL( 0, ::LoadDatabase("phreeqc.dat") ); + + // add solution block + CPPUNIT_ASSERT_EQUAL( VR_OK, SOLUTION(1.0, 1.0, 1.0) ); + + // run + ::SetOutputOn(0); + ::SetErrorOn(0); + ::SetLogOn(0); + ::SetSelectedOutputOn(0); + ::SetDumpOn(0); + ::SetDumpStringOn(0); + CPPUNIT_ASSERT_EQUAL( 0, ::Run() ); + + + CPPUNIT_ASSERT_EQUAL( 4, ::GetComponentCount() ); +} + +void +TestInterface::TestGetComponent(void) +{ + CPPUNIT_ASSERT_EQUAL( 0, ::LoadDatabase("phreeqc.dat") ); + + // add solution block + CPPUNIT_ASSERT_EQUAL( VR_OK, SOLUTION(1.0, 1.0, 1.0) ); + + // run + ::SetOutputOn(1); + ::SetErrorOn(0); + ::SetLogOn(0); + ::SetSelectedOutputOn(0); + ::SetDumpOn(0); + ::SetDumpStringOn(0); + + std::cout << "\n"; + ::OutputLines(); + std::cout << "\n"; + + CPPUNIT_ASSERT_EQUAL( 0, ::Run() ); + + + CPPUNIT_ASSERT_EQUAL( 4, ::GetComponentCount() ); + + CPPUNIT_ASSERT_EQUAL( std::string("Ca"), std::string(::GetComponent(0)) ); + CPPUNIT_ASSERT_EQUAL( std::string("H"), std::string(::GetComponent(1)) ); + CPPUNIT_ASSERT_EQUAL( std::string("Na"), std::string(::GetComponent(2)) ); + CPPUNIT_ASSERT_EQUAL( std::string("O"), std::string(::GetComponent(3)) ); +} diff --git a/unit/TestInterface.h b/unit/TestInterface.h index 08a8306f..5a0dffed 100644 --- a/unit/TestInterface.h +++ b/unit/TestInterface.h @@ -38,6 +38,8 @@ class TestInterface : CPPUNIT_TEST( TestDumpString ); CPPUNIT_TEST( TestGetDumpLineCount ); CPPUNIT_TEST( TestGetDumpLine ); + CPPUNIT_TEST( TestGetComponentCount ); + CPPUNIT_TEST( TestGetComponent ); CPPUNIT_TEST_SUITE_END(); @@ -46,35 +48,37 @@ public: ~TestInterface(void); public: - void TestLoadDatabase(); - void TestLoadDatabaseString(); - void TestLoadDatabaseMissingFile(); - void TestLoadDatabaseWithErrors(); - void TestRun(); - void TestRunWithErrors(); - void TestRunFile(); - void TestGetSelectedOutputRowCount(); - void TestGetSelectedOutputValue(); - void TestGetSelectedOutputColumnCount(); - void TestAddError(); - void TestAccumulateLine(); - void TestOutputLastError(); - void TestRunWithCallback(); - void TestRunNoDatabaseLoaded(); - void TestRunFileNoDatabaseLoaded(); - void TestCase1(); - void TestCase2(); - void TestPrintSelectedOutputFalse(); - void TestOutputOnOff(); - void TestErrorOnOff(); - void TestLogOnOff(); - void TestSelOutOnOff(); - void TestLongHeadings(); - void TestDatabaseKeyword(); - void TestDumpOn(); - void TestDumpString(); - void TestGetDumpLineCount(); - void TestGetDumpLine(); + void TestLoadDatabase(void); + void TestLoadDatabaseString(void); + void TestLoadDatabaseMissingFile(void); + void TestLoadDatabaseWithErrors(void); + void TestRun(void); + void TestRunWithErrors(void); + void TestRunFile(void); + void TestGetSelectedOutputRowCount(void); + void TestGetSelectedOutputValue(void); + void TestGetSelectedOutputColumnCount(void); + void TestAddError(void); + void TestAccumulateLine(void); + void TestOutputLastError(void); + void TestRunWithCallback(void); + void TestRunNoDatabaseLoaded(void); + void TestRunFileNoDatabaseLoaded(void); + void TestCase1(void); + void TestCase2(void); + void TestPrintSelectedOutputFalse(void); + void TestOutputOnOff(void); + void TestErrorOnOff(void); + void TestLogOnOff(void); + void TestSelOutOnOff(void); + void TestLongHeadings(void); + void TestDatabaseKeyword(void); + void TestDumpOn(void); + void TestDumpString(void); + void TestGetDumpLineCount(void); + void TestGetDumpLine(void); + void TestGetComponentCount(void); + void TestGetComponent(void); };