Repository: incubator-hawq Updated Branches: refs/heads/master e3933e7b3 -> 9f7a3a427
HAWQ-810. Add stringFormat for feature test library Project: http://git-wip-us.apache.org/repos/asf/incubator-hawq/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-hawq/commit/9f7a3a42 Tree: http://git-wip-us.apache.org/repos/asf/incubator-hawq/tree/9f7a3a42 Diff: http://git-wip-us.apache.org/repos/asf/incubator-hawq/diff/9f7a3a42 Branch: refs/heads/master Commit: 9f7a3a427ab8b4f0eb85cb88f1c64a6ec973fe2b Parents: e3933e7 Author: xunzhang <[email protected]> Authored: Mon Jun 13 19:08:01 2016 +0800 Committer: rlei <[email protected]> Committed: Tue Jun 14 11:26:14 2016 +0800 ---------------------------------------------------------------------- src/test/feature/lib/string_util.h | 10 ++++++++++ src/test/feature/testlib/test_lib.cpp | 6 ++++++ 2 files changed, 16 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/9f7a3a42/src/test/feature/lib/string_util.h ---------------------------------------------------------------------- diff --git a/src/test/feature/lib/string_util.h b/src/test/feature/lib/string_util.h index 5aa6246..9a97b13 100644 --- a/src/test/feature/lib/string_util.h +++ b/src/test/feature/lib/string_util.h @@ -3,6 +3,7 @@ #include <string> #include <vector> +#include <cstdio> namespace hawq { namespace test { @@ -27,6 +28,15 @@ bool startsWith(const std::string &, const std::string &); bool endsWith(const std::string &, const std::string &); +template <typename... T> +std::string stringFormat(const std::string &fmt, T... vs) { + char b; + unsigned required = std::snprintf(&b, 0, fmt.c_str(), vs...) + 1; + char bytes[required]; + std::snprintf(bytes, required, fmt.c_str(), vs...); + return std::string(bytes); +} + } // namespace test } // namespace hawq http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/9f7a3a42/src/test/feature/testlib/test_lib.cpp ---------------------------------------------------------------------- diff --git a/src/test/feature/testlib/test_lib.cpp b/src/test/feature/testlib/test_lib.cpp index 99325f6..63ade3e 100644 --- a/src/test/feature/testlib/test_lib.cpp +++ b/src/test/feature/testlib/test_lib.cpp @@ -10,6 +10,7 @@ #include "lib/data_gen.h" #include "lib/hawq_config.h" #include "lib/sql_util.h" +#include "lib/string_util.h" #include "gtest/gtest.h" @@ -80,6 +81,11 @@ TEST_F(TestCommonLib, TestSqlUtil) { EXPECT_EQ(err_msg, "ERROR: table \"non_exist_tbl\" does not exist\n"); } +TEST_F(TestCommonLib, TestStringFormat) { + auto s1 = hawq::test::stringFormat("%s are welcome to apache %s project", "you", "HAWQ"); + EXPECT_EQ(s1, "you are welcome to apache HAWQ project"); +} + TEST_F(TestCommonLib, TestDataGenerator) { hawq::test::SQLUtility util; hawq::test::DataGenerator dGen(&util);
