Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Structure for testing #32

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 3 additions & 135 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
cmake_minimum_required (VERSION 2.8)
SET (EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
SET (LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)

project ("EPANET")
set_property( GLOBAL PROPERTY USE_FOLDERS ON)
Expand All @@ -15,137 +13,7 @@ else()
SET (CMAKE_CXX_FLAGS "-Wall -std=c++11")
endif(MSVC)

SET (epanet_lib_sources
src/Core/datamanager.cpp
src/Core/diagnostics.cpp
src/Core/epanet3.cpp
src/Core/error.cpp
src/Core/hydbalance.cpp
src/Core/hydengine.cpp
src/Core/network.cpp
src/Core/options.cpp
src/Core/project.cpp
src/Core/qualbalance.cpp
src/Core/qualengine.cpp
src/Core/units.cpp
src/Elements/control.cpp
src/Elements/curve.cpp
src/Elements/demand.cpp
src/Elements/element.cpp
src/Elements/emitter.cpp
src/Elements/junction.cpp
src/Elements/link.cpp
src/Elements/node.cpp
src/Elements/pattern.cpp
src/Elements/pipe.cpp
src/Elements/pump.cpp
src/Elements/pumpcurve.cpp
src/Elements/qualsource.cpp
src/Elements/reservoir.cpp
src/Elements/tank.cpp
src/Elements/valve.cpp
src/Input/controlparser.cpp
src/Input/curveparser.cpp
src/Input/inputparser.cpp
src/Input/inputreader.cpp
src/Input/linkparser.cpp
src/Input/nodeparser.cpp
src/Input/optionparser.cpp
src/Input/patternparser.cpp
src/Models/demandmodel.cpp
src/Models/headlossmodel.cpp
src/Models/leakagemodel.cpp
src/Models/pumpenergy.cpp
src/Models/qualmodel.cpp
src/Models/tankmixmodel.cpp
src/Output/outputfile.cpp
src/Output/projectwriter.cpp
src/Output/reportfields.cpp
src/Output/reportwriter.cpp
src/Solvers/ggasolver.cpp
src/Solvers/hydsolver.cpp
src/Solvers/ltdsolver.cpp
src/Solvers/matrixsolver.cpp
src/Solvers/qualsolver.cpp
src/Solvers/sparspak.cpp
src/Solvers/sparspaksolver.cpp
src/Utilities/graph.cpp
src/Utilities/mempool.cpp
src/Utilities/segpool.cpp
src/Utilities/utilities.cpp
)
add_subdirectory (src)
enable_testing()
add_subdirectory (test)

SET (epanet_lib_headers
src/Core/constants.h
src/Core/datamanager.h
src/Core/diagnostics.h
src/Core/error.h
src/Core/hydbalance.h
src/Core/hydengine.h
src/Core/network.h
src/Core/options.h
src/Core/project.h
src/Core/qualbalance.h
src/Core/qualengine.h
src/Core/units.h
src/Elements/control.h
src/Elements/curve.h
src/Elements/demand.h
src/Elements/element.h
src/Elements/emitter.h
src/Elements/junction.h
src/Elements/link.h
src/Elements/node.h
src/Elements/pattern.h
src/Elements/pipe.h
src/Elements/pump.h
src/Elements/pumpcurve.h
src/Elements/qualsource.h
src/Elements/reservoir.h
src/Elements/tank.h
src/Elements/valve.h
src/Input/controlparser.h
src/Input/curveparser.h
src/Input/inputparser.h
src/Input/inputreader.h
src/Input/linkparser.h
src/Input/nodeparser.h
src/Input/optionparser.h
src/Input/patternparser.h
src/Models/demandmodel.h
src/Models/headlossmodel.h
src/Models/leakagemodel.h
src/Models/pumpenergy.h
src/Models/qualmodel.h
src/Models/tankmixmodel.h
src/Output/outputfile.h
src/Output/projectwriter.h
src/Output/reportfields.h
src/Output/reportwriter.h
src/Solvers/ggasolver.h
src/Solvers/hydsolver.h
src/Solvers/ltdsolver.h
src/Solvers/matrixsolver.h
src/Solvers/qualsolver.h
src/Solvers/sparspak.h
src/Solvers/sparspaksolver.h
src/Utilities/graph.h
src/Utilities/mempool.h
src/Utilities/segpool.h
src/Utilities/utilities.h
)

source_group("Core" REGULAR_EXPRESSION "src/Core/.*")
source_group("Elements" REGULAR_EXPRESSION "src/Elements/.*")
source_group("Input" REGULAR_EXPRESSION "src/Input/.*")
source_group("Models" REGULAR_EXPRESSION "src/Models/.*")
source_group("Output" REGULAR_EXPRESSION "src/Output/.*")
source_group("Solvers" REGULAR_EXPRESSION "src/Solvers/.*")
source_group("Utilities" REGULAR_EXPRESSION "src/Utilities/.*")

include_directories(src src/Core src/Elements src/Input src/Output src/Utilities src/Solvers)

add_library(epanet3 SHARED ${epanet_lib_sources} ${epanet_lib_headers})

add_executable(run-epanet3 src/CLI/main.cpp)
target_link_libraries(run-epanet3 LINK_PUBLIC epanet3)
142 changes: 142 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
# cmakelists.txt for epanet3 src

SET (epanet_lib_sources
Core/datamanager.cpp
Core/diagnostics.cpp
Core/epanet3.cpp
Core/error.cpp
Core/hydbalance.cpp
Core/hydengine.cpp
Core/network.cpp
Core/options.cpp
Core/project.cpp
Core/qualbalance.cpp
Core/qualengine.cpp
Core/units.cpp
Elements/control.cpp
Elements/curve.cpp
Elements/demand.cpp
Elements/element.cpp
Elements/emitter.cpp
Elements/junction.cpp
Elements/link.cpp
Elements/node.cpp
Elements/pattern.cpp
Elements/pipe.cpp
Elements/pump.cpp
Elements/pumpcurve.cpp
Elements/qualsource.cpp
Elements/reservoir.cpp
Elements/tank.cpp
Elements/valve.cpp
Input/controlparser.cpp
Input/curveparser.cpp
Input/inputparser.cpp
Input/inputreader.cpp
Input/linkparser.cpp
Input/nodeparser.cpp
Input/optionparser.cpp
Input/patternparser.cpp
Models/demandmodel.cpp
Models/headlossmodel.cpp
Models/leakagemodel.cpp
Models/pumpenergy.cpp
Models/qualmodel.cpp
Models/tankmixmodel.cpp
Output/outputfile.cpp
Output/projectwriter.cpp
Output/reportfields.cpp
Output/reportwriter.cpp
Solvers/ggasolver.cpp
Solvers/hydsolver.cpp
Solvers/ltdsolver.cpp
Solvers/matrixsolver.cpp
Solvers/qualsolver.cpp
Solvers/sparspak.cpp
Solvers/sparspaksolver.cpp
Utilities/graph.cpp
Utilities/mempool.cpp
Utilities/segpool.cpp
Utilities/utilities.cpp
)

SET (epanet_lib_headers
Core/constants.h
Core/datamanager.h
Core/diagnostics.h
Core/error.h
Core/hydbalance.h
Core/hydengine.h
Core/network.h
Core/options.h
Core/project.h
Core/qualbalance.h
Core/qualengine.h
Core/units.h
Elements/control.h
Elements/curve.h
Elements/demand.h
Elements/element.h
Elements/emitter.h
Elements/junction.h
Elements/link.h
Elements/node.h
Elements/pattern.h
Elements/pipe.h
Elements/pump.h
Elements/pumpcurve.h
Elements/qualsource.h
Elements/reservoir.h
Elements/tank.h
Elements/valve.h
Input/controlparser.h
Input/curveparser.h
Input/inputparser.h
Input/inputreader.h
Input/linkparser.h
Input/nodeparser.h
Input/optionparser.h
Input/patternparser.h
Models/demandmodel.h
Models/headlossmodel.h
Models/leakagemodel.h
Models/pumpenergy.h
Models/qualmodel.h
Models/tankmixmodel.h
Output/outputfile.h
Output/projectwriter.h
Output/reportfields.h
Output/reportwriter.h
Solvers/ggasolver.h
Solvers/hydsolver.h
Solvers/ltdsolver.h
Solvers/matrixsolver.h
Solvers/qualsolver.h
Solvers/sparspak.h
Solvers/sparspaksolver.h
Utilities/graph.h
Utilities/mempool.h
Utilities/segpool.h
Utilities/utilities.h
)

source_group("Core" REGULAR_EXPRESSION "Core/.*")
source_group("Elements" REGULAR_EXPRESSION "Elements/.*")
source_group("Input" REGULAR_EXPRESSION "Input/.*")
source_group("Models" REGULAR_EXPRESSION "Models/.*")
source_group("Output" REGULAR_EXPRESSION "Output/.*")
source_group("Solvers" REGULAR_EXPRESSION "Solvers/.*")
source_group("Utilities" REGULAR_EXPRESSION "Utilities/.*")

include_directories(. Core Elements Input Output Utilities Solvers)

# static for ease of testing
add_library(epanet3 STATIC ${epanet_lib_sources} ${epanet_lib_headers})

add_executable(run-epanet3 CLI/main.cpp)
target_link_libraries(run-epanet3 LINK_PUBLIC epanet3)

# put the library and executable in bin
set_target_properties( epanet3 run-epanet3
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
4 changes: 3 additions & 1 deletion src/Elements/element.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ class Element
std::string name; //!< element's ID name
int index; //!< index in array of elements

protected:
Element(const Element& e);
private:

// Elements can't be copied or tested for equality
Element(const Element& e);
//Element(const Element& e);
Element& operator=(const Element& e);
};

Expand Down
9 changes: 9 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

# a cmake file for a test build
# For test
include_directories (${CMAKE_SOURCE_DIR}/src)

## have to do this for each test
add_executable(test_pipe src/Elements/test_pipe.cpp)
target_link_libraries(test_pipe LINK_PUBLIC epanet3)
add_test( pipe test_pipe )
26 changes: 26 additions & 0 deletions test/src/Elements/test_pipe.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <iostream>
#include <string>
#include "Elements/pipe.h"



/**
* An application for testing the pipe class.
* Should return 0 for passing, any other value
* fails.
*/
int main (void )
{

std::string expected = "myPipe";
Pipe p = Pipe( expected );

// see that the pipe has the correct name
std::cout << "Created a pipe named " << p.name << std::endl;

std::string actual = p.name;

int value = actual.compare(expected);

return value;
}