[glibmm/wip/dboles/ustring_format_fold_and_test: 2/2] tests/glibmm_ustring_format: Test subst & iomanips
- From: Daniel Boles <dboles src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glibmm/wip/dboles/ustring_format_fold_and_test: 2/2] tests/glibmm_ustring_format: Test subst & iomanips
- Date: Sun, 14 Oct 2018 12:41:43 +0000 (UTC)
commit 36c73b963deb94a346ade6b69e94ae1439b05c9e
Author: Daniel Boles <dboles src gnome org>
Date: Sun Oct 14 13:33:01 2018 +0100
tests/glibmm_ustring_format: Test subst & iomanips
We only tested here whether single arguments got formatted without
throwing exceptions, but not whether they got formatted into the
expected output or combinations of multiple types and I/O manipulators.
This adds a test for that, so we at least have something to ensure that
things are working correctly, e.g. if refactoring format() as I just did
tests/glibmm_ustring_format/main.cc | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
---
diff --git a/tests/glibmm_ustring_format/main.cc b/tests/glibmm_ustring_format/main.cc
index 0925f84c..76a3efab 100644
--- a/tests/glibmm_ustring_format/main.cc
+++ b/tests/glibmm_ustring_format/main.cc
@@ -1,5 +1,6 @@
#include <glibmm.h>
+#include <iomanip>
#include <iostream>
int
@@ -27,5 +28,26 @@ main(int, char**)
// This threw an exception before we added a ustring::FormatStream::stream(char*) overload.
Glib::ustring::format(cptr);
+ // Test substitution of various types and I/O manipulators
+ Glib::ustring expected("The meaning of life is 42, or with 2 decimal places, 42.00.");
+ auto the = "The";
+ std::string meaning("meaning");
+ Glib::ustring life("life");
+ auto number = 42.0;
+ auto places = 2;
+ auto actual = Glib::ustring::format(the, ' ', meaning, " of ", life, " is ",
+ number,
+ ", or with ", places, " decimal places, ",
+ std::fixed, std::setprecision(places), number,
+ '.');
+
+ if (actual != expected)
+ {
+ std::cerr << "expected (" << expected.size() << "):\n" << expected << "\n\n"
+ << "actual (" << actual .size() << "):\n" << actual << "\n";
+
+ return EXIT_FAILURE;
+ }
+
return EXIT_SUCCESS;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]