diff options
author | Tom Tromey <tom@tromey.com> | 2017-09-28 07:44:50 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2017-09-29 20:46:42 -0600 |
commit | bd413795d364d3bed8dbb8c596cb45c82ed31041 (patch) | |
tree | a5ab5045c72498fe96689c39d2d6abd192e6ce1b /gdb/unittests | |
parent | 8b5b25295998e10723bd51d127c87249a779f628 (diff) | |
download | gdb-bd413795d364d3bed8dbb8c596cb45c82ed31041.zip gdb-bd413795d364d3bed8dbb8c596cb45c82ed31041.tar.gz gdb-bd413795d364d3bed8dbb8c596cb45c82ed31041.tar.bz2 |
Introduce string_vprintf
This adds string_vprintf, a va_list variant of string_printf. This
will be used in later patches.
gdb/ChangeLog
2017-09-29 Tom Tromey <tom@tromey.com>
* unittests/common-utils-selftests.c (format): New function.
(string_vprintf_tests): New function.
(_initialize_common_utils_selftests): Register new tests.
* common/common-utils.c (string_vprintf): New function.
* common/common-utils.h (string_vprintf): Declare.
Diffstat (limited to 'gdb/unittests')
-rw-r--r-- | gdb/unittests/common-utils-selftests.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/gdb/unittests/common-utils-selftests.c b/gdb/unittests/common-utils-selftests.c index 71bc2df..0f26b21 100644 --- a/gdb/unittests/common-utils-selftests.c +++ b/gdb/unittests/common-utils-selftests.c @@ -41,10 +41,33 @@ string_printf_tests () SELF_CHECK (string_printf ("%s", X100000) == X100000); } +static std::string +format (const char *fmt, ...) +{ + va_list vp; + + va_start (vp, fmt); + std::string result = string_vprintf (fmt, vp); + va_end (vp); + return result; +} + +static void +string_vprintf_tests () +{ + /* Basic smoke tests. */ + SELF_CHECK (format ("%s", "test") == "test"); + SELF_CHECK (format ("%d", 23) == "23"); + SELF_CHECK (format ("%s %d %s", "test", 23, "done") + == "test 23 done"); + SELF_CHECK (format ("nothing") == "nothing"); +} + } /* namespace selftests */ void _initialize_common_utils_selftests () { selftests::register_test ("string_printf", selftests::string_printf_tests); + selftests::register_test ("string_vprintf", selftests::string_vprintf_tests); } |