dump file changes

git-svn-id: svn://136.177.114.72/svn_GW/IPhreeqc/branches/ErrorHandling@5913 1feff8c3-07ed-0310-ac33-dd36852eb9cd
This commit is contained in:
Scott R Charlton 2011-12-20 04:26:38 +00:00
parent b6ddcdabc4
commit 04aa629aed
16 changed files with 776 additions and 184 deletions

View File

@ -69,6 +69,7 @@ C
INTEGER(KIND=4) RunAccumulated
INTEGER(KIND=4) RunFile
INTEGER(KIND=4) RunString
INTEGER(KIND=4) SetDumpFileName
INTEGER(KIND=4) SetDumpFileOn
INTEGER(KIND=4) SetDumpStringOn
INTEGER(KIND=4) SetErrorFileOn

View File

@ -82,6 +82,14 @@
END INTERFACE
INTERFACE
SUBROUTINE GetDumpFileName(ID,FNAME)
INTEGER(KIND=4), INTENT(IN) :: ID
CHARACTER(LEN=*), INTENT(OUT) :: FNAME
END SUBROUTINE GetDumpFileName
END INTERFACE
INTERFACE
FUNCTION GetDumpFileOn(ID)
INTEGER(KIND=4), INTENT(IN) :: ID
@ -275,6 +283,15 @@
END INTERFACE
INTERFACE
FUNCTION SetDumpFileName(ID,FNAME)
INTEGER(KIND=4), INTENT(IN) :: ID
CHARACTER(LEN=*), INTENT(IN) :: FNAME
INTEGER(KIND=4) :: SetDumpFileName
END FUNCTION SetDumpFileName
END INTERFACE
INTERFACE
FUNCTION SetDumpFileOn(ID,DUMP_ON)
INTEGER(KIND=4), INTENT(IN) :: ID

View File

