add test_util for common test functions (only slurp() at the moment) ENGINE-189
authorRoker <roker@pep-project.org>
Mon, 13 Mar 2017 20:20:10 +0100
branchENGINE-189
changeset 1656ea7d229bed3f
parent 1655 3a31b803ae83
child 1657 8b06f5627683
add test_util for common test functions (only slurp() at the moment)
test/Makefile
test/pEpEngine_test.h
test/test_util.cc
test/test_util.h
     1.1 --- a/test/Makefile	Mon Mar 13 19:44:31 2017 +0100
     1.2 +++ b/test/Makefile	Mon Mar 13 20:20:10 2017 +0100
     1.3 @@ -42,9 +42,13 @@
     1.4  test: pEpEngineTest .imported
     1.5  	LD_LIBRARY_PATH=~/lib:../src ./pEpEngineTest
     1.6  
     1.7 +%_test : %_test.o test_util.o
     1.8 +	 $(LD) $(LDFLAGS) -o $@ $^ $(LDLIBS)
     1.9 +
    1.10  %_test_run : %_test
    1.11  	LD_LIBRARY_PATH=~/lib:../src ./$<
    1.12  
    1.13 +
    1.14  %_test_lldb : %_test
    1.15  	LD_LIBRARY_PATH=~/lib:../src lldb ./$<
    1.16  
     2.1 --- a/test/pEpEngine_test.h	Mon Mar 13 19:44:31 2017 +0100
     2.2 +++ b/test/pEpEngine_test.h	Mon Mar 13 20:20:10 2017 +0100
     2.3 @@ -1,4 +1,3 @@
     2.4  #include <iomanip>
     2.5  
     2.6  #define ASSERT_STATUS(status) { cout << setfill('0') << "status: 0x" << hex << setw(4) << status << "\n"; assert(status == PEP_STATUS_OK); }
     2.7 -
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/test_util.cc	Mon Mar 13 20:20:10 2017 +0100
     3.3 @@ -0,0 +1,17 @@
     3.4 +#include "pEpEngine_test.h"
     3.5 +#include <fstream>
     3.6 +#include <sstream>
     3.7 +#include <stdexcept>
     3.8 +
     3.9 +std::string slurp(const std::string& filename)
    3.10 +{
    3.11 +	std::ifstream input(filename.c_str());
    3.12 +	if(!input)
    3.13 +	{
    3.14 +		throw std::runtime_error("Cannot read file \"" + filename + "\"! ");
    3.15 +	}
    3.16 +	
    3.17 +	std::stringstream sstr;
    3.18 +	sstr << input.rdbuf();
    3.19 +	return sstr.str();
    3.20 +}
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/test/test_util.h	Mon Mar 13 20:20:10 2017 +0100
     4.3 @@ -0,0 +1,5 @@
     4.4 +#include <string>
     4.5 +
     4.6 +// reads a whole file and returns it as std::string
     4.7 +// throws std::runtime_error() if the file cannot be read. Empty file is not an error.
     4.8 +std::string slurp(const std::string& filename);