Cleaning up include statements

Removing inclusion of malloc.h. Adding crtdbg.h
This commit is contained in:
Michael Tryby
2019-03-28 09:26:26 -04:00
parent 8574f52256
commit 1b167b5caf
28 changed files with 164 additions and 169 deletions

View File

@@ -12,6 +12,7 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include "epanet2.h" #include "epanet2.h"
void writeConsole(char *s) void writeConsole(char *s)

View File

@@ -11,12 +11,17 @@
****************************************************************************** ******************************************************************************
*/ */
#include <stdio.h> #ifdef _DEBUG
#include <stdlib.h> #define _CRTDBG_MAP_ALLOC
#include <string.h> #include <stdlib.h>
#ifndef __APPLE__ #include <crtdbg.h>
#include <malloc.h> #else
#include <stdlib.h>
#endif #endif
#include <stdio.h>
#include <string.h>
#include <float.h> #include <float.h>
#include <math.h> #include <math.h>
@@ -216,26 +221,24 @@ 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));
// Read input data if (!errcode) {
ERRCODE(getdata(p)); // Read input data
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;
} }
// Free temporary linked lists used for Patterns & Curves // Free temporary linked lists used for Patterns & Curves
freeTmplist(p->parser.Patlist); freeTmplist(p->parser.Patlist);
freeTmplist(p->parser.Curvelist); freeTmplist(p->parser.Curvelist);
// If using previously saved hydraulics file then open it // If using previously saved hydraulics file then open it
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;
@@ -279,7 +282,7 @@ int DLLEXPORT EN_getcomment(EN_Project p, int object, int index, char *comment)
/*---------------------------------------------------------------- /*----------------------------------------------------------------
** Input: object = a type of object (see EN_ObjectType) ** Input: object = a type of object (see EN_ObjectType)
** index = the object's index ** index = the object's index
** Output: comment = the object's descriptive comment ** Output: comment = the object's descriptive comment
** Returns: error code ** Returns: error code
** Purpose: Retrieves an object's descriptive comment ** Purpose: Retrieves an object's descriptive comment
**---------------------------------------------------------------- **----------------------------------------------------------------
@@ -840,7 +843,7 @@ int DLLEXPORT EN_closeQ(EN_Project p)
if (!p->Openflag) return 102; if (!p->Openflag) return 102;
closequal(p); closequal(p);
p->quality.OpenQflag = FALSE; p->quality.OpenQflag = FALSE;
closeoutfile(p); closeoutfile(p);
return 0; return 0;
} }

View File

@@ -10,11 +10,15 @@
Last Updated: 03/17/2019 Last Updated: 03/17/2019
****************************************************************************** ******************************************************************************
*/ */
#ifndef __APPLE__
#include <malloc.h> #ifdef _DEBUG
#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"

View File

@@ -26,6 +26,7 @@ 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

View File

@@ -11,12 +11,9 @@
****************************************************************************** ******************************************************************************
*/ */
#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

View File

@@ -11,13 +11,9 @@
****************************************************************************** ******************************************************************************
*/ */
#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"

View File

@@ -11,13 +11,9 @@
****************************************************************************** ******************************************************************************
*/ */
#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"

View File

@@ -12,13 +12,9 @@
****************************************************************************** ******************************************************************************
*/ */
#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"

View File

@@ -12,6 +12,7 @@ Last Updated: 11/27/2018
*/ */
#include <stdio.h> #include <stdio.h>
#include "types.h" #include "types.h"
#include "funcs.h" #include "funcs.h"

View File

@@ -13,11 +13,7 @@ Last Updated: 03/17/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"

View File

