working on multi_punch tests

git-svn-id: svn://136.177.114.72/svn_GW/IPhreeqc/branches/multi_punch@7945 1feff8c3-07ed-0310-ac33-dd36852eb9cd
This commit is contained in:
Scott R Charlton 2013-08-17 06:01:58 +00:00
parent 5b051717fd
commit 1e8bc19acb
8 changed files with 664 additions and 96 deletions

148
unit/FileTest.cpp Normal file
View File

@ -0,0 +1,148 @@
#include "FileTest.h"
#if defined(_WIN32) || defined(__CYGWIN32__)
#include <windows.h>
#else
#include <stdio.h>
#endif
#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
#if defined(_WIN32) || defined(__CYGWIN32__)
size_t FileSize(const char *szPathName)
{
HANDLE hFile = ::CreateFile(
szPathName, // file to open
GENERIC_READ, // open for reading
FILE_SHARE_READ, // share for reading
NULL, // default security
OPEN_EXISTING, // existing file only
FILE_ATTRIBUTE_NORMAL, // normal file
NULL); // no attr. template
if (hFile != INVALID_HANDLE_VALUE)
{
// read file size
LARGE_INTEGER liFileSize;
::GetFileSizeEx(hFile, &liFileSize);
::CloseHandle(hFile);
return (size_t) liFileSize.QuadPart;
}
return 0;
}
#else
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
size_t FileSize(const char *szPathName)
{
struct stat s;
stat(szPathName, &s);
return (size_t) s.st_size;
}
#endif
FileTest::FileTest(std::string fn) : _fn(fn)
{
}
FileTest::~FileTest(void)
{
int max_tries = 100;
while(::FileExists(_fn.c_str()) && --max_tries)
{
::DeleteFile(_fn.c_str());
}
}
std::string FileTest::GetName(void)
{
return _fn;
}
bool FileTest::RemoveExisting(void)
{
int max_tries = 100;
while(::FileExists(_fn.c_str()) && --max_tries)
{
::DeleteFile(_fn.c_str());
}
return !::FileExists(_fn.c_str());
}
bool FileTest::VerifyMissing(void)
{
int max_tries = 100;
while(::FileExists(_fn.c_str()) && --max_tries);
return !::FileExists(_fn.c_str());
}
bool FileTest::VerifyExists(void)
{
int max_tries = 100;
while(!::FileExists(_fn.c_str()) && --max_tries);
return ::FileExists(_fn.c_str());
}
bool FileTest::Exists(void)
{
return ::FileExists(_fn.c_str());
}
int FileTest::Delete(void)
{
if (::FileExists(_fn.c_str()))
{
return ::DeleteFile(_fn.c_str());
}
return TRUE;
}

32
unit/FileTest.h Normal file
View File

@ -0,0 +1,32 @@
#if !defined(FILETEST_H_INCLUDED)
#define FILETEST_H_INCLUDED
#include <string>
#if defined(_WIN32) || defined(__CYGWIN32__)
// DeleteFile defined in <windows.h>
#else
int DeleteFile(const char* szPathName);
#endif
bool FileExists(const char *szPathName);
size_t FileSize(const char *szPathName);
class FileTest
{
public:
FileTest(std::string fn);
~FileTest(void);
std::string GetName(void);
bool RemoveExisting(void);
bool VerifyMissing(void);
bool VerifyExists(void);
bool Exists(void);
int Delete(void);
protected:
std::string _fn;
};
#endif // FILETEST_H_INCLUDED

View File

