diff options
author | Marco Bubke <marco.bubke@qt.io> | 2016-10-18 18:22:17 +0200 |
---|---|---|
committer | Marco Bubke <marco.bubke@qt.io> | 2016-11-01 14:04:56 +0000 |
commit | a23f3c5e07c0b6ad6302390b6ce6d8a543959f38 (patch) | |
tree | 29ee0bb4b0135f52e50fdf8c9d548a73e23c239a /src/libs/utils/smallstringio.h | |
parent | 30a4c13d1dec71221826b3244726c4d21b604554 (diff) |
Utils: Improve test printing functions
Change-Id: I35df70a504f976422b6c05d4d60e7bc8d918ee1c
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
Diffstat (limited to 'src/libs/utils/smallstringio.h')
-rw-r--r-- | src/libs/utils/smallstringio.h | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/src/libs/utils/smallstringio.h b/src/libs/utils/smallstringio.h index f8aea82815..c8cf70cb27 100644 --- a/src/libs/utils/smallstringio.h +++ b/src/libs/utils/smallstringio.h @@ -30,8 +30,13 @@ #include <QDataStream> #include <QDebug> +#include <iterator> #include <ostream> +#ifdef UNIT_TESTS +#include <gtest/gtest.h> +#endif + namespace Utils { inline @@ -78,7 +83,7 @@ std::ostream &operator<<(std::ostream &stream, const SmallString &string) { using std::operator<<; - return stream << std::string(string.data()); + return stream << std::string(string.data(), string.size()); } inline @@ -220,6 +225,37 @@ QDataStream &operator>>(QDataStream &in, vector<Type> &vector) return in; } +#ifdef UNIT_TESTS +template <typename T> +ostream &operator<<(ostream &out, const vector<T> &vector) +{ + out << "["; + + ostream_iterator<string> outIterator(out, ", "); + + for (const auto &entry : vector) + outIterator = ::testing::PrintToString(entry); + + out << "]"; + + return out; +} +#else +template <typename T> +ostream &operator<<(ostream &out, const vector<T> &vector) +{ + out << "["; + + copy(vector.cbegin(), vector.cend(), ostream_iterator<T>(out, ", ")); + + out << "]"; + + return out; +} +#endif + +} // namespace std + QT_BEGIN_NAMESPACE template<typename Type> @@ -234,5 +270,3 @@ QDebug &operator<<(QDebug &debug, const std::vector<Type> &vector) } QT_END_NAMESPACE - -} // namespace std |