diff options
author | Daniel Boles <dboles@src.gnome.org> | 2018-10-14 13:33:01 +0100 |
---|---|---|
committer | Daniel Boles <dboles@src.gnome.org> | 2018-10-14 13:43:51 +0100 |
commit | a485da170962743f29e4a18d5d8745874042d662 (patch) | |
tree | 745d8606af5fddcf6ab7d57417ccabf7e5053f82 /tests | |
parent | fbe267d6b84ccec41ff3440e9260b471d27af9ad (diff) | |
download | glibmm-a485da170962743f29e4a18d5d8745874042d662.tar.gz |
tests/glibmm_ustring_format: Test output, 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
Diffstat (limited to 'tests')
-rw-r--r-- | tests/glibmm_ustring_format/main.cc | 22 |
1 files changed, 22 insertions, 0 deletions
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; } |