@ -5,18 +5,19 @@
#include <cassert>
#include "IPhreeqc.hpp"
#include "Phreeqc.h"
#include "FileTest.h"
#undef true
#undef false
#include "CVar.hxx"
#if defined(_WIN32) || defined(__CYGWIN32__)
// DeleteFile defined in <windows.h>
#else
int DeleteFile(const char* szPathName);
#endif
bool FileExists(const char *szPathName);
size_t FileSize(const char *szPathName);
// COMMENT: {8/16/2013 11:49:20 PM}#if defined(_WIN32) || defined(__CYGWIN32__)
// COMMENT: {8/16/2013 11:49:20 PM}// DeleteFile defined in <windows.h>
// COMMENT: {8/16/2013 11:49:20 PM}#else
// COMMENT: {8/16/2013 11:49:20 PM}int DeleteFile(const char* szPathName);
// COMMENT: {8/16/2013 11:49:20 PM}#endif
// COMMENT: {8/16/2013 11:49:20 PM}
// COMMENT: {8/16/2013 11:49:20 PM}bool FileExists(const char *szPathName);
// COMMENT: {8/16/2013 11:49:20 PM}size_t FileSize(const char *szPathName);
VRESULT SOLUTION(IPhreeqc& obj, double C, double Ca, double Na);
VRESULT EQUILIBRIUM_PHASES(IPhreeqc& obj, const char* phase, double si, double amount);
@ -3470,3 +3471,169 @@ void TestIPhreeqc::TestDelete(void)
CPPUNIT_ASSERT(::DeleteFile(OUTPUT_FILE));
}
}
void TestIPhreeqc::TestRunFileMultiPunchOn(void)
{
if (::FileExists("multi_punch_1.sel"))
{
CPPUNIT_ASSERT(::DeleteFile("multi_punch_1.sel"));
}
if (::FileExists("multi_punch_2.sel"))
{
CPPUNIT_ASSERT(::DeleteFile("multi_punch_2.sel"));
}
if (::FileExists("multi_punch_3.sel"))
{
CPPUNIT_ASSERT(::DeleteFile("multi_punch_3.sel"));
}
CPPUNIT_ASSERT_EQUAL( false, ::FileExists("multi_punch_1.sel") );
CPPUNIT_ASSERT_EQUAL( false, ::FileExists("multi_punch_2.sel") );
CPPUNIT_ASSERT_EQUAL( false, ::FileExists("multi_punch_3.sel") );
IPhreeqc obj;
CPPUNIT_ASSERT_EQUAL(0, obj.LoadDatabase("phreeqc.dat"));
obj.SetSelectedOutputFileOn(true);
CPPUNIT_ASSERT_EQUAL(0, obj.RunFile("multi_punch"));
CPPUNIT_ASSERT_EQUAL( true, ::FileExists("multi_punch_1.sel") );
CPPUNIT_ASSERT_EQUAL( true, ::FileExists("multi_punch_2.sel") );
CPPUNIT_ASSERT_EQUAL( true, ::FileExists("multi_punch_3.sel") );
// CLEANUP
if (::FileExists("multi_punch_1.sel"))
{
CPPUNIT_ASSERT(::DeleteFile("multi_punch_1.sel"));
}
if (::FileExists("multi_punch_2.sel"))
{
CPPUNIT_ASSERT(::DeleteFile("multi_punch_2.sel"));
}
if (::FileExists("multi_punch_3.sel"))
{
CPPUNIT_ASSERT(::DeleteFile("multi_punch_3.sel"));
}
}
void TestIPhreeqc::TestRunFileMultiPunchOff(void)
{
const char dump_file[] = "error.inp";
if (::FileExists("multi_punch_1.sel"))
{
CPPUNIT_ASSERT(::DeleteFile("multi_punch_1.sel"));
}
if (::FileExists("multi_punch_2.sel"))
{
CPPUNIT_ASSERT(::DeleteFile("multi_punch_2.sel"));
}
if (::FileExists("multi_punch_3.sel"))
{
CPPUNIT_ASSERT(::DeleteFile("multi_punch_3.sel"));
}
CPPUNIT_ASSERT_EQUAL( false, ::FileExists("multi_punch_1.sel") );
CPPUNIT_ASSERT_EQUAL( false, ::FileExists("multi_punch_2.sel") );
CPPUNIT_ASSERT_EQUAL( false, ::FileExists("multi_punch_3.sel") );
IPhreeqc obj;
CPPUNIT_ASSERT_EQUAL(0, obj.LoadDatabase("phreeqc.dat"));
obj.SetOutputFileOn(false);
obj.SetErrorFileOn(false);
obj.SetLogFileOn(false);
obj.SetSelectedOutputFileOn(false);
obj.SetDumpFileOn(false);
CPPUNIT_ASSERT_EQUAL(0, obj.RunFile("multi_punch"));
CPPUNIT_ASSERT_EQUAL( false, ::FileExists("multi_punch_1.sel") );
CPPUNIT_ASSERT_EQUAL( false, ::FileExists("multi_punch_2.sel") );
CPPUNIT_ASSERT_EQUAL( false, ::FileExists("multi_punch_3.sel") );
// CLEANUP
if (::FileExists("multi_punch_1.sel"))
{
CPPUNIT_ASSERT(::DeleteFile("multi_punch_1.sel"));
}
if (::FileExists("multi_punch_2.sel"))
{
CPPUNIT_ASSERT(::DeleteFile("multi_punch_2.sel"));
}
if (::FileExists("multi_punch_3.sel"))
{
CPPUNIT_ASSERT(::DeleteFile("multi_punch_3.sel"));
}
}
void TestIPhreeqc::TestRunFileMultiPunchSet(void)
{
if (::FileExists("multi_punch_1.sel"))
{
CPPUNIT_ASSERT(::DeleteFile("multi_punch_1.sel"));
}
if (::FileExists("multi_punch_2.sel"))
{
CPPUNIT_ASSERT(::DeleteFile("multi_punch_2.sel"));
}
if (::FileExists("multi_punch_3.sel"))
{
CPPUNIT_ASSERT(::DeleteFile("multi_punch_3.sel"));
}
CPPUNIT_ASSERT_EQUAL( false, ::FileExists("multi_punch_1.sel") );
CPPUNIT_ASSERT_EQUAL( false, ::FileExists("multi_punch_2.sel") );
CPPUNIT_ASSERT_EQUAL( false, ::FileExists("multi_punch_3.sel") );
IPhreeqc obj;
CPPUNIT_ASSERT_EQUAL(0, obj.LoadDatabase("phreeqc.dat"));
obj.SetSelectedOutputFileOn(true);
obj.SetSelectedOutputFileName("XXX");
CPPUNIT_ASSERT_EQUAL(0, obj.RunFile("multi_punch"));
CPPUNIT_ASSERT_EQUAL( false, ::FileExists("XXX") );
CPPUNIT_ASSERT_EQUAL( true, ::FileExists("multi_punch_1.sel") );
CPPUNIT_ASSERT_EQUAL( true, ::FileExists("multi_punch_2.sel") );
CPPUNIT_ASSERT_EQUAL( true, ::FileExists("multi_punch_3.sel") );
// CLEANUP
if (::FileExists("multi_punch_1.sel"))
{
CPPUNIT_ASSERT(::DeleteFile("multi_punch_1.sel"));
}
if (::FileExists("multi_punch_2.sel"))
{
CPPUNIT_ASSERT(::DeleteFile("multi_punch_2.sel"));
}
if (::FileExists("multi_punch_3.sel"))
{
CPPUNIT_ASSERT(::DeleteFile("multi_punch_3.sel"));
}
}
void TestIPhreeqc::TestRunFileMultiPunchNoSet(void)
{
IPhreeqc obj;
FileTest set("XXX.sel");
CPPUNIT_ASSERT( set.RemoveExisting() );
FileTest unset1(obj.sel_file_name(1));
CPPUNIT_ASSERT( unset1.RemoveExisting() );
FileTest unset2(obj.sel_file_name(2));
CPPUNIT_ASSERT( unset2.RemoveExisting() );
FileTest unset3(obj.sel_file_name(3));
CPPUNIT_ASSERT( unset3.RemoveExisting() );
CPPUNIT_ASSERT_EQUAL(0, obj.LoadDatabase("phreeqc.dat"));
obj.SetSelectedOutputFileOn(true);
obj.SetSelectedOutputFileName(set.GetName().c_str());
CPPUNIT_ASSERT_EQUAL(0, obj.RunFile("multi_punch_no_set"));
CPPUNIT_ASSERT( set.VerifyExists() );
CPPUNIT_ASSERT( !unset1.VerifyExists() );
CPPUNIT_ASSERT( unset2.VerifyExists() );
CPPUNIT_ASSERT( unset3.VerifyExists() );
}

