passes all cunit tests on win32

git-svn-id: svn://136.177.114.72/svn_GW/IPhreeqc/branches/class@4200 1feff8c3-07ed-0310-ac33-dd36852eb9cd
This commit is contained in:
Scott R Charlton 2010-04-01 23:11:17 +00:00
parent c0fd5b6c0f
commit dafa59942f
8 changed files with 3987 additions and 85 deletions

1760
unit/TestIPhreeqc.cpp Normal file

File diff suppressed because it is too large Load Diff

84
unit/TestIPhreeqc.h Normal file
View File

@ -0,0 +1,84 @@
#if !defined(TESTIPHREEQC_H_INCLUDED)
#define TESTIPHREEQC_H_INCLUDED
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/TestFixture.h>
class TestIPhreeqc : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE( TestIPhreeqc );
CPPUNIT_TEST( TestLoadDatabase );
CPPUNIT_TEST( TestLoadDatabaseString );
CPPUNIT_TEST( TestLoadDatabaseMissingFile );
CPPUNIT_TEST( TestLoadDatabaseWithErrors );
CPPUNIT_TEST( TestRun );
CPPUNIT_TEST( TestRunWithErrors );
CPPUNIT_TEST( TestRunFile );
CPPUNIT_TEST( TestGetSelectedOutputRowCount );
CPPUNIT_TEST( TestGetSelectedOutputValue );
CPPUNIT_TEST( TestGetSelectedOutputColumnCount );
CPPUNIT_TEST( TestAddError );
CPPUNIT_TEST( TestAccumulateLine );
CPPUNIT_TEST( TestOutputLastError );
CPPUNIT_TEST( TestRunWithCallback );
CPPUNIT_TEST( TestRunNoDatabaseLoaded );
CPPUNIT_TEST( TestCase1 );
CPPUNIT_TEST( TestCase2 );
CPPUNIT_TEST( TestPrintSelectedOutputFalse );
CPPUNIT_TEST( TestOutputOnOff );
CPPUNIT_TEST( TestErrorOnOff );
CPPUNIT_TEST( TestLogOnOff );
CPPUNIT_TEST( TestDumpOn );
CPPUNIT_TEST( TestSelOutOnOff );
CPPUNIT_TEST( TestLongHeadings );
CPPUNIT_TEST( TestDatabaseKeyword );
CPPUNIT_TEST( TestDumpString );
CPPUNIT_TEST( TestGetDumpLineCount );
CPPUNIT_TEST( TestGetDumpLine );
CPPUNIT_TEST( TestGetComponentCount );
CPPUNIT_TEST( TestGetComponent );
CPPUNIT_TEST( TestListComponents );
CPPUNIT_TEST_SUITE_END();
public:
TestIPhreeqc(void);
~TestIPhreeqc(void);
// COMMENT: {3/30/2010 3:27:03 PM} static bool FileExists(const char *szPathName);
public:
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 TestCase1(void);
void TestCase2(void);
void TestPrintSelectedOutputFalse(void);
void TestOutputOnOff(void);
void TestErrorOnOff(void);
void TestLogOnOff(void);
void TestDumpOn(void);
void TestSelOutOnOff(void);
void TestLongHeadings(void);
void TestDatabaseKeyword(void);
void TestDumpString(void);
void TestGetDumpLineCount(void);
void TestGetDumpLine(void);
void TestGetComponentCount(void);
void TestGetComponent(void);
void TestListComponents(void);
};
#endif // TESTIPHREEQC_H_INCLUDED

1839
unit/TestIPhreeqcLib.cpp Normal file

File diff suppressed because it is too large Load Diff

88
unit/TestIPhreeqcLib.h Normal file
View File

