├── .clang-format ├── CMakeLists.txt ├── Doxyfile ├── README.md ├── TUTORIAL.md ├── alb ├── affix_allocator.hpp ├── aligned_mallocator.hpp ├── allocator_base.hpp ├── allocator_with_stats.hpp ├── bucketizer.hpp ├── cascading_allocator.hpp ├── doxygroups.h ├── fallback_allocator.hpp ├── freelist.hpp ├── global_allocator.hpp ├── heap.hpp ├── internal │ ├── affix_helper.hpp │ ├── array_creation_evaluator.hpp │ ├── atomic_shared_ptr.h │ ├── block.hpp │ ├── dynastic.hpp │ ├── heap_helpers.hpp │ ├── noatomic.hpp │ ├── reallocator.hpp │ ├── shared_helpers.hpp │ ├── stack.hpp │ └── traits.hpp ├── mallocator.hpp ├── memory_corruption_detector.hpp ├── null_allocator.hpp ├── segregator.hpp ├── shared_heap.hpp ├── stack_allocator.hpp ├── stl_allocator.hpp └── stl_allocator_adapter.hpp ├── project.sublime-workspace ├── source ├── CMakeLists.txt ├── allocator_base.cpp └── array_creation_evaluator.cpp ├── test ├── AffixAllocatorTest.cpp ├── AllocatorBaseTest.cpp ├── AllocatorWithStatsTest.cpp ├── BucketizerTest.cpp ├── CMakeLists.txt ├── CascadingAllocatorsTest.cpp ├── FallbackAllocatorTest.cpp ├── FreeListTest.cpp ├── HeapTest.cpp ├── MallocatorTest.cpp ├── MemoryTest.cpp ├── NullAllocatorTest.cpp ├── SegregatorTest.cpp ├── StackAllocatorTest.cpp ├── TestHelpers │ ├── AffixGuard.h │ ├── Algorithm.h │ ├── AllocatorBaseTest.h │ ├── Base.cpp │ ├── Base.h │ ├── Data.h │ ├── Thread.h │ └── UsedMemGenerator.h ├── main.cpp └── util.hpp └── util └── gtest-1.7.0 ├── CHANGES ├── CMakeLists.txt ├── CONTRIBUTORS ├── LICENSE ├── Makefile.am ├── Makefile.in ├── README ├── aclocal.m4 ├── build-aux ├── config.guess ├── config.h.in ├── config.sub ├── depcomp ├── install-sh ├── ltmain.sh └── missing ├── cmake └── internal_utils.cmake ├── codegear ├── gtest.cbproj ├── gtest.groupproj ├── gtest_all.cc ├── gtest_link.cc ├── gtest_main.cbproj └── gtest_unittest.cbproj ├── configure ├── configure.ac ├── fused-src └── gtest │ ├── gtest-all.cc │ ├── gtest.h │ └── gtest_main.cc ├── include └── gtest │ ├── gtest-death-test.h │ ├── gtest-message.h │ ├── gtest-param-test.h │ ├── gtest-param-test.h.pump │ ├── gtest-printers.h │ ├── gtest-spi.h │ ├── gtest-test-part.h │ ├── gtest-typed-test.h │ ├── gtest.h │ ├── gtest_pred_impl.h │ ├── gtest_prod.h │ └── internal │ ├── gtest-death-test-internal.h │ ├── gtest-filepath.h │ ├── gtest-internal.h │ ├── gtest-linked_ptr.h │ ├── gtest-param-util-generated.h │ ├── gtest-param-util-generated.h.pump │ ├── gtest-param-util.h │ ├── gtest-port.h │ ├── gtest-string.h │ ├── gtest-tuple.h │ ├── gtest-tuple.h.pump │ ├── gtest-type-util.h │ └── gtest-type-util.h.pump ├── m4 ├── acx_pthread.m4 ├── gtest.m4 ├── libtool.m4 ├── ltoptions.m4 ├── ltsugar.m4 ├── ltversion.m4 └── lt~obsolete.m4 ├── make └── Makefile ├── msvc ├── gtest-md.sln ├── gtest-md.vcproj ├── gtest.sln ├── gtest.vcproj ├── gtest_main-md.vcproj ├── gtest_main.vcproj ├── gtest_prod_test-md.vcproj ├── gtest_prod_test.vcproj ├── gtest_unittest-md.vcproj └── gtest_unittest.vcproj ├── samples ├── prime_tables.h ├── sample1.cc ├── sample1.h ├── sample10_unittest.cc ├── sample1_unittest.cc ├── sample2.cc ├── sample2.h ├── sample2_unittest.cc ├── sample3-inl.h ├── sample3_unittest.cc ├── sample4.cc ├── sample4.h ├── sample4_unittest.cc ├── sample5_unittest.cc ├── sample6_unittest.cc ├── sample7_unittest.cc ├── sample8_unittest.cc └── sample9_unittest.cc ├── scripts ├── fuse_gtest_files.py ├── gen_gtest_pred_impl.py ├── gtest-config.in ├── pump.py └── test │ └── Makefile ├── src ├── gtest-all.cc ├── gtest-death-test.cc ├── gtest-filepath.cc ├── gtest-internal-inl.h ├── gtest-port.cc ├── gtest-printers.cc ├── gtest-test-part.cc ├── gtest-typed-test.cc ├── gtest.cc └── gtest_main.cc ├── test ├── gtest-death-test_ex_test.cc ├── gtest-death-test_test.cc ├── gtest-filepath_test.cc ├── gtest-linked_ptr_test.cc ├── gtest-listener_test.cc ├── gtest-message_test.cc ├── gtest-options_test.cc ├── gtest-param-test2_test.cc ├── gtest-param-test_test.cc ├── gtest-param-test_test.h ├── gtest-port_test.cc ├── gtest-printers_test.cc ├── gtest-test-part_test.cc ├── gtest-tuple_test.cc ├── gtest-typed-test2_test.cc ├── gtest-typed-test_test.cc ├── gtest-typed-test_test.h ├── gtest-unittest-api_test.cc ├── gtest_all_test.cc ├── gtest_break_on_failure_unittest.py ├── gtest_break_on_failure_unittest_.cc ├── gtest_catch_exceptions_test.py ├── gtest_catch_exceptions_test_.cc ├── gtest_color_test.py ├── gtest_color_test_.cc ├── gtest_env_var_test.py ├── gtest_env_var_test_.cc ├── gtest_environment_test.cc ├── gtest_filter_unittest.py ├── gtest_filter_unittest_.cc ├── gtest_help_test.py ├── gtest_help_test_.cc ├── gtest_list_tests_unittest.py ├── gtest_list_tests_unittest_.cc ├── gtest_main_unittest.cc ├── gtest_no_test_unittest.cc ├── gtest_output_test.py ├── gtest_output_test_.cc ├── gtest_output_test_golden_lin.txt ├── gtest_pred_impl_unittest.cc ├── gtest_premature_exit_test.cc ├── gtest_prod_test.cc ├── gtest_repeat_test.cc ├── gtest_shuffle_test.py ├── gtest_shuffle_test_.cc ├── gtest_sole_header_test.cc ├── gtest_stress_test.cc ├── gtest_test_utils.py ├── gtest_throw_on_failure_ex_test.cc ├── gtest_throw_on_failure_test.py ├── gtest_throw_on_failure_test_.cc ├── gtest_uninitialized_test.py ├── gtest_uninitialized_test_.cc ├── gtest_unittest.cc ├── gtest_xml_outfile1_test_.cc ├── gtest_xml_outfile2_test_.cc ├── gtest_xml_outfiles_test.py ├── gtest_xml_output_unittest.py ├── gtest_xml_output_unittest_.cc ├── gtest_xml_test_utils.py ├── production.cc └── production.h └── xcode ├── Config ├── DebugProject.xcconfig ├── FrameworkTarget.xcconfig ├── General.xcconfig ├── ReleaseProject.xcconfig ├── StaticLibraryTarget.xcconfig └── TestTarget.xcconfig ├── Resources └── Info.plist ├── Samples └── FrameworkSample │ ├── Info.plist │ ├── WidgetFramework.xcodeproj │ └── project.pbxproj │ ├── runtests.sh │ ├── widget.cc │ ├── widget.h │ └── widget_test.cc ├── Scripts ├── runtests.sh └── versiongenerate.py └── gtest.xcodeproj └── project.pbxproj /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | Language: Cpp 3 | # BasedOnStyle: LLVM 4 | AccessModifierOffset: -2 5 | AlignAfterOpenBracket: true 6 | AlignEscapedNewlinesLeft: false 7 | AlignOperands: true 8 | AlignTrailingComments: true 9 | AllowAllParametersOfDeclarationOnNextLine: true 10 | AllowShortBlocksOnASingleLine: false 11 | AllowShortCaseLabelsOnASingleLine: false 12 | AllowShortIfStatementsOnASingleLine: false 13 | AllowShortLoopsOnASingleLine: false 14 | AllowShortFunctionsOnASingleLine: None 15 | AlwaysBreakAfterDefinitionReturnType: false 16 | AlwaysBreakTemplateDeclarations: false 17 | AlwaysBreakBeforeMultilineStrings: false 18 | BreakBeforeBinaryOperators: None 19 | BreakBeforeTernaryOperators: true 20 | BreakConstructorInitializersBeforeComma: true 21 | BinPackParameters: true 22 | BinPackArguments: true 23 | ColumnLimit: 100 24 | ConstructorInitializerAllOnOneLineOrOnePerLine: false 25 | ConstructorInitializerIndentWidth: 2 26 | DerivePointerAlignment: false 27 | ExperimentalAutoDetectBinPacking: false 28 | IndentCaseLabels: false 29 | IndentWrappedFunctionNames: false 30 | IndentFunctionDeclarationAfterType: true 31 | MaxEmptyLinesToKeep: 1 32 | KeepEmptyLinesAtTheStartOfBlocks: true 33 | NamespaceIndentation: All 34 | ObjCBlockIndentWidth: 2 35 | ObjCSpaceAfterProperty: false 36 | ObjCSpaceBeforeProtocolList: true 37 | PenaltyBreakBeforeFirstCallParameter: 19 38 | PenaltyBreakComment: 300 39 | PenaltyBreakString: 1000 40 | PenaltyBreakFirstLessLess: 120 41 | PenaltyExcessCharacter: 1000000 42 | PenaltyReturnTypeOnItsOwnLine: 60 43 | PointerAlignment: Right 44 | SpacesBeforeTrailingComments: 1 45 | Cpp11BracedListStyle: true 46 | Standard: Cpp11 47 | IndentWidth: 2 48 | TabWidth: 2 49 | UseTab: Never 50 | BreakBeforeBraces: Stroustrup 51 | SpacesInParentheses: false 52 | SpacesInSquareBrackets: false 53 | SpacesInAngles: false 54 | SpaceInEmptyParentheses: false 55 | SpacesInCStyleCastParentheses: false 56 | SpaceAfterCStyleCast: false 57 | SpacesInContainerLiterals: true 58 | SpaceBeforeAssignmentOperators: true 59 | ContinuationIndentWidth: 4 60 | CommentPragmas: '^ IWYU pragma:' 61 | ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] 62 | SpaceBeforeParens: ControlStatements 63 | DisableFormat: false 64 | ... 65 | 66 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | 3 | project(AllocatorBuilder) 4 | 5 | if(WIN32) 6 | add_definitions(-D_WIN32_WINNT=0x0501) 7 | ENDIF(WIN32) 8 | 9 | # Visual Studio 2012 only supports up to 8 template parameters in 10 | # std::tr1::tuple by default, but gtest requires 10 11 | if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" AND MSVC_VERSION EQUAL 1700) 12 | add_definitions(-D_VARIADIC_MAX=10) 13 | endif () 14 | 15 | if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") 16 | #set(CMAKE_CXX_FLAGS "-O3 -fsanitize=thread -g -Wall -std=c++11") 17 | set(CMAKE_CXX_FLAGS "-O3 -g -Wall -std=c++14") 18 | set(CMAKE_LINK_FLAGS "-pthreads") 19 | endif() 20 | 21 | set(BOOST_ROOT D:/boost_1_59_0) 22 | set(Boost_USE_STATIC_LIBS OFF) 23 | set(Boost_USE_MULTITHREADED ON) 24 | set(Boost_USE_STATIC_RUNTIME OFF) 25 | #set(BOOST_ALL_DYN_LINK ON) 26 | find_package( Boost 1.55.0 REQUIRED COMPONENTS system thread chrono date_time) 27 | 28 | 29 | add_subdirectory(util/gtest-1.7.0) 30 | add_subdirectory(source) 31 | add_subdirectory(test) 32 | 33 | -------------------------------------------------------------------------------- /alb/doxygroups.h: -------------------------------------------------------------------------------- 1 | #ifndef _DOXYGROUPS_ 2 | #define _DOXYGROUPS_ 3 | 4 | /** 5 | \defgroup group_allocators Allocators 6 | \defgroup group_shared Shared\ Allocators 7 | \defgroup group_traits Traits 8 | \defgroup group_internal Internal 9 | \defgroup group_stats Statistic 10 | */ 11 | 12 | #endif -------------------------------------------------------------------------------- /alb/global_allocator.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright 2014 Felix Petriconi 4 | // 5 | // License: http://boost.org/LICENSE_1_0.txt, Boost License 1.0 6 | // 7 | // Authors: http://petriconi.net, Felix Petriconi 8 | // 9 | /////////////////////////////////////////////////////////////////// 10 | #pragma once 11 | 12 | namespace alb { 13 | struct length_prefix { 14 | unsigned length; 15 | }; 16 | 17 | template 18 | class global_allocator 19 | { 20 | public: 21 | using value_type = Allocator; 22 | 23 | static Allocator &instance() { 24 | static Allocator in; 25 | return in; 26 | } 27 | }; 28 | } 29 | -------------------------------------------------------------------------------- /alb/internal/affix_helper.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright 2014 Felix Petriconi 4 | // 5 | // License: http://boost.org/LICENSE_1_0.txt, Boost License 1.0 6 | // 7 | // Authors: http://petriconi.net, Felix Petriconi 8 | // 9 | /////////////////////////////////////////////////////////////////// 10 | #pragma once 11 | 12 | #include 13 | 14 | namespace alb { 15 | inline namespace v_100 { 16 | namespace affix_helper { 17 | 18 | template 19 | struct affix_creator; 20 | 21 | template 22 | struct affix_creator::value>::type> 23 | { 24 | template 25 | static constexpr void doIt(void *p, Allocator&) 26 | { 27 | new (p) Affix{}; 28 | } 29 | }; 30 | 31 | template 32 | struct affix_creator::value>::type> 33 | { 34 | template 35 | static constexpr void doIt(void *p, Allocator& a) 36 | { 37 | new (p) Affix(a); 38 | } 39 | }; 40 | 41 | template 42 | void create_affix_in_place(void *p, Allocator& a) 43 | { 44 | affix_creator::doIt(p, a); 45 | } 46 | 47 | 48 | /** 49 | * This special kind of no_affix is necessary to have the possibility to test 50 | * the 51 | * affix_allocator in a generic way. This must be used to disable a Prefix or 52 | * Sufix. 53 | */ 54 | struct no_affix { 55 | using value_type = int; 56 | static const int pattern = 0; 57 | }; 58 | 59 | /* simple optional store of a Sufix if the sufix_size > 0 */ 60 | template 61 | struct optinal_sufix_store 62 | { 63 | Sufix o_; 64 | void store(Sufix* o) noexcept { 65 | o_ = *o; 66 | } 67 | void unload(Sufix* o) noexcept { 68 | new (o) Sufix(o_); 69 | } 70 | }; 71 | 72 | template 73 | struct optinal_sufix_store 74 | { 75 | void store(Sufix*) {} 76 | void unload(Sufix*) {} 77 | }; 78 | 79 | } 80 | } 81 | using namespace v_100; 82 | 83 | } -------------------------------------------------------------------------------- /alb/internal/array_creation_evaluator.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright 2015 Felix Petriconi 4 | // 5 | // License: http://boost.org/LICENSE_1_0.txt, Boost License 1.0 6 | // 7 | // Authors: http://petriconi.net, Felix Petriconi 8 | // 9 | ////////////////////////////////////////////////////////////////// 10 | #pragma once 11 | #include 12 | 13 | namespace alb 14 | { 15 | inline namespace v_100 16 | { 17 | namespace helpers 18 | { 19 | size_t array_offset(); 20 | } 21 | } 22 | using namespace v_100; 23 | } 24 | -------------------------------------------------------------------------------- /alb/internal/atomic_shared_ptr.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright 2014 Felix Petriconi 4 | // 5 | // License: http://boost.org/LICENSE_1_0.txt, Boost License 1.0 6 | // 7 | // Authors: http://petriconi.net, Felix Petriconi 8 | // 9 | /////////////////////////////////////////////////////////////////// 10 | 11 | #pragma once 12 | #include 13 | #include 14 | 15 | namespace alb { 16 | namespace internal { 17 | 18 | template class atomic_shared_ptr { 19 | std::shared_ptr data_; 20 | 21 | public: 22 | constexpr atomic_shared_ptr() noexcept = default; 23 | 24 | explicit atomic_shared_ptr(std::shared_ptr p) noexcept 25 | { 26 | auto current = std::atomic_load(&data_); 27 | while (!std::atomic_compare_exchange_weak(&data_, ¤t, p)) 28 | ; 29 | } 30 | 31 | atomic_shared_ptr &operator=(std::shared_ptr p) noexcept 32 | { 33 | auto current = std::atomic_load(&data_); 34 | while (!std::atomic_compare_exchange_weak(&data_, ¤t, p)) 35 | ; 36 | return *this; 37 | } 38 | 39 | bool is_lock_free() const noexcept 40 | { 41 | return std::atomic_is_lock_free(); 42 | } 43 | 44 | void store(std::shared_ptr p, std::memory_order order = memory_order_seq_cst) noexcept 45 | { 46 | std::atomic_store_explicit(&data_, p, order); 47 | } 48 | 49 | std::shared_ptr load(std::memory_order order = std::memory_order_seq_cst) const noexcept 50 | { 51 | return std::atomic_load_explicit(&data_, order); 52 | } 53 | 54 | std::shared_ptr exchange(std::shared_ptr p, 55 | std::memory_order order = std::memory_order_seq_cst) noexcept 56 | { 57 | return std::atomic_exchange_explicit(&data_, p, order); 58 | } 59 | 60 | bool compare_exchange_strong(std::shared_ptr &old_value, std::shared_ptr new_value, 61 | std::memory_order order = std::memory_order_seq_cst) noexcept; 62 | 63 | bool compare_exchange_strong(std::shared_ptr &old_value, std::shared_ptr new_value, 64 | std::memory_order success_order, 65 | std::memory_order failure_order) noexcept; 66 | 67 | bool compare_exchange_weak(std::shared_ptr &old_value, std::shared_ptr new_value, 68 | std::memory_order order = std::memory_order_seq_cst) noexcept; 69 | 70 | bool compare_exchange_weak(std::shared_ptr &old_value, std::shared_ptr new_value, 71 | std::memory_order success_order, 72 | std::memory_order failure_order) noexcept; 73 | 74 | operator std::shared_ptr() const noexcept 75 | { 76 | return load(); 77 | } 78 | }; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /alb/internal/block.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BLOCK_HPP 2 | #define BLOCK_HPP 3 | 4 | #include 5 | 6 | namespace alb { 7 | inline namespace v_100 { 8 | 9 | struct block { 10 | block() noexcept 11 | : ptr(nullptr) 12 | , length(0) 13 | { 14 | } 15 | 16 | constexpr block(void *ptr, size_t length) noexcept 17 | : ptr(ptr) 18 | , length(length) 19 | { 20 | } 21 | 22 | block(block &&x) noexcept 23 | { 24 | *this = std::move(x); 25 | } 26 | 27 | block &operator=(block &&x) noexcept 28 | { 29 | ptr = x.ptr; 30 | length = x.length; 31 | x.reset(); 32 | return *this; 33 | } 34 | 35 | block &operator=(const block &x) noexcept = default; 36 | block(const block &x) noexcept = default; 37 | 38 | /** 39 | * During destruction of any of this instance, the described memory 40 | * is not freed! 41 | */ 42 | // ~block() 43 | // { 44 | // } 45 | 46 | /** 47 | * Clears the block 48 | */ 49 | void reset() noexcept 50 | { 51 | ptr = nullptr; 52 | length = 0; 53 | } 54 | 55 | /** 56 | * Bool operator to make the Allocator code better readable 57 | */ 58 | explicit operator bool() const 59 | { 60 | return length != 0; 61 | } 62 | 63 | bool operator==(const block &rhs) const 64 | { 65 | return ptr == rhs.ptr && length == rhs.length; 66 | } 67 | 68 | /// This points to the start address of the described memory block 69 | void *ptr; 70 | 71 | /// This describes the length of the reserved bytes. 72 | size_t length; 73 | }; 74 | 75 | } 76 | } 77 | #endif 78 | -------------------------------------------------------------------------------- /alb/internal/dynastic.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright 2014 Felix Petriconi 4 | // 5 | // License: http://boost.org/LICENSE_1_0.txt, Boost License 1.0 6 | // 7 | // Authors: http://petriconi.net, Felix Petriconi 8 | // 9 | /////////////////////////////////////////////////////////////////// 10 | #pragma once 11 | 12 | #include 13 | 14 | namespace alb { 15 | inline namespace v_100 { 16 | namespace internal { 17 | 18 | /** 19 | * Flag to be used inside the Dynastic struct to signal that the value 20 | * can be changed during runtime. 21 | * \ingroup group_internal 22 | */ 23 | enum DynasticOptions : size_t { 24 | DynasticUndefined = std::numeric_limits::max(), 25 | DynasticDynamicSet = std::numeric_limits::max() - 1 26 | }; 27 | 28 | /** 29 | * Simple generic value type that is either compile time constant or dynamically 30 | * set-able depending of DynamicEnableSwitch. If v and DynamicEnableSwitch, then 31 | * value can be changed during runtime. 32 | * @Author Andrei Alexandrescu 33 | * 34 | * \ingroup group_internal 35 | */ 36 | template struct dynastic { 37 | size_t value() const noexcept 38 | { 39 | return v; 40 | } 41 | }; 42 | 43 | template 44 | struct dynastic { 45 | private: 46 | size_t _v; 47 | 48 | public: 49 | dynastic() noexcept 50 | : _v(DynasticUndefined) 51 | { 52 | } 53 | 54 | size_t value() const noexcept 55 | { 56 | return _v; 57 | } 58 | 59 | void value(size_t w) noexcept 60 | { 61 | _v = w; 62 | } 63 | }; 64 | 65 | } // namespace internal 66 | } 67 | 68 | using namespace v_100; 69 | } // alb 70 | -------------------------------------------------------------------------------- /alb/internal/heap_helpers.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright 2014 Felix Petriconi 4 | // 5 | // License: http://boost.org/LICENSE_1_0.txt, Boost License 1.0 6 | // 7 | // Authors: http://petriconi.net, Felix Petriconi 8 | // 9 | /////////////////////////////////////////////////////////////////// 10 | #pragma once 11 | 12 | #include 13 | 14 | namespace alb { 15 | inline namespace v_100 { 16 | namespace helpers { 17 | 18 | template uint64_t set_used(uint64_t const ¤tRegister, uint64_t const &mask) noexcept; 19 | 20 | template <> 21 | inline uint64_t set_used(uint64_t const ¤tRegister, uint64_t const &mask) noexcept 22 | { 23 | return currentRegister & (mask ^ uint64_t(-1)); 24 | } 25 | template <> inline uint64_t set_used(uint64_t const ¤tRegister, uint64_t const &mask) noexcept 26 | { 27 | return currentRegister | mask; 28 | } 29 | } 30 | } 31 | using namespace v_100; 32 | } -------------------------------------------------------------------------------- /alb/internal/noatomic.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright 2014 Felix Petriconi 4 | // 5 | // License: http://boost.org/LICENSE_1_0.txt, Boost License 1.0 6 | // 7 | // Authors: http://petriconi.net, Felix Petriconi 8 | // 9 | /////////////////////////////////////////////////////////////////// 10 | #pragma once 11 | 12 | namespace alb { 13 | inline namespace v_100 { 14 | namespace internal { 15 | 16 | /** 17 | * Template that mimics (partly) the std::atomic interface, without 18 | * beeing an atomic. 19 | * It is usefull, if during compilation time the selection between single 20 | * threaded or multi threaded is needed 21 | * \tparam T The value that the class encapsulate 22 | * 23 | * \ingroup group_internal 24 | */ 25 | template 26 | class no_atomic 27 | { 28 | T value_; 29 | 30 | public: 31 | using type = T; 32 | 33 | no_atomic() noexcept 34 | {} 35 | 36 | explicit no_atomic(T v) noexcept 37 | : value_(std::move(v)) 38 | {} 39 | 40 | T load() const noexcept { 41 | return value_; 42 | } 43 | 44 | no_atomic &operator=(T v) noexcept { 45 | value_ = std::move(v); 46 | return *this; 47 | } 48 | 49 | bool compare_exchange_strong(T &, T v) noexcept 50 | { 51 | value_ = std::move(v); 52 | return true; 53 | } 54 | 55 | operator T() const { 56 | return value_; 57 | } 58 | 59 | T operator++() { return ++value_; } 60 | T operator++(int) { return value_++; } 61 | T operator--() { return --value_;} 62 | T operator--(int) { return value_--; } 63 | T operator+=(T arg) { return value_ += arg; } 64 | T operator-=(T arg) { return value_ -= arg; } 65 | }; 66 | } 67 | } 68 | using namespace v_100; 69 | } -------------------------------------------------------------------------------- /alb/internal/shared_helpers.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright 2014 Felix Petriconi 4 | // 5 | // License: http://boost.org/LICENSE_1_0.txt, Boost License 1.0 6 | // 7 | // Authors: http://petriconi.net, Felix Petriconi 8 | // 9 | /////////////////////////////////////////////////////////////////// 10 | #pragma once 11 | 12 | #include 13 | #include 14 | 15 | namespace alb { 16 | inline namespace v_100 { 17 | namespace shared_helpers { 18 | 19 | /** 20 | * Class that does not lock a given mutex 21 | * 22 | * \ingroup group_internal 23 | */ 24 | class NullLock { 25 | public: 26 | explicit NullLock(boost::shared_mutex &) noexcept 27 | { 28 | } 29 | }; 30 | 31 | /** 32 | * Class that locks with a shared lock then given mutex 33 | * 34 | * \ingroup group_internal 35 | */ 36 | class SharedLock { 37 | boost::shared_lock _lock; 38 | 39 | public: 40 | explicit SharedLock(boost::shared_mutex &m) noexcept 41 | : _lock(m) 42 | { 43 | } 44 | }; 45 | 46 | /** 47 | * Class that locks with a unique lock a given mutex 48 | * 49 | * \ingroup group_internal 50 | */ 51 | class UniqueLock { 52 | boost::unique_lock _lock; 53 | 54 | public: 55 | explicit UniqueLock(boost::shared_mutex &m) noexcept 56 | : _lock(m) 57 | { 58 | } 59 | }; 60 | 61 | struct null_mutex { 62 | }; 63 | 64 | struct null_lock { 65 | explicit null_lock(null_mutex &) noexcept 66 | { 67 | } 68 | }; 69 | 70 | template struct lock_guard; 71 | 72 | template <> struct lock_guard { 73 | lock_guard(null_mutex &) noexcept 74 | { 75 | } 76 | }; 77 | 78 | template <> struct lock_guard { 79 | std::unique_lock _lock; 80 | 81 | private: 82 | explicit lock_guard(std::mutex &m) noexcept 83 | : _lock(m) 84 | { 85 | } 86 | }; 87 | 88 | } // namespace helpers 89 | } 90 | using namespace v_100; 91 | } // namespace alb 92 | -------------------------------------------------------------------------------- /alb/internal/stack.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright 2014 Felix Petriconi 4 | // 5 | // License: http://boost.org/LICENSE_1_0.txt, Boost License 1.0 6 | // 7 | // Authors: http://petriconi.net, Felix Petriconi 8 | // 9 | /////////////////////////////////////////////////////////////////// 10 | #pragma once 11 | 12 | #include 13 | #include 14 | 15 | namespace alb { 16 | inline namespace v_100 { 17 | namespace internal { 18 | 19 | /** 20 | * Simple stack with the same interface as boost::lockfree::stack with a fixed 21 | * number of elements 22 | * It's intend is to be used as not shared variant in the FreeList 23 | * \tparam T The element type to be put into the stack 24 | * \tparam MaxSize The maximum number of elements that can be put into the stack 25 | * 26 | * \ingroup group_internal 27 | */ 28 | template 29 | class stack { 30 | static_assert(boost::has_trivial_assign::value, "T must be trivially copyable"); 31 | static_assert(boost::has_trivial_destructor::value, "T must be trivially destroyable"); 32 | 33 | T elements_[MaxSize]; 34 | int pos_; 35 | 36 | public: 37 | using value_type = T; 38 | static const size_t max_size = MaxSize; 39 | 40 | stack() noexcept 41 | : pos_(-1) 42 | {} 43 | 44 | bool push(T v) noexcept 45 | { 46 | if (pos_ < static_cast(MaxSize) - 1) { 47 | pos_++; 48 | elements_[pos_] = std::move(v); 49 | return true; 50 | } 51 | return false; 52 | } 53 | 54 | bool pop(T &v) noexcept 55 | { 56 | if (pos_ >= 0) { 57 | v = std::move(elements_[pos_]); 58 | pos_--; 59 | return true; 60 | } 61 | return false; 62 | } 63 | 64 | bool empty() const noexcept 65 | { 66 | return pos_ == -1; 67 | } 68 | }; 69 | } 70 | } 71 | 72 | using namespace v_100; 73 | } -------------------------------------------------------------------------------- /alb/mallocator.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright 2014 Felix Petriconi 4 | // 5 | // License: http://boost.org/LICENSE_1_0.txt, Boost License 1.0 6 | // 7 | // Authors: http://petriconi.net, Felix Petriconi 8 | // 9 | /////////////////////////////////////////////////////////////////// 10 | #pragma once 11 | 12 | #include "allocator_base.hpp" 13 | #include "internal/reallocator.hpp" 14 | 15 | namespace alb { 16 | inline namespace v_100 { 17 | /** 18 | * This class implements a facade against the system ::malloc() 19 | * 20 | * \ingroup group_allocators group_shared 21 | */ 22 | class mallocator { 23 | public: 24 | static constexpr bool supports_truncated_deallocation = false; 25 | static constexpr unsigned alignment = 4; 26 | 27 | /** 28 | * Allocates the specified number of bytes. 29 | * If the system cannot allocate the specified amount of memory then 30 | * a null Block is returned. 31 | * \param n The number of bytes. 32 | * \return Block with memory information 33 | */ 34 | block allocate(size_t n) noexcept { 35 | block result; 36 | 37 | if (n == 0) { 38 | return result; 39 | } 40 | auto p = ::malloc(n); 41 | if (p != nullptr) { 42 | result.ptr = p; 43 | result.length = n; 44 | return result; 45 | } 46 | return result; 47 | } 48 | 49 | /** 50 | * Reallocate the specified block to the specified size. 51 | * \param b The block to be reallocated 52 | * \param n The new size 53 | * \return True, if the operation was successful. 54 | */ 55 | bool reallocate(block &b, size_t n) noexcept { 56 | if (internal::is_reallocation_handled_default(*this, b, n)) { 57 | return true; 58 | } 59 | 60 | block reallocatedBlock(::realloc(b.ptr, n), n); 61 | 62 | if (reallocatedBlock) { 63 | b = reallocatedBlock; 64 | return true; 65 | } 66 | return false; 67 | } 68 | 69 | /** 70 | * Frees the given block and resets it. 71 | * \param b Block to be freed. 72 | */ 73 | void deallocate(block &b) noexcept 74 | { 75 | if (b) { 76 | ::free(b.ptr); 77 | b.reset(); 78 | } 79 | } 80 | }; 81 | } 82 | using namespace v_100; 83 | } 84 | -------------------------------------------------------------------------------- /alb/memory_corruption_detector.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright 2014 Felix Petriconi 4 | // 5 | // License: http://boost.org/LICENSE_1_0.txt, Boost License 1.0 6 | // 7 | // Authors: http://petriconi.net, Felix Petriconi 8 | // 9 | /////////////////////////////////////////////////////////////////// 10 | 11 | #pragma once 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | namespace alb { 18 | inline namespace v_100 { 19 | /** 20 | * This class can be used as Prefix and/or Suffix with the affix_allocator to 21 | * detect 22 | * buffer under-runs or overflows. 23 | * \tparam T must be an integral type. A guard with its size is used 24 | * \tparam Pattern this pattern is put into the memory as guard e.g. 0xdeadbeef 25 | * 26 | * \ingroup group_internal 27 | */ 28 | template 29 | class memory_corruption_detector 30 | { 31 | static_assert(sizeof(char) < sizeof(T) && sizeof(T) <= sizeof(uint64_t), 32 | "Memory check not for supported types"); 33 | 34 | T pattern_; 35 | 36 | public: 37 | using value_type = T; 38 | static const size_t pattern = Pattern; 39 | 40 | memory_corruption_detector() noexcept 41 | : pattern_(Pattern) 42 | {} 43 | 44 | ~memory_corruption_detector() 45 | { 46 | #ifndef NDEBUG 47 | if (pattern_ != Pattern) 48 | { 49 | std::cout << std::to_string(pattern_) << " is unequal to " << std::to_string(Pattern) << "!" << std::endl; 50 | throw 42; 51 | } 52 | #endif 53 | assert(pattern_ == Pattern); 54 | } 55 | }; 56 | 57 | template 58 | const size_t memory_corruption_detector::pattern; 59 | } 60 | using namespace v_100; 61 | } 62 | -------------------------------------------------------------------------------- /alb/null_allocator.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright 2015 Felix Petriconi 4 | // 5 | // License: http://boost.org/LICENSE_1_0.txt, Boost License 1.0 6 | // 7 | // Authors: http://petriconi.net, Felix Petriconi 8 | // 9 | ////////////////////////////////////////////////////////////////// 10 | 11 | #pragma once 12 | #include "allocator_base.hpp" 13 | 14 | #include 15 | 16 | namespace alb 17 | { 18 | inline namespace v_100 19 | { 20 | class null_allocator 21 | { 22 | public: 23 | static const unsigned alignment = 64 * 1024; 24 | 25 | block allocate(size_t) noexcept { 26 | return {nullptr, 0}; 27 | } 28 | 29 | bool owns(const block& b) noexcept { 30 | return !b; 31 | } 32 | 33 | bool expand(block& b, size_t) noexcept { 34 | assert(!b); 35 | return false; 36 | } 37 | 38 | bool reallocate(block& b, size_t) noexcept { 39 | assert(!b); 40 | return false; 41 | } 42 | 43 | void deallocate(block& b) noexcept { 44 | assert(!b); 45 | } 46 | 47 | void deallocateAll() noexcept { 48 | } 49 | }; 50 | } 51 | using namespace v_100; 52 | } 53 | -------------------------------------------------------------------------------- /alb/stl_allocator.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright 2014 Felix Petriconi 4 | // 5 | // License: http://boost.org/LICENSE_1_0.txt, Boost License 1.0 6 | // 7 | // Authors: http://petriconi.net, Felix Petriconi 8 | // 9 | /////////////////////////////////////////////////////////////////// 10 | #pragma once 11 | 12 | #include 13 | #include "allocator_base.hpp" 14 | 15 | namespace alb { 16 | 17 | template 18 | class stl_allocator; 19 | 20 | template 21 | class stl_allocator { 22 | public: 23 | using pointer = void *; 24 | using const_pointer = const void *; 25 | using value_type = void; 26 | template struct rebind { 27 | typedef stl_allocator other; 28 | }; 29 | }; 30 | 31 | template 32 | class stl_allocator { 33 | typename Allocator::value_type &allocator_; 34 | 35 | public: 36 | using size_type = size_t; 37 | using difference_type = ptrdiff_t; 38 | using pointer = T *; 39 | using const_pointer = const T *; 40 | using reference = T &; 41 | using const_reference = const T &; 42 | using value_type = T; 43 | 44 | template struct rebind { 45 | typedef stl_allocator other; 46 | }; 47 | 48 | stl_allocator() 49 | : allocator_(Allocator::instance()) 50 | { 51 | } 52 | stl_allocator(const stl_allocator &) 53 | : allocator_(Allocator::instance()) 54 | { 55 | } 56 | 57 | template 58 | explicit stl_allocator(const stl_allocator &) 59 | : allocator_(Allocator::instance()) 60 | { 61 | } 62 | 63 | ~stl_allocator() 64 | { 65 | } 66 | 67 | pointer address(reference r) const 68 | { 69 | return &r; 70 | }; 71 | const_pointer address(const_reference r) const 72 | { 73 | return &r; 74 | }; 75 | 76 | T *allocate(std::size_t n, const void * /*hint*/ = nullptr) 77 | { 78 | auto b = allocator_.allocate(n * sizeof(T)); 79 | if (b) { 80 | auto p = allocator_.outer_to_prefix(b); 81 | p->length = static_cast(b.length); 82 | return static_cast(b.ptr); 83 | } 84 | throw std::bad_alloc(); 85 | } 86 | 87 | void deallocate(T *ptr, std::size_t n) 88 | { 89 | block pseudoBlock(ptr, n); 90 | auto p = allocator_.outer_to_prefix(pseudoBlock); 91 | block realBlock(ptr, p->length); 92 | allocator_.deallocate(realBlock); 93 | } 94 | 95 | size_t max_size() const 96 | { // estimate maximum array size 97 | return ((size_t)(-1) / sizeof(T)); 98 | } 99 | 100 | void construct(pointer ptr) 101 | { 102 | ::new (static_cast(ptr)) T; 103 | }; 104 | 105 | template void construct(pointer ptr, const U &val) 106 | { 107 | ::new (static_cast(ptr)) T(val); 108 | }; 109 | 110 | void construct(pointer ptr, const T &val) 111 | { 112 | ::new (static_cast(ptr)) T(val); 113 | }; 114 | 115 | void destroy(pointer p) 116 | { 117 | p->T::~T(); 118 | }; 119 | }; 120 | 121 | template 122 | bool operator==(const stl_allocator &, const stl_allocator &) 123 | { 124 | return true; 125 | } 126 | 127 | template 128 | bool operator!=(const stl_allocator &, const stl_allocator &) 129 | { 130 | return false; 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /alb/stl_allocator_adapter.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright 2014 Felix Petriconi 4 | // 5 | // License: http://boost.org/LICENSE_1_0.txt, Boost License 1.0 6 | // 7 | // Authors: http://petriconi.net, Felix Petriconi 8 | // 9 | /////////////////////////////////////////////////////////////////// 10 | #pragma once 11 | 12 | #include 13 | #include 14 | #include "allocator_base.hpp" 15 | 16 | namespace alb { 17 | 18 | inline namespace v_100 { 19 | 20 | template 21 | class std_allocator_adapter; 22 | 23 | template 24 | class std_allocator_adapter { 25 | public: 26 | using pointer = void *; 27 | using const_pointer = const void *; 28 | using value_type = void; 29 | template struct rebind { 30 | typedef std_allocator_adapter other; 31 | }; 32 | }; 33 | 34 | template 35 | class std_allocator_adapter { 36 | const Allocator& allocator_; 37 | 38 | public: 39 | using size_type = size_t; 40 | using difference_type = ptrdiff_t; 41 | using pointer = T *; 42 | using const_pointer = const T *; 43 | using reference = T &; 44 | using const_reference = const T &; 45 | using value_type = T; 46 | 47 | template struct rebind { 48 | typedef std_allocator_adapter other; 49 | }; 50 | 51 | explicit std_allocator_adapter(const Allocator& allocator) noexcept 52 | : allocator_(allocator) 53 | { 54 | } 55 | 56 | ~std_allocator_adapter() noexcept {} 57 | 58 | const Allocator& allocator() const 59 | { 60 | return allocator_; 61 | } 62 | 63 | template 64 | explicit std_allocator_adapter(const std_allocator_adapter &other) 65 | : allocator_(other.allocator()) 66 | { 67 | } 68 | 69 | pointer address(reference r) const 70 | { 71 | return &r; 72 | }; 73 | 74 | const_pointer address(const_reference r) const 75 | { 76 | return &r; 77 | }; 78 | 79 | T *allocate(std::size_t n, const void * /*hint*/ = nullptr) 80 | { 81 | auto b = const_cast(allocator_).allocate(n * sizeof(T)); 82 | if (b) { 83 | auto p = allocator_.outer_to_prefix(b); 84 | *p = b.length; 85 | return static_cast(b.ptr); 86 | } 87 | return nullptr; 88 | } 89 | 90 | void deallocate(T *ptr, std::size_t n) 91 | { 92 | block pseudoBlock(ptr, n); 93 | auto p = allocator_.outer_to_prefix(pseudoBlock); 94 | block realBlock(ptr, *p); 95 | const_cast(allocator_).deallocate(realBlock); 96 | } 97 | 98 | size_t max_size() const 99 | { // estimate maximum array size 100 | return ((size_t)(-1) / sizeof(T)); 101 | } 102 | 103 | void construct(pointer ptr) 104 | { 105 | ::new (static_cast(ptr)) T; 106 | }; 107 | 108 | template 109 | void construct(pointer ptr, U&&... val) 110 | { 111 | ::new (static_cast(ptr)) T(std::forward(val)...); 112 | }; 113 | 114 | void destroy(pointer p) 115 | { 116 | p->T::~T(); 117 | }; 118 | }; 119 | 120 | template 121 | bool operator==(const std_allocator_adapter &, const std_allocator_adapter &) 122 | { 123 | return true; 124 | } 125 | 126 | template 127 | bool operator!=(const std_allocator_adapter &x, const std_allocator_adapter &y) 128 | { 129 | return !(x == y); 130 | } 131 | } 132 | 133 | using namespace v_100; 134 | } 135 | -------------------------------------------------------------------------------- /source/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(ALB) 2 | 3 | include_directories("${PROJECT_SOURCE_DIR}/../alb;${PROJECT_SOURCE_DIR}/../alb/internal") 4 | 5 | if(WIN32) 6 | add_definitions(-D_WIN32_WINNT=0x0501) 7 | endif(WIN32) 8 | 9 | set(SOURCE 10 | allocator_base.cpp 11 | array_creation_evaluator.cpp 12 | ) 13 | 14 | set(HEADERS 15 | ../alb/affix_allocator.hpp 16 | ../alb/aligned_mallocator.hpp 17 | ../alb/allocator_base.hpp 18 | ../alb/allocator_with_stats.hpp 19 | ../alb/bucketizer.hpp 20 | ../alb/cascading_allocator.hpp 21 | ../alb/fallback_allocator.hpp 22 | ../alb/global_allocator.hpp 23 | ../alb/heap.hpp 24 | ../alb/mallocator.hpp 25 | ../alb/memory_corruption_detector.hpp 26 | ../alb/null_allocator.hpp 27 | ../alb/segregator.hpp 28 | ../alb/freelist.hpp 29 | ../alb/shared_heap.hpp 30 | ../alb/stack_allocator.hpp 31 | ../alb/stl_allocator.hpp 32 | ../alb/stl_allocator_adapter.hpp 33 | ../alb/internal/affix_helper.hpp 34 | ../alb/internal/array_creation_evaluator.hpp 35 | ../alb/internal/dynastic.hpp 36 | ../alb/internal/heap_helpers.hpp 37 | ../alb/internal/noatomic.hpp 38 | ../alb/internal/reallocator.hpp 39 | ../alb/internal/shared_helpers.hpp 40 | ../alb/internal/stack.hpp 41 | ../alb/internal/traits.hpp 42 | ) 43 | 44 | include_directories(${Boost_INCLUDE_DIRS}) 45 | 46 | add_library(ALB ${SOURCE} ${HEADERS}) 47 | set_property(TARGET ALB PROPERTY CXX_STANDARD 14) 48 | set_property(TARGET ALB PROPERTY CXX_STANDARD_REQUIRED ON) 49 | 50 | -------------------------------------------------------------------------------- /source/allocator_base.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright 2014 Felix Petriconi 4 | // 5 | // License: http://boost.org/LICENSE_1_0.txt, Boost License 1.0 6 | // 7 | // Authors: http://petriconi.net, Felix Petriconi 8 | // 9 | /////////////////////////////////////////////////////////////////// 10 | #include "allocator_base.hpp" 11 | 12 | #include 13 | #include 14 | 15 | void alb::v_100::internal::block_copy(const alb::block& source, alb::block& destination) noexcept 16 | { 17 | ::memcpy(destination.ptr, source.ptr, std::min(source.length, destination.length)); 18 | } -------------------------------------------------------------------------------- /source/array_creation_evaluator.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright 2014 Felix Petriconi 4 | // 5 | // License: http://boost.org/LICENSE_1_0.txt, Boost License 1.0 6 | // 7 | // Authors: http://petriconi.net, Felix Petriconi 8 | // 9 | /////////////////////////////////////////////////////////////////// 10 | 11 | #include "array_creation_evaluator.hpp" 12 | #include 13 | #include 14 | 15 | namespace 16 | { 17 | struct Test 18 | { 19 | Test() : v(0) 20 | { 21 | s[0] = '\0'; 22 | } 23 | 24 | ~Test() 25 | { 26 | s[0] = '\0'; 27 | } 28 | 29 | int v; 30 | char s[2]; 31 | }; 32 | 33 | size_t array_offset_internal() 34 | { 35 | alignas(Test) char buffer[sizeof(Test) * 6]; 36 | Test* p = new (buffer) Test[5]; 37 | 38 | return reinterpret_cast(p) - buffer; 39 | } 40 | } 41 | 42 | 43 | size_t alb::v_100::helpers::array_offset() 44 | { 45 | static size_t result = array_offset_internal(); 46 | return result; 47 | } -------------------------------------------------------------------------------- /test/AllocatorBaseTest.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright 2014 Felix Petriconi 4 | // 5 | // License: http://boost.org/LICENSE_1_0.txt, Boost License 1.0 6 | // 7 | // Authors: http://petriconi.net, Felix Petriconi 8 | // 9 | /////////////////////////////////////////////////////////////////// 10 | #include 11 | 12 | #include 13 | 14 | TEST(roundToAlignmentTest, ThatForDifferentAlignmentsTheCorrectValuesAreCalculated) 15 | { 16 | EXPECT_EQ(0u, alb::internal::round_to_alignment(4, 0)); 17 | EXPECT_EQ(4u, alb::internal::round_to_alignment(4, 1)); 18 | EXPECT_EQ(4u, alb::internal::round_to_alignment(4, 4)); 19 | EXPECT_EQ(8u, alb::internal::round_to_alignment(4, 5)); 20 | 21 | EXPECT_EQ(0u, alb::internal::round_to_alignment(8, 0)); 22 | EXPECT_EQ(8u, alb::internal::round_to_alignment(8, 1)); 23 | EXPECT_EQ(8u, alb::internal::round_to_alignment(8, 8)); 24 | EXPECT_EQ(16u, alb::internal::round_to_alignment(8, 9)); 25 | } 26 | -------------------------------------------------------------------------------- /test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(ALBUnitTest) 2 | 3 | if(WIN32) 4 | add_definitions(-D_WIN32_WINNT=0x0501) 5 | ENDIF(WIN32) 6 | 7 | # Visual Studio 2012 only supports up to 8 template parameters in 8 | # std::tr1::tuple by default, but gtest requires 10 9 | if(MSVC AND MSVC_VERSION EQUAL 1700) 10 | add_definitions(-D_VARIADIC_MAX=10) 11 | endif () 12 | 13 | 14 | include_directories("${PROJECT_SOURCE_DIR}/../.") 15 | include_directories("${PROJECT_SOURCE_DIR}/../util/gtest-1.7.0/include") 16 | 17 | set(HEADERS 18 | TestHelpers/Base.h 19 | TestHelpers/AffixGuard.h 20 | TestHelpers/Algorithm.h 21 | TestHelpers/AllocatorBaseTest.h 22 | TestHelpers/Data.h 23 | TestHelpers/Thread.h 24 | TestHelpers/UsedMemGenerator.h 25 | ) 26 | 27 | set(SOURCE 28 | AffixAllocatorTest.cpp 29 | AllocatorBaseTest.cpp 30 | AllocatorWithStatsTest.cpp 31 | BucketizerTest.cpp 32 | CascadingAllocatorsTest.cpp 33 | FallbackAllocatorTest.cpp 34 | HeapTest 35 | MallocatorTest.cpp 36 | MemoryTest.cpp 37 | NullAllocatorTest.cpp 38 | SegregatorTest.cpp 39 | FreeListTest.cpp 40 | StackAllocatorTest.cpp 41 | main.cpp 42 | TestHelpers/Base.cpp 43 | ) 44 | 45 | add_executable(ALBUnitTest ${SOURCE} ${HEADERS}) 46 | 47 | include_directories(${Boost_INCLUDE_DIRS}) 48 | LINK_DIRECTORIES(${Boost_LIBRARY_DIRS}) 49 | add_definitions(-DBOOST_ALL_NO_LIB) 50 | 51 | add_dependencies(ALBUnitTest gtest) 52 | add_dependencies(ALBUnitTest ALB) 53 | 54 | set_property(TARGET ALBUnitTest PROPERTY CXX_STANDARD 14) 55 | set_property(TARGET ALBUnitTest PROPERTY CXX_STANDARD_REQUIRED ON) 56 | target_link_libraries(ALBUnitTest ${Boost_LIBRARIES} gtest ALB) 57 | 58 | 59 | -------------------------------------------------------------------------------- /test/CascadingAllocatorsTest.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright 2014 Felix Petriconi 4 | // 5 | // License: http://boost.org/LICENSE_1_0.txt, Boost License 1.0 6 | // 7 | // Authors: http://petriconi.net, Felix Petriconi 8 | // 9 | /////////////////////////////////////////////////////////////////// 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include "TestHelpers/Thread.h" 15 | #include "TestHelpers/Base.h" 16 | 17 | #include 18 | #include 19 | 20 | class TCascadingAllocatorsTest : public ::testing::Test { 21 | }; 22 | 23 | TEST_F(TCascadingAllocatorsTest, SingleAllocation) 24 | { 25 | alb::shared_cascading_allocator> sut; 26 | 27 | auto m1 = sut.allocate(64 * 8); 28 | auto m2 = sut.allocate(64 * 8); 29 | 30 | sut.deallocate(m2); 31 | sut.deallocate(m1); 32 | } 33 | 34 | TEST_F(TCascadingAllocatorsTest, BruteForceAllocationByOneRunningThread) 35 | { 36 | typedef alb::shared_cascading_allocator> 37 | AllocatorUnderTest; 38 | AllocatorUnderTest sut; 39 | 40 | alb::test_helpers::TestWorker testWorker(sut, 129); 41 | testWorker.check(); 42 | } 43 | 44 | TEST_F(TCascadingAllocatorsTest, BruteForceSingleAllocationWithinTwoRunningThreads) 45 | { 46 | typedef alb::shared_cascading_allocator> 47 | AllocatorUnderTest; 48 | AllocatorUnderTest sut; 49 | const size_t NumberOfThreads = 4; 50 | 51 | typedef std::array TestParams; 52 | TestParams maxUsedBytes = {{127, 129, 65, 130}}; 53 | 54 | alb::test_helpers::TestWorkerCollector, 56 | TestParams> singleMemoryAccessTest(sut, maxUsedBytes); 57 | 58 | singleMemoryAccessTest.check(); 59 | } 60 | 61 | TEST_F(TCascadingAllocatorsTest, BruteForceWithSeveralAllocatedBlocksWithinTwoRunningThreads) 62 | { 63 | typedef alb::shared_cascading_allocator> 64 | AllocatorUnderTest; 65 | AllocatorUnderTest sut; 66 | const size_t NumberOfThreads = 4; 67 | 68 | typedef std::array TestParams; 69 | TestParams maxUsedBytes = {{127, 129, 65, 130}}; 70 | 71 | alb::test_helpers::TestWorkerCollector, 73 | TestParams> multipleMemoryAccessTest(sut, maxUsedBytes); 74 | 75 | multipleMemoryAccessTest.check(); 76 | } 77 | -------------------------------------------------------------------------------- /test/MallocatorTest.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright 2014 Felix Petriconi 4 | // 5 | // License: http://boost.org/LICENSE_1_0.txt, Boost License 1.0 6 | // 7 | // Authors: http://petriconi.net, Felix Petriconi 8 | // 9 | ////////////////////////////////////////////////////////////////// 10 | #include 11 | #include 12 | #include "TestHelpers/Base.h" 13 | #include "TestHelpers/AllocatorBaseTest.h" 14 | 15 | using namespace alb::test_helpers; 16 | 17 | class MallocatorTest : public AllocatorBaseTest { 18 | protected: 19 | void TearDown() 20 | { 21 | deallocateAndCheckBlockIsThenEmpty(mem); 22 | } 23 | alb::block mem; 24 | }; 25 | 26 | TEST_F(MallocatorTest, ThatAllocatingZeroBytesResultsInAnEmptyBlock) 27 | { 28 | mem = sut.allocate(0); 29 | EXPECT_FALSE(mem); 30 | } 31 | 32 | TEST_F(MallocatorTest, ThatAllocatingResultsInAnCorrectBock) 33 | { 34 | mem = sut.allocate(8); 35 | EXPECT_EQ(8u, mem.length); 36 | } 37 | 38 | #ifdef NDEBUG // cannot be tested in debug mode 39 | TEST_F(MallocatorTest, ThatAllocatingATooHugeBlockResultsIntoAnEmptyBlock) 40 | { 41 | mem = sut.allocate(-1); 42 | EXPECT_FALSE(mem); 43 | } 44 | #endif 45 | 46 | TEST_F(MallocatorTest, ThatReallocatingResultsInAnNewSizedBlock) 47 | { 48 | mem = sut.allocate(8); 49 | EXPECT_TRUE(sut.reallocate(mem, 16)); 50 | EXPECT_EQ(16u, mem.length); 51 | } 52 | 53 | TEST_F(MallocatorTest, ThatReallocatingABlockToZeroResultsInAnEmptyBlock) 54 | { 55 | mem = sut.allocate(8); 56 | EXPECT_TRUE(sut.reallocate(mem, 0)); 57 | EXPECT_FALSE(mem); 58 | } 59 | 60 | #if 0 61 | TEST_F(MallocatorTest, ThatReallocatingABlockToATooHugeFails) 62 | { 63 | mem = sut.allocate(8); 64 | EXPECT_FALSE(sut.reallocate(mem, std::numeric_limits::max())); 65 | EXPECT_EQ(8u, mem.length); 66 | } 67 | #endif -------------------------------------------------------------------------------- /test/MemoryTest.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright 2014 Felix Petriconi 4 | // 5 | // License: http://boost.org/LICENSE_1_0.txt, Boost License 1.0 6 | // 7 | // Authors: http://petriconi.net, Felix Petriconi 8 | // 9 | /////////////////////////////////////////////////////////////////// 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include "TestHelpers/AllocatorBaseTest.h" 15 | 16 | using MyAllocator = alb::affix_allocator; 17 | 18 | struct HelpObjectNonTrivialDestructable 19 | { 20 | HelpObjectNonTrivialDestructable() 21 | : v(42) 22 | , s(std::to_string(++objectCounter)) 23 | {} 24 | 25 | HelpObjectNonTrivialDestructable(int p1, const std::string& p2) 26 | : v(p1) 27 | , s(p2) 28 | { 29 | ++objectCounter; 30 | } 31 | 32 | ~HelpObjectNonTrivialDestructable() 33 | { 34 | --objectCounter; 35 | } 36 | 37 | int v; 38 | std::string s; 39 | static int objectCounter; 40 | }; 41 | 42 | int HelpObjectNonTrivialDestructable::objectCounter = 0; 43 | 44 | 45 | class MakeUniqueTest : public alb::test_helpers::AllocatorBaseTest 46 | { 47 | }; 48 | 49 | TEST_F(MakeUniqueTest, TestThatMakeUniqueOfASingleObjectWithoutPassingCTorsArgumentsAllocatesAnObject) 50 | { 51 | { 52 | auto t = alb::make_unique(sut); 53 | EXPECT_EQ(1, HelpObjectNonTrivialDestructable::objectCounter); 54 | } 55 | EXPECT_EQ(0, HelpObjectNonTrivialDestructable::objectCounter); 56 | } 57 | 58 | TEST_F(MakeUniqueTest, TestThatMakeUniqueOfASingleObjectWithPassingCtorsArgumentsAllocatesAnObject) 59 | { 60 | { 61 | auto t = alb::make_unique(sut, 42, "Don't panic" ); 62 | EXPECT_EQ(1, HelpObjectNonTrivialDestructable::objectCounter); 63 | EXPECT_EQ(42, t->v); 64 | EXPECT_EQ(std::string("Don't panic"), t->s); 65 | } 66 | EXPECT_EQ(0, HelpObjectNonTrivialDestructable::objectCounter); 67 | } 68 | 69 | TEST_F(MakeUniqueTest, TestThatMakeUniqueOfMultipleNonDefaultDestructableObjectsWithoutPassingCtorsArgumentsAllocatesAnObject) 70 | { 71 | { 72 | auto t = alb::make_unique(sut, 42); 73 | for (auto i = 0u; i < 42; ++i) 74 | { 75 | EXPECT_EQ(42, t[i].v); 76 | EXPECT_EQ(std::to_string(i+1), t[i].s); 77 | } 78 | EXPECT_EQ(42, HelpObjectNonTrivialDestructable::objectCounter); 79 | } 80 | EXPECT_EQ(0, HelpObjectNonTrivialDestructable::objectCounter); 81 | } 82 | 83 | 84 | struct HelpObjectTrivialyDestructable 85 | { 86 | HelpObjectTrivialyDestructable() 87 | : v(42) 88 | { 89 | s[0] = '\0'; 90 | } 91 | 92 | int v; 93 | char s[32]; 94 | }; 95 | 96 | TEST_F(MakeUniqueTest, TestThatMakeUniqueOfMultipleDefaultDestructableObjectsWithoutPassingCtorsArgumentsAllocatesAnObject) 97 | { 98 | auto t = alb::make_unique(sut, 42); 99 | } 100 | 101 | 102 | class MakeSharedTest : public alb::test_helpers::AllocatorBaseTest 103 | { 104 | }; 105 | 106 | TEST_F(MakeSharedTest, TestThatMakeUniqueOfASingleObjectWithoutPassingCTorsArgumentsAllocatesAnObject) 107 | { 108 | { 109 | auto t = alb::make_shared(sut); 110 | EXPECT_EQ(1, HelpObjectNonTrivialDestructable::objectCounter); 111 | } 112 | EXPECT_EQ(0, HelpObjectNonTrivialDestructable::objectCounter); 113 | } 114 | 115 | TEST_F(MakeSharedTest, TestThatMakeSharedWithPassingCtorsArgumentsAllocatesAnObject) 116 | { 117 | { 118 | auto t = alb::make_shared(sut, 42, "Don't panic"); 119 | EXPECT_EQ(1, HelpObjectNonTrivialDestructable::objectCounter); 120 | EXPECT_EQ(42, t->v); 121 | EXPECT_EQ(std::string("Don't panic"), t->s); 122 | auto t2 = t; 123 | 124 | EXPECT_EQ(2, t.use_count()); 125 | EXPECT_EQ(42, t2->v); 126 | EXPECT_EQ(std::string("Don't panic"), t2->s); 127 | } 128 | EXPECT_EQ(0, HelpObjectNonTrivialDestructable::objectCounter); 129 | } -------------------------------------------------------------------------------- /test/NullAllocatorTest.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright 2015 Felix Petriconi 4 | // 5 | // License: http://boost.org/LICENSE_1_0.txt, Boost License 1.0 6 | // 7 | // Authors: http://petriconi.net, Felix Petriconi 8 | // 9 | ////////////////////////////////////////////////////////////////// 10 | #include 11 | #include 12 | 13 | TEST(NullAllocatorTest, AllocationAllocatesNothing) 14 | { 15 | alb::null_allocator sut; 16 | auto b = sut.allocate(16); 17 | EXPECT_FALSE(b); 18 | } 19 | -------------------------------------------------------------------------------- /test/SegregatorTest.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright 2014 Felix Petriconi 4 | // 5 | // License: http://boost.org/LICENSE_1_0.txt, Boost License 1.0 6 | // 7 | // Authors: http://petriconi.net, Felix Petriconi 8 | // 9 | ////////////////////////////////////////////////////////////////// 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include "TestHelpers/AllocatorBaseTest.h" 16 | #include "TestHelpers/Data.h" 17 | #include "TestHelpers/Base.h" 18 | 19 | namespace { 20 | const size_t LargeBlockSize = 64; 21 | } 22 | 23 | class SegregatorTest 24 | : public alb::test_helpers::AllocatorBaseTest< 25 | alb::segregator::max_size, alb::stack_allocator<32, 4>, 26 | alb::shared_heap>> { 27 | protected: 28 | void SetUp() 29 | { 30 | mem = sut.allocate(4); 31 | StartSmallAllocatorPtr = mem.ptr; 32 | deallocateAndCheckBlockIsThenEmpty(mem); 33 | 34 | mem = sut.allocate(alb::stack_allocator<32>::max_size + 1); 35 | StartLargeAllocatorPtr = mem.ptr; 36 | deallocateAndCheckBlockIsThenEmpty(mem); 37 | 38 | ASSERT_NE(StartSmallAllocatorPtr, StartLargeAllocatorPtr); 39 | } 40 | 41 | void TearDown() 42 | { 43 | deallocateAndCheckBlockIsThenEmpty(mem); 44 | } 45 | 46 | void *StartSmallAllocatorPtr; 47 | void *StartLargeAllocatorPtr; 48 | alb::block mem; 49 | }; 50 | 51 | TEST_F(SegregatorTest, ThatAllocatingZeroBytesResultsInAnEmptyBlock) 52 | { 53 | mem = sut.allocate(0); 54 | 55 | EXPECT_EQ(0u, mem.length); 56 | EXPECT_EQ(nullptr, mem.ptr); 57 | } 58 | 59 | TEST_F(SegregatorTest, ThatAllocating8BytesResultsInABlockOfThatSize) 60 | { 61 | mem = sut.allocate(8); 62 | 63 | EXPECT_EQ(8u, mem.length); 64 | EXPECT_NE(nullptr, mem.ptr); 65 | } 66 | 67 | TEST_F(SegregatorTest, ThatAllocatingSmallAllocatorsSizeReturnsABlockOfThatSize) 68 | { 69 | mem = sut.allocate(alb::stack_allocator<32>::max_size); 70 | 71 | EXPECT_EQ(alb::stack_allocator<32>::max_size, mem.length); 72 | EXPECT_NE(nullptr, mem.ptr); 73 | } 74 | 75 | TEST_F( 76 | SegregatorTest, 77 | ThatAllocatingLargeAllocatorsSizeReturnsABlockOfThatSizeAndItsBufferDoesNotComeFromTheSmallAllocator) 78 | { 79 | mem = sut.allocate(LargeBlockSize); 80 | 81 | EXPECT_EQ(LargeBlockSize, mem.length); 82 | EXPECT_EQ(StartLargeAllocatorPtr, mem.ptr); 83 | } 84 | 85 | TEST_F(SegregatorTest, ThatReallocatingASmallBlockWithInTheBoundsOfTheSmallAllocatorStaysThere) 86 | { 87 | mem = sut.allocate(8); 88 | alb::test_helpers::fillBlockWithReferenceData(mem); 89 | 90 | EXPECT_TRUE(sut.reallocate(mem, alb::stack_allocator<32>::max_size)); 91 | alb::test_helpers::EXPECT_MEM_EQ(mem.ptr, (void *)alb::test_helpers::ReferenceData.data(), 8); 92 | 93 | EXPECT_EQ(alb::stack_allocator<32>::max_size, mem.length); 94 | EXPECT_EQ(StartSmallAllocatorPtr, mem.ptr); 95 | } 96 | 97 | TEST_F(SegregatorTest, 98 | ThatReallocatingASmallBlockOutOfTheBoundsOfTheSmallAllocatorItGoesToTheLargeAllocator) 99 | { 100 | mem = sut.allocate(8); 101 | alb::test_helpers::fillBlockWithReferenceData(mem); 102 | 103 | EXPECT_TRUE(sut.reallocate(mem, alb::stack_allocator<32>::max_size + 1)); 104 | alb::test_helpers::EXPECT_MEM_EQ(mem.ptr, (void *)alb::test_helpers::ReferenceData.data(), 8); 105 | 106 | EXPECT_LE(alb::stack_allocator<32>::max_size, mem.length); 107 | EXPECT_EQ(StartLargeAllocatorPtr, mem.ptr); 108 | } 109 | 110 | TEST_F(SegregatorTest, ThatReallocatingALargeBlockToASmallerSizeGoesToTheSmallAllocator) 111 | { 112 | mem = sut.allocate(LargeBlockSize); 113 | alb::test_helpers::fillBlockWithReferenceData(mem); 114 | 115 | EXPECT_TRUE(sut.reallocate(mem, 4)); 116 | alb::test_helpers::EXPECT_MEM_EQ(mem.ptr, (void *)alb::test_helpers::ReferenceData.data(), 4); 117 | 118 | EXPECT_EQ(4u, mem.length); 119 | EXPECT_EQ(StartSmallAllocatorPtr, mem.ptr); 120 | } 121 | -------------------------------------------------------------------------------- /test/TestHelpers/AffixGuard.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright 2014 Felix Petriconi 4 | // 5 | // License: http://boost.org/LICENSE_1_0.txt, Boost License 1.0 6 | // 7 | // Authors: http://petriconi.net, Felix Petriconi 8 | // 9 | /////////////////////////////////////////////////////////////////// 10 | #pragma once 11 | 12 | #include 13 | 14 | namespace alb { 15 | namespace test_helpers { 16 | 17 | template 18 | class AffixGuard { 19 | static_assert(sizeof(char) < sizeof(T) && sizeof(T) <= sizeof(uint64_t), "Memory check not for valid types"); 20 | 21 | T _pattern; 22 | public: 23 | typedef T value_type; 24 | static const T pattern = Pattern; 25 | 26 | AffixGuard() : _pattern(Pattern) {} 27 | 28 | AffixGuard(const AffixGuard& o) : _pattern(o._pattern) { 29 | EXPECT_EQ(_pattern, Pattern); 30 | } 31 | ~AffixGuard() { 32 | EXPECT_EQ(_pattern, Pattern); 33 | } 34 | }; 35 | } 36 | } -------------------------------------------------------------------------------- /test/TestHelpers/Algorithm.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright 2014 Felix Petriconi 4 | // 5 | // License: http://boost.org/LICENSE_1_0.txt, Boost License 1.0 6 | // 7 | // Authors: http://petriconi.net, Felix Petriconi 8 | // 9 | /////////////////////////////////////////////////////////////////// 10 | #pragma once 11 | 12 | namespace alb { 13 | namespace test_helpers { 14 | 15 | /** 16 | * Simple class that oscillates from zero to maxValue with each increment 17 | */ 18 | class Oszillator 19 | { 20 | int _value; 21 | bool _up; 22 | int _maxValue; 23 | public: 24 | explicit Oszillator(int maxValue) 25 | : _value(0) 26 | , _up(true) 27 | , _maxValue(maxValue) 28 | {} 29 | 30 | operator int(){ 31 | return _value; 32 | } 33 | 34 | Oszillator& operator++() 35 | { 36 | if (_up) { 37 | ++_value; 38 | } 39 | else { 40 | --_value; 41 | } 42 | if (_value == _maxValue) { 43 | _up = false; 44 | } 45 | else if (_value == 0) { 46 | _up = true; 47 | } 48 | return *this; 49 | } 50 | }; 51 | 52 | 53 | 54 | template 55 | N iota(I first, I last, N start, N step) { 56 | typedef typename std::iterator_traits::value_type T; 57 | while (first != last) { 58 | *first = T(start); 59 | start += step; 60 | ++first; 61 | } 62 | return start; 63 | } 64 | } 65 | 66 | } -------------------------------------------------------------------------------- /test/TestHelpers/AllocatorBaseTest.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright 2014 Felix Petriconi 4 | // 5 | // License: http://boost.org/LICENSE_1_0.txt, Boost License 1.0 6 | // 7 | // Authors: http://petriconi.net, Felix Petriconi 8 | // 9 | /////////////////////////////////////////////////////////////////// 10 | #pragma once 11 | 12 | #include 13 | #include 14 | 15 | namespace alb 16 | { 17 | namespace test_helpers 18 | { 19 | 20 | template 21 | class AllocatorBaseTest : public ::testing::Test 22 | { 23 | protected: 24 | typedef Allocator allocator; 25 | 26 | void deallocateAndCheckBlockIsThenEmpty(alb::block& b) { 27 | sut.deallocate(b); 28 | EXPECT_FALSE(b); 29 | EXPECT_EQ(nullptr, b.ptr); 30 | } 31 | Allocator sut; 32 | }; 33 | 34 | } 35 | } -------------------------------------------------------------------------------- /test/TestHelpers/Base.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright 2014 Felix Petriconi 4 | // 5 | // License: http://boost.org/LICENSE_1_0.txt, Boost License 1.0 6 | // 7 | // Authors: http://petriconi.net, Felix Petriconi 8 | // 9 | /////////////////////////////////////////////////////////////////// 10 | #include 11 | #include "Base.h" 12 | 13 | void alb::test_helpers::EXPECT_MEM_EQ(void *a, void *b, size_t n) 14 | { 15 | auto isDifferentAt = ::memcmp(a, b, n); 16 | EXPECT_EQ(0, isDifferentAt) << "Memory is different at offset: " << isDifferentAt 17 | << ". Should be " << (int)*(static_cast(b) + isDifferentAt) 18 | << " but should be " 19 | << (int)*(static_cast(a) + isDifferentAt); 20 | } 21 | 22 | std::atomic alb::test_helpers::TestMallocator::_allocatedMem; 23 | -------------------------------------------------------------------------------- /test/TestHelpers/Base.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright 2014 Felix Petriconi 4 | // 5 | // License: http://boost.org/LICENSE_1_0.txt, Boost License 1.0 6 | // 7 | // Authors: http://petriconi.net, Felix Petriconi 8 | // 9 | /////////////////////////////////////////////////////////////////// 10 | #pragma once 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #include 21 | #include 22 | 23 | namespace alb 24 | { 25 | namespace test_helpers 26 | { 27 | /** 28 | * Checks that both memory blocks are equal until n bytes 29 | */ 30 | void EXPECT_MEM_EQ(void* a, void* b, size_t n); 31 | 32 | class TestMallocator{ 33 | alb::mallocator _mallocator; 34 | static std::atomic _allocatedMem; 35 | 36 | public: 37 | static constexpr bool supports_truncated_deallocation = false; 38 | static constexpr unsigned alignment = alb::mallocator::alignment; 39 | 40 | TestMallocator() {} 41 | 42 | block allocate(size_t n) { 43 | auto result = _mallocator.allocate(n); 44 | if (result) { 45 | _allocatedMem.fetch_add(result.length); 46 | } 47 | return result; 48 | } 49 | 50 | bool reallocate(block& b, size_t n) { 51 | _allocatedMem.fetch_sub(b.length); 52 | auto result = _mallocator.reallocate(b, n); 53 | _allocatedMem.fetch_add(b.length); 54 | return result; 55 | } 56 | 57 | void deallocate(block& b) { 58 | _allocatedMem.fetch_sub(b.length); 59 | _mallocator.deallocate(b); 60 | } 61 | 62 | static size_t currentlyAllocatedBytes() { 63 | return _allocatedMem.load(); 64 | } 65 | }; 66 | 67 | } 68 | } 69 | 70 | -------------------------------------------------------------------------------- /test/TestHelpers/Data.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright 2014 Felix Petriconi 4 | // 5 | // License: http://boost.org/LICENSE_1_0.txt, Boost License 1.0 6 | // 7 | // Authors: http://petriconi.net, Felix Petriconi 8 | // 9 | /////////////////////////////////////////////////////////////////// 10 | #pragma once 11 | 12 | #include 13 | #include "Algorithm.h" 14 | #include 15 | 16 | namespace alb { 17 | namespace test_helpers { 18 | 19 | const size_t ReferenceDataSize = 64; 20 | const std::vector ReferenceData = 21 | []() -> std::vector { 22 | std::vector result(ReferenceDataSize); 23 | iota(std::begin(result), std::end(result), 0, 1); 24 | return result; 25 | }(); 26 | 27 | 28 | 29 | template 30 | void fillBlockWithReferenceData(alb::block& b) 31 | { 32 | for (size_t i = 0; i < std::min(ReferenceData.size(), b.length / sizeof(T)); i++) { 33 | *(static_cast(b.ptr) + i) = ReferenceData[i]; 34 | } 35 | } 36 | 37 | } 38 | } -------------------------------------------------------------------------------- /test/TestHelpers/UsedMemGenerator.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright 2014 Felix Petriconi 4 | // 5 | // License: http://boost.org/LICENSE_1_0.txt, Boost License 1.0 6 | // 7 | // Authors: http://petriconi.net, Felix Petriconi 8 | // 9 | /////////////////////////////////////////////////////////////////// 10 | #pragma once 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | namespace alb { 24 | namespace test_helpers { 25 | 26 | template 27 | class UsedMem 28 | { 29 | Allocator& allocator_; 30 | std::vector _usedBlocks; 31 | template 32 | friend class UsedMemGenerator; 33 | 34 | public: 35 | UsedMem(Allocator& allocator) 36 | : allocator_(allocator) { 37 | } 38 | 39 | const std::vector& blocks() const { return _usedBlocks; } 40 | }; 41 | 42 | template 43 | class UsedMemGenerator { 44 | UsedMem _usedMem; 45 | std::vector _freedLater; 46 | public: 47 | UsedMemGenerator(Allocator& allocator) 48 | : _usedMem(allocator) 49 | {} 50 | 51 | UsedMemGenerator& withAUsedPatternOf(const char* pattern) { 52 | char* p = const_cast(pattern); 53 | while (*p) { 54 | if (*p == '1') { 55 | _usedMem._usedBlocks.push_back(_usedMem.allocator_.allocate(BytesPerBitMarker)); 56 | } 57 | else if (*p == '0') { 58 | _freedLater.push_back(_usedMem.allocator_.allocate(BytesPerBitMarker)); 59 | } 60 | ++p; 61 | } 62 | return *this; 63 | } 64 | 65 | UsedMem build() { 66 | for (auto& b : _freedLater) { 67 | _usedMem.allocator_.deallocate(b); 68 | } 69 | return _usedMem; 70 | } 71 | 72 | }; 73 | 74 | } 75 | } -------------------------------------------------------------------------------- /test/main.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright 2014 Felix Petriconi 4 | // 5 | // License: http://boost.org/LICENSE_1_0.txt, Boost License 1.0 6 | // 7 | // Authors: http://petriconi.net, Felix Petriconi 8 | // 9 | /////////////////////////////////////////////////////////////////// 10 | 11 | #include 12 | #include 13 | 14 | int main(int argc, char **argv) 15 | { 16 | std::cout << "Running main() from gtest_main.cc\n"; 17 | ::testing::InitGoogleTest(&argc, argv); 18 | return RUN_ALL_TESTS(); 19 | } 20 | -------------------------------------------------------------------------------- /test/util.hpp: -------------------------------------------------------------------------------- 1 | #ifndef UTIL_HPP 2 | #define UTIL_HPP 3 | 4 | template 5 | void ignore_unused(T&&) 6 | {} 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/gtest-1.7.0/msvc/gtest-md.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 11 | 12 | 13 | 20 | 31 | 33 | 36 | 38 | 40 | 42 | 44 | 46 | 48 | 50 | 52 | 54 | 55 | 62 | 70 | 72 | 75 | 77 | 79 | 81 | 83 | 85 | 87 | 89 | 91 | 93 | 94 | 95 | 96 | 97 | 98 | 102 | 104 | 106 | 109 | 110 | 112 | 115 | 116 | 117 | 118 | 122 | 123 | 124 | 125 | 126 | 127 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/gtest-1.7.0/msvc/gtest.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 11 | 12 | 13 | 20 | 31 | 33 | 36 | 38 | 40 | 42 | 44 | 46 | 48 | 50 | 52 | 54 | 55 | 62 | 70 | 72 | 75 | 77 | 79 | 81 | 83 | 85 | 87 | 89 | 91 | 93 | 94 | 95 | 96 | 97 | 98 | 102 | 104 | 106 | 109 | 110 | 112 | 115 | 116 | 117 | 118 | 122 | 123 | 124 | 125 | 126 | 127 | -------------------------------------------------------------------------------- /util/gtest-1.7.0/msvc/gtest_main-md.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 11 | 12 | 13 | 20 | 31 | 33 | 36 | 38 | 40 | 42 | 44 | 46 | 48 | 50 | 52 | 54 | 55 | 62 | 70 | 72 | 75 | 77 | 79 | 81 | 83 | 85 | 87 | 89 | 91 | 93 | 94 | 95 | 96 | 99 | 100 | 101 | 105 | 107 | 109 | 112 | 113 | 115 | 118 | 119 | 120 | 121 | 125 | 126 | 127 | 128 | 129 | 130 | -------------------------------------------------------------------------------- /util/gtest-1.7.0/msvc/gtest_main.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 11 | 12 | 13 | 20 | 31 | 33 | 36 | 38 | 40 | 42 | 44 | 46 | 48 | 50 | 52 | 54 | 55 | 62 | 70 | 72 | 75 | 77 | 79 | 81 | 83 | 85 | 87 | 89 | 91 | 93 | 94 | 95 | 96 | 99 | 100 | 101 | 105 | 107 | 109 | 112 | 113 | 115 | 118 | 119 | 120 | 121 | 125 | 126 | 127 | 128 | 129 | 130 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/gtest-1.7.0/test/gtest-death-test_ex_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2010, 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 that verify interaction of exceptions and death tests. 33 | 34 | #include "gtest/gtest-death-test.h" 35 | #include "gtest/gtest.h" 36 | 37 | #if GTEST_HAS_DEATH_TEST 38 | 39 | # if GTEST_HAS_SEH 40 | # include // For RaiseException(). 41 | # endif 42 | 43 | # include "gtest/gtest-spi.h" 44 | 45 | # if GTEST_HAS_EXCEPTIONS 46 | 47 | # include // For std::exception. 48 | 49 | // Tests that death tests report thrown exceptions as failures and that the 50 | // exceptions do not escape death test macros. 51 | TEST(CxxExceptionDeathTest, ExceptionIsFailure) { 52 | try { 53 | EXPECT_NONFATAL_FAILURE(EXPECT_DEATH(throw 1, ""), "threw an exception"); 54 | } catch (...) { // NOLINT 55 | FAIL() << "An exception escaped a death test macro invocation " 56 | << "with catch_exceptions " 57 | << (testing::GTEST_FLAG(catch_exceptions) ? "enabled" : "disabled"); 58 | } 59 | } 60 | 61 | class TestException : public std::exception { 62 | public: 63 | virtual const char* what() const throw() { return "exceptional message"; } 64 | }; 65 | 66 | TEST(CxxExceptionDeathTest, PrintsMessageForStdExceptions) { 67 | // Verifies that the exception message is quoted in the failure text. 68 | EXPECT_NONFATAL_FAILURE(EXPECT_DEATH(throw TestException(), ""), 69 | "exceptional message"); 70 | // Verifies that the location is mentioned in the failure text. 71 | EXPECT_NONFATAL_FAILURE(EXPECT_DEATH(throw TestException(), ""), 72 | "gtest-death-test_ex_test.cc"); 73 | } 74 | # endif // GTEST_HAS_EXCEPTIONS 75 | 76 | # if GTEST_HAS_SEH 77 | // Tests that enabling interception of SEH exceptions with the 78 | // catch_exceptions flag does not interfere with SEH exceptions being 79 | // treated as death by death tests. 80 | TEST(SehExceptionDeasTest, CatchExceptionsDoesNotInterfere) { 81 | EXPECT_DEATH(RaiseException(42, 0x0, 0, NULL), "") 82 | << "with catch_exceptions " 83 | << (testing::GTEST_FLAG(catch_exceptions) ? "enabled" : "disabled"); 84 | } 85 | # endif 86 | 87 | #endif // GTEST_HAS_DEATH_TEST 88 | 89 | int main(int argc, char** argv) { 90 | testing::InitGoogleTest(&argc, argv); 91 | testing::GTEST_FLAG(catch_exceptions) = GTEST_ENABLE_CATCH_EXCEPTIONS_ != 0; 92 | return RUN_ALL_TESTS(); 93 | } 94 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/gtest-1.7.0/test/gtest_env_var_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 correctly parses environment variables.""" 33 | 34 | __author__ = 'wan@google.com (Zhanyong Wan)' 35 | 36 | import os 37 | import gtest_test_utils 38 | 39 | 40 | IS_WINDOWS = os.name == 'nt' 41 | IS_LINUX = os.name == 'posix' and os.uname()[0] == 'Linux' 42 | 43 | COMMAND = gtest_test_utils.GetTestExecutablePath('gtest_env_var_test_') 44 | 45 | environ = os.environ.copy() 46 | 47 | 48 | def AssertEq(expected, actual): 49 | if expected != actual: 50 | print 'Expected: %s' % (expected,) 51 | print ' Actual: %s' % (actual,) 52 | raise AssertionError 53 | 54 | 55 | def SetEnvVar(env_var, value): 56 | """Sets the env variable to 'value'; unsets it when 'value' is None.""" 57 | 58 | if value is not None: 59 | environ[env_var] = value 60 | elif env_var in environ: 61 | del environ[env_var] 62 | 63 | 64 | def GetFlag(flag): 65 | """Runs gtest_env_var_test_ and returns its output.""" 66 | 67 | args = [COMMAND] 68 | if flag is not None: 69 | args += [flag] 70 | return gtest_test_utils.Subprocess(args, env=environ).output 71 | 72 | 73 | def TestFlag(flag, test_val, default_val): 74 | """Verifies that the given flag is affected by the corresponding env var.""" 75 | 76 | env_var = 'GTEST_' + flag.upper() 77 | SetEnvVar(env_var, test_val) 78 | AssertEq(test_val, GetFlag(flag)) 79 | SetEnvVar(env_var, None) 80 | AssertEq(default_val, GetFlag(flag)) 81 | 82 | 83 | class GTestEnvVarTest(gtest_test_utils.TestCase): 84 | def testEnvVarAffectsFlag(self): 85 | """Tests that environment variable should affect the corresponding flag.""" 86 | 87 | TestFlag('break_on_failure', '1', '0') 88 | TestFlag('color', 'yes', 'auto') 89 | TestFlag('filter', 'FooTest.Bar', '*') 90 | TestFlag('output', 'xml:tmp/foo.xml', '') 91 | TestFlag('print_time', '0', '1') 92 | TestFlag('repeat', '999', '1') 93 | TestFlag('throw_on_failure', '1', '0') 94 | TestFlag('death_test_style', 'threadsafe', 'fast') 95 | TestFlag('catch_exceptions', '0', '1') 96 | 97 | if IS_LINUX: 98 | TestFlag('death_test_use_fork', '1', '0') 99 | TestFlag('stack_trace_depth', '0', '100') 100 | 101 | 102 | if __name__ == '__main__': 103 | gtest_test_utils.Main() 104 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/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 | -------------------------------------------------------------------------------- /util/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 | --------------------------------------------------------------------------------