View File

@ -64,7 +64,10 @@ class TestIPhreeqc : public CppUnit::TestFixture
CPPUNIT_TEST( TestBasicSURF );
CPPUNIT_TEST( TestCErrorReporter );
CPPUNIT_TEST( TestDelete );
CPPUNIT_TEST( TestRunFileMultiPunchOn );
CPPUNIT_TEST( TestRunFileMultiPunchOff );
CPPUNIT_TEST( TestRunFileMultiPunchSet );
CPPUNIT_TEST( TestRunFileMultiPunchNoSet );
CPPUNIT_TEST_SUITE_END();
public:
@ -129,7 +132,10 @@ public:
void TestBasicSURF(void);
void TestCErrorReporter(void);
void TestDelete(void);
void TestRunFileMultiPunchOn(void);
void TestRunFileMultiPunchOff(void);
void TestRunFileMultiPunchSet(void);
void TestRunFileMultiPunchNoSet(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);

105
unit/multi_punch Normal file
View File

@ -0,0 +1,105 @@
SOLUTION 1
pH 7 charge
Na 1
Cl 1
Ca 1
C 2
END
CALCULATE_VALUES
TOTAL_C
-start
10 save TOT("C")
-end
END
EQUILIBRIUM_PHASES 1
CO2(g) -2
Dolomite 0
END
REACTION 1
HCl 1
0.1 mmol
END
GAS_PHASE
-fixed_volume
N2(g) 1.2
END
KINETICS
Calcite
-tol 1e-8
-m0 3.e-3
-m 3.e-3
-parms 50 0.6
END
SOLID_SOLUTION
Sulfate
-comp Anhydrite 1.0
-comp Barite 1.0
END
RUN_CELLS
-cell 1
SELECTED_OUTPUT
-file multi_punch_1.sel
-reset false
-sim
-state
-solution
-dist
-time
-step
-pH
-pe
-reaction
-temperature
-alkalinity
-ionic_strength
-water
-charge_balance
-percent_error
-totals Na Ca
-molalities Na+ HCO3-
-activities Ca+2 CO3-2
-equilibrium_phases CO2(g) dolomite
-saturation_indices Halite
-gases N2(g)
-kinetics Calcite
-solid_solutions Anhydrite Barite
-calculate_values TOTAL_C
-inverse false
SELECTED_OUTPUT 2
-file multi_punch_2.sel
-si Halite Calcite
USER_PUNCH 20
-heading Dummy
10 PUNCH "Dummy"
END
USER_PUNCH 2
-heading DUMMY_1 DUMMY_2
10 PUNCH "Dummy1", "Dummy2"
RUN_CELLS
-cell 1
SELECTED_OUTPUT 1
-active false
END
RUN_CELLS
-cell 1
SELECTED_OUTPUT 1
-active true
END
SOLUTION 2
pH 7 charge
END
SOLUTION 3
pH 7 charge
Na 1
Cl 1
END
INVERSE_MODELING
-solution 2 3
-phases
Halite
SELECTED_OUTPUT 3
-reset false
-file multi_punch_3.sel
END
RUN_CELLS
-cell 1