@ -0,0 +1,88 @@
#if !defined(TEST_IPHREEQC_LIB_H_INCLUDED)
#define TEST_IPHREEQC_LIB_H_INCLUDED
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/TestFixture.h>
class TestIPhreeqcLib : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE( TestIPhreeqcLib );
CPPUNIT_TEST( TestCreateIPhreeqc );
CPPUNIT_TEST( TestDestroyIPhreeqc );
CPPUNIT_TEST( TestLoadDatabase );
CPPUNIT_TEST( TestLoadDatabaseString );
CPPUNIT_TEST( TestLoadDatabaseMissingFile );
CPPUNIT_TEST( TestLoadDatabaseWithErrors );
CPPUNIT_TEST( TestRunAccumulated );
CPPUNIT_TEST( TestRunWithErrors );
CPPUNIT_TEST( TestRunFile );
CPPUNIT_TEST( TestGetSelectedOutputRowCount );
CPPUNIT_TEST( TestGetSelectedOutputValue );
CPPUNIT_TEST( TestGetSelectedOutputColumnCount );
CPPUNIT_TEST( TestAddError );
CPPUNIT_TEST( TestAccumulateLine );
CPPUNIT_TEST( TestAddError );
CPPUNIT_TEST( TestOutputLastError );
CPPUNIT_TEST( TestRunWithCallback );
CPPUNIT_TEST( TestRunNoDatabaseLoaded );
CPPUNIT_TEST( TestCase1 );
CPPUNIT_TEST( TestCase2 );
CPPUNIT_TEST( TestPrintSelectedOutputFalse );
CPPUNIT_TEST( TestOutputOnOff );
CPPUNIT_TEST( TestErrorOnOff );
CPPUNIT_TEST( TestLogOnOff );
CPPUNIT_TEST( TestDumpOn );
CPPUNIT_TEST( TestSelOutOnOff );
CPPUNIT_TEST( TestLongHeadings );
CPPUNIT_TEST( TestDatabaseKeyword );
CPPUNIT_TEST( TestDumpString );
CPPUNIT_TEST( TestGetDumpLineCount );
CPPUNIT_TEST( TestGetDumpLine );
CPPUNIT_TEST( TestGetComponentCount );
CPPUNIT_TEST( TestGetComponent );
CPPUNIT_TEST_SUITE_END();
public:
TestIPhreeqcLib(void);
~TestIPhreeqcLib(void);
public:
void TestCreateIPhreeqc(void);
void TestDestroyIPhreeqc(void);
void TestLoadDatabase(void);
void TestLoadDatabaseString(void);
void TestLoadDatabaseMissingFile(void);
void TestLoadDatabaseWithErrors(void);
void TestRunAccumulated(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 TestCase1(void);
void TestCase2(void);
void TestPrintSelectedOutputFalse(void);
void TestOutputOnOff(void);
void TestErrorOnOff(void);
void TestLogOnOff(void);
void TestDumpOn(void);
void TestSelOutOnOff(void);
void TestLongHeadings(void);
void TestDatabaseKeyword();
void TestDumpString();
void TestGetDumpLineCount(void);
void TestGetDumpLine(void);
void TestGetComponentCount(void);
void TestGetComponent(void);
protected:
void TestOnOff(const char* FILENAME, int output_on, int error_on, int log_on, int selected_output_on, int dump_on);
};
#endif // TEST_IPHREEQC_LIB_H_INCLUDED

View File

