From 1cc1f7301cc903375549477ce2f97598255ebb18 Mon Sep 17 00:00:00 2001 From: Kjell Ahlstedt Date: Thu, 13 Feb 2014 15:18:04 +0100 Subject: MemoryInputStream test: Small improvements * tests/giomm_memoryinputstream/main.cc: Slightly better test of the deletion of the data. More output in case of failure. --- tests/giomm_memoryinputstream/main.cc | 53 ++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 22 deletions(-) (limited to 'tests') diff --git a/tests/giomm_memoryinputstream/main.cc b/tests/giomm_memoryinputstream/main.cc index 66112908..813fa4e3 100644 --- a/tests/giomm_memoryinputstream/main.cc +++ b/tests/giomm_memoryinputstream/main.cc @@ -1,38 +1,39 @@ #include #include +#include +#include #include +#include +namespace +{ //Use this line if you want debug output: //std::ostream& ostr = std::cout; //This seems nicer and more useful than putting an ifdef around the use of ostr: -std::stringstream debug; +std::ostringstream debug; std::ostream& ostr = debug; -namespace -{ - int n_called1 = 0; - int n_called2 = 0; +std::string func1_output; +std::string func2_output; - void destroy_func1(void* data) - { - ++n_called1; - char* cdata = static_cast(data); - // cdata is not null-terminated. - ostr << "Deleting " << std::string(cdata, cdata+6); - delete[] cdata; - } +void destroy_func1(void* data) +{ + char* cdata = static_cast(data); + func1_output += "Deleting "; + func1_output += cdata; + delete[] cdata; +} - void destroy_func2(void* data, const Glib::ustring& intro) - { - ++n_called2; - char* cdata = static_cast(data); - // cdata is not null-terminated. - ostr << intro << std::string(cdata, cdata+6); - delete[] cdata; - } +void destroy_func2(void* data, const Glib::ustring& intro) +{ + char* cdata = static_cast(data); + func2_output += intro + cdata; + delete[] cdata; } +} // anonymous namespace + int main(int, char**) { Glib::init(); @@ -79,8 +80,16 @@ int main(int, char**) return EXIT_FAILURE; } + ostr << func1_output << std::endl; + ostr << func2_output << std::endl; + if (std::strcmp(buffer, "Data not owned by stream.\ndata2\ndata3\n") == 0 && - n_called1 == 1 && n_called2 == 1) + func1_output == "Deleting data2\n" && + func2_output == "Now deleting data3\n") return EXIT_SUCCESS; + + std::cerr << "buffer: \"" << buffer << "\"" << std::endl; + std::cerr << "func1_output: \"" << func1_output << "\"" << std::endl; + std::cerr << "func2_output: \"" << func2_output << "\"" << std::endl; return EXIT_FAILURE; } -- cgit v1.2.1