15 #ifndef INCG_IRIS_IUTEST_ENV_HPP_F4017EAB_6CA3_4E6E_8983_059393DADD04_
16 #define INCG_IRIS_IUTEST_ENV_HPP_F4017EAB_6CA3_4E6E_8983_059393DADD04_
56 #define IUTEST_FLAG(name) IIUT_FLAG(name)
62 #define IIUT_FLAG(name) TestEnv::name()
68 #if IUTEST_HAS_LIB && IUTEST_HAS_EXTERN_TEMPLATE
70 namespace iutest {
class Environment; }
72 IUTEST_PRAGMA_EXTERN_TEMPLATE_WARN_DISABLE_BEGIN()
74 extern template class ::std::vector< ::
iutest::Environment* >;
76 IUTEST_PRAGMA_EXTERN_TEMPLATE_WARN_DISABLE_END()
91 detail::GetEnvironmentVariable(name, var);
104 virtual void SetUp() {}
109 struct should_be_SetUp {};
131 m_test_flags = TestFlag::GetInstance().m_test_flags;
135 TestFlag::GetInstance().m_test_flags = m_test_flags;
178 #if defined(_MSC_VER)
199 static void SetFlag(
int enable,
int mask=-1)
201 GetInstance().m_test_flags |= enable;
202 GetInstance().m_test_flags &= mask;
209 static bool IsEnableFlag(
int flag) {
return (GetInstance().m_test_flags & flag) ? true :
false; }
215 typedef Fragment<KIND> _Myt;
218 Fragment(
bool enabled) {
SetFlag(KIND, enabled ? -1 : ~KIND); }
219 _Myt& operator = (
bool enabled) {
SetFlag(KIND, enabled ? -1 : ~KIND);
return *
this; }
225 #if defined(IUTEST_NO_PRIVATE_IN_AGGREGATE)
226 friend class ScopedGuard;
233 class TestPartResultReporterInterface;
240 typedef ::std::vector<Environment*> iuEnvironmentList;
247 typedef TestFlag::Fragment<TestFlag::SHUFFLE_TESTS> shuffle;
248 typedef TestFlag::Fragment<TestFlag::RUN_DISABLED_TESTS> also_run_disabled_tests;
249 typedef TestFlag::Fragment<TestFlag::BREAK_ON_FAILURE> break_on_failure;
250 typedef TestFlag::Fragment<TestFlag::CATCH_EXCEPTION> catch_exceptions;
251 typedef TestFlag::Fragment<TestFlag::THROW_ON_FAILURE> throw_on_failure;
252 typedef TestFlag::Fragment<TestFlag::WARNING_INTO_ERROR> warning_into_error;
253 typedef TestFlag::Fragment<TestFlag::PRINT_TIME> print_time;
254 typedef TestFlag::Fragment<TestFlag::SHOW_TESTS_LIST> list_tests;
255 typedef TestFlag::Fragment<TestFlag::SHOW_TESTS_LIST_WITH_WHERE> list_tests_with_where;
257 typedef TestFlag::Fragment<TestFlag::CATCH_EXCEPTION_EACH> catch_exceptions_each;
258 typedef TestFlag::Fragment<TestFlag::CATCH_EXCEPTION_GLOBAL> catch_exceptions_global;
260 typedef TestFlag::Fragment<TestFlag::FILELOCATION_STYLE_MSVC> file_location_style_msvc;
261 typedef TestFlag::Fragment<TestFlag::VERBOSE> verbose;
271 typedef class RandomSeedSet
275 RandomSeedSet(
unsigned int seed) { init_random(seed); }
276 RandomSeedSet& operator = (
unsigned int seed) { init_random(seed);
return *
this; }
284 typedef class RepeatCountSet
288 RepeatCountSet(
int count) { set_repeat_count(count); }
289 RepeatCountSet& operator = (
int count) { set_repeat_count(count);
return *
this; }
293 #if defined(IUTEST_NO_PRIVATE_IN_AGGREGATE)
294 friend class RandomSeedSet;
295 friend class RepeatCountSet;
304 StateVariable& operator = (
const T& rhs) { m_value = rhs; m_dirty =
true;
return *
this; }
305 operator const T& ()
const {
return m_value; }
306 const T& operator ()()
const {
return m_value; }
307 bool is_dirty()
const {
return m_dirty; }
308 void flush() { m_dirty =
false; }
309 T& get() {
return m_value; }
310 const T& get()
const {
return m_value; }
318 , m_current_random_seed(0)
319 , m_before_origin_random_seed(0)
321 , m_testpartresult_reporter(NULL)
323 unsigned int m_random_seed;
324 unsigned int m_current_random_seed;
325 unsigned int m_before_origin_random_seed;
328 ::std::string m_test_filter;
329 ::std::string m_flagfile;
330 #if IUTEST_HAS_STREAM_RESULT
333 ::std::string m_default_package_name;
334 detail::iuRandom m_genrand;
335 iuEnvironmentList m_environment_list;
338 #if IUTEST_HAS_STRINGSTREAM || IUTEST_HAS_STRSTREAM
339 iu_stringstream m_ostream_formatter;
341 ::std::string m_locale_ctype;
344 static Variable& get_vars() {
static Variable sVars;
return sVars; }
347 static const char* get_output_option_c_str() {
return get_vars().m_output_option.get().c_str(); }
348 #if IUTEST_HAS_STREAM_RESULT
349 static const char* get_stream_result_to_c_str() {
return get_vars().m_stream_result_to.get().c_str(); }
353 static detail::iuRandom&
genrand() {
return get_vars().m_genrand; }
359 static const char*
test_filter() {
return get_vars().m_test_filter.c_str(); }
360 static const char*
get_flagfile() {
return get_vars().m_flagfile.c_str(); }
361 #if IUTEST_HAS_STREAM_RESULT
364 #if IUTEST_HAS_STRINGSTREAM || IUTEST_HAS_STRSTREAM
365 static void global_ostream_copyfmt(iu_ostream& os) { os.copyfmt(get_vars().m_ostream_formatter); }
367 static const char*
get_locale_ctype() {
return get_vars().m_locale_ctype.c_str(); }
368 static bool is_specific_locale_ctype() {
return !get_vars().m_locale_ctype.empty(); }
384 return get_vars().m_testpartresult_reporter;
387 static void SetGlobalTestPartResultReporter(TestPartResultReporterInterface* ptr)
389 get_vars().m_testpartresult_reporter = ptr;
392 static bool has_output_option()
394 return !get_vars().m_output_option.get().empty();
397 static bool is_output_option_dirty()
399 return get_vars().m_output_option.is_dirty();
402 static void flush_output_option()
404 get_vars().m_output_option.flush();
411 static void init_random(
unsigned int seed)
413 get_vars().m_random_seed = seed;
419 static void set_repeat_count(
int count)
421 get_vars().m_repeat_count = count;
427 static void set_test_filter(
const char* str)
429 get_vars().m_test_filter = str == NULL ?
"*" : str;
436 static void set_flagfile_path(
const char* str)
438 get_vars().m_flagfile = str;
444 static void set_flagfile(
const char* str)
446 ParseFlagFileOption(str);
450 #if IUTEST_HAS_STREAM_RESULT
454 static void set_stream_result_to(
const char* str)
456 get_vars().m_stream_result_to = detail::NullableString(str);
463 static const char* get_color_option()
482 static void set_color_option(
const char* str)
484 ParseColorOption(str);
490 static void set_output_option(
const char* str)
492 get_vars().m_output_option = detail::NullableString(str);
498 static void set_default_package_name(
const char* str)
500 get_vars().m_default_package_name = detail::NullableString(str);
506 static void set_locale_ctype(
const char* str)
508 get_vars().m_locale_ctype = detail::NullableString(str);
512 typedef const char* (*pfnOptionStringGet)();
513 typedef void(*pfnOptionStringSet)(
const char*);
514 template<pfnOptionStringGet G, pfnOptionStringSet S>
517 typedef OptionString<G, S> _Myt;
518 typedef const _Myt& _Argt;
520 ::std::string m_option;
522 friend bool operator == (
const char* c_str_, _Argt rhs) {
return rhs.m_option == c_str_; }
523 friend bool operator == (const ::std::string& str, _Argt rhs) {
return rhs.m_option == str; }
524 friend bool operator == (_Argt lhs,
const char* c_str_) {
return lhs.m_option == c_str_; }
525 friend bool operator == (_Argt lhs, const ::std::string& str) {
return lhs.m_option == str; }
526 friend bool operator != (
const char* c_str_, _Argt rhs) {
return rhs.m_option != c_str_; }
527 friend bool operator != (const ::std::string& str, _Argt rhs) {
return rhs.m_option != str; }
528 friend bool operator != (_Argt lhs,
const char* c_str_) {
return lhs.m_option != c_str_; }
529 friend bool operator != (_Argt lhs, const ::std::string& str) {
return lhs.m_option != str; }
531 operator ::std::string()
const {
return m_option; }
533 bool empty()
const {
return m_option.empty(); }
534 const char* c_str()
const {
return m_option.c_str(); }
535 size_t length()
const {
return m_option.length(); }
541 const _Myt& operator = (
const char* c_str_)
543 m_option = detail::NullableString(c_str_);
547 const _Myt& operator = (const ::std::string& str)
560 typedef OptionString<get_color_option, set_color_option> color;
566 typedef OptionString<test_filter, set_test_filter> filter;
572 typedef OptionString<get_flagfile, set_flagfile> flagfile;
578 typedef OptionString<get_output_option_c_str, set_output_option> output;
580 #if IUTEST_HAS_STREAM_RESULT
585 typedef OptionString<get_stream_result_to_c_str, set_stream_result_to> stream_result_to;
592 typedef OptionString<get_default_package_name, set_default_package_name> default_package_name;
598 typedef OptionString<get_locale_ctype, set_locale_ctype> locale_ctype;
600 #if IUTEST_HAS_STRINGSTREAM || IUTEST_HAS_STRSTREAM
605 typedef class OStreamFormatter :
public iu_stringstream
607 IUTEST_WORKAROUND_MSC_STLSTREAM_C4250()
611 copyfmt(get_vars().m_ostream_formatter);
613 virtual ~OStreamFormatter()
615 get_vars().m_ostream_formatter.copyfmt(*
this);
619 #if defined(IUTEST_NO_PRIVATE_IN_AGGREGATE)
620 friend class OStreamFormatter;
626 static iuEnvironmentList& environments() {
return get_vars().m_environment_list; }
640 environments().push_back(env);
655 iuEnvironmentList& list = environments();
656 iuEnvironmentList::iterator it = ::std::find(list.begin(), list.end(), env);
657 if( it == list.end() )
677 for( iuEnvironmentList::iterator it=environments().begin(); it != environments().end(); )
680 it = environments().erase(it);
690 template<
typename CharType>
691 static void ParseCommandLine(
int* pargc, CharType** argv)
699 for(
int i=0; i < argc; )
701 if( ParseCommandLineElem(argv[i]) )
705 for(
int k=i; k < argc; ++k )
707 CharType* tmp = argv[k];
724 template<
typename CharType>
725 static void ParseCommandLine(::std::vector< ::std::basic_string<CharType> >& argv)
727 typedef ::std::vector< ::std::basic_string<CharType> > argv_t;
728 for(
typename argv_t::iterator it = argv.begin(); it != argv.end(); )
730 if( ParseCommandLineElem(it->c_str()) )
745 template<
typename CharType>
746 static bool ParseCommandLineElem(CharType* argv)
748 typedef typename detail::mbs_ptr<CharType> formatter;
750 formatter argv_format;
751 const char* str = argv_format.ptr(argv);
752 return ParseCommandLineElemA(str);
754 static bool ParseCommandLineElemA(
const char* str);
755 static bool ParseIutestOptionCommandLineElemA(
const char* str);
756 static bool SetFlag(
int enable,
int mask = -1);
762 static void LoadEnvironmentVariable();
773 static inline const char* ParseOptionSettingStr(
const char* opt)
775 const char* eq = strchr(opt,
'=');
785 static bool ParseColorOption(
const char* option);
790 static bool ParseOutputOption(
const char* option);
795 static bool ParseFileLocationOption(
const char* option);
800 static bool ParseFilterOption(
const char* option);
805 static bool ParseFlagFileOption(
const char* option);
814 static bool ParseYesNoFlagCommandLine(
const char* str,
TestFlag::Kind flag,
int def);
823 static int ParseYesNoOption(
const char* option);
828 static bool IsYes(
const char* option);
832 static bool IsNo(
const char* option);
835 friend class UnitTest;
841 class iu_global_format_stringstream :
public iu_stringstream
843 IUTEST_WORKAROUND_MSC_STLSTREAM_C4250()
847 #if IUTEST_HAS_STRINGSTREAM || IUTEST_HAS_STRSTREAM
848 TestEnv::global_ostream_copyfmt(*
this);
852 : iu_stringstream(str)
854 #if IUTEST_HAS_STRINGSTREAM || IUTEST_HAS_STRSTREAM
855 TestEnv::global_ostream_copyfmt(*
this);
859 : iu_stringstream(str)
861 #if IUTEST_HAS_STRINGSTREAM || IUTEST_HAS_STRSTREAM
862 TestEnv::global_ostream_copyfmt(*
this);
870 return os << value.get();
877 # include "impl/iutest_env.ipp"
環境セットクラス
Definition: iutest_env.hpp:102
virtual void SetUp()
事前処理
Definition: iutest_env.hpp:105
virtual void TearDown()
事後処理
Definition: iutest_env.hpp:106
ファイル処理クラスインターフェイス
Definition: iutest_file.hpp:173
Definition: iutest_env.hpp:301
テスト環境
Definition: iutest_env.hpp:240
static const char * get_default_package_name()
root package オプション
Definition: iutest_env.hpp:359
static const char * get_locale_ctype()
ctype locale オプション
Definition: iutest_env.hpp:368
static Environment * ReleaseGlobalTestEnvironment(Environment *env)
グローバル環境セットクラスの削除
Definition: iutest_env.hpp:650
static const char * get_flagfile()
flag file
Definition: iutest_env.hpp:361
static const StateVariable< ::std::string > & get_output_option()
出力オプション
Definition: iutest_env.hpp:358
::std::string get_report_junit_xml_filepath()
junit xml 出力パスを取得
static const char * test_filter()
フィルター文字列
Definition: iutest_env.hpp:360
static int get_repeat_count()
繰り返し回数
Definition: iutest_env.hpp:357
static detail::iuRandom & genrand()
乱数生成器
Definition: iutest_env.hpp:354
static Environment * AddGlobalTestEnvironment(Environment *env)
グローバル環境セットクラスの追加
Definition: iutest_env.hpp:635
static bool LoadFlagFile()
フラグファイルをロード
static unsigned int current_random_seed()
乱数シード
Definition: iutest_env.hpp:356
static unsigned int get_random_seed()
乱数シード
Definition: iutest_env.hpp:355
::std::string AddDefaultPackageName(const char *testsuite_name)
default package name を追加
::std::string get_report_xml_filepath()
xml 出力パスを取得
イベントリスナーの管理クラス
Definition: iutest_listener.hpp:169
テストフラグ
Definition: iutest_env.hpp:118
Kind
フラグ
Definition: iutest_env.hpp:144
@ SHOW_TESTS_LIST
テストのリスト表示
Definition: iutest_env.hpp:170
@ CONSOLE_COLOR_ANSI
エスケープシーケンスで出力
Definition: iutest_env.hpp:155
@ FILTERING_TESTS
テストのフィルタリング
Definition: iutest_env.hpp:147
@ SHOW_FEATURE
機能の出力
Definition: iutest_env.hpp:167
@ CONSOLE_COLOR_OFF
色つき出力OFF
Definition: iutest_env.hpp:154
@ SHOW_INFO_MASK
情報表示系マスク
Definition: iutest_env.hpp:174
@ BREAK_ON_FAILURE
テスト失敗時にブレーク
Definition: iutest_env.hpp:149
@ MASK
マスク
Definition: iutest_env.hpp:176
@ WARNING_INTO_ERROR
警告をエラーとする
Definition: iutest_env.hpp:151
@ PRINT_TIME
経過時間の出力
Definition: iutest_env.hpp:157
@ VERBOSE
verbose
Definition: iutest_env.hpp:159
@ CATCH_EXCEPTION_EACH
例外を catch する(TestInfo)
Definition: iutest_env.hpp:161
@ DEFAULT
デフォルト
Definition: iutest_env.hpp:182
@ CATCH_EXCEPTION_GLOBAL
例外を catch する(UnitTest)
Definition: iutest_env.hpp:162
@ CATCH_EXCEPTION
例外を catch する
Definition: iutest_env.hpp:163
@ THROW_ON_FAILURE
致命的な失敗時に throw する
Definition: iutest_env.hpp:150
@ SHOW_VERSION
バージョン表示
Definition: iutest_env.hpp:166
@ SHOW_HELP
ヘルプ表示
Definition: iutest_env.hpp:165
@ CONSOLE_COLOR_ON
色つき出力ON
Definition: iutest_env.hpp:153
@ RUN_DISABLED_TESTS
DISABLED テストも実行
Definition: iutest_env.hpp:146
@ SHUFFLE_TESTS
シャッフルテスト
Definition: iutest_env.hpp:145
@ SHOW_SPEC
Specの出力
Definition: iutest_env.hpp:168
@ FILELOCATION_STYLE_MSVC
ファイル/行出力スタイルを Visual Studio スタイルにする
Definition: iutest_env.hpp:158
@ SHOW_TESTS_LIST_WITH_WHERE
テストのリスト表示(with where)
Definition: iutest_env.hpp:171
@ SHOW_MASK
表示系マスク
Definition: iutest_env.hpp:175
static bool IsEnableFlag(int flag)
フラグが立っているかどうか
Definition: iutest_env.hpp:210
static void SetFlag(int enable, int mask=-1)
フラグのビット操作
Definition: iutest_env.hpp:200
テスト結果の通知処理インターフェイス
Definition: iutest_result.hpp:43
iris unit test 文字コード対応 ファイル
#define IUTEST_CXX_NOEXCEPT_SPEC
noexcept specification definition
Definition: iutest_compiler.hpp:811
iris unit test イベントリスナー 定義 ファイル
#define IUTEST_PP_DISALLOW_COPY_AND_ASSIGN(TypeName)
コピー禁止定義
Definition: iutest_pp.hpp:31
iris unit test 乱数生成器 定義 ファイル
iutest root namespace
Definition: iutest_charcode.hpp:33
inline ::std::string EnvironmentString(const char *name)
環境変数の取得
Definition: iutest_env.hpp:89