102
unit/multi_punch_no_set Normal file
View File

@ -0,0 +1,102 @@
SOLUTION 1
pH 7 charge
Na 1
Cl 1
Ca 1
C 2
END
CALCULATE_VALUES
TOTAL_C
-start
10 save TOT("C")
-end
END
EQUILIBRIUM_PHASES 1
CO2(g) -2
Dolomite 0
END
REACTION 1
HCl 1
0.1 mmol
END
GAS_PHASE
-fixed_volume
N2(g) 1.2
END
KINETICS
Calcite
-tol 1e-8
-m0 3.e-3
-m 3.e-3
-parms 50 0.6
END
SOLID_SOLUTION
Sulfate
-comp Anhydrite 1.0
-comp Barite 1.0
END
RUN_CELLS
-cell 1
SELECTED_OUTPUT
-reset false
-sim
-state
-solution
-dist
-time
-step
-pH
-pe
-reaction
-temperature
-alkalinity
-ionic_strength
-water
-charge_balance
-percent_error
-totals Na Ca
-molalities Na+ HCO3-
-activities Ca+2 CO3-2
-equilibrium_phases CO2(g) dolomite
-saturation_indices Halite
-gases N2(g)
-kinetics Calcite
-solid_solutions Anhydrite Barite
-calculate_values TOTAL_C
-inverse false
SELECTED_OUTPUT 2
-si Halite Calcite
USER_PUNCH 20
-heading Dummy
10 PUNCH "Dummy"
END
USER_PUNCH 2
-heading DUMMY_1 DUMMY_2
10 PUNCH "Dummy1", "Dummy2"
RUN_CELLS
-cell 1
SELECTED_OUTPUT 1
-active false
END
RUN_CELLS
-cell 1
SELECTED_OUTPUT 1
-active true
END
SOLUTION 2
pH 7 charge
END
SOLUTION 3
pH 7 charge
Na 1
Cl 1
END
INVERSE_MODELING
-solution 2 3
-phases
Halite
SELECTED_OUTPUT 3
-reset false
END
RUN_CELLS
-cell 1

View File

