├── .gitignore ├── .travis.yml ├── AUTHORS ├── CMakeLists.txt ├── LICENSE ├── README.md ├── debian ├── changelog ├── compat ├── control ├── copyright ├── libmedida-dev.docs ├── libmedida-dev.install ├── libmedida0.docs ├── libmedida0.install └── rules ├── doc ├── api │ ├── _footer.html │ └── _header.html ├── css │ ├── bootstrap-responsive.min.css │ ├── bootstrap.min.css │ └── medida.css ├── doxygen.cfg.in ├── img │ ├── glyphicons-halflings-white.png │ ├── glyphicons-halflings.png │ └── meter.png ├── index.html ├── js │ └── bootstrap.min.js └── medida ├── etc └── collectd │ └── medida-types.db ├── examples ├── CMakeLists.txt └── medida_example1.cc ├── libmedida.pc.in ├── src └── medida │ ├── counter.cc │ ├── counter.h │ ├── histogram.cc │ ├── histogram.h │ ├── medida.h │ ├── meter.cc │ ├── meter.h │ ├── metered_interface.h │ ├── metric_interface.h │ ├── metric_name.cc │ ├── metric_name.h │ ├── metric_processor.cc │ ├── metric_processor.h │ ├── metrics_registry.cc │ ├── metrics_registry.h │ ├── reporting │ ├── abstract_polling_reporter.cc │ ├── abstract_polling_reporter.h │ ├── collectd_reporter.cc │ ├── collectd_reporter.h │ ├── console_reporter.cc │ ├── console_reporter.h │ ├── json_reporter.cc │ ├── json_reporter.h │ ├── util.cc │ └── util.h │ ├── sampling_interface.h │ ├── stats │ ├── ewma.cc │ ├── ewma.h │ ├── exp_decay_sample.cc │ ├── exp_decay_sample.h │ ├── sample.h │ ├── snapshot.cc │ ├── snapshot.h │ ├── uniform_sample.cc │ └── uniform_sample.h │ ├── summarizable_interface.h │ ├── timer.cc │ ├── timer.h │ ├── timer_context.cc │ ├── timer_context.h │ └── types.h └── test ├── CMakeLists.txt ├── gtest-1.6.0 ├── CHANGES ├── CMakeLists.txt ├── CONTRIBUTORS ├── COPYING ├── 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 ├── 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 ├── 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_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 ├── reporting ├── test_collectd_reporter.cc ├── test_console_reporter.cc └── test_json_reporter.cc ├── stats ├── test_ewma.cc ├── test_exp_decay_sample.cc ├── test_snapshot.cc └── test_uniform_sample.cc ├── test_counter.cc ├── test_histogram.cc ├── test_meter.cc ├── test_metric_name.cc ├── test_metrics_registry.cc └── test_timer.cc /.gitignore: -------------------------------------------------------------------------------- 1 | *.a 2 | *.marks 3 | *.dylib 4 | *.o 5 | *.pb.* 6 | *.pc 7 | *.pyc 8 | .tags* 9 | .DS_Store 10 | /CMakeFiles/* 11 | /build* 12 | /debian/*.debhelper 13 | /debian/*.log 14 | /debian/*.substvars 15 | /debian/stamp-* 16 | /debian/files 17 | /debian/libmedida-dbg/ 18 | /debian/libmedida-dev/ 19 | /debian/libmedida0-dbg/ 20 | /debian/libmedida0/ 21 | /debian/tmp/ 22 | /dist/* 23 | /obj-*/ 24 | /tags 25 | /target 26 | /test/CMakeFiles/* 27 | /test/test-medida 28 | /test/gtest-1.6.0/build-aux/config.guess.cdbs-orig 29 | /test/gtest-1.6.0/build-aux/config.sub.cdbs-orig 30 | CMakeCache.txt 31 | Makefile 32 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | compiler: 3 | - gcc 4 | before_install: 5 | - sudo apt-get update -qq 6 | - sudo apt-get install -qq cmake 7 | before_script: 8 | cmake --config=Debug . 9 | script: 10 | cmake --build . && ctest -V 11 | branches: 12 | only: 13 | - master 14 | notifications: 15 | recipients: 16 | - dln@eintr.org 17 | email: 18 | on_success: change 19 | on_failure: always 20 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Daniel Lundin 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Medida - Simple metrics for C++ programs 2 | ======================================== 3 | 4 | *NOTE: Work in progress and not for human consumption! Go away!* 5 | 6 | Project homepage and documentation: http://dln.github.com/medida/ 7 | 8 | Created out of envy of Coda Hale's awesome Metrics library for the JVM. 9 | 10 | 11 | Copyright 12 | --------- 13 | Copyright (c) 2012 Daniel Lundin 14 | 15 | This software is licensed under the Apache License, Version 2.0. 16 | Please see LICENSE for details. 17 | -------------------------------------------------------------------------------- /debian/changelog: -------------------------------------------------------------------------------- 1 | medida (0.1.0) unstable; urgency=low 2 | 3 | * First package. 4 | 5 | -- Daniel Lundin Fri, 28 Sep 2012 14:51:30 +0200 6 | -------------------------------------------------------------------------------- /debian/compat: -------------------------------------------------------------------------------- 1 | 8 2 | -------------------------------------------------------------------------------- /debian/control: -------------------------------------------------------------------------------- 1 | Source: medida 2 | Section: libs 3 | Priority: optional 4 | Maintainer: Daniel Lundin 5 | Homepage: https://github.com/dln/medida/ 6 | Standards-Version: 3.9.2 7 | Build-Depends: debhelper (>= 8), cmake (>= 2.8.8), doxygen, pkg-config 8 | 9 | Package: libmedida-dev 10 | Architecture: any 11 | Depends: ${misc:Depends}, ${shlibs:Depends} 12 | Description: Medida metrics library 13 | 14 | Package: libmedida0 15 | Architecture: any 16 | Recommends: libmedida-dbg (= ${binary:Version}) 17 | Depends: ${misc:Depends}, ${shlibs:Depends} 18 | Description: Medida metrics library. 19 | 20 | Package: libmedida-dbg 21 | Section: debug 22 | Priority: extra 23 | Architecture: any 24 | Depends: ${misc:Depends}, ${shlibs:Depends}, libmedida0 (= ${binary:Version}) 25 | Description: Medida metrics library. Debug symbols. 26 | 27 | -------------------------------------------------------------------------------- /debian/copyright: -------------------------------------------------------------------------------- 1 | This package was debianized by Daniel Lundin 2 | Fri Sep 28 18:29:52 CEST 2012 3 | 4 | It was downloaded from: https://github.com/dln/medida/ 5 | 6 | Upstream Author(s): Daniel Lundin 7 | 8 | Copyright: 9 | Copyright (C) 2012 by Daniel Lundin 10 | 11 | License: 12 | 13 | Licensed to the Apache Software Foundation (ASF) under one or more contributor 14 | license agreements. The ASF licenses this work to You under the Apache License, 15 | Version 2.0 (the "License"); you may not use this work except in compliance 16 | with the License. You may obtain a copy of the License at 17 | 18 | http://www.apache.org/licenses/LICENSE-2.0 19 | 20 | On a Debian system, the license can be found at 21 | /usr/share/common-licenses/Apache-2.0 . 22 | -------------------------------------------------------------------------------- /debian/libmedida-dev.docs: -------------------------------------------------------------------------------- 1 | AUTHORS 2 | README.md 3 | -------------------------------------------------------------------------------- /debian/libmedida-dev.install: -------------------------------------------------------------------------------- 1 | usr/include/* 2 | usr/lib/libmedida.so 3 | usr/lib/pkgconfig/libmedida.pc 4 | usr/share/doc/libmedida-dev 5 | -------------------------------------------------------------------------------- /debian/libmedida0.docs: -------------------------------------------------------------------------------- 1 | AUTHORS 2 | README.md 3 | -------------------------------------------------------------------------------- /debian/libmedida0.install: -------------------------------------------------------------------------------- 1 | usr/lib/libmedida.so.* 2 | -------------------------------------------------------------------------------- /debian/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | 3 | export DH_VERBOSE=1 4 | 5 | DEB_CMAKE_EXTRA_FLAGS := -DBUILD_DOCS=ON 6 | 7 | include /usr/share/cdbs/1/class/cmake.mk 8 | include /usr/share/cdbs/1/rules/debhelper.mk 9 | 10 | override_dh_strip: 11 | dh_strip --dbg-package=libmedida-dbg 12 | 13 | .PHONY: override_dh_strip 14 | -------------------------------------------------------------------------------- /doc/api/_footer.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /doc/api/_header.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | $projectname: $title 7 | $title 8 | 9 | 10 | $treeview 11 | $search 12 | $mathjax 13 | 29 | 30 | 31 |
32 | 33 | 34 |
35 | Medida 36 |
37 | 38 | -------------------------------------------------------------------------------- /doc/css/medida.css: -------------------------------------------------------------------------------- 1 | 2 | #header { 3 | background-image: url("/medida/img/meter.png"); 4 | background-repeat: no-repeat; 5 | background-position: right center; 6 | padding-right: 250px; 7 | } -------------------------------------------------------------------------------- /doc/img/glyphicons-halflings-white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dln/medida/1a488e50dd22140bc7d365d2cb2a5c47b69b6044/doc/img/glyphicons-halflings-white.png -------------------------------------------------------------------------------- /doc/img/glyphicons-halflings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dln/medida/1a488e50dd22140bc7d365d2cb2a5c47b69b6044/doc/img/glyphicons-halflings.png -------------------------------------------------------------------------------- /doc/img/meter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dln/medida/1a488e50dd22140bc7d365d2cb2a5c47b69b6044/doc/img/meter.png -------------------------------------------------------------------------------- /doc/medida: -------------------------------------------------------------------------------- 1 | . -------------------------------------------------------------------------------- /etc/collectd/medida-types.db: -------------------------------------------------------------------------------- 1 | medida_counter count:GAUGE:0:U 2 | medida_meter count:GAUGE:0:U, mean_rate:GAUGE:0:U, 1min_rate:GAUGE:0:U, 5min_rate:GAUGE:0:U, 15min_rate:GAUGE:0:U 3 | medida_histogram min:GAUGE:0:U, max:GAUGE:0:U, mean:GAUGE:0:U, std_dev:GAUGE:0:U, median:GAUGE:0:U, 75pct:GAUGE:0:U, 95pct:GAUGE:0:U, 98pct:GAUGE:0:U, 99pct:GAUGE:0:U, 999pct:GAUGE:0:U 4 | medida_timer min:GAUGE:0:U, max:GAUGE:0:U, mean:GAUGE:0:U, std_dev:GAUGE:0:U, median:GAUGE:0:U, 75pct:GAUGE:0:U, 95pct:GAUGE:0:U, 98pct:GAUGE:0:U, 99pct:GAUGE:0:U, 999pct:GAUGE:0:U 5 | -------------------------------------------------------------------------------- /examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 2.8.6) 2 | 3 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") 4 | 5 | include(FindPkgConfig) 6 | 7 | pkg_check_modules(MEDIDA libmedida) 8 | 9 | include_directories(${MEDIDA_INCLUDE_DIRS}) 10 | 11 | link_directories(${MEDIDA_LIBRARY_DIRS}) 12 | 13 | add_executable(medida-example1 medida_example1.cc) 14 | 15 | target_link_libraries(medida-example1 medida) 16 | 17 | 18 | -------------------------------------------------------------------------------- /examples/medida_example1.cc: -------------------------------------------------------------------------------- 1 | #include "medida/medida.h" 2 | 3 | int main(int argc, char* argv[]) { 4 | medida::MetricsRegistry registry; 5 | auto& counter = registry.NewCounter({"foo", "bar", "baz"}); 6 | counter.inc(); 7 | 8 | return 0; 9 | } -------------------------------------------------------------------------------- /libmedida.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | exec_prefix=@CMAKE_INSTALL_PREFIX@ 3 | libdir=${prefix}/@LIB_INSTALL_DIR@ 4 | includedir=${prefix}/@INCLUDE_INSTALL_ROOT_DIR@ 5 | 6 | Name: libmedida 7 | Description: Medida metrics library for C++ 8 | Version: @medida_VERSION@ 9 | Libs: -L${libdir} -lmedida 10 | Cflags: -I${includedir} 11 | -------------------------------------------------------------------------------- /src/medida/counter.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 Daniel Lundin 3 | // 4 | 5 | #include "medida/counter.h" 6 | 7 | #include 8 | 9 | namespace medida { 10 | 11 | class Counter::Impl { 12 | public: 13 | Impl(std::int64_t init = 0); 14 | ~Impl(); 15 | void Process(MetricProcessor& processor); 16 | std::int64_t count() const; 17 | void set_count(std::int64_t n); 18 | void inc(std::int64_t n = 1); 19 | void dec(std::int64_t n = 1); 20 | void clear(); 21 | private: 22 | std::atomic count_; 23 | }; 24 | 25 | 26 | Counter::Counter(std::int64_t init) 27 | : impl_ {new Counter::Impl {init}} { 28 | } 29 | 30 | 31 | Counter::~Counter() { 32 | } 33 | 34 | 35 | void Counter::Process(MetricProcessor& processor) { 36 | processor.Process(*this); // FIXME: pimpl? 37 | } 38 | 39 | 40 | std::int64_t Counter::count() const { 41 | return impl_->count(); 42 | } 43 | 44 | 45 | void Counter::set_count(std::int64_t n) { 46 | return impl_->set_count(n); 47 | } 48 | 49 | 50 | void Counter::inc(std::int64_t n) { 51 | impl_->inc(n); 52 | } 53 | 54 | 55 | void Counter::dec(std::int64_t n) { 56 | impl_->dec(n); 57 | } 58 | 59 | 60 | void Counter::clear() { 61 | impl_->clear(); 62 | } 63 | 64 | 65 | // === Implementation === 66 | 67 | 68 | Counter::Impl::Impl(std::int64_t init) : count_ {init} { 69 | } 70 | 71 | 72 | Counter::Impl::~Impl() { 73 | } 74 | 75 | 76 | std::int64_t Counter::Impl::count() const { 77 | return count_.load(); 78 | } 79 | 80 | 81 | void Counter::Impl::set_count(std::int64_t n) { 82 | count_ = n; 83 | } 84 | 85 | 86 | void Counter::Impl::inc(std::int64_t n) { 87 | count_ += n; 88 | } 89 | 90 | 91 | void Counter::Impl::dec(std::int64_t n) { 92 | count_ -= n; 93 | } 94 | 95 | 96 | void Counter::Impl::clear() { 97 | set_count(0); 98 | } 99 | 100 | 101 | } // namespace medida -------------------------------------------------------------------------------- /src/medida/counter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 Daniel Lundin 3 | // 4 | 5 | #ifndef MEDIDA_COUNTER_H_ 6 | #define MEDIDA_COUNTER_H_ 7 | 8 | #include 9 | #include 10 | 11 | #include "medida/metric_interface.h" 12 | 13 | namespace medida { 14 | 15 | class Counter : public MetricInterface { 16 | public: 17 | Counter(std::int64_t init = 0); 18 | ~Counter(); 19 | void Process(MetricProcessor& processor); 20 | std::int64_t count() const; 21 | void set_count(std::int64_t n); 22 | void inc(std::int64_t n = 1); 23 | void dec(std::int64_t n = 1); 24 | void clear(); 25 | private: 26 | class Impl; 27 | std::unique_ptr impl_; 28 | }; 29 | 30 | } // namespace medida 31 | 32 | #endif // MEDIDA_COUNTER_H_ 33 | -------------------------------------------------------------------------------- /src/medida/histogram.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 Daniel Lundin 3 | // 4 | 5 | #ifndef MEDIDA_HISTOGRAM_H_ 6 | #define MEDIDA_HISTOGRAM_H_ 7 | 8 | #include 9 | #include 10 | 11 | #include "medida/metric_interface.h" 12 | #include "medida/sampling_interface.h" 13 | #include "medida/summarizable_interface.h" 14 | #include "medida/stats/sample.h" 15 | 16 | namespace medida { 17 | 18 | class Histogram : public MetricInterface, SamplingInterface, SummarizableInterface { 19 | public: 20 | Histogram(SampleType sample_type = kUniform); 21 | ~Histogram(); 22 | virtual stats::Snapshot GetSnapshot() const; 23 | virtual double sum() const; 24 | virtual double max() const; 25 | virtual double min() const; 26 | virtual double mean() const; 27 | virtual double std_dev() const; 28 | void Update(std::int64_t value); 29 | std::uint64_t count() const; 30 | double variance() const; 31 | void Process(MetricProcessor& processor); 32 | void Clear(); 33 | private: 34 | class Impl; 35 | std::unique_ptr impl_; 36 | }; 37 | 38 | } // namespace medida 39 | 40 | #endif // MEDIDA_HISTOGRAM_H_ 41 | -------------------------------------------------------------------------------- /src/medida/medida.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 Daniel Lundin 3 | // 4 | 5 | #ifndef MEDIDA_H_ 6 | #define MEDIDA_H_ 7 | 8 | #include "medida/metrics_registry.h" 9 | #include "medida/reporting/collectd_reporter.h" 10 | #include "medida/reporting/console_reporter.h" 11 | #include "medida/reporting/json_reporter.h" 12 | 13 | #endif // MEDIDA_H_ 14 | -------------------------------------------------------------------------------- /src/medida/meter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 Daniel Lundin 3 | // 4 | 5 | #ifndef MEDIDA_METER_H_ 6 | #define MEDIDA_METER_H_ 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include "medida/stats/ewma.h" 13 | #include "medida/metered_interface.h" 14 | #include "medida/metric_interface.h" 15 | #include "medida/metric_processor.h" 16 | #include "medida/stats/sample.h" 17 | 18 | namespace medida { 19 | 20 | class Meter : public MetricInterface, MeteredInterface { 21 | public: 22 | Meter(std::string event_type, std::chrono::nanoseconds rate_unit = std::chrono::seconds(1)); 23 | ~Meter(); 24 | virtual std::chrono::nanoseconds rate_unit() const; 25 | virtual std::string event_type() const; 26 | virtual std::uint64_t count() const; 27 | virtual double fifteen_minute_rate(); 28 | virtual double five_minute_rate(); 29 | virtual double one_minute_rate(); 30 | virtual double mean_rate(); 31 | void Mark(std::uint64_t n = 1); 32 | void Process(MetricProcessor& processor); 33 | private: 34 | class Impl; 35 | std::unique_ptr impl_; 36 | }; 37 | 38 | } // namespace medida 39 | 40 | #endif // MEDIDA_METER_H_ 41 | -------------------------------------------------------------------------------- /src/medida/metered_interface.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 Daniel Lundin 3 | // 4 | 5 | #ifndef MEDIDA_METERED_INTERFACE_H_ 6 | #define MEDIDA_METERED_INTERFACE_H_ 7 | 8 | #include "medida/types.h" 9 | 10 | namespace medida { 11 | 12 | class MeteredInterface { 13 | public: 14 | virtual ~MeteredInterface() {}; 15 | virtual std::chrono::nanoseconds rate_unit() const = 0; 16 | virtual std::string event_type() const = 0; 17 | virtual std::uint64_t count() const = 0; 18 | virtual double fifteen_minute_rate() = 0; 19 | virtual double five_minute_rate() = 0; 20 | virtual double one_minute_rate() = 0; 21 | virtual double mean_rate() = 0; 22 | }; 23 | 24 | } // namespace medida 25 | 26 | #endif // MEDIDA_METERED_INTERFACE_H_ 27 | -------------------------------------------------------------------------------- /src/medida/metric_interface.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 Daniel Lundin 3 | // 4 | 5 | #ifndef MEDIDA_METRIC_INTERFACE_H_ 6 | #define MEDIDA_METRIC_INTERFACE_H_ 7 | 8 | #include "medida/metric_processor.h" 9 | 10 | namespace medida { 11 | 12 | class MetricInterface { 13 | public: 14 | virtual ~MetricInterface() {}; 15 | virtual void Process(MetricProcessor& processor) = 0; 16 | }; 17 | 18 | } // namespace medida 19 | 20 | #endif // MEDIDA_METRIC_INTERFACE_H_ 21 | -------------------------------------------------------------------------------- /src/medida/metric_name.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 Daniel Lundin 3 | // 4 | 5 | #ifndef MEDIDA_METRIC_NAME_H_ 6 | #define MEDIDA_METRIC_NAME_H_ 7 | 8 | 9 | #include 10 | #include 11 | 12 | namespace medida { 13 | 14 | class MetricName { 15 | public: 16 | MetricName(const std::string &domain, const std::string &type, const std::string &name, const std::string &scope = ""); 17 | MetricName(const MetricName& other); 18 | ~MetricName(); 19 | std::string domain() const; 20 | std::string type() const; 21 | std::string name() const; 22 | std::string scope() const; 23 | std::string ToString() const; 24 | bool has_scope() const; 25 | bool operator==(const MetricName& other) const; 26 | bool operator!=(const MetricName& other) const; 27 | bool operator<(const MetricName& other) const; 28 | bool operator>(const MetricName& other) const; 29 | private: 30 | class Impl; 31 | std::unique_ptr impl_; 32 | }; 33 | 34 | 35 | } // namespace medida 36 | 37 | #endif // MEDIDA_METRIC_NAME_H_ 38 | -------------------------------------------------------------------------------- /src/medida/metric_processor.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 Daniel Lundin 3 | // 4 | 5 | #include "medida/metric_processor.h" 6 | 7 | namespace medida { 8 | 9 | MetricProcessor::~MetricProcessor() { 10 | } 11 | 12 | void MetricProcessor::Process(Counter& counter) { 13 | } 14 | 15 | 16 | void MetricProcessor::Process(Histogram& histogram) { 17 | } 18 | 19 | 20 | void MetricProcessor::Process(Meter& meter) { 21 | } 22 | 23 | 24 | void MetricProcessor::Process(Timer& timer) { 25 | } 26 | 27 | 28 | void MetricProcessor::Process(MetricInterface& metric) { 29 | } 30 | 31 | 32 | 33 | } // namespace medida -------------------------------------------------------------------------------- /src/medida/metric_processor.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 Daniel Lundin 3 | // 4 | 5 | #ifndef MEDIDA_METRIC_PROCESSOR_H_ 6 | #define MEDIDA_METRIC_PROCESSOR_H_ 7 | 8 | namespace medida { 9 | 10 | class Counter; 11 | class Histogram; 12 | class Meter; 13 | class MetricInterface; 14 | class Timer; 15 | 16 | class MetricProcessor { 17 | public: 18 | virtual ~MetricProcessor(); 19 | virtual void Process(Counter& counter); 20 | virtual void Process(Histogram& histogram); 21 | virtual void Process(Meter& meter); 22 | virtual void Process(Timer& timer); 23 | virtual void Process(MetricInterface& metric); 24 | }; 25 | 26 | } // namespace medida 27 | 28 | #endif // MEDIDA_METRIC_PROCESSOR_H_ 29 | -------------------------------------------------------------------------------- /src/medida/metrics_registry.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 Daniel Lundin 3 | // 4 | 5 | #include "medida/metrics_registry.h" 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #include "medida/metric_name.h" 12 | 13 | namespace medida { 14 | 15 | class MetricsRegistry::Impl { 16 | public: 17 | Impl(); 18 | ~Impl(); 19 | Counter& NewCounter(const MetricName &name, std::int64_t init_value = 0); 20 | Histogram& NewHistogram(const MetricName &name, 21 | SamplingInterface::SampleType sample_type = SamplingInterface::kUniform); 22 | Meter& NewMeter(const MetricName &name, std::string event_type, 23 | Clock::duration rate_unit = std::chrono::seconds(1)); 24 | Timer& NewTimer(const MetricName &name, 25 | std::chrono::nanoseconds duration_unit = std::chrono::milliseconds(1), 26 | std::chrono::nanoseconds rate_unit = std::chrono::seconds(1)); 27 | std::map> GetAllMetrics() const; 28 | void ProcessAll(MetricProcessor& processor); 29 | private: 30 | std::map> metrics_; 31 | mutable std::mutex mutex_; 32 | template T& NewMetric(const MetricName& name, Args... args); 33 | }; 34 | 35 | 36 | MetricsRegistry::MetricsRegistry() : impl_ {new MetricsRegistry::Impl} { 37 | } 38 | 39 | 40 | MetricsRegistry::~MetricsRegistry() { 41 | } 42 | 43 | 44 | Counter& MetricsRegistry::NewCounter(const MetricName &name, std::int64_t init_value) { 45 | return impl_->NewCounter(name, init_value); 46 | } 47 | 48 | 49 | Histogram& MetricsRegistry::NewHistogram(const MetricName &name, 50 | SamplingInterface::SampleType sample_type) { 51 | return impl_->NewHistogram(name, sample_type); 52 | } 53 | 54 | 55 | Meter& MetricsRegistry::NewMeter(const MetricName &name, std::string event_type, 56 | Clock::duration rate_unit) { 57 | return impl_->NewMeter(name, event_type, rate_unit); 58 | } 59 | 60 | 61 | Timer& MetricsRegistry::NewTimer(const MetricName &name, std::chrono::nanoseconds duration_unit, 62 | std::chrono::nanoseconds rate_unit) { 63 | return impl_->NewTimer(name, duration_unit, rate_unit); 64 | } 65 | 66 | 67 | std::map> MetricsRegistry::GetAllMetrics() const { 68 | return impl_->GetAllMetrics(); 69 | } 70 | 71 | 72 | // === Implementation === 73 | 74 | 75 | MetricsRegistry::Impl::Impl() { 76 | } 77 | 78 | 79 | MetricsRegistry::Impl::~Impl() { 80 | } 81 | 82 | 83 | Counter& MetricsRegistry::Impl::NewCounter(const MetricName &name, std::int64_t init_value) { 84 | return NewMetric(name, init_value); 85 | } 86 | 87 | 88 | Histogram& MetricsRegistry::Impl::NewHistogram(const MetricName &name, 89 | SamplingInterface::SampleType sample_type) { 90 | return NewMetric(name, sample_type); 91 | } 92 | 93 | 94 | Meter& MetricsRegistry::Impl::NewMeter(const MetricName &name, std::string event_type, 95 | Clock::duration rate_unit) { 96 | return NewMetric(name, event_type, rate_unit); 97 | } 98 | 99 | 100 | Timer& MetricsRegistry::Impl::NewTimer(const MetricName &name, std::chrono::nanoseconds duration_unit, 101 | std::chrono::nanoseconds rate_unit) { 102 | return NewMetric(name, duration_unit, rate_unit); 103 | } 104 | 105 | 106 | template 107 | MetricType& MetricsRegistry::Impl::NewMetric(const MetricName& name, Args... args) { 108 | std::lock_guard lock {mutex_}; 109 | if (metrics_.find(name) == std::end(metrics_)) { 110 | // GCC 4.6: Bug 44436 emplace* not implemented. Use ::reset instead. 111 | // metrics_[name].reset(new MetricType(args...)); 112 | metrics_[name] = std::make_shared(args...); 113 | } else { 114 | } 115 | return dynamic_cast(*metrics_[name]); 116 | } 117 | 118 | std::map> MetricsRegistry::Impl::GetAllMetrics() const { 119 | return {metrics_}; 120 | } 121 | 122 | 123 | } // namespace medida -------------------------------------------------------------------------------- /src/medida/metrics_registry.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 Daniel Lundin 3 | // 4 | 5 | #ifndef MEDIDA_METRICS_REGISTRY_H_ 6 | #define MEDIDA_METRICS_REGISTRY_H_ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "medida/counter.h" 14 | #include "medida/histogram.h" 15 | #include "medida/meter.h" 16 | #include "medida/metric_interface.h" 17 | #include "medida/metric_name.h" 18 | #include "medida/metric_processor.h" 19 | #include "medida/timer.h" 20 | 21 | namespace medida { 22 | 23 | class MetricsRegistry { 24 | public: 25 | MetricsRegistry(); 26 | ~MetricsRegistry(); 27 | Counter& NewCounter(const MetricName &name, std::int64_t init_value = 0); 28 | Histogram& NewHistogram(const MetricName &name, 29 | SamplingInterface::SampleType sample_type = SamplingInterface::kUniform); 30 | Meter& NewMeter(const MetricName &name, std::string event_type, 31 | Clock::duration rate_unit = std::chrono::seconds(1)); 32 | Timer& NewTimer(const MetricName &name, 33 | std::chrono::nanoseconds duration_unit = std::chrono::milliseconds(1), 34 | std::chrono::nanoseconds rate_unit = std::chrono::seconds(1)); 35 | std::map> GetAllMetrics() const; 36 | private: 37 | class Impl; 38 | std::unique_ptr impl_; 39 | }; 40 | 41 | } // namespace medida 42 | 43 | #endif // MEDIDA_METRICS_REGISTRY_H_ 44 | -------------------------------------------------------------------------------- /src/medida/reporting/abstract_polling_reporter.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 Daniel Lundin 3 | // 4 | 5 | #include "medida/reporting/abstract_polling_reporter.h" 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | namespace medida { 12 | namespace reporting { 13 | 14 | class AbstractPollingReporter::Impl { 15 | public: 16 | Impl(AbstractPollingReporter& self); 17 | ~Impl(); 18 | void Shutdown(); 19 | void Start(Clock::duration period = std::chrono::seconds(5)); 20 | private: 21 | AbstractPollingReporter& self_; 22 | std::atomic running_; 23 | std::thread thread_; 24 | void Loop(Clock::duration period); 25 | }; 26 | 27 | 28 | AbstractPollingReporter::AbstractPollingReporter() 29 | : impl_ {new AbstractPollingReporter::Impl {*this}} { 30 | } 31 | 32 | 33 | AbstractPollingReporter::~AbstractPollingReporter() { 34 | } 35 | 36 | 37 | void AbstractPollingReporter::Shutdown() { 38 | impl_->Shutdown(); 39 | } 40 | 41 | 42 | void AbstractPollingReporter::Start(Clock::duration period) { 43 | impl_->Start(period); 44 | } 45 | 46 | 47 | void AbstractPollingReporter::Run() { 48 | } 49 | 50 | 51 | // === Implementation === 52 | 53 | 54 | AbstractPollingReporter::Impl::Impl(AbstractPollingReporter& self) 55 | : self_ (self), 56 | running_ {false} { 57 | } 58 | 59 | 60 | AbstractPollingReporter::Impl::~Impl() { 61 | Shutdown(); 62 | } 63 | 64 | 65 | void AbstractPollingReporter::Impl::Shutdown() { 66 | if (running_) { 67 | running_ = false; 68 | thread_.join(); 69 | } 70 | } 71 | 72 | 73 | void AbstractPollingReporter::Impl::Start(Clock::duration period) { 74 | if (!running_) { 75 | running_ = true; 76 | thread_ = std::thread(&AbstractPollingReporter::Impl::Loop, this, period); 77 | } 78 | } 79 | 80 | 81 | void AbstractPollingReporter::Impl::Loop(Clock::duration period) { 82 | while (running_) { 83 | std::this_thread::sleep_for(period); 84 | self_.Run(); 85 | } 86 | } 87 | 88 | 89 | } // namespace reporting 90 | } // namespace medida 91 | -------------------------------------------------------------------------------- /src/medida/reporting/abstract_polling_reporter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 Daniel Lundin 3 | // 4 | 5 | #ifndef MEDIDA_REPORTING_ABSTRACT_POLLING_REPORTER_H_ 6 | #define MEDIDA_REPORTING_ABSTRACT_POLLING_REPORTER_H_ 7 | 8 | #include 9 | 10 | #include "medida/types.h" 11 | 12 | namespace medida { 13 | namespace reporting { 14 | 15 | class AbstractPollingReporter { 16 | public: 17 | AbstractPollingReporter(); 18 | virtual ~AbstractPollingReporter(); 19 | virtual void Shutdown(); 20 | virtual void Start(Clock::duration period = std::chrono::seconds(5)); 21 | virtual void Run(); 22 | private: 23 | class Impl; 24 | std::unique_ptr impl_; 25 | }; 26 | 27 | } // namespace reporting 28 | } // namespace medida 29 | 30 | #endif // MEDIDA_REPORTING_ABSTRACT_POLLING_REPORTER_H_ 31 | -------------------------------------------------------------------------------- /src/medida/reporting/collectd_reporter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 Daniel Lundin 3 | // 4 | 5 | #ifndef MEDIDA_REPORTING_COLLECTD_REPORTER_H_ 6 | #define MEDIDA_REPORTING_COLLECTD_REPORTER_H_ 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include "medida/metrics_registry.h" 13 | #include "medida/metric_processor.h" 14 | #include "medida/reporting/abstract_polling_reporter.h" 15 | 16 | namespace medida { 17 | namespace reporting { 18 | 19 | 20 | class CollectdReporter : public AbstractPollingReporter, MetricProcessor { 21 | public: 22 | CollectdReporter(MetricsRegistry ®istry, const std::string& hostname = "127.0.0.1", std::uint16_t port = 25826); 23 | virtual ~CollectdReporter(); 24 | virtual void Run(); 25 | virtual void Process(Counter& counter); 26 | virtual void Process(Meter& meter); 27 | virtual void Process(Histogram& histogram); 28 | virtual void Process(Timer& timer); 29 | private: 30 | class Impl; 31 | std::unique_ptr impl_; 32 | }; 33 | 34 | 35 | } // namespace reporting 36 | } // namespace medida 37 | 38 | #endif // MEDIDA_REPORTING_COLLECTD_REPORTER_H_ 39 | -------------------------------------------------------------------------------- /src/medida/reporting/console_reporter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 Daniel Lundin 3 | // 4 | 5 | #ifndef MEDIDA_REPORTING_CONSOLE_REPORTER_H_ 6 | #define MEDIDA_REPORTING_CONSOLE_REPORTER_H_ 7 | 8 | #include 9 | 10 | #include "medida/metric_processor.h" 11 | #include "medida/metrics_registry.h" 12 | #include "medida/reporting/abstract_polling_reporter.h" 13 | 14 | namespace medida { 15 | namespace reporting { 16 | 17 | class ConsoleReporter : public AbstractPollingReporter, MetricProcessor { 18 | public: 19 | ConsoleReporter(MetricsRegistry ®istry, std::ostream& out = std::cerr); 20 | virtual ~ConsoleReporter(); 21 | virtual void Run(); 22 | virtual void Process(Counter& counter); 23 | virtual void Process(Meter& meter); 24 | virtual void Process(Histogram& histogram); 25 | virtual void Process(Timer& timer); 26 | private: 27 | class Impl; 28 | std::unique_ptr impl_; 29 | }; 30 | 31 | 32 | } // namespace reporting 33 | } // namespace medida 34 | 35 | #endif // MEDIDA_REPORTING_CONSOLE_REPORTER_H_ 36 | -------------------------------------------------------------------------------- /src/medida/reporting/json_reporter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 Daniel Lundin 3 | // 4 | 5 | #ifndef MEDIDA_REPORTING_JSON_REPORTER_H_ 6 | #define MEDIDA_REPORTING_JSON_REPORTER_H_ 7 | 8 | #include 9 | #include 10 | 11 | #include "medida/metric_processor.h" 12 | #include "medida/metrics_registry.h" 13 | 14 | namespace medida { 15 | namespace reporting { 16 | 17 | class JsonReporter : public MetricProcessor { 18 | public: 19 | JsonReporter(MetricsRegistry ®istry); 20 | virtual ~JsonReporter(); 21 | virtual void Process(Counter& counter); 22 | virtual void Process(Meter& meter); 23 | virtual void Process(Histogram& histogram); 24 | virtual void Process(Timer& timer); 25 | virtual std::string Report(); 26 | private: 27 | class Impl; 28 | std::unique_ptr impl_; 29 | }; 30 | 31 | 32 | } // namespace reporting 33 | } // namespace medida 34 | 35 | #endif // MEDIDA_REPORTING_JSON_REPORTER_H_ 36 | -------------------------------------------------------------------------------- /src/medida/reporting/util.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 Daniel Lundin 3 | // 4 | 5 | #include "medida/reporting/util.h" 6 | 7 | #include 8 | 9 | namespace medida { 10 | namespace reporting { 11 | 12 | static const std::int64_t 13 | NS_PER_US = 1000, 14 | NS_PER_MS = 1000 * NS_PER_US, 15 | NS_PER_SECOND = 1000 * NS_PER_MS, 16 | NS_PER_MIN = 60 * NS_PER_SECOND, 17 | NS_PER_HOUR = 60 * NS_PER_MIN, 18 | NS_PER_DAY = 24 * NS_PER_HOUR; 19 | 20 | 21 | std::string FormatRateUnit(const std::chrono::nanoseconds& rate_unit) { 22 | auto nanosecs = rate_unit.count(); 23 | if (nanosecs >= NS_PER_DAY) { 24 | return "d"; 25 | } else if (nanosecs >= NS_PER_HOUR) { 26 | return "h"; 27 | } else if (nanosecs >= NS_PER_MIN) { 28 | return "m"; 29 | } else if (nanosecs >= NS_PER_SECOND) { 30 | return "s"; 31 | } else if (nanosecs >= NS_PER_MS) { 32 | return "ms"; 33 | } else if (nanosecs >= NS_PER_US) { 34 | return "us"; 35 | } 36 | return "ns"; 37 | } 38 | 39 | 40 | } // namespace reporting 41 | } // namespace medida 42 | -------------------------------------------------------------------------------- /src/medida/reporting/util.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 Daniel Lundin 3 | // 4 | 5 | #ifndef MEDIDA_REPORTING_UTIL_H_ 6 | #define MEDIDA_REPORTING_UTIL_H_ 7 | 8 | #include 9 | #include 10 | 11 | namespace medida { 12 | namespace reporting { 13 | 14 | std::string FormatRateUnit(const std::chrono::nanoseconds& rate_unit); 15 | 16 | } // namespace reporting 17 | } // namespace medida 18 | 19 | #endif // MEDIDA_REPORTING_UTIL_H_ 20 | -------------------------------------------------------------------------------- /src/medida/sampling_interface.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 Daniel Lundin 3 | // 4 | 5 | #ifndef MEDIDA_SAMPLING_INTERFACE_H_ 6 | #define MEDIDA_SAMPLING_INTERFACE_H_ 7 | 8 | #include "medida/stats/snapshot.h" 9 | 10 | namespace medida { 11 | 12 | class SamplingInterface { 13 | public: 14 | enum SampleType { kUniform, kBiased }; 15 | virtual ~SamplingInterface() {}; 16 | virtual stats::Snapshot GetSnapshot() const = 0; 17 | }; 18 | 19 | } // namespace medida 20 | 21 | #endif // MEDIDA_SAMPLING_INTERFACE_H_ 22 | -------------------------------------------------------------------------------- /src/medida/stats/ewma.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 Daniel Lundin 3 | // 4 | 5 | #include "medida/stats/ewma.h" 6 | 7 | #include 8 | #include 9 | 10 | namespace medida { 11 | namespace stats { 12 | 13 | static constexpr int kINTERVAL = 5; 14 | static constexpr double kSECONDS_PER_MINUTE = 60.0; 15 | static constexpr int kONE_MINUTE = 1; 16 | static constexpr int kFIVE_MINUTES = 5; 17 | static constexpr int kFIFTEEN_MINUTES = 15; 18 | static constexpr double kM1_ALPHA = 1 - std::exp(-kINTERVAL / kSECONDS_PER_MINUTE / kONE_MINUTE); 19 | static constexpr double kM5_ALPHA = 1 - std::exp(-kINTERVAL / kSECONDS_PER_MINUTE / kFIVE_MINUTES); 20 | static constexpr double kM15_ALPHA = 1 - std::exp(-kINTERVAL / kSECONDS_PER_MINUTE / kFIFTEEN_MINUTES); 21 | 22 | class EWMA::Impl { 23 | public: 24 | Impl(double alpha, std::chrono::nanoseconds interval); 25 | Impl(Impl &other); 26 | ~Impl(); 27 | void update(std::int64_t n); 28 | void tick(); 29 | double getRate(std::chrono::nanoseconds duration = std::chrono::seconds {1}) const; 30 | private: 31 | volatile bool initialized_; 32 | volatile double rate_; 33 | std::atomic uncounted_; 34 | const double alpha_; 35 | const std::uint64_t interval_nanos_; 36 | }; 37 | 38 | 39 | EWMA::EWMA(double alpha, std::chrono::nanoseconds interval) 40 | : impl_ {new EWMA::Impl {alpha, interval}} { 41 | } 42 | 43 | 44 | EWMA::EWMA(EWMA &&other) 45 | : impl_ {new EWMA::Impl{*other.impl_}} { 46 | } 47 | 48 | 49 | EWMA::~EWMA() { 50 | } 51 | 52 | 53 | EWMA EWMA::oneMinuteEWMA() { 54 | return {kM1_ALPHA, std::chrono::seconds{5}}; 55 | } 56 | 57 | 58 | EWMA EWMA::fiveMinuteEWMA() { 59 | return {kM5_ALPHA, std::chrono::seconds{5}}; 60 | } 61 | 62 | 63 | EWMA EWMA::fifteenMinuteEWMA() { 64 | return {kM15_ALPHA, std::chrono::seconds{5}}; 65 | } 66 | 67 | 68 | void EWMA::update(std::int64_t n) { 69 | impl_->update(n); 70 | } 71 | 72 | 73 | void EWMA::tick() { 74 | impl_->tick(); 75 | } 76 | 77 | 78 | double EWMA::getRate(std::chrono::nanoseconds duration) const { 79 | return impl_->getRate(duration); 80 | } 81 | 82 | 83 | // === Implementation === 84 | 85 | 86 | EWMA::Impl::Impl(double alpha, std::chrono::nanoseconds interval) 87 | : initialized_ {false}, 88 | rate_ {0.0}, 89 | uncounted_ {0}, 90 | alpha_ {alpha}, 91 | interval_nanos_ {interval.count()} { 92 | } 93 | 94 | 95 | EWMA::Impl::Impl(Impl &other) 96 | : initialized_ {other.initialized_}, 97 | rate_ {other.rate_}, 98 | uncounted_ {other.uncounted_.load()}, 99 | alpha_ {other.alpha_}, 100 | interval_nanos_ {other.interval_nanos_} { 101 | } 102 | 103 | 104 | EWMA::Impl::~Impl() { 105 | } 106 | 107 | 108 | void EWMA::Impl::update(std::int64_t n) { 109 | uncounted_ += n; 110 | } 111 | 112 | 113 | void EWMA::Impl::tick() { 114 | double count = uncounted_.exchange(0); 115 | auto instantRate = count / interval_nanos_; 116 | if (initialized_) { 117 | rate_ += (alpha_ * (instantRate - rate_)); 118 | } else { 119 | rate_ = instantRate; 120 | initialized_ = true; 121 | } 122 | } 123 | 124 | 125 | double EWMA::Impl::getRate(std::chrono::nanoseconds duration) const { 126 | return rate_ * duration.count(); 127 | } 128 | 129 | 130 | } // namespace stats 131 | } // namespace medida 132 | -------------------------------------------------------------------------------- /src/medida/stats/ewma.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 Daniel Lundin 3 | // 4 | 5 | #ifndef MEDIDA_EWMA_H_ 6 | #define MEDIDA_EWMA_H_ 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | namespace medida { 13 | namespace stats { 14 | 15 | class EWMA { 16 | public: 17 | EWMA() = delete; 18 | EWMA(double alpha, std::chrono::nanoseconds interval); 19 | EWMA(EWMA &&other); 20 | ~EWMA(); 21 | static EWMA oneMinuteEWMA(); 22 | static EWMA fiveMinuteEWMA(); 23 | static EWMA fifteenMinuteEWMA(); 24 | void update(std::int64_t n); 25 | void tick(); 26 | double getRate(std::chrono::nanoseconds duration = std::chrono::seconds {1}) const; 27 | private: 28 | class Impl; 29 | std::unique_ptr impl_; 30 | }; 31 | 32 | } // namespace stats 33 | } // namespace medida 34 | 35 | #endif // MEDIDA_EWMA_H_ 36 | -------------------------------------------------------------------------------- /src/medida/stats/exp_decay_sample.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 Daniel Lundin 3 | // 4 | 5 | #ifndef MEDIDA_EXP_DECAY_SAMPLE_H_ 6 | #define MEDIDA_EXP_DECAY_SAMPLE_H_ 7 | 8 | #include 9 | #include 10 | 11 | #include "medida/types.h" 12 | #include "medida/stats/sample.h" 13 | 14 | namespace medida { 15 | namespace stats { 16 | 17 | class ExpDecaySample : public Sample { 18 | public: 19 | ExpDecaySample() = delete; 20 | ExpDecaySample(std::uint32_t reservoirSize, double alpha); 21 | ~ExpDecaySample(); 22 | virtual void Clear(); 23 | virtual std::uint64_t size() const; 24 | virtual void Update(std::int64_t value); 25 | virtual void Update(std::int64_t value, Clock::time_point timestamp); 26 | virtual Snapshot MakeSnapshot() const; 27 | private: 28 | class Impl; 29 | std::unique_ptr impl_; 30 | }; 31 | 32 | } // namespace stats 33 | } // namespace medida 34 | 35 | #endif // MEDIDA_EXP_DECAY_SAMPLE_H_ 36 | -------------------------------------------------------------------------------- /src/medida/stats/sample.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 Daniel Lundin 3 | // 4 | 5 | #ifndef MEDIDA_SAMPLE_H_ 6 | #define MEDIDA_SAMPLE_H_ 7 | 8 | #include 9 | #include 10 | 11 | #include "medida/stats/snapshot.h" 12 | 13 | namespace medida { 14 | namespace stats { 15 | 16 | class Sample { 17 | public: 18 | virtual ~Sample() {}; 19 | virtual void Clear() = 0; 20 | virtual std::uint64_t size() const = 0; 21 | virtual void Update(std::int64_t value) = 0; 22 | virtual Snapshot MakeSnapshot() const = 0; 23 | }; 24 | 25 | } // namespace stats 26 | } // namespace medida 27 | 28 | #endif // MEDIDA_SAMPLE_H_ 29 | -------------------------------------------------------------------------------- /src/medida/stats/snapshot.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 Daniel Lundin 3 | // 4 | 5 | #include "medida/stats/snapshot.h" 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | namespace medida { 13 | namespace stats { 14 | 15 | static const double kMEDIAN_Q = 0.5; 16 | static const double kP75_Q = 0.75; 17 | static const double kP95_Q = 0.95; 18 | static const double kP98_Q = 0.98; 19 | static const double kP99_Q = 0.99; 20 | static const double kP999_Q = 0.999; 21 | 22 | class Snapshot::Impl { 23 | public: 24 | Impl(const std::vector& values); 25 | ~Impl(); 26 | std::size_t size() const; 27 | double getValue(double quantile) const; 28 | double getMedian() const; 29 | double get75thPercentile() const; 30 | double get95thPercentile() const; 31 | double get98thPercentile() const; 32 | double get99thPercentile() const; 33 | double get999thPercentile() const; 34 | std::vector getValues() const; 35 | private: 36 | std::vector values_; 37 | }; 38 | 39 | 40 | Snapshot::Snapshot(const std::vector& values) 41 | : impl_ {new Snapshot::Impl {values}} { 42 | } 43 | 44 | 45 | Snapshot::~Snapshot() { 46 | delete impl_; // FIXME: Why std::unique_ptr bork? 47 | } 48 | 49 | 50 | std::size_t Snapshot::size() const { 51 | return impl_->size(); 52 | } 53 | 54 | 55 | std::vector Snapshot::getValues() const { 56 | return impl_->getValues(); 57 | } 58 | 59 | 60 | double Snapshot::getValue(double quantile) const { 61 | return impl_->getValue(quantile); 62 | } 63 | 64 | 65 | double Snapshot::getMedian() const { 66 | return impl_->getMedian(); 67 | } 68 | 69 | 70 | double Snapshot::get75thPercentile() const { 71 | return impl_->get75thPercentile(); 72 | } 73 | 74 | 75 | double Snapshot::get95thPercentile() const { 76 | return impl_->get95thPercentile(); 77 | } 78 | 79 | 80 | double Snapshot::get98thPercentile() const { 81 | return impl_->get98thPercentile(); 82 | } 83 | 84 | 85 | double Snapshot::get99thPercentile() const { 86 | return impl_->get99thPercentile(); 87 | } 88 | 89 | 90 | double Snapshot::get999thPercentile() const { 91 | return impl_->get999thPercentile(); 92 | } 93 | 94 | 95 | // === Implementation === 96 | 97 | 98 | Snapshot::Impl::Impl(const std::vector& values) 99 | : values_ {values} { 100 | std::sort(std::begin(this->values_), std::end(this->values_)); 101 | } 102 | 103 | 104 | Snapshot::Impl::~Impl() { 105 | } 106 | 107 | 108 | std::size_t Snapshot::Impl::size() const { 109 | return values_.size(); 110 | } 111 | 112 | 113 | std::vector Snapshot::Impl::getValues() const { 114 | return values_; 115 | } 116 | 117 | 118 | double Snapshot::Impl::getValue(double quantile) const { 119 | if (quantile < 0.0 || quantile > 1.0) { 120 | throw std::invalid_argument("quantile is not in [0..1]"); 121 | } 122 | 123 | if (values_.empty()) { 124 | return 0.0; 125 | } 126 | 127 | auto pos = quantile * (values_.size() + 1); 128 | 129 | if (pos < 1) { 130 | return values_.front(); 131 | } 132 | 133 | if (pos >= values_.size()) { 134 | return values_.back(); 135 | } 136 | 137 | auto lower = values_[pos - 1]; 138 | auto upper = values_[pos]; 139 | return lower + (pos - std::floor(pos)) * (upper - lower); 140 | } 141 | 142 | 143 | double Snapshot::Impl::getMedian() const { 144 | return getValue(kMEDIAN_Q); 145 | } 146 | 147 | 148 | double Snapshot::Impl::get75thPercentile() const { 149 | return getValue(kP75_Q); 150 | } 151 | 152 | 153 | double Snapshot::Impl::get95thPercentile() const { 154 | return getValue(kP95_Q); 155 | } 156 | 157 | 158 | double Snapshot::Impl::get98thPercentile() const { 159 | return getValue(kP98_Q); 160 | } 161 | 162 | 163 | double Snapshot::Impl::get99thPercentile() const { 164 | return getValue(kP99_Q); 165 | } 166 | 167 | 168 | double Snapshot::Impl::get999thPercentile() const { 169 | return getValue(kP999_Q); 170 | } 171 | 172 | 173 | } // namespace stats 174 | } // namespace medida 175 | -------------------------------------------------------------------------------- /src/medida/stats/snapshot.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 Daniel Lundin 3 | // 4 | 5 | #ifndef MEDIDA_METRICS_SNAPSHOT_H_ 6 | #define MEDIDA_METRICS_SNAPSHOT_H_ 7 | 8 | #include 9 | #include 10 | 11 | namespace medida { 12 | namespace stats { 13 | 14 | class Snapshot { 15 | public: 16 | Snapshot(const std::vector& values); 17 | ~Snapshot(); 18 | std::size_t size() const; 19 | double getValue(double quantile) const; 20 | double getMedian() const; 21 | double get75thPercentile() const; 22 | double get95thPercentile() const; 23 | double get98thPercentile() const; 24 | double get99thPercentile() const; 25 | double get999thPercentile() const; 26 | std::vector getValues() const; 27 | private: 28 | class Impl; 29 | Impl* impl_; 30 | // std::unique_ptr impl_; // FIXME: y u incomplete type?!? 31 | }; 32 | 33 | 34 | } // namespace stats 35 | } // namespace medida 36 | 37 | #endif // MEDIDA_METRICS_SNAPSHOT_H_ 38 | -------------------------------------------------------------------------------- /src/medida/stats/uniform_sample.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 Daniel Lundin 3 | // 4 | 5 | #include "medida/stats/uniform_sample.h" 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | namespace medida { 14 | namespace stats { 15 | 16 | class UniformSample::Impl { 17 | public: 18 | Impl(std::uint32_t reservoirSize); 19 | ~Impl(); 20 | void Clear(); 21 | std::uint64_t size() const; 22 | void Update(std::int64_t value); 23 | Snapshot MakeSnapshot() const; 24 | private: 25 | std::uint64_t reservoir_size_; 26 | std::atomic count_; 27 | std::vector> values_; 28 | mutable std::mt19937_64 rng_; 29 | mutable std::mutex rng_mutex_; 30 | }; 31 | 32 | 33 | UniformSample::UniformSample(std::uint32_t reservoirSize) 34 | : impl_ {new UniformSample::Impl {reservoirSize}} { 35 | } 36 | 37 | 38 | UniformSample::~UniformSample() { 39 | } 40 | 41 | 42 | void UniformSample::Clear() { 43 | impl_->Clear(); 44 | } 45 | 46 | 47 | std::uint64_t UniformSample::size() const { 48 | return impl_->size(); 49 | } 50 | 51 | 52 | void UniformSample::Update(std::int64_t value) { 53 | impl_->Update(value); 54 | } 55 | 56 | 57 | Snapshot UniformSample::MakeSnapshot() const { 58 | return impl_->MakeSnapshot(); 59 | } 60 | 61 | 62 | // === Implementation === 63 | 64 | 65 | UniformSample::Impl::Impl(std::uint32_t reservoirSize) 66 | : reservoir_size_ {reservoirSize}, 67 | count_ {}, 68 | values_ (reservoirSize), // FIXME: Explicit and non-uniform 69 | rng_ {std::random_device()()}, 70 | rng_mutex_ {} { 71 | Clear(); 72 | } 73 | 74 | 75 | UniformSample::Impl::~Impl() { 76 | } 77 | 78 | 79 | void UniformSample::Impl::Clear() { 80 | for (auto& v : values_) { 81 | v = 0; 82 | } 83 | count_ = 0; 84 | } 85 | 86 | 87 | std::uint64_t UniformSample::Impl::size() const { 88 | std::uint64_t size = values_.size(); 89 | std::uint64_t count = count_.load(); 90 | return std::min(count, size); 91 | } 92 | 93 | 94 | void UniformSample::Impl::Update(std::int64_t value) { 95 | auto count = ++count_; 96 | auto size = values_.size(); 97 | if (count < size) { 98 | values_[count - 1] = value; 99 | } else { 100 | std::uniform_int_distribution<> uniform(0, count - 1); 101 | std::lock_guard lock {rng_mutex_}; // FIXME: Thread-local RNG? 102 | auto rand = uniform(rng_); 103 | if (rand < size) { 104 | values_[rand] = value; 105 | } 106 | } 107 | } 108 | 109 | 110 | Snapshot UniformSample::Impl::MakeSnapshot() const { 111 | std::uint64_t size = values_.size(); 112 | std::uint64_t count = count_.load(); 113 | auto begin = std::begin(values_); 114 | return Snapshot {{begin, begin + std::min(count, size)}}; 115 | } 116 | 117 | 118 | } // namespace stats 119 | } // namespace medida 120 | -------------------------------------------------------------------------------- /src/medida/stats/uniform_sample.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 Daniel Lundin 3 | // 4 | 5 | #ifndef MEDIDA_UNIFORM_SAMPLE_H_ 6 | #define MEDIDA_UNIFORM_SAMPLE_H_ 7 | 8 | #include 9 | #include 10 | 11 | #include "medida/stats/sample.h" 12 | #include "medida/stats/snapshot.h" 13 | 14 | namespace medida { 15 | namespace stats { 16 | 17 | class UniformSample : public Sample { 18 | public: 19 | UniformSample(std::uint32_t reservoirSize); 20 | ~UniformSample(); 21 | virtual void Clear(); 22 | virtual std::uint64_t size() const; 23 | virtual void Update(std::int64_t value); 24 | virtual Snapshot MakeSnapshot() const; 25 | private: 26 | class Impl; 27 | std::unique_ptr impl_; 28 | }; 29 | 30 | } // namespace stats 31 | } // namespace medida 32 | 33 | #endif // MEDIDA_UNIFORM_SAMPLE_H_ 34 | -------------------------------------------------------------------------------- /src/medida/summarizable_interface.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 Daniel Lundin 3 | // 4 | 5 | #ifndef MEDIDA_SUMMARIZABLE_INTERFACE_H_ 6 | #define MEDIDA_SUMMARIZABLE_INTERFACE_H_ 7 | 8 | namespace medida { 9 | 10 | class SummarizableInterface { 11 | public: 12 | virtual ~SummarizableInterface() {}; 13 | virtual double max() const = 0; 14 | virtual double min() const = 0; 15 | virtual double mean() const = 0; 16 | virtual double std_dev() const = 0; 17 | virtual double sum() const = 0; 18 | }; 19 | 20 | } // namespace medida 21 | 22 | #endif // MEDIDA_SUMMARIZABLE_INTERFACE_H_ 23 | -------------------------------------------------------------------------------- /src/medida/timer.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 Daniel Lundin 3 | // 4 | 5 | #ifndef MEDIDA_TIMER_H_ 6 | #define MEDIDA_TIMER_H_ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "medida/metered_interface.h" 14 | #include "medida/metric_interface.h" 15 | #include "medida/metric_processor.h" 16 | #include "medida/sampling_interface.h" 17 | #include "medida/summarizable_interface.h" 18 | #include "medida/timer_context.h" 19 | 20 | namespace medida { 21 | 22 | class Timer : public MetricInterface, MeteredInterface, SamplingInterface, SummarizableInterface { 23 | public: 24 | Timer(std::chrono::nanoseconds duration_unit = std::chrono::milliseconds(1), 25 | std::chrono::nanoseconds rate_unit = std::chrono::seconds(1)); 26 | ~Timer(); 27 | void Process(MetricProcessor& processor); 28 | virtual std::chrono::nanoseconds rate_unit() const; 29 | virtual std::string event_type() const; 30 | virtual std::uint64_t count() const; 31 | virtual double fifteen_minute_rate(); 32 | virtual double five_minute_rate(); 33 | virtual double one_minute_rate(); 34 | virtual double mean_rate(); 35 | virtual stats::Snapshot GetSnapshot() const; 36 | virtual double max() const; 37 | virtual double min() const; 38 | virtual double mean() const; 39 | virtual double std_dev() const; 40 | virtual double sum() const; 41 | std::chrono::nanoseconds duration_unit() const; 42 | void Clear(); 43 | void Update(std::chrono::nanoseconds duration); 44 | TimerContext TimeScope(); 45 | void Time(std::function); 46 | private: 47 | class Impl; 48 | std::unique_ptr impl_; 49 | }; 50 | 51 | } // namespace medida 52 | 53 | #endif // MEDIDA_TIMER_H_ 54 | -------------------------------------------------------------------------------- /src/medida/timer_context.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 Daniel Lundin 3 | // 4 | 5 | #include "medida/timer_context.h" 6 | 7 | #include "medida/timer.h" 8 | #include "medida/types.h" 9 | 10 | namespace medida { 11 | 12 | class TimerContext::Impl { 13 | public: 14 | Impl(Timer& timer); 15 | ~Impl(); 16 | void Reset(); 17 | std::chrono::nanoseconds Stop(); 18 | private: 19 | Clock::time_point start_time_; 20 | Timer& timer_; 21 | bool active_; 22 | }; 23 | 24 | 25 | TimerContext::TimerContext(Timer& timer) 26 | : impl_ {new TimerContext::Impl {timer}} { 27 | } 28 | 29 | 30 | TimerContext::~TimerContext() { 31 | delete impl_; // FIXME: Why std::unique_ptr bork? 32 | } 33 | 34 | 35 | void TimerContext::Reset() { 36 | impl_->Reset(); 37 | } 38 | 39 | 40 | std::chrono::nanoseconds TimerContext::Stop() { 41 | return impl_->Stop(); 42 | } 43 | 44 | 45 | // === Implementation === 46 | 47 | 48 | TimerContext::Impl::Impl(Timer& timer) 49 | : timer_ (timer) { // FIXME: GCC Bug 50025 - Uniform initialization of reference members broken 50 | Reset(); 51 | } 52 | 53 | 54 | TimerContext::Impl::~Impl() { 55 | Stop(); 56 | } 57 | 58 | 59 | void TimerContext::Impl::Reset() { 60 | start_time_ = Clock::now(); 61 | active_ = true; 62 | } 63 | 64 | 65 | std::chrono::nanoseconds TimerContext::Impl::Stop() { 66 | if (active_) { 67 | auto dur = Clock::now() - start_time_; 68 | timer_.Update(dur); 69 | active_ = false; 70 | return dur; 71 | } 72 | return std::chrono::nanoseconds(0); 73 | } 74 | 75 | 76 | } // namespace medida -------------------------------------------------------------------------------- /src/medida/timer_context.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 Daniel Lundin 3 | // 4 | 5 | #ifndef MEDIDA_TIMER_CONTEXT_H_ 6 | #define MEDIDA_TIMER_CONTEXT_H_ 7 | 8 | #include 9 | #include 10 | 11 | namespace medida { 12 | 13 | class Timer; 14 | 15 | class TimerContext { 16 | public: 17 | TimerContext(Timer& timer); 18 | ~TimerContext(); 19 | void Reset(); 20 | std::chrono::nanoseconds Stop(); 21 | private: 22 | class Impl; 23 | Impl* impl_; 24 | // std::unique_ptr impl_; // FIXME: y u incomplete type?!? 25 | }; 26 | 27 | } // namespace medida 28 | 29 | #endif // MEDIDA_TIMER_CONTEXT_H_ 30 | -------------------------------------------------------------------------------- /src/medida/types.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 Daniel Lundin 3 | // 4 | 5 | #ifndef MEDIDA_TYPES_H_ 6 | #define MEDIDA_TYPES_H_ 7 | 8 | #include 9 | 10 | namespace medida { 11 | 12 | typedef std::chrono::high_resolution_clock Clock; 13 | 14 | } // namespace medida 15 | 16 | #endif // MEDIDA_TYPES_H_ 17 | -------------------------------------------------------------------------------- /test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Build gtest from source 2 | add_subdirectory (gtest-1.6.0) 3 | include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR}) 4 | 5 | set(test_sources 6 | test_counter.cc 7 | test_histogram.cc 8 | test_meter.cc 9 | test_metric_name.cc 10 | test_metrics_registry.cc 11 | test_timer.cc 12 | reporting/test_collectd_reporter.cc 13 | reporting/test_console_reporter.cc 14 | reporting/test_json_reporter.cc 15 | stats/test_ewma.cc 16 | stats/test_exp_decay_sample.cc 17 | stats/test_snapshot.cc 18 | stats/test_uniform_sample.cc 19 | ) 20 | 21 | add_executable(test-medida ${test_sources}) 22 | 23 | target_link_libraries(test-medida 24 | gtest 25 | gtest_main 26 | medida 27 | ) 28 | 29 | add_test(test-medida test-medida --gtest_output=xml) 30 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | -------------------------------------------------------------------------------- /test/gtest-1.6.0/COPYING: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | -------------------------------------------------------------------------------- /test/gtest-1.6.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.6.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([./COPYING]) 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 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | std::cout << "Running main() from gtest_main.cc\n"; 36 | 37 | testing::InitGoogleTest(&argc, argv); 38 | return RUN_ALL_TESTS(); 39 | } 40 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | # Generated from ltversion.in. 11 | 12 | # serial 3017 ltversion.m4 13 | # This file is part of GNU Libtool 14 | 15 | m4_define([LT_PACKAGE_VERSION], [2.2.6b]) 16 | m4_define([LT_PACKAGE_REVISION], [1.3017]) 17 | 18 | AC_DEFUN([LTVERSION_VERSION], 19 | [macro_version='2.2.6b' 20 | macro_revision='1.3017' 21 | _LT_DECL(, macro_version, 0, [Which release of libtool.m4 was used?]) 22 | _LT_DECL(, macro_revision, 0) 23 | ]) 24 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | 48 | // Clones a 0-terminated C string, allocating memory using new. 49 | static const char* CloneCString(const char* a_c_string); 50 | 51 | //////////////////////////////////////////////////////////// 52 | // 53 | // C'tors 54 | 55 | // The default c'tor constructs a NULL string. 56 | MyString() : c_string_(NULL) {} 57 | 58 | // Constructs a MyString by cloning a 0-terminated C string. 59 | explicit MyString(const char* a_c_string) : c_string_(NULL) { 60 | Set(a_c_string); 61 | } 62 | 63 | // Copy c'tor 64 | MyString(const MyString& string) : c_string_(NULL) { 65 | Set(string.c_string_); 66 | } 67 | 68 | //////////////////////////////////////////////////////////// 69 | // 70 | // D'tor. MyString is intended to be a final class, so the d'tor 71 | // doesn't need to be virtual. 72 | ~MyString() { delete[] c_string_; } 73 | 74 | // Gets the 0-terminated C string this MyString object represents. 75 | const char* c_string() const { return c_string_; } 76 | 77 | size_t Length() const { 78 | return c_string_ == NULL ? 0 : strlen(c_string_); 79 | } 80 | 81 | // Sets the 0-terminated C string this MyString object represents. 82 | void Set(const char* c_string); 83 | }; 84 | 85 | 86 | #endif // GTEST_SAMPLES_SAMPLE2_H_ 87 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | std::cout << "Running main() from gtest_main.cc\n"; 36 | 37 | testing::InitGoogleTest(&argc, argv); 38 | return RUN_ALL_TESTS(); 39 | } 40 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | // Test fixture for testing instantiation of a test in multiple 49 | // translation units. 50 | class InstantiationInMultipleTranslaionUnitsTest 51 | : public ::testing::TestWithParam {}; 52 | 53 | #endif // GTEST_HAS_PARAM_TEST 54 | 55 | #endif // GTEST_TEST_GTEST_PARAM_TEST_TEST_H_ 56 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | -------------------------------------------------------------------------------- /test/gtest-1.6.0/test/gtest_list_tests_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: phanna@google.com (Patrick Hanna) 31 | 32 | // Unit test for Google Test's --gtest_list_tests flag. 33 | // 34 | // A user can ask Google Test to list all tests that will run 35 | // so that when using a filter, a user will know what 36 | // tests to look for. The tests will not be run after listing. 37 | // 38 | // This program will be invoked from a Python unit test. 39 | // Don't run it directly. 40 | 41 | #include "gtest/gtest.h" 42 | 43 | namespace { 44 | 45 | // Several different test cases and tests that will be listed. 46 | TEST(Foo, Bar1) { 47 | } 48 | 49 | TEST(Foo, Bar2) { 50 | } 51 | 52 | TEST(Foo, DISABLED_Bar3) { 53 | } 54 | 55 | TEST(Abc, Xyz) { 56 | } 57 | 58 | TEST(Abc, Def) { 59 | } 60 | 61 | TEST(FooBar, Baz) { 62 | } 63 | 64 | class FooTest : public testing::Test { 65 | }; 66 | 67 | TEST_F(FooTest, Test1) { 68 | } 69 | 70 | TEST_F(FooTest, DISABLED_Test2) { 71 | } 72 | 73 | TEST_F(FooTest, Test3) { 74 | } 75 | 76 | TEST(FooDeathTest, Test1) { 77 | } 78 | 79 | } // namespace 80 | 81 | int main(int argc, char **argv) { 82 | ::testing::InitGoogleTest(&argc, argv); 83 | 84 | return RUN_ALL_TESTS(); 85 | } 86 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | 38 | int main(int argc, char **argv) { 39 | testing::InitGoogleTest(&argc, argv); 40 | 41 | // An ad-hoc assertion outside of all tests. 42 | // 43 | // This serves three purposes: 44 | // 45 | // 1. It verifies that an ad-hoc assertion can be executed even if 46 | // no test is defined. 47 | // 2. It verifies that a failed ad-hoc assertion causes the test 48 | // program to fail. 49 | // 3. We had a bug where the XML output won't be generated if an 50 | // assertion is executed before RUN_ALL_TESTS() is called, even 51 | // though --gtest_output=xml is specified. This makes sure the 52 | // bug is fixed and doesn't regress. 53 | EXPECT_EQ(1, 2); 54 | 55 | // The above EXPECT_EQ() should cause RUN_ALL_TESTS() to return non-zero. 56 | return RUN_ALL_TESTS() ? 0 : 1; 57 | } 58 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | -------------------------------------------------------------------------------- /test/gtest-1.6.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::String; 46 | using ::testing::internal::scoped_ptr; 47 | 48 | // The test methods are empty, as the sole purpose of this program is 49 | // to print the test names before/after shuffling. 50 | 51 | class A : public Test {}; 52 | TEST_F(A, A) {} 53 | TEST_F(A, B) {} 54 | 55 | TEST(ADeathTest, A) {} 56 | TEST(ADeathTest, B) {} 57 | TEST(ADeathTest, C) {} 58 | 59 | TEST(B, A) {} 60 | TEST(B, B) {} 61 | TEST(B, C) {} 62 | TEST(B, DISABLED_D) {} 63 | TEST(B, DISABLED_E) {} 64 | 65 | TEST(BDeathTest, A) {} 66 | TEST(BDeathTest, B) {} 67 | 68 | TEST(C, A) {} 69 | TEST(C, B) {} 70 | TEST(C, C) {} 71 | TEST(C, DISABLED_D) {} 72 | 73 | TEST(CDeathTest, A) {} 74 | 75 | TEST(DISABLED_D, A) {} 76 | TEST(DISABLED_D, DISABLED_B) {} 77 | 78 | // This printer prints the full test names only, starting each test 79 | // iteration with a "----" marker. 80 | class TestNamePrinter : public EmptyTestEventListener { 81 | public: 82 | virtual void OnTestIterationStart(const UnitTest& /* unit_test */, 83 | int /* iteration */) { 84 | printf("----\n"); 85 | } 86 | 87 | virtual void OnTestStart(const TestInfo& test_info) { 88 | printf("%s.%s\n", test_info.test_case_name(), test_info.name()); 89 | } 90 | }; 91 | 92 | } // namespace 93 | 94 | int main(int argc, char **argv) { 95 | InitGoogleTest(&argc, argv); 96 | 97 | // Replaces the default printer with TestNamePrinter, which prints 98 | // the test name only. 99 | TestEventListeners& listeners = UnitTest::GetInstance()->listeners(); 100 | delete listeners.Release(listeners.default_result_printer()); 101 | listeners.Append(new TestNamePrinter); 102 | 103 | return RUN_ALL_TESTS(); 104 | } 105 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | int main(int argc, char** argv) { 41 | testing::InitGoogleTest(&argc, argv); 42 | 43 | // We want to ensure that people can use Google Test assertions in 44 | // other testing frameworks, as long as they initialize Google Test 45 | // properly and set the thrown-on-failure mode. Therefore, we don't 46 | // use Google Test's constructs for defining and running tests 47 | // (e.g. TEST and RUN_ALL_TESTS) here. 48 | 49 | // In the throw-on-failure mode with exceptions disabled, this 50 | // assertion will cause the program to exit with a non-zero code. 51 | EXPECT_EQ(2, 3); 52 | 53 | // When not in the throw-on-failure mode, the control will reach 54 | // here. 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | -------------------------------------------------------------------------------- /test/gtest-1.6.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 | -------------------------------------------------------------------------------- /test/reporting/test_collectd_reporter.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 Daniel Lundin 3 | // 4 | 5 | #include "medida/reporting/collectd_reporter.h" 6 | 7 | #include 8 | 9 | #include 10 | 11 | #include "medida/metrics_registry.h" 12 | 13 | using namespace medida; 14 | using namespace medida::reporting; 15 | 16 | 17 | TEST(CollectdReporterTest, foo) { 18 | MetricsRegistry registry {}; 19 | auto& counter = registry.NewCounter({"test", "console_reporter", "mycounter"}); 20 | auto& histogram = registry.NewHistogram({"test", "console_reporter", "myhistogram"}); 21 | auto& meter = registry.NewMeter({"test", "console_reporter", "mymeter"}, "cycles"); 22 | auto& timer = registry.NewTimer({"test", "console_reporter", "mytimer"}); 23 | CollectdReporter reporter {registry, "localhost", 25826}; 24 | for (auto i = 1; i <= 100; i++) { 25 | auto t = timer.TimeScope(); 26 | counter.inc(); 27 | histogram.Update(i); 28 | meter.Mark(); 29 | std::this_thread::sleep_for(std::chrono::milliseconds(5)); 30 | } 31 | reporter.Run(); 32 | } 33 | 34 | 35 | -------------------------------------------------------------------------------- /test/reporting/test_console_reporter.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 Daniel Lundin 3 | // 4 | 5 | #include "medida/reporting/console_reporter.h" 6 | 7 | #include 8 | 9 | #include 10 | 11 | #include "medida/metrics_registry.h" 12 | 13 | using namespace medida; 14 | using namespace medida::reporting; 15 | 16 | 17 | TEST(ConsoleReporterTest, foo) { 18 | MetricsRegistry registry {}; 19 | auto& counter = registry.NewCounter({"test", "console_reporter", "counter"}); 20 | auto& histogram = registry.NewHistogram({"test", "console_reporter", "histogram"}); 21 | auto& meter = registry.NewMeter({"test", "console_reporter", "meter"}, "cycles"); 22 | auto& timer = registry.NewTimer({"test", "console_reporter", "timer"}); 23 | ConsoleReporter reporter {registry}; 24 | counter.inc(); 25 | for (auto i = 1; i <= 1000; i++) { 26 | auto t = timer.TimeScope(); 27 | histogram.Update(i); 28 | meter.Mark(); 29 | } 30 | reporter.Start(std::chrono::milliseconds(300)); 31 | std::this_thread::sleep_for(std::chrono::milliseconds(400)); 32 | } 33 | 34 | 35 | -------------------------------------------------------------------------------- /test/reporting/test_json_reporter.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 Daniel Lundin 3 | // 4 | 5 | #include "medida/reporting/json_reporter.h" 6 | 7 | #include 8 | 9 | #include "medida/metrics_registry.h" 10 | 11 | using namespace medida; 12 | using namespace medida::reporting; 13 | 14 | 15 | TEST(JsonReporterTest, foo) { 16 | MetricsRegistry registry {}; 17 | auto& counter = registry.NewCounter({"test", "console_reporter", "counter"}); 18 | auto& histogram = registry.NewHistogram({"test", "console_reporter", "histogram"}); 19 | auto& meter = registry.NewMeter({"test", "console_reporter", "meter"}, "cycles"); 20 | auto& timer = registry.NewTimer({"test", "console_reporter", "timer"}); 21 | JsonReporter reporter {registry}; 22 | counter.inc(); 23 | for (auto i = 1; i <= 1000; i++) { 24 | auto t = timer.TimeScope(); 25 | histogram.Update(i); 26 | meter.Mark(); 27 | } 28 | auto json = reporter.Report(); 29 | std::cerr << json << std::endl; 30 | } 31 | 32 | 33 | -------------------------------------------------------------------------------- /test/stats/test_exp_decay_sample.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 Daniel Lundin 3 | // 4 | 5 | #include "medida/stats/exp_decay_sample.h" 6 | 7 | #include 8 | 9 | using namespace medida::stats; 10 | 11 | TEST(ExpDecaySampleTest, aSampleOf100OutOf1000Elements) { 12 | ExpDecaySample sample {100, 0.99}; 13 | EXPECT_EQ(0, sample.size()); 14 | 15 | auto t = medida::Clock::now(); 16 | 17 | for (auto i = 0; i < 1000; i++) { 18 | sample.Update(i, t); 19 | t += std::chrono::microseconds(1); 20 | } 21 | EXPECT_EQ(100, sample.size()); 22 | 23 | auto snapshot = sample.MakeSnapshot(); 24 | EXPECT_EQ(100, snapshot.size()); 25 | 26 | for (auto& v : snapshot.getValues()) { 27 | EXPECT_LT(v, 1000.0); 28 | EXPECT_GE(v, 0.0); 29 | } 30 | } 31 | 32 | 33 | TEST(ExpDecaySampleTest, aSampleOf10OutOf1000Elements) { 34 | ExpDecaySample sample {100, 0.99}; 35 | EXPECT_EQ(0, sample.size()); 36 | 37 | for (auto i = 0; i < 10; i++) { 38 | sample.Update(i); 39 | } 40 | EXPECT_EQ(10, sample.size()); 41 | 42 | auto snapshot = sample.MakeSnapshot(); 43 | EXPECT_EQ(10, snapshot.size()); 44 | 45 | for (auto& v : snapshot.getValues()) { 46 | EXPECT_LT(v, 10.0); 47 | EXPECT_GE(v, 0.0); 48 | } 49 | } 50 | 51 | 52 | TEST(ExpDecaySampleTest, aHeavilyBiasedSampleOf100OutOf1000Elements) { 53 | ExpDecaySample sample {1000, 0.01}; 54 | 55 | for (auto i = 0; i < 100; i++) { 56 | sample.Update(i); 57 | } 58 | EXPECT_EQ(100, sample.size()); 59 | 60 | auto snapshot = sample.MakeSnapshot(); 61 | EXPECT_EQ(100, snapshot.size()); 62 | 63 | for (auto& v : snapshot.getValues()) { 64 | EXPECT_LT(v, 100.0); 65 | EXPECT_GE(v, 0.0); 66 | } 67 | } 68 | 69 | 70 | TEST(ExpDecaySampleTest, longPeriodsOfInactivityShouldNotCorruptSamplingState) { 71 | ExpDecaySample sample {10, 0.015}; 72 | auto t = medida::Clock::now(); 73 | 74 | for (auto i = 0; i < 1000; i++) { 75 | sample.Update(1000 + i, t); 76 | t += std::chrono::milliseconds(100); 77 | } 78 | EXPECT_EQ(10, sample.size()); 79 | 80 | for (auto& v : sample.MakeSnapshot().getValues()) { 81 | EXPECT_LT(v, 2000.0); 82 | EXPECT_GE(v, 1000.0); 83 | } 84 | 85 | // wait for 15 hours and add another value. 86 | // this should trigger a rescale. Note that the number of samples will be reduced to 2 87 | // because of the very small scaling factor that will make all existing priorities equal to 88 | // zero after rescale. 89 | t += std::chrono::hours(15); 90 | sample.Update(2000, t); 91 | EXPECT_EQ(2, sample.size()); 92 | 93 | for (auto& v : sample.MakeSnapshot().getValues()) { 94 | EXPECT_LT(v, 3000.0); 95 | EXPECT_GE(v, 1000.0); 96 | } 97 | 98 | 99 | // add 1000 values at a rate of 10 values/second 100 | for (auto i = 0; i < 1000; i++) { 101 | sample.Update(3000 + i, t); 102 | t += std::chrono::milliseconds(100); 103 | } 104 | EXPECT_EQ(10, sample.size()); 105 | 106 | for (auto& v : sample.MakeSnapshot().getValues()) { 107 | EXPECT_LE(v, 4000.0); 108 | EXPECT_GE(v, 3000.0); 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /test/stats/test_snapshot.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 Daniel Lundin 3 | // 4 | 5 | #include "medida/stats/snapshot.h" 6 | 7 | #include 8 | 9 | using namespace medida::stats; 10 | 11 | struct SnapshotTest : public ::testing::Test { 12 | SnapshotTest() 13 | : values {5, 1, 2, 3, 4}, 14 | snapshot {values} { 15 | }; 16 | const std::vector values; 17 | const Snapshot snapshot; 18 | }; 19 | 20 | 21 | TEST_F(SnapshotTest, smallQuantilesAreTheFirstValue) { 22 | EXPECT_DOUBLE_EQ(1, snapshot.getValue(0.0)); 23 | } 24 | 25 | 26 | TEST_F(SnapshotTest, bigQuantilesAreTheLastValue) { 27 | EXPECT_DOUBLE_EQ(5, snapshot.getValue(1.0)); 28 | } 29 | 30 | 31 | TEST_F(SnapshotTest, hasAMedian) { 32 | EXPECT_DOUBLE_EQ(3, snapshot.getMedian()); 33 | } 34 | 35 | 36 | TEST_F(SnapshotTest, hasAp75) { 37 | EXPECT_DOUBLE_EQ(4.5, snapshot.get75thPercentile()); 38 | } 39 | 40 | 41 | TEST_F(SnapshotTest, hasAp95) { 42 | EXPECT_DOUBLE_EQ(5.0, snapshot.get95thPercentile()); 43 | } 44 | 45 | 46 | TEST_F(SnapshotTest, hasAp98) { 47 | EXPECT_DOUBLE_EQ(5.0, snapshot.get98thPercentile()); 48 | } 49 | 50 | 51 | TEST_F(SnapshotTest, hasAp99) { 52 | EXPECT_DOUBLE_EQ(5.0, snapshot.get99thPercentile()); 53 | } 54 | 55 | 56 | TEST_F(SnapshotTest, hasAp999) { 57 | EXPECT_DOUBLE_EQ(5.0, snapshot.get999thPercentile()); 58 | } 59 | 60 | 61 | TEST_F(SnapshotTest, hasValues) { 62 | auto ref = {1, 2, 3, 4, 5}; 63 | EXPECT_TRUE(std::equal(ref.begin(), ref.end(), snapshot.getValues().begin())); 64 | } 65 | 66 | 67 | TEST_F(SnapshotTest, hasASize) { 68 | EXPECT_EQ(5, snapshot.size()); 69 | } 70 | -------------------------------------------------------------------------------- /test/stats/test_uniform_sample.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 Daniel Lundin 3 | // 4 | 5 | 6 | #include "medida/stats/uniform_sample.h" 7 | 8 | #include 9 | 10 | using namespace medida::stats; 11 | 12 | TEST(UniformSampleTest, aSampleOf100OutOf1000Elements) { 13 | UniformSample sample {100}; 14 | 15 | for (auto i = 0; i < 1000; i++) { 16 | sample.Update(i); 17 | } 18 | 19 | EXPECT_EQ(100, sample.size()); 20 | 21 | auto vals = sample.MakeSnapshot().getValues(); 22 | EXPECT_EQ(100, vals.size()); 23 | 24 | for (auto& v : vals) { 25 | EXPECT_LT(v, 1000.0); 26 | EXPECT_GE(v, 0.0); 27 | } 28 | } 29 | 30 | 31 | TEST(UniformSampleTest, clear) { 32 | UniformSample sample {100}; 33 | for (auto i = 0; i < 10; i++) { 34 | sample.Update(i); 35 | } 36 | 37 | EXPECT_EQ(10, sample.size()); 38 | 39 | sample.Clear(); 40 | 41 | EXPECT_EQ(0, sample.size()); 42 | } 43 | -------------------------------------------------------------------------------- /test/test_counter.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 Daniel Lundin 3 | // 4 | 5 | #include "medida/counter.h" 6 | 7 | #include 8 | 9 | using namespace medida; 10 | 11 | struct CounterTest : public ::testing::Test { 12 | Counter counter; 13 | }; 14 | 15 | 16 | TEST_F(CounterTest, startsAtZero) { 17 | EXPECT_EQ(0, counter.count()); 18 | } 19 | 20 | 21 | TEST_F(CounterTest, initValue) { 22 | Counter c = {42}; 23 | EXPECT_EQ(42, c.count()); 24 | } 25 | 26 | 27 | TEST_F(CounterTest, incrementsByOne) { 28 | counter.inc(); 29 | EXPECT_EQ(1, counter.count()); 30 | } 31 | 32 | 33 | TEST_F(CounterTest, incrementsByAnArbitraryDelta) { 34 | counter.inc(42); 35 | EXPECT_EQ(42, counter.count()); 36 | } 37 | 38 | 39 | TEST_F(CounterTest, incrementsByAnArbitraryNegativeDelta) { 40 | counter.inc(-42); 41 | EXPECT_EQ(-42, counter.count()); 42 | } 43 | 44 | 45 | TEST_F(CounterTest, decrementsByOne) { 46 | counter.dec(); 47 | EXPECT_EQ(-1, counter.count()); 48 | } 49 | 50 | 51 | TEST_F(CounterTest, decrementsByAnArbitraryDelta) { 52 | counter.dec(42); 53 | EXPECT_EQ(-42, counter.count()); 54 | } 55 | 56 | 57 | TEST_F(CounterTest, decrementsByAnArbitraryNegativeDelta) { 58 | counter.dec(-42); 59 | EXPECT_EQ(42, counter.count()); 60 | } 61 | 62 | 63 | TEST_F(CounterTest, isZeroAfterBeingCleared) { 64 | counter.dec(4); 65 | counter.clear(); 66 | EXPECT_EQ(0, counter.count()); 67 | } 68 | -------------------------------------------------------------------------------- /test/test_histogram.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 Daniel Lundin 3 | // 4 | 5 | #include "medida/histogram.h" 6 | 7 | #include 8 | 9 | #include "medida/metrics_registry.h" 10 | 11 | using namespace medida; 12 | 13 | TEST(HistogramTest, anEmptyHistogram) { 14 | MetricsRegistry registry {}; 15 | auto& histogram = registry.NewHistogram({"a", "b", "c"}); 16 | 17 | EXPECT_EQ(0, histogram.count()); 18 | EXPECT_EQ(0.0, histogram.max()); 19 | EXPECT_EQ(0.0, histogram.min()); 20 | EXPECT_EQ(0.0, histogram.mean()); 21 | EXPECT_EQ(0.0, histogram.std_dev()); 22 | EXPECT_EQ(0.0, histogram.sum()); 23 | 24 | auto snapshot = histogram.GetSnapshot(); 25 | EXPECT_EQ(0.0, snapshot.getMedian()); 26 | EXPECT_EQ(0.0, snapshot.get75thPercentile()); 27 | EXPECT_EQ(0.0, snapshot.get99thPercentile()); 28 | EXPECT_EQ(0, snapshot.size()); 29 | } 30 | 31 | 32 | TEST(HistogramTest, aHistogramWith1000Elements) { 33 | MetricsRegistry registry {}; 34 | auto& histogram = registry.NewHistogram({"a", "b", "c"}); 35 | 36 | for (auto i = 1; i <= 1000; i++) { 37 | histogram.Update(i); 38 | } 39 | 40 | EXPECT_EQ(1000, histogram.count()); 41 | EXPECT_NEAR(1000.0, histogram.max(), 0.001); 42 | EXPECT_NEAR(1.0, histogram.min(), 0.001); 43 | EXPECT_NEAR(500.5, histogram.mean(), 0.001); 44 | EXPECT_NEAR(288.8194360957494, histogram.std_dev(), 0.001); 45 | EXPECT_NEAR(500500, histogram.sum(), 0.1); 46 | 47 | auto snapshot = histogram.GetSnapshot(); 48 | EXPECT_NEAR(500.5, snapshot.getMedian(), 0.0001); 49 | EXPECT_NEAR(750.75, snapshot.get75thPercentile(), 0.0001); 50 | EXPECT_NEAR(990.99, snapshot.get99thPercentile(), 0.0001); 51 | EXPECT_EQ(1000, snapshot.size()); 52 | } 53 | -------------------------------------------------------------------------------- /test/test_meter.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 Daniel Lundin 3 | // 4 | 5 | #include "medida/meter.h" 6 | 7 | #include 8 | 9 | #include 10 | 11 | #include "medida/metrics_registry.h" 12 | 13 | using namespace medida; 14 | 15 | 16 | TEST(MeterTest, aBlankMeter) { 17 | Meter meter {"things"}; 18 | EXPECT_EQ("things", meter.event_type()); 19 | EXPECT_EQ(0, meter.count()); 20 | EXPECT_NEAR(0.0, meter.mean_rate(), 0.001); 21 | } 22 | 23 | 24 | TEST(MeterTest, createFromRegistry) { 25 | MetricsRegistry registry {}; 26 | auto& meter = registry.NewMeter({"a", "b", "c"}, "things"); 27 | EXPECT_EQ(0, meter.count()); 28 | EXPECT_EQ("things", meter.event_type()); 29 | } 30 | 31 | 32 | TEST(MeterTest, aMeterWithThreeEvents) { 33 | Meter meter {"things"}; 34 | meter.Mark(3); 35 | EXPECT_EQ(3, meter.count()); 36 | } 37 | 38 | 39 | TEST(MeterTest, meterTiming) { 40 | Meter meter {"things"}; 41 | for (auto i = 0; i < 10; i++) { 42 | meter.Mark(); 43 | std::this_thread::sleep_for(std::chrono::milliseconds(100)); 44 | } 45 | EXPECT_EQ(10, meter.count()); 46 | EXPECT_NEAR(10, meter.mean_rate(), 0.1); 47 | } 48 | 49 | -------------------------------------------------------------------------------- /test/test_metric_name.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 Daniel Lundin 3 | // 4 | 5 | #include "medida/metric_name.h" 6 | 7 | #include 8 | 9 | using namespace medida; 10 | 11 | struct MetricNameTest : public ::testing::Test { 12 | MetricNameTest() : name {"domain", "type", "name", "scope"} {}; 13 | MetricName name; 14 | }; 15 | 16 | 17 | TEST_F(MetricNameTest, hasADomain) { 18 | EXPECT_EQ("domain", name.domain()); 19 | } 20 | 21 | 22 | TEST_F(MetricNameTest, hasAType) { 23 | EXPECT_EQ("type", name.type()); 24 | } 25 | 26 | 27 | TEST_F(MetricNameTest, hasAName) { 28 | EXPECT_EQ("name", name.name()); 29 | } 30 | 31 | 32 | TEST_F(MetricNameTest, hasAScope) { 33 | EXPECT_EQ("scope", name.scope()); 34 | EXPECT_TRUE(name.has_scope()); 35 | } 36 | 37 | 38 | TEST_F(MetricNameTest, isHumanReadable) { 39 | EXPECT_EQ("domain.type.name.scope", name.ToString()); 40 | } 41 | 42 | 43 | TEST_F(MetricNameTest, hasAWorkingEquals) { 44 | EXPECT_EQ(name, name); 45 | EXPECT_EQ(MetricName("domain", "type", "name", "scope"), name); 46 | EXPECT_NE(MetricName("domain", "type", "name"), name); 47 | } 48 | 49 | 50 | TEST_F(MetricNameTest, hasAWorkingLessThan) { 51 | EXPECT_FALSE(MetricName("a", "a", "a") < MetricName("a", "a", "a")); 52 | 53 | EXPECT_FALSE(MetricName("a", "a", "b") < MetricName("a", "a", "a")); 54 | EXPECT_FALSE(MetricName("a", "b", "a") < MetricName("a", "a", "a")); 55 | EXPECT_FALSE(MetricName("b", "a", "b") < MetricName("a", "a", "a")); 56 | EXPECT_FALSE(MetricName("a", "a", "a", "a") < MetricName("a", "a", "a")); 57 | 58 | EXPECT_TRUE(MetricName("a", "a", "a") < MetricName("b", "a", "a")); 59 | EXPECT_TRUE(MetricName("a", "a", "a") < MetricName("a", "b", "a")); 60 | EXPECT_TRUE(MetricName("a", "a", "a") < MetricName("a", "a", "b")); 61 | EXPECT_TRUE(MetricName("a", "a", "a") < MetricName("a", "a", "a", "a")); 62 | } 63 | 64 | 65 | TEST_F(MetricNameTest, hasAWorkingGreaterThan) { 66 | EXPECT_FALSE(MetricName("a", "a", "a") > MetricName("a", "a", "a")); 67 | 68 | EXPECT_TRUE(MetricName("a", "a", "b") > MetricName("a", "a", "a")); 69 | EXPECT_TRUE(MetricName("a", "b", "a") > MetricName("a", "a", "a")); 70 | EXPECT_TRUE(MetricName("b", "a", "b") > MetricName("a", "a", "a")); 71 | EXPECT_TRUE(MetricName("a", "a", "a", "a") > MetricName("a", "a", "a")); 72 | 73 | EXPECT_FALSE(MetricName("a", "a", "a") > MetricName("b", "a", "a")); 74 | EXPECT_FALSE(MetricName("a", "a", "a") > MetricName("a", "b", "a")); 75 | EXPECT_FALSE(MetricName("a", "a", "a") > MetricName("a", "a", "b")); 76 | EXPECT_FALSE(MetricName("a", "a", "a") > MetricName("a", "a", "a", "a")); 77 | } 78 | -------------------------------------------------------------------------------- /test/test_metrics_registry.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 Daniel Lundin 3 | // 4 | 5 | #include "medida/metrics_registry.h" 6 | 7 | #include 8 | 9 | using namespace medida; 10 | 11 | struct MetricsRegistryTest : public ::testing::Test { 12 | MetricsRegistry registry; 13 | }; 14 | 15 | 16 | TEST_F(MetricsRegistryTest, keysByName) { 17 | auto& abc = registry.NewCounter({"a", "b", "c"}); 18 | auto& abc2 = registry.NewCounter({"a", "b", "c"}); 19 | auto& abcd = registry.NewCounter({"a", "b", "c", "d"}); 20 | EXPECT_EQ(0, abc.count()) << "Counter a.b.c was not initialied to 0"; 21 | EXPECT_EQ(&abc, &abc2) << "Counter a.b.c was created twice"; 22 | EXPECT_NE(&abc, &abcd) << "Counter a.b.c and a.b.c.d are the same object"; 23 | } 24 | -------------------------------------------------------------------------------- /test/test_timer.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2012 Daniel Lundin 3 | // 4 | 5 | #include "medida/timer.h" 6 | 7 | #include 8 | #include 9 | 10 | #include 11 | 12 | #include "medida/metrics_registry.h" 13 | 14 | using namespace medida; 15 | 16 | 17 | struct TimerTest : public ::testing::Test { 18 | Timer timer; 19 | }; 20 | 21 | 22 | TEST_F(TimerTest, hasDurationUnit) { 23 | EXPECT_EQ(std::chrono::milliseconds(1), timer.duration_unit()); 24 | } 25 | 26 | 27 | TEST_F(TimerTest, hasRateUnit) { 28 | EXPECT_EQ(std::chrono::seconds(1), timer.rate_unit()); 29 | } 30 | 31 | 32 | TEST_F(TimerTest, createFromRegistry) { 33 | MetricsRegistry registry {}; 34 | auto& timer2 = registry.NewTimer({"a", "b", "c"}); 35 | EXPECT_EQ(0, timer2.count()); 36 | } 37 | 38 | 39 | TEST_F(TimerTest, aBlankTimer) { 40 | EXPECT_EQ(0, timer.count()); 41 | EXPECT_NEAR(0.0, timer.min(), 0.001); 42 | EXPECT_NEAR(0.0, timer.max(), 0.001); 43 | EXPECT_NEAR(0.0, timer.mean(), 0.001); 44 | EXPECT_NEAR(0.0, timer.std_dev(), 0.001); 45 | EXPECT_NEAR(0.0, timer.mean_rate(), 0.001); 46 | EXPECT_NEAR(0.0, timer.one_minute_rate(), 0.001); 47 | EXPECT_NEAR(0.0, timer.five_minute_rate(), 0.001); 48 | EXPECT_NEAR(0.0, timer.fifteen_minute_rate(), 0.001); 49 | 50 | auto snapshot = timer.GetSnapshot(); 51 | EXPECT_NEAR(0.0, snapshot.getMedian(), 0.001); 52 | EXPECT_NEAR(0.0, snapshot.get75thPercentile(), 0.001); 53 | EXPECT_NEAR(0.0, snapshot.get99thPercentile(), 0.001); 54 | EXPECT_EQ(0, snapshot.size()); 55 | } 56 | 57 | 58 | TEST_F(TimerTest, timingASeriesOfEvents) { 59 | timer.Update(std::chrono::milliseconds(10)); 60 | timer.Update(std::chrono::milliseconds(20)); 61 | timer.Update(std::chrono::milliseconds(20)); 62 | timer.Update(std::chrono::milliseconds(30)); 63 | timer.Update(std::chrono::milliseconds(40)); 64 | 65 | EXPECT_EQ(5, timer.count()); 66 | EXPECT_NEAR(10.0, timer.min(), 0.001); 67 | EXPECT_NEAR(40.0, timer.max(), 0.001); 68 | EXPECT_NEAR(24.0, timer.mean(), 0.001); 69 | EXPECT_NEAR(11.401, timer.std_dev(), 0.001); 70 | 71 | auto snapshot = timer.GetSnapshot(); 72 | EXPECT_NEAR(20.0, snapshot.getMedian(), 0.001); 73 | EXPECT_NEAR(35.0, snapshot.get75thPercentile(), 0.001); 74 | EXPECT_NEAR(40.0, snapshot.get99thPercentile(), 0.001); 75 | EXPECT_EQ(5, snapshot.size()); 76 | } 77 | 78 | 79 | TEST_F(TimerTest, timingVariantValues) { 80 | timer.Update(std::chrono::nanoseconds(9223372036854775807)); // INT64_MAX 81 | timer.Update(std::chrono::nanoseconds(0)); 82 | EXPECT_NEAR(6.521908912666392E12, timer.std_dev(), 0.001); 83 | } 84 | 85 | 86 | TEST_F(TimerTest, timerTimeScope) { 87 | { 88 | auto t = timer.TimeScope(); 89 | std::this_thread::sleep_for(std::chrono::milliseconds(100)); 90 | } 91 | { 92 | auto t = timer.TimeScope(); 93 | std::this_thread::sleep_for(std::chrono::milliseconds(200)); 94 | } 95 | EXPECT_EQ(2, timer.count()); 96 | EXPECT_NEAR(150.0, timer.mean(), 0.5); 97 | } 98 | 99 | 100 | void my_func() { 101 | std::this_thread::sleep_for(std::chrono::milliseconds(100)); 102 | } 103 | 104 | 105 | TEST_F(TimerTest, timerTimeFunction) { 106 | timer.Time(my_func); 107 | EXPECT_EQ(1, timer.count()); 108 | EXPECT_NEAR(100.0, timer.mean(), 0.5); 109 | } 110 | 111 | 112 | TEST_F(TimerTest, timerTimeLambda) { 113 | timer.Time([]() { 114 | std::this_thread::sleep_for(std::chrono::milliseconds(100)); 115 | }); 116 | EXPECT_EQ(1, timer.count()); 117 | EXPECT_NEAR(100.0, timer.mean(), 1.0); 118 | } 119 | --------------------------------------------------------------------------------