Merge branch 'dev' of https://github.com/OpenWaterAnalytics/EPANET into dev-unittesting
This commit is contained in:
@@ -28,7 +28,7 @@ env:
|
|||||||
- TEST_HOME=nrtestsuite
|
- TEST_HOME=nrtestsuite
|
||||||
|
|
||||||
before_install:
|
before_install:
|
||||||
- sudo apt-get -qq update
|
# - sudo apt-get -qq update
|
||||||
- eval "${MATRIX_EVAL}"
|
- eval "${MATRIX_EVAL}"
|
||||||
|
|
||||||
#install:
|
#install:
|
||||||
|
|||||||
29
appveyor.yml
29
appveyor.yml
@@ -20,7 +20,6 @@ environment:
|
|||||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||||
GENERATOR: "Visual Studio 15 2017"
|
GENERATOR: "Visual Studio 15 2017"
|
||||||
GROUP: "SUPPORTED"
|
GROUP: "SUPPORTED"
|
||||||
BUILD_CONFIG: "Release"
|
|
||||||
BOOST_ROOT: "C:/Libraries/boost_1_67_0"
|
BOOST_ROOT: "C:/Libraries/boost_1_67_0"
|
||||||
PLATFORM: "win32"
|
PLATFORM: "win32"
|
||||||
REF_BUILD_ID: "220dev5"
|
REF_BUILD_ID: "220dev5"
|
||||||
@@ -28,15 +27,6 @@ environment:
|
|||||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||||
GENERATOR: "Visual Studio 15 2017 Win64"
|
GENERATOR: "Visual Studio 15 2017 Win64"
|
||||||
GROUP: "EXPERIMENTAL"
|
GROUP: "EXPERIMENTAL"
|
||||||
BUILD_CONFIG: "Release"
|
|
||||||
BOOST_ROOT: "C:/Libraries/boost_1_67_0"
|
|
||||||
PLATFORM: "win64"
|
|
||||||
REF_BUILD_ID: "381_2"
|
|
||||||
# adding debug configuration so we can monitor memory leaks
|
|
||||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
|
||||||
GENERATOR: "Visual Studio 15 2017 Win64"
|
|
||||||
GROUP: "EXPERIMENTAL"
|
|
||||||
BUILD_CONFIG: "Debug"
|
|
||||||
BOOST_ROOT: "C:/Libraries/boost_1_67_0"
|
BOOST_ROOT: "C:/Libraries/boost_1_67_0"
|
||||||
PLATFORM: "win64"
|
PLATFORM: "win64"
|
||||||
REF_BUILD_ID: "381_2"
|
REF_BUILD_ID: "381_2"
|
||||||
@@ -69,7 +59,7 @@ before_build:
|
|||||||
|
|
||||||
# run custom build script
|
# run custom build script
|
||||||
build_script:
|
build_script:
|
||||||
- cmake --build . --config %BUILD_CONFIG%
|
- cmake --build . --config Release
|
||||||
|
|
||||||
before_test:
|
before_test:
|
||||||
- cd %EPANET_HOME%
|
- cd %EPANET_HOME%
|
||||||
@@ -79,22 +69,17 @@ before_test:
|
|||||||
test_script:
|
test_script:
|
||||||
# run unit tests
|
# run unit tests
|
||||||
- cd %BUILD_HOME%\tests
|
- cd %BUILD_HOME%\tests
|
||||||
- ctest -C %BUILD_CONFIG% --output-on-failure
|
- ctest -C Release --output-on-failure
|
||||||
# run regression tests
|
# run regression tests
|
||||||
- cd %EPANET_HOME%
|
- cd %EPANET_HOME%
|
||||||
- IF "%BUILD_CONFIG%" == "Release" (
|
- tools\run-nrtest.cmd %REF_BUILD_ID% %SUT_BUILD_ID%
|
||||||
tools\run-nrtest.cmd %REF_BUILD_ID% %SUT_BUILD_ID%
|
|
||||||
)
|
|
||||||
on_success:
|
on_success:
|
||||||
- cd %TEST_HOME%\benchmark
|
- cd %TEST_HOME%\benchmark
|
||||||
- IF "%BUILD_CONFIG%" == "Release" (
|
- appveyor PushArtifact receipt.json
|
||||||
appveyor PushArtifact receipt.json
|
|
||||||
)
|
|
||||||
|
|
||||||
on_failure:
|
on_failure:
|
||||||
- cd %TEST_HOME%\benchmark
|
- cd %TEST_HOME%\benchmark
|
||||||
# zip up the SUT benchmarks
|
# zip up the SUT benchmarks
|
||||||
- IF "%BUILD_CONFIG%" == "Release" (
|
- 7z a benchmark-%PLATFORM%-%SUT_BUILD_ID%.zip .\epanet-%SUT_BUILD_ID%
|
||||||
7z a benchmark-%PLATFORM%-%SUT_BUILD_ID%.zip .\epanet-%SUT_BUILD_ID% &
|
- appveyor PushArtifact benchmark-%PLATFORM%-%SUT_BUILD_ID%.zip
|
||||||
appveyor PushArtifact benchmark-%PLATFORM%-%SUT_BUILD_ID%.zip
|
|
||||||
)
|
|
||||||
|
|||||||
@@ -343,7 +343,7 @@ extern "C" {
|
|||||||
EN_API_FLOAT_TYPE x, EN_API_FLOAT_TYPE y);
|
EN_API_FLOAT_TYPE x, EN_API_FLOAT_TYPE y);
|
||||||
|
|
||||||
int DLLEXPORT ENgetcurve(int index, char* id, int *nPoints,
|
int DLLEXPORT ENgetcurve(int index, char* id, int *nPoints,
|
||||||
EN_API_FLOAT_TYPE **xValues, EN_API_FLOAT_TYPE **yValues);
|
EN_API_FLOAT_TYPE *xValues, EN_API_FLOAT_TYPE *yValues);
|
||||||
|
|
||||||
int DLLEXPORT ENsetcurve(int index, EN_API_FLOAT_TYPE *xValues,
|
int DLLEXPORT ENsetcurve(int index, EN_API_FLOAT_TYPE *xValues,
|
||||||
EN_API_FLOAT_TYPE *yValues, int nPoints);
|
EN_API_FLOAT_TYPE *yValues, int nPoints);
|
||||||
|
|||||||
@@ -1422,7 +1422,7 @@ typedef struct Project *EN_Project;
|
|||||||
@ref EN_MAXID characters.
|
@ref EN_MAXID characters.
|
||||||
*/
|
*/
|
||||||
int DLLEXPORT EN_getcurve(EN_Project ph, int index, char* id, int *nPoints,
|
int DLLEXPORT EN_getcurve(EN_Project ph, int index, char* id, int *nPoints,
|
||||||
double **xValues, double **yValues);
|
double *xValues, double *yValues);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief assigns a set of data points to a curve.
|
@brief assigns a set of data points to a curve.
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ int EXPORT_PY_API curv_getlength(Handle ph, int index, int *len);
|
|||||||
int EXPORT_PY_API curv_gettype(Handle ph, int curveIndex, int *outType);
|
int EXPORT_PY_API curv_gettype(Handle ph, int curveIndex, int *outType);
|
||||||
int EXPORT_PY_API curv_getvalue(Handle ph, int curveIndex, int pointIndex, double *x, double *y);
|
int EXPORT_PY_API curv_getvalue(Handle ph, int curveIndex, int pointIndex, double *x, double *y);
|
||||||
int EXPORT_PY_API curv_setvalue(Handle ph, int curveIndex, int pointIndex, double x, double y);
|
int EXPORT_PY_API curv_setvalue(Handle ph, int curveIndex, int pointIndex, double x, double y);
|
||||||
int EXPORT_PY_API curv_get(Handle ph, int curveIndex, char* id, int *nValues, double **xValues, double **yValues);
|
int EXPORT_PY_API curv_get(Handle ph, int curveIndex, char* id, int *nValues, double *xValues, double *yValues);
|
||||||
int EXPORT_PY_API curv_set(Handle ph, int index, double *x, double *y, int len);
|
int EXPORT_PY_API curv_set(Handle ph, int index, double *x, double *y, int len);
|
||||||
|
|
||||||
int EXPORT_PY_API scntl_add(Handle ph, int type, int linkIndex, double setting, int nodeIndex, double level, int *index);
|
int EXPORT_PY_API scntl_add(Handle ph, int type, int linkIndex, double setting, int nodeIndex, double level, int *index);
|
||||||
|
|||||||
@@ -12,7 +12,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "epanet2.h"
|
#include "epanet2.h"
|
||||||
|
|
||||||
void writeConsole(char *s)
|
void writeConsole(char *s)
|
||||||
|
|||||||
42
src/epanet.c
42
src/epanet.c
@@ -7,21 +7,16 @@
|
|||||||
Authors: see AUTHORS
|
Authors: see AUTHORS
|
||||||
Copyright: see AUTHORS
|
Copyright: see AUTHORS
|
||||||
License: see LICENSE
|
License: see LICENSE
|
||||||
Last Updated: 03/17/2019
|
Last Updated: 04/02/2019
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef _DEBUG
|
|
||||||
#define _CRTDBG_MAP_ALLOC
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <crtdbg.h>
|
|
||||||
#else
|
|
||||||
#include <stdlib.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#ifndef __APPLE__
|
||||||
|
#include <malloc.h>
|
||||||
|
#endif
|
||||||
#include <float.h>
|
#include <float.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
@@ -221,12 +216,12 @@ int DLLEXPORT EN_open(EN_Project p, const char *inpFile, const char *rptFile,
|
|||||||
ERRCODE(netsize(p));
|
ERRCODE(netsize(p));
|
||||||
ERRCODE(allocdata(p));
|
ERRCODE(allocdata(p));
|
||||||
|
|
||||||
if (!errcode) {
|
|
||||||
// Read input data
|
// Read input data
|
||||||
ERRCODE(getdata(p));
|
ERRCODE(getdata(p));
|
||||||
|
|
||||||
// Close input file
|
// Close input file
|
||||||
if (p->parser.InFile != NULL) {
|
if (p->parser.InFile != NULL)
|
||||||
|
{
|
||||||
fclose(p->parser.InFile);
|
fclose(p->parser.InFile);
|
||||||
p->parser.InFile = NULL;
|
p->parser.InFile = NULL;
|
||||||
}
|
}
|
||||||
@@ -239,6 +234,8 @@ int DLLEXPORT EN_open(EN_Project p, const char *inpFile, const char *rptFile,
|
|||||||
if (p->outfile.Hydflag == USE) ERRCODE(openhydfile(p));
|
if (p->outfile.Hydflag == USE) ERRCODE(openhydfile(p));
|
||||||
|
|
||||||
// Write input summary to report file
|
// Write input summary to report file
|
||||||
|
if (!errcode)
|
||||||
|
{
|
||||||
if (p->report.Summaryflag) writesummary(p);
|
if (p->report.Summaryflag) writesummary(p);
|
||||||
writetime(p, FMT104);
|
writetime(p, FMT104);
|
||||||
p->Openflag = TRUE;
|
p->Openflag = TRUE;
|
||||||
@@ -1592,13 +1589,20 @@ int DLLEXPORT EN_setqualtype(EN_Project p, int qualType, char *chemName,
|
|||||||
Quality *qual = &p->quality;
|
Quality *qual = &p->quality;
|
||||||
|
|
||||||
double *Ucf = p->Ucf;
|
double *Ucf = p->Ucf;
|
||||||
int i;
|
int i, oldQualFlag, traceNodeIndex;
|
||||||
double ccf = 1.0;
|
double ccf = 1.0;
|
||||||
|
|
||||||
if (!p->Openflag) return 102;
|
if (!p->Openflag) return 102;
|
||||||
if (qual->OpenQflag) return 262;
|
if (qual->OpenQflag) return 262;
|
||||||
if (qualType < EN_NONE || qualType > EN_TRACE) return 251;
|
if (qualType < NONE || qualType > TRACE) return 251;
|
||||||
qual->Qualflag = (char)qualType;
|
if (qualType == TRACE)
|
||||||
|
{
|
||||||
|
traceNodeIndex = findnode(net, traceNode);
|
||||||
|
if (traceNodeIndex == 0) return 212;
|
||||||
|
}
|
||||||
|
|
||||||
|
oldQualFlag = qual->Qualflag;
|
||||||
|
qual->Qualflag = qualType;
|
||||||
qual->Ctol *= Ucf[QUALITY];
|
qual->Ctol *= Ucf[QUALITY];
|
||||||
if (qual->Qualflag == CHEM) // Chemical analysis
|
if (qual->Qualflag == CHEM) // Chemical analysis
|
||||||
{
|
{
|
||||||
@@ -1626,7 +1630,7 @@ int DLLEXPORT EN_setqualtype(EN_Project p, int qualType, char *chemName,
|
|||||||
|
|
||||||
// When changing from CHEM to AGE or TRACE, nodes initial quality
|
// When changing from CHEM to AGE or TRACE, nodes initial quality
|
||||||
// values must be returned to their original ones
|
// values must be returned to their original ones
|
||||||
if ((qual->Qualflag == AGE || qual->Qualflag == TRACE) & (Ucf[QUALITY] != 1))
|
if ((qual->Qualflag == AGE || qual->Qualflag == TRACE) && oldQualFlag == CHEM)
|
||||||
{
|
{
|
||||||
for (i = 1; i <= p->network.Nnodes; i++)
|
for (i = 1; i <= p->network.Nnodes; i++)
|
||||||
{
|
{
|
||||||
@@ -4381,7 +4385,7 @@ int DLLEXPORT EN_setcurvevalue(EN_Project p, int curveIndex, int pointIndex,
|
|||||||
}
|
}
|
||||||
|
|
||||||
int DLLEXPORT EN_getcurve(EN_Project p, int index, char *id, int *nPoints,
|
int DLLEXPORT EN_getcurve(EN_Project p, int index, char *id, int *nPoints,
|
||||||
double **xValues, double **yValues)
|
double *xValues, double *yValues)
|
||||||
/*----------------------------------------------------------------
|
/*----------------------------------------------------------------
|
||||||
** Input: index = data curve index
|
** Input: index = data curve index
|
||||||
** Output: id = ID name of data curve
|
** Output: id = ID name of data curve
|
||||||
@@ -4406,8 +4410,8 @@ int DLLEXPORT EN_getcurve(EN_Project p, int index, char *id, int *nPoints,
|
|||||||
*nPoints = curve->Npts;
|
*nPoints = curve->Npts;
|
||||||
for (i = 0; i < curve->Npts; i++)
|
for (i = 0; i < curve->Npts; i++)
|
||||||
{
|
{
|
||||||
*xValues[i] = curve->X[i];
|
xValues[i] = curve->X[i];
|
||||||
*yValues[i] = curve->Y[i];
|
yValues[i] = curve->Y[i];
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,15 +10,11 @@
|
|||||||
Last Updated: 03/17/2019
|
Last Updated: 03/17/2019
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
#ifndef __APPLE__
|
||||||
#ifdef _DEBUG
|
#include <malloc.h>
|
||||||
#define _CRTDBG_MAP_ALLOC
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <crtdbg.h>
|
|
||||||
#else
|
#else
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
@@ -649,7 +645,7 @@ int DLLEXPORT ENsetcurvevalue(int curveIndex, int pointIndex, EN_API_FLOAT_TYPE
|
|||||||
}
|
}
|
||||||
|
|
||||||
int DLLEXPORT ENgetcurve(int index, char *id, int *nPoints,
|
int DLLEXPORT ENgetcurve(int index, char *id, int *nPoints,
|
||||||
EN_API_FLOAT_TYPE **xValues, EN_API_FLOAT_TYPE **yValues)
|
EN_API_FLOAT_TYPE *xValues, EN_API_FLOAT_TYPE *yValues)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
Network *net = &_defaultProject->network;
|
Network *net = &_defaultProject->network;
|
||||||
@@ -661,8 +657,8 @@ int DLLEXPORT ENgetcurve(int index, char *id, int *nPoints,
|
|||||||
*nPoints = curve->Npts;
|
*nPoints = curve->Npts;
|
||||||
for (i = 0; i < curve->Npts; i++)
|
for (i = 0; i < curve->Npts; i++)
|
||||||
{
|
{
|
||||||
*xValues[i] = (EN_API_FLOAT_TYPE)curve->X[i];
|
xValues[i] = (EN_API_FLOAT_TYPE)curve->X[i];
|
||||||
*yValues[i] = (EN_API_FLOAT_TYPE)curve->Y[i];
|
yValues[i] = (EN_API_FLOAT_TYPE)curve->Y[i];
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ typedef struct {
|
|||||||
Project *project;
|
Project *project;
|
||||||
error_handle_t *error;
|
error_handle_t *error;
|
||||||
}handle_t;
|
}handle_t;
|
||||||
|
|
||||||
// Extern functions
|
// Extern functions
|
||||||
extern char *geterrmsg(int, char *);
|
extern char *geterrmsg(int, char *);
|
||||||
// Local functions
|
// Local functions
|
||||||
@@ -625,7 +624,7 @@ int EXPORT_PY_API curv_setvalue(Handle ph, int curveIndex, int pointIndex, doubl
|
|||||||
return set_error(pr->error, EN_setcurvevalue(pr->project, curveIndex, pointIndex, x, y));
|
return set_error(pr->error, EN_setcurvevalue(pr->project, curveIndex, pointIndex, x, y));
|
||||||
}
|
}
|
||||||
|
|
||||||
int EXPORT_PY_API curv_get(Handle ph, int curveIndex, char* id, int *nValues, double **xValues, double **yValues)
|
int EXPORT_PY_API curv_get(Handle ph, int curveIndex, char* id, int *nValues, double *xValues, double *yValues)
|
||||||
{
|
{
|
||||||
handle_t *pr = (handle_t *)ph;
|
handle_t *pr = (handle_t *)ph;
|
||||||
return set_error(pr->error, EN_getcurve(pr->project, curveIndex, id, nValues, xValues, yValues));
|
return set_error(pr->error, EN_getcurve(pr->project, curveIndex, id, nValues, xValues, yValues));
|
||||||
@@ -787,26 +786,22 @@ void error_lookup(int errcode, char *dest_msg, int dest_len)
|
|||||||
{
|
{
|
||||||
char *msg = NULL;
|
char *msg = NULL;
|
||||||
|
|
||||||
switch (errcode) {
|
switch (errcode)
|
||||||
case 1:
|
{
|
||||||
msg = WARN1;
|
case 1: msg = WARN1;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2: msg = WARN2;
|
||||||
msg = WARN2;
|
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3: msg = WARN3;
|
||||||
msg = WARN3;
|
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4: msg = WARN4;
|
||||||
msg = WARN4;
|
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5: msg = WARN5;
|
||||||
msg = WARN5;
|
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6: msg = WARN6;
|
||||||
msg = WARN6;
|
|
||||||
break;
|
break;
|
||||||
default: {
|
default:
|
||||||
|
{
|
||||||
char new_msg[MAXMSG + 1];
|
char new_msg[MAXMSG + 1];
|
||||||
msg = geterrmsg(errcode, new_msg);
|
msg = geterrmsg(errcode, new_msg);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,9 +11,12 @@
|
|||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef __APPLE__
|
||||||
|
#include <malloc.h>
|
||||||
|
#else
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#endif
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "hash.h"
|
#include "hash.h"
|
||||||
|
|
||||||
#define HASHTABLEMAXSIZE 128000
|
#define HASHTABLEMAXSIZE 128000
|
||||||
|
|||||||
@@ -11,9 +11,13 @@
|
|||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#ifndef __APPLE__
|
||||||
|
#include <malloc.h>
|
||||||
|
#else
|
||||||
|
#include <stdlib.h>
|
||||||
|
#endif
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|||||||
@@ -11,9 +11,13 @@
|
|||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#ifndef __APPLE__
|
||||||
|
#include <malloc.h>
|
||||||
|
#else
|
||||||
|
#include <stdlib.h>
|
||||||
|
#endif
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|||||||
@@ -12,9 +12,13 @@
|
|||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#ifndef __APPLE__
|
||||||
|
#include <malloc.h>
|
||||||
|
#else
|
||||||
|
#include <stdlib.h>
|
||||||
|
#endif
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ Last Updated: 11/27/2018
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "funcs.h"
|
#include "funcs.h"
|
||||||
|
|
||||||
|
|||||||
@@ -7,13 +7,17 @@ Description: saves network data to an EPANET formatted text file
|
|||||||
Authors: see AUTHORS
|
Authors: see AUTHORS
|
||||||
Copyright: see AUTHORS
|
Copyright: see AUTHORS
|
||||||
License: see LICENSE
|
License: see LICENSE
|
||||||
Last Updated: 03/17/2019
|
Last Updated: 04/02/2019
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#ifndef __APPLE__
|
||||||
|
#include <malloc.h>
|
||||||
|
#else
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#endif
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
@@ -538,7 +542,7 @@ int saveinpfile(Project *pr, const char *fname)
|
|||||||
|
|
||||||
if (qual->Climit > 0.0)
|
if (qual->Climit > 0.0)
|
||||||
{
|
{
|
||||||
fprintf(f, "\n LIMITING POTENTIAL %-.6f", qual->Climit);
|
fprintf(f, "\n LIMITING POTENTIAL %-.6f", qual->Climit * pr->Ucf[QUALITY]);
|
||||||
}
|
}
|
||||||
if (qual->Rfactor != MISSING && qual->Rfactor != 0.0)
|
if (qual->Rfactor != MISSING && qual->Rfactor != 0.0)
|
||||||
{
|
{
|
||||||
@@ -793,8 +797,7 @@ int saveinpfile(Project *pr, const char *fname)
|
|||||||
saveauxdata(pr, f);
|
saveauxdata(pr, f);
|
||||||
|
|
||||||
// Close the new input file
|
// Close the new input file
|
||||||
fprintf(f, "\n");
|
fprintf(f, "\n%s\n", s_END);
|
||||||
fprintf(f, s_END);
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
14
src/input1.c
14
src/input1.c
@@ -10,23 +10,19 @@ License: see LICENSE
|
|||||||
Last Updated: 03/17/2019
|
Last Updated: 03/17/2019
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
#ifdef _DEBUG
|
|
||||||
#define _CRTDBG_MAP_ALLOC
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <crtdbg.h>
|
|
||||||
#else
|
|
||||||
#include <stdlib.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <math.h>
|
#ifndef __APPLE__
|
||||||
|
#include <malloc.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "funcs.h"
|
#include "funcs.h"
|
||||||
#include "hash.h"
|
#include "hash.h"
|
||||||
#include "text.h"
|
#include "text.h"
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
// Default values
|
// Default values
|
||||||
#define MAXITER 200 // Default max. # hydraulic iterations
|
#define MAXITER 200 // Default max. # hydraulic iterations
|
||||||
|
|||||||
23
src/input2.c
23
src/input2.c
@@ -7,19 +7,16 @@ Description: reads and interprets network data from an EPANET input file
|
|||||||
Authors: see AUTHORS
|
Authors: see AUTHORS
|
||||||
Copyright: see AUTHORS
|
Copyright: see AUTHORS
|
||||||
License: see LICENSE
|
License: see LICENSE
|
||||||
Last Updated: 03/17/2019
|
Last Updated: 04/02/2019
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
#ifdef _DEBUG
|
|
||||||
#define _CRTDBG_MAP_ALLOC
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <crtdbg.h>
|
|
||||||
#else
|
|
||||||
#include <stdlib.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#ifndef __APPLE__
|
||||||
|
#include <malloc.h>
|
||||||
|
#endif
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
@@ -150,7 +147,7 @@ int readdata(Project *pr)
|
|||||||
inperr, errsum; // Error code & total error count
|
inperr, errsum; // Error code & total error count
|
||||||
|
|
||||||
// Allocate input buffer
|
// Allocate input buffer
|
||||||
parser->X = (double *)calloc(MAXTOKS + 1, sizeof(double));
|
parser->X = (double *)calloc(MAXTOKS, sizeof(double));
|
||||||
ERRCODE(MEMCHECK(parser->X));
|
ERRCODE(MEMCHECK(parser->X));
|
||||||
if (errcode) return errcode;
|
if (errcode) return errcode;
|
||||||
|
|
||||||
@@ -178,7 +175,7 @@ int readdata(Project *pr)
|
|||||||
while (fgets(line, MAXLINE, parser->InFile) != NULL)
|
while (fgets(line, MAXLINE, parser->InFile) != NULL)
|
||||||
{
|
{
|
||||||
// Make copy of line and scan for tokens
|
// Make copy of line and scan for tokens
|
||||||
strncpy(wline, line, MAXLINE);
|
strcpy(wline, line);
|
||||||
parser->Ntokens = gettokens(wline, parser->Tok, MAXTOKS, parser->Comment);
|
parser->Ntokens = gettokens(wline, parser->Tok, MAXTOKS, parser->Comment);
|
||||||
|
|
||||||
// Skip blank lines and those filled with a comment
|
// Skip blank lines and those filled with a comment
|
||||||
@@ -863,6 +860,12 @@ int gettokens(char *s, char** Tok, int maxToks, char *comment)
|
|||||||
while (len > 0 && n < MAXTOKS)
|
while (len > 0 && n < MAXTOKS)
|
||||||
{
|
{
|
||||||
m = (int)strcspn(s,SEPSTR); // Find token length
|
m = (int)strcspn(s,SEPSTR); // Find token length
|
||||||
|
if (m == len) // s is last token
|
||||||
|
{
|
||||||
|
Tok[n] = s;
|
||||||
|
n++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
len -= m+1; // Update length of s
|
len -= m+1; // Update length of s
|
||||||
if (m == 0) s++; // No token found
|
if (m == 0) s++; // No token found
|
||||||
else
|
else
|
||||||
|
|||||||
11
src/input3.c
11
src/input3.c
@@ -10,16 +10,13 @@ License: see LICENSE
|
|||||||
Last Updated: 03/17/2019
|
Last Updated: 03/17/2019
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
#ifdef _DEBUG
|
|
||||||
#define _CRTDBG_MAP_ALLOC
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <crtdbg.h>
|
|
||||||
#else
|
|
||||||
#include <stdlib.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#ifndef __APPLE__
|
||||||
|
#include <malloc.h>
|
||||||
|
#endif
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|||||||
@@ -15,7 +15,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#ifndef __APPLE__
|
||||||
|
#include <malloc.h>
|
||||||
|
#endif
|
||||||
#include "mempool.h"
|
#include "mempool.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -21,7 +21,9 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
|||||||
|
|
||||||
# configure file groups
|
# configure file groups
|
||||||
set(EPANET_OUT_SOURCES src/epanet_output.c
|
set(EPANET_OUT_SOURCES src/epanet_output.c
|
||||||
../util/errormanager.c)
|
../util/errormanager.c
|
||||||
|
../util/filemanager.c
|
||||||
|
../util/cstr_helper.c)
|
||||||
|
|
||||||
|
|
||||||
# the binary output file API
|
# the binary output file API
|
||||||
|
|||||||
@@ -2,8 +2,9 @@
|
|||||||
//
|
//
|
||||||
// epanet_output.c -- API for reading results from EPANET binary output file
|
// epanet_output.c -- API for reading results from EPANET binary output file
|
||||||
//
|
//
|
||||||
// Version: 0.30
|
// Version: 0.40
|
||||||
// Date 09/06/2017
|
// Date 04/02/2019
|
||||||
|
// 09/06/2017
|
||||||
// 06/17/2016
|
// 06/17/2016
|
||||||
// 08/05/2014
|
// 08/05/2014
|
||||||
// 05/21/2014
|
// 05/21/2014
|
||||||
@@ -40,18 +41,13 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "util/errormanager.h"
|
#include "util/errormanager.h"
|
||||||
|
#include "util/filemanager.h"
|
||||||
|
|
||||||
#include "epanet_output.h"
|
#include "epanet_output.h"
|
||||||
#include "messages.h"
|
#include "messages.h"
|
||||||
|
|
||||||
|
|
||||||
// NOTE: These depend on machine data model and may change when porting
|
// NOTE: These depend on machine data model and may change when porting
|
||||||
// F_OFF Must be a 8 byte / 64 bit integer for large file support
|
|
||||||
#ifdef _WIN32 // Windows (32-bit and 64-bit)
|
|
||||||
#define F_OFF __int64
|
|
||||||
#else // Other platforms
|
|
||||||
#define F_OFF off_t
|
|
||||||
#endif
|
|
||||||
#define INT4 int // Must be a 4 byte / 32 bit integer type
|
#define INT4 int // Must be a 4 byte / 32 bit integer type
|
||||||
#define REAL4 float // Must be a 4 byte / 32 bit real type
|
#define REAL4 float // Must be a 4 byte / 32 bit real type
|
||||||
#define WORDSIZE 4 // Memory alignment 4 byte word size for both int and real
|
#define WORDSIZE 4 // Memory alignment 4 byte word size for both int and real
|
||||||
@@ -71,13 +67,12 @@
|
|||||||
|
|
||||||
// Typedefs for opaque pointer
|
// Typedefs for opaque pointer
|
||||||
typedef struct data_s {
|
typedef struct data_s {
|
||||||
char name[MAXFNAME+1]; // file path/name
|
|
||||||
FILE* file; // FILE structure pointer
|
|
||||||
INT4 nodeCount, tankCount, linkCount, pumpCount, valveCount, nPeriods;
|
INT4 nodeCount, tankCount, linkCount, pumpCount, valveCount, nPeriods;
|
||||||
F_OFF outputStartPos; // starting file position of output data
|
F_OFF outputStartPos; // starting file position of output data
|
||||||
F_OFF bytesPerPeriod; // bytes saved per simulation time period
|
F_OFF bytesPerPeriod; // bytes saved per simulation time period
|
||||||
|
|
||||||
error_handle_t* error_handle;
|
error_handle_t *error_handle;
|
||||||
|
file_handle_t *file_handle;
|
||||||
} data_t;
|
} data_t;
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@@ -88,16 +83,12 @@ int validateFile(ENR_Handle);
|
|||||||
float getNodeValue(ENR_Handle, int, int, int);
|
float getNodeValue(ENR_Handle, int, int, int);
|
||||||
float getLinkValue(ENR_Handle, int, int, int);
|
float getLinkValue(ENR_Handle, int, int, int);
|
||||||
|
|
||||||
int _fopen(FILE **f, const char *name, const char *mode);
|
float *newFloatArray(int n);
|
||||||
int _fseek(FILE* stream, F_OFF offset, int whence);
|
int *newIntArray(int n);
|
||||||
F_OFF _ftell(FILE* stream);
|
char *newCharArray(int n);
|
||||||
|
|
||||||
float* newFloatArray(int n);
|
|
||||||
int* newIntArray(int n);
|
|
||||||
char* newCharArray(int n);
|
|
||||||
|
|
||||||
|
|
||||||
int EXPORT_OUT_API ENR_init(ENR_Handle* dp_handle)
|
int EXPORT_OUT_API ENR_init(ENR_Handle *dp_handle)
|
||||||
// Purpose: Initialized pointer for the opaque ENR_Handle.
|
// Purpose: Initialized pointer for the opaque ENR_Handle.
|
||||||
//
|
//
|
||||||
// Returns: Error code 0 on success, -1 on failure
|
// Returns: Error code 0 on success, -1 on failure
|
||||||
@@ -114,6 +105,7 @@ int EXPORT_OUT_API ENR_init(ENR_Handle* dp_handle)
|
|||||||
|
|
||||||
if (p_data != NULL){
|
if (p_data != NULL){
|
||||||
p_data->error_handle = create_error_manager(&errorLookup);
|
p_data->error_handle = create_error_manager(&errorLookup);
|
||||||
|
p_data->file_handle = create_file_manager();
|
||||||
*dp_handle = p_data;
|
*dp_handle = p_data;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -123,7 +115,7 @@ int EXPORT_OUT_API ENR_init(ENR_Handle* dp_handle)
|
|||||||
return errorcode;
|
return errorcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
int EXPORT_OUT_API ENR_close(ENR_Handle* p_handle)
|
int EXPORT_OUT_API ENR_close(ENR_Handle *p_handle)
|
||||||
/*------------------------------------------------------------------------
|
/*------------------------------------------------------------------------
|
||||||
** Input: *p_handle = pointer to ENR_Handle struct
|
** Input: *p_handle = pointer to ENR_Handle struct
|
||||||
**
|
**
|
||||||
@@ -143,13 +135,16 @@ int EXPORT_OUT_API ENR_close(ENR_Handle* p_handle)
|
|||||||
|
|
||||||
p_data = (data_t*)(*p_handle);
|
p_data = (data_t*)(*p_handle);
|
||||||
|
|
||||||
if (p_data == NULL || p_data->file == NULL)
|
if (p_data == NULL || p_data->file_handle == NULL)
|
||||||
errorcode = -1;
|
errorcode = -1;
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
close_file(p_data->file_handle);
|
||||||
|
|
||||||
delete_error_manager(p_data->error_handle);
|
delete_error_manager(p_data->error_handle);
|
||||||
fclose(p_data->file);
|
delete_file_manager(p_data->file_handle);
|
||||||
|
|
||||||
free(p_data);
|
free(p_data);
|
||||||
|
|
||||||
*p_handle = NULL;
|
*p_handle = NULL;
|
||||||
@@ -178,23 +173,22 @@ int EXPORT_OUT_API ENR_open(ENR_Handle p_handle, const char* path)
|
|||||||
if (p_data == NULL) return -1;
|
if (p_data == NULL) return -1;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
strncpy(p_data->name, path, MAXFNAME);
|
|
||||||
// Attempt to open binary output file for reading only
|
// Attempt to open binary output file for reading only
|
||||||
if ((_fopen(&(p_data->file), path, "rb")) != 0) errorcode = 434;
|
if ((open_file(p_data->file_handle, path, "rb")) != 0)
|
||||||
|
errorcode = 434;
|
||||||
|
|
||||||
// Perform checks to insure the file is valid
|
// Perform checks to insure the file is valid
|
||||||
else if ((err = validateFile(p_data)) != 0) errorcode = err;
|
else if ((err = validateFile(p_data)) != 0) errorcode = err;
|
||||||
|
|
||||||
// If a warning is encountered read file header
|
// If a warning is encountered read file header
|
||||||
if (errorcode < 400 ) {
|
if (errorcode < 400 ) {
|
||||||
|
|
||||||
// read network size
|
// read network size
|
||||||
fseek(p_data->file, 2*WORDSIZE, SEEK_SET);
|
seek_file(p_data->file_handle, 2*WORDSIZE, SEEK_SET);
|
||||||
fread(&(p_data->nodeCount), WORDSIZE, 1, p_data->file);
|
read_file(&(p_data->nodeCount), WORDSIZE, 1, p_data->file_handle);
|
||||||
fread(&(p_data->tankCount), WORDSIZE, 1, p_data->file);
|
read_file(&(p_data->tankCount), WORDSIZE, 1, p_data->file_handle);
|
||||||
fread(&(p_data->linkCount), WORDSIZE, 1, p_data->file);
|
read_file(&(p_data->linkCount), WORDSIZE, 1, p_data->file_handle);
|
||||||
fread(&(p_data->pumpCount), WORDSIZE, 1, p_data->file);
|
read_file(&(p_data->pumpCount), WORDSIZE, 1, p_data->file_handle);
|
||||||
fread(&(p_data->valveCount), WORDSIZE, 1, p_data->file);
|
read_file(&(p_data->valveCount), WORDSIZE, 1, p_data->file_handle);
|
||||||
|
|
||||||
// Compute positions and offsets for retrieving data
|
// Compute positions and offsets for retrieving data
|
||||||
// fixed portion of header + title section + filenames + chem names
|
// fixed portion of header + title section + filenames + chem names
|
||||||
@@ -240,8 +234,8 @@ int EXPORT_OUT_API ENR_getVersion(ENR_Handle p_handle, int* version)
|
|||||||
if (p_data == NULL) return -1;
|
if (p_data == NULL) return -1;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fseek(p_data->file, 1*WORDSIZE, SEEK_SET);
|
seek_file(p_data->file_handle, 1*WORDSIZE, SEEK_SET);
|
||||||
if (fread(version, WORDSIZE, 1, p_data->file) != 1)
|
if (read_file(version, WORDSIZE, 1, p_data->file_handle) != 1)
|
||||||
errorcode = 436;
|
errorcode = 436;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -319,26 +313,26 @@ int EXPORT_OUT_API ENR_getUnits(ENR_Handle p_handle, ENR_Units code, int* unitFl
|
|||||||
switch (code)
|
switch (code)
|
||||||
{
|
{
|
||||||
case ENR_flowUnits:
|
case ENR_flowUnits:
|
||||||
_fseek(p_data->file, 9*WORDSIZE, SEEK_SET);
|
seek_file(p_data->file_handle, 9*WORDSIZE, SEEK_SET);
|
||||||
fread(unitFlag, WORDSIZE, 1, p_data->file);
|
read_file(unitFlag, WORDSIZE, 1, p_data->file_handle);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ENR_pressUnits:
|
case ENR_pressUnits:
|
||||||
_fseek(p_data->file, 10*WORDSIZE, SEEK_SET);
|
seek_file(p_data->file_handle, 10*WORDSIZE, SEEK_SET);
|
||||||
fread(unitFlag, WORDSIZE, 1, p_data->file);
|
read_file(unitFlag, WORDSIZE, 1, p_data->file_handle);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ENR_qualUnits:
|
case ENR_qualUnits:
|
||||||
offset = 7*WORDSIZE;
|
offset = 7*WORDSIZE;
|
||||||
_fseek(p_data->file, offset, SEEK_SET);
|
seek_file(p_data->file_handle, offset, SEEK_SET);
|
||||||
fread(unitFlag, WORDSIZE, 1, p_data->file);
|
read_file(unitFlag, WORDSIZE, 1, p_data->file_handle);
|
||||||
|
|
||||||
if (*unitFlag == 0) *unitFlag = ENR_NONE;
|
if (*unitFlag == 0) *unitFlag = ENR_NONE;
|
||||||
|
|
||||||
else if (*unitFlag == 1) {
|
else if (*unitFlag == 1) {
|
||||||
offset = 15*WORDSIZE + 3*MAXMSG_P1 + 2*(MAXFNAME+1) + MAXID_P1;
|
offset = 15*WORDSIZE + 3*MAXMSG_P1 + 2*(MAXFNAME+1) + MAXID_P1;
|
||||||
_fseek(p_data->file, offset, SEEK_SET);
|
seek_file(p_data->file_handle, offset, SEEK_SET);
|
||||||
fread(temp, MAXID_P1, 1, p_data->file);
|
read_file(temp, MAXID_P1, 1, p_data->file_handle);
|
||||||
|
|
||||||
if (!strcmp(temp, "mg/L")) *unitFlag = ENR_MGL;
|
if (!strcmp(temp, "mg/L")) *unitFlag = ENR_MGL;
|
||||||
else *unitFlag = ENR_UGL;
|
else *unitFlag = ENR_UGL;
|
||||||
@@ -379,18 +373,18 @@ int EXPORT_OUT_API ENR_getTimes(ENR_Handle p_handle, ENR_Time code, int* time)
|
|||||||
switch (code)
|
switch (code)
|
||||||
{
|
{
|
||||||
case ENR_reportStart:
|
case ENR_reportStart:
|
||||||
fseek(p_data->file, 12*WORDSIZE, SEEK_SET);
|
seek_file(p_data->file_handle, 12*WORDSIZE, SEEK_SET);
|
||||||
fread(time, WORDSIZE, 1, p_data->file);
|
read_file(time, WORDSIZE, 1, p_data->file_handle);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ENR_reportStep:
|
case ENR_reportStep:
|
||||||
fseek(p_data->file, 13*WORDSIZE, SEEK_SET);
|
seek_file(p_data->file_handle, 13*WORDSIZE, SEEK_SET);
|
||||||
fread(time, WORDSIZE, 1, p_data->file);
|
read_file(time, WORDSIZE, 1, p_data->file_handle);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ENR_simDuration:
|
case ENR_simDuration:
|
||||||
fseek(p_data->file, 14*WORDSIZE, SEEK_SET);
|
seek_file(p_data->file_handle, 14*WORDSIZE, SEEK_SET);
|
||||||
fread(time, WORDSIZE, 1, p_data->file);
|
read_file(time, WORDSIZE, 1, p_data->file_handle);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ENR_numPeriods:
|
case ENR_numPeriods:
|
||||||
@@ -405,7 +399,6 @@ int EXPORT_OUT_API ENR_getTimes(ENR_Handle p_handle, ENR_Time code, int* time)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int EXPORT_OUT_API ENR_getChemData(ENR_Handle p_handle, char** name, int* length)
|
int EXPORT_OUT_API ENR_getChemData(ENR_Handle p_handle, char** name, int* length)
|
||||||
|
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -459,8 +452,8 @@ int EXPORT_OUT_API ENR_getElementName(ENR_Handle p_handle, ENR_ElementType type,
|
|||||||
|
|
||||||
if (!errorcode)
|
if (!errorcode)
|
||||||
{
|
{
|
||||||
_fseek(p_data->file, offset, SEEK_SET);
|
seek_file(p_data->file_handle, offset, SEEK_SET);
|
||||||
fread(temp, 1, MAXID_P1, p_data->file);
|
read_file(temp, 1, MAXID_P1, p_data->file_handle);
|
||||||
|
|
||||||
*name = temp;
|
*name = temp;
|
||||||
*length = MAXID_P1;
|
*length = MAXID_P1;
|
||||||
@@ -505,9 +498,9 @@ int EXPORT_OUT_API ENR_getEnergyUsage(ENR_Handle p_handle, int pumpIndex,
|
|||||||
offset += (pumpIndex - 1)*(WORDSIZE + 6*WORDSIZE);
|
offset += (pumpIndex - 1)*(WORDSIZE + 6*WORDSIZE);
|
||||||
|
|
||||||
// Power summary is 1 int and 6 floats for each pump
|
// Power summary is 1 int and 6 floats for each pump
|
||||||
_fseek(p_data->file, offset, SEEK_SET);
|
seek_file(p_data->file_handle, offset, SEEK_SET);
|
||||||
fread(linkIndex, WORDSIZE, 1, p_data->file);
|
read_file(linkIndex, WORDSIZE, 1, p_data->file_handle);
|
||||||
fread(temp, WORDSIZE, 6, p_data->file);
|
read_file(temp, WORDSIZE, 6, p_data->file_handle);
|
||||||
|
|
||||||
*outValues = temp;
|
*outValues = temp;
|
||||||
*length = NENERGYRESULTS;
|
*length = NENERGYRESULTS;
|
||||||
@@ -541,8 +534,8 @@ int EXPORT_OUT_API ENR_getNetReacts(ENR_Handle p_handle, float** outValues, int*
|
|||||||
// Reaction summary is 4 floats located right before epilogue.
|
// Reaction summary is 4 floats located right before epilogue.
|
||||||
// This offset is relative to the end of the file.
|
// This offset is relative to the end of the file.
|
||||||
offset = - 3*WORDSIZE - 4*WORDSIZE;
|
offset = - 3*WORDSIZE - 4*WORDSIZE;
|
||||||
_fseek(p_data->file, offset, SEEK_END);
|
seek_file(p_data->file_handle, offset, SEEK_END);
|
||||||
fread(temp, WORDSIZE, 4, p_data->file);
|
read_file(temp, WORDSIZE, 4, p_data->file_handle);
|
||||||
|
|
||||||
*outValues = temp;
|
*outValues = temp;
|
||||||
*length = NREACTRESULTS;
|
*length = NREACTRESULTS;
|
||||||
@@ -670,8 +663,8 @@ int EXPORT_OUT_API ENR_getNodeAttribute(ENR_Handle p_handle, int periodIndex,
|
|||||||
// add offset for node and attribute
|
// add offset for node and attribute
|
||||||
offset += ((attr - 1)*p_data->nodeCount)*WORDSIZE;
|
offset += ((attr - 1)*p_data->nodeCount)*WORDSIZE;
|
||||||
|
|
||||||
_fseek(p_data->file, offset, SEEK_SET);
|
seek_file(p_data->file_handle, offset, SEEK_SET);
|
||||||
fread(temp, WORDSIZE, p_data->nodeCount, p_data->file);
|
read_file(temp, WORDSIZE, p_data->nodeCount, p_data->file_handle);
|
||||||
|
|
||||||
*outValueArray = temp;
|
*outValueArray = temp;
|
||||||
*length = p_data->nodeCount;
|
*length = p_data->nodeCount;
|
||||||
@@ -720,8 +713,8 @@ int EXPORT_OUT_API ENR_getLinkAttribute(ENR_Handle p_handle, int periodIndex,
|
|||||||
// add offset for link and attribute
|
// add offset for link and attribute
|
||||||
offset += ((attr - 1)*p_data->linkCount)*WORDSIZE;
|
offset += ((attr - 1)*p_data->linkCount)*WORDSIZE;
|
||||||
|
|
||||||
_fseek(p_data->file, offset, SEEK_SET);
|
seek_file(p_data->file_handle, offset, SEEK_SET);
|
||||||
fread(temp, WORDSIZE, p_data->linkCount, p_data->file);
|
read_file(temp, WORDSIZE, p_data->linkCount, p_data->file_handle);
|
||||||
|
|
||||||
*outValueArray = temp;
|
*outValueArray = temp;
|
||||||
*length = p_data->linkCount;
|
*length = p_data->linkCount;
|
||||||
@@ -852,16 +845,16 @@ int validateFile(ENR_Handle p_handle)
|
|||||||
p_data = (data_t*)p_handle;
|
p_data = (data_t*)p_handle;
|
||||||
|
|
||||||
// Read magic number from beginning of file
|
// Read magic number from beginning of file
|
||||||
fseek(p_data->file, 0L, SEEK_SET);
|
seek_file(p_data->file_handle, 0L, SEEK_SET);
|
||||||
fread(&magic1, WORDSIZE, 1, p_data->file);
|
read_file(&magic1, WORDSIZE, 1, p_data->file_handle);
|
||||||
|
|
||||||
// Fast forward to end and read file epilogue
|
// Fast forward to end and read file epilogue
|
||||||
fseek(p_data->file, -3*WORDSIZE, SEEK_END);
|
seek_file(p_data->file_handle, -3*WORDSIZE, SEEK_END);
|
||||||
fread(&(p_data->nPeriods), WORDSIZE, 1, p_data->file);
|
read_file(&(p_data->nPeriods), WORDSIZE, 1, p_data->file_handle);
|
||||||
fread(&hydcode, WORDSIZE, 1, p_data->file);
|
read_file(&hydcode, WORDSIZE, 1, p_data->file_handle);
|
||||||
fread(&magic2, WORDSIZE, 1, p_data->file);
|
read_file(&magic2, WORDSIZE, 1, p_data->file_handle);
|
||||||
|
|
||||||
filepos = _ftell(p_data->file);
|
filepos = tell_file(p_data->file_handle);
|
||||||
|
|
||||||
// Is the file an EPANET binary file?
|
// Is the file an EPANET binary file?
|
||||||
if (magic1 != magic2) errorcode = 435;
|
if (magic1 != magic2) errorcode = 435;
|
||||||
@@ -891,8 +884,8 @@ float getNodeValue(ENR_Handle p_handle, int periodIndex, int nodeIndex,
|
|||||||
// add byte position for attribute and node
|
// add byte position for attribute and node
|
||||||
offset += ((attr - 1)*p_data->nodeCount + (nodeIndex - 1))*WORDSIZE;
|
offset += ((attr - 1)*p_data->nodeCount + (nodeIndex - 1))*WORDSIZE;
|
||||||
|
|
||||||
_fseek(p_data->file, offset, SEEK_SET);
|
seek_file(p_data->file_handle, offset, SEEK_SET);
|
||||||
fread(&y, WORDSIZE, 1, p_data->file);
|
read_file(&y, WORDSIZE, 1, p_data->file_handle);
|
||||||
|
|
||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
@@ -915,56 +908,12 @@ float getLinkValue(ENR_Handle p_handle, int periodIndex, int linkIndex,
|
|||||||
// add byte position for attribute and link
|
// add byte position for attribute and link
|
||||||
offset += ((attr - 1)*p_data->linkCount + (linkIndex - 1))*WORDSIZE;
|
offset += ((attr - 1)*p_data->linkCount + (linkIndex - 1))*WORDSIZE;
|
||||||
|
|
||||||
_fseek(p_data->file, offset, SEEK_SET);
|
seek_file(p_data->file_handle, offset, SEEK_SET);
|
||||||
fread(&y, WORDSIZE, 1, p_data->file);
|
read_file(&y, WORDSIZE, 1, p_data->file_handle);
|
||||||
|
|
||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _fopen(FILE **f, const char *name, const char *mode) {
|
|
||||||
//
|
|
||||||
// Purpose: Substitute for fopen_s on platforms where it doesn't exist
|
|
||||||
// Note: fopen_s is part of C++11 standard
|
|
||||||
//
|
|
||||||
int ret = 0;
|
|
||||||
#ifdef _WIN32
|
|
||||||
ret = (int)fopen_s(f, name, mode);
|
|
||||||
#else
|
|
||||||
*f = fopen(name, mode);
|
|
||||||
if (!*f)
|
|
||||||
ret = -1;
|
|
||||||
#endif
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int _fseek(FILE* stream, F_OFF offset, int whence)
|
|
||||||
//
|
|
||||||
// Purpose: Selects platform fseek() for large file support
|
|
||||||
//
|
|
||||||
{
|
|
||||||
#ifdef _WIN32 // Windows (32-bit and 64-bit)
|
|
||||||
#define FSEEK64 _fseeki64
|
|
||||||
#else // Other platforms
|
|
||||||
#define FSEEK64 fseeko
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return FSEEK64(stream, offset, whence);
|
|
||||||
}
|
|
||||||
|
|
||||||
F_OFF _ftell(FILE* stream)
|
|
||||||
//
|
|
||||||
// Purpose: Selects platform ftell() for large file support
|
|
||||||
//
|
|
||||||
{
|
|
||||||
#ifdef _WIN32 // Windows (32-bit and 64-bit)
|
|
||||||
#define FTELL64 _ftelli64
|
|
||||||
#else // Other platforms
|
|
||||||
#define FTELL64 ftello
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return FTELL64(stream);
|
|
||||||
}
|
|
||||||
|
|
||||||
float* newFloatArray(int n)
|
float* newFloatArray(int n)
|
||||||
//
|
//
|
||||||
// Warning: Caller must free memory allocated by this function.
|
// Warning: Caller must free memory allocated by this function.
|
||||||
|
|||||||
@@ -11,9 +11,13 @@ Last Updated: 11/27/2018
|
|||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#ifndef __APPLE__
|
||||||
|
#include <malloc.h>
|
||||||
|
#else
|
||||||
|
#include <stdlib.h>
|
||||||
|
#endif
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|||||||
@@ -11,18 +11,10 @@
|
|||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef _DEBUG
|
|
||||||
#define _CRTDBG_MAP_ALLOC
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <crtdbg.h>
|
|
||||||
#else
|
|
||||||
#include <stdlib.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
//*** For the Windows SDK _tempnam function ***//
|
//*** For the Windows SDK _tempnam function ***//
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|||||||
@@ -11,9 +11,13 @@ Last Updated: 11/27/2018
|
|||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#ifndef __APPLE__
|
||||||
|
#include <malloc.h>
|
||||||
|
#else
|
||||||
|
#include <stdlib.h>
|
||||||
|
#endif
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
#include "mempool.h"
|
#include "mempool.h"
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ Last Updated: 11/27/2018
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
// Exported functions
|
// Exported functions
|
||||||
|
|||||||
@@ -11,10 +11,13 @@ Last Updated: 11/27/2018
|
|||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#ifndef __APPLE__
|
||||||
|
#include <malloc.h>
|
||||||
|
#else
|
||||||
|
#include <stdlib.h>
|
||||||
|
#endif
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
#include "mempool.h"
|
#include "mempool.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
|
|||||||
@@ -11,10 +11,13 @@
|
|||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#ifndef __APPLE__
|
||||||
|
#include <malloc.h>
|
||||||
|
#else
|
||||||
|
#include <stdlib.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#define snprintf _snprintf
|
#define snprintf _snprintf
|
||||||
|
|||||||
@@ -11,9 +11,13 @@
|
|||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#ifndef __APPLE__
|
||||||
|
#include <malloc.h>
|
||||||
|
#else
|
||||||
|
#include <stdlib.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "funcs.h"
|
#include "funcs.h"
|
||||||
|
|||||||
@@ -18,11 +18,16 @@
|
|||||||
linsolve() -- called from netsolve() in HYDRAUL.C
|
linsolve() -- called from netsolve() in HYDRAUL.C
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#ifndef __APPLE__
|
||||||
|
#include <malloc.h>
|
||||||
|
#else
|
||||||
|
#include <stdlib.h>
|
||||||
|
#endif
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
|
||||||
#include <time.h> //For optional timer macros
|
#include <time.h> //For optional timer macros
|
||||||
|
|
||||||
#include "text.h"
|
#include "text.h"
|
||||||
|
|||||||
@@ -14,10 +14,8 @@
|
|||||||
#ifndef TYPES_H
|
#ifndef TYPES_H
|
||||||
#define TYPES_H
|
#define TYPES_H
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#include "hash.h"
|
#include "hash.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
-------------------------------------------
|
-------------------------------------------
|
||||||
|
|||||||
48
src/util/cstr_helper.c
Normal file
48
src/util/cstr_helper.c
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
******************************************************************************
|
||||||
|
Project: OWA EPANET
|
||||||
|
Version: 2.2
|
||||||
|
Module: util/cstr_helper.c
|
||||||
|
Description: Provides C string helper functions
|
||||||
|
Authors: see AUTHORS
|
||||||
|
Copyright: see AUTHORS
|
||||||
|
License: see LICENSE
|
||||||
|
Last Updated: 04/02/2019
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "cstr_helper.h"
|
||||||
|
|
||||||
|
|
||||||
|
int copy_cstr(const char *source, char **dest)
|
||||||
|
// Determines length, allocates memory, and returns a null terminated copy
|
||||||
|
// Be Aware: caller is responsible for freeing memory
|
||||||
|
{
|
||||||
|
size_t size;
|
||||||
|
|
||||||
|
size = 1 + strlen(source);
|
||||||
|
*dest = (char *) calloc(size, sizeof(char));
|
||||||
|
|
||||||
|
if (*dest == NULL)
|
||||||
|
return -1;
|
||||||
|
else {
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
strncpy_s(*dest, size, source, size);
|
||||||
|
#else
|
||||||
|
strncpy(*dest, source, size);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool isnullterm_cstr(const char *source)
|
||||||
|
{
|
||||||
|
if (strchr(source, '\0'))
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
25
src/util/cstr_helper.h
Normal file
25
src/util/cstr_helper.h
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
******************************************************************************
|
||||||
|
Project: OWA EPANET
|
||||||
|
Version: 2.2
|
||||||
|
Module: util/cstr_helper.h
|
||||||
|
Description: Provides C string helper functions
|
||||||
|
Authors: see AUTHORS
|
||||||
|
Copyright: see AUTHORS
|
||||||
|
License: see LICENSE
|
||||||
|
Last Updated: 04/02/2019
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef CSTR_HELPER_H_
|
||||||
|
#define CSTR_HELPER_H_
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
|
||||||
|
int copy_cstr(const char *source, char **destination);
|
||||||
|
bool isnullterm_cstr(const char *source);
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* CSTR_HELPER_H_ */
|
||||||
@@ -1,21 +1,34 @@
|
|||||||
//-----------------------------------------------------------------------------
|
/*
|
||||||
//
|
******************************************************************************
|
||||||
// errormanager.c
|
Project: OWA EPANET
|
||||||
//
|
Version: 2.2
|
||||||
// Purpose: Provides a simple interface for managing runtime error messages.
|
Module: util/errormanager.c
|
||||||
//
|
Description: Provides a simple interface for managing errors
|
||||||
// Date: 08/25/2017
|
Authors: see AUTHORS
|
||||||
//
|
Copyright: see AUTHORS
|
||||||
// Author: Michael E. Tryby
|
License: see LICENSE
|
||||||
// US EPA - ORD/NRMRL
|
Last Updated: 04/02/2019
|
||||||
//-----------------------------------------------------------------------------
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
//#ifdef _WIN32
|
||||||
|
//#define _CRTDBG_MAP_ALLOC
|
||||||
|
//#include <stdlib.h>
|
||||||
|
//#include <crtdbg.h>
|
||||||
|
//#else
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
//#endif
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "errormanager.h"
|
#include "errormanager.h"
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct error_s {
|
||||||
|
int error_status;
|
||||||
|
void (*p_msg_lookup)(int, char*, int);
|
||||||
|
} error_handle_t;
|
||||||
|
|
||||||
|
|
||||||
error_handle_t *create_error_manager(void (*p_error_message)(int, char*, int))
|
error_handle_t *create_error_manager(void (*p_error_message)(int, char*, int))
|
||||||
//
|
//
|
||||||
// Purpose: Constructs a new error handle.
|
// Purpose: Constructs a new error handle.
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
/*
|
/*
|
||||||
* errormanager.h
|
******************************************************************************
|
||||||
*
|
Project: OWA EPANET
|
||||||
* Created on: Aug 25, 2017
|
Version: 2.2
|
||||||
*
|
Module: util/errormanager.h
|
||||||
* Author: Michael E. Tryby
|
Description: Provides a simple interface for managing errors
|
||||||
* US EPA - ORD/NRMRL
|
Authors: see AUTHORS
|
||||||
*/
|
Copyright: see AUTHORS
|
||||||
|
License: see LICENSE
|
||||||
|
Last Updated: 04/02/2019
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef ERRORMANAGER_H_
|
#ifndef ERRORMANAGER_H_
|
||||||
#define ERRORMANAGER_H_
|
#define ERRORMANAGER_H_
|
||||||
@@ -17,11 +21,8 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Forward declaration
|
||||||
typedef struct error_s {
|
typedef struct error_s error_handle_t;
|
||||||
int error_status;
|
|
||||||
void (*p_msg_lookup)(int, char*, int);
|
|
||||||
} error_handle_t;
|
|
||||||
|
|
||||||
error_handle_t* create_error_manager(void (*p_error_message)(int, char*, int));
|
error_handle_t* create_error_manager(void (*p_error_message)(int, char*, int));
|
||||||
void delete_error_manager(error_handle_t* error_handle);
|
void delete_error_manager(error_handle_t* error_handle);
|
||||||
|
|||||||
211
src/util/filemanager.c
Normal file
211
src/util/filemanager.c
Normal file
@@ -0,0 +1,211 @@
|
|||||||
|
/*
|
||||||
|
******************************************************************************
|
||||||
|
Project: OWA EPANET
|
||||||
|
Version: 2.2
|
||||||
|
Module: util/filemanager.c
|
||||||
|
Description: Provides a simple interface for managing files
|
||||||
|
Authors: see AUTHORS
|
||||||
|
Copyright: see AUTHORS
|
||||||
|
License: see LICENSE
|
||||||
|
Last Updated: 04/01/2019
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
// MSVC ONLY
|
||||||
|
#ifdef _DEBUG
|
||||||
|
#define _CRTDBG_MAP_ALLOC
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <crtdbg.h>
|
||||||
|
#else
|
||||||
|
#include <stdlib.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
#include "filemanager.h"
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct file_s {
|
||||||
|
char *filename; // Assumes this is a null terminated string
|
||||||
|
FILE *file;
|
||||||
|
} file_handle_t;
|
||||||
|
|
||||||
|
|
||||||
|
// local (private) functions
|
||||||
|
int _fopen(FILE **f, const char *name, const char *mode);
|
||||||
|
int _get_temp_filename(char **tempname);
|
||||||
|
|
||||||
|
|
||||||
|
file_handle_t *create_file_manager() {
|
||||||
|
|
||||||
|
file_handle_t *file_handle;
|
||||||
|
file_handle = (file_handle_t *)calloc(1, sizeof(file_handle_t));
|
||||||
|
|
||||||
|
file_handle->filename = NULL;
|
||||||
|
file_handle->file = NULL;
|
||||||
|
|
||||||
|
return file_handle;
|
||||||
|
}
|
||||||
|
|
||||||
|
void delete_file_manager(file_handle_t *file_handle) {
|
||||||
|
|
||||||
|
if (file_handle->file != NULL)
|
||||||
|
close_file(file_handle);
|
||||||
|
|
||||||
|
free(file_handle->filename);
|
||||||
|
free(file_handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int get_filename(file_handle_t *file_handle, char **filename)
|
||||||
|
//
|
||||||
|
// BE AWARE: The memory allocated here must be freed by the caller
|
||||||
|
//
|
||||||
|
{
|
||||||
|
return copy_cstr(file_handle->filename, filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int open_file(file_handle_t *file_handle, const char *filename, const char *file_mode) {
|
||||||
|
int error = 0;
|
||||||
|
|
||||||
|
if (filename == NULL)
|
||||||
|
_get_temp_filename(&(file_handle->filename));
|
||||||
|
else
|
||||||
|
copy_cstr(filename, &(file_handle->filename));
|
||||||
|
|
||||||
|
if (file_mode == NULL)
|
||||||
|
error = -1;
|
||||||
|
else {
|
||||||
|
error = _fopen(&(file_handle->file), file_handle->filename, file_mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
int seek_file(file_handle_t *file_handle, F_OFF offset, int whence)
|
||||||
|
{
|
||||||
|
#ifdef _MSC_VER // Windows (32-bit and 64-bit)
|
||||||
|
#define FSEEK64 _fseeki64
|
||||||
|
#else // Other platforms
|
||||||
|
#define FSEEK64 fseeko
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return FSEEK64(file_handle->file, offset, whence);
|
||||||
|
}
|
||||||
|
|
||||||
|
F_OFF tell_file(file_handle_t *file_handle)
|
||||||
|
{
|
||||||
|
#ifdef _MSC_VER // Windows (32-bit and 64-bit)
|
||||||
|
#define FTELL64 _ftelli64
|
||||||
|
#else // Other platforms
|
||||||
|
#define FTELL64 ftello
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return FTELL64(file_handle->file);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read and write to a binary file
|
||||||
|
size_t read_file(void *ptr, size_t size, size_t nmemb, file_handle_t *file_handle)
|
||||||
|
{
|
||||||
|
return fread(ptr, size, nmemb, file_handle->file);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t write_file(const void * ptr, size_t size, size_t count, file_handle_t *file_handle)
|
||||||
|
{
|
||||||
|
return fwrite(ptr, size, count, file_handle->file);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// print and get from a text file
|
||||||
|
int printf_file(file_handle_t *file_handle, const char *format, ... )
|
||||||
|
{
|
||||||
|
int error = 0;
|
||||||
|
va_list args;
|
||||||
|
|
||||||
|
va_start(args, format);
|
||||||
|
error = vfprintf(file_handle->file, format, args);
|
||||||
|
va_end(args);
|
||||||
|
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
int gets_file(char *str, int num, file_handle_t *file_handle)
|
||||||
|
{
|
||||||
|
fgets(str, num, file_handle->file);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int close_file(file_handle_t *file_handle) {
|
||||||
|
int error = 0;
|
||||||
|
|
||||||
|
if (file_handle->file != NULL) {
|
||||||
|
error = fclose(file_handle->file);
|
||||||
|
file_handle->file = NULL;
|
||||||
|
}
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
int remove_file(file_handle_t *file_handle) {
|
||||||
|
return remove(file_handle->filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool is_valid(file_handle_t *file_handle)
|
||||||
|
{
|
||||||
|
if ((file_handle->filename == NULL && file_handle->file == NULL) ||
|
||||||
|
(isnullterm_cstr(file_handle->filename) && file_handle != NULL))
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int _fopen(FILE **f, const char *name, const char *mode)
|
||||||
|
//
|
||||||
|
// Purpose: Substitute for fopen_s on platforms where it doesn't exist
|
||||||
|
// Note: fopen_s is part of C++11 standard
|
||||||
|
//
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
ret = (int)fopen_s(f, name, mode);
|
||||||
|
#else
|
||||||
|
*f = fopen(name, mode);
|
||||||
|
if (!*f)
|
||||||
|
ret = -1;
|
||||||
|
#endif
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int _get_temp_filename(char **tempname)
|
||||||
|
{
|
||||||
|
int error = 0;
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
char *name = NULL;
|
||||||
|
|
||||||
|
// --- use Windows _tempnam function to get a pointer to an
|
||||||
|
// unused file name that begins with "en"
|
||||||
|
if ((name = _tempnam(name, "en")) == NULL) {
|
||||||
|
error = -1;
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
copy_cstr(name, tempname);
|
||||||
|
|
||||||
|
// --- free the pointer returned by _tempnam
|
||||||
|
if (name)
|
||||||
|
free(name);
|
||||||
|
|
||||||
|
// --- for non-Windows systems:
|
||||||
|
#else
|
||||||
|
// --- use system function mkstemp() to create a temporary file name
|
||||||
|
copy_cstr("enXXXXXX", tempname);
|
||||||
|
error = mkstemp(*tempname);
|
||||||
|
#endif
|
||||||
|
return error;
|
||||||
|
}
|
||||||
81
src/util/filemanager.h
Normal file
81
src/util/filemanager.h
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
******************************************************************************
|
||||||
|
Project: OWA EPANET
|
||||||
|
Version: 2.2
|
||||||
|
Module: util/filemanager.h
|
||||||
|
Description: Provides a simple interface for managing files
|
||||||
|
Authors: see AUTHORS
|
||||||
|
Copyright: see AUTHORS
|
||||||
|
License: see LICENSE
|
||||||
|
Last Updated: 04/01/2019
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef FILEMANAGER_H_
|
||||||
|
#define FILEMANAGER_H_
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
#include "cstr_helper.h"
|
||||||
|
|
||||||
|
|
||||||
|
// F_OFF Must be a 8 byte / 64 bit integer for large file support
|
||||||
|
#ifdef _MSC_VER // Windows (32-bit and 64-bit)
|
||||||
|
#define F_OFF __int64
|
||||||
|
#else // Other platforms
|
||||||
|
#define F_OFF off_t
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define FILE_MAXNAME 259
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Forward declariation of file_handle_t
|
||||||
|
typedef struct file_s file_handle_t;
|
||||||
|
|
||||||
|
|
||||||
|
file_handle_t *create_file_manager();
|
||||||
|
|
||||||
|
void delete_file_manager(file_handle_t *file_handle);
|
||||||
|
|
||||||
|
|
||||||
|
int get_filename(file_handle_t *file_handle, char **filename);
|
||||||
|
|
||||||
|
|
||||||
|
int open_file(file_handle_t *file_handle, const char *filename, const char *file_mode);
|
||||||
|
|
||||||
|
int seek_file(file_handle_t *file_handle, F_OFF offset, int whence);
|
||||||
|
|
||||||
|
F_OFF tell_file(file_handle_t *file_handle);
|
||||||
|
|
||||||
|
|
||||||
|
// Functions for working with binary files
|
||||||
|
size_t read_file(void *ptr, size_t size, size_t nmemb, file_handle_t *file_handle);
|
||||||
|
|
||||||
|
size_t write_file(const void *ptr, size_t size, size_t count, file_handle_t *file_handle);
|
||||||
|
|
||||||
|
|
||||||
|
// Functions for working with text files
|
||||||
|
int printf_file(file_handle_t *file_handle, const char *format, ... );
|
||||||
|
|
||||||
|
int gets_file(char *str, int num, file_handle_t *file_handle);
|
||||||
|
|
||||||
|
|
||||||
|
int close_file(file_handle_t *file_handle);
|
||||||
|
|
||||||
|
int remove_file(file_handle_t *file_handle);
|
||||||
|
|
||||||
|
|
||||||
|
bool is_valid(file_handle_t *file_handle);
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* FILEMANAGER_H_ */
|
||||||
@@ -19,19 +19,18 @@ endif(UNIX)
|
|||||||
set(toolkit_test_srcs
|
set(toolkit_test_srcs
|
||||||
test_toolkit.cpp
|
test_toolkit.cpp
|
||||||
test_project.cpp
|
test_project.cpp
|
||||||
# test_hydraulics.cpp
|
test_hydraulics.cpp
|
||||||
# test_quality.cpp
|
test_quality.cpp
|
||||||
# test_report.cpp
|
test_report.cpp
|
||||||
# test_analysis.cpp
|
test_analysis.cpp
|
||||||
# test_node.cpp
|
test_node.cpp
|
||||||
# test_demand.cpp
|
test_demand.cpp
|
||||||
# test_link.cpp
|
test_link.cpp
|
||||||
# test_pump.cpp
|
# test_pump.cpp
|
||||||
# test_pattern.cpp
|
test_pattern.cpp
|
||||||
# test_curve.cpp
|
test_curve.cpp
|
||||||
# test_control.cpp
|
test_control.cpp
|
||||||
# test_net_builder.cpp
|
test_net_builder.cpp)
|
||||||
)
|
|
||||||
|
|
||||||
add_executable(test_toolkit ${toolkit_test_srcs})
|
add_executable(test_toolkit ${toolkit_test_srcs})
|
||||||
|
|
||||||
@@ -60,6 +59,10 @@ add_test(NAME test_reent
|
|||||||
add_test(NAME test_errormanager
|
add_test(NAME test_errormanager
|
||||||
COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test_errormanager)
|
COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test_errormanager)
|
||||||
|
|
||||||
|
add_test(NAME test_filemanager
|
||||||
|
COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test_filemanager
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/outfile/data)
|
||||||
|
|
||||||
add_test(NAME test_output
|
add_test(NAME test_output
|
||||||
COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test_output
|
COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test_output
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/outfile/data)
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/outfile/data)
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
//#define BOOST_ALL_DYN_LINK
|
||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
#include "test_toolkit.hpp"
|
#include "test_toolkit.hpp"
|
||||||
|
|||||||
@@ -35,6 +35,35 @@ BOOST_FIXTURE_TEST_CASE(test_curve_comments, FixtureOpenClose)
|
|||||||
error = EN_getcomment(ph, EN_CURVE, index, comment);
|
error = EN_getcomment(ph, EN_CURVE, index, comment);
|
||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
BOOST_CHECK(check_string(comment, (char *)"Curve 1"));
|
BOOST_CHECK(check_string(comment, (char *)"Curve 1"));
|
||||||
|
|
||||||
|
// Test of EN_setcurve and EN_getcurve
|
||||||
|
int i;
|
||||||
|
char id1[] = "NewCurve";
|
||||||
|
int n1 = 5;
|
||||||
|
double X1[] = {16.88889, 19.5, 22.13889, 25.94445, 33.33334};
|
||||||
|
double Y1[] = {156.7, 146.5, 136.2, 117.9, 50.0};
|
||||||
|
int n2;
|
||||||
|
double X2[5], Y2[5];
|
||||||
|
char id2[EN_MAXID+1];
|
||||||
|
|
||||||
|
// Add data to a new curve
|
||||||
|
error = EN_addcurve(ph, id1);
|
||||||
|
BOOST_REQUIRE(error == 0);
|
||||||
|
error = EN_getcurveindex(ph, id1, &i);
|
||||||
|
BOOST_REQUIRE(error == 0);
|
||||||
|
error = EN_setcurve(ph, i, X1, Y1, n1);
|
||||||
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
|
// Retrieve data from curve
|
||||||
|
error = EN_getcurve(ph, i, id2, &n2, X2, Y2);
|
||||||
|
BOOST_REQUIRE(error == 0);
|
||||||
|
BOOST_CHECK(check_string(id2, id1));
|
||||||
|
BOOST_REQUIRE(n2 == n1);
|
||||||
|
for (i = 0; i < n1; i++)
|
||||||
|
{
|
||||||
|
BOOST_REQUIRE(X1[i] == X2[i]);
|
||||||
|
BOOST_REQUIRE(Y1[i] == Y2[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
|||||||
@@ -11,6 +11,8 @@
|
|||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
#include "test_toolkit.hpp"
|
#include "test_toolkit.hpp"
|
||||||
|
|||||||
@@ -58,47 +58,35 @@ BOOST_AUTO_TEST_CASE(test_save)
|
|||||||
{
|
{
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
EN_Project ph = NULL;
|
EN_Project ph_save;
|
||||||
|
|
||||||
error = EN_createproject(&ph);
|
EN_createproject(&ph_save);
|
||||||
|
error = EN_open(ph_save, DATA_PATH_NET1, DATA_PATH_RPT, DATA_PATH_OUT);
|
||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
error = EN_open(ph, DATA_PATH_NET1, DATA_PATH_RPT, DATA_PATH_OUT);
|
error = EN_saveinpfile(ph_save, "test_reopen.inp");
|
||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
error = EN_saveinpfile(ph, DATA_PATH_TMP);
|
BOOST_CHECK(boost::filesystem::exists("test_reopen.inp") == true);
|
||||||
|
|
||||||
|
error = EN_close(ph_save);
|
||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
|
EN_deleteproject(&ph_save);
|
||||||
BOOST_CHECK(boost::filesystem::exists(DATA_PATH_TMP) == true);
|
|
||||||
|
|
||||||
error = EN_close(ph);
|
|
||||||
BOOST_REQUIRE(error == 0);
|
|
||||||
|
|
||||||
error = EN_deleteproject(&ph);
|
|
||||||
BOOST_REQUIRE(error == 0);
|
|
||||||
|
|
||||||
BOOST_CHECK(ph == NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(test_reopen, * boost::unit_test::depends_on("test_project/test_save"))
|
BOOST_AUTO_TEST_CASE(test_reopen, * boost::unit_test::depends_on("test_project/test_save"))
|
||||||
{
|
{
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
EN_Project ph = NULL;
|
EN_Project ph_reopen;
|
||||||
|
|
||||||
error = EN_createproject(&ph);
|
EN_createproject(&ph_reopen);
|
||||||
|
error = EN_open(ph_reopen, "test_reopen.inp", DATA_PATH_RPT, DATA_PATH_OUT);
|
||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
error = EN_open(ph, DATA_PATH_TMP, DATA_PATH_RPT, DATA_PATH_OUT);
|
error = EN_close(ph_reopen);
|
||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
|
EN_deleteproject(&ph_reopen);
|
||||||
error = EN_close(ph);
|
|
||||||
BOOST_REQUIRE(error == 0);
|
|
||||||
|
|
||||||
EN_deleteproject(&ph);
|
|
||||||
BOOST_REQUIRE(error == 0);
|
|
||||||
|
|
||||||
BOOST_CHECK(ph == NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(test_run)
|
BOOST_AUTO_TEST_CASE(test_run)
|
||||||
|
|||||||
@@ -14,12 +14,6 @@
|
|||||||
#ifndef TEST_TOOLKIT_HPP
|
#ifndef TEST_TOOLKIT_HPP
|
||||||
#define TEST_TOOLKIT_HPP
|
#define TEST_TOOLKIT_HPP
|
||||||
|
|
||||||
// MSVC ONLY
|
|
||||||
#ifdef _DEBUG
|
|
||||||
#define _CRTDBG_MAP_ALLOC
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <crtdbg.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "epanet2_2.h"
|
#include "epanet2_2.h"
|
||||||
|
|
||||||
|
|||||||
@@ -7,11 +7,14 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
|
|||||||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
|
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
|
||||||
|
|
||||||
|
|
||||||
set (test_source
|
add_executable(test_errormanager ./test_errormanager.cpp
|
||||||
./test_errormanager.cpp
|
../../src/util/errormanager.c)
|
||||||
../../src/util/errormanager.c
|
|
||||||
)
|
|
||||||
|
|
||||||
add_executable(test_errormanager ${test_source})
|
|
||||||
target_include_directories(test_errormanager PUBLIC ../../src/)
|
target_include_directories(test_errormanager PUBLIC ../../src/)
|
||||||
target_link_libraries(test_errormanager ${Boost_LIBRARIES})
|
target_link_libraries(test_errormanager ${Boost_LIBRARIES})
|
||||||
|
|
||||||
|
|
||||||
|
add_executable(test_filemanager ./test_filemanager.cpp
|
||||||
|
../../src/util/filemanager.c
|
||||||
|
../../src/util/cstr_helper.c)
|
||||||
|
target_include_directories(test_filemanager PUBLIC ../../src/)
|
||||||
|
target_link_libraries(test_filemanager ${Boost_LIBRARIES})
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#define BOOST_TEST_MODULE errormanager
|
#define BOOST_TEST_MODULE errormanager
|
||||||
//#define BOOST_TEST_DYN_LINK
|
|
||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
#include "util/errormanager.h"
|
#include "util/errormanager.h"
|
||||||
@@ -15,10 +15,10 @@ void mock_lookup(int errcode, char *errmsg, int len)
|
|||||||
char *msg = NULL;
|
char *msg = NULL;
|
||||||
|
|
||||||
if (errcode == 100) {
|
if (errcode == 100) {
|
||||||
msg = MESSAGE_STRING;
|
msg = (char *)MESSAGE_STRING;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
msg = "";
|
msg = (char *)"";
|
||||||
}
|
}
|
||||||
strncpy(errmsg, msg, len);
|
strncpy(errmsg, msg, len);
|
||||||
}
|
}
|
||||||
|
|||||||
97
tests/util/test_filemanager.cpp
Normal file
97
tests/util/test_filemanager.cpp
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
/*
|
||||||
|
******************************************************************************
|
||||||
|
Project: OWA EPANET
|
||||||
|
Version: 2.2
|
||||||
|
Module: util/test_filemanager.cpp
|
||||||
|
Description: Tests for util/filemanager.c
|
||||||
|
Authors: see AUTHORS
|
||||||
|
Copyright: see AUTHORS
|
||||||
|
License: see LICENSE
|
||||||
|
Last Updated: 04/01/2019
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define BOOST_TEST_MODULE filemanager
|
||||||
|
|
||||||
|
#include <boost/test/unit_test.hpp>
|
||||||
|
#include <boost/filesystem.hpp>
|
||||||
|
|
||||||
|
#include "util/filemanager.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define DATA_PATH_OUTPUT "./example1.out"
|
||||||
|
|
||||||
|
|
||||||
|
boost::test_tools::predicate_result check_string(std::string test, std::string ref)
|
||||||
|
{
|
||||||
|
if (ref.compare(test) == 0)
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_SUITE(test_filemanager)
|
||||||
|
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE (test_create_destroy)
|
||||||
|
{
|
||||||
|
file_handle_t *file_handle = NULL;
|
||||||
|
|
||||||
|
file_handle = create_file_manager();
|
||||||
|
BOOST_CHECK(file_handle != NULL);
|
||||||
|
BOOST_CHECK(is_valid(file_handle) == true);
|
||||||
|
|
||||||
|
delete_file_manager(file_handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(test_open_close)
|
||||||
|
{
|
||||||
|
int error = 0;
|
||||||
|
file_handle_t *file_handle = NULL;
|
||||||
|
|
||||||
|
file_handle = create_file_manager();
|
||||||
|
BOOST_CHECK(file_handle != NULL);
|
||||||
|
|
||||||
|
error = open_file(file_handle, DATA_PATH_OUTPUT, "rb");
|
||||||
|
BOOST_REQUIRE(error == 0);
|
||||||
|
BOOST_CHECK(is_valid(file_handle) == true);
|
||||||
|
|
||||||
|
error = close_file(file_handle);
|
||||||
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
|
delete_file_manager(file_handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Fixture{
|
||||||
|
Fixture() {
|
||||||
|
error = 0;
|
||||||
|
file_handle = NULL;
|
||||||
|
|
||||||
|
file_handle = create_file_manager();
|
||||||
|
open_file(file_handle, NULL, "wt");
|
||||||
|
}
|
||||||
|
~Fixture() {
|
||||||
|
close_file(file_handle);
|
||||||
|
delete_file_manager(file_handle);
|
||||||
|
}
|
||||||
|
int error;
|
||||||
|
file_handle_t *file_handle;
|
||||||
|
};
|
||||||
|
|
||||||
|
BOOST_FIXTURE_TEST_CASE(test_temp_file, Fixture)
|
||||||
|
{
|
||||||
|
char *filename;
|
||||||
|
|
||||||
|
printf_file(file_handle, "%s", "This is a test.");
|
||||||
|
|
||||||
|
error = get_filename(file_handle, &filename);
|
||||||
|
BOOST_REQUIRE(error == 0);
|
||||||
|
BOOST_CHECK(is_valid(file_handle) == true);
|
||||||
|
|
||||||
|
BOOST_CHECK(boost::filesystem::exists(filename) == true);
|
||||||
|
|
||||||
|
free(filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
Reference in New Issue
Block a user