1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236 |
- #ifndef GTEST_INCLUDE_GTEST_GTEST_H_
- #define GTEST_INCLUDE_GTEST_GTEST_H_
- #include <limits>
- #include <ostream>
- #include <vector>
- #include "gtest/internal/gtest-internal.h"
- #include "gtest/internal/gtest-string.h"
- #include "gtest/gtest-death-test.h"
- #include "gtest/gtest-message.h"
- #include "gtest/gtest-param-test.h"
- #include "gtest/gtest-printers.h"
- #include "gtest/gtest_prod.h"
- #include "gtest/gtest-test-part.h"
- #include "gtest/gtest-typed-test.h"
- namespace testing {
- GTEST_DECLARE_bool_(also_run_disabled_tests);
- GTEST_DECLARE_bool_(break_on_failure);
- GTEST_DECLARE_bool_(catch_exceptions);
- GTEST_DECLARE_string_(color);
- GTEST_DECLARE_string_(filter);
- GTEST_DECLARE_bool_(list_tests);
- GTEST_DECLARE_string_(output);
- GTEST_DECLARE_bool_(print_time);
- GTEST_DECLARE_int32_(random_seed);
- GTEST_DECLARE_int32_(repeat);
- GTEST_DECLARE_bool_(show_internal_stack_frames);
- GTEST_DECLARE_bool_(shuffle);
- GTEST_DECLARE_int32_(stack_trace_depth);
- GTEST_DECLARE_bool_(throw_on_failure);
- GTEST_DECLARE_string_(stream_result_to);
- const int kMaxStackTraceDepth = 100;
- namespace internal {
- class AssertHelper;
- class DefaultGlobalTestPartResultReporter;
- class ExecDeathTest;
- class NoExecDeathTest;
- class FinalSuccessChecker;
- class GTestFlagSaver;
- class StreamingListenerTest;
- class TestResultAccessor;
- class TestEventListenersAccessor;
- class TestEventRepeater;
- class UnitTestRecordPropertyTestHelper;
- class WindowsDeathTest;
- class UnitTestImpl* GetUnitTestImpl();
- void ReportFailureInUnknownLocation(TestPartResult::Type result_type,
- const std::string& message);
- }
- class Test;
- class TestCase;
- class TestInfo;
- class UnitTest;
- class GTEST_API_ AssertionResult {
- public:
-
-
- AssertionResult(const AssertionResult& other);
- GTEST_DISABLE_MSC_WARNINGS_PUSH_(4800 )
-
-
-
-
-
-
-
- template <typename T>
- explicit AssertionResult(
- const T& success,
- typename internal::EnableIf<
- !internal::ImplicitlyConvertible<T, AssertionResult>::value>::type*
- = NULL)
- : success_(success) {}
- GTEST_DISABLE_MSC_WARNINGS_POP_()
-
- AssertionResult& operator=(AssertionResult other) {
- swap(other);
- return *this;
- }
-
- operator bool() const { return success_; }
-
- AssertionResult operator!() const;
-
-
-
-
- const char* message() const {
- return message_.get() != NULL ? message_->c_str() : "";
- }
-
-
- const char* failure_message() const { return message(); }
-
- template <typename T> AssertionResult& operator<<(const T& value) {
- AppendMessage(Message() << value);
- return *this;
- }
-
-
- AssertionResult& operator<<(
- ::std::ostream& (*basic_manipulator)(::std::ostream& stream)) {
- AppendMessage(Message() << basic_manipulator);
- return *this;
- }
- private:
-
- void AppendMessage(const Message& a_message) {
- if (message_.get() == NULL)
- message_.reset(new ::std::string);
- message_->append(a_message.GetString().c_str());
- }
-
- void swap(AssertionResult& other);
-
- bool success_;
-
-
-
-
- internal::scoped_ptr< ::std::string> message_;
- };
- GTEST_API_ AssertionResult AssertionSuccess();
- GTEST_API_ AssertionResult AssertionFailure();
- GTEST_API_ AssertionResult AssertionFailure(const Message& msg);
- class GTEST_API_ Test {
- public:
- friend class TestInfo;
-
-
- typedef internal::SetUpTestCaseFunc SetUpTestCaseFunc;
- typedef internal::TearDownTestCaseFunc TearDownTestCaseFunc;
-
- virtual ~Test();
-
-
-
-
-
-
- static void SetUpTestCase() {}
-
-
-
-
-
-
- static void TearDownTestCase() {}
-
- static bool HasFatalFailure();
-
- static bool HasNonfatalFailure();
-
-
- static bool HasFailure() { return HasFatalFailure() || HasNonfatalFailure(); }
-
-
-
-
-
-
-
-
-
-
-
-
-
- static void RecordProperty(const std::string& key, const std::string& value);
- static void RecordProperty(const std::string& key, int value);
- protected:
-
- Test();
-
- virtual void SetUp();
-
- virtual void TearDown();
- private:
-
-
- static bool HasSameFixtureClass();
-
-
-
-
-
-
- virtual void TestBody() = 0;
-
- void Run();
-
-
- void DeleteSelf_() { delete this; }
- const internal::scoped_ptr< GTEST_FLAG_SAVER_ > gtest_flag_saver_;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- struct Setup_should_be_spelled_SetUp {};
- virtual Setup_should_be_spelled_SetUp* Setup() { return NULL; }
-
- GTEST_DISALLOW_COPY_AND_ASSIGN_(Test);
- };
- typedef internal::TimeInMillis TimeInMillis;
- class TestProperty {
- public:
-
-
-
- TestProperty(const std::string& a_key, const std::string& a_value) :
- key_(a_key), value_(a_value) {
- }
-
- const char* key() const {
- return key_.c_str();
- }
-
- const char* value() const {
- return value_.c_str();
- }
-
- void SetValue(const std::string& new_value) {
- value_ = new_value;
- }
- private:
-
- std::string key_;
-
- std::string value_;
- };
- class GTEST_API_ TestResult {
- public:
-
- TestResult();
-
- ~TestResult();
-
-
- int total_part_count() const;
-
- int test_property_count() const;
-
- bool Passed() const { return !Failed(); }
-
- bool Failed() const;
-
- bool HasFatalFailure() const;
-
- bool HasNonfatalFailure() const;
-
- TimeInMillis elapsed_time() const { return elapsed_time_; }
-
-
-
- const TestPartResult& GetTestPartResult(int i) const;
-
-
-
- const TestProperty& GetTestProperty(int i) const;
- private:
- friend class TestInfo;
- friend class TestCase;
- friend class UnitTest;
- friend class internal::DefaultGlobalTestPartResultReporter;
- friend class internal::ExecDeathTest;
- friend class internal::TestResultAccessor;
- friend class internal::UnitTestImpl;
- friend class internal::WindowsDeathTest;
-
- const std::vector<TestPartResult>& test_part_results() const {
- return test_part_results_;
- }
-
- const std::vector<TestProperty>& test_properties() const {
- return test_properties_;
- }
-
- void set_elapsed_time(TimeInMillis elapsed) { elapsed_time_ = elapsed; }
-
-
-
-
-
-
- void RecordProperty(const std::string& xml_element,
- const TestProperty& test_property);
-
-
-
- static bool ValidateTestProperty(const std::string& xml_element,
- const TestProperty& test_property);
-
- void AddTestPartResult(const TestPartResult& test_part_result);
-
- int death_test_count() const { return death_test_count_; }
-
- int increment_death_test_count() { return ++death_test_count_; }
-
- void ClearTestPartResults();
-
- void Clear();
-
-
- internal::Mutex test_properites_mutex_;
-
- std::vector<TestPartResult> test_part_results_;
-
- std::vector<TestProperty> test_properties_;
-
- int death_test_count_;
-
- TimeInMillis elapsed_time_;
-
- GTEST_DISALLOW_COPY_AND_ASSIGN_(TestResult);
- };
- class GTEST_API_ TestInfo {
- public:
-
-
- ~TestInfo();
-
- const char* test_case_name() const { return test_case_name_.c_str(); }
-
- const char* name() const { return name_.c_str(); }
-
-
- const char* type_param() const {
- if (type_param_.get() != NULL)
- return type_param_->c_str();
- return NULL;
- }
-
-
- const char* value_param() const {
- if (value_param_.get() != NULL)
- return value_param_->c_str();
- return NULL;
- }
-
- const char* file() const { return location_.file.c_str(); }
-
- int line() const { return location_.line; }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- bool should_run() const { return should_run_; }
-
- bool is_reportable() const {
-
-
-
- return matches_filter_;
- }
-
- const TestResult* result() const { return &result_; }
- private:
- #if GTEST_HAS_DEATH_TEST
- friend class internal::DefaultDeathTestFactory;
- #endif
- friend class Test;
- friend class TestCase;
- friend class internal::UnitTestImpl;
- friend class internal::StreamingListenerTest;
- friend TestInfo* internal::MakeAndRegisterTestInfo(
- const char* test_case_name,
- const char* name,
- const char* type_param,
- const char* value_param,
- internal::CodeLocation code_location,
- internal::TypeId fixture_class_id,
- Test::SetUpTestCaseFunc set_up_tc,
- Test::TearDownTestCaseFunc tear_down_tc,
- internal::TestFactoryBase* factory);
-
-
- TestInfo(const std::string& test_case_name,
- const std::string& name,
- const char* a_type_param,
- const char* a_value_param,
- internal::CodeLocation a_code_location,
- internal::TypeId fixture_class_id,
- internal::TestFactoryBase* factory);
-
-
- int increment_death_test_count() {
- return result_.increment_death_test_count();
- }
-
-
- void Run();
- static void ClearTestResult(TestInfo* test_info) {
- test_info->result_.Clear();
- }
-
- const std::string test_case_name_;
- const std::string name_;
-
-
- const internal::scoped_ptr<const ::std::string> type_param_;
-
-
- const internal::scoped_ptr<const ::std::string> value_param_;
- internal::CodeLocation location_;
- const internal::TypeId fixture_class_id_;
- bool should_run_;
- bool is_disabled_;
- bool matches_filter_;
-
- internal::TestFactoryBase* const factory_;
-
-
-
- TestResult result_;
- GTEST_DISALLOW_COPY_AND_ASSIGN_(TestInfo);
- };
- class GTEST_API_ TestCase {
- public:
-
-
-
-
-
-
-
-
-
-
-
-
- TestCase(const char* name, const char* a_type_param,
- Test::SetUpTestCaseFunc set_up_tc,
- Test::TearDownTestCaseFunc tear_down_tc);
-
- virtual ~TestCase();
-
- const char* name() const { return name_.c_str(); }
-
-
- const char* type_param() const {
- if (type_param_.get() != NULL)
- return type_param_->c_str();
- return NULL;
- }
-
- bool should_run() const { return should_run_; }
-
- int successful_test_count() const;
-
- int failed_test_count() const;
-
- int reportable_disabled_test_count() const;
-
- int disabled_test_count() const;
-
- int reportable_test_count() const;
-
- int test_to_run_count() const;
-
- int total_test_count() const;
-
- bool Passed() const { return !Failed(); }
-
- bool Failed() const { return failed_test_count() > 0; }
-
- TimeInMillis elapsed_time() const { return elapsed_time_; }
-
-
- const TestInfo* GetTestInfo(int i) const;
-
-
- const TestResult& ad_hoc_test_result() const { return ad_hoc_test_result_; }
- private:
- friend class Test;
- friend class internal::UnitTestImpl;
-
- std::vector<TestInfo*>& test_info_list() { return test_info_list_; }
-
- const std::vector<TestInfo*>& test_info_list() const {
- return test_info_list_;
- }
-
-
- TestInfo* GetMutableTestInfo(int i);
-
- void set_should_run(bool should) { should_run_ = should; }
-
-
- void AddTestInfo(TestInfo * test_info);
-
- void ClearResult();
-
- static void ClearTestCaseResult(TestCase* test_case) {
- test_case->ClearResult();
- }
-
- void Run();
-
-
- void RunSetUpTestCase() { (*set_up_tc_)(); }
-
-
- void RunTearDownTestCase() { (*tear_down_tc_)(); }
-
- static bool TestPassed(const TestInfo* test_info) {
- return test_info->should_run() && test_info->result()->Passed();
- }
-
- static bool TestFailed(const TestInfo* test_info) {
- return test_info->should_run() && test_info->result()->Failed();
- }
-
-
- static bool TestReportableDisabled(const TestInfo* test_info) {
- return test_info->is_reportable() && test_info->is_disabled_;
- }
-
- static bool TestDisabled(const TestInfo* test_info) {
- return test_info->is_disabled_;
- }
-
- static bool TestReportable(const TestInfo* test_info) {
- return test_info->is_reportable();
- }
-
- static bool ShouldRunTest(const TestInfo* test_info) {
- return test_info->should_run();
- }
-
- void ShuffleTests(internal::Random* random);
-
- void UnshuffleTests();
-
- std::string name_;
-
-
- const internal::scoped_ptr<const ::std::string> type_param_;
-
-
- std::vector<TestInfo*> test_info_list_;
-
-
-
- std::vector<int> test_indices_;
-
- Test::SetUpTestCaseFunc set_up_tc_;
-
- Test::TearDownTestCaseFunc tear_down_tc_;
-
- bool should_run_;
-
- TimeInMillis elapsed_time_;
-
-
- TestResult ad_hoc_test_result_;
-
- GTEST_DISALLOW_COPY_AND_ASSIGN_(TestCase);
- };
- class Environment {
- public:
-
- virtual ~Environment() {}
-
- virtual void SetUp() {}
-
- virtual void TearDown() {}
- private:
-
-
- struct Setup_should_be_spelled_SetUp {};
- virtual Setup_should_be_spelled_SetUp* Setup() { return NULL; }
- };
- class TestEventListener {
- public:
- virtual ~TestEventListener() {}
-
- virtual void OnTestProgramStart(const UnitTest& unit_test) = 0;
-
-
-
- virtual void OnTestIterationStart(const UnitTest& unit_test,
- int iteration) = 0;
-
- virtual void OnEnvironmentsSetUpStart(const UnitTest& unit_test) = 0;
-
- virtual void OnEnvironmentsSetUpEnd(const UnitTest& unit_test) = 0;
-
- virtual void OnTestCaseStart(const TestCase& test_case) = 0;
-
- virtual void OnTestStart(const TestInfo& test_info) = 0;
-
- virtual void OnTestPartResult(const TestPartResult& test_part_result) = 0;
-
- virtual void OnTestEnd(const TestInfo& test_info) = 0;
-
- virtual void OnTestCaseEnd(const TestCase& test_case) = 0;
-
- virtual void OnEnvironmentsTearDownStart(const UnitTest& unit_test) = 0;
-
- virtual void OnEnvironmentsTearDownEnd(const UnitTest& unit_test) = 0;
-
- virtual void OnTestIterationEnd(const UnitTest& unit_test,
- int iteration) = 0;
-
- virtual void OnTestProgramEnd(const UnitTest& unit_test) = 0;
- };
- class EmptyTestEventListener : public TestEventListener {
- public:
- virtual void OnTestProgramStart(const UnitTest& ) {}
- virtual void OnTestIterationStart(const UnitTest& ,
- int ) {}
- virtual void OnEnvironmentsSetUpStart(const UnitTest& ) {}
- virtual void OnEnvironmentsSetUpEnd(const UnitTest& ) {}
- virtual void OnTestCaseStart(const TestCase& ) {}
- virtual void OnTestStart(const TestInfo& ) {}
- virtual void OnTestPartResult(const TestPartResult& ) {}
- virtual void OnTestEnd(const TestInfo& ) {}
- virtual void OnTestCaseEnd(const TestCase& ) {}
- virtual void OnEnvironmentsTearDownStart(const UnitTest& ) {}
- virtual void OnEnvironmentsTearDownEnd(const UnitTest& ) {}
- virtual void OnTestIterationEnd(const UnitTest& ,
- int ) {}
- virtual void OnTestProgramEnd(const UnitTest& ) {}
- };
- class GTEST_API_ TestEventListeners {
- public:
- TestEventListeners();
- ~TestEventListeners();
-
-
-
- void Append(TestEventListener* listener);
-
-
-
- TestEventListener* Release(TestEventListener* listener);
-
-
-
-
-
- TestEventListener* default_result_printer() const {
- return default_result_printer_;
- }
-
-
-
-
-
-
-
- TestEventListener* default_xml_generator() const {
- return default_xml_generator_;
- }
- private:
- friend class TestCase;
- friend class TestInfo;
- friend class internal::DefaultGlobalTestPartResultReporter;
- friend class internal::NoExecDeathTest;
- friend class internal::TestEventListenersAccessor;
- friend class internal::UnitTestImpl;
-
-
- TestEventListener* repeater();
-
-
-
-
-
- void SetDefaultResultPrinter(TestEventListener* listener);
-
-
-
-
-
- void SetDefaultXmlGenerator(TestEventListener* listener);
-
-
- bool EventForwardingEnabled() const;
- void SuppressEventForwarding();
-
- internal::TestEventRepeater* repeater_;
-
- TestEventListener* default_result_printer_;
-
- TestEventListener* default_xml_generator_;
-
- GTEST_DISALLOW_COPY_AND_ASSIGN_(TestEventListeners);
- };
- class GTEST_API_ UnitTest {
- public:
-
-
-
- static UnitTest* GetInstance();
-
-
-
-
-
-
- int Run() GTEST_MUST_USE_RESULT_;
-
-
- const char* original_working_dir() const;
-
-
- const TestCase* current_test_case() const
- GTEST_LOCK_EXCLUDED_(mutex_);
-
-
- const TestInfo* current_test_info() const
- GTEST_LOCK_EXCLUDED_(mutex_);
-
- int random_seed() const;
- #if GTEST_HAS_PARAM_TEST
-
-
-
-
- internal::ParameterizedTestCaseRegistry& parameterized_test_registry()
- GTEST_LOCK_EXCLUDED_(mutex_);
- #endif
-
- int successful_test_case_count() const;
-
- int failed_test_case_count() const;
-
- int total_test_case_count() const;
-
-
- int test_case_to_run_count() const;
-
- int successful_test_count() const;
-
- int failed_test_count() const;
-
- int reportable_disabled_test_count() const;
-
- int disabled_test_count() const;
-
- int reportable_test_count() const;
-
- int total_test_count() const;
-
- int test_to_run_count() const;
-
-
- TimeInMillis start_timestamp() const;
-
- TimeInMillis elapsed_time() const;
-
- bool Passed() const;
-
-
- bool Failed() const;
-
-
- const TestCase* GetTestCase(int i) const;
-
-
- const TestResult& ad_hoc_test_result() const;
-
-
- TestEventListeners& listeners();
- private:
-
-
-
-
-
-
-
-
-
- Environment* AddEnvironment(Environment* env);
-
-
-
-
- void AddTestPartResult(TestPartResult::Type result_type,
- const char* file_name,
- int line_number,
- const std::string& message,
- const std::string& os_stack_trace)
- GTEST_LOCK_EXCLUDED_(mutex_);
-
-
-
-
-
- void RecordProperty(const std::string& key, const std::string& value);
-
-
- TestCase* GetMutableTestCase(int i);
-
- internal::UnitTestImpl* impl() { return impl_; }
- const internal::UnitTestImpl* impl() const { return impl_; }
-
-
- friend class Test;
- friend class internal::AssertHelper;
- friend class internal::ScopedTrace;
- friend class internal::StreamingListenerTest;
- friend class internal::UnitTestRecordPropertyTestHelper;
- friend Environment* AddGlobalTestEnvironment(Environment* env);
- friend internal::UnitTestImpl* internal::GetUnitTestImpl();
- friend void internal::ReportFailureInUnknownLocation(
- TestPartResult::Type result_type,
- const std::string& message);
-
- UnitTest();
-
- virtual ~UnitTest();
-
-
- void PushGTestTrace(const internal::TraceInfo& trace)
- GTEST_LOCK_EXCLUDED_(mutex_);
-
- void PopGTestTrace()
- GTEST_LOCK_EXCLUDED_(mutex_);
-
-
- mutable internal::Mutex mutex_;
-
-
-
-
- internal::UnitTestImpl* impl_;
-
- GTEST_DISALLOW_COPY_AND_ASSIGN_(UnitTest);
- };
- inline Environment* AddGlobalTestEnvironment(Environment* env) {
- return UnitTest::GetInstance()->AddEnvironment(env);
- }
- GTEST_API_ void InitGoogleTest(int* argc, char** argv);
- GTEST_API_ void InitGoogleTest(int* argc, wchar_t** argv);
- namespace internal {
- template <typename T1, typename T2>
- AssertionResult CmpHelperEQFailure(const char* lhs_expression,
- const char* rhs_expression,
- const T1& lhs, const T2& rhs) {
- return EqFailure(lhs_expression,
- rhs_expression,
- FormatForComparisonFailureMessage(lhs, rhs),
- FormatForComparisonFailureMessage(rhs, lhs),
- false);
- }
- template <typename T1, typename T2>
- AssertionResult CmpHelperEQ(const char* lhs_expression,
- const char* rhs_expression,
- const T1& lhs,
- const T2& rhs) {
- GTEST_DISABLE_MSC_WARNINGS_PUSH_(4389 )
- if (lhs == rhs) {
- return AssertionSuccess();
- }
- GTEST_DISABLE_MSC_WARNINGS_POP_()
- return CmpHelperEQFailure(lhs_expression, rhs_expression, lhs, rhs);
- }
- GTEST_API_ AssertionResult CmpHelperEQ(const char* lhs_expression,
- const char* rhs_expression,
- BiggestInt lhs,
- BiggestInt rhs);
- template <bool lhs_is_null_literal>
- class EqHelper {
- public:
-
- template <typename T1, typename T2>
- static AssertionResult Compare(const char* lhs_expression,
- const char* rhs_expression,
- const T1& lhs,
- const T2& rhs) {
- return CmpHelperEQ(lhs_expression, rhs_expression, lhs, rhs);
- }
-
-
-
-
-
-
- static AssertionResult Compare(const char* lhs_expression,
- const char* rhs_expression,
- BiggestInt lhs,
- BiggestInt rhs) {
- return CmpHelperEQ(lhs_expression, rhs_expression, lhs, rhs);
- }
- };
- template <>
- class EqHelper<true> {
- public:
-
-
-
-
- template <typename T1, typename T2>
- static AssertionResult Compare(
- const char* lhs_expression,
- const char* rhs_expression,
- const T1& lhs,
- const T2& rhs,
-
-
-
-
-
- typename EnableIf<!is_pointer<T2>::value>::type* = 0) {
- return CmpHelperEQ(lhs_expression, rhs_expression, lhs, rhs);
- }
-
-
- template <typename T>
- static AssertionResult Compare(
- const char* lhs_expression,
- const char* rhs_expression,
-
-
-
-
-
-
- Secret* ,
- T* rhs) {
-
- return CmpHelperEQ(lhs_expression, rhs_expression,
- static_cast<T*>(NULL), rhs);
- }
- };
- template <typename T1, typename T2>
- AssertionResult CmpHelperOpFailure(const char* expr1, const char* expr2,
- const T1& val1, const T2& val2,
- const char* op) {
- return AssertionFailure()
- << "Expected: (" << expr1 << ") " << op << " (" << expr2
- << "), actual: " << FormatForComparisonFailureMessage(val1, val2)
- << " vs " << FormatForComparisonFailureMessage(val2, val1);
- }
- #define GTEST_IMPL_CMP_HELPER_(op_name, op)\
- template <typename T1, typename T2>\
- AssertionResult CmpHelper##op_name(const char* expr1, const char* expr2, \
- const T1& val1, const T2& val2) {\
- if (val1 op val2) {\
- return AssertionSuccess();\
- } else {\
- return CmpHelperOpFailure(expr1, expr2, val1, val2, #op);\
- }\
- }\
- GTEST_API_ AssertionResult CmpHelper##op_name(\
- const char* expr1, const char* expr2, BiggestInt val1, BiggestInt val2)
- GTEST_IMPL_CMP_HELPER_(NE, !=);
- GTEST_IMPL_CMP_HELPER_(LE, <=);
- GTEST_IMPL_CMP_HELPER_(LT, <);
- GTEST_IMPL_CMP_HELPER_(GE, >=);
- GTEST_IMPL_CMP_HELPER_(GT, >);
- #undef GTEST_IMPL_CMP_HELPER_
- GTEST_API_ AssertionResult CmpHelperSTREQ(const char* s1_expression,
- const char* s2_expression,
- const char* s1,
- const char* s2);
- GTEST_API_ AssertionResult CmpHelperSTRCASEEQ(const char* s1_expression,
- const char* s2_expression,
- const char* s1,
- const char* s2);
- GTEST_API_ AssertionResult CmpHelperSTRNE(const char* s1_expression,
- const char* s2_expression,
- const char* s1,
- const char* s2);
- GTEST_API_ AssertionResult CmpHelperSTRCASENE(const char* s1_expression,
- const char* s2_expression,
- const char* s1,
- const char* s2);
- GTEST_API_ AssertionResult CmpHelperSTREQ(const char* s1_expression,
- const char* s2_expression,
- const wchar_t* s1,
- const wchar_t* s2);
- GTEST_API_ AssertionResult CmpHelperSTRNE(const char* s1_expression,
- const char* s2_expression,
- const wchar_t* s1,
- const wchar_t* s2);
- }
- GTEST_API_ AssertionResult IsSubstring(
- const char* needle_expr, const char* haystack_expr,
- const char* needle, const char* haystack);
- GTEST_API_ AssertionResult IsSubstring(
- const char* needle_expr, const char* haystack_expr,
- const wchar_t* needle, const wchar_t* haystack);
- GTEST_API_ AssertionResult IsNotSubstring(
- const char* needle_expr, const char* haystack_expr,
- const char* needle, const char* haystack);
- GTEST_API_ AssertionResult IsNotSubstring(
- const char* needle_expr, const char* haystack_expr,
- const wchar_t* needle, const wchar_t* haystack);
- GTEST_API_ AssertionResult IsSubstring(
- const char* needle_expr, const char* haystack_expr,
- const ::std::string& needle, const ::std::string& haystack);
- GTEST_API_ AssertionResult IsNotSubstring(
- const char* needle_expr, const char* haystack_expr,
- const ::std::string& needle, const ::std::string& haystack);
- #if GTEST_HAS_STD_WSTRING
- GTEST_API_ AssertionResult IsSubstring(
- const char* needle_expr, const char* haystack_expr,
- const ::std::wstring& needle, const ::std::wstring& haystack);
- GTEST_API_ AssertionResult IsNotSubstring(
- const char* needle_expr, const char* haystack_expr,
- const ::std::wstring& needle, const ::std::wstring& haystack);
- #endif
- namespace internal {
- template <typename RawType>
- AssertionResult CmpHelperFloatingPointEQ(const char* lhs_expression,
- const char* rhs_expression,
- RawType lhs_value,
- RawType rhs_value) {
- const FloatingPoint<RawType> lhs(lhs_value), rhs(rhs_value);
- if (lhs.AlmostEquals(rhs)) {
- return AssertionSuccess();
- }
- ::std::stringstream lhs_ss;
- lhs_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)
- << lhs_value;
- ::std::stringstream rhs_ss;
- rhs_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)
- << rhs_value;
- return EqFailure(lhs_expression,
- rhs_expression,
- StringStreamToString(&lhs_ss),
- StringStreamToString(&rhs_ss),
- false);
- }
- GTEST_API_ AssertionResult DoubleNearPredFormat(const char* expr1,
- const char* expr2,
- const char* abs_error_expr,
- double val1,
- double val2,
- double abs_error);
- class GTEST_API_ AssertHelper {
- public:
-
- AssertHelper(TestPartResult::Type type,
- const char* file,
- int line,
- const char* message);
- ~AssertHelper();
-
-
- void operator=(const Message& message) const;
- private:
-
-
-
-
- struct AssertHelperData {
- AssertHelperData(TestPartResult::Type t,
- const char* srcfile,
- int line_num,
- const char* msg)
- : type(t), file(srcfile), line(line_num), message(msg) { }
- TestPartResult::Type const type;
- const char* const file;
- int const line;
- std::string const message;
- private:
- GTEST_DISALLOW_COPY_AND_ASSIGN_(AssertHelperData);
- };
- AssertHelperData* const data_;
- GTEST_DISALLOW_COPY_AND_ASSIGN_(AssertHelper);
- };
- }
- #if GTEST_HAS_PARAM_TEST
- template <typename T>
- class WithParamInterface {
- public:
- typedef T ParamType;
- virtual ~WithParamInterface() {}
-
-
-
-
-
- const ParamType& GetParam() const {
- GTEST_CHECK_(parameter_ != NULL)
- << "GetParam() can only be called inside a value-parameterized test "
- << "-- did you intend to write TEST_P instead of TEST_F?";
- return *parameter_;
- }
- private:
-
-
- static void SetParam(const ParamType* parameter) {
- parameter_ = parameter;
- }
-
- static const ParamType* parameter_;
-
- template <class TestClass> friend class internal::ParameterizedTestFactory;
- };
- template <typename T>
- const T* WithParamInterface<T>::parameter_ = NULL;
- template <typename T>
- class TestWithParam : public Test, public WithParamInterface<T> {
- };
- #endif
- #define ADD_FAILURE() GTEST_NONFATAL_FAILURE_("Failed")
- #define ADD_FAILURE_AT(file, line) \
- GTEST_MESSAGE_AT_(file, line, "Failed", \
- ::testing::TestPartResult::kNonFatalFailure)
- #define GTEST_FAIL() GTEST_FATAL_FAILURE_("Failed")
- #if !GTEST_DONT_DEFINE_FAIL
- # define FAIL() GTEST_FAIL()
- #endif
- #define GTEST_SUCCEED() GTEST_SUCCESS_("Succeeded")
- #if !GTEST_DONT_DEFINE_SUCCEED
- # define SUCCEED() GTEST_SUCCEED()
- #endif
- #define EXPECT_THROW(statement, expected_exception) \
- GTEST_TEST_THROW_(statement, expected_exception, GTEST_NONFATAL_FAILURE_)
- #define EXPECT_NO_THROW(statement) \
- GTEST_TEST_NO_THROW_(statement, GTEST_NONFATAL_FAILURE_)
- #define EXPECT_ANY_THROW(statement) \
- GTEST_TEST_ANY_THROW_(statement, GTEST_NONFATAL_FAILURE_)
- #define ASSERT_THROW(statement, expected_exception) \
- GTEST_TEST_THROW_(statement, expected_exception, GTEST_FATAL_FAILURE_)
- #define ASSERT_NO_THROW(statement) \
- GTEST_TEST_NO_THROW_(statement, GTEST_FATAL_FAILURE_)
- #define ASSERT_ANY_THROW(statement) \
- GTEST_TEST_ANY_THROW_(statement, GTEST_FATAL_FAILURE_)
- #define EXPECT_TRUE(condition) \
- GTEST_TEST_BOOLEAN_((condition), #condition, false, true, \
- GTEST_NONFATAL_FAILURE_)
- #define EXPECT_FALSE(condition) \
- GTEST_TEST_BOOLEAN_(!(condition), #condition, true, false, \
- GTEST_NONFATAL_FAILURE_)
- #define ASSERT_TRUE(condition) \
- GTEST_TEST_BOOLEAN_((condition), #condition, false, true, \
- GTEST_FATAL_FAILURE_)
- #define ASSERT_FALSE(condition) \
- GTEST_TEST_BOOLEAN_(!(condition), #condition, true, false, \
- GTEST_FATAL_FAILURE_)
- #include "gtest/gtest_pred_impl.h"
- #define EXPECT_EQ(val1, val2) \
- EXPECT_PRED_FORMAT2(::testing::internal:: \
- EqHelper<GTEST_IS_NULL_LITERAL_(val1)>::Compare, \
- val1, val2)
- #define EXPECT_NE(val1, val2) \
- EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperNE, val1, val2)
- #define EXPECT_LE(val1, val2) \
- EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperLE, val1, val2)
- #define EXPECT_LT(val1, val2) \
- EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperLT, val1, val2)
- #define EXPECT_GE(val1, val2) \
- EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperGE, val1, val2)
- #define EXPECT_GT(val1, val2) \
- EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperGT, val1, val2)
- #define GTEST_ASSERT_EQ(val1, val2) \
- ASSERT_PRED_FORMAT2(::testing::internal:: \
- EqHelper<GTEST_IS_NULL_LITERAL_(val1)>::Compare, \
- val1, val2)
- #define GTEST_ASSERT_NE(val1, val2) \
- ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperNE, val1, val2)
- #define GTEST_ASSERT_LE(val1, val2) \
- ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperLE, val1, val2)
- #define GTEST_ASSERT_LT(val1, val2) \
- ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperLT, val1, val2)
- #define GTEST_ASSERT_GE(val1, val2) \
- ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperGE, val1, val2)
- #define GTEST_ASSERT_GT(val1, val2) \
- ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperGT, val1, val2)
- #if !GTEST_DONT_DEFINE_ASSERT_EQ
- # define ASSERT_EQ(val1, val2) GTEST_ASSERT_EQ(val1, val2)
- #endif
- #if !GTEST_DONT_DEFINE_ASSERT_NE
- # define ASSERT_NE(val1, val2) GTEST_ASSERT_NE(val1, val2)
- #endif
- #if !GTEST_DONT_DEFINE_ASSERT_LE
- # define ASSERT_LE(val1, val2) GTEST_ASSERT_LE(val1, val2)
- #endif
- #if !GTEST_DONT_DEFINE_ASSERT_LT
- # define ASSERT_LT(val1, val2) GTEST_ASSERT_LT(val1, val2)
- #endif
- #if !GTEST_DONT_DEFINE_ASSERT_GE
- # define ASSERT_GE(val1, val2) GTEST_ASSERT_GE(val1, val2)
- #endif
- #if !GTEST_DONT_DEFINE_ASSERT_GT
- # define ASSERT_GT(val1, val2) GTEST_ASSERT_GT(val1, val2)
- #endif
- #define EXPECT_STREQ(s1, s2) \
- EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTREQ, s1, s2)
- #define EXPECT_STRNE(s1, s2) \
- EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRNE, s1, s2)
- #define EXPECT_STRCASEEQ(s1, s2) \
- EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASEEQ, s1, s2)
- #define EXPECT_STRCASENE(s1, s2)\
- EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASENE, s1, s2)
- #define ASSERT_STREQ(s1, s2) \
- ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTREQ, s1, s2)
- #define ASSERT_STRNE(s1, s2) \
- ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRNE, s1, s2)
- #define ASSERT_STRCASEEQ(s1, s2) \
- ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASEEQ, s1, s2)
- #define ASSERT_STRCASENE(s1, s2)\
- ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASENE, s1, s2)
- #define EXPECT_FLOAT_EQ(val1, val2)\
- EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<float>, \
- val1, val2)
- #define EXPECT_DOUBLE_EQ(val1, val2)\
- EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<double>, \
- val1, val2)
- #define ASSERT_FLOAT_EQ(val1, val2)\
- ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<float>, \
- val1, val2)
- #define ASSERT_DOUBLE_EQ(val1, val2)\
- ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<double>, \
- val1, val2)
- #define EXPECT_NEAR(val1, val2, abs_error)\
- EXPECT_PRED_FORMAT3(::testing::internal::DoubleNearPredFormat, \
- val1, val2, abs_error)
- #define ASSERT_NEAR(val1, val2, abs_error)\
- ASSERT_PRED_FORMAT3(::testing::internal::DoubleNearPredFormat, \
- val1, val2, abs_error)
- GTEST_API_ AssertionResult FloatLE(const char* expr1, const char* expr2,
- float val1, float val2);
- GTEST_API_ AssertionResult DoubleLE(const char* expr1, const char* expr2,
- double val1, double val2);
- #if GTEST_OS_WINDOWS
- # define EXPECT_HRESULT_SUCCEEDED(expr) \
- EXPECT_PRED_FORMAT1(::testing::internal::IsHRESULTSuccess, (expr))
- # define ASSERT_HRESULT_SUCCEEDED(expr) \
- ASSERT_PRED_FORMAT1(::testing::internal::IsHRESULTSuccess, (expr))
- # define EXPECT_HRESULT_FAILED(expr) \
- EXPECT_PRED_FORMAT1(::testing::internal::IsHRESULTFailure, (expr))
- # define ASSERT_HRESULT_FAILED(expr) \
- ASSERT_PRED_FORMAT1(::testing::internal::IsHRESULTFailure, (expr))
- #endif
- #define ASSERT_NO_FATAL_FAILURE(statement) \
- GTEST_TEST_NO_FATAL_FAILURE_(statement, GTEST_FATAL_FAILURE_)
- #define EXPECT_NO_FATAL_FAILURE(statement) \
- GTEST_TEST_NO_FATAL_FAILURE_(statement, GTEST_NONFATAL_FAILURE_)
- #define SCOPED_TRACE(message) \
- ::testing::internal::ScopedTrace GTEST_CONCAT_TOKEN_(gtest_trace_, __LINE__)(\
- __FILE__, __LINE__, ::testing::Message() << (message))
- template <typename T1, typename T2>
- bool StaticAssertTypeEq() {
- (void)internal::StaticAssertTypeEqHelper<T1, T2>();
- return true;
- }
- #define GTEST_TEST(test_case_name, test_name)\
- GTEST_TEST_(test_case_name, test_name, \
- ::testing::Test, ::testing::internal::GetTestTypeId())
- #if !GTEST_DONT_DEFINE_TEST
- # define TEST(test_case_name, test_name) GTEST_TEST(test_case_name, test_name)
- #endif
- #define TEST_F(test_fixture, test_name)\
- GTEST_TEST_(test_fixture, test_name, test_fixture, \
- ::testing::internal::GetTypeId<test_fixture>())
- }
- int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_;
- inline int RUN_ALL_TESTS() {
- return ::testing::UnitTest::GetInstance()->Run();
- }
- #endif
|