From ee973e1fe7b252b652fa57205e9962a0c5d11dd8 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 28 May 2015 14:12:48 +0200 Subject: [PATCH] Add more wxString::Format() positional parameters tests. Verify that repeating positional parameters does work with wxString::Format() instead of keeping these tests commented out in wxVsnprintf() tests, which are not run at all if we're using the compiler-provided vsprintf(). Closes #9367. --- tests/strings/strings.cpp | 13 +++++++++++++ tests/strings/vsnprintf.cpp | 13 ------------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/strings/strings.cpp b/tests/strings/strings.cpp index f31c57988e..49cbd8d4af 100644 --- a/tests/strings/strings.cpp +++ b/tests/strings/strings.cpp @@ -168,11 +168,24 @@ void StringTestCase::Format() } + // Positional parameters tests: CPPUNIT_ASSERT_EQUAL ( "two one", wxString::Format(wxT("%2$s %1$s"), wxT("one"), wxT("two")) ); + + CPPUNIT_ASSERT_EQUAL + ( + "hello hello", + wxString::Format("%1$s %1$s", "hello") + ); + + CPPUNIT_ASSERT_EQUAL + ( + "4 world hello world 3", + wxString::Format("%4$d %2$s %1$s %2$s %3$d", "hello", "world", 3, 4) + ); } void StringTestCase::FormatUnicode() diff --git a/tests/strings/vsnprintf.cpp b/tests/strings/vsnprintf.cpp index 4018229cea..14d2144272 100644 --- a/tests/strings/vsnprintf.cpp +++ b/tests/strings/vsnprintf.cpp @@ -435,19 +435,6 @@ void VsnprintfTestCase::WrongFormatStrings() { // test how wxVsnprintf() behaves with wrong format string: -#if 0 - // NB: the next 2 tests currently return an error but it would be nice - // if they didn't (see ticket #9367) - - // two positionals with the same index: - r = wxSnprintf(buf, MAX_TEST_LEN, wxT("%1$s %1$s"), "hello"); - CPPUNIT_ASSERT(r != -1); - - // three positionals with the same index mixed with other pos args: - r = wxSnprintf(buf, MAX_TEST_LEN, wxT("%4$d %2$f %1$s %2$s %3$d"), "hello", "world", 3, 4); - CPPUNIT_ASSERT(r != -1); -#endif - // a missing positional arg should result in an assert WX_ASSERT_FAILS_WITH_ASSERT( wxSnprintf(buf, MAX_TEST_LEN, wxT("%1$d %3$d"), 1, 2, 3) );