@ -217,7 +217,7 @@ extern "C" {
/**
* Retrieves the number of components in the current component list .
* Retrieves the number of components in the current component list.
* @param id The instance id returned from \ref CreateIPhreeqc.
* @return The current count of components.
* A negative value indicates an error occured (see \ref IPQ_RESULT).
@ -240,7 +240,28 @@ extern "C" {
* @par Fortran90 Example:
* see \ref GetComponent_f90 "GetComponent"
*/
IPQ_DLL_EXPORT int GetComponentCount(int id);
IPQ_DLL_EXPORT int GetComponentCount(int id);
/**
* Retrieves the name of the dump file. This file name is used if not specified within <B>DUMP</B> input.
* The default value is <B><I>dump.id.out</I></B>.
* @param id The instance id returned from \ref CreateIPhreeqc.
* @return filename The name of the file to write <B>DUMP</B> output to.
* @see GetDumpFileOn, GetDumpString, GetDumpStringOn, GetDumpStringLine, GetDumpStringLineCount, SetDumpFileName, SetDumpFileOn, SetDumpStringOn
* @par Fortran90 Interface:
* @htmlonly
* <CODE>
* <PRE>
* SUBROUTINE GetDumpFileName(ID,FILENAME)
* INTEGER(KIND=4), INTENT(IN) :: ID
* CHARACTER(LEN=*), INTENT(OUT) :: FILENAME
* END SUBROUTINE GetDumpFileName
* </PRE>
* </CODE>
* @endhtmlonly
*/
IPQ_DLL_EXPORT const char* GetDumpFileName(int id);
/**
@ -260,7 +281,7 @@ extern "C" {
* </CODE>
* @endhtmlonly
*/
IPQ_DLL_EXPORT int GetDumpFileOn(int id);
IPQ_DLL_EXPORT int GetDumpFileOn(int id);
/**
@ -970,6 +991,28 @@ Headings
IPQ_DLL_EXPORT int RunString(int id, const char* input);
/**
* Sets the name of the dump file. This file name is used if not specified within <B>DUMP</B> input.
* The default value is <B><I>dump.id.out</I></B>.
* @param id The instance id returned from \ref CreateIPhreeqc.
* @return filename The name of the file to write <B>DUMP</B> output to.
* @see GetDumpFileName, GetDumpFileOn, GetDumpString, GetDumpStringOn, GetDumpStringLine, GetDumpStringLineCount, SetDumpFileOn, SetDumpStringOn
* @par Fortran90 Interface:
* @htmlonly
* <CODE>
* <PRE>
* FUNCTION SetDumpFileName(ID,FILENAME)
* INTEGER(KIND=4), INTENT(IN) :: ID
* CHARACTER(LEN=*), INTENT(OUT) :: FILENAME
* INTEGER(KIND=4) :: SetDumpFileOn
* END FUNCTION SetDumpFileName
* </PRE>
* </CODE>
* @endhtmlonly
*/
IPQ_DLL_EXPORT IPQ_RESULT SetDumpFileName(int id, const char* filename);
/**
* Sets the dump file switch on or off. This switch controls whether or not phreeqc writes to the dump file.
* The initial setting after calling \ref CreateIPhreeqc is off.

View File

@ -8,6 +8,7 @@
#include <exception>
#include <list>
#include <vector>
#include <map>
#include <cstdarg>
#include "IPhreeqcCallbacks.h" /* PFN_PRERUN_CALLBACK, PFN_POSTRUN_CALLBACK, PFN_CATCH_CALLBACK */
#include "Var.h" /* VRESULT */
@ -115,9 +116,18 @@ public:
*/
size_t GetComponentCount(void);
/**
* Retrieves the name of the dump file. This file name is used if not specified within <B>DUMP</B> input.
* The default value is <B><I>dump.id.out</I></B>, where id is obtained from \ref GetId.
* @return filename The name of the file to write <B>DUMP</B> output to.
* @see GetDumpFileOn, GetDumpString, GetDumpStringOn, GetDumpStringLine, GetDumpStringLineCount, SetDumpFileName, SetDumpFileOn, SetDumpStringOn
*/
const char* GetDumpFileName(void)const;
/**
* Retrieves the current value of the dump file switch.
* @retval true Output is written to the <B>DUMP</B> (<B><I>dump.out</I></B> if unspecified) file.
* @retval true Output is written to the <B>DUMP</B> (<B><I>dump.id.out</I></B> if unspecified, where id is obtained from \ref GetId) file.
* @retval false No output is written.
* @see GetDumpStringLine, GetDumpStringLineCount, GetDumpStringOn, GetDumpString, SetDumpFileOn, SetDumpStringOn
*/
@ -160,7 +170,7 @@ public:
/**
* Retrieves the current value of the error file switch.
* @retval true Errors are written to the <B><I>phreeqc.err</I></B> file.
* @retval true Errors are written to the <B><I>phreeqc.id.err</I></B> (where id is obtained from \ref GetId) file.
* @retval false No errors are written.
* @see SetErrorFileOn
*/
@ -188,9 +198,16 @@ public:
*/
int GetErrorStringLineCount(void)const;
/**
* Retrieves the id of this object. Each instance receives an id which is incremented for each instance
* starting with the value zero.
* @return The id.
*/
int GetId(void)const;
/**
* Retrieves the current value of the log file switch.
* @retval true Log messages are written to the <B><I>phreeqc.log</I></B> file.
* @retval true Log messages are written to the <B><I>phreeqc.id.log</I></B> (where id is obtained from \ref GetId) file.
* @retval false No log messages are written.
* @remarks
* Logging must be enabled through the use of the KNOBS -logfile option in order to receive any log messages.
@ -200,7 +217,7 @@ public:
/**
* Retrieves the current value of the output file switch.
* @retval true Output is written to the <B><I>phreeqc.out</I></B> file.
* @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
*/
@ -215,7 +232,7 @@ public:
/**
* Retrieves the selected-output file switch.
* @retval true Output is written to the selected-output (<B><I>selected.out</I></B> if unspecified) file.
* @retval true Output is written to the selected-output (<B><I>selected.id.out</I></B> if unspecified, where id is obtained from \ref GetId) file.
* @retval false No output is written.
* @see GetSelectedOutputValue, GetSelectedOutputColumnCount, GetSelectedOutputRowCount, SetSelectedOutputFileOn
*/
@ -440,7 +457,8 @@ public:
void OutputAccumulatedLines(void);
/**
* Output the error messages normally stored in the <B><I>phreeqc.err</I></B> file to stdout.
* Output the error messages normally stored in the <B><I>phreeqc.id.err</I></B> (where id is obtained from \ref GetId)
* file to stdout.
* @see GetErrorStringLine, GetErrorStringLineCount, GetErrorFileOn, SetErrorFileOn
*/
void OutputErrorString(void);
@ -483,7 +501,16 @@ public:
int RunString(const char* input);
/**
* Sets the dump file switch on or off. This switch controls whether or not phreeqc writes to the <B>DUMP</B> (<B><I>dump.out</I></B> if unspecified) file.
* Sets the name of the dump file. This file name is used if not specified within <B>DUMP</B> input.
* The default value is <B><I>dump.id.out</I></B>, where id is obtained from \ref GetId.
* @param filename The name of the file to write <B>DUMP</B> output to.
* @see GetDumpFileName, GetDumpFileOn, GetDumpString, GetDumpStringOn, GetDumpStringLine, GetDumpStringLineCount, SetDumpStringOn
*/
void SetDumpFileName(const char *filename);
/**
* Sets the dump file switch on or off. This switch controls whether or not phreeqc writes to the <B>DUMP</B> (<B><I>dump.id.out</I></B>
* if unspecified, where id is obtained from \ref GetId) file.
* The initial setting is false.
* @param bValue If true, turns on output to the <B>DUMP</B> file;
* if false, turns off output to the <B>DUMP</B> file.
@ -502,7 +529,8 @@ public:
/**
* Sets the error file switch on or off. This switch controls whether or not
* error messages are written to the <B><I>phreeqc.err</I></B> file. The initial setting is false.
* error messages are written to the <B><I>phreeqc.id.err</I></B> (where id is obtained from \ref GetId) file.
* The initial setting is false.
* @param bValue If true, writes errors to the error file; if false, no errors are written to the error file.
* @see GetErrorStringLine, GetErrorStringLineCount, GetErrorFileOn, OutputErrorString
*/
@ -510,7 +538,7 @@ public:
/**
* Sets the log file switch on or off. This switch controls whether or not phreeqc
* writes log messages to the <B><I>phreeqc.log</I></B> file. The initial setting is false.
* writes log messages to the <B><I>phreeqc.id.log</I></B> (where id is obtained from \ref GetId) file. The initial setting is false.
* @param bValue If true, turns on output to the log file; if false, no log messages are written to the log file.
* @remarks
* Logging must be enabled through the use of the KNOBS -logfile option in order to receive any log messages.
@ -520,7 +548,7 @@ public:
/**
* Sets the output file switch on or off. This switch controls whether or not phreeqc
* writes to the <B><I>phreeqc.out</I></B> file. This is the output that is normally generated
* 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
* when phreeqc is run. The initial setting is false.
* @param bValue If true, writes output to the output file; if false, no output is written to the output file.
* @see GetOutputFileOn
@ -529,7 +557,8 @@ public:
/**
* Sets the selected-output file switch on or off. This switch controls whether or not phreeqc writes output to
* the <B>SELECTED_OUTPUT</B> (<B><I>selected.out</I></B> if unspecified) file. The initial setting is false.
* the <B>SELECTED_OUTPUT</B> (<B><I>selected.id.out</I></B> if unspecified, where id is obtained from \ref GetId) file.
* The initial setting is false.
* @param bValue If true, writes output to the selected-output file; if false, no output is written to the selected-output file.
* @see GetSelectedOutputColumnCount, GetSelectedOutputFileOn, GetSelectedOutputRowCount, GetSelectedOutputValue
*/
@ -591,7 +620,6 @@ protected:
std::vector< std::string > WarningLines;
CSelectedOutput *SelectedOutput;
std::string PunchFileName;
std::string StringInput;
std::string DumpString;
@ -599,6 +627,12 @@ protected:
std::list< std::string > Components;
std::string PunchFileName;
std::string OutputFileName;
std::string ErrorFileName;
std::string LogFileName;
std::string DumpFileName;
#if defined(_MSC_VER)
/* reset warning C4251 */
#pragma warning(default:4251)
@ -609,6 +643,11 @@ protected:
FILE *input_file;
FILE *database_file;
friend class IPhreeqcLib;
static std::map<size_t, IPhreeqc*> Instances;
static size_t InstancesIndex;
const size_t Index;
#if defined(CPPUNIT)
friend class TestIPhreeqc;
friend class TestSelectedOutput;

View File

@ -8,17 +8,15 @@
#include "SelectedOutput.hxx" // CSelectedOutput
#include "dumper.h" // dumper
int istream_getc(void *cookie);
const char OUTPUT_FILENAME_FORMAT[] = "phreeqc.%d.out";
const char ERROR_FILENAME_FORMAT[] = "phreeqc.%d.err";
const char LOG_FILENAME_FORMAT[] = "phreeqc.%d.log";
const char PUNCH_FILENAME_FORMAT[] = "selected.%d.out";
const char DUMP_FILENAME_FORMAT[] = "dump.%d.out";
typedef enum {
ACTION_ISOPEN = -100,
} module_action_type;
const char OUTPUT_FILENAME[] = "phreeqc.out";
const char ERROR_FILENAME[] = "phreeqc.err";
const char LOG_FILENAME[] = "phreeqc.log";
const char PUNCH_FILENAME[] = "selected.out";
// statics
std::map<size_t, IPhreeqc*> IPhreeqc::Instances;
size_t IPhreeqc::InstancesIndex = 0;
IPhreeqc::IPhreeqc(void)
: DatabaseLoaded(false)
@ -36,7 +34,10 @@ IPhreeqc::IPhreeqc(void)
, PhreeqcPtr(0)
, input_file(0)
, database_file(0)
, Index(IPhreeqc::InstancesIndex++)
{
char buffer[80];
this->ErrorReporter = new CErrorReporter<std::ostringstream>;
this->WarningReporter = new CErrorReporter<std::ostringstream>;
this->SelectedOutput = new CSelectedOutput();
@ -44,6 +45,25 @@ IPhreeqc::IPhreeqc(void)
ASSERT(this->PhreeqcPtr->phast == 0);
this->UnLoadDatabase();
std::map<size_t, IPhreeqc*>::value_type instance(this->Index, this);
std::pair<std::map<size_t, IPhreeqc*>::iterator, bool> pr = IPhreeqc::Instances.insert(instance);
::sprintf(buffer, PUNCH_FILENAME_FORMAT, this->Index);
this->PunchFileName = buffer;
::sprintf(buffer, OUTPUT_FILENAME_FORMAT, this->Index);
this->OutputFileName = buffer;
::sprintf(buffer, ERROR_FILENAME_FORMAT, this->Index);
this->ErrorFileName = buffer;
::sprintf(buffer, LOG_FILENAME_FORMAT, this->Index);
this->LogFileName = buffer;
::sprintf(buffer, DUMP_FILENAME_FORMAT, this->Index);
this->DumpFileName = buffer;
this->PhreeqcPtr->dump_info.Set_file_name(this->DumpFileName);
}
IPhreeqc::~IPhreeqc(void)
@ -55,6 +75,12 @@ IPhreeqc::~IPhreeqc(void)
delete this->SelectedOutput;
delete this->WarningReporter;
delete this->ErrorReporter;
std::map<size_t, IPhreeqc*>::iterator it = IPhreeqc::Instances.find(this->Index);
if (it != IPhreeqc::Instances.end())
{
IPhreeqc::Instances.erase(it);
}
}
VRESULT IPhreeqc::AccumulateLine(const char *line)
@ -122,6 +148,11 @@ size_t IPhreeqc::GetComponentCount(void)
return this->Components.size();
}
const char* IPhreeqc::GetDumpFileName(void)const
{
return this->DumpFileName.c_str();
}
bool IPhreeqc::GetDumpFileOn(void)const
{
return this->DumpOn;
@ -183,6 +214,11 @@ int IPhreeqc::GetErrorStringLineCount(void)const
return (int)this->ErrorLines.size();
}
int IPhreeqc::GetId(void)const
{
return (int)this->Index;
}
bool IPhreeqc::GetLogFileOn(void)const
{
return this->LogOn;
@ -517,6 +553,12 @@ int IPhreeqc::RunString(const char* input)
return this->PhreeqcPtr->get_input_errors();
}
void IPhreeqc::SetDumpFileName(const char *filename)
{
this->DumpFileName = filename;
this->PhreeqcPtr->dump_info.Set_file_name(this->DumpFileName);
}
void IPhreeqc::SetDumpFileOn(bool bValue)
{
this->DumpOn = bValue;
@ -752,11 +794,7 @@ void IPhreeqc::do_run(const char* sz_routine, std::istream* pis, PFN_PRERUN_CALL
// do_run -- containing SELECTED_OUTPUT ****TODO**** check -file option
// another do_run with SELECTED_OUTPUT
//
std::string filename = PUNCH_FILENAME;
if (this->PunchFileName.size())
{
filename = this->PunchFileName;
}
std::string filename = this->PunchFileName;
if (!this->punch_open(filename.c_str()))
{
std::ostringstream oss;
@ -981,10 +1019,10 @@ void IPhreeqc::open_output_files(const char* sz_routine)
delete this->output_ostream;
this->output_ostream = NULL;
}
if ( (this->output_ostream = new std::ofstream(OUTPUT_FILENAME)) == NULL)
if ( (this->output_ostream = new std::ofstream(this->OutputFileName.c_str())) == NULL)
{
std::ostringstream oss;
oss << sz_routine << ": Unable to open:" << "\"" << OUTPUT_FILENAME << "\".\n";
oss << sz_routine << ": Unable to open:" << "\"" << this->OutputFileName << "\".\n";
this->warning_msg(oss.str().c_str());
}
}
@ -995,10 +1033,10 @@ void IPhreeqc::open_output_files(const char* sz_routine)
delete this->error_ostream;
this->error_ostream = NULL;
}
if ( (this->error_ostream = new std::ofstream(ERROR_FILENAME)) == NULL)
if ( (this->error_ostream = new std::ofstream(this->ErrorFileName.c_str())) == NULL)
{
std::ostringstream oss;
oss << sz_routine << ": Unable to open:" << "\"" << ERROR_FILENAME << "\".\n";
oss << sz_routine << ": Unable to open:" << "\"" << this->ErrorFileName << "\".\n";
this->warning_msg(oss.str().c_str());
}
}
@ -1009,10 +1047,10 @@ void IPhreeqc::open_output_files(const char* sz_routine)
delete this->log_ostream;
this->log_ostream = NULL;
}
if ( (this->log_ostream = new std::ofstream(LOG_FILENAME)) == NULL)
if ( (this->log_ostream = new std::ofstream(this->LogFileName.c_str())) == NULL)
{
std::ostringstream oss;
oss << sz_routine << ": Unable to open:" << "\"" << LOG_FILENAME << "\".\n";
oss << sz_routine << ": Unable to open:" << "\"" << this->LogFileName << "\".\n";
this->warning_msg(oss.str().c_str());
}
}
@ -1037,19 +1075,18 @@ int IPhreeqc::close_output_files(void)
{
int ret = 0;
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_ostream != NULL)
delete this->error_ostream;
this->error_ostream = NULL;
this->output_ostream = this->log_ostream = this->punch_ostream = NULL;
this->dump_ostream = NULL;
delete this->output_ostream;
delete this->log_ostream;
delete this->punch_ostream;
delete this->dump_ostream;
delete this->error_ostream;
this->error_ostream = 0;
this->output_ostream = 0;
this->log_ostream = 0;
this->punch_ostream = 0;
this->dump_ostream = 0;
return ret;
}
@ -1078,23 +1115,19 @@ void IPhreeqc::fpunchf_end_row(const char *format)
bool IPhreeqc::punch_open(const char *file_name, std::ios_base::openmode mode)
{
if (file_name)
if (file_name && this->PhreeqcPtr->have_punch_name)
{
this->PunchFileName = file_name;
}
if (this->SelectedOutputOn)
{
return this->PHRQ_io::punch_open(file_name, mode);
return this->PHRQ_io::punch_open(this->PunchFileName.c_str(), mode);
}
return true;
}
bool IPhreeqc::output_open(const char *file_name, std::ios_base::openmode mode)
{
if (file_name)
{
//this->PunchFileName = file_name;
}
if (this->OutputOn)
{
return this->PHRQ_io::output_open(file_name, mode);

View File

@ -11,10 +11,6 @@ public:
static int CreateIPhreeqc(void);
static IPQ_RESULT DestroyIPhreeqc(int n);
static IPhreeqc* GetInstance(int n);
private:
static std::map<size_t, IPhreeqc*> Instances;
static size_t InstancesIndex;
};
IPQ_RESULT
@ -108,6 +104,18 @@ GetComponentCount(int id)
return IPQ_BADINSTANCE;
}
const char*
GetDumpFileName(int id)
{
static const char empty[] = "";
IPhreeqc* IPhreeqcPtr = IPhreeqcLib::GetInstance(id);
if (IPhreeqcPtr)
{
return IPhreeqcPtr->GetDumpFileName();
}
return empty;
}
int
GetDumpFileOn(int id)
{
@ -458,6 +466,18 @@ RunString(int id, const char* input)
return IPQ_BADINSTANCE;
}
IPQ_RESULT
SetDumpFileName(int id, const char* filename)
{
IPhreeqc* IPhreeqcPtr = IPhreeqcLib::GetInstance(id);
if (IPhreeqcPtr)
{
IPhreeqcPtr->SetDumpFileName(filename);
return IPQ_OK;
}
return IPQ_BADINSTANCE;
}
IPQ_RESULT
SetDumpFileOn(int id, int value)
{
@ -533,9 +553,6 @@ SetSelectedOutputFileOn(int id, int value)
// helper functions
//
std::map<size_t, IPhreeqc*> IPhreeqcLib::Instances;
size_t IPhreeqcLib::InstancesIndex = 0;
int
IPhreeqcLib::CreateIPhreeqc(void)
{
@ -543,16 +560,7 @@ IPhreeqcLib::CreateIPhreeqc(void)
try
{
IPhreeqc* IPhreeqcPtr = new IPhreeqc;
if (IPhreeqcPtr)
{
std::map<size_t, IPhreeqc*>::value_type instance(IPhreeqcLib::InstancesIndex, IPhreeqcPtr);
std::pair<std::map<size_t, IPhreeqc*>::iterator, bool> pr = IPhreeqcLib::Instances.insert(instance);
if (pr.second)
{
n = (int) (*pr.first).first;
++IPhreeqcLib::InstancesIndex;
}
}
n = IPhreeqcPtr->Index;
}
catch(...)
{
@ -567,11 +575,9 @@ IPhreeqcLib::DestroyIPhreeqc(int id)
IPQ_RESULT retval = IPQ_BADINSTANCE;
if (id >= 0)
{
std::map<size_t, IPhreeqc*>::iterator it = IPhreeqcLib::Instances.find(size_t(id));
if (it != IPhreeqcLib::Instances.end())
if (IPhreeqc *ptr = IPhreeqcLib::GetInstance(id))
{
delete (*it).second;
IPhreeqcLib::Instances.erase(it);
delete ptr;
retval = IPQ_OK;
}
}
@ -581,8 +587,8 @@ IPhreeqcLib::DestroyIPhreeqc(int id)
IPhreeqc*
IPhreeqcLib::GetInstance(int id)
{
std::map<size_t, IPhreeqc*>::iterator it = IPhreeqcLib::Instances.find(size_t(id));
if (it != IPhreeqcLib::Instances.end())
std::map<size_t, IPhreeqc*>::iterator it = IPhreeqc::Instances.find(size_t(id));
if (it != IPhreeqc::Instances.end())
{
return (*it).second;
}

View File

@ -120,6 +120,12 @@ GetComponentF(int *id, int *n, char* comp, unsigned int line_length)
padfstring(comp, ::GetComponent(*id, (*n) - 1), line_length);
}
void
GetDumpFileNameF(int *id, char* fname, unsigned int fname_length)
{
padfstring(fname, ::GetDumpFileName(*id), fname_length);
}
int
GetDumpFileOnF(int *id)
{
@ -355,6 +361,23 @@ RunStringF(int *id, char* input, unsigned int input_length)
return n;
}
IPQ_RESULT
SetDumpFileNameF(int *id, char* fname, unsigned int fname_length)
{
char* cinput;
cinput = f2cstring(fname, fname_length);
if (!cinput)
{
::AddError(*id, "SetDumpFileName: Out of memory.\n");
return IPQ_OUTOFMEMORY;
}
IPQ_RESULT n = ::SetDumpFileName(*id, cinput);
free(cinput);
return n;
}
IPQ_RESULT
SetDumpFileOnF(int *id, int* dump_on)
{
@ -432,6 +455,10 @@ IPQ_DLL_EXPORT int __stdcall GETCOMPONENTCOUNT(int *id)
{
return GetComponentCountF(id);
}
IPQ_DLL_EXPORT void __stdcall GETDUMPFILENAME(int *id, char *filename, unsigned int len)
{
GetDumpFileNameF(id, filename, len);
}
IPQ_DLL_EXPORT int __stdcall GETDUMPFILEON(int *id)
{
return GetDumpFileOnF(id);
@ -527,29 +554,33 @@ IPQ_DLL_EXPORT int __stdcall RUNSTRING(int *id, char *input, unsigned int len)
{
return RunStringF(id, input, len);
}
IPQ_DLL_EXPORT void __stdcall SETDUMPFILEON(int *id, int *dump_on)
IPQ_DLL_EXPORT int __stdcall SETDUMPFILENAME(int *id, char *filename, unsigned int len)
{
SetDumpFileOnF(id, dump_on);
return SetDumpFileNameF(id, filename, len);
}
IPQ_DLL_EXPORT void __stdcall SETDUMPSTRINGON(int *id, int *dump_string_on)
IPQ_DLL_EXPORT int __stdcall SETDUMPFILEON(int *id, int *dump_on)
{
SetDumpStringOnF(id, dump_string_on);
return SetDumpFileOnF(id, dump_on);
}
IPQ_DLL_EXPORT void __stdcall SETERRORFILEON(int *id, int *error_on)
IPQ_DLL_EXPORT int __stdcall SETDUMPSTRINGON(int *id, int *dump_string_on)
{
SetErrorFileOnF(id, error_on);
return SetDumpStringOnF(id, dump_string_on);
}
IPQ_DLL_EXPORT void __stdcall SETLOGFILEON(int *id, int *log_on)
IPQ_DLL_EXPORT int __stdcall SETERRORFILEON(int *id, int *error_on)
{
SetLogFileOnF(id, log_on);
return SetErrorFileOnF(id, error_on);
}
IPQ_DLL_EXPORT void __stdcall SETOUTPUTFILEON(int *id, int *output_on)
IPQ_DLL_EXPORT int __stdcall SETLOGFILEON(int *id, int *log_on)
{
SetOutputFileOnF(id, output_on);
return SetLogFileOnF(id, log_on);
}
IPQ_DLL_EXPORT void __stdcall SETSELECTEDOUTPUTFILEON(int *id, int *selected_on)
IPQ_DLL_EXPORT int __stdcall SETOUTPUTFILEON(int *id, int *output_on)
{
SetSelOutFileOnF(id, selected_on);
return SetOutputFileOnF(id, output_on);
}
IPQ_DLL_EXPORT int __stdcall SETSELECTEDOUTPUTFILEON(int *id, int *selected_on)
{
return SetSelOutFileOnF(id, selected_on);
}
#if defined(__cplusplus)
}

View File

@ -18,6 +18,7 @@
#define GetComponentF FC_FUNC (getcomponentf, GETCOMPONENTF)
#define GetDumpStringLineCountF FC_FUNC (getdumpstringlinecountf, GETDUMPSTRINGLINECOUNTF)
#define GetDumpStringLineF FC_FUNC (getdumpstringlinef, GETDUMPSTRINGLINEF)
#define GetDumpFileNameF FC_FUNC (getdumpfilenamef, GETDUMPFILENAMEF)
#define GetDumpFileOnF FC_FUNC (getdumpfileonf, GETDUMPFILEONF)
#define GetDumpStringOnF FC_FUNC (getdumpstringonf, GETDUMPSTRINGONF)
#define GetErrorStringLineCountF FC_FUNC (geterrorstringlinecountf, GETERRORSTRINGLINECOUNTF)
@ -39,6 +40,7 @@
#define RunAccumulatedF FC_FUNC (runaccumulatedf, RUNACCUMULATEDF)
#define RunFileF FC_FUNC (runfilef, RUNFILEF)
#define RunStringF FC_FUNC (runstringf, RUNSTRINGF)
#define SetDumpFileNameF FC_FUNC (setdumpfilenamef, SETDUMPFILENAMEF)
#define SetDumpFileOnF FC_FUNC (setdumpfileonf, SETDUMPFILEONF)
#define SetDumpStringOnF FC_FUNC (setdumpstringonf, SETDUMPSTRINGONF)
#define SetErrorFileOnF FC_FUNC (seterrorfileonf, SETERRORFILEONF)
@ -61,6 +63,7 @@ extern "C" {
void GetComponentF(int *id, int* n, char* line, unsigned int line_length);
int GetDumpStringLineCountF(int *id);
void GetDumpStringLineF(int *id, int* n, char* line, unsigned int line_length);
void GetDumpFileNameF(int *id, char* filename, unsigned int filename_length);
int GetDumpFileOnF(int *id);
int GetDumpStringOnF(int *id);
int GetErrorStringLineCountF(int *id);
@ -82,6 +85,7 @@ extern "C" {
int RunAccumulatedF(int *id);
int RunFileF(int *id, char* filename, unsigned int filename_length);
int RunStringF(int *id, char* input, unsigned int input_length);
IPQ_RESULT SetDumpFileNameF(int *id, char* fname, unsigned int fname_length);
IPQ_RESULT SetDumpFileOnF(int *id, int* dump_on);
IPQ_RESULT SetDumpStringOnF(int *id, int* dump_string_on);
IPQ_RESULT SetErrorFileOnF(int *id, int* error_on);

View File

@ -43,6 +43,10 @@ IPQ_DLL_EXPORT int GETCOMPONENTCOUNT(int *id)
{
return GetComponentCountF(id);
}
IPQ_DLL_EXPORT void GETDUMPFILENAME(int *id, char *filename, unsigned int len)
{
GetDumpFileNameF(id, filename, len);
}
IPQ_DLL_EXPORT int GETDUMPFILEON(int *id)
{
return GetDumpFileOnF(id);
@ -136,29 +140,33 @@ IPQ_DLL_EXPORT int RUNSTRING(int *id, char *input, unsigned int len)
{
return RunStringF(id, input, len);
}
IPQ_DLL_EXPORT void SETDUMPFILEON(int *id, int *dump_on)
IPQ_DLL_EXPORT int SETDUMPFILENAME(int *id, char *filename, unsigned int len)
{
SetDumpFileOnF(id, dump_on);
return SetDumpFileNameF(id, filename, len);
}
IPQ_DLL_EXPORT void SETDUMPSTRINGON(int *id, int *dump_string_on)
IPQ_DLL_EXPORT int SETDUMPFILEON(int *id, int *dump_on)
{
SetDumpStringOnF(id, dump_string_on);
return SetDumpFileOnF(id, dump_on);
}
IPQ_DLL_EXPORT void SETERRORFILEON(int *id, int *error_on)
IPQ_DLL_EXPORT int SETDUMPSTRINGON(int *id, int *dump_string_on)
{
SetErrorFileOnF(id, error_on);
return SetDumpStringOnF(id, dump_string_on);
}
IPQ_DLL_EXPORT void SETLOGFILEON(int *id, int *log_on)
IPQ_DLL_EXPORT int SETERRORFILEON(int *id, int *error_on)
{
SetLogFileOnF(id, log_on);
return SetErrorFileOnF(id, error_on);
}
IPQ_DLL_EXPORT void SETOUTPUTFILEON(int *id, int *output_on)
IPQ_DLL_EXPORT int SETLOGFILEON(int *id, int *log_on)
{
SetOutputFileOnF(id, output_on);
return SetLogFileOnF(id, log_on);
}
IPQ_DLL_EXPORT void SETSELECTEDOUTPUTFILEON(int *id, int *selected_on)
IPQ_DLL_EXPORT int SETOUTPUTFILEON(int *id, int *output_on)
{
SetSelOutFileOnF(id, selected_on);
return SetOutputFileOnF(id, output_on);
}
IPQ_DLL_EXPORT int SETSELECTEDOUTPUTFILEON(int *id, int *selected_on)
{
return SetSelOutFileOnF(id, selected_on);
}
#if defined(__cplusplus)

View File

@ -14,11 +14,11 @@ IPQ_DLL_EXPORT int accumulateline_(int *id, char *line, unsigned int len)
{
return AccumulateLineF(id, line, len);
}
IPQ_DLL_EXPORT int adderror(int *id, char *error_msg, unsigned int len)
IPQ_DLL_EXPORT int adderror_(int *id, char *error_msg, unsigned int len)
{
return AddErrorF(id, error_msg, len);
}
IPQ_DLL_EXPORT int addwarning(int *id, char *warn_msg, unsigned int len)
IPQ_DLL_EXPORT int addwarning_(int *id, char *warn_msg, unsigned int len)
{
return AddWarningF(id, warn_msg, len);
}
@ -42,6 +42,10 @@ IPQ_DLL_EXPORT int getcomponentcount_(int *id)
{
return GetComponentCountF(id);
}
IPQ_DLL_EXPORT void getdumpfilename_(int *id, char *filename, unsigned int len)
{
GetDumpFileNameF(id, filename, len);
}
IPQ_DLL_EXPORT int getdumpfileon_(int *id)
{
return GetDumpFileOnF(id);
@ -137,29 +141,33 @@ IPQ_DLL_EXPORT int runstring_(int *id, char *input, unsigned int len)
{
return RunStringF(id, input, len);
}
IPQ_DLL_EXPORT void setdumpfileon_(int *id, int *dump_on)
IPQ_DLL_EXPORT int setdumpfilename_(int *id, char *filename, unsigned int len)
{
SetDumpFileOnF(id, dump_on);
return SetDumpFileNameF(id, filename, len);
}
IPQ_DLL_EXPORT void setdumpstringon_(int *id, int *dump_string_on)
IPQ_DLL_EXPORT int setdumpfileon_(int *id, int *dump_on)
{
SetDumpStringOnF(id, dump_string_on);
return SetDumpFileOnF(id, dump_on);
}
IPQ_DLL_EXPORT void seterrorfileon_(int *id, int *error_on)
IPQ_DLL_EXPORT int setdumpstringon_(int *id, int *dump_string_on)
{
SetErrorFileOnF(id, error_on);
return SetDumpStringOnF(id, dump_string_on);
}
IPQ_DLL_EXPORT void setlogfileon_(int *id, int *log_on)
IPQ_DLL_EXPORT int seterrorfileon_(int *id, int *error_on)
{
SetLogFileOnF(id, log_on);
return SetErrorFileOnF(id, error_on);
}
IPQ_DLL_EXPORT void setoutputfileon_(int *id, int *output_on)
IPQ_DLL_EXPORT int setlogfileon_(int *id, int *log_on)
{
SetOutputFileOnF(id, output_on);
return SetLogFileOnF(id, log_on);
}
IPQ_DLL_EXPORT void setselectedoutputfileon_(int *id, int *selected_on)
IPQ_DLL_EXPORT int setoutputfileon_(int *id, int *output_on)
{
SetSelOutFileOnF(id, selected_on);
return SetOutputFileOnF(id, output_on);
}
IPQ_DLL_EXPORT int setselectedoutputfileon_(int *id, int *selected_on)
{
return SetSelOutFileOnF(id, selected_on);
}
#if defined(__cplusplus)

View File

@ -12,7 +12,8 @@
INTEGER(KIND=4) F_MAIN
INTEGER(KIND=4) TestGetSet
INTEGER(KIND=4) TestGetSetName
INTEGER(KIND=4) EXIT_SUCCESS
PARAMETER (EXIT_SUCCESS=0)
@ -36,6 +37,9 @@
EXTERNAL GetSelectedOutputFileOn
EXTERNAL SetSelectedOutputFileOn
EXTERNAL GetDumpFileName
EXTERNAL SetDumpFileName
id = CreateIPhreeqc()
IF (id.LT.0) THEN
@ -55,6 +59,12 @@ C Dump string
RETURN
END IF
C Dump filename
IF (TestGetSetName(id,GetDumpFileName,SetDumpFileName).NE.0) THEN
F_MAIN = EXIT_FAILURE
RETURN
END IF
C Error
IF (TestGetSet(id,GetErrorFileOn,SetErrorFileOn).NE.0) THEN
F_MAIN = EXIT_FAILURE
@ -155,3 +165,56 @@ C Selected output
RETURN
END FUNCTION TestGetSet
FUNCTION TestGetSetName(id,getFuncName,setFuncName)
IMPLICIT NONE
INCLUDE 'IPhreeqc.f.inc'
INTEGER(KIND=4) id
INTEGER(KIND=4) TestGetSetName
EXTERNAL getFuncName
INTEGER(KIND=4) setFuncName
INTEGER(KIND=4) EXIT_SUCCESS
PARAMETER (EXIT_SUCCESS=0)
INTEGER(KIND=4) EXIT_FAILURE
PARAMETER (EXIT_FAILURE=1)
CHARACTER(LEN=80) FILEN
CALL getFuncName(id,FILEN)
IF (setFuncName(id,'ABCDEFG').NE.IPQ_OK) THEN
TestGetSetName = EXIT_FAILURE
WRITE(*,*) "FAILURE"
RETURN
END IF
CALL getFuncName(id,FILEN)
IF (.NOT.LLE('ABCDEFG', FILEN)) THEN
TestGetSetName = EXIT_FAILURE
WRITE(*,*) "FAILURE"
RETURN
END IF
IF (setFuncName(id,'XYZ').NE.IPQ_OK) THEN
TestGetSetName = EXIT_FAILURE
WRITE(*,*) "FAILURE"
RETURN
END IF
CALL getFuncName(id,FILEN)
IF (.NOT.LLE('XYZ', FILEN)) THEN
TestGetSetName = EXIT_FAILURE
WRITE(*,*) "FAILURE"
RETURN
END IF
TestGetSetName = EXIT_SUCCESS
RETURN
END FUNCTION TestGetSetName

View File

@ -12,6 +12,7 @@ FUNCTION F_MAIN()
INTEGER(KIND=4) F_MAIN
INTEGER(KIND=4) TestGetSet
INTEGER(KIND=4) TestGetSetName
INTEGER(KIND=4),PARAMETER :: EXIT_SUCCESS = 0
INTEGER(KIND=4),PARAMETER :: EXIT_FAILURE = 1
@ -46,6 +47,12 @@ FUNCTION F_MAIN()
RETURN
END IF
! Dump filename
IF (TestGetSetName(id,GetDumpFileName,SetDumpFileName).NE.0) THEN
F_MAIN = EXIT_FAILURE
RETURN
END IF
! Error
IF (TestGetSet(id,GetErrorFileOn,SetErrorFileOn).NE.0) THEN
F_MAIN = EXIT_FAILURE
@ -110,7 +117,7 @@ FUNCTION TestGetSet(id,getFunc,setFunc)
IMPLICIT NONE
INCLUDE 'IPhreeqc.f90.inc'
INTEGER(KIND=4) id
INTEGER(KIND=4) TESTGETSET
INTEGER(KIND=4) TestGetSet
INTERFACE
FUNCTION getFunc(id)
INTEGER(KIND=4) id
@ -129,21 +136,25 @@ FUNCTION TestGetSet(id,getFunc,setFunc)
IF (getFunc(id)) THEN
TestGetSet = EXIT_FAILURE
WRITE(*,*) "FAILURE"
RETURN
END IF
IF (setFunc(id,.TRUE.).NE.IPQ_OK) THEN
TestGetSet = EXIT_FAILURE
WRITE(*,*) "FAILURE"
RETURN
END IF
IF (.NOT.getFunc(id)) THEN
TestGetSet = EXIT_FAILURE
WRITE(*,*) "FAILURE"
RETURN
END IF
IF (setFunc(id,.FALSE.).NE.IPQ_OK) THEN
TestGetSet = EXIT_FAILURE
WRITE(*,*) "FAILURE"
RETURN
END IF
@ -151,3 +162,62 @@ FUNCTION TestGetSet(id,getFunc,setFunc)
RETURN
END FUNCTION TestGetSet
FUNCTION TestGetSetName(id,getFuncName,setFuncName)
IMPLICIT NONE
INCLUDE 'IPhreeqc.f90.inc'
INTEGER(KIND=4) id
INTEGER(KIND=4) TestGetSetName
INTERFACE
SUBROUTINE getFuncName(id,fname)
INTEGER(KIND=4) id
CHARACTER(LEN=*) fname
END SUBROUTINE getFuncName
END INTERFACE
INTERFACE
FUNCTION setFuncName(id,fname)
INTEGER(KIND=4) id
CHARACTER(LEN=*) fname
INTEGER(KIND=4) setFuncName
END FUNCTION setFuncName
END INTERFACE
INTEGER(KIND=4),PARAMETER :: EXIT_SUCCESS = 0
INTEGER(KIND=4),PARAMETER :: EXIT_FAILURE = 1
CHARACTER(LEN=80) FILEN
CALL getFuncName(id,FILEN)
FILEN = 'ABCDEFG'
IF (setFuncName(id,FILEN).NE.IPQ_OK) THEN
TestGetSetName = EXIT_FAILURE
WRITE(*,*) "FAILURE"
RETURN
END IF
CALL getFuncName(id,FILEN)
IF (.NOT.LLE('ABCDEFG', FILEN)) THEN
TestGetSetName = EXIT_FAILURE
WRITE(*,*) "FAILURE"
RETURN
END IF
IF (setFuncName(id,'XYZ').NE.IPQ_OK) THEN
TestGetSetName = EXIT_FAILURE
WRITE(*,*) "FAILURE"
RETURN
END IF
CALL getFuncName(id,FILEN)
IF (.NOT.LLE('XYZ', FILEN)) THEN
TestGetSetName = EXIT_FAILURE
WRITE(*,*) "FAILURE"
RETURN
END IF
TestGetSetName = EXIT_SUCCESS
RETURN
END FUNCTION TestGetSetName

View File

@ -354,24 +354,27 @@ void TestIPhreeqc::TestRunString(void)
IPhreeqc obj;
if (::FileExists("phreeqc.out"))
char OUTPUT_FILE[80];
sprintf(OUTPUT_FILE, "phreeqc.%d.out", obj.Index);
if (::FileExists(OUTPUT_FILE))
{
CPPUNIT_ASSERT(::DeleteFile("phreeqc.out"));
CPPUNIT_ASSERT(::DeleteFile(OUTPUT_FILE));
}
CPPUNIT_ASSERT_EQUAL(false, ::FileExists("phreeqc.out"));
CPPUNIT_ASSERT_EQUAL(false, ::FileExists(OUTPUT_FILE));
CPPUNIT_ASSERT_EQUAL(0, obj.LoadDatabase("phreeqc.dat"));
obj.SetOutputFileOn(1);
obj.SetErrorFileOn(0);
obj.SetLogFileOn(0);
obj.SetSelectedOutputFileOn(0);
obj.SetDumpFileOn(0);
CPPUNIT_ASSERT_EQUAL(false, ::FileExists("phreeqc.out"));
CPPUNIT_ASSERT_EQUAL(false, ::FileExists(OUTPUT_FILE));
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_EQUAL(true, ::FileExists(OUTPUT_FILE));
CPPUNIT_ASSERT(::FileSize(OUTPUT_FILE) > 0);
if (::FileExists(OUTPUT_FILE))
{
CPPUNIT_ASSERT(::DeleteFile("phreeqc.out"));
CPPUNIT_ASSERT(::DeleteFile(OUTPUT_FILE));
}
}
@ -1096,12 +1099,15 @@ void TestIPhreeqc::TestCase1(void)
IPhreeqc obj;
char SELECTED_OUT[80];
sprintf(SELECTED_OUT, "selected.%d.out", obj.Index);
// remove punch file if it exists
if (::FileExists("selected.out"))
if (::FileExists(SELECTED_OUT))
{
CPPUNIT_ASSERT(::DeleteFile("selected.out"));
CPPUNIT_ASSERT(::DeleteFile(SELECTED_OUT));
}
CPPUNIT_ASSERT_EQUAL( false, ::FileExists("selected.out") );
CPPUNIT_ASSERT_EQUAL( false, ::FileExists(SELECTED_OUT) );
// clear all flags
@ -1118,8 +1124,8 @@ void TestIPhreeqc::TestCase1(void)
obj.SetSelectedOutputFileOn(true);
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( 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) );
@ -1129,8 +1135,8 @@ void TestIPhreeqc::TestCase1(void)
obj.SetSelectedOutputFileOn(true);
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( true, ::FileExists(SELECTED_OUT) );
CPPUNIT_ASSERT( ::FileSize(SELECTED_OUT) > 0 );
CPPUNIT_ASSERT_EQUAL( 62, obj.GetSelectedOutputColumnCount() );
}
@ -1279,7 +1285,7 @@ void TestIPhreeqc::TestOutputOnOff()
onoff[2] = false; // log_on
onoff[3] = false; // selected_output_on
onoff[4] = false; // dump_on
::TestOnOff("phreeqc.out", onoff[0], onoff[1], onoff[2], onoff[3], onoff[4]);
::TestOnOff("phreeqc.%d.out", onoff[0], onoff[1], onoff[2], onoff[3], onoff[4]);
}
void TestIPhreeqc::TestErrorOnOff()
@ -1290,7 +1296,7 @@ void TestIPhreeqc::TestErrorOnOff()
onoff[2] = false; // log_on
onoff[3] = false; // selected_output_on
onoff[4] = false; // dump_on
::TestOnOff("phreeqc.err", onoff[0], onoff[1], onoff[2], onoff[3], onoff[4]);
::TestOnOff("phreeqc.%d.err", onoff[0], onoff[1], onoff[2], onoff[3], onoff[4]);
}
void TestIPhreeqc::TestLogOnOff()
@ -1301,10 +1307,10 @@ void TestIPhreeqc::TestLogOnOff()
onoff[2] = true; // log_on
onoff[3] = false; // selected_output_on
onoff[4] = false; // dump_on
::TestOnOff("phreeqc.log", onoff[0], onoff[1], onoff[2], onoff[3], onoff[4]);
::TestOnOff("phreeqc.%d.log", onoff[0], onoff[1], onoff[2], onoff[3], onoff[4]);
}
void TestIPhreeqc::TestDumpOn()
void TestIPhreeqc::TestDumpOnOff()
{
bool onoff[5];
onoff[0] = false; // output_on
@ -1312,7 +1318,7 @@ void TestIPhreeqc::TestDumpOn()
onoff[2] = false; // log_on
onoff[3] = false; // selected_output_on
onoff[4] = true; // dump_on
::TestOnOff("dump.out", onoff[0], onoff[1], onoff[2], onoff[3], onoff[4]);
::TestOnOff("dump.%d.out", onoff[0], onoff[1], onoff[2], onoff[3], onoff[4]);
}
void TestIPhreeqc::TestSelOutOnOff()
@ -1323,13 +1329,16 @@ void TestIPhreeqc::TestSelOutOnOff()
onoff[2] = false; // log_on
onoff[3] = true; // selected_output_on
onoff[4] = false; // dump_on
::TestOnOff("selected.out", onoff[0], onoff[1], onoff[2], onoff[3], onoff[4]);
::TestOnOff("selected.%d.out", onoff[0], onoff[1], onoff[2], onoff[3], onoff[4]);
}
void TestOnOff(const char* FILENAME, bool output_on, bool error_on, bool log_on, bool selected_output_on, bool dump_on)
void TestOnOff(const char* FILENAME_FORMAT, bool output_on, bool error_on, bool log_on, bool selected_output_on, bool dump_on)
{
IPhreeqc obj;
char FILENAME[80];
sprintf(FILENAME, FILENAME_FORMAT, obj.GetId());
// remove FILENAME if it exists
//
if (::FileExists(FILENAME))
@ -1486,7 +1495,6 @@ SELECTED_OUTPUT(IPhreeqc& obj)
std::ostringstream oss;
oss << "SELECTED_OUTPUT" << "\n";
oss << "-file selected.out" << "\n";
oss << "-totals C Ca Na" << "\n";
return obj.AccumulateLine(oss.str().c_str());
@ -1878,3 +1886,117 @@ void TestIPhreeqc::TestListComponents(void)
CPPUNIT_ASSERT_EQUAL( std::string("Ca"), std::string((*it++)) );
CPPUNIT_ASSERT_EQUAL( std::string("Na"), std::string((*it++)) );
}
void TestIPhreeqc::TestSetDumpFileName(void)
{
char DUMP_FILENAME[80];
sprintf(DUMP_FILENAME, "dump.%06d.log", ::rand());
if (::FileExists(DUMP_FILENAME))
{
::DeleteFile(DUMP_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(false);
obj.SetErrorFileOn(false);
obj.SetLogFileOn(false);
obj.SetSelectedOutputFileOn(false);
obj.SetDumpStringOn(false);
obj.SetDumpFileOn(true);
obj.SetDumpFileName(DUMP_FILENAME);
CPPUNIT_ASSERT_EQUAL( 0, obj.RunAccumulated() );
CPPUNIT_ASSERT_EQUAL( true, ::FileExists(DUMP_FILENAME) );
std::string lines[30];
std::ifstream ifs(DUMP_FILENAME);
size_t i = 0;
while (std::getline(ifs, lines[i]) && i < sizeof(lines)/sizeof(lines[0]))
{
++i;
}
int line = 0;
#if defined(_MSC_VER)
CPPUNIT_ASSERT_EQUAL( std::string("SOLUTION_RAW 1 "), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -temp 25"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -total_h 111.0132593403"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -total_o 55.509043478605"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -cb 0.0021723831003929"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -totals"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" C(4) 0.0010000000000376"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" Ca 0.001000000004331"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" H(0) 1.4149476909313e-025"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" Na 0.001"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -Isotopes"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -pH 7"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -pe 4"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -mu 0.0028961089894362"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -ah2o 0.99994915105857"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -mass_water 1"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -total_alkalinity 0.00082761690826911"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -activities"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" C(-4) -67.370522674574"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" C(4) -6.4415889265024"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" Ca -3.1040445240857"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" E -4"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" H(0) -25.15"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" Na -3.0255625287599"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" O(0) -42.080044167952"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -gammas"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string("USE mix none"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string("USE reaction none"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string("USE reaction_temperature none"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string("USE reaction_pressure none"), lines[line++] );
#endif
#if defined(__GNUC__)
CPPUNIT_ASSERT_EQUAL( std::string("SOLUTION_RAW 1 "), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -temp 25"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -total_h 111.0132593403"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -total_o 55.509043478605"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -cb 0.0021723831003928"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -totals"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" C(4) 0.0010000000000376"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" Ca 0.001000000004331"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" H(0) 1.4149476909313e-25"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" Na 0.001"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -Isotopes"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -pH 7"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -pe 4"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -mu 0.0028961089894362"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -ah2o 0.99994915105857"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -mass_water 1"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -total_alkalinity 0.00082761690826912"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -activities"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" C(-4) -67.370522674574"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" C(4) -6.4415889265024"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" Ca -3.1040445240857"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" E -4"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" H(0) -25.15"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" Na -3.0255625287599"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" O(0) -42.080044167952"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -gammas"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string("USE mix none"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string("USE reaction none"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string("USE reaction_temperature none"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string("USE reaction_pressure none"), lines[line++] );
#endif
if (::FileExists(DUMP_FILENAME))
{
::DeleteFile(DUMP_FILENAME);
}
}

View File

@ -29,7 +29,7 @@ class TestIPhreeqc : public CppUnit::TestFixture
CPPUNIT_TEST( TestOutputOnOff );
CPPUNIT_TEST( TestErrorOnOff );
CPPUNIT_TEST( TestLogOnOff );
CPPUNIT_TEST( TestDumpOn );
CPPUNIT_TEST( TestDumpOnOff );
CPPUNIT_TEST( TestSelOutOnOff );
CPPUNIT_TEST( TestLongHeadings );
CPPUNIT_TEST( TestDatabaseKeyword );
@ -39,6 +39,7 @@ class TestIPhreeqc : public CppUnit::TestFixture
CPPUNIT_TEST( TestGetComponentCount );
CPPUNIT_TEST( TestGetComponent );
CPPUNIT_TEST( TestListComponents );
CPPUNIT_TEST( TestSetDumpFileName );
CPPUNIT_TEST_SUITE_END();
public:
@ -68,7 +69,7 @@ public:
void TestOutputOnOff(void);
void TestErrorOnOff(void);
void TestLogOnOff(void);
void TestDumpOn(void);
void TestDumpOnOff(void);
void TestSelOutOnOff(void);
void TestLongHeadings(void);
void TestDatabaseKeyword(void);
@ -78,6 +79,7 @@ public:
void TestGetComponentCount(void);
void TestGetComponent(void);
void TestListComponents(void);
void TestSetDumpFileName(void);
};

View File

@ -425,30 +425,35 @@ void TestIPhreeqcLib::TestRunString(void)
"END\n"
"\n";
if (::FileExists("phreeqc.out"))
{
CPPUNIT_ASSERT(::DeleteFile("phreeqc.out"));
}
CPPUNIT_ASSERT_EQUAL(false, ::FileExists("phreeqc.out"));
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, 1);
::SetErrorFileOn(n, 0);
::SetLogFileOn(n, 0);
::SetSelectedOutputFileOn(n, 0);
::SetDumpFileOn(n, 0);
CPPUNIT_ASSERT_EQUAL(false, ::FileExists("phreeqc.out"));
CPPUNIT_ASSERT_EQUAL(false, ::FileExists(OUTPUT_FILE));
CPPUNIT_ASSERT_EQUAL(0, ::RunString(n, input));
CPPUNIT_ASSERT_EQUAL(true, ::FileExists("phreeqc.out"));
CPPUNIT_ASSERT(::FileSize("phreeqc.out") > 0);
CPPUNIT_ASSERT_EQUAL(true, ::FileExists(OUTPUT_FILE));
CPPUNIT_ASSERT(::FileSize(OUTPUT_FILE) > 0);
if (n >= 0)
{
CPPUNIT_ASSERT_EQUAL(IPQ_OK, ::DestroyIPhreeqc(n));
}
if (::FileExists("phreeqc.out"))
if (::FileExists(OUTPUT_FILE))
{
CPPUNIT_ASSERT(::DeleteFile("phreeqc.out"));
CPPUNIT_ASSERT(::DeleteFile(OUTPUT_FILE));
}
}
@ -1159,7 +1164,6 @@ SELECTED_OUTPUT(int n)
std::ostringstream oss;
oss << "SELECTED_OUTPUT" << "\n";
oss << "-file selected.out" << "\n";
oss << "-totals C Ca Na" << "\n";
return ::AccumulateLine(n, oss.str().c_str());
@ -1285,12 +1289,15 @@ void TestIPhreeqcLib::TestCase1(void)
int n = ::CreateIPhreeqc();
CPPUNIT_ASSERT(n >= 0);
char SELECTED_OUT[80];
sprintf(SELECTED_OUT, "selected.%d.out", n);
// remove punch file if it exists
if (::FileExists("selected.out"))
if (::FileExists(SELECTED_OUT))
{
CPPUNIT_ASSERT(::DeleteFile("selected.out"));
CPPUNIT_ASSERT(::DeleteFile(SELECTED_OUT));
}
CPPUNIT_ASSERT_EQUAL( false, ::FileExists("selected.out") );
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") );
@ -1298,14 +1305,14 @@ void TestIPhreeqcLib::TestCase1(void)
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( 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( true, ::FileExists(SELECTED_OUT) );
CPPUNIT_ASSERT( ::FileSize(SELECTED_OUT) > 0 );
CPPUNIT_ASSERT_EQUAL( 62, ::GetSelectedOutputColumnCount(n) );
if (n >= 0)
@ -1325,17 +1332,20 @@ void TestIPhreeqcLib::TestCase2(void)
int n = ::CreateIPhreeqc();
CPPUNIT_ASSERT(n >= 0);
char SELECTED_OUT[80];
sprintf(SELECTED_OUT, "selected.%d.out", n);
// remove punch files if they exists
//
if (::FileExists("selected.out"))
if (::FileExists(SELECTED_OUT))
{
::DeleteFile("selected.out");
::DeleteFile(SELECTED_OUT);
}
if (::FileExists("case2.punch"))
{
::DeleteFile("case2.punch");
}
CPPUNIT_ASSERT_EQUAL( false, ::FileExists("selected.out") );
CPPUNIT_ASSERT_EQUAL( false, ::FileExists(SELECTED_OUT) );
CPPUNIT_ASSERT_EQUAL( false, ::FileExists("case2.punch") );
CPPUNIT_ASSERT_EQUAL( 0, ::LoadDatabase(n, "phreeqc.dat") );
CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SOLUTION(n, 1.0, 1.0, 1.0) );
@ -1343,7 +1353,7 @@ void TestIPhreeqcLib::TestCase2(void)
CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::AccumulateLine(n, "-file case2.punch") ); // force have_punch_name to TRUE (see read_selected_ouput)
CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SetSelectedOutputFileOn(n, 1) );
CPPUNIT_ASSERT_EQUAL( 0, ::RunAccumulated(n) );
CPPUNIT_ASSERT_EQUAL( false, ::FileExists("selected.out") );
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) );
@ -1351,21 +1361,21 @@ void TestIPhreeqcLib::TestCase2(void)
// remove punch files if they exists
//
if (::FileExists("selected.out"))
if (::FileExists(SELECTED_OUT))
{
::DeleteFile("selected.out");
::DeleteFile(SELECTED_OUT);
}
if (::FileExists("case2.punch"))
{
::DeleteFile("case2.punch");
}
CPPUNIT_ASSERT_EQUAL( false, ::FileExists("selected.out") );
CPPUNIT_ASSERT_EQUAL( false, ::FileExists(SELECTED_OUT) );
CPPUNIT_ASSERT_EQUAL( false, ::FileExists("case2.punch") );
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( false, ::FileExists("selected.out") );
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) );
@ -1444,7 +1454,7 @@ void TestIPhreeqcLib::TestOutputOnOff()
onoff[2] = 0; // log_on
onoff[3] = 0; // selected_output_on
onoff[4] = 0; // dump_on
TestOnOff("phreeqc.out", onoff[0], onoff[1], onoff[2], onoff[3], onoff[4]);
TestOnOff("phreeqc.%d.out", onoff[0], onoff[1], onoff[2], onoff[3], onoff[4]);
}
void TestIPhreeqcLib::TestErrorOnOff()
@ -1455,7 +1465,7 @@ void TestIPhreeqcLib::TestErrorOnOff()
onoff[2] = 0; // log_on
onoff[3] = 0; // selected_output_on
onoff[4] = 0; // dump_on
TestOnOff("phreeqc.err", onoff[0], onoff[1], onoff[2], onoff[3], onoff[4]);
TestOnOff("phreeqc.%d.err", onoff[0], onoff[1], onoff[2], onoff[3], onoff[4]);
}
void TestIPhreeqcLib::TestLogOnOff()
@ -1466,10 +1476,10 @@ void TestIPhreeqcLib::TestLogOnOff()
onoff[2] = 1; // log_on
onoff[3] = 0; // selected_output_on
onoff[4] = 0; // dump_on
TestOnOff("phreeqc.log", onoff[0], onoff[1], onoff[2], onoff[3], onoff[4]);
TestOnOff("phreeqc.%d.log", onoff[0], onoff[1], onoff[2], onoff[3], onoff[4]);
}
void TestIPhreeqcLib::TestDumpOn()
void TestIPhreeqcLib::TestDumpOnOff()
{
int onoff[5];
onoff[0] = 0; // output_on
@ -1477,7 +1487,7 @@ void TestIPhreeqcLib::TestDumpOn()
onoff[2] = 0; // log_on
onoff[3] = 0; // selected_output_on
onoff[4] = 1; // dump_on
TestOnOff("dump.out", onoff[0], onoff[1], onoff[2], onoff[3], onoff[4]);
TestOnOff("dump.%d.out", onoff[0], onoff[1], onoff[2], onoff[3], onoff[4]);
}
void TestIPhreeqcLib::TestSelOutOnOff()
@ -1486,18 +1496,21 @@ void TestIPhreeqcLib::TestSelOutOnOff()
onoff[0] = 0; // output_on
onoff[1] = 0; // error_on
onoff[2] = 0; // log_on
onoff[3] = 1; // selected_output_on
onoff[3] = 1; // selected_output_on
onoff[4] = 0; // dump_on
TestOnOff("selected.out", onoff[0], onoff[1], onoff[2], onoff[3], onoff[4]);
TestOnOff("selected.%d.out", onoff[0], onoff[1], onoff[2], onoff[3], onoff[4]);
}
void TestIPhreeqcLib::TestOnOff(const char* FILENAME, int output_on, int error_on, int log_on, int selected_output_on, int dump_on)
void TestIPhreeqcLib::TestOnOff(const char* FILENAME_FORMAT, int output_on, int error_on, int log_on, int selected_output_on, int dump_on)
{
int dump_string_on = 0;
int n = ::CreateIPhreeqc();
CPPUNIT_ASSERT(n >= 0);
char FILENAME[80];
sprintf(FILENAME, FILENAME_FORMAT, n);
// remove FILENAME if it exists
//
if (::FileExists(FILENAME))
@ -2083,11 +2096,12 @@ void TestIPhreeqcLib::TestGetErrorStringLine(void)
void TestIPhreeqcLib::TestErrorFileOn(void)
{
const char FILENAME[] = "phreeqc.err";
int n = ::CreateIPhreeqc();
CPPUNIT_ASSERT(n >= 0);
char FILENAME[80];
sprintf(FILENAME, "phreeqc.%d.err", n);
if (::FileExists(FILENAME))
{
::DeleteFile(FILENAME);
@ -2130,11 +2144,12 @@ void TestIPhreeqcLib::TestErrorFileOn(void)
void TestIPhreeqcLib::TestLogFileOn(void)
{
const char FILENAME[] = "phreeqc.log";
int n = ::CreateIPhreeqc();
CPPUNIT_ASSERT(n >= 0);
char FILENAME[80];
sprintf(FILENAME, "phreeqc.%d.log", n);
if (::FileExists(FILENAME))
{
::DeleteFile(FILENAME);
@ -2146,6 +2161,7 @@ void TestIPhreeqcLib::TestLogFileOn(void)
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) );
@ -2288,3 +2304,131 @@ void TestIPhreeqcLib::TestClearAccumulatedLines(void)
CPPUNIT_ASSERT_EQUAL(IPQ_OK, ::DestroyIPhreeqc(id));
}
}
void TestIPhreeqcLib::TestSetDumpFileName(void)
{
char DUMP_FILENAME[80];
sprintf(DUMP_FILENAME, "dump.%06d.out", ::rand());
if (::FileExists(DUMP_FILENAME))
{
::DeleteFile(DUMP_FILENAME);
}
int n = ::CreateIPhreeqc();
CPPUNIT_ASSERT(n >= 0);
CPPUNIT_ASSERT_EQUAL( 0, ::LoadDatabase(n, "phreeqc.dat"));
// add solution block
CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SOLUTION(n, 1.0, 1.0, 1.0) );
// add dump block
CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::DUMP(n) );
// run
CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SetOutputFileOn(n, 0) );
CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SetErrorFileOn(n, 0) );
CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SetLogFileOn(n, 0) );
CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SetSelectedOutputFileOn(n, 0) );
CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SetDumpStringOn(n, 0) );
CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SetDumpFileOn(n, 1) );
CPPUNIT_ASSERT_EQUAL( IPQ_OK, ::SetDumpFileName(n, DUMP_FILENAME) );
CPPUNIT_ASSERT_EQUAL( std::string(DUMP_FILENAME), std::string(::GetDumpFileName(n)) );
CPPUNIT_ASSERT_EQUAL( 0, ::RunAccumulated(n) );
CPPUNIT_ASSERT_EQUAL( std::string(DUMP_FILENAME), std::string(::GetDumpFileName(n)) );
CPPUNIT_ASSERT_EQUAL( true, ::FileExists(DUMP_FILENAME) );
std::string lines[32];
std::ifstream ifs(DUMP_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("SOLUTION_RAW 1 "), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -temp 25"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -total_h 111.0132593403"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -total_o 55.509043478605"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -cb 0.0021723831003929"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -totals"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" C(4) 0.0010000000000376"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" Ca 0.001000000004331"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" H(0) 1.4149476909313e-025"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" Na 0.001"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -Isotopes"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -pH 7"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -pe 4"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -mu 0.0028961089894362"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -ah2o 0.99994915105857"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -mass_water 1"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -total_alkalinity 0.00082761690826911"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -activities"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" C(-4) -67.370522674574"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" C(4) -6.4415889265024"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" Ca -3.1040445240857"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" E -4"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" H(0) -25.15"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" Na -3.0255625287599"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" O(0) -42.080044167952"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -gammas"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string("USE mix none"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string("USE reaction none"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string("USE reaction_temperature none"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string("USE reaction_pressure none"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] );
#endif
#if defined(__GNUC__)
CPPUNIT_ASSERT_EQUAL( std::string("SOLUTION_RAW 1 "), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -temp 25"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -total_h 111.0132593403"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -total_o 55.509043478605"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -cb 0.0021723831003928"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -totals"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" C(4) 0.0010000000000376"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" Ca 0.001000000004331"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" H(0) 1.4149476909313e-25"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" Na 0.001"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -Isotopes"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -pH 7"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -pe 4"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -mu 0.0028961089894362"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -ah2o 0.99994915105857"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -mass_water 1"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -total_alkalinity 0.00082761690826912"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -activities"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" C(-4) -67.370522674574"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" C(4) -6.4415889265024"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" Ca -3.1040445240857"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" E -4"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" H(0) -25.15"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" Na -3.0255625287599"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" O(0) -42.080044167952"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(" -gammas"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string("USE mix none"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string("USE reaction none"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string("USE reaction_temperature none"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string("USE reaction_pressure none"), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] );
CPPUNIT_ASSERT_EQUAL( std::string(""), lines[line++] );
#endif
if (::FileExists(DUMP_FILENAME))
{
::DeleteFile(DUMP_FILENAME);
}
if (n >= 0)
{
CPPUNIT_ASSERT_EQUAL(IPQ_OK, ::DestroyIPhreeqc(n));
}
}

View File

@ -31,7 +31,7 @@ class TestIPhreeqcLib : public CppUnit::TestFixture
CPPUNIT_TEST( TestOutputOnOff );
CPPUNIT_TEST( TestErrorOnOff );
CPPUNIT_TEST( TestLogOnOff );
CPPUNIT_TEST( TestDumpOn );
CPPUNIT_TEST( TestDumpOnOff );
CPPUNIT_TEST( TestSelOutOnOff );
CPPUNIT_TEST( TestLongHeadings );
CPPUNIT_TEST( TestDatabaseKeyword ); // ***
@ -46,6 +46,7 @@ class TestIPhreeqcLib : public CppUnit::TestFixture
CPPUNIT_TEST( TestGetWarningStringLine );
CPPUNIT_TEST( TestPitzer );
CPPUNIT_TEST( TestClearAccumulatedLines );
CPPUNIT_TEST( TestSetDumpFileName );
CPPUNIT_TEST_SUITE_END();
public:
@ -77,7 +78,7 @@ public:
void TestOutputOnOff(void);
void TestErrorOnOff(void);
void TestLogOnOff(void);
void TestDumpOn(void);
void TestDumpOnOff(void);
void TestSelOutOnOff(void);
void TestLongHeadings(void);
void TestDatabaseKeyword();
@ -92,7 +93,7 @@ public:
void TestGetWarningStringLine(void);
void TestPitzer(void);
void TestClearAccumulatedLines(void);
void TestSetDumpFileName(void);
protected:
void TestOnOff(const char* FILENAME, int output_on, int error_on, int log_on, int selected_output_on, int dump_on);