Skip to content

Commit

Permalink
Expand API to return error code and support unit testing #162
Browse files Browse the repository at this point in the history
  • Loading branch information
cbuahin committed Feb 16, 2024
1 parent e1f906e commit 58e330b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/solver/consts.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
// General Constants
//------------------

#define VERSION 52004
#define VERSION 53000
#define MAGICNUMBER 516114522
#define EOFMARK 0x1A // Use 0x04 for UNIX systems
#define MAXTITLE 3 // Max. # title lines
Expand Down
2 changes: 1 addition & 1 deletion src/solver/include/swmm5.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ int DLLEXPORT swmm_getErrorFromCode(int error_code, char **outErrMsg);
int DLLEXPORT swmm_getWarnings(void);

int DLLEXPORT swmm_getCount(int objType);
void DLLEXPORT swmm_getName(int objType, int index, char *name, int size);
int DLLEXPORT swmm_getName(int objType, int index, char *name, int size);
int DLLEXPORT swmm_getIndex(int objType, const char *name);
double DLLEXPORT swmm_getValue(int property, int index);
int DLLEXPORT swmm_setValue(int property, int index, double value);
Expand Down
2 changes: 1 addition & 1 deletion src/solver/project.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ char *project_findID(int type, char *id)

//=============================================================================

double ** project_createMatrix(int nrows, int ncols)
double **project_createMatrix(int nrows, int ncols)
//
// Input: nrows = number of rows (0-based)
// ncols = number of columns (0-based)
Expand Down
34 changes: 19 additions & 15 deletions src/solver/swmm5.c
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,6 @@ int DLLEXPORT swmm_useHotStart(const char* hotStartFile)
FhotstartInput.mode = USE_FILE;
sstrncpy(FhotstartInput.name, addAbsolutePath(fname), MAXFNAME);


return error_code;
}

Expand All @@ -574,7 +573,6 @@ int DLLEXPORT swmm_saveHotStart(const char* hotStartFile)
else if (!IsStartedFlag)
return (ErrorCode = ERR_API_NOT_STARTED);


error_code = hotstart_save_to_file(hotStartFile);

return error_code;
Expand Down Expand Up @@ -863,42 +861,42 @@ int DLLEXPORT swmm_getErrorFromCode(int error_code, char **outErrMsg)
return 0;
}


//=============================================================================

int DLLEXPORT swmm_getCount(int objType)
//
// Input: objType = a type of SWMM object
// Output: returns the number of objects;
// Output: returns the number of objects or error code;
// Purpose: retrieves the number of objects of a specific type.
{
if (!IsOpenFlag)
return 0;
return ERR_API_NOT_OPEN;
if (objType < swmm_GAGE || objType > swmm_LINK)
return 0;
return ERR_API_OBJECT_TYPE;
return Nobjects[objType];
}

//=============================================================================

void DLLEXPORT swmm_getName(int objType, int index, char *name, int size)
int DLLEXPORT swmm_getName(int objType, int index, char *name, int size)
//
// Input: objType = a type of SWMM object
// index = the object's index in the array of objects
// name = a character array
// size = size of the name array
// Output: name = the object's ID name;
// Output: name = the object's ID name;
// error code
// Purpose: retrieves the ID name of an object.
{
char *idName = NULL;

name[0] = '\0';
if (!IsOpenFlag)
return;
return ERR_API_NOT_OPEN;
if (objType < swmm_GAGE || objType > swmm_LINK)
return;
return ERR_API_OBJECT_TYPE;
if (index < 0 || index >= Nobjects[objType])
return;
return ERR_API_OBJECT_INDEX;
switch (objType)
{
case GAGE: idName = Gage[index].ID; break;
Expand All @@ -908,6 +906,8 @@ void DLLEXPORT swmm_getName(int objType, int index, char *name, int size)
}
if (idName)
sstrncpy(name, idName, size);

return 0;
}

//=============================================================================
Expand All @@ -916,13 +916,13 @@ int DLLEXPORT swmm_getIndex(int objType, const char *name)
//
// Input: objType = a type of SWMM object
// name = the object's ID name
// Output: returns the object's position in the array of like objects;
// Output: returns the object's position in the array of like objects or error code;
// Purpose: retrieves the index of a named object.
{
if (!IsOpenFlag)
return -1;
return ERR_API_NOT_OPEN;
if (objType < swmm_GAGE || objType > swmm_LINK)
return -1;
return ERR_API_OBJECT_TYPE;
return project_findObject(objType, name);
}

Expand Down Expand Up @@ -1273,6 +1273,10 @@ double getSystemValue(int property)
return SkipSteadyState;
case swmm_IGNORERAINFALL:
return IgnoreRainfall;
case swmm_RULESTEP:
return RuleStep;
case swmm_SWEEPSTART:
return SweepStart;
default:
return ERR_API_PROPERTY_TYPE;
}
Expand Down Expand Up @@ -1519,7 +1523,7 @@ int setSystemValue(int property, double value)
//
// Input: property = a system property code
// value = the property's new value
// Output: none
// Output: returns an error code
// Purpose: sets the value of a system property.
{
int y, m, d, h, min, s;
Expand Down

0 comments on commit 58e330b

Please sign in to comment.