Skip to content

Commit

Permalink
Merge 391297f into 7ea67f0
Browse files Browse the repository at this point in the history
  • Loading branch information
srz-zumix committed May 23, 2020
2 parents 7ea67f0 + 391297f commit 9973e8f
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 15 deletions.
9 changes: 4 additions & 5 deletions include/impl/iutest_default_xml_generator.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,14 @@ IUTEST_IPP_INLINE void DefaultXmlGeneratorListener::OnTestIterationStart(const U
}
if( !m_output_path_format.empty() )
{
// FIXME: -Wformat-nonliteral
IUTEST_PRAGMA_WARN_PUSH()
IUTEST_PRAGMA_WARN_FORMAT_NONLITERAL()
m_output_path = detail::StringFormat(m_output_path_format.c_str(), iteration);
m_output_path = m_output_path_format;
::std::string strIte = detail::iu_to_string(iteration);
detail::StringReplace(m_output_path, "%d", 2, strIte.c_str());
detail::StringReplace(m_output_path, "{I}", 3, strIte.c_str());
if( m_output_path == m_output_path_format)
{
m_output_path_format.clear();
}
IUTEST_PRAGMA_WARN_POP()
if( m_fp != NULL )
{
OnReportTest(m_fp, test);
Expand Down
11 changes: 8 additions & 3 deletions include/internal/iutest_string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,20 @@ inline bool IsStringContains(const char* str1, const char* str2) { return strstr
inline bool IsStringContains(const ::std::string& str1, const char* str2) { return str1.find(str2) != ::std::string::npos; }
inline bool IsStringContains(const ::std::string& str1, const ::std::string& str2) { return str1.find(str2) != ::std::string::npos; }

inline void StringReplace(::std::string& str, char a, const char* to)
inline void StringReplace(::std::string& str, const char* from, size_t n, const char* to)
{
::std::string::size_type pos = 0;
while( static_cast<void>(pos = str.find(a, pos)), pos != ::std::string::npos )
while( static_cast<void>(pos = str.find(from, pos)), pos != ::std::string::npos )
{
str.replace(pos, 1, to);
str.replace(pos, n, to);
++pos;
}
}
inline void StringReplace(::std::string& str, char a, const char* to)
{
char s[] = { a, 0 };
return StringReplace(str, s, 1, to);
}
inline ::std::string StripLeadingSpace(const ::std::string& str)
{
::std::string::const_iterator it = str.begin();
Expand Down
1 change: 1 addition & 0 deletions include/iutest_ver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ modification, are permitted provided that the following conditions are met: \n
<li>GTEST_SKIP 対応</li>
<li>::std::wstring_view / ::std::u16string_view / ::std::u32string_view 対応</li>
<li>アサーションに operator &lt;&lt; したときの出力を PrintToString したものと同じになるように変更</li>
<li>テストをリピートした際のレポート出力ファイル名の書式を printf 書式から {I} に変更({I} にリピート回数が置換されます)</li>
<li>Python2 のサポート終了</li>
<li>C++20 で削除された basic_ostream::operator &lt;&lt; に対応</li>
<li>Google Test 旧バージョンとの互換性を修正</li>
Expand Down
4 changes: 3 additions & 1 deletion test/assertion_only_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* @author t.shirayanagi
* @par copyright
* Copyright (C) 2012-2019, Takazumi Shirayanagi\n
* Copyright (C) 2012-2020, Takazumi Shirayanagi\n
* This software is released under the new BSD License,
* see LICENSE
*/
Expand Down Expand Up @@ -40,9 +40,11 @@ static ::iutest::iu_stringstream s_outstream;

void test_vprintf(const char* fmt, va_list va)
{
IUTEST_PRAGMA_CRT_SECURE_WARN_DISABLE_BEGIN()
char buf[4096];
vsprintf(buf, fmt, va);
s_outstream << buf;
IUTEST_PRAGMA_CRT_SECURE_WARN_DISABLE_END()
}

#ifdef UNICODE
Expand Down
18 changes: 14 additions & 4 deletions test/output_xml_repeat_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
//-----------------------------------------------------------------------
/**
* @file output_xml_repeat_tests.cpp
* @brief xml 出力対応テスト
* @brief Test output file name when repeating
*
* @author t.shirayanagi
* @par copyright
* Copyright (C) 2016, Takazumi Shirayanagi\n
* Copyright (C) 2016-2020, Takazumi Shirayanagi\n
* This software is released under the new BSD License,
* see LICENSE
*/
Expand Down Expand Up @@ -59,12 +59,22 @@ int main(int argc, char* argv[])
#if OUTPUT_XML_TEST
IUTEST_INIT(&argc, argv);

::iutest::IUTEST_FLAG(output) = "xml:test_%d.xml";
if( ::iutest::IUTEST_FLAG(repeat) == 1 )
{
::iutest::IUTEST_FLAG(repeat) = 3;
}
return IUTEST_RUN_ALL_TESTS();
::iutest::IUTEST_FLAG(output) = "xml:test_{I}.xml";
if( IUTEST_RUN_ALL_TESTS() )
{
return 1;
}
TestF::nI = 0;
::iutest::IUTEST_FLAG(output) = "xml:test_%d.xml"; // deprecated format
if( IUTEST_RUN_ALL_TESTS() )
{
return 1;
}
return 0;
#else
(void)argc;
(void)argv;
Expand Down
18 changes: 16 additions & 2 deletions test/unit_string_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* @author t.shirayanagi
* @par copyright
* Copyright (C) 2013-2019, Takazumi Shirayanagi\n
* Copyright (C) 2013-2020, Takazumi Shirayanagi\n
* The new BSD License is applied to this software.
* see LICENSE
*/
Expand Down Expand Up @@ -81,13 +81,27 @@ IUTEST(UnitStringTest, StringStrip)
IUTEST_EXPECT_STREQ("a1 a2" , ::iutest::detail::StripSpace(str));
}

IUTEST(UnitStringTest, StringReplace)
IUTEST(UnitStringTest, StringReplaceChar)
{
::std::string str = "a1a2a3a4b5";
::iutest::detail::StringReplace(str, 'a', "ii");
IUTEST_EXPECT_STREQ("ii1ii2ii3ii4b5", str);
}

IUTEST(UnitStringTest, StringReplaceString)
{
{
::std::string str = "a1a2a3a4b5";
::iutest::detail::StringReplace(str, "a1", 2, "ii");
IUTEST_EXPECT_STREQ("iia2a3a4b5", str);
}
{
::std::string str = "a1a2a3a4b5";
::iutest::detail::StringReplace(str, "a1", 1, "ii");
IUTEST_EXPECT_STREQ("ii1a2a3a4b5", str);
}
}

IUTEST(UnitStringTest, StringReplaceToLF)
{
::std::string str = "a\r\nb\r\rc\r\n\nd";
Expand Down

0 comments on commit 9973e8f

Please sign in to comment.