Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions include/impl/iutest_core_impl.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,7 @@ IUTEST_IPP_INLINE bool UnitTestImpl::SkipTest()

IUTEST_IPP_INLINE int UnitTestImpl::Listup() const
{
detail::iuConsole::output("%d tests from %" IUPRzu " testsuite\n", m_total_test_num, m_testsuites.size() );
for( iuTestSuites::const_iterator it = m_testsuites.begin(), end=m_testsuites.end(); it != end; ++it )
{
detail::iuConsole::output("%s\n", (*it)->name());

for( TestSuite::iuTestInfos::const_iterator it2 = (*it)->begin(), end2=(*it)->end(); it2 != end2; ++it2 )
{
detail::iuConsole::output(" %s\n", (*it2)->name());
}
}
TestEnv::event_listeners().OnListup(m_total_test_num, m_testsuites);
return 0;
}

Expand All @@ -80,7 +71,7 @@ IUTEST_IPP_INLINE int UnitTestImpl::ListupWithWhere() const
detail::iuConsole::output("%d tests from %" IUPRzu " testsuite\n", m_total_test_num, m_testsuites.size() );
for( iuTestSuites::const_iterator it = m_testsuites.begin(), end=m_testsuites.end(); it != end; ++it )
{
detail::iuConsole::output("%s\n", (*it)->testsuite_name_with_where().c_str());
detail::iuConsole::output("%s.\n", (*it)->testsuite_name_with_where().c_str());

for( TestSuite::iuTestInfos::const_iterator it2 = (*it)->begin(), end2=(*it)->end(); it2 != end2; ++it2 )
{
Expand Down
26 changes: 20 additions & 6 deletions include/impl/iutest_default_printer.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ IUTEST_IPP_INLINE void DefaultResultPrintListener::OnTestEnd(const TestInfo& tes
if( TestFlag::IsEnableFlag(TestFlag::PRINT_TIME) )
{
#if defined(IUTEST_NOT_SUPPORT_STOPWATCH)
detail::iuConsole::output(" (--ms)" );
detail::iuConsole::output(" (-- ms)" );
#else
detail::iuConsole::output(" (%sms)", detail::FormatTimeInMillisec(test_info.elapsed_time()).c_str());
detail::iuConsole::output(" (%s ms)", detail::FormatTimeInMillisec(test_info.elapsed_time()).c_str());
#endif
}
detail::iuConsole::output("\n");
Expand All @@ -117,9 +117,9 @@ IUTEST_IPP_INLINE void DefaultResultPrintListener::OnTestSuiteEnd(const TestSuit
if( TestFlag::IsEnableFlag(TestFlag::PRINT_TIME) )
{
#if defined(IUTEST_NOT_SUPPORT_STOPWATCH)
detail::iuConsole::output("(--ms total)");
detail::iuConsole::output("(-- ms total)");
#else
detail::iuConsole::output("(%sms total)", detail::FormatTimeInMillisec(test_suite.elapsed_time()).c_str());
detail::iuConsole::output("(%s ms total)", detail::FormatTimeInMillisec(test_suite.elapsed_time()).c_str());
#endif
}
detail::iuConsole::output("\n\n");
Expand All @@ -146,9 +146,9 @@ IUTEST_IPP_INLINE void DefaultResultPrintListener::OnTestIterationEnd(const Unit
if( TestFlag::IsEnableFlag(TestFlag::PRINT_TIME) )
{
#if defined(IUTEST_NOT_SUPPORT_STOPWATCH)
detail::iuConsole::output(" (--ms total)");
detail::iuConsole::output(" (-- ms total)");
#else
detail::iuConsole::output(" (%sms total)", detail::FormatTimeInMillisec(test.elapsed_time()).c_str());
detail::iuConsole::output(" (%s ms total)", detail::FormatTimeInMillisec(test.elapsed_time()).c_str());
#endif
}
detail::iuConsole::output("\n");
Expand Down Expand Up @@ -245,6 +245,20 @@ IUTEST_IPP_INLINE void DefaultResultPrintListener::OnTestProgramEnd(const UnitTe
{
IUTEST_UNUSED_VAR(test);
}
IUTEST_IPP_INLINE void DefaultResultPrintListener::OnListup(int total_test_num, const ::std::vector<TestSuite*>& tests)
{
detail::iuConsole::output("%d tests from %" IUPRzu " testsuite\n", total_test_num, tests.size() );
for( ::std::vector<TestSuite*>::const_iterator it = tests.begin(), end=tests.end(); it != end; ++it )
{
detail::iuConsole::output("%s.\n", (*it)->name());

for( int i = 0; i < (*it)->total_test_count(); ++i )
{
const TestInfo* testinfo = (*it)->GetTestInfo(i);
detail::iuConsole::output(" %s\n", testinfo->name());
}
}
}

} // end of namespace iutest

Expand Down
37 changes: 37 additions & 0 deletions include/impl/iutest_default_xml_generator.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,43 @@ IUTEST_IPP_INLINE void DefaultXmlGeneratorListener::OnTestProgramEnd(const UnitT
FileClose();
}

IUTEST_IPP_INLINE void DefaultXmlGeneratorListener::OnListup(int total_test_num, const ::std::vector<TestSuite*>& tests)
{
FileOpen(m_output_path.c_str());
m_fp->Printf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
m_fp->Printf("<testsuites tests=\"%d\" name=\"AllTests\">\n", total_test_num);
for( ::std::vector<TestSuite*>::const_iterator it = tests.begin(), end=tests.end(); it != end; ++it )
{
m_fp->Printf(" <testsuite name=\"%s\" tests=\"%d\">\n"
, (*it)->testsuite_name_with_default_package_name().c_str()
, (*it)->total_test_count());

for( int i = 0; i < (*it)->total_test_count(); ++i )
{
const TestInfo* testinfo = (*it)->GetTestInfo(i);
std::string value_param, type_param;
if ( testinfo->value_param() != NULL )
{
value_param = " value_param=\"" + EscapeXmlAttribute(testinfo->value_param()) + "\"";
}
if ( testinfo->type_param() != NULL )
{
type_param = " type_param=\"" + EscapeXmlAttribute(testinfo->type_param()) + "\"";
}
m_fp->Printf(" <testcase name=\"%s\"%s%s file=\"%s\" line=\"%d\" />\n"
, testinfo->name()
, value_param.c_str()
, type_param.c_str()
, testinfo->file()
, testinfo->line());
}

m_fp->Printf(" </testsuite>\n");
}
m_fp->Printf("</testsuites>\n");
FileClose();
}

IUTEST_IPP_INLINE void DefaultXmlGeneratorListener::OnReportTest(IFile* file, const UnitTest& test)
{
file->Printf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
Expand Down
7 changes: 7 additions & 0 deletions include/impl/iutest_listener.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@ IUTEST_IPP_INLINE void TestEventRepeater::OnTestProgramEnd(const UnitTest& test)
(*it)->OnTestProgramEnd(test);
}
}
IUTEST_IPP_INLINE void TestEventRepeater::OnListup(int total_test_num, const ::std::vector<TestSuite*>& tests)
{
for( ListenerContainer::iterator it=m_listeners.begin(), end=m_listeners.end(); it != end; ++it )
{
(*it)->OnListup(total_test_num, tests);
}
}

IUTEST_IPP_INLINE void TestEventListeners::set_default_result_printer(TestEventListener* listener)
{
Expand Down
3 changes: 3 additions & 0 deletions include/internal/iutest_internal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@
::iutest::detail::TestInstance<IUTEST_TEST_CLASS_NAME_(testsuite_, testname_)> \
IUTEST_TEST_INSTANCE_NAME_(testsuite_, testname_)( \
IUTEST_CONCAT_PACKAGE_(IIUT_TO_NAME_(testsuite_)), IIUT_TO_NAME_STR_(testname_) \
, __FILE__, __LINE__ \
, type_id_, IUTEST_GET_SETUP_TESTSUITE(parent_class_, __FILE__, __LINE__) \
, IUTEST_GET_TEARDOWN_TESTSUITE(parent_class_, __FILE__, __LINE__)); \
void IUTEST_TEST_CLASS_NAME_(testsuite_, testname_)::Body()
Expand All @@ -176,6 +177,7 @@
::iutest::detail::TestInstance<IUTEST_TEST_CLASS_NAME_(testsuite_, testname_)> \
IUTEST_TEST_INSTANCE_NAME_(testsuite_, testname_)( \
IUTEST_CONCAT_PACKAGE_(IIUT_TO_NAME_(testsuite_)), IIUT_TO_NAME_STR_(testname_) \
, __FILE__, __LINE__ \
, type_id_, IUTEST_GET_SETUP_TESTSUITE(parent_class_, __FILE__, __LINE__) \
, IUTEST_GET_TEARDOWN_TESTSUITE(parent_class_, __FILE__, __LINE__)); \
template<typename T>void IUTEST_TEST_CLASS_NAME_(testsuite_, testname_ )::Body()
Expand Down Expand Up @@ -213,6 +215,7 @@
IUTEST_PP_CAT( IUTEST_TEST_INSTANCE_NAME_(testsuite_, testname_), __LINE__)( \
IUTEST_CONCAT_PACKAGE_(IIUT_TO_NAME_(testsuite_)) \
, IUTEST_PMZ_TEST_CLASS_NAME_(testsuite_, testname_)::MakeTestName().c_str() \
, __FILE__, __LINE__ \
, #__VA_ARGS__, type_id_, IUTEST_GET_SETUP_TESTSUITE(parent_class_, __FILE__, __LINE__) \
, IUTEST_GET_TEARDOWN_TESTSUITE(parent_class_, __FILE__, __LINE__))

Expand Down
8 changes: 6 additions & 2 deletions include/internal/iutest_option_message.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,15 @@ inline void iuOptionMessage::ShowHelp()
"Name\n"
" iutest - iris unit test framework\n"
"--------------------------------------------------\n"
"Description\n"
" This program contains tests written using iutest. You can use the\n"
" following command line flags to control its behavior:\n"
"--------------------------------------------------\n"
"Command Line Options\n"
"\n"
" --help, -h : Generate help message.\n"
" --iutest_list_tests : List up tests.\n"
" --iutest_list_tests_with_where : List up tests with where.\n"
" --iutest_list_tests : List the names of all tests instead of running them.\n"
" --iutest_list_tests_with_where : List the names of all tests with where instead of running them.\n"
" --iutest_color=<yes|no|auto|ansi>: Console color enable.\n"
" --iutest_flagfile=<file> : Set the flag from the file.\n"
" --iutest_filter=<filter> : Select the test run.\n"
Expand Down
4 changes: 2 additions & 2 deletions include/internal/iutest_params_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class IParamTestInfoData
explicit IParamTestInfoData(const char* name) : m_name(name) {}
virtual ~IParamTestInfoData() IUTEST_CXX_DEFAULT_FUNCTION
virtual TestSuite* MakeTestSuite(const ::std::string& , TestTypeId , SetUpMethod , TearDownMethod ) const = 0;
virtual EachTestBase* RegisterTest(TestSuite* , const ::std::string& ) const = 0;
virtual EachTestBase* RegisterTest(TestSuite* , const ::std::string& , const ::std::string& , int ) const = 0;
const char* GetName() const { return m_name.c_str(); }
protected:
::std::string m_name;
Expand Down Expand Up @@ -203,7 +203,7 @@ class ParamTestSuiteInfo IUTEST_CXX_FINAL : public IParamTestSuiteInfo
IUTEST_LOG_(WARNING) << testsuite_name << "." << name << " is already exist.";
}
#endif
EachTest* test = static_cast<EachTest*>(infodata->RegisterTest(testsuite, name));
EachTest* test = static_cast<EachTest*>(infodata->RegisterTest(testsuite, name, file, line));
test->SetParam(p->GetCurrent());
++i;
}
Expand Down
16 changes: 8 additions & 8 deletions include/iutest_core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,35 +242,35 @@ class TestInstance
{
public:
/** コンストラクタ */
TestInstance(const char* testsuite, const char* name, TestTypeId id
TestInstance(const char* testsuite, const char* name, const char* file, int line, TestTypeId id
, SetUpMethod setup, TearDownMethod teardown)
: m_mediator(AddTestSuite(testsuite, id, setup, teardown))
, m_info(&m_mediator, name, &m_factory)
, m_info(&m_mediator, name, file, line, &m_factory)
{
UnitTest::instance().AddTestInfo(m_mediator.ptr(), &m_info);
}
/** コンストラクタ */
TestInstance(const ::std::string& testsuite, const char* name, TestTypeId id
TestInstance(const ::std::string& testsuite, const char* name, const char* file, int line, TestTypeId id
, SetUpMethod setup, TearDownMethod teardown)
: m_mediator(AddTestSuite(testsuite, id, setup, teardown))
, m_info(&m_mediator, name, &m_factory)
, m_info(&m_mediator, name, file, line, &m_factory)
{
UnitTest::instance().AddTestInfo(m_mediator.ptr(), &m_info);
}
/** コンストラクタ */
TestInstance(const char* testsuite, const char* name, const char* value_params, TestTypeId id
TestInstance(const char* testsuite, const char* name, const char* file, int line, const char* value_params, TestTypeId id
, SetUpMethod setup, TearDownMethod teardown)
: m_mediator(AddTestSuite(testsuite, id, setup, teardown))
, m_info(&m_mediator, name, &m_factory)
, m_info(&m_mediator, name, file, line, &m_factory)
{
m_info.set_value_param(value_params);
UnitTest::instance().AddTestInfo(m_mediator.ptr(), &m_info);
}
/** コンストラクタ */
TestInstance(const ::std::string& testsuite, const char* name, const char* value_params, TestTypeId id
TestInstance(const ::std::string& testsuite, const char* name, const char* file, int line, const char* value_params, TestTypeId id
, SetUpMethod setup, TearDownMethod teardown)
: m_mediator(AddTestSuite(testsuite, id, setup, teardown))
, m_info(&m_mediator, name, &m_factory)
, m_info(&m_mediator, name, file, line, &m_factory)
{
m_info.set_value_param(value_params);
UnitTest::instance().AddTestInfo(m_mediator.ptr(), &m_info);
Expand Down
12 changes: 11 additions & 1 deletion include/iutest_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,14 @@ class TestInfo
* @brief コンストラクタ
* @param [in] testsuite = TestSuite 仲介者
* @param [in] name = テスト名
* @param [in] file = テストファイル名
* @param [in] line = テスト行番号
* @param [in] factory = テスト生成器
*/
TestInfo(detail::iuITestSuiteMediator* testsuite, const ::std::string& name, detail::iuFactoryBase* factory)
TestInfo(detail::iuITestSuiteMediator* testsuite, const ::std::string& name, const ::std::string& file, int line, detail::iuFactoryBase* factory)
: m_testname(name)
, m_file(file)
, m_line(line)
, m_factory(factory)
, m_testsuite(testsuite)
, m_should_run(true)
Expand All @@ -63,6 +67,10 @@ class TestInfo
#endif
/** test 名の取得 */
const char* name() const { return m_testname.c_str(); }
/** test ファイル名の取得 */
const char* file() const { return m_file.c_str(); }
/** test 行番号の取得 */
int line() const { return m_line; }
/** should_run */
bool should_run() const IUTEST_CXX_NOEXCEPT_SPEC { return m_should_run; }
/** is ran */
Expand Down Expand Up @@ -245,6 +253,8 @@ class TestInfo
friend class detail::UncaughtScopedTrace;

::std::string m_testname; //!< テスト名
::std::string m_file; //!< テストファイル名
int m_line; //!< テストファイル行番号
::std::string m_value_param; //!< value param string
TestResult m_test_result; //!< テスト結果
Mediator m_mediator; //!< 自身の仲介インスタンス
Expand Down
9 changes: 9 additions & 0 deletions include/iutest_listener.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ class TestEventListener
virtual void OnTestIterationEnd(const UnitTest& test
, int iteration) = 0; //!< 単体テスト終了時に毎回呼ばれます
virtual void OnTestProgramEnd(const UnitTest& test) = 0; //!< テストプログラム終了時に呼ばれます
virtual void OnListup(int total_test_num
, const ::std::vector<TestSuite*>& tests) = 0; //!< テストリストアップ時に呼ばれます
};

/**
Expand All @@ -116,6 +118,8 @@ class EmptyTestEventListener : public TestEventListener
virtual void OnTestIterationEnd(const UnitTest& /*test*/
, int /*iteration*/) IUTEST_CXX_OVERRIDE {}
virtual void OnTestProgramEnd(const UnitTest& /*test*/) IUTEST_CXX_OVERRIDE {}
virtual void OnListup(int /* total_test_num */
, const ::std::vector<TestSuite*>& /*tests*/) IUTEST_CXX_OVERRIDE {}
};

/**
Expand Down Expand Up @@ -156,6 +160,8 @@ class TestEventRepeater : public TestEventListener
virtual void OnTestIterationEnd(const UnitTest& test
, int iteration) IUTEST_CXX_OVERRIDE;
virtual void OnTestProgramEnd(const UnitTest& test) IUTEST_CXX_OVERRIDE;
virtual void OnListup(int total_test_num
, const ::std::vector<TestSuite*>& tests) IUTEST_CXX_OVERRIDE;

private:
ListenerContainer m_listeners;
Expand Down Expand Up @@ -223,6 +229,9 @@ class TestEventListeners
void OnTestIterationEnd(const UnitTest& test, int iteration) { m_repeater.OnTestIterationEnd(test, iteration); }
void OnTestProgramEnd(const UnitTest& test) { m_repeater.OnTestProgramEnd(test); }

void OnListup(int total_test_num
, const ::std::vector<TestSuite*>& tests) { m_repeater.OnListup(total_test_num, tests); }

private:
void set_default_result_printer(TestEventListener* listener);
void set_default_xml_generator(TestEventListener* listener);
Expand Down
10 changes: 6 additions & 4 deletions include/iutest_param_tests.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,9 @@ class ParamTestInstance : public IParamTestInfoData
class EachTest IUTEST_CXX_FINAL : public IParamTestInfoData::ParamEachTestBase<ParamType>
{
public:
EachTest(TestSuite* testsuite, const ::std::string& name)
EachTest(TestSuite* testsuite, const ::std::string& name, const ::std::string& file, int line)
: m_mediator(testsuite)
, m_info(&m_mediator, name, &m_factory)
, m_info(&m_mediator, name, file, line, &m_factory)
{
UnitTest::instance().AddTestInfo(testsuite, &m_info);
}
Expand Down Expand Up @@ -333,9 +333,11 @@ class ParamTestInstance : public IParamTestInfoData

// テストの作成登録
virtual IParamTestInfoData::EachTestBase* RegisterTest(TestSuite* testsuite
, const ::std::string& name) const IUTEST_CXX_OVERRIDE
, const ::std::string& name
, const ::std::string& file
, int line) const IUTEST_CXX_OVERRIDE
{
EachTest* test = new EachTest(testsuite, name);
EachTest* test = new EachTest(testsuite, name, file, line);
// new オブジェクトを管理してもらう
detail::iuPool::GetInstance().push(test);
return test;
Expand Down
Loading
Loading