summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorKjell Ahlstedt <kjell.ahlstedt@bredband.net>2014-02-13 15:18:04 +0100
committerKjell Ahlstedt <kjell.ahlstedt@bredband.net>2014-02-13 15:18:04 +0100
commit1cc1f7301cc903375549477ce2f97598255ebb18 (patch)
tree88dff98606f3e8d6bfabd3e03c1759d1cc1713ba /tests
parente762a455ad3f69fd21b057b65b7ae3e2259e6610 (diff)
downloadglibmm-1cc1f7301cc903375549477ce2f97598255ebb18.tar.gz
MemoryInputStream test: Small improvements
* tests/giomm_memoryinputstream/main.cc: Slightly better test of the deletion of the data. More output in case of failure.
Diffstat (limited to 'tests')
-rw-r--r--tests/giomm_memoryinputstream/main.cc53
1 files changed, 31 insertions, 22 deletions
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 <giomm.h>
#include <iostream>
+#include <sstream>
+#include <string>
#include <cstring>
+#include <cstdlib>
+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<char*>(data);
- // cdata is not null-terminated.
- ostr << "Deleting " << std::string(cdata, cdata+6);
- delete[] cdata;
- }
+void destroy_func1(void* data)
+{
+ char* cdata = static_cast<char*>(data);
+ func1_output += "Deleting ";
+ func1_output += cdata;
+ delete[] cdata;
+}
- void destroy_func2(void* data, const Glib::ustring& intro)
- {
- ++n_called2;
- char* cdata = static_cast<char*>(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<char*>(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;
}