@ -1,18 +1,5 @@
#include "TestInterface.h"
#if defined(_WIN32) || defined(__CYGWIN32__)
#include <windows.h>
#else
#include <stdio.h>
int DeleteFile(const char* szPathName)
{
if (remove(szPathName) == 0) {
return 1;
}
return 0; // failure
}
#endif
#include "IPhreeqc.hpp"
#undef true
#undef false
@ -45,6 +32,9 @@ TestInterface::~TestInterface()
void TestInterface::TestLoadDatabase()
{
CPPUNIT_ASSERT_EQUAL(0, ::LoadDatabase("phreeqc.dat"));
#if defined(_WIN32)
CPPUNIT_ASSERT_EQUAL(0, ::_fcloseall());
#endif
}
void TestInterface::TestLoadDatabaseString()
@ -138,40 +128,41 @@ void TestInterface::TestLoadDatabaseWithErrors()
{
for (int i = 0; i < 5; ++i)
{
CPPUNIT_ASSERT_EQUAL(6, ::LoadDatabase("missing_e.dat"));
CPPUNIT_ASSERT_EQUAL(true, ::FileExists("missing_e.dat"));
const char *expected =
"ERROR: Could not reduce equation to primary master species, CH4.\n"
"ERROR: Could not reduce equation to primary master species, Cu+.\n"
"ERROR: Could not reduce equation to primary master species, Fe+3.\n"
"ERROR: Could not reduce equation to primary master species, H2.\n"
"ERROR: Could not reduce equation to primary master species, Mn+3.\n"
"ERROR: Could not reduce equation to primary master species, NH4+.\n"
"ERROR: Could not reduce equation to primary master species, N2.\n"
"ERROR: Could not reduce equation to primary master species, NO2-.\n"
"ERROR: Could not reduce equation to primary master species, O2.\n"
"ERROR: Could not reduce equation to primary master species, HS-.\n"
"ERROR: Could not reduce equation to secondary master species, e-.\n"
"ERROR: Non-master species in secondary reaction, e-.\n"
"ERROR: No master species for element e.\n"
"ERROR: Could not find primary master species for e.\n"
"ERROR: No master species for element e.\n"
"ERROR: Could not reduce equation to secondary master species, Hausmannite.\n"
"ERROR: Could not reduce equation to secondary master species, Manganite.\n"
"ERROR: Could not reduce equation to secondary master species, Pyrite.\n"
"ERROR: Could not reduce equation to secondary master species, Pyrolusite.\n"
"ERROR: Could not reduce equation to secondary master species, Sulfur.\n"
"ERROR: e-, primary master species for E-, not defined.\n"
"ERROR: Calculations terminating due to input errors.\n"
"Stopping.\n";
CPPUNIT_ASSERT_EQUAL(6, ::LoadDatabase("missing_e.dat"));
const char* err = ::GetLastErrorString();
static const char *expected =
"ERROR: Could not reduce equation to primary master species, CH4.\n"
"ERROR: Could not reduce equation to primary master species, Cu+.\n"
"ERROR: Could not reduce equation to primary master species, Fe+3.\n"
"ERROR: Could not reduce equation to primary master species, H2.\n"
"ERROR: Could not reduce equation to primary master species, Mn+3.\n"
"ERROR: Could not reduce equation to primary master species, NH4+.\n"
"ERROR: Could not reduce equation to primary master species, N2.\n"
"ERROR: Could not reduce equation to primary master species, NO2-.\n"
"ERROR: Could not reduce equation to primary master species, O2.\n"
"ERROR: Could not reduce equation to primary master species, HS-.\n"
"ERROR: Could not reduce equation to secondary master species, e-.\n"
"ERROR: Non-master species in secondary reaction, e-.\n"
"ERROR: No master species for element e.\n"
"ERROR: Could not find primary master species for e.\n"
"ERROR: No master species for element e.\n"
"ERROR: Could not reduce equation to secondary master species, Hausmannite.\n"
"ERROR: Could not reduce equation to secondary master species, Manganite.\n"
"ERROR: Could not reduce equation to secondary master species, Pyrite.\n"
"ERROR: Could not reduce equation to secondary master species, Pyrolusite.\n"
"ERROR: Could not reduce equation to secondary master species, Sulfur.\n"
"ERROR: e-, primary master species for E-, not defined.\n"
"ERROR: Calculations terminating due to input errors.\n"
"Stopping.\n";
CPPUNIT_ASSERT_EQUAL( std::string(expected), std::string(err) );
const char* err = ::GetLastErrorString();
CPPUNIT_ASSERT_EQUAL( std::string(expected), std::string(err) );
}
}
void TestInterface::TestRun()
{
int files_on = 0;
@ -1191,8 +1182,7 @@ void TestInterface::TestLogOnOff()
TestOnOff("phreeqc.log", onoff[0], onoff[1], onoff[2], onoff[3], onoff[4]);
}
void
TestInterface::TestDumpOn()
void TestInterface::TestDumpOn()
{
int onoff[5];
onoff[0] = 0; // output_on
@ -1294,42 +1284,6 @@ DUMP(void)
return ::AccumulateLine(oss.str().c_str());
}
#if defined(_WIN32) || defined(__CYGWIN32__)
bool FileExists(const char *szPathName)
{
SECURITY_ATTRIBUTES sa;
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = NULL;
sa.bInheritHandle = TRUE;
HANDLE fileHandle = ::CreateFile(szPathName, GENERIC_READ, 0, &sa, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
bool retValue;
if (fileHandle == INVALID_HANDLE_VALUE)
{
retValue = false;
}
else
{
retValue = true;
::CloseHandle(fileHandle);
}
return retValue;
}
#else
bool FileExists(const char *szPathName)
{
FILE* fp;
fp = fopen(szPathName, "r");
if (fp == NULL) {
return false;
} else {
fclose(fp);
return true;
}
}
#endif
void TestOnOff(const char* FILENAME, int output_on, int error_on, int log_on, int selected_output_on, int dump_on)
{
//const char *FILENAME = "phreeqc.out";

View File

@ -1,3 +1,10 @@
#if defined(_WIN32) || defined(__CYGWIN32__)
#include <windows.h>
#else
#include <stdio.h>
#endif
#include <cassert>
#include <cppunit/ui/text/TestRunner.h>
#include <cppunit/CompilerOutputter.h>
@ -5,6 +12,8 @@
#include "TestCVar.h"
#include "TestSelectedOutput.h"
#include "TestInterface.h"
#include "TestIPhreeqc.h"
#include "TestIPhreeqcLib.h"
int main(int argc, char **argv)
{
@ -14,9 +23,66 @@ int main(int argc, char **argv)
runner.addTest(TestCVar::suite());
runner.addTest(TestSelectedOutput::suite());
runner.addTest(TestInterface::suite());
runner.addTest(TestIPhreeqc::suite());
runner.addTest(TestIPhreeqcLib::suite());
runner.setOutputter(CppUnit::CompilerOutputter::defaultOutputter(&runner.result(), std::cout));
#if defined(_WIN32)
int n = ::_fcloseall();
assert(n == 0);
#endif
bool wasSucessful = runner.run("", false);
return wasSucessful;
}
#if defined(_WIN32) || defined(__CYGWIN32__)
bool FileExists(const char *szPathName)
{
SECURITY_ATTRIBUTES sa;
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = NULL;
sa.bInheritHandle = TRUE;
HANDLE fileHandle = ::CreateFile(szPathName, GENERIC_READ, 0, &sa, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
bool retValue;
if (fileHandle == INVALID_HANDLE_VALUE)
{
char buffer[100];
sprintf(buffer, "Could not open file (error %d)\n", GetLastError());
retValue = false;
}
else
{
retValue = true;
::CloseHandle(fileHandle);
}
return retValue;
}
#else
bool FileExists(const char *szPathName)
{
FILE* fp;
fp = fopen(szPathName, "r");
if (fp == NULL) {
return false;
} else {
fclose(fp);
return true;
}
}
#endif
#if defined(_WIN32) || defined(__CYGWIN32__)
// DeleteFile defined in <windows.h>
#else
int DeleteFile(const char* szPathName)
{
if (remove(szPathName) == 0)
{
return 1;
}
return 0; // failure
}
#endif

View File

@ -354,6 +354,14 @@
/>
</FileConfiguration>
</File>
<File
RelativePath=".\TestIPhreeqc.cpp"
>
</File>
<File
RelativePath=".\TestIPhreeqcLib.cpp"
>
</File>
<File
RelativePath="TestSelectedOutput.cpp"
>
@ -493,6 +501,14 @@
RelativePath="..\src\IPhreeqc.cpp"
>
</File>
<File
RelativePath="..\src\IPhreeqc2.cpp"
>
</File>
<File
RelativePath="..\src\IPhreeqcLib.cpp"
>
</File>
<File
RelativePath="..\src\module_files.cpp"
>
@ -1464,7 +1480,6 @@
>
<FileConfiguration
Name="Debug|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
@ -1475,7 +1490,6 @@
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
@ -1486,7 +1500,6 @@
</FileConfiguration>
<FileConfiguration
Name="MemDebug|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
@ -1603,7 +1616,6 @@
>
<FileConfiguration
Name="Debug|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
@ -1614,7 +1626,6 @@
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
@ -1625,7 +1636,6 @@
</FileConfiguration>
<FileConfiguration
Name="MemDebug|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
@ -2217,6 +2227,14 @@
RelativePath="TestInterface.h"
>
</File>
<File
RelativePath=".\TestIPhreeqc.h"
>
</File>
<File
RelativePath=".\TestIPhreeqcLib.h"
>
</File>
<File
RelativePath="TestSelectedOutput.h"
>

View File

@ -0,0 +1,93 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioUserFile
ProjectType="Visual C++"
Version="8.00"
ShowAllFiles="false"
>
<Configurations>
<Configuration
Name="Debug|Win32"
>
<DebugSettings
Command="$(TargetPath)"
WorkingDirectory=""
CommandArguments=""
Attach="false"
DebuggerType="3"
Remote="1"
RemoteMachine="IGSKAHHWWSNY5H1"
RemoteCommand=""
HttpUrl=""
PDBPath=""
SQLDebugging=""
Environment=""
EnvironmentMerge="true"
DebuggerFlavor=""
MPIRunCommand=""
MPIRunArguments=""
MPIRunWorkingDirectory=""
ApplicationCommand=""
ApplicationArguments=""
ShimCommand=""
MPIAcceptMode=""
MPIAcceptFilter=""
/>
</Configuration>
<Configuration
Name="Release|Win32"
>
<DebugSettings
Command="$(TargetPath)"
WorkingDirectory=""
CommandArguments=""
Attach="false"
DebuggerType="3"
Remote="1"
RemoteMachine="IGSKAHHWWSNY5H1"
RemoteCommand=""
HttpUrl=""
PDBPath=""
SQLDebugging=""
Environment=""
EnvironmentMerge="true"
DebuggerFlavor=""
MPIRunCommand=""
MPIRunArguments=""
MPIRunWorkingDirectory=""
ApplicationCommand=""
ApplicationArguments=""
ShimCommand=""
MPIAcceptMode=""
MPIAcceptFilter=""
/>
</Configuration>
<Configuration
Name="MemDebug|Win32"
>
<DebugSettings
Command="$(TargetPath)"
WorkingDirectory=""
CommandArguments=""
Attach="false"
DebuggerType="3"
Remote="1"
RemoteMachine="IGSKAHHWWSNY5H1"
RemoteCommand=""
HttpUrl=""
PDBPath=""
SQLDebugging=""
Environment=""
EnvironmentMerge="true"
DebuggerFlavor=""
MPIRunCommand=""
MPIRunArguments=""
MPIRunWorkingDirectory=""
ApplicationCommand=""
ApplicationArguments=""
ShimCommand=""
MPIAcceptMode=""
MPIAcceptFilter=""
/>
</Configuration>
</Configurations>
</VisualStudioUserFile>