@@ -3,26 +3,30 @@
Project: OWA EPANET Project: OWA EPANET
Version: 2.2 Version: 2.2
Module: input1.c Module: input1.c
Description: retrieves network data from an EPANET input file Description: retrieves 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: 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 <math.h>
#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
@@ -56,7 +60,7 @@ int getdata(Project *pr)
int errcode = 0; int errcode = 0;
// Assign default data values & reporting options // Assign default data values & reporting options
setdefaults(pr); setdefaults(pr);
initreport(&pr->report); initreport(&pr->report);
// Read in network data // Read in network data
@@ -102,7 +106,7 @@ void setdefaults(Project *pr)
parser->Pressflag = PSI; // Pressure units are psi parser->Pressflag = PSI; // Pressure units are psi
out->Hydflag = SCRATCH; // No external hydraulics file out->Hydflag = SCRATCH; // No external hydraulics file
rpt->Tstatflag = SERIES; // Generate time series output rpt->Tstatflag = SERIES; // Generate time series output
hyd->Formflag = HW; // Use Hazen-Williams formula hyd->Formflag = HW; // Use Hazen-Williams formula
hyd->Htol = HTOL; // Default head tolerance hyd->Htol = HTOL; // Default head tolerance
hyd->Qtol = QTOL; // Default flow tolerance hyd->Qtol = QTOL; // Default flow tolerance
@@ -353,7 +357,7 @@ int inittanks(Project *pr)
*/ */
{ {
Network *net = &pr->network; Network *net = &pr->network;
int i, j, n = 0; int i, j, n = 0;
double a; double a;
int errcode = 0, levelerr; int errcode = 0, levelerr;
@@ -546,7 +550,7 @@ void convertunits(Project *pr)
Slink *link; Slink *link;
Spump *pump; Spump *pump;
Scontrol *control; Scontrol *control;
// Convert nodal elevations & initial WQ // Convert nodal elevations & initial WQ
// (WQ source units are converted in QUALITY.C // (WQ source units are converted in QUALITY.C
for (i = 1; i <= net->Nnodes; i++) for (i = 1; i <= net->Nnodes; i++)
@@ -644,7 +648,7 @@ void convertunits(Project *pr)
pump->H0 /= pr->Ucf[HEAD]; pump->H0 /= pr->Ucf[HEAD];
pump->R *= (pow(pr->Ucf[FLOW], pump->N) / pr->Ucf[HEAD]); pump->R *= (pow(pr->Ucf[FLOW], pump->N) / pr->Ucf[HEAD]);
} }
// Convert flow range & max. head units // Convert flow range & max. head units
pump->Q0 /= pr->Ucf[FLOW]; pump->Q0 /= pr->Ucf[FLOW];
pump->Qmax /= pr->Ucf[FLOW]; pump->Qmax /= pr->Ucf[FLOW];
@@ -653,7 +657,7 @@ void convertunits(Project *pr)
} }
else else
{ {
// For flow control valves, convert flow setting // For flow control valves, convert flow setting
// while for other valves convert pressure setting // while for other valves convert pressure setting
link->Diam /= pr->Ucf[DIAM]; link->Diam /= pr->Ucf[DIAM];
link->Km = 0.02517 * link->Km / SQR(link->Diam) / SQR(link->Diam); link->Km = 0.02517 * link->Km / SQR(link->Diam) / SQR(link->Diam);

View File

@@ -10,13 +10,16 @@ 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"
@@ -56,7 +59,7 @@ int netsize(Project *pr)
*/ */
{ {
Parser *parser = &pr->parser; Parser *parser = &pr->parser;
char line[MAXLINE + 1]; // Line from input data file char line[MAXLINE + 1]; // Line from input data file
char *tok; // First token of line char *tok; // First token of line
int sect, newsect; // Input data sections int sect, newsect; // Input data sections
@@ -147,7 +150,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, sizeof(double)); parser->X = (double *)calloc(MAXTOKS + 1, sizeof(double));
ERRCODE(MEMCHECK(parser->X)); ERRCODE(MEMCHECK(parser->X));
if (errcode) return errcode; if (errcode) return errcode;
@@ -175,7 +178,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
strcpy(wline, line); strncpy(wline, line, MAXLINE);
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
@@ -246,10 +249,10 @@ int readdata(Project *pr)
// Stop if reach end of file or max. error count // Stop if reach end of file or max. error count
if (errsum == MAXERRS) break; if (errsum == MAXERRS) break;
} }
// Check for errors // Check for errors
if (errsum > 0) errcode = 200; if (errsum > 0) errcode = 200;
// Check for unlinked nodes // Check for unlinked nodes
if (!errcode) errcode = unlinked(pr); if (!errcode) errcode = unlinked(pr);
@@ -397,7 +400,7 @@ int updatepumpparams(Project *pr, int pumpindex)
curve->Type = PUMP_CURVE; curve->Type = PUMP_CURVE;
npts = curve->Npts; npts = curve->Npts;
// Generic power function curve // Generic power function curve
if (npts == 1) if (npts == 1)
{ {
pump->Ptype = POWER_FUNC; pump->Ptype = POWER_FUNC;
@@ -407,7 +410,7 @@ int updatepumpparams(Project *pr, int pumpindex)
q2 = 2.0 * q1; q2 = 2.0 * q1;
h2 = 0.0; h2 = 0.0;
} }
// 3 point curve with shutoff head // 3 point curve with shutoff head
else if (npts == 3 && curve->X[0] == 0.0) else if (npts == 3 && curve->X[0] == 0.0)
{ {
@@ -418,7 +421,7 @@ int updatepumpparams(Project *pr, int pumpindex)
q2 = curve->X[2]; q2 = curve->X[2];
h2 = curve->Y[2]; h2 = curve->Y[2];
} }
// Custom pump curve // Custom pump curve
else else
{ {
@@ -431,7 +434,7 @@ int updatepumpparams(Project *pr, int pumpindex)
pump->Q0 = (curve->X[0] + pump->Qmax) / 2.0; pump->Q0 = (curve->X[0] + pump->Qmax) / 2.0;
pump->Hmax = curve->Y[0]; pump->Hmax = curve->Y[0];
} }
// Compute shape factors & limits of power function curves // Compute shape factors & limits of power function curves
if (pump->Ptype == POWER_FUNC) if (pump->Ptype == POWER_FUNC)
{ {
@@ -461,7 +464,7 @@ int addnodeID(Network *net, int n, char *id)
**-------------------------------------------------------------- **--------------------------------------------------------------
*/ */
{ {
if (findnode(net,id)) return 0; if (findnode(net,id)) return 0;
strncpy(net->Node[n].ID, id, MAXID); strncpy(net->Node[n].ID, id, MAXID);
hashtable_insert(net->NodeHashTable, net->Node[n].ID, n); hashtable_insert(net->NodeHashTable, net->Node[n].ID, n);
return 1; return 1;
@@ -587,7 +590,7 @@ int unlinked(Project *pr)
Network *net = &pr->network; Network *net = &pr->network;
int *marked; int *marked;
int i, err, errcode; int i, err, errcode;
errcode = 0; errcode = 0;
err = 0; err = 0;
@@ -596,19 +599,19 @@ int unlinked(Project *pr)
ERRCODE(MEMCHECK(marked)); ERRCODE(MEMCHECK(marked));
if (errcode) return errcode; if (errcode) return errcode;
memset(marked, 0, (net->Nnodes + 1) * sizeof(int)); memset(marked, 0, (net->Nnodes + 1) * sizeof(int));
// Mark end nodes of each link // Mark end nodes of each link
for (i = 1; i <= net->Nlinks; i++) for (i = 1; i <= net->Nlinks; i++)
{ {
marked[net->Link[i].N1]++; marked[net->Link[i].N1]++;
marked[net->Link[i].N2]++; marked[net->Link[i].N2]++;
} }
// Check each junction // Check each junction
for (i = 1; i <= net->Njuncs; i++) for (i = 1; i <= net->Njuncs; i++)
{ {
// If not marked then error // If not marked then error
if (marked[i] == 0) if (marked[i] == 0)
{ {
err++; err++;
sprintf(pr->Msg, "Error 233: %s %s", geterrmsg(233, pr->Msg), net->Node[i].ID); sprintf(pr->Msg, "Error 233: %s %s", geterrmsg(233, pr->Msg), net->Node[i].ID);
@@ -638,7 +641,7 @@ int getpatterns(Project *pr)
SFloatlist *f; SFloatlist *f;
STmplist *tmppattern; STmplist *tmppattern;
Spattern *pattern; Spattern *pattern;
// Start at head of the list of patterns // Start at head of the list of patterns
tmppattern = parser->Patlist; tmppattern = parser->Patlist;
@@ -696,7 +699,7 @@ int getcurves(Project *pr)
{ {
Network *net = &pr->network; Network *net = &pr->network;
Parser *parser = &pr->parser; Parser *parser = &pr->parser;
int i, j; int i, j;
double x; double x;
char errmsg[MAXMSG+1]; char errmsg[MAXMSG+1];
@@ -827,14 +830,14 @@ int gettokens(char *s, char** Tok, int maxToks, char *comment)
int m, n; int m, n;
size_t len; size_t len;
char *c, *c2; char *c, *c2;
// clear comment // clear comment
comment[0] = '\0'; comment[0] = '\0';
// Begin with no tokens // Begin with no tokens
for (n=0; n<maxToks; n++) Tok[n] = NULL; for (n=0; n<maxToks; n++) Tok[n] = NULL;
n = 0; n = 0;
// Truncate s at start of comment // Truncate s at start of comment
c = strchr(s,';'); c = strchr(s,';');
if (c) if (c)
@@ -855,7 +858,7 @@ int gettokens(char *s, char** Tok, int maxToks, char *comment)
*c = '\0'; *c = '\0';
} }
len = (int)strlen(s); len = (int)strlen(s);
// Scan s for tokens until nothing left // Scan s for tokens until nothing left
while (len > 0 && n < MAXTOKS) while (len > 0 && n < MAXTOKS)
{ {
@@ -868,7 +871,7 @@ int gettokens(char *s, char** Tok, int maxToks, char *comment)
{ {
s++; // Start token after quote s++; // Start token after quote
m = (int)strcspn(s,"\"\n\r"); // Find end quote (or EOL) m = (int)strcspn(s,"\"\n\r"); // Find end quote (or EOL)
} }
s[m] = '\0'; // Null-terminate the token s[m] = '\0'; // Null-terminate the token
Tok[n] = s; // Save pointer to token Tok[n] = s; // Save pointer to token
n++; // Update token count n++; // Update token count
@@ -876,7 +879,7 @@ int gettokens(char *s, char** Tok, int maxToks, char *comment)
} }
} }
return n; return n;
} }
double hour(char *time, char *units) double hour(char *time, char *units)
/* /*
@@ -914,7 +917,7 @@ double hour(char *time, char *units)
if (match(units, w_DAYS)) return (y[0] * 24.0); if (match(units, w_DAYS)) return (y[0] * 24.0);
} }
// Convert hh:mm:ss format to decimal hours // Convert hh:mm:ss format to decimal hours
if (n > 1) y[0] = y[0] + y[1] / 60.0 + y[2] / 3600.0; if (n > 1) y[0] = y[0] + y[1] / 60.0 + y[2] / 3600.0;
// If am/pm attached then adjust hour accordingly // If am/pm attached then adjust hour accordingly
@@ -933,7 +936,7 @@ double hour(char *time, char *units)
else return (y[0] + 12.0); else return (y[0] + 12.0);
} }
return -1.0; return -1.0;
} }
int getfloat(char *s, double *y) int getfloat(char *s, double *y)
/* /*
@@ -979,14 +982,14 @@ void inperrmsg(Project *pr, int err, int sect, char *line)
*/ */
{ {
Parser *parser = &pr->parser; Parser *parser = &pr->parser;
char errStr[MAXMSG + 1] = ""; char errStr[MAXMSG + 1] = "";
char tok[MAXMSG + 1]; char tok[MAXMSG + 1];
// Get token associated with input error // Get token associated with input error
if (parser->ErrTok >= 0) strcpy(tok, parser->Tok[parser->ErrTok]); if (parser->ErrTok >= 0) strcpy(tok, parser->Tok[parser->ErrTok]);
else strcpy(tok, ""); else strcpy(tok, "");
// write error message to report file // write error message to report file
sprintf(pr->Msg, "Error %d: %s %s in %s section:", sprintf(pr->Msg, "Error %d: %s %s in %s section:",
err, geterrmsg(err, errStr), tok, SectTxt[sect]); err, geterrmsg(err, errStr), tok, SectTxt[sect]);

View File

@@ -10,13 +10,16 @@ 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"

View File

@@ -15,9 +15,7 @@
*/ */
#include <stdlib.h> #include <stdlib.h>
#ifndef __APPLE__
#include <malloc.h>
#endif
#include "mempool.h" #include "mempool.h"
/* /*

View File

@@ -11,13 +11,9 @@ 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"

View File

@@ -11,14 +11,18 @@
****************************************************************************** ******************************************************************************
*/ */
#include <stdio.h> #ifdef _DEBUG
#include <string.h> #define _CRTDBG_MAP_ALLOC
#ifndef __APPLE__ #include <stdlib.h>
#include <malloc.h> #include <crtdbg.h>
#else #else
#include <stdlib.h> #include <stdlib.h>
#endif #endif
#include <stdio.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>

View File

@@ -11,13 +11,9 @@ 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"

View File

@@ -13,6 +13,7 @@ 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

View File

@@ -11,13 +11,10 @@ Last Updated: 11/27/2018
****************************************************************************** ******************************************************************************
*/ */
#include <stdio.h>
#ifndef __APPLE__
#include <malloc.h>
#else
#include <stdlib.h> #include <stdlib.h>
#endif #include <stdio.h>
#include <math.h> #include <math.h>
#include "mempool.h" #include "mempool.h"
#include "types.h" #include "types.h"

View File

@@ -11,13 +11,10 @@
****************************************************************************** ******************************************************************************
*/ */
#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

View File

@@ -11,13 +11,9 @@
****************************************************************************** ******************************************************************************
*/ */
#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"

View File

@@ -18,16 +18,11 @@
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"

View File

@@ -14,9 +14,11 @@
#ifndef TYPES_H #ifndef TYPES_H
#define TYPES_H #define TYPES_H
#include "hash.h"
#include <stdio.h> #include <stdio.h>
#include "hash.h"
/* /*
------------------------------------------- -------------------------------------------
Definition of 4-byte integers & reals Definition of 4-byte integers & reals

View File

@@ -10,13 +10,7 @@
// US EPA - ORD/NRMRL // US EPA - ORD/NRMRL
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
//#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"

View File

@@ -19,18 +19,19 @@ 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})

View File

@@ -11,7 +11,6 @@
****************************************************************************** ******************************************************************************
*/ */
//#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"

View File

@@ -56,35 +56,47 @@ BOOST_AUTO_TEST_CASE(test_save)
{ {
int error; int error;
EN_Project ph_save; EN_Project ph = NULL;
EN_createproject(&ph_save); error = EN_createproject(&ph);
error = EN_open(ph_save, DATA_PATH_NET1, DATA_PATH_RPT, DATA_PATH_OUT);
BOOST_REQUIRE(error == 0);
error = EN_saveinpfile(ph_save, "test_reopen.inp");
BOOST_REQUIRE(error == 0);
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);
error = EN_open(ph, DATA_PATH_NET1, DATA_PATH_RPT, DATA_PATH_OUT);
BOOST_REQUIRE(error == 0);
error = EN_saveinpfile(ph, DATA_PATH_TMP);
BOOST_REQUIRE(error == 0);
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_reopen; EN_Project ph = NULL;
EN_createproject(&ph_reopen); error = EN_createproject(&ph);
error = EN_open(ph_reopen, "test_reopen.inp", DATA_PATH_RPT, DATA_PATH_OUT); BOOST_REQUIRE(error == 0);
BOOST_REQUIRE(error == 0);
error = EN_close(ph_reopen); error = EN_open(ph, DATA_PATH_TMP, DATA_PATH_RPT, DATA_PATH_OUT);
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)

View File

@@ -14,6 +14,12 @@
#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"