├── .gitignore ├── umls └── html-docs │ ├── assets │ ├── js │ │ └── main.js │ ├── img │ │ ├── glyphicons-halflings.png │ │ └── glyphicons-halflings-white.png │ └── css │ │ └── jquery.bonsai.css │ ├── index.html │ └── diagrams │ └── 078238f7718b97a7cea2ea60ee53dcd7.svg ├── .gitattributes ├── tests ├── CMakeLists.txt ├── lib │ └── gtest-1.7.0 │ │ ├── xcode │ │ ├── Config │ │ │ ├── TestTarget.xcconfig │ │ │ ├── FrameworkTarget.xcconfig │ │ │ ├── StaticLibraryTarget.xcconfig │ │ │ ├── DebugProject.xcconfig │ │ │ ├── ReleaseProject.xcconfig │ │ │ └── General.xcconfig │ │ ├── Samples │ │ │ └── FrameworkSample │ │ │ │ ├── Info.plist │ │ │ │ ├── widget.h │ │ │ │ ├── widget.cc │ │ │ │ ├── runtests.sh │ │ │ │ └── widget_test.cc │ │ ├── Resources │ │ │ └── Info.plist │ │ └── Scripts │ │ │ └── runtests.sh │ │ ├── m4 │ │ ├── ltversion.m4 │ │ └── gtest.m4 │ │ ├── CONTRIBUTORS │ │ ├── LICENSE │ │ ├── test │ │ ├── production.cc │ │ ├── gtest_main_unittest.cc │ │ ├── gtest_uninitialized_test_.cc │ │ ├── gtest_xml_outfile1_test_.cc │ │ ├── gtest_xml_outfile2_test_.cc │ │ ├── gtest-typed-test2_test.cc │ │ ├── gtest_help_test_.cc │ │ ├── production.h │ │ ├── gtest_all_test.cc │ │ ├── gtest_prod_test.cc │ │ ├── gtest_sole_header_test.cc │ │ ├── gtest-param-test_test.h │ │ ├── gtest_no_test_unittest.cc │ │ ├── gtest-typed-test_test.h │ │ ├── gtest_uninitialized_test.py │ │ ├── gtest-param-test2_test.cc │ │ ├── gtest_color_test_.cc │ │ ├── gtest_throw_on_failure_test_.cc │ │ ├── gtest_break_on_failure_unittest_.cc │ │ ├── gtest_throw_on_failure_ex_test.cc │ │ └── gtest_shuffle_test_.cc │ │ ├── src │ │ ├── gtest_main.cc │ │ └── gtest-all.cc │ │ ├── fused-src │ │ └── gtest │ │ │ └── gtest_main.cc │ │ ├── codegear │ │ ├── gtest_all.cc │ │ ├── gtest_link.cc │ │ └── gtest.groupproj │ │ ├── scripts │ │ └── test │ │ │ └── Makefile │ │ ├── samples │ │ ├── sample4_unittest.cc │ │ ├── sample1.h │ │ ├── sample4.cc │ │ ├── sample4.h │ │ ├── sample2.cc │ │ ├── sample1.cc │ │ └── sample2.h │ │ ├── build-aux │ │ └── config.h.in │ │ ├── msvc │ │ ├── gtest.sln │ │ └── gtest-md.sln │ │ ├── include │ │ └── gtest │ │ │ └── gtest_prod.h │ │ ├── configure.ac │ │ └── make │ │ └── Makefile └── unit_tests │ ├── facade_test.cc │ ├── proxy_test.cc │ ├── strategy_test.cc │ ├── singleton_test.cc │ ├── CMakeLists.txt │ ├── decorator_test.cc │ ├── mediator_test.cc │ ├── template_method_test.cc │ ├── state_test.cc │ ├── adapter_test.cc │ ├── factory_method_test.cc │ ├── memento_test.cc │ ├── bridge_test.cc │ ├── interpreter_test.cc │ ├── visitor_test.cc │ ├── observer_test.cc │ ├── aggregate_test.cc │ ├── prototype_test.cc │ ├── flyweight_test.cc │ ├── builder_test.cc │ ├── command_test.cc │ ├── chain_of_responsibility_test.cc │ ├── abstract_factory_test.cc │ └── composite_test.cc ├── CMakeLists.txt ├── src ├── singleton.h ├── singleton.cc ├── factory_method.cc ├── facade.h ├── decorator.cc ├── decorator.h ├── template_method.h ├── factory_method.h ├── memento.h ├── proxy.cc ├── interpreter.h ├── template_method.cc ├── CMakeLists.txt ├── state.h ├── flyweight.h ├── prototype.h ├── aggregate.cc ├── proxy.h ├── bridge.cc ├── memento.cc ├── bridge.h ├── aggregate.h ├── builder.h ├── command.h ├── facade.cc ├── strategy.h ├── visitor.h ├── builder.cc ├── flyweight.cc ├── adapter.h ├── chain_of_responsibility.h ├── composite.h ├── mediator.h ├── mediator.cc ├── observer.h ├── state.cc ├── visitor.cc ├── observer.cc ├── adapter.cc ├── interpreter.cc ├── strategy.cc ├── composite.cc ├── abstract_factory.h ├── command.cc ├── prototype.cc ├── abstract_factory.cc └── chain_of_responsibility.cc ├── README.md └── main.cc /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ -------------------------------------------------------------------------------- /umls/html-docs/assets/js/main.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.html linguist-language=c++ -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(patterns_tests) 2 | 3 | add_subdirectory(lib/gtest-1.7.0) 4 | add_subdirectory(unit_tests) 5 | -------------------------------------------------------------------------------- /umls/html-docs/assets/img/glyphicons-halflings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yogykwan/design-patterns-cpp/HEAD/umls/html-docs/assets/img/glyphicons-halflings.png -------------------------------------------------------------------------------- /umls/html-docs/assets/img/glyphicons-halflings-white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yogykwan/design-patterns-cpp/HEAD/umls/html-docs/assets/img/glyphicons-halflings-white.png -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/xcode/Config/TestTarget.xcconfig: -------------------------------------------------------------------------------- 1 | // 2 | // TestTarget.xcconfig 3 | // 4 | // These are Test target settings for the gtest framework and examples. It 5 | // is set in the "Based On:" dropdown in the "Target" info dialog. 6 | 7 | PRODUCT_NAME = $(TARGET_NAME) 8 | HEADER_SEARCH_PATHS = ../include 9 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.6) 2 | project(design-patterns) 3 | 4 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") 5 | 6 | set(SOURCE_FILES main.cc) 7 | add_executable(patterns_run ${SOURCE_FILES}) 8 | 9 | include_directories(src) 10 | 11 | add_subdirectory(src) 12 | add_subdirectory(tests) 13 | 14 | target_link_libraries(patterns_run patterns) -------------------------------------------------------------------------------- /src/singleton.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2016/12/28. 3 | // 4 | 5 | #ifndef DESIGN_PATTERNS_SINGLETON_H 6 | #define DESIGN_PATTERNS_SINGLETON_H 7 | 8 | 9 | #include 10 | 11 | class Singleton { 12 | private: 13 | Singleton() {}; 14 | public: 15 | static Singleton* GetInstance(); 16 | 17 | private: 18 | static Singleton* instance_; 19 | static pthread_mutex_t mutex_; 20 | }; 21 | 22 | 23 | #endif //DESIGN_PATTERNS_SINGLETON_H 24 | -------------------------------------------------------------------------------- /src/singleton.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2016/12/28. 3 | // 4 | 5 | #include "singleton.h" 6 | 7 | // initialize stastic parameters, compile errors occur without them 8 | Singleton* Singleton::instance_ = NULL; 9 | pthread_mutex_t Singleton::mutex_; 10 | 11 | Singleton* Singleton::GetInstance() { 12 | if(instance_ == NULL) { 13 | pthread_mutex_lock(&mutex_); 14 | if(instance_ == NULL) { 15 | instance_ = new Singleton(); 16 | } 17 | pthread_mutex_unlock(&mutex_); 18 | } 19 | return instance_; 20 | } -------------------------------------------------------------------------------- /tests/unit_tests/facade_test.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2016/12/28. 3 | // 4 | 5 | #include "gtest/gtest.h" 6 | #include "facade.h" 7 | 8 | class FacadeFixture: public ::testing::Test { 9 | protected: 10 | virtual void TearDown() {}; 11 | virtual void SetUp() {}; 12 | 13 | public: 14 | FacadeFixture(): Test() { 15 | fund_ = new Fund; 16 | fund_->BuyFund(); 17 | fund_->SellFund(); 18 | } 19 | 20 | virtual ~FacadeFixture() { 21 | delete fund_; 22 | } 23 | 24 | Fund *fund_; 25 | }; 26 | 27 | TEST_F(FacadeFixture, _test) { 28 | } -------------------------------------------------------------------------------- /src/factory_method.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2016/12/26. 3 | // 4 | 5 | #include "factory_method.h" 6 | #include 7 | 8 | void LeiFeng::Wash() { 9 | std::cout << "Wash" << std::endl; 10 | } 11 | 12 | void LeiFeng::Sweep() { 13 | std::cout << "Sweep" << std::endl; 14 | } 15 | 16 | void LeiFeng::BuyRice() { 17 | std::cout << "BuyRice" << std::endl; 18 | } 19 | 20 | LeiFeng* UndergraduateFactory::CreateLeiFeng() { 21 | LeiFeng* leifeng = new Undergraduate(); 22 | return leifeng; 23 | } 24 | 25 | LeiFeng* VolunteerFactory::CreateLeiFeng() { 26 | LeiFeng* leifeng = new Volunteer(); 27 | return leifeng; 28 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # design-patterns-cpp 2 | 《大话设计模式》中23种设计模式案例的C++实现版本。样例忠于原书,某些地方根据C++特性做了修改。 3 | 4 | ## 组织结构 5 | * src - 每个模式案例的声明(.h)和实现(.cc) 6 | * tests - 每个模式案例的gtest,相当于客户端 7 | * docs - 每个模式案例的UML(.html) 8 | 9 | ## 编译结果 10 | * patterns - src编译得到的模式案例类库 11 | * patterns_run - main输出设计模式字符图 12 | * patterns_test - tests中所有案例的单元测试 13 | 14 | ## 读书笔记 15 | * [创建型模式](http://jennica.space/2016/12/28/design-patterns-creational/) 16 | * [结构型模式](http://jennica.space/2016/12/30/design-patterns-structural/) 17 | * [行为型模式](http://jennica.space/2017/01/03/design-patterns-behavioral/) 18 | 19 | ## Python版 20 | [design-patterns-py](https://github.com/yogykwan/design-patterns-py) 21 | 22 | -------------------------------------------------------------------------------- /src/facade.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2016/12/29. 3 | // 4 | 5 | #ifndef DESIGN_PATTERNS_FACADE_H 6 | #define DESIGN_PATTERNS_FACADE_H 7 | 8 | 9 | class Stock1 { 10 | public: 11 | void Buy(); 12 | void Sell(); 13 | }; 14 | 15 | class Stock2 { 16 | public: 17 | void Buy(); 18 | void Sell(); 19 | }; 20 | 21 | class Reality1 { 22 | public: 23 | void Buy(); 24 | void Sell(); 25 | }; 26 | 27 | class Fund { 28 | public: 29 | Fund(); 30 | ~Fund(); 31 | void BuyFund(); 32 | void SellFund(); 33 | 34 | private: 35 | Stock1 *stock1_; 36 | Stock2 *stock2_; 37 | Reality1 *reality1_; 38 | }; 39 | 40 | 41 | #endif //DESIGN_PATTERNS_FACADE_H 42 | -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/xcode/Config/FrameworkTarget.xcconfig: -------------------------------------------------------------------------------- 1 | // 2 | // FrameworkTarget.xcconfig 3 | // 4 | // These are Framework target settings for the gtest framework and examples. It 5 | // is set in the "Based On:" dropdown in the "Target" info dialog. 6 | // This file is based on the Xcode Configuration files in: 7 | // http://code.google.com/p/google-toolbox-for-mac/ 8 | // 9 | 10 | // Dynamic libs need to be position independent 11 | GCC_DYNAMIC_NO_PIC = NO 12 | 13 | // Dynamic libs should not have their external symbols stripped. 14 | STRIP_STYLE = non-global 15 | 16 | // Let the user install by specifying the $DSTROOT with xcodebuild 17 | SKIP_INSTALL = NO 18 | -------------------------------------------------------------------------------- /tests/unit_tests/proxy_test.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2016/12/28. 3 | // 4 | 5 | #include "gtest/gtest.h" 6 | #include "proxy.h" 7 | 8 | class ProxyFixture: public ::testing::Test { 9 | protected: 10 | virtual void TearDown() {}; 11 | virtual void SetUp() {}; 12 | 13 | public: 14 | ProxyFixture(): Test() { 15 | school_girl_ = new SchoolGirl("Alice"); 16 | proxy_ = new Proxy(school_girl_); 17 | proxy_->GiveFlowers(); 18 | proxy_->GiveDolls(); 19 | } 20 | 21 | virtual ~ProxyFixture() { 22 | delete school_girl_; 23 | delete proxy_; 24 | } 25 | 26 | SchoolGirl *school_girl_; 27 | Proxy *proxy_; 28 | }; 29 | 30 | TEST_F(ProxyFixture, proxy_test) { 31 | } -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/xcode/Config/StaticLibraryTarget.xcconfig: -------------------------------------------------------------------------------- 1 | // 2 | // StaticLibraryTarget.xcconfig 3 | // 4 | // These are static library target settings for libgtest.a. It 5 | // is set in the "Based On:" dropdown in the "Target" info dialog. 6 | // This file is based on the Xcode Configuration files in: 7 | // http://code.google.com/p/google-toolbox-for-mac/ 8 | // 9 | 10 | // Static libs can be included in bundles so make them position independent 11 | GCC_DYNAMIC_NO_PIC = NO 12 | 13 | // Static libs should not have their internal globals or external symbols 14 | // stripped. 15 | STRIP_STYLE = debugging 16 | 17 | // Let the user install by specifying the $DSTROOT with xcodebuild 18 | SKIP_INSTALL = NO 19 | -------------------------------------------------------------------------------- /src/decorator.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2016/12/29. 3 | // 4 | 5 | #include "decorator.h" 6 | #include 7 | 8 | void Person::Show() { 9 | std::cout << "person" << std::endl; 10 | } 11 | 12 | Finery::Finery(Person *component): component_(component) {} 13 | 14 | Tie::Tie(Person *component): Finery(component) {} 15 | 16 | void Tie::Show() { 17 | std::cout << "tie "; 18 | component_->Show(); 19 | } 20 | 21 | Suit::Suit(Person *component): Finery(component) {} 22 | 23 | void Suit::Show() { 24 | std::cout << "suit "; 25 | component_->Show(); 26 | } 27 | 28 | Shoes::Shoes(Person *component): Finery(component) {} 29 | 30 | void Shoes::Show() { 31 | std::cout << "shoes "; 32 | component_->Show(); 33 | } -------------------------------------------------------------------------------- /tests/unit_tests/strategy_test.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2016/12/28. 3 | // 4 | 5 | #include "gtest/gtest.h" 6 | #include "strategy.h" 7 | 8 | class StrategyFixture: public ::testing::Test { 9 | protected: 10 | virtual void TearDown() {}; 11 | virtual void SetUp() {}; 12 | 13 | public: 14 | StrategyFixture(): Test() { 15 | cash_context_ = new CashContext("rebate", "0.8"); 16 | cash_context_->GetResult(1000); 17 | 18 | cash_context_ = new CashContext("return", "300 100"); 19 | cash_context_->GetResult(1000); 20 | } 21 | 22 | virtual ~StrategyFixture() { 23 | delete cash_context_; 24 | } 25 | 26 | CashContext *cash_context_; 27 | }; 28 | 29 | TEST_F(StrategyFixture, strategy_test) { 30 | } -------------------------------------------------------------------------------- /umls/html-docs/assets/css/jquery.bonsai.css: -------------------------------------------------------------------------------- 1 | .bonsai, 2 | .bonsai li { 3 | margin: 0; 4 | padding: 0; 5 | list-style: none; 6 | overflow: hidden; 7 | } 8 | 9 | .bonsai li { 10 | position: relative; 11 | padding-left: 1.3em; /* padding for the thumb */ 12 | } 13 | 14 | li .thumb { 15 | margin: -1px 0 0 -1em; /* negative margin into the padding of the li */ 16 | position: absolute; 17 | cursor: pointer; 18 | } 19 | 20 | li.has-children > .thumb:after { 21 | content: '▸'; 22 | } 23 | 24 | li.has-children.expanded > .thumb:after { 25 | content: '▾'; 26 | } 27 | 28 | li.collapsed > ol.bonsai { 29 | height: 0; 30 | overflow: hidden; 31 | } 32 | 33 | .bonsai .all, 34 | .bonsai .none { 35 | cursor: pointer; 36 | } 37 | -------------------------------------------------------------------------------- /tests/unit_tests/singleton_test.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2016/12/28. 3 | // 4 | 5 | #include "gtest/gtest.h" 6 | #include "singleton.h" 7 | 8 | class SingletonFixture: public ::testing::Test { 9 | protected: 10 | virtual void TearDown() {}; 11 | virtual void SetUp() {}; 12 | 13 | public: 14 | SingletonFixture(): Test() { 15 | instance1_ = Singleton::GetInstance(); 16 | instance2_ = Singleton::GetInstance(); 17 | } 18 | 19 | virtual ~SingletonFixture() { 20 | delete instance1_; 21 | if(instance1_ != instance2_){ 22 | delete instance2_; 23 | } 24 | } 25 | 26 | Singleton* instance1_; 27 | Singleton* instance2_; 28 | }; 29 | 30 | TEST_F(SingletonFixture, singleton_test) { 31 | EXPECT_EQ(instance1_, instance2_); 32 | } -------------------------------------------------------------------------------- /tests/unit_tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR}) 2 | 3 | set(SOURCE_FILES 4 | abstract_factory_test.cc factory_method_test.cc singleton_test.cc builder_test.cc 5 | prototype_test.cc proxy_test.cc adapter_test.cc bridge_test.cc 6 | facade_test.cc decorator_test.cc flyweight_test.cc composite_test.cc 7 | chain_of_responsibility_test.cc strategy_test.cc state_test.cc observer_test.cc 8 | aggregate_test.cc memento_test.cc command_test.cc template_method_test.cc 9 | mediator_test.cc interpreter_test.cc visitor_test.cc) 10 | add_executable(patterns_test ${SOURCE_FILES}) 11 | 12 | target_link_libraries(patterns_test gtest gtest_main) 13 | target_link_libraries(patterns_test patterns) 14 | 15 | -------------------------------------------------------------------------------- /tests/unit_tests/decorator_test.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2016/12/28. 3 | // 4 | 5 | #include "gtest/gtest.h" 6 | #include "decorator.h" 7 | 8 | class DecoratorFixture: public ::testing::Test { 9 | protected: 10 | virtual void TearDown() {}; 11 | virtual void SetUp() {}; 12 | 13 | public: 14 | DecoratorFixture(): Test() { 15 | person_ = new Person(); 16 | tie_ = new Tie(person_); 17 | suit_ = new Suit(tie_); 18 | shoes_ = new Shoes(suit_); 19 | shoes_->Show(); 20 | } 21 | 22 | virtual ~DecoratorFixture() { 23 | delete person_; 24 | delete shoes_; 25 | delete suit_; 26 | delete tie_; 27 | } 28 | 29 | Person* person_; 30 | Tie* tie_; 31 | Suit* suit_; 32 | Shoes* shoes_; 33 | }; 34 | 35 | TEST_F(DecoratorFixture, decorator_test) { 36 | } -------------------------------------------------------------------------------- /src/decorator.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2016/12/29. 3 | // 4 | 5 | #ifndef DESIGN_PATTERNS_DECORATOR_H 6 | #define DESIGN_PATTERNS_DECORATOR_H 7 | 8 | 9 | class Person { 10 | public: 11 | virtual void Show(); 12 | }; 13 | 14 | class Finery: public Person { 15 | public: 16 | Finery() {} 17 | Finery(Person*); 18 | void Show() {} 19 | 20 | protected: 21 | Person *component_; 22 | }; 23 | 24 | class Tie: public Finery { 25 | public: 26 | Tie() {} 27 | Tie(Person*); 28 | void Show(); 29 | }; 30 | 31 | class Suit: public Finery { 32 | public: 33 | Suit() {} 34 | Suit(Person*); 35 | void Show(); 36 | }; 37 | 38 | class Shoes: public Finery { 39 | public: 40 | Shoes() {} 41 | Shoes(Person*); 42 | void Show(); 43 | }; 44 | 45 | 46 | #endif //DESIGN_PATTERNS_DECORATOR_H 47 | -------------------------------------------------------------------------------- /src/template_method.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2017/1/3. 3 | // 4 | 5 | #ifndef DESIGN_PATTERNS_TEMPLATE_METHOD_H 6 | #define DESIGN_PATTERNS_TEMPLATE_METHOD_H 7 | 8 | #include 9 | 10 | class TestPaper { 11 | public: 12 | void Question1(); 13 | void Question2(); 14 | void Question3(); 15 | 16 | protected: 17 | virtual std::string Answer1() = 0; 18 | virtual std::string Answer2() = 0; 19 | virtual std::string Answer3() = 0; 20 | }; 21 | 22 | class TestPaperA: public TestPaper { 23 | std::string Answer1(); 24 | std::string Answer2(); 25 | std::string Answer3(); 26 | }; 27 | 28 | class TestPaperB: public TestPaper { 29 | std::string Answer1(); 30 | std::string Answer2(); 31 | std::string Answer3(); 32 | }; 33 | 34 | 35 | #endif //DESIGN_PATTERNS_TEMPLATE_METHOD_H 36 | -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/m4/ltversion.m4: -------------------------------------------------------------------------------- 1 | # ltversion.m4 -- version numbers -*- Autoconf -*- 2 | # 3 | # Copyright (C) 2004 Free Software Foundation, Inc. 4 | # Written by Scott James Remnant, 2004 5 | # 6 | # This file is free software; the Free Software Foundation gives 7 | # unlimited permission to copy and/or distribute it, with or without 8 | # modifications, as long as this notice is preserved. 9 | 10 | # @configure_input@ 11 | 12 | # serial 3337 ltversion.m4 13 | # This file is part of GNU Libtool 14 | 15 | m4_define([LT_PACKAGE_VERSION], [2.4.2]) 16 | m4_define([LT_PACKAGE_REVISION], [1.3337]) 17 | 18 | AC_DEFUN([LTVERSION_VERSION], 19 | [macro_version='2.4.2' 20 | macro_revision='1.3337' 21 | _LT_DECL(, macro_version, 0, [Which release of libtool.m4 was used?]) 22 | _LT_DECL(, macro_revision, 0) 23 | ]) 24 | -------------------------------------------------------------------------------- /src/factory_method.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2016/12/26. 3 | // 4 | 5 | #ifndef DESIGN_PATTERNS_FACTORY_METHOD_H 6 | #define DESIGN_PATTERNS_FACTORY_METHOD_H 7 | 8 | class LeiFeng { 9 | public: 10 | virtual void Wash(); 11 | virtual void Sweep(); 12 | virtual void BuyRice(); 13 | }; 14 | 15 | class Undergraduate: public LeiFeng { 16 | 17 | }; 18 | 19 | class Volunteer: public LeiFeng { 20 | 21 | }; 22 | 23 | class IFactory { 24 | public: 25 | IFactory() {}; 26 | virtual ~IFactory() {}; 27 | virtual LeiFeng* CreateLeiFeng() = 0; 28 | }; 29 | 30 | class UndergraduateFactory: public IFactory { 31 | public: 32 | LeiFeng* CreateLeiFeng(); 33 | }; 34 | 35 | class VolunteerFactory: public IFactory { 36 | public: 37 | LeiFeng* CreateLeiFeng(); 38 | }; 39 | 40 | #endif //DESIGN_PATTERNS_FACTORY_METHOD_H 41 | -------------------------------------------------------------------------------- /src/memento.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2017/1/3. 3 | // 4 | 5 | #ifndef DESIGN_PATTERNS_MEMENTO_H 6 | #define DESIGN_PATTERNS_MEMENTO_H 7 | 8 | class StateMemento { 9 | public: 10 | StateMemento() {} 11 | StateMemento(int, int); 12 | int GetHp(); 13 | int GetMp(); 14 | 15 | private: 16 | int hp_; 17 | int mp_; 18 | }; 19 | 20 | class GameRole { 21 | public: 22 | GameRole(); 23 | StateMemento* CreateMemento(); 24 | void StateDisplay(); 25 | void Fight(); 26 | void RecoveryState(StateMemento*); 27 | 28 | private: 29 | int hp_; 30 | int mp_; 31 | }; 32 | 33 | class StateCaretaker { 34 | public: 35 | StateCaretaker() {} 36 | StateCaretaker(StateMemento*); 37 | ~StateCaretaker(); 38 | StateMemento* GetMemento(); 39 | private: 40 | StateMemento* memento_; 41 | }; 42 | 43 | 44 | #endif //DESIGN_PATTERNS_MEMENTO_H 45 | -------------------------------------------------------------------------------- /src/proxy.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2016/12/29. 3 | // 4 | 5 | #include "proxy.h" 6 | 7 | SchoolGirl::SchoolGirl(std::string name): name_(name) { 8 | } 9 | 10 | std::string SchoolGirl::GetName() { 11 | return name_; 12 | } 13 | 14 | Pursuit::Pursuit(SchoolGirl *school_girl): school_girl_(school_girl){ 15 | } 16 | 17 | void Pursuit::GiveFlowers() { 18 | std::cout << "Give flowers to " << school_girl_->GetName() << std::endl; 19 | } 20 | 21 | void Pursuit::GiveDolls() { 22 | std::cout << "Give dolls to " << school_girl_->GetName() << std::endl; 23 | } 24 | 25 | Proxy::Proxy(SchoolGirl *school_girl) { 26 | pursuit_ = new Pursuit(school_girl); 27 | } 28 | 29 | Proxy::~Proxy() { 30 | delete pursuit_; 31 | } 32 | 33 | void Proxy::GiveFlowers() { 34 | pursuit_->GiveFlowers(); 35 | } 36 | 37 | void Proxy::GiveDolls() { 38 | pursuit_->GiveDolls(); 39 | } -------------------------------------------------------------------------------- /tests/unit_tests/mediator_test.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2016/12/28. 3 | // 4 | 5 | #include "gtest/gtest.h" 6 | #include "mediator.h" 7 | 8 | class MediatorFixture: public ::testing::Test { 9 | protected: 10 | virtual void TearDown() {}; 11 | virtual void SetUp() {}; 12 | 13 | public: 14 | MediatorFixture(): Test() { 15 | unsc_ = new UnitedNationsSecurityCouncil(); 16 | usa_ = new Usa(unsc_); 17 | iraq_ = new Iraq(unsc_); 18 | unsc_->SetUsa(usa_); 19 | unsc_->SetIraq(iraq_); 20 | usa_->Declare("Stop nuclear weapons"); 21 | iraq_->Declare("No nuclear here"); 22 | } 23 | 24 | virtual ~MediatorFixture() { 25 | delete unsc_; 26 | delete usa_; 27 | delete iraq_; 28 | } 29 | 30 | UnitedNationsSecurityCouncil *unsc_; 31 | Country *usa_; 32 | Country *iraq_; 33 | }; 34 | 35 | TEST_F(MediatorFixture, mediator_test) { 36 | } -------------------------------------------------------------------------------- /umls/html-docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | <h2>Frame Alert</h2> 16 | This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. 17 | <br> 18 | Link to<a href="overview-summary.html">Non-frame version.</a> 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/interpreter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2017/1/3. 3 | // 4 | 5 | #ifndef DESIGN_PATTERNS_INTERPRETER_H 6 | #define DESIGN_PATTERNS_INTERPRETER_H 7 | 8 | #include 9 | 10 | class Context { 11 | public: 12 | void SetText(std::string); 13 | std::string GetText(); 14 | 15 | private: 16 | std::string text_; 17 | }; 18 | 19 | class Expression { 20 | public: 21 | virtual ~Expression() {} 22 | void Interprete(Context*); 23 | 24 | protected: 25 | virtual void Excute(std::string, double) = 0; 26 | }; 27 | 28 | class Scale: public Expression { 29 | private: 30 | void Excute(std::string, double); 31 | }; 32 | 33 | class Note: public Expression { 34 | private: 35 | void Excute(std::string, double); 36 | }; 37 | 38 | class ExpressionFactory { 39 | public: 40 | Expression* CreateExpression(Context*); 41 | }; 42 | 43 | #endif //DESIGN_PATTERNS_INTERPRETER_H 44 | -------------------------------------------------------------------------------- /tests/unit_tests/template_method_test.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2016/12/28. 3 | // 4 | 5 | #include "gtest/gtest.h" 6 | #include "template_method.h" 7 | 8 | class TemplateMethodFixture: public ::testing::Test { 9 | protected: 10 | virtual void TearDown() {}; 11 | virtual void SetUp() {}; 12 | 13 | public: 14 | TemplateMethodFixture(): Test() { 15 | test_paper_a_ = new TestPaperA(); 16 | test_paper_a_->Question1(); 17 | test_paper_a_->Question2(); 18 | test_paper_a_->Question3(); 19 | 20 | test_paper_b_ = new TestPaperB(); 21 | test_paper_b_->Question1(); 22 | test_paper_b_->Question2(); 23 | test_paper_b_->Question3(); 24 | } 25 | 26 | virtual ~TemplateMethodFixture() { 27 | 28 | } 29 | 30 | TestPaper *test_paper_a_; 31 | TestPaper *test_paper_b_; 32 | }; 33 | 34 | TEST_F(TemplateMethodFixture, template_method_test) { 35 | } -------------------------------------------------------------------------------- /src/template_method.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2017/1/3. 3 | // 4 | 5 | #include "template_method.h" 6 | #include 7 | 8 | void TestPaper::Question1() { 9 | std::cout << "question 1: " << Answer1() << std::endl; 10 | } 11 | 12 | void TestPaper::Question2() { 13 | std::cout << "question 2: " << Answer2() << std::endl; 14 | } 15 | 16 | void TestPaper::Question3() { 17 | std::cout << "question 3: " << Answer3() << std::endl; 18 | } 19 | 20 | std::string TestPaperA::Answer1() { 21 | return "a"; 22 | } 23 | 24 | std::string TestPaperA::Answer2() { 25 | return "a"; 26 | } 27 | 28 | std::string TestPaperA::Answer3() { 29 | return "a"; 30 | } 31 | 32 | std::string TestPaperB::Answer1() { 33 | return "b"; 34 | } 35 | 36 | std::string TestPaperB::Answer2() { 37 | return "b"; 38 | } 39 | 40 | std::string TestPaperB::Answer3() { 41 | return "b"; 42 | } 43 | 44 | -------------------------------------------------------------------------------- /tests/unit_tests/state_test.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2016/12/28. 3 | // 4 | 5 | #include "gtest/gtest.h" 6 | #include "state.h" 7 | 8 | class StateFixture: public ::testing::Test { 9 | protected: 10 | virtual void TearDown() {}; 11 | virtual void SetUp() {}; 12 | 13 | public: 14 | StateFixture(): Test() { 15 | work_ = new Work(); 16 | 17 | work_->hour_ = 15; 18 | work_->WriteProgram(); 19 | 20 | work_->hour_ = 20; 21 | work_->finished_ = false; 22 | work_->WriteProgram(); 23 | 24 | work_->hour_ = 22; 25 | work_->WriteProgram(); 26 | 27 | delete work_; 28 | work_ = new Work(); 29 | work_->hour_ = 20; 30 | work_->finished_ = true; 31 | work_->WriteProgram(); 32 | } 33 | 34 | virtual ~StateFixture() { 35 | delete work_; 36 | } 37 | 38 | Work *work_; 39 | }; 40 | 41 | TEST_F(StateFixture, state_test) { 42 | } -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(patterns) 2 | 3 | set(HEADER_FILES 4 | abstract_factory.h factory_method.h singleton.h builder.h 5 | prototype.h proxy.h adapter.h bridge.h 6 | facade.h decorator.h flyweight.h composite.h 7 | chain_of_responsibility.h strategy.h state.h observer.h 8 | aggregate.h memento.h command.h template_method.h 9 | mediator.h interpreter.h visitor.h) 10 | 11 | set(SOURCE_FILES 12 | abstract_factory.cc factory_method.cc singleton.cc builder.cc 13 | prototype.cc proxy.cc adapter.cc bridge.cc 14 | facade.cc decorator.cc flyweight.cc composite.cc 15 | chain_of_responsibility.cc strategy.cc state.cc observer.cc 16 | aggregate.cc memento.cc command.cc template_method.cc 17 | mediator.cc interpreter.cc visitor.cc) 18 | 19 | add_library(patterns STATIC ${SOURCE_FILES} ${HEADER_FILES}) 20 | -------------------------------------------------------------------------------- /src/state.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2017/1/2. 3 | // 4 | 5 | #ifndef DESIGN_PATTERNS_STATE_H 6 | #define DESIGN_PATTERNS_STATE_H 7 | 8 | class State; 9 | 10 | class Work { 11 | public: 12 | Work(); 13 | ~Work(); 14 | void SetState(State*); 15 | void WriteProgram(); 16 | 17 | public: 18 | bool finished_; 19 | int hour_; 20 | 21 | private: 22 | State* state_; 23 | }; 24 | 25 | class State { 26 | public: 27 | virtual ~State() {} 28 | virtual void WriteProgram(Work*) = 0; 29 | }; 30 | 31 | class WorkingState: public State { 32 | void WriteProgram(Work* work); 33 | }; 34 | 35 | class OvertimeState: public State { 36 | void WriteProgram(Work* work); 37 | }; 38 | 39 | class RestState: public State { 40 | void WriteProgram(Work* work); 41 | }; 42 | 43 | class SleepingState: public State { 44 | void WriteProgram(Work* work); 45 | }; 46 | 47 | 48 | #endif //DESIGN_PATTERNS_STATE_H 49 | -------------------------------------------------------------------------------- /src/flyweight.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2016/12/29. 3 | // 4 | 5 | #ifndef DESIGN_PATTERNS_FLYWEIGHT_H 6 | #define DESIGN_PATTERNS_FLYWEIGHT_H 7 | 8 | #include 9 | #include 10 | 11 | class User { 12 | public: 13 | User() {} 14 | User(std::string); 15 | std::string GetName(); 16 | 17 | private: 18 | std::string name_; 19 | }; 20 | 21 | class Website { 22 | public: 23 | virtual void Use(User *) = 0; 24 | }; 25 | 26 | class ConcreteWebsite: public Website { 27 | public: 28 | ConcreteWebsite() {} 29 | ConcreteWebsite(std::string); 30 | void Use(User *); 31 | private: 32 | std::string website_name_; 33 | }; 34 | 35 | class WebsiteFactory { 36 | public: 37 | ~WebsiteFactory(); 38 | Website* GetWebsiteCategory(std::string); 39 | int GetWebsiteCount(); 40 | 41 | private: 42 | std::map flyweights_; 43 | }; 44 | 45 | #endif //DESIGN_PATTERNS_FLYWEIGHT_H 46 | -------------------------------------------------------------------------------- /src/prototype.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2016/12/28. 3 | // 4 | 5 | #ifndef DESIGN_PATTERNS_PROTOTYPE_H 6 | #define DESIGN_PATTERNS_PROTOTYPE_H 7 | 8 | #include 9 | class WorkExperience { 10 | public: 11 | void SetCompany(std::string); 12 | void SetTimeArea(std::string); 13 | std::string GetCompany(); 14 | std::string GetTimeArea(); 15 | WorkExperience* Clone(); 16 | 17 | private: 18 | std::string company_; 19 | std::string time_area_; 20 | }; 21 | 22 | class Resume { 23 | public: 24 | Resume() {}; 25 | Resume(std::string); 26 | ~Resume(); 27 | void SetPersonalInfo(std::string, std::string); 28 | void SetWorkExperience(std::string, std::string); 29 | Resume* Clone(); 30 | void PrintResume(); 31 | 32 | private: 33 | std::string name_; 34 | std::string sex_; 35 | std::string age_; 36 | WorkExperience *work_experience_; 37 | }; 38 | 39 | 40 | #endif //DESIGN_PATTERNS_PROTOTYPE_H 41 | -------------------------------------------------------------------------------- /tests/unit_tests/adapter_test.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2016/12/28. 3 | // 4 | 5 | #include "gtest/gtest.h" 6 | #include "adapter.h" 7 | 8 | class AdapterFixture: public ::testing::Test { 9 | protected: 10 | virtual void TearDown() {}; 11 | virtual void SetUp() {}; 12 | 13 | public: 14 | AdapterFixture(): Test() { 15 | forward_ = new Forward("Battier"); 16 | forward_->Attack(); 17 | forward_->Defense(); 18 | 19 | center_ = new Center("Russell"); 20 | center_->Attack(); 21 | center_->Defense(); 22 | 23 | translator_ = new Translator("YaoMing"); 24 | translator_->Attack(); 25 | translator_->Defense(); 26 | } 27 | 28 | virtual ~AdapterFixture() { 29 | delete forward_; 30 | delete center_; 31 | delete translator_; 32 | } 33 | 34 | Forward *forward_; 35 | Center *center_; 36 | Translator *translator_; 37 | }; 38 | 39 | TEST_F(AdapterFixture, adapter_test) { 40 | } -------------------------------------------------------------------------------- /src/aggregate.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2017/1/2. 3 | // 4 | 5 | #include "aggregate.h" 6 | 7 | Iterator* List::CreateIterator() { 8 | return new ListIterator(this); 9 | } 10 | 11 | int List::Count() { 12 | return (int)items_.size(); 13 | } 14 | 15 | int List::operator[] (int index) const { 16 | return items_[index]; 17 | } 18 | 19 | void List::Insert(int value) { 20 | items_.push_back(value); 21 | } 22 | 23 | ListIterator::ListIterator(List *aggregate): aggregate_(aggregate), current_(0) {} 24 | 25 | int ListIterator::First() { 26 | return (*aggregate_)[0]; 27 | } 28 | 29 | int ListIterator::Next() { 30 | int next = -1; 31 | if(++current_ < aggregate_->Count()) 32 | next = (*aggregate_)[current_]; 33 | return next; 34 | } 35 | 36 | bool ListIterator::IsDone() { 37 | return current_ >= aggregate_->Count(); 38 | } 39 | 40 | int ListIterator::CurrentItem() { 41 | return (*aggregate_)[current_]; 42 | } 43 | -------------------------------------------------------------------------------- /tests/unit_tests/factory_method_test.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2016/12/23. 3 | // 4 | 5 | 6 | #include "gtest/gtest.h" 7 | #include "factory_method.h" 8 | 9 | class FactoryMethodFixture: public ::testing::Test { 10 | protected: 11 | virtual void TearDown() {}; 12 | virtual void SetUp() {}; 13 | 14 | public: 15 | FactoryMethodFixture(): Test() { 16 | // use undergraduate to do chores 17 | i_factory_ = new UndergraduateFactory(); 18 | leifeng_ = i_factory_->CreateLeiFeng(); 19 | leifeng_->Wash(); 20 | 21 | // use volunteer to do chores 22 | i_factory_ = new VolunteerFactory(); 23 | leifeng_ = i_factory_->CreateLeiFeng(); 24 | leifeng_->Wash(); 25 | } 26 | 27 | virtual ~FactoryMethodFixture() { 28 | delete i_factory_; 29 | delete leifeng_; 30 | } 31 | 32 | IFactory* i_factory_; 33 | LeiFeng* leifeng_; 34 | }; 35 | 36 | TEST_F(FactoryMethodFixture, factory_method_test) { 37 | 38 | } -------------------------------------------------------------------------------- /tests/unit_tests/memento_test.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2016/12/28. 3 | // 4 | 5 | #include "gtest/gtest.h" 6 | #include "memento.h" 7 | #include 8 | #include 9 | 10 | class MementoFixture: public ::testing::Test { 11 | protected: 12 | virtual void TearDown() {}; 13 | virtual void SetUp() {}; 14 | 15 | public: 16 | MementoFixture(): Test() { 17 | game_role_ = new GameRole(); 18 | state_caretaker_ = new StateCaretaker(game_role_->CreateMemento()); 19 | game_role_->StateDisplay(); 20 | 21 | game_role_->Fight(); 22 | game_role_->StateDisplay(); 23 | 24 | game_role_->RecoveryState(state_caretaker_->GetMemento()); 25 | game_role_->StateDisplay(); 26 | } 27 | 28 | virtual ~MementoFixture() { 29 | delete game_role_; 30 | delete state_caretaker_; 31 | } 32 | 33 | GameRole* game_role_; 34 | StateCaretaker* state_caretaker_; 35 | }; 36 | 37 | TEST_F(MementoFixture, memento_test) { 38 | } -------------------------------------------------------------------------------- /src/proxy.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2016/12/29. 3 | // 4 | 5 | #ifndef DESIGN_PATTERNS_PROXY_H 6 | #define DESIGN_PATTERNS_PROXY_H 7 | 8 | #include 9 | #include 10 | 11 | class SchoolGirl { 12 | public: 13 | SchoolGirl() {} 14 | SchoolGirl(std::string); 15 | std::string GetName(); 16 | private: 17 | std::string name_; 18 | }; 19 | 20 | class GiveGift { 21 | public: 22 | virtual void GiveFlowers() = 0; 23 | virtual void GiveDolls() = 0; 24 | }; 25 | 26 | class Pursuit: public GiveGift{ 27 | public: 28 | Pursuit() {} 29 | Pursuit(SchoolGirl *); 30 | void GiveFlowers(); 31 | void GiveDolls(); 32 | 33 | private: 34 | SchoolGirl *school_girl_; 35 | }; 36 | 37 | class Proxy: public GiveGift{ 38 | public: 39 | Proxy() {} 40 | Proxy(SchoolGirl *); 41 | ~Proxy(); 42 | void GiveFlowers(); 43 | void GiveDolls(); 44 | 45 | private: 46 | Pursuit *pursuit_; 47 | }; 48 | 49 | 50 | #endif //DESIGN_PATTERNS_PROXY_H 51 | -------------------------------------------------------------------------------- /src/bridge.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2016/12/29. 3 | // 4 | 5 | #include "bridge.h" 6 | #include 7 | 8 | void HandsetGame::run() { 9 | std::cout << "run game" << std::endl; 10 | } 11 | 12 | void HandsetAddressList::run() { 13 | std::cout << "run address list" << std::endl; 14 | } 15 | 16 | HandsetBrand::HandsetBrand(HandsetSoft *handset_soft): handset_soft_(handset_soft) {} 17 | 18 | HandsetBrandM::HandsetBrandM(HandsetSoft *handset_soft): HandsetBrand(handset_soft) {} 19 | 20 | HandsetBrandM::~HandsetBrandM() { 21 | delete handset_soft_; 22 | } 23 | 24 | void HandsetBrandM::run() { 25 | std::cout << "handset brand M: "; 26 | handset_soft_->run(); 27 | } 28 | 29 | HandsetBrandN::HandsetBrandN(HandsetSoft *handset_soft): HandsetBrand(handset_soft) {} 30 | 31 | HandsetBrandN::~HandsetBrandN() { 32 | delete handset_soft_; 33 | } 34 | 35 | void HandsetBrandN::run() { 36 | std::cout << "handset brand N: "; 37 | handset_soft_->run(); 38 | } -------------------------------------------------------------------------------- /tests/unit_tests/bridge_test.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2016/12/28. 3 | // 4 | 5 | #include "gtest/gtest.h" 6 | #include "bridge.h" 7 | 8 | class BridgeFixture: public ::testing::Test { 9 | protected: 10 | virtual void TearDown() {}; 11 | virtual void SetUp() {}; 12 | 13 | public: 14 | BridgeFixture(): Test() { 15 | handset_brand_ = new HandsetBrandM(new HandsetGame); 16 | handset_brand_->run(); 17 | 18 | handset_brand_ = new HandsetBrandM(new HandsetAddressList); 19 | handset_brand_->run(); 20 | 21 | handset_brand_ = new HandsetBrandN(new HandsetGame); 22 | handset_brand_->run(); 23 | 24 | handset_brand_ = new HandsetBrandN(new HandsetAddressList); 25 | handset_brand_->run(); 26 | } 27 | 28 | virtual ~BridgeFixture() { 29 | delete handset_brand_; 30 | // delete handset_soft_; 31 | } 32 | 33 | HandsetBrand *handset_brand_; 34 | // HandsetSoft *handset_soft_; 35 | }; 36 | 37 | TEST_F(BridgeFixture, bridge_test) { 38 | } -------------------------------------------------------------------------------- /tests/unit_tests/interpreter_test.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2016/12/28. 3 | // 4 | 5 | #include "gtest/gtest.h" 6 | #include "interpreter.h" 7 | 8 | class InterpreterFixture: public ::testing::Test { 9 | protected: 10 | virtual void TearDown() {}; 11 | virtual void SetUp() {}; 12 | 13 | public: 14 | InterpreterFixture(): Test() { 15 | expression_factory_ = new ExpressionFactory(); 16 | context_ = new Context(); 17 | context_->SetText("O 2 E 0.5 G 0.5 A 3"); 18 | while(context_->GetText().length()) { 19 | expression_ = expression_factory_->CreateExpression(context_); 20 | expression_->Interprete(context_); 21 | delete expression_; 22 | } 23 | } 24 | 25 | virtual ~InterpreterFixture() { 26 | delete context_; 27 | delete expression_factory_; 28 | } 29 | 30 | Context *context_; 31 | ExpressionFactory *expression_factory_; 32 | Expression *expression_; 33 | }; 34 | 35 | TEST_F(InterpreterFixture, interpreter_test) { 36 | } -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/xcode/Samples/FrameworkSample/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | com.google.gtest.${PRODUCT_NAME:identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | FMWK 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | CSResourcesFileMapped 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/memento.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2017/1/3. 3 | // 4 | 5 | #include "memento.h" 6 | #include 7 | 8 | StateMemento::StateMemento(int hp, int mp): hp_(hp), mp_(mp) {} 9 | 10 | int StateMemento::GetHp() { 11 | return hp_; 12 | } 13 | 14 | int StateMemento::GetMp() { 15 | return mp_; 16 | } 17 | 18 | GameRole::GameRole(): hp_(100), mp_(100) {} 19 | 20 | StateMemento* GameRole::CreateMemento() { 21 | return new StateMemento(hp_, mp_); 22 | } 23 | 24 | void GameRole::StateDisplay() { 25 | std::cout << hp_ << " " << mp_ << std::endl; 26 | } 27 | 28 | void GameRole::Fight() { 29 | hp_ = 0; 30 | mp_ = 0; 31 | } 32 | 33 | void GameRole::RecoveryState(StateMemento *memento) { 34 | hp_ = memento->GetHp(); 35 | mp_ = memento->GetMp(); 36 | } 37 | 38 | StateCaretaker::StateCaretaker(StateMemento *memento): memento_(memento) {} 39 | 40 | StateCaretaker::~StateCaretaker() { 41 | delete memento_; 42 | } 43 | 44 | StateMemento* StateCaretaker::GetMemento() { 45 | return memento_; 46 | } 47 | 48 | 49 | -------------------------------------------------------------------------------- /src/bridge.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2016/12/29. 3 | // 4 | 5 | #ifndef DESIGN_PATTERNS_BRIDGE_H 6 | #define DESIGN_PATTERNS_BRIDGE_H 7 | 8 | class HandsetSoft { 9 | public: 10 | virtual void run() {} 11 | }; 12 | 13 | class HandsetGame: public HandsetSoft { 14 | public: 15 | void run(); 16 | }; 17 | 18 | class HandsetAddressList: public HandsetSoft { 19 | public: 20 | void run(); 21 | }; 22 | 23 | class HandsetBrand { 24 | public: 25 | HandsetBrand() {} 26 | HandsetBrand(HandsetSoft *); 27 | virtual ~HandsetBrand() {} 28 | virtual void run() {} 29 | 30 | protected: 31 | HandsetSoft *handset_soft_; 32 | }; 33 | 34 | class HandsetBrandM: public HandsetBrand { 35 | public: 36 | HandsetBrandM() {} 37 | HandsetBrandM(HandsetSoft *); 38 | ~HandsetBrandM(); 39 | void run(); 40 | }; 41 | 42 | class HandsetBrandN: public HandsetBrand { 43 | public: 44 | HandsetBrandN() {} 45 | HandsetBrandN(HandsetSoft *); 46 | ~HandsetBrandN(); 47 | void run(); 48 | }; 49 | 50 | 51 | #endif //DESIGN_PATTERNS_BRIDGE_H 52 | -------------------------------------------------------------------------------- /src/aggregate.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2017/1/2. 3 | // 4 | 5 | #ifndef DESIGN_PATTERNS_AGGREGATE_H 6 | #define DESIGN_PATTERNS_AGGREGATE_H 7 | 8 | #include 9 | 10 | class Iterator; 11 | 12 | class Aggregate { 13 | public: 14 | virtual ~Aggregate() {} 15 | virtual Iterator* CreateIterator() = 0; 16 | }; 17 | 18 | class List: public Aggregate { 19 | public: 20 | Iterator* CreateIterator(); 21 | int Count(); 22 | int operator[] (int) const; 23 | void Insert(int); 24 | 25 | private: 26 | std::vector items_; 27 | }; 28 | 29 | class Iterator { 30 | public: 31 | virtual int First() = 0; 32 | virtual int Next() = 0; 33 | virtual bool IsDone() = 0; 34 | virtual int CurrentItem() = 0; 35 | }; 36 | 37 | class ListIterator: public Iterator { 38 | public: 39 | ListIterator() {} 40 | ListIterator(List*); 41 | int First(); 42 | int Next(); 43 | bool IsDone(); 44 | int CurrentItem(); 45 | 46 | private: 47 | int current_; 48 | List *aggregate_; 49 | }; 50 | 51 | 52 | #endif //DESIGN_PATTERNS_AGGREGATE_H 53 | -------------------------------------------------------------------------------- /src/builder.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2016/12/28. 3 | // 4 | 5 | #ifndef DESIGN_PATTERNS_BUILDER_H 6 | #define DESIGN_PATTERNS_BUILDER_H 7 | 8 | class Pen { 9 | }; 10 | 11 | class Graphics { 12 | }; 13 | 14 | class PersonBuilder { 15 | public: 16 | PersonBuilder() {}; 17 | virtual ~PersonBuilder() {}; 18 | PersonBuilder(Pen*, Graphics*); 19 | virtual void BuildHead() {}; 20 | virtual void BuildBody() {}; 21 | 22 | protected: 23 | Pen* pen_; 24 | Graphics* graphics_; 25 | }; 26 | 27 | class PersonThinBuilder: public PersonBuilder { 28 | public: 29 | PersonThinBuilder(Pen*, Graphics*); 30 | void BuildHead(); 31 | void BuildBody(); 32 | }; 33 | 34 | class PersonFatBuilder: public PersonBuilder { 35 | public: 36 | PersonFatBuilder(Pen*, Graphics*); 37 | void BuildHead(); 38 | void BuildBody(); 39 | }; 40 | 41 | class PersonDirector { 42 | public: 43 | PersonDirector(PersonBuilder*); 44 | void CreatePerson(); 45 | private: 46 | PersonBuilder* person_builder_; 47 | 48 | }; 49 | 50 | #endif //DESIGN_PATTERNS_BUILDER_H 51 | -------------------------------------------------------------------------------- /src/command.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2017/1/3. 3 | // 4 | 5 | #ifndef DESIGN_PATTERNS_COMMAND_H 6 | #define DESIGN_PATTERNS_COMMAND_H 7 | 8 | #include 9 | 10 | class Barbecuer { 11 | public: 12 | void BakeMutton(); 13 | void BakeChicken(); 14 | }; 15 | 16 | class Command { 17 | public: 18 | Command() {} 19 | Command(Barbecuer*); 20 | virtual ~Command() {} 21 | virtual void ExecuteCommand() = 0; 22 | 23 | protected: 24 | Barbecuer* barbecuer_; 25 | }; 26 | 27 | class BakeMuttonCommand: public Command { 28 | public: 29 | BakeMuttonCommand() {} 30 | BakeMuttonCommand(Barbecuer*); 31 | void ExecuteCommand(); 32 | }; 33 | 34 | class BakeChickenCommand: public Command { 35 | public: 36 | BakeChickenCommand() {} 37 | BakeChickenCommand(Barbecuer*); 38 | void ExecuteCommand(); 39 | }; 40 | 41 | class Waiter { 42 | public: 43 | void SetOrder(Command*); 44 | void CancelOrder(Command*); 45 | void Notify(); 46 | 47 | private: 48 | std::vector commands_; 49 | }; 50 | 51 | 52 | #endif //DESIGN_PATTERNS_COMMAND_H 53 | -------------------------------------------------------------------------------- /tests/unit_tests/visitor_test.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2016/12/28. 3 | // 4 | 5 | #include "gtest/gtest.h" 6 | #include "visitor.h" 7 | 8 | class VisitorFixture: public ::testing::Test { 9 | protected: 10 | virtual void TearDown() {}; 11 | virtual void SetUp() {}; 12 | 13 | public: 14 | VisitorFixture(): Test() { 15 | man_ = new Man(); 16 | woman_ = new Woman(); 17 | object_structure_ = new ObjectStructure(); 18 | success_ = new Success(); 19 | failure_ = new Failure(); 20 | object_structure_->Attach(man_); 21 | object_structure_->Attach(woman_); 22 | object_structure_->Display(success_); 23 | object_structure_->Display(failure_); 24 | } 25 | 26 | virtual ~VisitorFixture() { 27 | delete man_; 28 | delete woman_; 29 | delete object_structure_; 30 | delete success_; 31 | delete failure_; 32 | } 33 | 34 | Person *man_; 35 | Person *woman_; 36 | ObjectStructure *object_structure_; 37 | Action *success_; 38 | Action *failure_; 39 | }; 40 | 41 | TEST_F(VisitorFixture, visitor_test) { 42 | } -------------------------------------------------------------------------------- /src/facade.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2016/12/29. 3 | // 4 | 5 | #include "facade.h" 6 | #include 7 | 8 | void Stock1::Buy() { 9 | std::cout << "buy stock1" << std::endl; 10 | } 11 | 12 | void Stock1::Sell() { 13 | std::cout << "sell stock1" << std::endl; 14 | } 15 | 16 | void Stock2::Buy() { 17 | std::cout << "buy stock2" << std::endl; 18 | } 19 | 20 | void Stock2::Sell() { 21 | std::cout << "sell stock2" << std::endl; 22 | } 23 | 24 | void Reality1::Buy() { 25 | std::cout << "buy reality1" << std::endl; 26 | } 27 | 28 | void Reality1::Sell() { 29 | std::cout << "sell reality1" << std::endl; 30 | } 31 | 32 | Fund::Fund() { 33 | stock1_ = new Stock1; 34 | stock2_ = new Stock2; 35 | reality1_ = new Reality1; 36 | } 37 | 38 | Fund::~Fund() { 39 | delete stock1_; 40 | delete stock2_; 41 | delete reality1_; 42 | } 43 | 44 | void Fund::BuyFund() { 45 | stock1_->Buy(); 46 | stock2_->Buy(); 47 | reality1_->Buy(); 48 | } 49 | 50 | void Fund::SellFund() { 51 | stock1_->Sell(); 52 | stock2_->Sell(); 53 | reality1_->Sell(); 54 | } 55 | -------------------------------------------------------------------------------- /tests/unit_tests/observer_test.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2016/12/28. 3 | // 4 | 5 | #include "gtest/gtest.h" 6 | #include "observer.h" 7 | 8 | class ObserverFixture: public ::testing::Test { 9 | protected: 10 | virtual void TearDown() {}; 11 | virtual void SetUp() {}; 12 | 13 | public: 14 | ObserverFixture(): Test() { 15 | boss_ = new Boss(); 16 | stock_observer_ = new StockObserver("Alice"); 17 | nba_observer_ = new NbaObserver("Bob"); 18 | boss_->SetState("boss is back himself"); 19 | 20 | stock_observer_->SetNotifier(boss_); 21 | nba_observer_->SetNotifier(boss_); 22 | boss_->Attach(stock_observer_); 23 | boss_->Attach(nba_observer_); 24 | boss_->Notify(); 25 | 26 | boss_->Detach(nba_observer_); 27 | boss_->Notify(); 28 | } 29 | 30 | virtual ~ObserverFixture() { 31 | delete boss_; 32 | delete stock_observer_; 33 | delete nba_observer_; 34 | } 35 | 36 | Boss *boss_; 37 | StockObserver *stock_observer_; 38 | NbaObserver *nba_observer_; 39 | 40 | }; 41 | 42 | TEST_F(ObserverFixture, observer_test) { 43 | } -------------------------------------------------------------------------------- /src/strategy.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2017/1/2. 3 | // 4 | 5 | #ifndef DESIGN_PATTERNS_STRATEGY_H 6 | #define DESIGN_PATTERNS_STRATEGY_H 7 | 8 | #include 9 | 10 | class CashSuper { 11 | public: 12 | virtual ~CashSuper() {} 13 | virtual double AcceptCash(double) = 0; 14 | }; 15 | 16 | class CashNormal: public CashSuper { 17 | public: 18 | double AcceptCash(double); 19 | }; 20 | 21 | class CashRebate: public CashSuper { 22 | public: 23 | CashRebate() {} 24 | CashRebate(double); 25 | double AcceptCash(double); 26 | 27 | private: 28 | double money_rebate_; 29 | }; 30 | 31 | class CashReturn: public CashSuper { 32 | public: 33 | CashReturn() {} 34 | CashReturn(double, double); 35 | double AcceptCash(double); 36 | 37 | private: 38 | double money_condition_; 39 | double money_return_; 40 | }; 41 | 42 | class CashContext { 43 | public: 44 | CashContext() {} 45 | CashContext(std::string, std::string); 46 | ~CashContext(); 47 | double GetResult(double); 48 | 49 | private: 50 | CashSuper *cash_; 51 | }; 52 | 53 | 54 | #endif //DESIGN_PATTERNS_STRATEGY_H 55 | -------------------------------------------------------------------------------- /src/visitor.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2017/1/3. 3 | // 4 | 5 | #ifndef DESIGN_PATTERNS_VISITOR_H 6 | #define DESIGN_PATTERNS_VISITOR_H 7 | 8 | #include 9 | 10 | class Action; 11 | 12 | class Person { 13 | public: 14 | virtual ~Person() {} 15 | virtual void Accept(Action*) = 0; 16 | }; 17 | 18 | class Man: public Person { 19 | public: 20 | void Accept(Action*); 21 | }; 22 | 23 | class Woman: public Person { 24 | public: 25 | void Accept(Action*); 26 | }; 27 | 28 | class ObjectStructure { 29 | public: 30 | void Attach(Person*); 31 | void Detach(Person*); 32 | void Display(Action*); 33 | 34 | private: 35 | std::vector people; 36 | }; 37 | 38 | class Action { 39 | public: 40 | virtual void GetManConclusion(Person*) = 0; 41 | virtual void GetWomanConclusion(Person*) = 0; 42 | }; 43 | 44 | class Success: public Action { 45 | void GetManConclusion(Person*); 46 | void GetWomanConclusion(Person*); 47 | }; 48 | 49 | class Failure: public Action { 50 | void GetManConclusion(Person*); 51 | void GetWomanConclusion(Person*); 52 | }; 53 | 54 | #endif //DESIGN_PATTERNS_VISITOR_H 55 | -------------------------------------------------------------------------------- /src/builder.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2016/12/28. 3 | // 4 | 5 | #include "builder.h" 6 | #include 7 | 8 | PersonDirector::PersonDirector(PersonBuilder* person_builder): person_builder_(person_builder) { 9 | 10 | } 11 | 12 | void PersonDirector::CreatePerson() { 13 | person_builder_->BuildBody(); 14 | person_builder_->BuildHead(); 15 | } 16 | 17 | PersonBuilder::PersonBuilder(Pen* pen, Graphics* graphics): pen_(pen), graphics_(graphics){ 18 | 19 | } 20 | 21 | PersonThinBuilder::PersonThinBuilder(Pen* pen, Graphics* graphics): PersonBuilder(pen, graphics) { 22 | 23 | } 24 | 25 | void PersonThinBuilder::BuildHead() { 26 | std::cout<< "Build Thin Head"< 7 | 8 | User::User(std::string name): name_(name) {} 9 | 10 | std::string User::GetName() { 11 | return name_; 12 | } 13 | 14 | ConcreteWebsite::ConcreteWebsite(std::string website_name): website_name_(website_name) {} 15 | 16 | void ConcreteWebsite::Use(User *user) { 17 | std::cout << user->GetName() << " use " << website_name_ << std::endl; 18 | } 19 | 20 | WebsiteFactory::~WebsiteFactory() { 21 | std::map ::iterator it; 22 | for(it = flyweights_.begin(); it != flyweights_.end(); it++) { 23 | delete it->second; 24 | } 25 | } 26 | 27 | Website* WebsiteFactory::GetWebsiteCategory(std::string website_name) { 28 | if(flyweights_.find(website_name) == flyweights_.end()) { 29 | Website *website = new ConcreteWebsite(website_name); 30 | flyweights_[website_name] = website; 31 | } 32 | return flyweights_[website_name]; 33 | } 34 | 35 | int WebsiteFactory::GetWebsiteCount() { 36 | int cnt = (int)flyweights_.size(); 37 | std::cout << cnt << std::endl; 38 | return cnt; 39 | } 40 | 41 | -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/xcode/Config/DebugProject.xcconfig: -------------------------------------------------------------------------------- 1 | // 2 | // DebugProject.xcconfig 3 | // 4 | // These are Debug Configuration project settings for the gtest framework and 5 | // examples. It is set in the "Based On:" dropdown in the "Project" info 6 | // dialog. 7 | // This file is based on the Xcode Configuration files in: 8 | // http://code.google.com/p/google-toolbox-for-mac/ 9 | // 10 | 11 | #include "General.xcconfig" 12 | 13 | // No optimization 14 | GCC_OPTIMIZATION_LEVEL = 0 15 | 16 | // Deployment postprocessing is what triggers Xcode to strip, turn it off 17 | DEPLOYMENT_POSTPROCESSING = NO 18 | 19 | // Dead code stripping off 20 | DEAD_CODE_STRIPPING = NO 21 | 22 | // Debug symbols should be on obviously 23 | GCC_GENERATE_DEBUGGING_SYMBOLS = YES 24 | 25 | // Define the DEBUG macro in all debug builds 26 | OTHER_CFLAGS = $(OTHER_CFLAGS) -DDEBUG=1 27 | 28 | // These are turned off to avoid STL incompatibilities with client code 29 | // // Turns on special C++ STL checks to "encourage" good STL use 30 | // GCC_PREPROCESSOR_DEFINITIONS = $(GCC_PREPROCESSOR_DEFINITIONS) _GLIBCXX_DEBUG_PEDANTIC _GLIBCXX_DEBUG _GLIBCPP_CONCEPT_CHECKS 31 | -------------------------------------------------------------------------------- /tests/unit_tests/aggregate_test.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2016/12/28. 3 | // 4 | 5 | #include "gtest/gtest.h" 6 | #include "aggregate.h" 7 | #include 8 | 9 | class AggregateFixture: public ::testing::Test { 10 | protected: 11 | virtual void TearDown() {}; 12 | virtual void SetUp() {}; 13 | 14 | public: 15 | AggregateFixture(): Test() { 16 | list_ = new List(); 17 | list_->Insert(1); 18 | list_->Insert(2); 19 | list_->Insert(3); 20 | list_iterator_ = list_->CreateIterator(); 21 | std::cout << list_iterator_->CurrentItem() << std::endl; 22 | std::cout << list_iterator_->First() << std::endl; 23 | std::cout << list_iterator_->Next() << std::endl; 24 | std::cout << list_iterator_->IsDone() << std::endl; 25 | std::cout << list_iterator_->Next() << std::endl; 26 | std::cout << list_iterator_->Next() << std::endl; 27 | std::cout << list_iterator_->IsDone() << std::endl; 28 | } 29 | 30 | virtual ~AggregateFixture() { 31 | delete list_; 32 | delete list_iterator_; 33 | } 34 | List *list_; 35 | Iterator *list_iterator_; 36 | }; 37 | 38 | TEST_F(AggregateFixture, aggregate_test) { 39 | } -------------------------------------------------------------------------------- /src/adapter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2016/12/29. 3 | // 4 | 5 | #ifndef DESIGN_PATTERNS_ADAPTER_H 6 | #define DESIGN_PATTERNS_ADAPTER_H 7 | 8 | #include 9 | 10 | class Player { 11 | public: 12 | Player() {} 13 | Player(std::string); 14 | virtual void Attack() {} 15 | virtual void Defense() {} 16 | 17 | protected: 18 | std::string name_; 19 | }; 20 | 21 | class Forward: public Player { 22 | public: 23 | Forward() {} 24 | Forward(std::string); 25 | void Attack(); 26 | void Defense(); 27 | }; 28 | 29 | class Center: public Player { 30 | public: 31 | Center() {} 32 | Center(std::string); 33 | void Attack(); 34 | void Defense(); 35 | }; 36 | 37 | class ForeignCenter { 38 | public: 39 | ForeignCenter() {} 40 | ForeignCenter(std::string); 41 | void Gong(); 42 | void Shou(); 43 | 44 | private: 45 | std::string name_; 46 | }; 47 | 48 | class Translator: public Player { 49 | public: 50 | Translator() {} 51 | Translator(std::string); 52 | ~Translator(); 53 | void Attack(); 54 | void Defense(); 55 | 56 | private: 57 | ForeignCenter *foreign_center_; 58 | }; 59 | 60 | 61 | #endif //DESIGN_PATTERNS_ADAPTER_H 62 | -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/xcode/Config/ReleaseProject.xcconfig: -------------------------------------------------------------------------------- 1 | // 2 | // ReleaseProject.xcconfig 3 | // 4 | // These are Release Configuration project settings for the gtest framework 5 | // and examples. It is set in the "Based On:" dropdown in the "Project" info 6 | // dialog. 7 | // This file is based on the Xcode Configuration files in: 8 | // http://code.google.com/p/google-toolbox-for-mac/ 9 | // 10 | 11 | #include "General.xcconfig" 12 | 13 | // subconfig/Release.xcconfig 14 | 15 | // Optimize for space and size (Apple recommendation) 16 | GCC_OPTIMIZATION_LEVEL = s 17 | 18 | // Deploment postprocessing is what triggers Xcode to strip 19 | DEPLOYMENT_POSTPROCESSING = YES 20 | 21 | // No symbols 22 | GCC_GENERATE_DEBUGGING_SYMBOLS = NO 23 | 24 | // Dead code strip does not affect ObjC code but can help for C 25 | DEAD_CODE_STRIPPING = YES 26 | 27 | // NDEBUG is used by things like assert.h, so define it for general compat. 28 | // ASSERT going away in release tends to create unused vars. 29 | OTHER_CFLAGS = $(OTHER_CFLAGS) -DNDEBUG=1 -Wno-unused-variable 30 | 31 | // When we strip we want to strip all symbols in release, but save externals. 32 | STRIP_STYLE = all 33 | -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/xcode/Resources/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | com.google.${PRODUCT_NAME} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleSignature 18 | ???? 19 | CFBundleVersion 20 | GTEST_VERSIONINFO_LONG 21 | CFBundleShortVersionString 22 | GTEST_VERSIONINFO_SHORT 23 | CFBundleGetInfoString 24 | ${PRODUCT_NAME} GTEST_VERSIONINFO_LONG, ${GTEST_VERSIONINFO_ABOUT} 25 | NSHumanReadableCopyright 26 | ${GTEST_VERSIONINFO_ABOUT} 27 | CSResourcesFileMapped 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /tests/unit_tests/prototype_test.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2016/12/28. 3 | // 4 | 5 | #include "gtest/gtest.h" 6 | #include "prototype.h" 7 | 8 | class PrototypeFixture: public ::testing::Test { 9 | protected: 10 | virtual void TearDown() {}; 11 | virtual void SetUp() {}; 12 | 13 | public: 14 | PrototypeFixture(): Test() { 15 | resume1_ = new Resume("Bob"); 16 | resume1_->SetPersonalInfo("M", "24"); 17 | resume1_->SetWorkExperience("Google", "2015~2017"); 18 | resume2_ = resume1_->Clone(); 19 | resume1_->PrintResume(); 20 | resume2_->PrintResume(); 21 | resume2_->SetPersonalInfo("F", "23"); 22 | resume1_->PrintResume(); 23 | resume2_->PrintResume(); 24 | resume2_->SetWorkExperience("Twitter", "2016~2017"); 25 | resume1_->PrintResume(); 26 | resume2_->PrintResume(); 27 | resume1_->SetWorkExperience("Amazon", "2015-2017"); 28 | resume1_->PrintResume(); 29 | resume2_->PrintResume(); 30 | } 31 | 32 | virtual ~PrototypeFixture() { 33 | delete resume1_; 34 | delete resume2_; 35 | } 36 | 37 | Resume *resume1_; 38 | Resume *resume2_; 39 | }; 40 | 41 | TEST_F(PrototypeFixture, prototype_test) { 42 | } -------------------------------------------------------------------------------- /src/chain_of_responsibility.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2016/12/31. 3 | // 4 | 5 | #ifndef DESIGN_PATTERNS_CHAIN_OF_RESPONSIBILITY_H 6 | #define DESIGN_PATTERNS_CHAIN_OF_RESPONSIBILITY_H 7 | 8 | #include 9 | 10 | class Request { 11 | public: 12 | Request() {} 13 | Request(std::string, int); 14 | std::string GetType(); 15 | int GetNumber(); 16 | 17 | private: 18 | std::string type_; 19 | int number_; 20 | }; 21 | 22 | class Manager { 23 | public: 24 | Manager() {} 25 | Manager(std::string); 26 | void SetSuperior(Manager *); 27 | virtual void RequestApplications(Request *) = 0; 28 | 29 | protected: 30 | Manager *superior_; 31 | std::string name_; 32 | }; 33 | 34 | class CommonManager: public Manager { 35 | public: 36 | CommonManager(std::string); 37 | void RequestApplications(Request *); 38 | }; 39 | 40 | class Majordomo: public Manager { 41 | public: 42 | Majordomo(std::string); 43 | void RequestApplications(Request *); 44 | }; 45 | 46 | class GeneralManager: public Manager { 47 | public: 48 | GeneralManager(std::string); 49 | void RequestApplications(Request *); 50 | }; 51 | 52 | 53 | #endif //DESIGN_PATTERNS_CHAIN_OF_RESPONSIBILITY_H 54 | -------------------------------------------------------------------------------- /src/composite.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2016/12/30. 3 | // 4 | 5 | #ifndef DESIGN_PATTERNS_COMPOSITE_H 6 | #define DESIGN_PATTERNS_COMPOSITE_H 7 | 8 | #include 9 | #include 10 | 11 | class Company { 12 | public: 13 | Company() {} 14 | Company(std::string); 15 | virtual void Add(Company*) = 0; 16 | virtual void Display(int) = 0; 17 | virtual void LineOfDuty() = 0; 18 | 19 | protected: 20 | std::string name_; 21 | }; 22 | 23 | class HrDepartment: public Company { 24 | public: 25 | HrDepartment() {} 26 | HrDepartment(std::string); 27 | void Add(Company*) {} 28 | void Display(int); 29 | void LineOfDuty(); 30 | }; 31 | 32 | class FinanceDepartment: public Company { 33 | public: 34 | FinanceDepartment() {} 35 | FinanceDepartment(std::string); 36 | void Add(Company*) {} 37 | void Display(int); 38 | void LineOfDuty(); 39 | }; 40 | 41 | class ConcreteCompany: public Company { 42 | public: 43 | ConcreteCompany() {} 44 | ConcreteCompany(std::string); 45 | void Add(Company*); 46 | void Display(int); 47 | void LineOfDuty(); 48 | 49 | private: 50 | std::vector companies_; 51 | }; 52 | 53 | 54 | #endif //DESIGN_PATTERNS_COMPOSITE_H 55 | -------------------------------------------------------------------------------- /tests/unit_tests/flyweight_test.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2016/12/28. 3 | // 4 | 5 | #include "gtest/gtest.h" 6 | #include "flyweight.h" 7 | 8 | class FlyweightFixture: public ::testing::Test { 9 | protected: 10 | virtual void TearDown() {}; 11 | virtual void SetUp() {}; 12 | 13 | public: 14 | FlyweightFixture(): Test() { 15 | website_factory_ = new WebsiteFactory(); 16 | website_ = website_factory_->GetWebsiteCategory("bbs"); 17 | website_->Use(new User("Bob")); 18 | website_->Use(new User("Alice")); 19 | website_factory_->GetWebsiteCount(); 20 | 21 | website_ = website_factory_->GetWebsiteCategory("blog"); 22 | website_->Use(new User("Bob")); 23 | website_->Use(new User("Alice")); 24 | website_factory_->GetWebsiteCount(); 25 | 26 | website_ = website_factory_->GetWebsiteCategory("bbs"); 27 | website_->Use(new User("Bob")); 28 | website_->Use(new User("Alice")); 29 | website_factory_->GetWebsiteCount(); 30 | 31 | } 32 | 33 | virtual ~FlyweightFixture() { 34 | delete website_factory_; 35 | } 36 | 37 | WebsiteFactory *website_factory_; 38 | Website *website_; 39 | }; 40 | 41 | TEST_F(FlyweightFixture, flyweight_test) { 42 | } -------------------------------------------------------------------------------- /src/mediator.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2017/1/3. 3 | // 4 | 5 | #ifndef DESIGN_PATTERNS_MEDIATOR_H 6 | #define DESIGN_PATTERNS_MEDIATOR_H 7 | 8 | #include 9 | 10 | class Country; 11 | 12 | class UnitedNations { 13 | public: 14 | virtual void Declare(std::string, Country*) = 0; 15 | }; 16 | 17 | class UnitedNationsSecurityCouncil: public UnitedNations { 18 | public: 19 | UnitedNationsSecurityCouncil() {} 20 | void SetUsa(Country*); 21 | void SetIraq(Country*); 22 | void Declare(std::string, Country*); 23 | 24 | private: 25 | Country *usa_; 26 | Country *iraq_; 27 | }; 28 | 29 | class Country { 30 | public: 31 | Country() {} 32 | Country(UnitedNations*); 33 | virtual void Declare(std::string) = 0; 34 | virtual void GetMessage(std::string) = 0; 35 | 36 | protected: 37 | UnitedNations *mediator_; 38 | }; 39 | 40 | class Usa: public Country { 41 | public: 42 | Usa(UnitedNations*); 43 | void Declare(std::string); 44 | void GetMessage(std::string); 45 | }; 46 | 47 | class Iraq: public Country { 48 | public: 49 | Iraq(UnitedNations*); 50 | void Declare(std::string); 51 | void GetMessage(std::string); 52 | }; 53 | 54 | 55 | #endif //DESIGN_PATTERNS_MEDIATOR_H 56 | -------------------------------------------------------------------------------- /src/mediator.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2017/1/3. 3 | // 4 | 5 | #include "mediator.h" 6 | #include 7 | 8 | void UnitedNationsSecurityCouncil::SetUsa(Country *usa) { 9 | usa_ = usa; 10 | } 11 | 12 | void UnitedNationsSecurityCouncil::SetIraq(Country *iraq) { 13 | iraq_ = iraq; 14 | } 15 | 16 | void UnitedNationsSecurityCouncil::Declare(std::string message, Country * country) { 17 | if(country == usa_) { 18 | iraq_->GetMessage(message); 19 | } else if(country == iraq_){ 20 | usa_->GetMessage(message); 21 | } 22 | } 23 | 24 | Country::Country(UnitedNations *mediator): mediator_(mediator) {} 25 | 26 | Usa::Usa(UnitedNations *mediator): Country(mediator) {} 27 | 28 | void Usa::Declare(std::string message) { 29 | mediator_->Declare(message, this); 30 | } 31 | 32 | void Usa::GetMessage(std::string message) { 33 | std::cout << "USA gets: \"" << message << "\"" << std::endl; 34 | } 35 | 36 | Iraq::Iraq(UnitedNations *mediator): Country(mediator) {} 37 | 38 | void Iraq::Declare(std::string message) { 39 | mediator_->Declare(message, this); 40 | } 41 | 42 | void Iraq::GetMessage(std::string message) { 43 | std::cout << "Iraq gets: \"" << message << "\"" << std::endl; 44 | } 45 | 46 | -------------------------------------------------------------------------------- /tests/unit_tests/builder_test.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2016/12/23. 3 | // 4 | 5 | 6 | #include "gtest/gtest.h" 7 | #include "builder.h" 8 | 9 | class BuilderFixture: public ::testing::Test { 10 | protected: 11 | virtual void TearDown() {}; 12 | virtual void SetUp() {}; 13 | 14 | public: 15 | BuilderFixture(): Test() { 16 | pen_ = new Pen; 17 | graphics_ = new Graphics; 18 | 19 | // build thin person 20 | person_builder_ = new PersonThinBuilder(pen_, graphics_); 21 | person_director_ = new PersonDirector(person_builder_); 22 | person_director_->CreatePerson(); 23 | 24 | // build fat person 25 | person_builder_ = new PersonFatBuilder(pen_, graphics_); // just replace PersonThinBuilder with PersonFatBuilder 26 | person_director_ = new PersonDirector(person_builder_); 27 | person_director_->CreatePerson(); 28 | } 29 | 30 | virtual ~BuilderFixture() { 31 | delete pen_; 32 | delete graphics_; 33 | delete person_builder_; 34 | delete person_director_; 35 | } 36 | 37 | Pen *pen_; 38 | Graphics *graphics_; 39 | PersonBuilder* person_builder_; 40 | PersonDirector* person_director_; 41 | }; 42 | 43 | TEST_F(BuilderFixture, builder_test) { 44 | } -------------------------------------------------------------------------------- /src/observer.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2017/1/2. 3 | // 4 | 5 | #ifndef DESIGN_PATTERNS_OBSERVER_H 6 | #define DESIGN_PATTERNS_OBSERVER_H 7 | 8 | #include 9 | #include 10 | 11 | class Notifier; 12 | 13 | class Observer { 14 | public: 15 | Observer() {} 16 | Observer(std::string); 17 | virtual ~Observer() {} 18 | void SetNotifier(Notifier *); 19 | virtual void Update() = 0; 20 | 21 | protected: 22 | std::string name_; 23 | Notifier *notifier_; 24 | }; 25 | 26 | class StockObserver: public Observer { 27 | public: 28 | StockObserver() {} 29 | StockObserver(std::string); 30 | void Update(); 31 | }; 32 | 33 | class NbaObserver: public Observer { 34 | public: 35 | NbaObserver() {} 36 | NbaObserver(std::string); 37 | void Update(); 38 | }; 39 | 40 | class Notifier { 41 | public: 42 | virtual ~Notifier() {} 43 | void Attach(Observer *); 44 | void Detach(Observer *); 45 | void SetState(std::string); 46 | std::string GetState(); 47 | void Notify(); 48 | 49 | protected: 50 | std::vector observers_; 51 | std::string state_; 52 | }; 53 | 54 | class Secretary: public Notifier { 55 | }; 56 | 57 | class Boss: public Notifier { 58 | }; 59 | 60 | 61 | #endif //DESIGN_PATTERNS_OBSERVER_H 62 | -------------------------------------------------------------------------------- /src/state.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2017/1/2. 3 | // 4 | 5 | #include "state.h" 6 | #include 7 | 8 | Work::Work() { 9 | state_ = new WorkingState(); 10 | } 11 | 12 | Work::~Work() { 13 | delete state_; 14 | } 15 | 16 | void Work::SetState(State *state) { 17 | delete state_; 18 | state_ = state; 19 | } 20 | 21 | void Work::WriteProgram() { 22 | state_->WriteProgram(this); 23 | } 24 | 25 | void WorkingState::WriteProgram(Work *work) { 26 | if(work->hour_ < 17) { 27 | std::cout << work->hour_ << " : working" << std::endl; 28 | } else { 29 | work->SetState(new OvertimeState()); 30 | work->WriteProgram(); 31 | } 32 | } 33 | 34 | void OvertimeState::WriteProgram(Work *work) { 35 | if(work->finished_) { 36 | work->SetState(new RestState()); 37 | work->WriteProgram(); 38 | } else if (work->hour_ < 21) { 39 | std::cout << work->hour_ << " : overtime" << std::endl; 40 | } else { 41 | work->SetState(new SleepingState()); 42 | work->WriteProgram(); 43 | } 44 | } 45 | 46 | void RestState::WriteProgram(Work *work) { 47 | std::cout << work->hour_ << " : return to rest" << std::endl; 48 | } 49 | 50 | void SleepingState::WriteProgram(Work *work) { 51 | std::cout << work->hour_ << " : sleeping" << std::endl; 52 | } -------------------------------------------------------------------------------- /tests/unit_tests/command_test.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2016/12/28. 3 | // 4 | 5 | #include "gtest/gtest.h" 6 | #include "command.h" 7 | 8 | class CommandFixture: public ::testing::Test { 9 | protected: 10 | virtual void TearDown() {}; 11 | virtual void SetUp() {}; 12 | 13 | public: 14 | CommandFixture(): Test() { 15 | barbecuer_ = new Barbecuer(); 16 | bake_mutton_command1_ = new BakeMuttonCommand(barbecuer_); 17 | bake_mutton_command2_ = new BakeMuttonCommand(barbecuer_); 18 | bake_chicken_command_ = new BakeChickenCommand(barbecuer_); 19 | waiter_ = new Waiter(); 20 | waiter_->SetOrder(bake_mutton_command1_); 21 | waiter_->SetOrder(bake_mutton_command2_); 22 | waiter_->SetOrder(bake_chicken_command_); 23 | waiter_->CancelOrder(bake_mutton_command2_); 24 | waiter_->Notify(); 25 | } 26 | 27 | virtual ~CommandFixture() { 28 | delete barbecuer_; 29 | delete bake_mutton_command1_; 30 | delete bake_mutton_command2_; 31 | delete bake_chicken_command_; 32 | delete waiter_; 33 | } 34 | 35 | Barbecuer *barbecuer_; 36 | Command *bake_mutton_command1_; 37 | Command *bake_mutton_command2_; 38 | Command *bake_chicken_command_; 39 | Waiter *waiter_; 40 | }; 41 | 42 | TEST_F(CommandFixture, command_test) { 43 | } -------------------------------------------------------------------------------- /main.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | std::cout << "\n" 6 | "________ .__ \n" 7 | "\\______ \\ ____ _____|__| ____ ____ \n" 8 | " | | \\_/ __ \\ / ___/ |/ ___\\ / \\ \n" 9 | " | ` \\ ___/ \\___ \\| / /_/ > | \\\n" 10 | "/_______ /\\___ >____ >__\\___ /|___| /\n" 11 | " \\/ \\/ \\/ /_____/ \\/ \n" 12 | "__________ __ __ \n" 13 | "\\______ \\_____ _/ |__/ |_ ___________ ____ ______\n" 14 | " | ___/\\__ \\\\ __\\ __\\/ __ \\_ __ \\/ \\ / ___/\n" 15 | " | | / __ \\| | | | \\ ___/| | \\/ | \\\\___ \\ \n" 16 | " |____| (____ /__| |__| \\___ >__| |___| /____ >\n" 17 | " \\/ \\/ \\/ \\/ " 18 | "\n\n" 19 | " | ~~|~ ' \n" 20 | " |~~\\\\ / |/~/|/~\\ |/~\\ |/~~/~~|\n" 21 | " |__/ \\/ \\_|\\/_| || ||\\__\\__|\n" 22 | " _/ " 23 | "\n" << std::endl; 24 | return 0; 25 | } -------------------------------------------------------------------------------- /src/visitor.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2017/1/3. 3 | // 4 | 5 | #include "visitor.h" 6 | #include 7 | 8 | void Man::Accept(Action *action) { 9 | action->GetManConclusion(this); 10 | } 11 | 12 | void Woman::Accept(Action *action) { 13 | action->GetWomanConclusion(this); 14 | } 15 | 16 | void ObjectStructure::Attach(Person *person) { 17 | people.push_back(person); 18 | } 19 | 20 | void ObjectStructure::Detach(Person *person) { 21 | for(std::vector ::iterator it = people.begin(); it != people.end(); ++it) { 22 | if(*it == person) { 23 | people.erase(it); 24 | return; 25 | } 26 | } 27 | } 28 | 29 | void ObjectStructure::Display(Action *action) { 30 | for (std::vector::iterator it = people.begin(); it != people.end(); ++it) { 31 | (*it)->Accept(action); 32 | } 33 | } 34 | 35 | void Success::GetManConclusion(Person *person) { 36 | std::cout << "man gets success" << std::endl; 37 | } 38 | 39 | void Success::GetWomanConclusion(Person *person) { 40 | std::cout << "woman gets success" << std::endl; 41 | } 42 | 43 | void Failure::GetManConclusion(Person *person) { 44 | std::cout << "man gets failure" << std::endl; 45 | } 46 | 47 | void Failure::GetWomanConclusion(Person *person) { 48 | std::cout << "woman gets failure" << std::endl; 49 | } 50 | 51 | 52 | -------------------------------------------------------------------------------- /tests/unit_tests/chain_of_responsibility_test.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2016/12/28. 3 | // 4 | 5 | #include "gtest/gtest.h" 6 | #include "chain_of_responsibility.h" 7 | 8 | class ChainOfResponsibilityFixture: public ::testing::Test { 9 | protected: 10 | virtual void TearDown() {}; 11 | virtual void SetUp() {}; 12 | 13 | public: 14 | ChainOfResponsibilityFixture(): Test() { 15 | common_manager_ = new CommonManager("JingLi"); 16 | majordomo_ = new Majordomo("ZongJian"); 17 | general_manager_ = new GeneralManager("ZongJingLi"); 18 | common_manager_->SetSuperior(majordomo_); 19 | majordomo_->SetSuperior(general_manager_); 20 | 21 | request1_ = new Request("leave application", 4); 22 | common_manager_->RequestApplications(request1_); 23 | 24 | request2_ = new Request("salary increase", 1000); 25 | common_manager_->RequestApplications(request2_); 26 | } 27 | 28 | virtual ~ChainOfResponsibilityFixture(){ 29 | delete request1_; 30 | delete request2_; 31 | delete common_manager_; 32 | delete majordomo_; 33 | delete general_manager_; 34 | } 35 | 36 | Request *request1_, *request2_; 37 | CommonManager *common_manager_; 38 | Majordomo *majordomo_; 39 | GeneralManager *general_manager_; 40 | }; 41 | 42 | TEST_F(ChainOfResponsibilityFixture, chain_of_responsibility_test) { 43 | } -------------------------------------------------------------------------------- /src/observer.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2017/1/2. 3 | // 4 | 5 | #include "observer.h" 6 | #include 7 | 8 | Observer::Observer(std::string name): name_(name) {} 9 | 10 | void Observer::SetNotifier(Notifier *notifier) { 11 | notifier_ = notifier; 12 | } 13 | 14 | void Notifier::Attach(Observer * observer) { 15 | observers_.push_back(observer); 16 | } 17 | 18 | void Notifier::Detach(Observer * observer) { 19 | for(std::vector ::iterator it = observers_.begin(); it != observers_.end(); ++it) { 20 | if(*it == observer) { 21 | observers_.erase(it); 22 | return; 23 | } 24 | } 25 | } 26 | 27 | void Notifier::SetState(std::string state) { 28 | state_ = state; 29 | } 30 | 31 | std::string Notifier::GetState() { 32 | return state_; 33 | } 34 | 35 | void Notifier::Notify() { 36 | for(std::vector ::iterator it = observers_.begin(); it != observers_.end(); ++it) { 37 | (*it)->Update(); 38 | } 39 | } 40 | 41 | StockObserver::StockObserver(std::string name): Observer(name) {} 42 | 43 | void StockObserver::Update() { 44 | std::cout << name_ << ", " << notifier_->GetState() << ", close stock" << std::endl; 45 | } 46 | 47 | NbaObserver::NbaObserver(std::string name): Observer(name) {} 48 | 49 | void NbaObserver::Update() { 50 | std::cout << name_ << ", " << notifier_->GetState() << ", close NBA" << std::endl; 51 | } -------------------------------------------------------------------------------- /src/adapter.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2016/12/29. 3 | // 4 | 5 | #include "adapter.h" 6 | #include 7 | 8 | Player::Player(std::string name): name_(name) {} 9 | 10 | Forward::Forward(std::string name): Player(name) {} 11 | 12 | void Forward::Attack() { 13 | std::cout << "forward " << name_ << " attack" << std::endl; 14 | } 15 | 16 | void Forward::Defense() { 17 | std::cout << "forward " << name_ << " defense" << std::endl; 18 | } 19 | 20 | Center::Center(std::string name): Player(name) {} 21 | 22 | void Center::Attack() { 23 | std::cout << "center " << name_ << " attack" << std::endl; 24 | } 25 | 26 | void Center::Defense() { 27 | std::cout << "center " << name_ << " defense" << std::endl; 28 | } 29 | 30 | ForeignCenter::ForeignCenter(std::string name): name_(name) {} 31 | 32 | void ForeignCenter::Gong() { 33 | std::cout << "foreign center " << name_ << " attack" << std::endl; 34 | } 35 | 36 | void ForeignCenter::Shou() { 37 | std::cout << "foreign center " << name_ << " defense" << std::endl; 38 | } 39 | 40 | Translator::Translator(std::string name): Player(name) { 41 | foreign_center_ = new ForeignCenter(name); 42 | } 43 | 44 | Translator::~Translator() { 45 | delete foreign_center_; 46 | } 47 | 48 | void Translator::Attack() { 49 | foreign_center_->Gong(); 50 | } 51 | 52 | void Translator::Defense() { 53 | foreign_center_->Shou(); 54 | } 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/xcode/Config/General.xcconfig: -------------------------------------------------------------------------------- 1 | // 2 | // General.xcconfig 3 | // 4 | // These are General configuration settings for the gtest framework and 5 | // examples. 6 | // This file is based on the Xcode Configuration files in: 7 | // http://code.google.com/p/google-toolbox-for-mac/ 8 | // 9 | 10 | // Build for PPC and Intel, 32- and 64-bit 11 | ARCHS = i386 x86_64 ppc ppc64 12 | 13 | // Zerolink prevents link warnings so turn it off 14 | ZERO_LINK = NO 15 | 16 | // Prebinding considered unhelpful in 10.3 and later 17 | PREBINDING = NO 18 | 19 | // Strictest warning policy 20 | WARNING_CFLAGS = -Wall -Werror -Wendif-labels -Wnewline-eof -Wno-sign-compare -Wshadow 21 | 22 | // Work around Xcode bugs by using external strip. See: 23 | // http://lists.apple.com/archives/Xcode-users/2006/Feb/msg00050.html 24 | SEPARATE_STRIP = YES 25 | 26 | // Force C99 dialect 27 | GCC_C_LANGUAGE_STANDARD = c99 28 | 29 | // not sure why apple defaults this on, but it's pretty risky 30 | ALWAYS_SEARCH_USER_PATHS = NO 31 | 32 | // Turn on position dependent code for most cases (overridden where appropriate) 33 | GCC_DYNAMIC_NO_PIC = YES 34 | 35 | // Default SDK and minimum OS version is 10.4 36 | SDKROOT = $(DEVELOPER_SDK_DIR)/MacOSX10.4u.sdk 37 | MACOSX_DEPLOYMENT_TARGET = 10.4 38 | GCC_VERSION = 4.0 39 | 40 | // VERSIONING BUILD SETTINGS (used in Info.plist) 41 | GTEST_VERSIONINFO_ABOUT = © 2008 Google Inc. 42 | -------------------------------------------------------------------------------- /tests/unit_tests/abstract_factory_test.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2016/12/23. 3 | // 4 | 5 | 6 | #include "gtest/gtest.h" 7 | #include "abstract_factory.h" 8 | 9 | class AbstractFactoryFixture: public ::testing::Test { 10 | protected: 11 | virtual void TearDown() {} 12 | virtual void SetUp() {} 13 | 14 | public: 15 | AbstractFactoryFixture() : Test() { 16 | // use sqlserver to insert/get user/department 17 | i_factory_ = new SqlserverFactory(); 18 | 19 | i_user_ = i_factory_->CreateUser(); 20 | i_user_->InsertUser(new User()); 21 | i_user_->GetUser(0); 22 | 23 | i_department_ = i_factory_->CreateDepartment(); 24 | i_department_->InsertDepartment(new Department()); 25 | i_department_-> GetDepartment(0); 26 | 27 | // use accecss to insert/get user/department 28 | i_factory_ = new AccessFactory(); //compared with sqlserver abobve, only change here 29 | 30 | i_user_ = i_factory_->CreateUser(); 31 | i_user_->InsertUser(new User()); 32 | i_user_->GetUser(0); 33 | 34 | i_department_ = i_factory_->CreateDepartment(); 35 | i_department_->InsertDepartment(new Department()); 36 | i_department_-> GetDepartment(0); 37 | } 38 | 39 | virtual ~AbstractFactoryFixture() { 40 | delete i_factory_; 41 | delete i_user_; 42 | delete i_department_; 43 | } 44 | 45 | IFactory* i_factory_; 46 | IUser* i_user_; 47 | IDepartment* i_department_; 48 | }; 49 | 50 | TEST_F(AbstractFactoryFixture, abstract_factory_test) { 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/interpreter.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2017/1/3. 3 | // 4 | 5 | #include "interpreter.h" 6 | #include 7 | #include 8 | 9 | std::string Context::GetText() { 10 | return text_; 11 | } 12 | 13 | void Context::SetText(std::string text) { 14 | text_ = text; 15 | } 16 | 17 | void Expression::Interprete(Context *context) { 18 | std::stringstream ss; 19 | std::string key; 20 | double value; 21 | std::string remain_text = context->GetText(); 22 | ss << remain_text; 23 | ss >> key >> value; 24 | remain_text = remain_text.substr(remain_text.find(" ")+1); 25 | remain_text = remain_text.substr(remain_text.find(" ")+1); 26 | if(remain_text.length() < 3){ 27 | remain_text = ""; 28 | } 29 | context->SetText(remain_text); 30 | Excute(key, value); 31 | } 32 | 33 | void Scale::Excute(std::string key, double value) { 34 | switch ((int)value){ 35 | case 1: 36 | std::cout << "bass " << std::endl; 37 | break; 38 | case 2: 39 | std::cout << "alto " << std::endl; 40 | break; 41 | case 3: 42 | std::cout << "treble " << std::endl; 43 | break; 44 | default: 45 | break; 46 | } 47 | } 48 | 49 | void Note::Excute(std::string key, double value) { 50 | std::cout << key[0] << std::endl; 51 | } 52 | 53 | Expression* ExpressionFactory::CreateExpression(Context *context) { 54 | char key = context->GetText()[0]; 55 | if(key == 'O') { 56 | return new Scale(); 57 | } else { 58 | return new Note(); 59 | } 60 | } -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | # This file contains a list of people who've made non-trivial 2 | # contribution to the Google C++ Testing Framework project. People 3 | # who commit code to the project are encouraged to add their names 4 | # here. Please keep the list sorted by first names. 5 | 6 | Ajay Joshi 7 | Balázs Dán 8 | Bharat Mediratta 9 | Chandler Carruth 10 | Chris Prince 11 | Chris Taylor 12 | Dan Egnor 13 | Eric Roman 14 | Hady Zalek 15 | Jeffrey Yasskin 16 | Jói Sigurðsson 17 | Keir Mierle 18 | Keith Ray 19 | Kenton Varda 20 | Manuel Klimek 21 | Markus Heule 22 | Mika Raento 23 | Miklós Fazekas 24 | Pasi Valminen 25 | Patrick Hanna 26 | Patrick Riley 27 | Peter Kaminski 28 | Preston Jackson 29 | Rainer Klaffenboeck 30 | Russ Cox 31 | Russ Rufer 32 | Sean Mcafee 33 | Sigurður Ásgeirsson 34 | Tracy Bialik 35 | Vadim Berman 36 | Vlad Losev 37 | Zhanyong Wan 38 | -------------------------------------------------------------------------------- /src/strategy.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2017/1/2. 3 | // 4 | 5 | #include "strategy.h" 6 | #include 7 | #include 8 | 9 | double CashNormal::AcceptCash(double money) { 10 | return money; 11 | } 12 | 13 | CashRebate::CashRebate(double money_rebate): money_rebate_(money_rebate) {} 14 | 15 | double CashRebate::AcceptCash(double money) { 16 | return money * money_rebate_; 17 | } 18 | 19 | CashReturn::CashReturn(double money_condition, double money_return): 20 | money_condition_(money_condition), money_return_(money_return) {} 21 | 22 | double CashReturn::AcceptCash(double money) { 23 | return money - (int)(money / money_condition_) * money_return_; 24 | } 25 | 26 | CashContext::CashContext(std::string type, std::string number) { 27 | if(type == "normal") { 28 | cash_ = new CashNormal(); 29 | } else if (type == "rebate") { 30 | std::stringstream ss; 31 | double money_rebate; 32 | ss << number; 33 | ss >> money_rebate; 34 | cash_ = new CashRebate(money_rebate); 35 | } else if (type == "return") { 36 | std::stringstream ss; 37 | double money_condition, money_return; 38 | ss << number; 39 | ss >> money_condition >> money_return; 40 | cash_ = new CashReturn(money_condition, money_return); 41 | } 42 | } 43 | 44 | CashContext::~CashContext() { 45 | delete cash_; 46 | } 47 | 48 | double CashContext::GetResult(double money) { 49 | double result = cash_->AcceptCash(money); 50 | std::cout << result << std::endl; 51 | return result; 52 | } 53 | 54 | -------------------------------------------------------------------------------- /src/composite.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2016/12/30. 3 | // 4 | 5 | #include "composite.h" 6 | #include 7 | 8 | Company::Company(std::string name): name_(name) {} 9 | 10 | HrDepartment::HrDepartment(std::string name): Company(name) {} 11 | 12 | void HrDepartment::Display(int depth) { 13 | for(int i = 0; i < depth; ++i) 14 | std::cout << "--"; 15 | std::cout << name_ << std::endl; 16 | } 17 | 18 | void HrDepartment::LineOfDuty() { 19 | std::cout << name_ << " : human resources" << std::endl; 20 | } 21 | 22 | FinanceDepartment::FinanceDepartment(std::string name): Company(name) {} 23 | 24 | void FinanceDepartment::Display(int depth) { 25 | for(int i = 0; i < depth; ++i) 26 | std::cout << "--"; 27 | std::cout << name_ << std::endl; 28 | } 29 | 30 | void FinanceDepartment::LineOfDuty() { 31 | std::cout << name_ << " : finance analysis" << std::endl; 32 | } 33 | 34 | ConcreteCompany::ConcreteCompany(std::string name): Company(name) {} 35 | 36 | void ConcreteCompany::Add(Company *company) { 37 | companies_.push_back(company); 38 | } 39 | 40 | void ConcreteCompany::Display(int depth) { 41 | for(int i = 0; i < depth; ++i) 42 | std::cout << "--"; 43 | std::cout << name_ << std::endl; 44 | for(std::vector ::iterator it = companies_.begin(); it != companies_.end(); ++it) { 45 | (*it)->Display(depth + 1); 46 | } 47 | } 48 | 49 | void ConcreteCompany::LineOfDuty() { 50 | for(std::vector ::iterator it = companies_.begin(); it != companies_.end(); ++it) { 51 | (*it)->LineOfDuty(); 52 | } 53 | } -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2008, Google Inc. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above 11 | copyright notice, this list of conditions and the following disclaimer 12 | in the documentation and/or other materials provided with the 13 | distribution. 14 | * Neither the name of Google Inc. nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | -------------------------------------------------------------------------------- /src/abstract_factory.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2016/12/23. 3 | // 4 | 5 | #ifndef DESIGN_PATTERNS_ABSTRACT_FACTORY_H 6 | #define DESIGN_PATTERNS_ABSTRACT_FACTORY_H 7 | 8 | 9 | class User { 10 | }; 11 | 12 | class IUser { 13 | public: 14 | virtual void InsertUser(User*) = 0; 15 | virtual User GetUser(int) = 0; 16 | }; 17 | 18 | class SqlserverUser: public IUser { 19 | public: 20 | void InsertUser(User* user); 21 | User GetUser(int id); 22 | }; 23 | 24 | class AccessUser: public IUser { 25 | public: 26 | void InsertUser(User* user); 27 | User GetUser(int id); 28 | }; 29 | 30 | class Department { 31 | }; 32 | 33 | class IDepartment { 34 | public: 35 | virtual void InsertDepartment(Department*) = 0; 36 | virtual Department GetDepartment(int) = 0; 37 | }; 38 | 39 | class SqlserverDepartment: public IDepartment { 40 | public: 41 | void InsertDepartment(Department* department); 42 | Department GetDepartment(int id); 43 | }; 44 | 45 | class AccessDepartment: public IDepartment { 46 | public: 47 | void InsertDepartment(Department* department); 48 | Department GetDepartment(int id); 49 | }; 50 | 51 | class IFactory { 52 | public: 53 | virtual IUser* CreateUser() = 0; 54 | virtual IDepartment* CreateDepartment() = 0; 55 | }; 56 | 57 | class SqlserverFactory: public IFactory { 58 | public: 59 | IUser* CreateUser(); 60 | IDepartment* CreateDepartment(); 61 | }; 62 | 63 | class AccessFactory: public IFactory { 64 | public: 65 | IUser* CreateUser(); 66 | IDepartment* CreateDepartment(); 67 | }; 68 | 69 | #endif //DESIGN_PATTERNS_ABSTRACT_FACTORY_H 70 | -------------------------------------------------------------------------------- /src/command.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2017/1/3. 3 | // 4 | 5 | #include "command.h" 6 | #include 7 | #include 8 | 9 | void Barbecuer::BakeMutton() { 10 | std::cout << "bake mutton" << std::endl; 11 | } 12 | 13 | void Barbecuer::BakeChicken() { 14 | std::cout << "bake chicken" << std::endl; 15 | } 16 | 17 | Command::Command(Barbecuer *barbecuer): barbecuer_(barbecuer) {} 18 | 19 | BakeMuttonCommand::BakeMuttonCommand(Barbecuer *barbecuer): Command(barbecuer) {} 20 | 21 | void BakeMuttonCommand::ExecuteCommand() { 22 | barbecuer_->BakeMutton(); 23 | } 24 | 25 | BakeChickenCommand::BakeChickenCommand(Barbecuer *barbecuer): Command(barbecuer) {} 26 | 27 | void BakeChickenCommand::ExecuteCommand() { 28 | barbecuer_->BakeChicken(); 29 | } 30 | 31 | void Waiter::SetOrder(Command *command) { 32 | if(dynamic_cast(command)){ 33 | std::cout << "chicken sold out" << std::endl; 34 | } else { 35 | commands_.push_back(command); 36 | std::cout << "add: " << std::string(typeid(*command).name()).substr(2) << std::endl; 37 | } 38 | } 39 | 40 | void Waiter::CancelOrder(Command *command) { 41 | for(std::vector ::iterator it = commands_.begin(); it != commands_.end(); ++it) { 42 | if(*it == command) { 43 | commands_.erase(it); 44 | std::cout << "cancel: " << std::string(typeid(*command).name()).substr(2) << std::endl; 45 | return; 46 | } 47 | } 48 | } 49 | 50 | void Waiter::Notify() { 51 | for (std::vector::iterator it = commands_.begin(); it != commands_.end(); ++it) { 52 | (*it)->ExecuteCommand(); 53 | } 54 | } 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /src/prototype.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2016/12/28. 3 | // 4 | 5 | #include "prototype.h" 6 | #include 7 | 8 | void WorkExperience::SetCompany(std::string company) { 9 | company_ = company; 10 | } 11 | 12 | void WorkExperience::SetTimeArea(std::string time_area) { 13 | time_area_ = time_area; 14 | } 15 | 16 | std::string WorkExperience::GetCompany() { 17 | return company_; 18 | } 19 | 20 | std::string WorkExperience::GetTimeArea() { 21 | return time_area_; 22 | } 23 | 24 | WorkExperience* WorkExperience::Clone() { 25 | WorkExperience* new_work_experience = new WorkExperience(); 26 | new_work_experience->SetCompany(company_); 27 | new_work_experience->SetTimeArea(time_area_); 28 | return new_work_experience; 29 | } 30 | 31 | Resume::Resume(std::string name) { 32 | name_ = name; 33 | work_experience_ = new WorkExperience(); 34 | } 35 | 36 | Resume::~Resume() { 37 | delete work_experience_; 38 | } 39 | 40 | void Resume::SetPersonalInfo(std::string sex, std::string age){ 41 | sex_ = sex; 42 | age_ = age; 43 | } 44 | 45 | void Resume::SetWorkExperience(std::string company, std::string time_area) { 46 | work_experience_->SetCompany(company); 47 | work_experience_->SetTimeArea(time_area); 48 | } 49 | 50 | Resume* Resume::Clone() { 51 | Resume* new_resume = new Resume(name_); 52 | new_resume->SetPersonalInfo(sex_, age_); 53 | new_resume->work_experience_ = work_experience_->Clone(); 54 | return new_resume; 55 | } 56 | 57 | void Resume::PrintResume() { 58 | std::cout<< name_ << ", " << sex_ << ", " << age_ << ", " 59 | << work_experience_->GetCompany() << " : " << work_experience_->GetTimeArea() << std::endl; 60 | } -------------------------------------------------------------------------------- /src/abstract_factory.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2016/12/23. 3 | // 4 | 5 | #include "abstract_factory.h" 6 | #include 7 | 8 | void SqlserverUser::InsertUser(User* user) { 9 | std::cout << "Insert User into Sqlserver" << std::endl; 10 | } 11 | 12 | User SqlserverUser::GetUser(int id) { 13 | std::cout << "Get User from Sqlserver" << std::endl; 14 | } 15 | 16 | void AccessUser::InsertUser(User* user) { 17 | std::cout << "Insert User into Access" << std::endl; 18 | } 19 | 20 | User AccessUser::GetUser(int id) { 21 | std::cout << "Get User from Access" << std::endl; 22 | } 23 | 24 | void SqlserverDepartment::InsertDepartment(Department* department) { 25 | std::cout << "Insert Department into Sqlserver" << std::endl; 26 | } 27 | 28 | Department SqlserverDepartment::GetDepartment(int id) { 29 | std::cout << "Get Department from Sqlserver" << std::endl; 30 | } 31 | 32 | void AccessDepartment::InsertDepartment(Department* department) { 33 | std::cout << "Insert Department into Access" << std::endl; 34 | } 35 | 36 | Department AccessDepartment::GetDepartment(int id) { 37 | std::cout << "Get Department from Access" << std::endl; 38 | } 39 | 40 | 41 | IUser* SqlserverFactory::CreateUser() { 42 | IUser* i_user = new SqlserverUser(); 43 | return i_user; 44 | } 45 | 46 | IDepartment* SqlserverFactory::CreateDepartment() { 47 | IDepartment* i_Department = new SqlserverDepartment(); 48 | return i_Department; 49 | } 50 | 51 | IUser* AccessFactory::CreateUser() { 52 | IUser* i_user = new AccessUser(); 53 | return i_user; 54 | } 55 | 56 | IDepartment* AccessFactory::CreateDepartment() { 57 | IDepartment* i_Department = new AccessDepartment(); 58 | return i_Department; 59 | } -------------------------------------------------------------------------------- /src/chain_of_responsibility.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2016/12/31. 3 | // 4 | 5 | #include "chain_of_responsibility.h" 6 | #include 7 | 8 | Request::Request(std::string type, int number): type_(type), number_(number) {} 9 | 10 | int Request::GetNumber() { 11 | return number_; 12 | } 13 | 14 | std::string Request::GetType() { 15 | return type_; 16 | } 17 | 18 | Manager::Manager(std::string name): name_(name) {} 19 | 20 | void Manager::SetSuperior(Manager *superior) { 21 | superior_ = superior; 22 | } 23 | 24 | CommonManager::CommonManager(std::string name): Manager(name) {} 25 | 26 | void CommonManager::RequestApplications(Request *request) { 27 | if(request->GetType() == "leave application" && request->GetNumber() <= 2){ 28 | std::cout << name_ << " : approve" << std::endl; 29 | } else { 30 | superior_->RequestApplications(request); 31 | } 32 | } 33 | 34 | Majordomo::Majordomo(std::string name): Manager(name) {} 35 | 36 | void Majordomo::RequestApplications(Request *request) { 37 | if(request->GetType() == "leave application" && request->GetNumber() <= 5){ 38 | std::cout << name_ << " : approve" << std::endl; 39 | } else { 40 | superior_->RequestApplications(request); 41 | } 42 | } 43 | 44 | GeneralManager::GeneralManager(std::string name): Manager(name) {} 45 | 46 | void GeneralManager::RequestApplications(Request *request) { 47 | if(request->GetType() == "leave application"){ 48 | std::cout << name_ << " : approve" << std::endl; 49 | } else if(request->GetType() == "salary increase" && request->GetNumber() <= 500){ 50 | std::cout << name_ << " : approve" << std::endl; 51 | } else { 52 | std::cout << name_ << " : not approve" << std::endl; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/test/production.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2006, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: wan@google.com (Zhanyong Wan) 31 | // 32 | // This is part of the unit test for include/gtest/gtest_prod.h. 33 | 34 | #include "production.h" 35 | 36 | PrivateCode::PrivateCode() : x_(0) {} 37 | -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/src/gtest_main.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2006, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | #include 31 | 32 | #include "gtest/gtest.h" 33 | 34 | GTEST_API_ int main(int argc, char **argv) { 35 | printf("Running main() from gtest_main.cc\n"); 36 | testing::InitGoogleTest(&argc, argv); 37 | return RUN_ALL_TESTS(); 38 | } 39 | -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/fused-src/gtest/gtest_main.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2006, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | #include 31 | 32 | #include "gtest/gtest.h" 33 | 34 | GTEST_API_ int main(int argc, char **argv) { 35 | printf("Running main() from gtest_main.cc\n"); 36 | testing::InitGoogleTest(&argc, argv); 37 | return RUN_ALL_TESTS(); 38 | } 39 | -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/codegear/gtest_all.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2009, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: Josh Kelley (joshkel@gmail.com) 31 | // 32 | // Google C++ Testing Framework (Google Test) 33 | // 34 | // C++Builder's IDE cannot build a static library from files with hyphens 35 | // in their name. See http://qc.codegear.com/wc/qcmain.aspx?d=70977 . 36 | // This file serves as a workaround. 37 | 38 | #include "src/gtest-all.cc" 39 | -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/scripts/test/Makefile: -------------------------------------------------------------------------------- 1 | # A Makefile for fusing Google Test and building a sample test against it. 2 | # 3 | # SYNOPSIS: 4 | # 5 | # make [all] - makes everything. 6 | # make TARGET - makes the given target. 7 | # make check - makes everything and runs the built sample test. 8 | # make clean - removes all files generated by make. 9 | 10 | # Points to the root of fused Google Test, relative to where this file is. 11 | FUSED_GTEST_DIR = output 12 | 13 | # Paths to the fused gtest files. 14 | FUSED_GTEST_H = $(FUSED_GTEST_DIR)/gtest/gtest.h 15 | FUSED_GTEST_ALL_CC = $(FUSED_GTEST_DIR)/gtest/gtest-all.cc 16 | 17 | # Where to find the sample test. 18 | SAMPLE_DIR = ../../samples 19 | 20 | # Where to find gtest_main.cc. 21 | GTEST_MAIN_CC = ../../src/gtest_main.cc 22 | 23 | # Flags passed to the preprocessor. 24 | # We have no idea here whether pthreads is available in the system, so 25 | # disable its use. 26 | CPPFLAGS += -I$(FUSED_GTEST_DIR) -DGTEST_HAS_PTHREAD=0 27 | 28 | # Flags passed to the C++ compiler. 29 | CXXFLAGS += -g 30 | 31 | all : sample1_unittest 32 | 33 | check : all 34 | ./sample1_unittest 35 | 36 | clean : 37 | rm -rf $(FUSED_GTEST_DIR) sample1_unittest *.o 38 | 39 | $(FUSED_GTEST_H) : 40 | ../fuse_gtest_files.py $(FUSED_GTEST_DIR) 41 | 42 | $(FUSED_GTEST_ALL_CC) : 43 | ../fuse_gtest_files.py $(FUSED_GTEST_DIR) 44 | 45 | gtest-all.o : $(FUSED_GTEST_H) $(FUSED_GTEST_ALL_CC) 46 | $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(FUSED_GTEST_DIR)/gtest/gtest-all.cc 47 | 48 | gtest_main.o : $(FUSED_GTEST_H) $(GTEST_MAIN_CC) 49 | $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(GTEST_MAIN_CC) 50 | 51 | sample1.o : $(SAMPLE_DIR)/sample1.cc $(SAMPLE_DIR)/sample1.h 52 | $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(SAMPLE_DIR)/sample1.cc 53 | 54 | sample1_unittest.o : $(SAMPLE_DIR)/sample1_unittest.cc \ 55 | $(SAMPLE_DIR)/sample1.h $(FUSED_GTEST_H) 56 | $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(SAMPLE_DIR)/sample1_unittest.cc 57 | 58 | sample1_unittest : sample1.o sample1_unittest.o gtest-all.o gtest_main.o 59 | $(CXX) $(CPPFLAGS) $(CXXFLAGS) $^ -o $@ 60 | -------------------------------------------------------------------------------- /tests/unit_tests/composite_test.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Jennica on 2016/12/28. 3 | // 4 | 5 | #include "gtest/gtest.h" 6 | #include "composite.h" 7 | 8 | class CompositeFixture: public ::testing::Test { 9 | protected: 10 | virtual void TearDown() {}; 11 | virtual void SetUp() {}; 12 | 13 | public: 14 | CompositeFixture(): Test() { 15 | beijing_head_office_ = new ConcreteCompany("Beijing Head Office"); 16 | beijing_head_office_->Add(new HrDepartment("Beijing HR Department")); 17 | beijing_head_office_->Add(new FinanceDepartment("Beijing Finance Department")); 18 | 19 | huadong_branch_office_ = new ConcreteCompany("Huadong Branch Office"); 20 | huadong_branch_office_->Add(new HrDepartment("Huadong HR Department")); 21 | huadong_branch_office_->Add(new FinanceDepartment("Huadong Finance Department")); 22 | beijing_head_office_->Add(huadong_branch_office_); 23 | 24 | nanjing_office_ = new ConcreteCompany("Nangjing Office"); 25 | nanjing_office_->Add(new HrDepartment("Nanjing HR Department")); 26 | nanjing_office_->Add(new FinanceDepartment("Nanjing Finance Department")); 27 | huadong_branch_office_->Add(nanjing_office_); 28 | 29 | hangzhou_office_ = new ConcreteCompany("Nangjing Office"); 30 | hangzhou_office_->Add(new HrDepartment("Hangzhou HR Department")); 31 | hangzhou_office_->Add(new FinanceDepartment("Hangzhou Finance Department")); 32 | huadong_branch_office_->Add(hangzhou_office_); 33 | 34 | std::cout << "Structure Tree:" << std::endl; 35 | beijing_head_office_->Display(0); 36 | 37 | std::cout << "Duty Lines:" << std::endl; 38 | beijing_head_office_->LineOfDuty(); 39 | } 40 | 41 | virtual ~CompositeFixture() { 42 | delete beijing_head_office_; 43 | delete huadong_branch_office_; 44 | delete nanjing_office_; 45 | delete hangzhou_office_; 46 | } 47 | 48 | ConcreteCompany *beijing_head_office_; 49 | ConcreteCompany *huadong_branch_office_; 50 | ConcreteCompany *nanjing_office_; 51 | ConcreteCompany *hangzhou_office_; 52 | }; 53 | 54 | TEST_F(CompositeFixture, composite_test) { 55 | } -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/test/gtest_main_unittest.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2006, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: wan@google.com (Zhanyong Wan) 31 | 32 | #include "gtest/gtest.h" 33 | 34 | // Tests that we don't have to define main() when we link to 35 | // gtest_main instead of gtest. 36 | 37 | namespace { 38 | 39 | TEST(GTestMainTest, ShouldSucceed) { 40 | } 41 | 42 | } // namespace 43 | 44 | // We are using the main() function defined in src/gtest_main.cc, so 45 | // we don't define it here. 46 | -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/samples/sample4_unittest.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2005, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: wan@google.com (Zhanyong Wan) 31 | 32 | #include "gtest/gtest.h" 33 | #include "sample4.h" 34 | 35 | // Tests the Increment() method. 36 | TEST(Counter, Increment) { 37 | Counter c; 38 | 39 | // EXPECT_EQ() evaluates its arguments exactly once, so they 40 | // can have side effects. 41 | 42 | EXPECT_EQ(0, c.Increment()); 43 | EXPECT_EQ(1, c.Increment()); 44 | EXPECT_EQ(2, c.Increment()); 45 | } 46 | -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/samples/sample1.h: -------------------------------------------------------------------------------- 1 | // Copyright 2005, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | // A sample program demonstrating using Google C++ testing framework. 31 | // 32 | // Author: wan@google.com (Zhanyong Wan) 33 | 34 | #ifndef GTEST_SAMPLES_SAMPLE1_H_ 35 | #define GTEST_SAMPLES_SAMPLE1_H_ 36 | 37 | // Returns n! (the factorial of n). For negative n, n! is defined to be 1. 38 | int Factorial(int n); 39 | 40 | // Returns true iff n is a prime number. 41 | bool IsPrime(int n); 42 | 43 | #endif // GTEST_SAMPLES_SAMPLE1_H_ 44 | -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/test/gtest_uninitialized_test_.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2008, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: wan@google.com (Zhanyong Wan) 31 | 32 | #include "gtest/gtest.h" 33 | 34 | TEST(DummyTest, Dummy) { 35 | // This test doesn't verify anything. We just need it to create a 36 | // realistic stage for testing the behavior of Google Test when 37 | // RUN_ALL_TESTS() is called without testing::InitGoogleTest() being 38 | // called first. 39 | } 40 | 41 | int main() { 42 | return RUN_ALL_TESTS(); 43 | } 44 | -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/samples/sample4.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2005, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | // A sample program demonstrating using Google C++ testing framework. 31 | // 32 | // Author: wan@google.com (Zhanyong Wan) 33 | 34 | #include 35 | 36 | #include "sample4.h" 37 | 38 | // Returns the current counter value, and increments it. 39 | int Counter::Increment() { 40 | return counter_++; 41 | } 42 | 43 | // Prints the current counter value to STDOUT. 44 | void Counter::Print() const { 45 | printf("%d", counter_); 46 | } 47 | -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/build-aux/config.h.in: -------------------------------------------------------------------------------- 1 | /* build-aux/config.h.in. Generated from configure.ac by autoheader. */ 2 | 3 | /* Define to 1 if you have the header file. */ 4 | #undef HAVE_DLFCN_H 5 | 6 | /* Define to 1 if you have the header file. */ 7 | #undef HAVE_INTTYPES_H 8 | 9 | /* Define to 1 if you have the header file. */ 10 | #undef HAVE_MEMORY_H 11 | 12 | /* Define if you have POSIX threads libraries and header files. */ 13 | #undef HAVE_PTHREAD 14 | 15 | /* Define to 1 if you have the header file. */ 16 | #undef HAVE_STDINT_H 17 | 18 | /* Define to 1 if you have the header file. */ 19 | #undef HAVE_STDLIB_H 20 | 21 | /* Define to 1 if you have the header file. */ 22 | #undef HAVE_STRINGS_H 23 | 24 | /* Define to 1 if you have the header file. */ 25 | #undef HAVE_STRING_H 26 | 27 | /* Define to 1 if you have the header file. */ 28 | #undef HAVE_SYS_STAT_H 29 | 30 | /* Define to 1 if you have the header file. */ 31 | #undef HAVE_SYS_TYPES_H 32 | 33 | /* Define to 1 if you have the header file. */ 34 | #undef HAVE_UNISTD_H 35 | 36 | /* Define to the sub-directory in which libtool stores uninstalled libraries. 37 | */ 38 | #undef LT_OBJDIR 39 | 40 | /* Name of package */ 41 | #undef PACKAGE 42 | 43 | /* Define to the address where bug reports for this package should be sent. */ 44 | #undef PACKAGE_BUGREPORT 45 | 46 | /* Define to the full name of this package. */ 47 | #undef PACKAGE_NAME 48 | 49 | /* Define to the full name and version of this package. */ 50 | #undef PACKAGE_STRING 51 | 52 | /* Define to the one symbol short name of this package. */ 53 | #undef PACKAGE_TARNAME 54 | 55 | /* Define to the home page for this package. */ 56 | #undef PACKAGE_URL 57 | 58 | /* Define to the version of this package. */ 59 | #undef PACKAGE_VERSION 60 | 61 | /* Define to necessary symbol if this constant uses a non-standard name on 62 | your system. */ 63 | #undef PTHREAD_CREATE_JOINABLE 64 | 65 | /* Define to 1 if you have the ANSI C header files. */ 66 | #undef STDC_HEADERS 67 | 68 | /* Version number of package */ 69 | #undef VERSION 70 | -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/codegear/gtest_link.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2009, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: Josh Kelley (joshkel@gmail.com) 31 | // 32 | // Google C++ Testing Framework (Google Test) 33 | // 34 | // Links gtest.lib and gtest_main.lib into the current project in C++Builder. 35 | // This means that these libraries can't be renamed, but it's the only way to 36 | // ensure that Debug versus Release test builds are linked against the 37 | // appropriate Debug or Release build of the libraries. 38 | 39 | #pragma link "gtest.lib" 40 | #pragma link "gtest_main.lib" 41 | -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/test/gtest_xml_outfile1_test_.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2008, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: keith.ray@gmail.com (Keith Ray) 31 | // 32 | // gtest_xml_outfile1_test_ writes some xml via TestProperty used by 33 | // gtest_xml_outfiles_test.py 34 | 35 | #include "gtest/gtest.h" 36 | 37 | class PropertyOne : public testing::Test { 38 | protected: 39 | virtual void SetUp() { 40 | RecordProperty("SetUpProp", 1); 41 | } 42 | virtual void TearDown() { 43 | RecordProperty("TearDownProp", 1); 44 | } 45 | }; 46 | 47 | TEST_F(PropertyOne, TestSomeProperties) { 48 | RecordProperty("TestSomeProperty", 1); 49 | } 50 | -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/test/gtest_xml_outfile2_test_.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2008, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: keith.ray@gmail.com (Keith Ray) 31 | // 32 | // gtest_xml_outfile2_test_ writes some xml via TestProperty used by 33 | // gtest_xml_outfiles_test.py 34 | 35 | #include "gtest/gtest.h" 36 | 37 | class PropertyTwo : public testing::Test { 38 | protected: 39 | virtual void SetUp() { 40 | RecordProperty("SetUpProp", 2); 41 | } 42 | virtual void TearDown() { 43 | RecordProperty("TearDownProp", 2); 44 | } 45 | }; 46 | 47 | TEST_F(PropertyTwo, TestSomeProperties) { 48 | RecordProperty("TestSomeProperty", 2); 49 | } 50 | -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/codegear/gtest.groupproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | {c1d923e0-6cba-4332-9b6f-3420acbf5091} 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | Default.Personality 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/test/gtest-typed-test2_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2008 Google Inc. 2 | // All Rights Reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: wan@google.com (Zhanyong Wan) 31 | 32 | #include 33 | 34 | #include "test/gtest-typed-test_test.h" 35 | #include "gtest/gtest.h" 36 | 37 | #if GTEST_HAS_TYPED_TEST_P 38 | 39 | // Tests that the same type-parameterized test case can be 40 | // instantiated in different translation units linked together. 41 | // (ContainerTest is also instantiated in gtest-typed-test_test.cc.) 42 | INSTANTIATE_TYPED_TEST_CASE_P(Vector, ContainerTest, 43 | testing::Types >); 44 | 45 | #endif // GTEST_HAS_TYPED_TEST_P 46 | -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/samples/sample4.h: -------------------------------------------------------------------------------- 1 | // Copyright 2005, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | // A sample program demonstrating using Google C++ testing framework. 31 | // 32 | // Author: wan@google.com (Zhanyong Wan) 33 | 34 | #ifndef GTEST_SAMPLES_SAMPLE4_H_ 35 | #define GTEST_SAMPLES_SAMPLE4_H_ 36 | 37 | // A simple monotonic counter. 38 | class Counter { 39 | private: 40 | int counter_; 41 | 42 | public: 43 | // Creates a counter that starts at 0. 44 | Counter() : counter_(0) {} 45 | 46 | // Returns the current counter value, and increments it. 47 | int Increment(); 48 | 49 | // Prints the current counter value to STDOUT. 50 | void Print() const; 51 | }; 52 | 53 | #endif // GTEST_SAMPLES_SAMPLE4_H_ 54 | -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/test/gtest_help_test_.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2009, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: wan@google.com (Zhanyong Wan) 31 | 32 | // This program is meant to be run by gtest_help_test.py. Do not run 33 | // it directly. 34 | 35 | #include "gtest/gtest.h" 36 | 37 | // When a help flag is specified, this program should skip the tests 38 | // and exit with 0; otherwise the following test will be executed, 39 | // causing this program to exit with a non-zero code. 40 | TEST(HelpFlagTest, ShouldNotBeRun) { 41 | ASSERT_TRUE(false) << "Tests shouldn't be run when --help is specified."; 42 | } 43 | 44 | #if GTEST_HAS_DEATH_TEST 45 | TEST(DeathTest, UsedByPythonScriptToDetectSupportForDeathTestsInThisBinary) {} 46 | #endif 47 | -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/src/gtest-all.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2008, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: mheule@google.com (Markus Heule) 31 | // 32 | // Google C++ Testing Framework (Google Test) 33 | // 34 | // Sometimes it's desirable to build Google Test by compiling a single file. 35 | // This file serves this purpose. 36 | 37 | // This line ensures that gtest.h can be compiled on its own, even 38 | // when it's fused. 39 | #include "gtest/gtest.h" 40 | 41 | // The following lines pull in the real gtest *.cc files. 42 | #include "src/gtest.cc" 43 | #include "src/gtest-death-test.cc" 44 | #include "src/gtest-filepath.cc" 45 | #include "src/gtest-port.cc" 46 | #include "src/gtest-printers.cc" 47 | #include "src/gtest-test-part.cc" 48 | #include "src/gtest-typed-test.cc" 49 | -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/test/production.h: -------------------------------------------------------------------------------- 1 | // Copyright 2006, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: wan@google.com (Zhanyong Wan) 31 | // 32 | // This is part of the unit test for include/gtest/gtest_prod.h. 33 | 34 | #ifndef GTEST_TEST_PRODUCTION_H_ 35 | #define GTEST_TEST_PRODUCTION_H_ 36 | 37 | #include "gtest/gtest_prod.h" 38 | 39 | class PrivateCode { 40 | public: 41 | // Declares a friend test that does not use a fixture. 42 | FRIEND_TEST(PrivateCodeTest, CanAccessPrivateMembers); 43 | 44 | // Declares a friend test that uses a fixture. 45 | FRIEND_TEST(PrivateCodeFixtureTest, CanAccessPrivateMembers); 46 | 47 | PrivateCode(); 48 | 49 | int x() const { return x_; } 50 | private: 51 | void set_x(int an_x) { x_ = an_x; } 52 | int x_; 53 | }; 54 | 55 | #endif // GTEST_TEST_PRODUCTION_H_ 56 | -------------------------------------------------------------------------------- /umls/html-docs/diagrams/078238f7718b97a7cea2ea60ee53dcd7.svg: -------------------------------------------------------------------------------- 1 | Singleton-mutex_: pthread_mutex_t-*instance: Singleton-Singleton()+GetInstance() -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/test/gtest_all_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2009, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: wan@google.com (Zhanyong Wan) 31 | // 32 | // Tests for Google C++ Testing Framework (Google Test) 33 | // 34 | // Sometimes it's desirable to build most of Google Test's own tests 35 | // by compiling a single file. This file serves this purpose. 36 | #include "test/gtest-filepath_test.cc" 37 | #include "test/gtest-linked_ptr_test.cc" 38 | #include "test/gtest-message_test.cc" 39 | #include "test/gtest-options_test.cc" 40 | #include "test/gtest-port_test.cc" 41 | #include "test/gtest_pred_impl_unittest.cc" 42 | #include "test/gtest_prod_test.cc" 43 | #include "test/gtest-test-part_test.cc" 44 | #include "test/gtest-typed-test_test.cc" 45 | #include "test/gtest-typed-test2_test.cc" 46 | #include "test/gtest_unittest.cc" 47 | #include "test/production.cc" 48 | -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/test/gtest_prod_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2006, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: wan@google.com (Zhanyong Wan) 31 | // 32 | // Unit test for include/gtest/gtest_prod.h. 33 | 34 | #include "gtest/gtest.h" 35 | #include "test/production.h" 36 | 37 | // Tests that private members can be accessed from a TEST declared as 38 | // a friend of the class. 39 | TEST(PrivateCodeTest, CanAccessPrivateMembers) { 40 | PrivateCode a; 41 | EXPECT_EQ(0, a.x_); 42 | 43 | a.set_x(1); 44 | EXPECT_EQ(1, a.x_); 45 | } 46 | 47 | typedef testing::Test PrivateCodeFixtureTest; 48 | 49 | // Tests that private members can be accessed from a TEST_F declared 50 | // as a friend of the class. 51 | TEST_F(PrivateCodeFixtureTest, CanAccessPrivateMembers) { 52 | PrivateCode a; 53 | EXPECT_EQ(0, a.x_); 54 | 55 | a.set_x(2); 56 | EXPECT_EQ(2, a.x_); 57 | } 58 | -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/test/gtest_sole_header_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2008, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: mheule@google.com (Markus Heule) 31 | // 32 | // This test verifies that it's possible to use Google Test by including 33 | // the gtest.h header file alone. 34 | 35 | #include "gtest/gtest.h" 36 | 37 | namespace { 38 | 39 | void Subroutine() { 40 | EXPECT_EQ(42, 42); 41 | } 42 | 43 | TEST(NoFatalFailureTest, ExpectNoFatalFailure) { 44 | EXPECT_NO_FATAL_FAILURE(;); 45 | EXPECT_NO_FATAL_FAILURE(SUCCEED()); 46 | EXPECT_NO_FATAL_FAILURE(Subroutine()); 47 | EXPECT_NO_FATAL_FAILURE({ SUCCEED(); }); 48 | } 49 | 50 | TEST(NoFatalFailureTest, AssertNoFatalFailure) { 51 | ASSERT_NO_FATAL_FAILURE(;); 52 | ASSERT_NO_FATAL_FAILURE(SUCCEED()); 53 | ASSERT_NO_FATAL_FAILURE(Subroutine()); 54 | ASSERT_NO_FATAL_FAILURE({ SUCCEED(); }); 55 | } 56 | 57 | } // namespace 58 | -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/samples/sample2.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2005, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | // A sample program demonstrating using Google C++ testing framework. 31 | // 32 | // Author: wan@google.com (Zhanyong Wan) 33 | 34 | #include "sample2.h" 35 | 36 | #include 37 | 38 | // Clones a 0-terminated C string, allocating memory using new. 39 | const char* MyString::CloneCString(const char* a_c_string) { 40 | if (a_c_string == NULL) return NULL; 41 | 42 | const size_t len = strlen(a_c_string); 43 | char* const clone = new char[ len + 1 ]; 44 | memcpy(clone, a_c_string, len + 1); 45 | 46 | return clone; 47 | } 48 | 49 | // Sets the 0-terminated C string this MyString object 50 | // represents. 51 | void MyString::Set(const char* a_c_string) { 52 | // Makes sure this works when c_string == c_string_ 53 | const char* const temp = MyString::CloneCString(a_c_string); 54 | delete[] c_string_; 55 | c_string_ = temp; 56 | } 57 | -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/xcode/Samples/FrameworkSample/widget.h: -------------------------------------------------------------------------------- 1 | // Copyright 2008, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: preston.a.jackson@gmail.com (Preston Jackson) 31 | // 32 | // Google Test - FrameworkSample 33 | // widget.h 34 | // 35 | 36 | // Widget is a very simple class used for demonstrating the use of gtest. It 37 | // simply stores two values a string and an integer, which are returned via 38 | // public accessors in multiple forms. 39 | 40 | #import 41 | 42 | class Widget { 43 | public: 44 | Widget(int number, const std::string& name); 45 | ~Widget(); 46 | 47 | // Public accessors to number data 48 | float GetFloatValue() const; 49 | int GetIntValue() const; 50 | 51 | // Public accessors to the string data 52 | std::string GetStringValue() const; 53 | void GetCharPtrValue(char* buffer, size_t max_size) const; 54 | 55 | private: 56 | // Data members 57 | float number_; 58 | std::string name_; 59 | }; 60 | -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/msvc/gtest.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 8.00 2 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gtest", "gtest.vcproj", "{C8F6C172-56F2-4E76-B5FA-C3B423B31BE7}" 3 | ProjectSection(ProjectDependencies) = postProject 4 | EndProjectSection 5 | EndProject 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gtest_main", "gtest_main.vcproj", "{3AF54C8A-10BF-4332-9147-F68ED9862032}" 7 | ProjectSection(ProjectDependencies) = postProject 8 | EndProjectSection 9 | EndProject 10 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gtest_unittest", "gtest_unittest.vcproj", "{4D9FDFB5-986A-4139-823C-F4EE0ED481A1}" 11 | ProjectSection(ProjectDependencies) = postProject 12 | EndProjectSection 13 | EndProject 14 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gtest_prod_test", "gtest_prod_test.vcproj", "{24848551-EF4F-47E8-9A9D-EA4D49BC3ECA}" 15 | ProjectSection(ProjectDependencies) = postProject 16 | EndProjectSection 17 | EndProject 18 | Global 19 | GlobalSection(SolutionConfiguration) = preSolution 20 | Debug = Debug 21 | Release = Release 22 | EndGlobalSection 23 | GlobalSection(ProjectConfiguration) = postSolution 24 | {C8F6C172-56F2-4E76-B5FA-C3B423B31BE7}.Debug.ActiveCfg = Debug|Win32 25 | {C8F6C172-56F2-4E76-B5FA-C3B423B31BE7}.Debug.Build.0 = Debug|Win32 26 | {C8F6C172-56F2-4E76-B5FA-C3B423B31BE7}.Release.ActiveCfg = Release|Win32 27 | {C8F6C172-56F2-4E76-B5FA-C3B423B31BE7}.Release.Build.0 = Release|Win32 28 | {3AF54C8A-10BF-4332-9147-F68ED9862032}.Debug.ActiveCfg = Debug|Win32 29 | {3AF54C8A-10BF-4332-9147-F68ED9862032}.Debug.Build.0 = Debug|Win32 30 | {3AF54C8A-10BF-4332-9147-F68ED9862032}.Release.ActiveCfg = Release|Win32 31 | {3AF54C8A-10BF-4332-9147-F68ED9862032}.Release.Build.0 = Release|Win32 32 | {4D9FDFB5-986A-4139-823C-F4EE0ED481A1}.Debug.ActiveCfg = Debug|Win32 33 | {4D9FDFB5-986A-4139-823C-F4EE0ED481A1}.Debug.Build.0 = Debug|Win32 34 | {4D9FDFB5-986A-4139-823C-F4EE0ED481A1}.Release.ActiveCfg = Release|Win32 35 | {4D9FDFB5-986A-4139-823C-F4EE0ED481A1}.Release.Build.0 = Release|Win32 36 | {24848551-EF4F-47E8-9A9D-EA4D49BC3ECA}.Debug.ActiveCfg = Debug|Win32 37 | {24848551-EF4F-47E8-9A9D-EA4D49BC3ECA}.Debug.Build.0 = Debug|Win32 38 | {24848551-EF4F-47E8-9A9D-EA4D49BC3ECA}.Release.ActiveCfg = Release|Win32 39 | {24848551-EF4F-47E8-9A9D-EA4D49BC3ECA}.Release.Build.0 = Release|Win32 40 | EndGlobalSection 41 | GlobalSection(ExtensibilityGlobals) = postSolution 42 | EndGlobalSection 43 | GlobalSection(ExtensibilityAddIns) = postSolution 44 | EndGlobalSection 45 | EndGlobal 46 | -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/include/gtest/gtest_prod.h: -------------------------------------------------------------------------------- 1 | // Copyright 2006, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: wan@google.com (Zhanyong Wan) 31 | // 32 | // Google C++ Testing Framework definitions useful in production code. 33 | 34 | #ifndef GTEST_INCLUDE_GTEST_GTEST_PROD_H_ 35 | #define GTEST_INCLUDE_GTEST_GTEST_PROD_H_ 36 | 37 | // When you need to test the private or protected members of a class, 38 | // use the FRIEND_TEST macro to declare your tests as friends of the 39 | // class. For example: 40 | // 41 | // class MyClass { 42 | // private: 43 | // void MyMethod(); 44 | // FRIEND_TEST(MyClassTest, MyMethod); 45 | // }; 46 | // 47 | // class MyClassTest : public testing::Test { 48 | // // ... 49 | // }; 50 | // 51 | // TEST_F(MyClassTest, MyMethod) { 52 | // // Can call MyClass::MyMethod() here. 53 | // } 54 | 55 | #define FRIEND_TEST(test_case_name, test_name)\ 56 | friend class test_case_name##_##test_name##_Test 57 | 58 | #endif // GTEST_INCLUDE_GTEST_GTEST_PROD_H_ 59 | -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/msvc/gtest-md.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 8.00 2 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gtest-md", "gtest-md.vcproj", "{C8F6C172-56F2-4E76-B5FA-C3B423B31BE8}" 3 | ProjectSection(ProjectDependencies) = postProject 4 | EndProjectSection 5 | EndProject 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gtest_main-md", "gtest_main-md.vcproj", "{3AF54C8A-10BF-4332-9147-F68ED9862033}" 7 | ProjectSection(ProjectDependencies) = postProject 8 | EndProjectSection 9 | EndProject 10 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gtest_prod_test-md", "gtest_prod_test-md.vcproj", "{24848551-EF4F-47E8-9A9D-EA4D49BC3ECB}" 11 | ProjectSection(ProjectDependencies) = postProject 12 | EndProjectSection 13 | EndProject 14 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gtest_unittest-md", "gtest_unittest-md.vcproj", "{4D9FDFB5-986A-4139-823C-F4EE0ED481A2}" 15 | ProjectSection(ProjectDependencies) = postProject 16 | EndProjectSection 17 | EndProject 18 | Global 19 | GlobalSection(SolutionConfiguration) = preSolution 20 | Debug = Debug 21 | Release = Release 22 | EndGlobalSection 23 | GlobalSection(ProjectConfiguration) = postSolution 24 | {C8F6C172-56F2-4E76-B5FA-C3B423B31BE8}.Debug.ActiveCfg = Debug|Win32 25 | {C8F6C172-56F2-4E76-B5FA-C3B423B31BE8}.Debug.Build.0 = Debug|Win32 26 | {C8F6C172-56F2-4E76-B5FA-C3B423B31BE8}.Release.ActiveCfg = Release|Win32 27 | {C8F6C172-56F2-4E76-B5FA-C3B423B31BE8}.Release.Build.0 = Release|Win32 28 | {3AF54C8A-10BF-4332-9147-F68ED9862033}.Debug.ActiveCfg = Debug|Win32 29 | {3AF54C8A-10BF-4332-9147-F68ED9862033}.Debug.Build.0 = Debug|Win32 30 | {3AF54C8A-10BF-4332-9147-F68ED9862033}.Release.ActiveCfg = Release|Win32 31 | {3AF54C8A-10BF-4332-9147-F68ED9862033}.Release.Build.0 = Release|Win32 32 | {24848551-EF4F-47E8-9A9D-EA4D49BC3ECB}.Debug.ActiveCfg = Debug|Win32 33 | {24848551-EF4F-47E8-9A9D-EA4D49BC3ECB}.Debug.Build.0 = Debug|Win32 34 | {24848551-EF4F-47E8-9A9D-EA4D49BC3ECB}.Release.ActiveCfg = Release|Win32 35 | {24848551-EF4F-47E8-9A9D-EA4D49BC3ECB}.Release.Build.0 = Release|Win32 36 | {4D9FDFB5-986A-4139-823C-F4EE0ED481A2}.Debug.ActiveCfg = Debug|Win32 37 | {4D9FDFB5-986A-4139-823C-F4EE0ED481A2}.Debug.Build.0 = Debug|Win32 38 | {4D9FDFB5-986A-4139-823C-F4EE0ED481A2}.Release.ActiveCfg = Release|Win32 39 | {4D9FDFB5-986A-4139-823C-F4EE0ED481A2}.Release.Build.0 = Release|Win32 40 | EndGlobalSection 41 | GlobalSection(ExtensibilityGlobals) = postSolution 42 | EndGlobalSection 43 | GlobalSection(ExtensibilityAddIns) = postSolution 44 | EndGlobalSection 45 | EndGlobal 46 | -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/test/gtest-param-test_test.h: -------------------------------------------------------------------------------- 1 | // Copyright 2008, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Authors: vladl@google.com (Vlad Losev) 31 | // 32 | // The Google C++ Testing Framework (Google Test) 33 | // 34 | // This header file provides classes and functions used internally 35 | // for testing Google Test itself. 36 | 37 | #ifndef GTEST_TEST_GTEST_PARAM_TEST_TEST_H_ 38 | #define GTEST_TEST_GTEST_PARAM_TEST_TEST_H_ 39 | 40 | #include "gtest/gtest.h" 41 | 42 | #if GTEST_HAS_PARAM_TEST 43 | 44 | // Test fixture for testing definition and instantiation of a test 45 | // in separate translation units. 46 | class ExternalInstantiationTest : public ::testing::TestWithParam { 47 | }; 48 | 49 | // Test fixture for testing instantiation of a test in multiple 50 | // translation units. 51 | class InstantiationInMultipleTranslaionUnitsTest 52 | : public ::testing::TestWithParam { 53 | }; 54 | 55 | #endif // GTEST_HAS_PARAM_TEST 56 | 57 | #endif // GTEST_TEST_GTEST_PARAM_TEST_TEST_H_ 58 | -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/xcode/Samples/FrameworkSample/widget.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2008, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: preston.a.jackson@gmail.com (Preston Jackson) 31 | // 32 | // Google Test - FrameworkSample 33 | // widget.cc 34 | // 35 | 36 | // Widget is a very simple class used for demonstrating the use of gtest 37 | 38 | #include "widget.h" 39 | 40 | Widget::Widget(int number, const std::string& name) 41 | : number_(number), 42 | name_(name) {} 43 | 44 | Widget::~Widget() {} 45 | 46 | float Widget::GetFloatValue() const { 47 | return number_; 48 | } 49 | 50 | int Widget::GetIntValue() const { 51 | return static_cast(number_); 52 | } 53 | 54 | std::string Widget::GetStringValue() const { 55 | return name_; 56 | } 57 | 58 | void Widget::GetCharPtrValue(char* buffer, size_t max_size) const { 59 | // Copy the char* representation of name_ into buffer, up to max_size. 60 | strncpy(buffer, name_.c_str(), max_size-1); 61 | buffer[max_size-1] = '\0'; 62 | return; 63 | } 64 | -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/xcode/Samples/FrameworkSample/runtests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright 2008, Google Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are 8 | # met: 9 | # 10 | # * Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # * Redistributions in binary form must reproduce the above 13 | # copyright notice, this list of conditions and the following disclaimer 14 | # in the documentation and/or other materials provided with the 15 | # distribution. 16 | # * Neither the name of Google Inc. nor the names of its 17 | # contributors may be used to endorse or promote products derived from 18 | # this software without specific prior written permission. 19 | # 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | # Executes the samples and tests for the Google Test Framework. 33 | 34 | # Help the dynamic linker find the path to the libraries. 35 | export DYLD_FRAMEWORK_PATH=$BUILT_PRODUCTS_DIR 36 | export DYLD_LIBRARY_PATH=$BUILT_PRODUCTS_DIR 37 | 38 | # Create some executables. 39 | test_executables=$@ 40 | 41 | # Now execute each one in turn keeping track of how many succeeded and failed. 42 | succeeded=0 43 | failed=0 44 | failed_list=() 45 | for test in ${test_executables[*]}; do 46 | "$test" 47 | result=$? 48 | if [ $result -eq 0 ]; then 49 | succeeded=$(( $succeeded + 1 )) 50 | else 51 | failed=$(( failed + 1 )) 52 | failed_list="$failed_list $test" 53 | fi 54 | done 55 | 56 | # Report the successes and failures to the console. 57 | echo "Tests complete with $succeeded successes and $failed failures." 58 | if [ $failed -ne 0 ]; then 59 | echo "The following tests failed:" 60 | echo $failed_list 61 | fi 62 | exit $failed 63 | -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/test/gtest_no_test_unittest.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2006, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | // Tests that a Google Test program that has no test defined can run 31 | // successfully. 32 | // 33 | // Author: wan@google.com (Zhanyong Wan) 34 | 35 | #include "gtest/gtest.h" 36 | 37 | int main(int argc, char **argv) { 38 | testing::InitGoogleTest(&argc, argv); 39 | 40 | // An ad-hoc assertion outside of all tests. 41 | // 42 | // This serves three purposes: 43 | // 44 | // 1. It verifies that an ad-hoc assertion can be executed even if 45 | // no test is defined. 46 | // 2. It verifies that a failed ad-hoc assertion causes the test 47 | // program to fail. 48 | // 3. We had a bug where the XML output won't be generated if an 49 | // assertion is executed before RUN_ALL_TESTS() is called, even 50 | // though --gtest_output=xml is specified. This makes sure the 51 | // bug is fixed and doesn't regress. 52 | EXPECT_EQ(1, 2); 53 | 54 | // The above EXPECT_EQ() should cause RUN_ALL_TESTS() to return non-zero. 55 | return RUN_ALL_TESTS() ? 0 : 1; 56 | } 57 | -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/test/gtest-typed-test_test.h: -------------------------------------------------------------------------------- 1 | // Copyright 2008 Google Inc. 2 | // All Rights Reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: wan@google.com (Zhanyong Wan) 31 | 32 | #ifndef GTEST_TEST_GTEST_TYPED_TEST_TEST_H_ 33 | #define GTEST_TEST_GTEST_TYPED_TEST_TEST_H_ 34 | 35 | #include "gtest/gtest.h" 36 | 37 | #if GTEST_HAS_TYPED_TEST_P 38 | 39 | using testing::Test; 40 | 41 | // For testing that the same type-parameterized test case can be 42 | // instantiated in different translation units linked together. 43 | // ContainerTest will be instantiated in both gtest-typed-test_test.cc 44 | // and gtest-typed-test2_test.cc. 45 | 46 | template 47 | class ContainerTest : public Test { 48 | }; 49 | 50 | TYPED_TEST_CASE_P(ContainerTest); 51 | 52 | TYPED_TEST_P(ContainerTest, CanBeDefaultConstructed) { 53 | TypeParam container; 54 | } 55 | 56 | TYPED_TEST_P(ContainerTest, InitialSizeIsZero) { 57 | TypeParam container; 58 | EXPECT_EQ(0U, container.size()); 59 | } 60 | 61 | REGISTER_TYPED_TEST_CASE_P(ContainerTest, 62 | CanBeDefaultConstructed, InitialSizeIsZero); 63 | 64 | #endif // GTEST_HAS_TYPED_TEST_P 65 | 66 | #endif // GTEST_TEST_GTEST_TYPED_TEST_TEST_H_ 67 | -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/samples/sample1.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2005, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | // A sample program demonstrating using Google C++ testing framework. 31 | // 32 | // Author: wan@google.com (Zhanyong Wan) 33 | 34 | #include "sample1.h" 35 | 36 | // Returns n! (the factorial of n). For negative n, n! is defined to be 1. 37 | int Factorial(int n) { 38 | int result = 1; 39 | for (int i = 1; i <= n; i++) { 40 | result *= i; 41 | } 42 | 43 | return result; 44 | } 45 | 46 | // Returns true iff n is a prime number. 47 | bool IsPrime(int n) { 48 | // Trivial case 1: small numbers 49 | if (n <= 1) return false; 50 | 51 | // Trivial case 2: even numbers 52 | if (n % 2 == 0) return n == 2; 53 | 54 | // Now, we have that n is odd and n >= 3. 55 | 56 | // Try to divide n by every odd number i, starting from 3 57 | for (int i = 3; ; i += 2) { 58 | // We only have to try i up to the squre root of n 59 | if (i > n/i) break; 60 | 61 | // Now, we have i <= n/i < n. 62 | // If n is divisible by i, n is not prime. 63 | if (n % i == 0) return false; 64 | } 65 | 66 | // n has no integer factor in the range (1, n), and thus is prime. 67 | return true; 68 | } 69 | -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/test/gtest_uninitialized_test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright 2008, Google Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are 8 | # met: 9 | # 10 | # * Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # * Redistributions in binary form must reproduce the above 13 | # copyright notice, this list of conditions and the following disclaimer 14 | # in the documentation and/or other materials provided with the 15 | # distribution. 16 | # * Neither the name of Google Inc. nor the names of its 17 | # contributors may be used to endorse or promote products derived from 18 | # this software without specific prior written permission. 19 | # 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | """Verifies that Google Test warns the user when not initialized properly.""" 33 | 34 | __author__ = 'wan@google.com (Zhanyong Wan)' 35 | 36 | import gtest_test_utils 37 | 38 | 39 | COMMAND = gtest_test_utils.GetTestExecutablePath('gtest_uninitialized_test_') 40 | 41 | 42 | def Assert(condition): 43 | if not condition: 44 | raise AssertionError 45 | 46 | 47 | def AssertEq(expected, actual): 48 | if expected != actual: 49 | print 'Expected: %s' % (expected,) 50 | print ' Actual: %s' % (actual,) 51 | raise AssertionError 52 | 53 | 54 | def TestExitCodeAndOutput(command): 55 | """Runs the given command and verifies its exit code and output.""" 56 | 57 | # Verifies that 'command' exits with code 1. 58 | p = gtest_test_utils.Subprocess(command) 59 | Assert(p.exited) 60 | AssertEq(1, p.exit_code) 61 | Assert('InitGoogleTest' in p.output) 62 | 63 | 64 | class GTestUninitializedTest(gtest_test_utils.TestCase): 65 | def testExitCodeAndOutput(self): 66 | TestExitCodeAndOutput(COMMAND) 67 | 68 | 69 | if __name__ == '__main__': 70 | gtest_test_utils.Main() 71 | -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/configure.ac: -------------------------------------------------------------------------------- 1 | m4_include(m4/acx_pthread.m4) 2 | 3 | # At this point, the Xcode project assumes the version string will be three 4 | # integers separated by periods and surrounded by square brackets (e.g. 5 | # "[1.0.1]"). It also asumes that there won't be any closing parenthesis 6 | # between "AC_INIT(" and the closing ")" including comments and strings. 7 | AC_INIT([Google C++ Testing Framework], 8 | [1.7.0], 9 | [googletestframework@googlegroups.com], 10 | [gtest]) 11 | 12 | # Provide various options to initialize the Autoconf and configure processes. 13 | AC_PREREQ([2.59]) 14 | AC_CONFIG_SRCDIR([./LICENSE]) 15 | AC_CONFIG_MACRO_DIR([m4]) 16 | AC_CONFIG_AUX_DIR([build-aux]) 17 | AC_CONFIG_HEADERS([build-aux/config.h]) 18 | AC_CONFIG_FILES([Makefile]) 19 | AC_CONFIG_FILES([scripts/gtest-config], [chmod +x scripts/gtest-config]) 20 | 21 | # Initialize Automake with various options. We require at least v1.9, prevent 22 | # pedantic complaints about package files, and enable various distribution 23 | # targets. 24 | AM_INIT_AUTOMAKE([1.9 dist-bzip2 dist-zip foreign subdir-objects]) 25 | 26 | # Check for programs used in building Google Test. 27 | AC_PROG_CC 28 | AC_PROG_CXX 29 | AC_LANG([C++]) 30 | AC_PROG_LIBTOOL 31 | 32 | # TODO(chandlerc@google.com): Currently we aren't running the Python tests 33 | # against the interpreter detected by AM_PATH_PYTHON, and so we condition 34 | # HAVE_PYTHON by requiring "python" to be in the PATH, and that interpreter's 35 | # version to be >= 2.3. This will allow the scripts to use a "/usr/bin/env" 36 | # hashbang. 37 | PYTHON= # We *do not* allow the user to specify a python interpreter 38 | AC_PATH_PROG([PYTHON],[python],[:]) 39 | AS_IF([test "$PYTHON" != ":"], 40 | [AM_PYTHON_CHECK_VERSION([$PYTHON],[2.3],[:],[PYTHON=":"])]) 41 | AM_CONDITIONAL([HAVE_PYTHON],[test "$PYTHON" != ":"]) 42 | 43 | # Configure pthreads. 44 | AC_ARG_WITH([pthreads], 45 | [AS_HELP_STRING([--with-pthreads], 46 | [use pthreads (default is yes)])], 47 | [with_pthreads=$withval], 48 | [with_pthreads=check]) 49 | 50 | have_pthreads=no 51 | AS_IF([test "x$with_pthreads" != "xno"], 52 | [ACX_PTHREAD( 53 | [], 54 | [AS_IF([test "x$with_pthreads" != "xcheck"], 55 | [AC_MSG_FAILURE( 56 | [--with-pthreads was specified, but unable to be used])])]) 57 | have_pthreads="$acx_pthread_ok"]) 58 | AM_CONDITIONAL([HAVE_PTHREADS],[test "x$have_pthreads" = "xyes"]) 59 | AC_SUBST(PTHREAD_CFLAGS) 60 | AC_SUBST(PTHREAD_LIBS) 61 | 62 | # TODO(chandlerc@google.com) Check for the necessary system headers. 63 | 64 | # TODO(chandlerc@google.com) Check the types, structures, and other compiler 65 | # and architecture characteristics. 66 | 67 | # Output the generated files. No further autoconf macros may be used. 68 | AC_OUTPUT 69 | -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/xcode/Scripts/runtests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright 2008, Google Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are 8 | # met: 9 | # 10 | # * Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # * Redistributions in binary form must reproduce the above 13 | # copyright notice, this list of conditions and the following disclaimer 14 | # in the documentation and/or other materials provided with the 15 | # distribution. 16 | # * Neither the name of Google Inc. nor the names of its 17 | # contributors may be used to endorse or promote products derived from 18 | # this software without specific prior written permission. 19 | # 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | # Executes the samples and tests for the Google Test Framework. 33 | 34 | # Help the dynamic linker find the path to the libraries. 35 | export DYLD_FRAMEWORK_PATH=$BUILT_PRODUCTS_DIR 36 | export DYLD_LIBRARY_PATH=$BUILT_PRODUCTS_DIR 37 | 38 | # Create some executables. 39 | test_executables=("$BUILT_PRODUCTS_DIR/gtest_unittest-framework" 40 | "$BUILT_PRODUCTS_DIR/gtest_unittest" 41 | "$BUILT_PRODUCTS_DIR/sample1_unittest-framework" 42 | "$BUILT_PRODUCTS_DIR/sample1_unittest-static") 43 | 44 | # Now execute each one in turn keeping track of how many succeeded and failed. 45 | succeeded=0 46 | failed=0 47 | failed_list=() 48 | for test in ${test_executables[*]}; do 49 | "$test" 50 | result=$? 51 | if [ $result -eq 0 ]; then 52 | succeeded=$(( $succeeded + 1 )) 53 | else 54 | failed=$(( failed + 1 )) 55 | failed_list="$failed_list $test" 56 | fi 57 | done 58 | 59 | # Report the successes and failures to the console. 60 | echo "Tests complete with $succeeded successes and $failed failures." 61 | if [ $failed -ne 0 ]; then 62 | echo "The following tests failed:" 63 | echo $failed_list 64 | fi 65 | exit $failed 66 | -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/xcode/Samples/FrameworkSample/widget_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2008, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: preston.a.jackson@gmail.com (Preston Jackson) 31 | // 32 | // Google Test - FrameworkSample 33 | // widget_test.cc 34 | // 35 | 36 | // This is a simple test file for the Widget class in the Widget.framework 37 | 38 | #include 39 | #include "gtest/gtest.h" 40 | 41 | #include 42 | 43 | // This test verifies that the constructor sets the internal state of the 44 | // Widget class correctly. 45 | TEST(WidgetInitializerTest, TestConstructor) { 46 | Widget widget(1.0f, "name"); 47 | EXPECT_FLOAT_EQ(1.0f, widget.GetFloatValue()); 48 | EXPECT_EQ(std::string("name"), widget.GetStringValue()); 49 | } 50 | 51 | // This test verifies the conversion of the float and string values to int and 52 | // char*, respectively. 53 | TEST(WidgetInitializerTest, TestConversion) { 54 | Widget widget(1.0f, "name"); 55 | EXPECT_EQ(1, widget.GetIntValue()); 56 | 57 | size_t max_size = 128; 58 | char buffer[max_size]; 59 | widget.GetCharPtrValue(buffer, max_size); 60 | EXPECT_STREQ("name", buffer); 61 | } 62 | 63 | // Use the Google Test main that is linked into the framework. It does something 64 | // like this: 65 | // int main(int argc, char** argv) { 66 | // testing::InitGoogleTest(&argc, argv); 67 | // return RUN_ALL_TESTS(); 68 | // } 69 | -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/make/Makefile: -------------------------------------------------------------------------------- 1 | # A sample Makefile for building Google Test and using it in user 2 | # tests. Please tweak it to suit your environment and project. You 3 | # may want to move it to your project's root directory. 4 | # 5 | # SYNOPSIS: 6 | # 7 | # make [all] - makes everything. 8 | # make TARGET - makes the given target. 9 | # make clean - removes all files generated by make. 10 | 11 | # Please tweak the following variable definitions as needed by your 12 | # project, except GTEST_HEADERS, which you can use in your own targets 13 | # but shouldn't modify. 14 | 15 | # Points to the root of Google Test, relative to where this file is. 16 | # Remember to tweak this if you move this file. 17 | GTEST_DIR = .. 18 | 19 | # Where to find user code. 20 | USER_DIR = ../samples 21 | 22 | # Flags passed to the preprocessor. 23 | # Set Google Test's header directory as a system directory, such that 24 | # the compiler doesn't generate warnings in Google Test headers. 25 | CPPFLAGS += -isystem $(GTEST_DIR)/include 26 | 27 | # Flags passed to the C++ compiler. 28 | CXXFLAGS += -g -Wall -Wextra -pthread 29 | 30 | # All tests produced by this Makefile. Remember to add new tests you 31 | # created to the list. 32 | TESTS = sample1_unittest 33 | 34 | # All Google Test headers. Usually you shouldn't change this 35 | # definition. 36 | GTEST_HEADERS = $(GTEST_DIR)/include/gtest/*.h \ 37 | $(GTEST_DIR)/include/gtest/internal/*.h 38 | 39 | # House-keeping build targets. 40 | 41 | all : $(TESTS) 42 | 43 | clean : 44 | rm -f $(TESTS) gtest.a gtest_main.a *.o 45 | 46 | # Builds gtest.a and gtest_main.a. 47 | 48 | # Usually you shouldn't tweak such internal variables, indicated by a 49 | # trailing _. 50 | GTEST_SRCS_ = $(GTEST_DIR)/src/*.cc $(GTEST_DIR)/src/*.h $(GTEST_HEADERS) 51 | 52 | # For simplicity and to avoid depending on Google Test's 53 | # implementation details, the dependencies specified below are 54 | # conservative and not optimized. This is fine as Google Test 55 | # compiles fast and for ordinary users its source rarely changes. 56 | gtest-all.o : $(GTEST_SRCS_) 57 | $(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c \ 58 | $(GTEST_DIR)/src/gtest-all.cc 59 | 60 | gtest_main.o : $(GTEST_SRCS_) 61 | $(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c \ 62 | $(GTEST_DIR)/src/gtest_main.cc 63 | 64 | gtest.a : gtest-all.o 65 | $(AR) $(ARFLAGS) $@ $^ 66 | 67 | gtest_main.a : gtest-all.o gtest_main.o 68 | $(AR) $(ARFLAGS) $@ $^ 69 | 70 | # Builds a sample test. A test should link with either gtest.a or 71 | # gtest_main.a, depending on whether it defines its own main() 72 | # function. 73 | 74 | sample1.o : $(USER_DIR)/sample1.cc $(USER_DIR)/sample1.h $(GTEST_HEADERS) 75 | $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/sample1.cc 76 | 77 | sample1_unittest.o : $(USER_DIR)/sample1_unittest.cc \ 78 | $(USER_DIR)/sample1.h $(GTEST_HEADERS) 79 | $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/sample1_unittest.cc 80 | 81 | sample1_unittest : sample1.o sample1_unittest.o gtest_main.a 82 | $(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@ 83 | -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/test/gtest-param-test2_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2008, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: vladl@google.com (Vlad Losev) 31 | // 32 | // Tests for Google Test itself. This verifies that the basic constructs of 33 | // Google Test work. 34 | 35 | #include "gtest/gtest.h" 36 | 37 | #include "test/gtest-param-test_test.h" 38 | 39 | #if GTEST_HAS_PARAM_TEST 40 | 41 | using ::testing::Values; 42 | using ::testing::internal::ParamGenerator; 43 | 44 | // Tests that generators defined in a different translation unit 45 | // are functional. The test using extern_gen is defined 46 | // in gtest-param-test_test.cc. 47 | ParamGenerator extern_gen = Values(33); 48 | 49 | // Tests that a parameterized test case can be defined in one translation unit 50 | // and instantiated in another. The test is defined in gtest-param-test_test.cc 51 | // and ExternalInstantiationTest fixture class is defined in 52 | // gtest-param-test_test.h. 53 | INSTANTIATE_TEST_CASE_P(MultiplesOf33, 54 | ExternalInstantiationTest, 55 | Values(33, 66)); 56 | 57 | // Tests that a parameterized test case can be instantiated 58 | // in multiple translation units. Another instantiation is defined 59 | // in gtest-param-test_test.cc and InstantiationInMultipleTranslaionUnitsTest 60 | // fixture is defined in gtest-param-test_test.h 61 | INSTANTIATE_TEST_CASE_P(Sequence2, 62 | InstantiationInMultipleTranslaionUnitsTest, 63 | Values(42*3, 42*4, 42*5)); 64 | 65 | #endif // GTEST_HAS_PARAM_TEST 66 | -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/test/gtest_color_test_.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2008, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: wan@google.com (Zhanyong Wan) 31 | 32 | // A helper program for testing how Google Test determines whether to use 33 | // colors in the output. It prints "YES" and returns 1 if Google Test 34 | // decides to use colors, and prints "NO" and returns 0 otherwise. 35 | 36 | #include 37 | 38 | #include "gtest/gtest.h" 39 | 40 | // Indicates that this translation unit is part of Google Test's 41 | // implementation. It must come before gtest-internal-inl.h is 42 | // included, or there will be a compiler error. This trick is to 43 | // prevent a user from accidentally including gtest-internal-inl.h in 44 | // his code. 45 | #define GTEST_IMPLEMENTATION_ 1 46 | #include "src/gtest-internal-inl.h" 47 | #undef GTEST_IMPLEMENTATION_ 48 | 49 | using testing::internal::ShouldUseColor; 50 | 51 | // The purpose of this is to ensure that the UnitTest singleton is 52 | // created before main() is entered, and thus that ShouldUseColor() 53 | // works the same way as in a real Google-Test-based test. We don't actual 54 | // run the TEST itself. 55 | TEST(GTestColorTest, Dummy) { 56 | } 57 | 58 | int main(int argc, char** argv) { 59 | testing::InitGoogleTest(&argc, argv); 60 | 61 | if (ShouldUseColor(true)) { 62 | // Google Test decides to use colors in the output (assuming it 63 | // goes to a TTY). 64 | printf("YES\n"); 65 | return 1; 66 | } else { 67 | // Google Test decides not to use colors in the output. 68 | printf("NO\n"); 69 | return 0; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/samples/sample2.h: -------------------------------------------------------------------------------- 1 | // Copyright 2005, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | // A sample program demonstrating using Google C++ testing framework. 31 | // 32 | // Author: wan@google.com (Zhanyong Wan) 33 | 34 | #ifndef GTEST_SAMPLES_SAMPLE2_H_ 35 | #define GTEST_SAMPLES_SAMPLE2_H_ 36 | 37 | #include 38 | 39 | 40 | // A simple string class. 41 | class MyString { 42 | private: 43 | const char* c_string_; 44 | const MyString& operator=(const MyString& rhs); 45 | 46 | public: 47 | // Clones a 0-terminated C string, allocating memory using new. 48 | static const char* CloneCString(const char* a_c_string); 49 | 50 | //////////////////////////////////////////////////////////// 51 | // 52 | // C'tors 53 | 54 | // The default c'tor constructs a NULL string. 55 | MyString() : c_string_(NULL) {} 56 | 57 | // Constructs a MyString by cloning a 0-terminated C string. 58 | explicit MyString(const char* a_c_string) : c_string_(NULL) { 59 | Set(a_c_string); 60 | } 61 | 62 | // Copy c'tor 63 | MyString(const MyString& string) : c_string_(NULL) { 64 | Set(string.c_string_); 65 | } 66 | 67 | //////////////////////////////////////////////////////////// 68 | // 69 | // D'tor. MyString is intended to be a final class, so the d'tor 70 | // doesn't need to be virtual. 71 | ~MyString() { delete[] c_string_; } 72 | 73 | // Gets the 0-terminated C string this MyString object represents. 74 | const char* c_string() const { return c_string_; } 75 | 76 | size_t Length() const { 77 | return c_string_ == NULL ? 0 : strlen(c_string_); 78 | } 79 | 80 | // Sets the 0-terminated C string this MyString object represents. 81 | void Set(const char* c_string); 82 | }; 83 | 84 | 85 | #endif // GTEST_SAMPLES_SAMPLE2_H_ 86 | -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/test/gtest_throw_on_failure_test_.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2009, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: wan@google.com (Zhanyong Wan) 31 | 32 | // Tests Google Test's throw-on-failure mode with exceptions disabled. 33 | // 34 | // This program must be compiled with exceptions disabled. It will be 35 | // invoked by gtest_throw_on_failure_test.py, and is expected to exit 36 | // with non-zero in the throw-on-failure mode or 0 otherwise. 37 | 38 | #include "gtest/gtest.h" 39 | 40 | #include // for fflush, fprintf, NULL, etc. 41 | #include // for exit 42 | #include // for set_terminate 43 | 44 | // This terminate handler aborts the program using exit() rather than abort(). 45 | // This avoids showing pop-ups on Windows systems and core dumps on Unix-like 46 | // ones. 47 | void TerminateHandler() { 48 | fprintf(stderr, "%s\n", "Unhandled C++ exception terminating the program."); 49 | fflush(NULL); 50 | exit(1); 51 | } 52 | 53 | int main(int argc, char** argv) { 54 | #if GTEST_HAS_EXCEPTIONS 55 | std::set_terminate(&TerminateHandler); 56 | #endif 57 | testing::InitGoogleTest(&argc, argv); 58 | 59 | // We want to ensure that people can use Google Test assertions in 60 | // other testing frameworks, as long as they initialize Google Test 61 | // properly and set the throw-on-failure mode. Therefore, we don't 62 | // use Google Test's constructs for defining and running tests 63 | // (e.g. TEST and RUN_ALL_TESTS) here. 64 | 65 | // In the throw-on-failure mode with exceptions disabled, this 66 | // assertion will cause the program to exit with a non-zero code. 67 | EXPECT_EQ(2, 3); 68 | 69 | // When not in the throw-on-failure mode, the control will reach 70 | // here. 71 | return 0; 72 | } 73 | -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/m4/gtest.m4: -------------------------------------------------------------------------------- 1 | dnl GTEST_LIB_CHECK([minimum version [, 2 | dnl action if found [,action if not found]]]) 3 | dnl 4 | dnl Check for the presence of the Google Test library, optionally at a minimum 5 | dnl version, and indicate a viable version with the HAVE_GTEST flag. It defines 6 | dnl standard variables for substitution including GTEST_CPPFLAGS, 7 | dnl GTEST_CXXFLAGS, GTEST_LDFLAGS, and GTEST_LIBS. It also defines 8 | dnl GTEST_VERSION as the version of Google Test found. Finally, it provides 9 | dnl optional custom action slots in the event GTEST is found or not. 10 | AC_DEFUN([GTEST_LIB_CHECK], 11 | [ 12 | dnl Provide a flag to enable or disable Google Test usage. 13 | AC_ARG_ENABLE([gtest], 14 | [AS_HELP_STRING([--enable-gtest], 15 | [Enable tests using the Google C++ Testing Framework. 16 | (Default is enabled.)])], 17 | [], 18 | [enable_gtest=]) 19 | AC_ARG_VAR([GTEST_CONFIG], 20 | [The exact path of Google Test's 'gtest-config' script.]) 21 | AC_ARG_VAR([GTEST_CPPFLAGS], 22 | [C-like preprocessor flags for Google Test.]) 23 | AC_ARG_VAR([GTEST_CXXFLAGS], 24 | [C++ compile flags for Google Test.]) 25 | AC_ARG_VAR([GTEST_LDFLAGS], 26 | [Linker path and option flags for Google Test.]) 27 | AC_ARG_VAR([GTEST_LIBS], 28 | [Library linking flags for Google Test.]) 29 | AC_ARG_VAR([GTEST_VERSION], 30 | [The version of Google Test available.]) 31 | HAVE_GTEST="no" 32 | AS_IF([test "x${enable_gtest}" != "xno"], 33 | [AC_MSG_CHECKING([for 'gtest-config']) 34 | AS_IF([test "x${enable_gtest}" != "xyes"], 35 | [AS_IF([test -x "${enable_gtest}/scripts/gtest-config"], 36 | [GTEST_CONFIG="${enable_gtest}/scripts/gtest-config"], 37 | [GTEST_CONFIG="${enable_gtest}/bin/gtest-config"]) 38 | AS_IF([test -x "${GTEST_CONFIG}"], [], 39 | [AC_MSG_RESULT([no]) 40 | AC_MSG_ERROR([dnl 41 | Unable to locate either a built or installed Google Test. 42 | The specific location '${enable_gtest}' was provided for a built or installed 43 | Google Test, but no 'gtest-config' script could be found at this location.]) 44 | ])], 45 | [AC_PATH_PROG([GTEST_CONFIG], [gtest-config])]) 46 | AS_IF([test -x "${GTEST_CONFIG}"], 47 | [AC_MSG_RESULT([${GTEST_CONFIG}]) 48 | m4_ifval([$1], 49 | [_gtest_min_version="--min-version=$1" 50 | AC_MSG_CHECKING([for Google Test at least version >= $1])], 51 | [_gtest_min_version="--min-version=0" 52 | AC_MSG_CHECKING([for Google Test])]) 53 | AS_IF([${GTEST_CONFIG} ${_gtest_min_version}], 54 | [AC_MSG_RESULT([yes]) 55 | HAVE_GTEST='yes'], 56 | [AC_MSG_RESULT([no])])], 57 | [AC_MSG_RESULT([no])]) 58 | AS_IF([test "x${HAVE_GTEST}" = "xyes"], 59 | [GTEST_CPPFLAGS=`${GTEST_CONFIG} --cppflags` 60 | GTEST_CXXFLAGS=`${GTEST_CONFIG} --cxxflags` 61 | GTEST_LDFLAGS=`${GTEST_CONFIG} --ldflags` 62 | GTEST_LIBS=`${GTEST_CONFIG} --libs` 63 | GTEST_VERSION=`${GTEST_CONFIG} --version` 64 | AC_DEFINE([HAVE_GTEST],[1],[Defined when Google Test is available.])], 65 | [AS_IF([test "x${enable_gtest}" = "xyes"], 66 | [AC_MSG_ERROR([dnl 67 | Google Test was enabled, but no viable version could be found.]) 68 | ])])]) 69 | AC_SUBST([HAVE_GTEST]) 70 | AM_CONDITIONAL([HAVE_GTEST],[test "x$HAVE_GTEST" = "xyes"]) 71 | AS_IF([test "x$HAVE_GTEST" = "xyes"], 72 | [m4_ifval([$2], [$2])], 73 | [m4_ifval([$3], [$3])]) 74 | ]) 75 | -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/test/gtest_break_on_failure_unittest_.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2006, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: wan@google.com (Zhanyong Wan) 31 | 32 | // Unit test for Google Test's break-on-failure mode. 33 | // 34 | // A user can ask Google Test to seg-fault when an assertion fails, using 35 | // either the GTEST_BREAK_ON_FAILURE environment variable or the 36 | // --gtest_break_on_failure flag. This file is used for testing such 37 | // functionality. 38 | // 39 | // This program will be invoked from a Python unit test. It is 40 | // expected to fail. Don't run it directly. 41 | 42 | #include "gtest/gtest.h" 43 | 44 | #if GTEST_OS_WINDOWS 45 | # include 46 | # include 47 | #endif 48 | 49 | namespace { 50 | 51 | // A test that's expected to fail. 52 | TEST(Foo, Bar) { 53 | EXPECT_EQ(2, 3); 54 | } 55 | 56 | #if GTEST_HAS_SEH && !GTEST_OS_WINDOWS_MOBILE 57 | // On Windows Mobile global exception handlers are not supported. 58 | LONG WINAPI ExitWithExceptionCode( 59 | struct _EXCEPTION_POINTERS* exception_pointers) { 60 | exit(exception_pointers->ExceptionRecord->ExceptionCode); 61 | } 62 | #endif 63 | 64 | } // namespace 65 | 66 | int main(int argc, char **argv) { 67 | #if GTEST_OS_WINDOWS 68 | // Suppresses display of the Windows error dialog upon encountering 69 | // a general protection fault (segment violation). 70 | SetErrorMode(SEM_NOGPFAULTERRORBOX | SEM_FAILCRITICALERRORS); 71 | 72 | # if GTEST_HAS_SEH && !GTEST_OS_WINDOWS_MOBILE 73 | 74 | // The default unhandled exception filter does not always exit 75 | // with the exception code as exit code - for example it exits with 76 | // 0 for EXCEPTION_ACCESS_VIOLATION and 1 for EXCEPTION_BREAKPOINT 77 | // if the application is compiled in debug mode. Thus we use our own 78 | // filter which always exits with the exception code for unhandled 79 | // exceptions. 80 | SetUnhandledExceptionFilter(ExitWithExceptionCode); 81 | 82 | # endif 83 | #endif 84 | 85 | testing::InitGoogleTest(&argc, argv); 86 | 87 | return RUN_ALL_TESTS(); 88 | } 89 | -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/test/gtest_throw_on_failure_ex_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2009, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: wan@google.com (Zhanyong Wan) 31 | 32 | // Tests Google Test's throw-on-failure mode with exceptions enabled. 33 | 34 | #include "gtest/gtest.h" 35 | 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | // Prints the given failure message and exits the program with 42 | // non-zero. We use this instead of a Google Test assertion to 43 | // indicate a failure, as the latter is been tested and cannot be 44 | // relied on. 45 | void Fail(const char* msg) { 46 | printf("FAILURE: %s\n", msg); 47 | fflush(stdout); 48 | exit(1); 49 | } 50 | 51 | // Tests that an assertion failure throws a subclass of 52 | // std::runtime_error. 53 | void TestFailureThrowsRuntimeError() { 54 | testing::GTEST_FLAG(throw_on_failure) = true; 55 | 56 | // A successful assertion shouldn't throw. 57 | try { 58 | EXPECT_EQ(3, 3); 59 | } catch(...) { 60 | Fail("A successful assertion wrongfully threw."); 61 | } 62 | 63 | // A failed assertion should throw a subclass of std::runtime_error. 64 | try { 65 | EXPECT_EQ(2, 3) << "Expected failure"; 66 | } catch(const std::runtime_error& e) { 67 | if (strstr(e.what(), "Expected failure") != NULL) 68 | return; 69 | 70 | printf("%s", 71 | "A failed assertion did throw an exception of the right type, " 72 | "but the message is incorrect. Instead of containing \"Expected " 73 | "failure\", it is:\n"); 74 | Fail(e.what()); 75 | } catch(...) { 76 | Fail("A failed assertion threw the wrong type of exception."); 77 | } 78 | Fail("A failed assertion should've thrown but didn't."); 79 | } 80 | 81 | int main(int argc, char** argv) { 82 | testing::InitGoogleTest(&argc, argv); 83 | 84 | // We want to ensure that people can use Google Test assertions in 85 | // other testing frameworks, as long as they initialize Google Test 86 | // properly and set the thrown-on-failure mode. Therefore, we don't 87 | // use Google Test's constructs for defining and running tests 88 | // (e.g. TEST and RUN_ALL_TESTS) here. 89 | 90 | TestFailureThrowsRuntimeError(); 91 | return 0; 92 | } 93 | -------------------------------------------------------------------------------- /tests/lib/gtest-1.7.0/test/gtest_shuffle_test_.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2009, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: wan@google.com (Zhanyong Wan) 31 | 32 | // Verifies that test shuffling works. 33 | 34 | #include "gtest/gtest.h" 35 | 36 | namespace { 37 | 38 | using ::testing::EmptyTestEventListener; 39 | using ::testing::InitGoogleTest; 40 | using ::testing::Message; 41 | using ::testing::Test; 42 | using ::testing::TestEventListeners; 43 | using ::testing::TestInfo; 44 | using ::testing::UnitTest; 45 | using ::testing::internal::scoped_ptr; 46 | 47 | // The test methods are empty, as the sole purpose of this program is 48 | // to print the test names before/after shuffling. 49 | 50 | class A : public Test {}; 51 | TEST_F(A, A) {} 52 | TEST_F(A, B) {} 53 | 54 | TEST(ADeathTest, A) {} 55 | TEST(ADeathTest, B) {} 56 | TEST(ADeathTest, C) {} 57 | 58 | TEST(B, A) {} 59 | TEST(B, B) {} 60 | TEST(B, C) {} 61 | TEST(B, DISABLED_D) {} 62 | TEST(B, DISABLED_E) {} 63 | 64 | TEST(BDeathTest, A) {} 65 | TEST(BDeathTest, B) {} 66 | 67 | TEST(C, A) {} 68 | TEST(C, B) {} 69 | TEST(C, C) {} 70 | TEST(C, DISABLED_D) {} 71 | 72 | TEST(CDeathTest, A) {} 73 | 74 | TEST(DISABLED_D, A) {} 75 | TEST(DISABLED_D, DISABLED_B) {} 76 | 77 | // This printer prints the full test names only, starting each test 78 | // iteration with a "----" marker. 79 | class TestNamePrinter : public EmptyTestEventListener { 80 | public: 81 | virtual void OnTestIterationStart(const UnitTest& /* unit_test */, 82 | int /* iteration */) { 83 | printf("----\n"); 84 | } 85 | 86 | virtual void OnTestStart(const TestInfo& test_info) { 87 | printf("%s.%s\n", test_info.test_case_name(), test_info.name()); 88 | } 89 | }; 90 | 91 | } // namespace 92 | 93 | int main(int argc, char **argv) { 94 | InitGoogleTest(&argc, argv); 95 | 96 | // Replaces the default printer with TestNamePrinter, which prints 97 | // the test name only. 98 | TestEventListeners& listeners = UnitTest::GetInstance()->listeners(); 99 | delete listeners.Release(listeners.default_result_printer()); 100 | listeners.Append(new TestNamePrinter); 101 | 102 | return RUN_ALL_TESTS(); 103 | } 104 | --------------------------------------------------------------------------------