@ -75,11 +75,11 @@ int main(int argc, char **argv)
s.startTimer();
#endif
runner.addTest(TestVar::suite());
runner.addTest(TestCVar::suite());
runner.addTest(TestSelectedOutput::suite());
// COMMENT: {8/16/2013 12:14:16 AM} runner.addTest(TestVar::suite());
// COMMENT: {8/16/2013 12:14:16 AM} runner.addTest(TestCVar::suite());
// COMMENT: {8/16/2013 12:14:16 AM} runner.addTest(TestSelectedOutput::suite());
runner.addTest(TestIPhreeqc::suite());
runner.addTest(TestIPhreeqcLib::suite());
// COMMENT: {8/16/2013 12:14:19 AM} runner.addTest(TestIPhreeqcLib::suite());
runner.setOutputter(CppUnit::CompilerOutputter::defaultOutputter(&runner.result(), std::cout));
@ -98,87 +98,87 @@ int main(int argc, char **argv)
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);
// COMMENT: {8/16/2013 11:40:58 PM}#if defined(_WIN32) || defined(__CYGWIN32__)
// COMMENT: {8/16/2013 11:40:58 PM}bool FileExists(const char *szPathName)
// COMMENT: {8/16/2013 11:40:58 PM}{
// COMMENT: {8/16/2013 11:40:58 PM} SECURITY_ATTRIBUTES sa;
// COMMENT: {8/16/2013 11:40:58 PM} sa.nLength = sizeof(SECURITY_ATTRIBUTES);
// COMMENT: {8/16/2013 11:40:58 PM} sa.lpSecurityDescriptor = NULL;
// COMMENT: {8/16/2013 11:40:58 PM} sa.bInheritHandle = TRUE;
// COMMENT: {8/16/2013 11:40:58 PM} HANDLE fileHandle = ::CreateFile(szPathName, GENERIC_READ, 0, &sa, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
// COMMENT: {8/16/2013 11:40:58 PM}
// COMMENT: {8/16/2013 11:40:58 PM} bool retValue;
// COMMENT: {8/16/2013 11:40:58 PM} if (fileHandle == INVALID_HANDLE_VALUE)
// COMMENT: {8/16/2013 11:40:58 PM} {
// COMMENT: {8/16/2013 11:40:58 PM} char buffer[100];
// COMMENT: {8/16/2013 11:40:58 PM} sprintf(buffer, "Could not open file (error %d)\n", GetLastError());
// COMMENT: {8/16/2013 11:40:58 PM} retValue = false;
// COMMENT: {8/16/2013 11:40:58 PM} }
// COMMENT: {8/16/2013 11:40:58 PM} else
// COMMENT: {8/16/2013 11:40:58 PM} {
// COMMENT: {8/16/2013 11:40:58 PM} retValue = true;
// COMMENT: {8/16/2013 11:40:58 PM} ::CloseHandle(fileHandle);
// COMMENT: {8/16/2013 11:40:58 PM} }
// COMMENT: {8/16/2013 11:40:58 PM} return retValue;
// COMMENT: {8/16/2013 11:40:58 PM}}
// COMMENT: {8/16/2013 11:40:58 PM}#else
// COMMENT: {8/16/2013 11:40:58 PM}bool FileExists(const char *szPathName)
// COMMENT: {8/16/2013 11:40:58 PM}{
// COMMENT: {8/16/2013 11:40:58 PM} FILE* fp;
// COMMENT: {8/16/2013 11:40:58 PM} fp = fopen(szPathName, "r");
// COMMENT: {8/16/2013 11:40:58 PM} if (fp == NULL) {
// COMMENT: {8/16/2013 11:40:58 PM} return false;
// COMMENT: {8/16/2013 11:40:58 PM} } else {
// COMMENT: {8/16/2013 11:40:58 PM} fclose(fp);
// COMMENT: {8/16/2013 11:40:58 PM} return true;
// COMMENT: {8/16/2013 11:40:58 PM} }
// COMMENT: {8/16/2013 11:40:58 PM}}
// COMMENT: {8/16/2013 11:40:58 PM}#endif
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
// COMMENT: {8/16/2013 11:40:25 PM}#if defined(_WIN32) || defined(__CYGWIN32__)
// COMMENT: {8/16/2013 11:40:25 PM}// DeleteFile defined in <windows.h>
// COMMENT: {8/16/2013 11:40:25 PM}#else
// COMMENT: {8/16/2013 11:40:25 PM}int DeleteFile(const char* szPathName)
// COMMENT: {8/16/2013 11:40:25 PM}{
// COMMENT: {8/16/2013 11:40:25 PM} if (remove(szPathName) == 0)
// COMMENT: {8/16/2013 11:40:25 PM} {
// COMMENT: {8/16/2013 11:40:25 PM} return 1;
// COMMENT: {8/16/2013 11:40:25 PM} }
// COMMENT: {8/16/2013 11:40:25 PM} return 0; // failure
// COMMENT: {8/16/2013 11:40:25 PM}}
// COMMENT: {8/16/2013 11:40:25 PM}#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
#if defined(_WIN32) || defined(__CYGWIN32__)
size_t FileSize(const char *szPathName)
{
HANDLE hFile = ::CreateFile(
szPathName, // file to open
GENERIC_READ, // open for reading
FILE_SHARE_READ, // share for reading
NULL, // default security
OPEN_EXISTING, // existing file only
FILE_ATTRIBUTE_NORMAL, // normal file
NULL); // no attr. template
if (hFile != INVALID_HANDLE_VALUE)
{
// read file size
LARGE_INTEGER liFileSize;
::GetFileSizeEx(hFile, &liFileSize);
::CloseHandle(hFile);
return (size_t) liFileSize.QuadPart;
}
return 0;
}
#else
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
size_t FileSize(const char *szPathName)
{
struct stat s;
stat(szPathName, &s);
return (size_t) s.st_size;
}
#endif
// COMMENT: {8/16/2013 11:42:03 PM}#if defined(_WIN32) || defined(__CYGWIN32__)
// COMMENT: {8/16/2013 11:42:03 PM}size_t FileSize(const char *szPathName)
// COMMENT: {8/16/2013 11:42:03 PM}{
// COMMENT: {8/16/2013 11:42:03 PM} HANDLE hFile = ::CreateFile(
// COMMENT: {8/16/2013 11:42:03 PM} szPathName, // file to open
// COMMENT: {8/16/2013 11:42:03 PM} GENERIC_READ, // open for reading
// COMMENT: {8/16/2013 11:42:03 PM} FILE_SHARE_READ, // share for reading
// COMMENT: {8/16/2013 11:42:03 PM} NULL, // default security
// COMMENT: {8/16/2013 11:42:03 PM} OPEN_EXISTING, // existing file only
// COMMENT: {8/16/2013 11:42:03 PM} FILE_ATTRIBUTE_NORMAL, // normal file
// COMMENT: {8/16/2013 11:42:03 PM} NULL); // no attr. template
// COMMENT: {8/16/2013 11:42:03 PM}
// COMMENT: {8/16/2013 11:42:03 PM} if (hFile != INVALID_HANDLE_VALUE)
// COMMENT: {8/16/2013 11:42:03 PM} {
// COMMENT: {8/16/2013 11:42:03 PM} // read file size
// COMMENT: {8/16/2013 11:42:03 PM} LARGE_INTEGER liFileSize;
// COMMENT: {8/16/2013 11:42:03 PM} ::GetFileSizeEx(hFile, &liFileSize);
// COMMENT: {8/16/2013 11:42:03 PM} ::CloseHandle(hFile);
// COMMENT: {8/16/2013 11:42:03 PM} return (size_t) liFileSize.QuadPart;
// COMMENT: {8/16/2013 11:42:03 PM} }
// COMMENT: {8/16/2013 11:42:03 PM} return 0;
// COMMENT: {8/16/2013 11:42:03 PM}}
// COMMENT: {8/16/2013 11:42:03 PM}#else
// COMMENT: {8/16/2013 11:42:03 PM}#include <sys/types.h>
// COMMENT: {8/16/2013 11:42:03 PM}#include <sys/stat.h>
// COMMENT: {8/16/2013 11:42:03 PM}#include <unistd.h>
// COMMENT: {8/16/2013 11:42:03 PM}
// COMMENT: {8/16/2013 11:42:03 PM}size_t FileSize(const char *szPathName)
// COMMENT: {8/16/2013 11:42:03 PM}{
// COMMENT: {8/16/2013 11:42:03 PM} struct stat s;
// COMMENT: {8/16/2013 11:42:03 PM} stat(szPathName, &s);
// COMMENT: {8/16/2013 11:42:03 PM} return (size_t) s.st_size;
// COMMENT: {8/16/2013 11:42:03 PM}}
// COMMENT: {8/16/2013 11:42:03 PM}

View File

@ -344,6 +344,10 @@
Name="Source Files"
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat;f90;for;f;fpp"
>
<File
RelativePath=".\FileTest.cpp"
>
</File>
<File
RelativePath="TestCVar.cpp"
>
@ -877,6 +881,10 @@
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;fi;fd"
>
<File
RelativePath=".\FileTest.h"
>
</File>
<File
RelativePath="TestCVar.h"
>