libcouchbase 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.gitmodules +3 -0
- data/.rspec +1 -0
- data/.travis.yml +35 -0
- data/Gemfile +4 -0
- data/LICENSE +24 -0
- data/README.md +389 -0
- data/Rakefile +75 -0
- data/ext/README.md +6 -0
- data/ext/Rakefile +20 -0
- data/ext/libcouchbase/.gitignore +130 -0
- data/ext/libcouchbase/.travis.yml +19 -0
- data/ext/libcouchbase/CMakeLists.txt +429 -0
- data/ext/libcouchbase/CONTRIBUTING.md +124 -0
- data/ext/libcouchbase/LICENSE +202 -0
- data/ext/libcouchbase/README.markdown +163 -0
- data/ext/libcouchbase/RELEASE_NOTES.markdown +2691 -0
- data/ext/libcouchbase/cmake/Modules/ConfigureDtrace.cmake +27 -0
- data/ext/libcouchbase/cmake/Modules/CopyPDB.cmake +42 -0
- data/ext/libcouchbase/cmake/Modules/DistScript.cmake +17 -0
- data/ext/libcouchbase/cmake/Modules/DownloadLcbDep.cmake +20 -0
- data/ext/libcouchbase/cmake/Modules/FindCouchbaseHdrHistogram.cmake +15 -0
- data/ext/libcouchbase/cmake/Modules/FindCouchbaseLibev.cmake +73 -0
- data/ext/libcouchbase/cmake/Modules/FindCouchbaseLibevent.cmake +52 -0
- data/ext/libcouchbase/cmake/Modules/FindCouchbaseLibuv.cmake +56 -0
- data/ext/libcouchbase/cmake/Modules/FindCouchbaseSnappy.cmake +11 -0
- data/ext/libcouchbase/cmake/Modules/GenerateConfigDotH.cmake +29 -0
- data/ext/libcouchbase/cmake/Modules/GetLibcouchbaseFlags.cmake +133 -0
- data/ext/libcouchbase/cmake/Modules/GetPlatformCCInfo.cmake +45 -0
- data/ext/libcouchbase/cmake/Modules/GetVersionInfo.cmake +70 -0
- data/ext/libcouchbase/cmake/config-cmake.h.in +60 -0
- data/ext/libcouchbase/cmake/configure +357 -0
- data/ext/libcouchbase/cmake/defs.mk.in +8 -0
- data/ext/libcouchbase/cmake/dtrace-instr-link.pl +38 -0
- data/ext/libcouchbase/cmake/source_files.cmake +73 -0
- data/ext/libcouchbase/configure.pl +1 -0
- data/ext/libcouchbase/contrib/cJSON/cJSON.c +624 -0
- data/ext/libcouchbase/contrib/cJSON/cJSON.h +158 -0
- data/ext/libcouchbase/contrib/cbsasl/CMakeLists.txt +9 -0
- data/ext/libcouchbase/contrib/cbsasl/COPYING +202 -0
- data/ext/libcouchbase/contrib/cbsasl/include/cbsasl/cbsasl.h +217 -0
- data/ext/libcouchbase/contrib/cbsasl/src/client.c +205 -0
- data/ext/libcouchbase/contrib/cbsasl/src/common.c +46 -0
- data/ext/libcouchbase/contrib/cbsasl/src/cram-md5/hmac.c +67 -0
- data/ext/libcouchbase/contrib/cbsasl/src/cram-md5/hmac.h +33 -0
- data/ext/libcouchbase/contrib/cbsasl/src/cram-md5/md5.c +296 -0
- data/ext/libcouchbase/contrib/cbsasl/src/cram-md5/md5.h +45 -0
- data/ext/libcouchbase/contrib/cbsasl/src/hash.c +573 -0
- data/ext/libcouchbase/contrib/cbsasl/src/hash.h +15 -0
- data/ext/libcouchbase/contrib/cbsasl/src/util.h +31 -0
- data/ext/libcouchbase/contrib/cliopts/CMakeLists.txt +2 -0
- data/ext/libcouchbase/contrib/cliopts/cliopts.c +747 -0
- data/ext/libcouchbase/contrib/cliopts/cliopts.h +493 -0
- data/ext/libcouchbase/contrib/genhash/genhash.c +372 -0
- data/ext/libcouchbase/contrib/genhash/genhash.h +235 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/CHANGES +157 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/CMakeLists.txt +252 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/CONTRIBUTORS +37 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/LICENSE +28 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/MINIFY.sh +15 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/README +435 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/cmake/internal_utils.cmake +227 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest-death-test.h +294 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest-message.h +250 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest-param-test.h +1421 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest-param-test.h.pump +487 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest-printers.h +855 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest-spi.h +232 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest-test-part.h +179 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest-typed-test.h +259 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest.h +2291 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest_pred_impl.h +358 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest_prod.h +58 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-death-test-internal.h +319 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-filepath.h +206 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-internal.h +1158 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-linked_ptr.h +233 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-param-util-generated.h +5143 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-param-util-generated.h.pump +301 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-param-util.h +619 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-port.h +1947 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-string.h +167 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-tuple.h +1012 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-tuple.h.pump +339 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-type-util.h +3331 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-type-util.h.pump +297 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest-all.cc +48 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest-death-test.cc +1344 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest-filepath.cc +382 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest-internal-inl.h +1218 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest-port.cc +805 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest-printers.cc +363 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest-test-part.cc +110 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest-typed-test.cc +110 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest.cc +5015 -0
- data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest_main.cc +38 -0
- data/ext/libcouchbase/contrib/http_parser/LICENSE-MIT +23 -0
- data/ext/libcouchbase/contrib/http_parser/README.md +178 -0
- data/ext/libcouchbase/contrib/http_parser/http_parser.c +2060 -0
- data/ext/libcouchbase/contrib/http_parser/http_parser.h +321 -0
- data/ext/libcouchbase/contrib/jsonsl/LICENSE +20 -0
- data/ext/libcouchbase/contrib/jsonsl/jsonsl.c +1452 -0
- data/ext/libcouchbase/contrib/jsonsl/jsonsl.h +971 -0
- data/ext/libcouchbase/contrib/lcb-jsoncpp/CMakeLists.txt +6 -0
- data/ext/libcouchbase/contrib/lcb-jsoncpp/LICENSE +55 -0
- data/ext/libcouchbase/contrib/lcb-jsoncpp/lcb-jsoncpp-forwards.h +255 -0
- data/ext/libcouchbase/contrib/lcb-jsoncpp/lcb-jsoncpp.cpp +4892 -0
- data/ext/libcouchbase/contrib/lcb-jsoncpp/lcb-jsoncpp.h +1961 -0
- data/ext/libcouchbase/contrib/snappy/CMakeLists.txt +8 -0
- data/ext/libcouchbase/contrib/snappy/COPYING +28 -0
- data/ext/libcouchbase/contrib/snappy/snappy-c.cc +90 -0
- data/ext/libcouchbase/contrib/snappy/snappy-c.h +138 -0
- data/ext/libcouchbase/contrib/snappy/snappy-internal.h +150 -0
- data/ext/libcouchbase/contrib/snappy/snappy-lcb-msvc.h +5 -0
- data/ext/libcouchbase/contrib/snappy/snappy-sinksource.cc +71 -0
- data/ext/libcouchbase/contrib/snappy/snappy-sinksource.h +137 -0
- data/ext/libcouchbase/contrib/snappy/snappy-stubs-internal.cc +42 -0
- data/ext/libcouchbase/contrib/snappy/snappy-stubs-internal.h +491 -0
- data/ext/libcouchbase/contrib/snappy/snappy-stubs-public.h +98 -0
- data/ext/libcouchbase/contrib/snappy/snappy.cc +1307 -0
- data/ext/libcouchbase/contrib/snappy/snappy.h +184 -0
- data/ext/libcouchbase/contrib/win32-defs/iocpdefs.h +133 -0
- data/ext/libcouchbase/contrib/win32-defs/mingwdefs.h +4396 -0
- data/ext/libcouchbase/contrib/win32-defs/win_stdint.h +258 -0
- data/ext/libcouchbase/example/CMakeLists.txt +37 -0
- data/ext/libcouchbase/example/README.markdown +47 -0
- data/ext/libcouchbase/example/db/db.c +167 -0
- data/ext/libcouchbase/example/db/vb.c +227 -0
- data/ext/libcouchbase/example/instancepool/main.cc +102 -0
- data/ext/libcouchbase/example/instancepool/pool.cc +102 -0
- data/ext/libcouchbase/example/instancepool/pool.h +69 -0
- data/ext/libcouchbase/example/libeventdirect/main.c +148 -0
- data/ext/libcouchbase/example/mcc/mcc.cc +246 -0
- data/ext/libcouchbase/example/minimal/minimal.c +130 -0
- data/ext/libcouchbase/example/observe/observe.c +146 -0
- data/ext/libcouchbase/example/subdoc/subdoc-multi.cc +132 -0
- data/ext/libcouchbase/example/subdoc/subdoc-simple.cc +191 -0
- data/ext/libcouchbase/example/tick/tick.c +119 -0
- data/ext/libcouchbase/example/views/views-example.cc +83 -0
- data/ext/libcouchbase/include/libcouchbase/_cxxwrap.h +150 -0
- data/ext/libcouchbase/include/libcouchbase/api-legacy.h +1689 -0
- data/ext/libcouchbase/include/libcouchbase/api3.h +2 -0
- data/ext/libcouchbase/include/libcouchbase/assert.h +44 -0
- data/ext/libcouchbase/include/libcouchbase/cbft.h +109 -0
- data/ext/libcouchbase/include/libcouchbase/cntl-private.h +356 -0
- data/ext/libcouchbase/include/libcouchbase/cntl.h +937 -0
- data/ext/libcouchbase/include/libcouchbase/configuration.h.in +23 -0
- data/ext/libcouchbase/include/libcouchbase/couchbase.h +3677 -0
- data/ext/libcouchbase/include/libcouchbase/deprecated.h +300 -0
- data/ext/libcouchbase/include/libcouchbase/error.h +595 -0
- data/ext/libcouchbase/include/libcouchbase/http.h +1 -0
- data/ext/libcouchbase/include/libcouchbase/iops.h +1050 -0
- data/ext/libcouchbase/include/libcouchbase/ixmgmt.h +263 -0
- data/ext/libcouchbase/include/libcouchbase/kvbuf.h +132 -0
- data/ext/libcouchbase/include/libcouchbase/n1ql.h +364 -0
- data/ext/libcouchbase/include/libcouchbase/pktfwd.h +270 -0
- data/ext/libcouchbase/include/libcouchbase/plugins/io/bsdio-inl.c +367 -0
- data/ext/libcouchbase/include/libcouchbase/plugins/io/wsaerr-inl.c +76 -0
- data/ext/libcouchbase/include/libcouchbase/plugins/io/wsaerr.h +199 -0
- data/ext/libcouchbase/include/libcouchbase/subdoc.h +312 -0
- data/ext/libcouchbase/include/libcouchbase/sysdefs.h +98 -0
- data/ext/libcouchbase/include/libcouchbase/vbucket.h +643 -0
- data/ext/libcouchbase/include/libcouchbase/views.h +298 -0
- data/ext/libcouchbase/include/libcouchbase/visibility.h +65 -0
- data/ext/libcouchbase/include/memcached/COPYING +30 -0
- data/ext/libcouchbase/include/memcached/README +10 -0
- data/ext/libcouchbase/include/memcached/protocol_binary.h +1916 -0
- data/ext/libcouchbase/include/memcached/vbucket.h +42 -0
- data/ext/libcouchbase/packaging/README +7 -0
- data/ext/libcouchbase/packaging/abicheck/.gitignore +4 -0
- data/ext/libcouchbase/packaging/abicheck/Makefile +17 -0
- data/ext/libcouchbase/packaging/abicheck/README.md +27 -0
- data/ext/libcouchbase/packaging/abicheck/template.xml +3 -0
- data/ext/libcouchbase/packaging/deb/compat +1 -0
- data/ext/libcouchbase/packaging/deb/control +73 -0
- data/ext/libcouchbase/packaging/deb/copyright +10 -0
- data/ext/libcouchbase/packaging/deb/libcouchbase-dev.docs +3 -0
- data/ext/libcouchbase/packaging/deb/package.mk +31 -0
- data/ext/libcouchbase/packaging/deb/rules +46 -0
- data/ext/libcouchbase/packaging/deb/source/format +1 -0
- data/ext/libcouchbase/packaging/distinfo/README +1 -0
- data/ext/libcouchbase/packaging/distinfo/distinfo.cmake.in +4 -0
- data/ext/libcouchbase/packaging/dllversion.rc.in +39 -0
- data/ext/libcouchbase/packaging/libcouchbase.pc.in +10 -0
- data/ext/libcouchbase/packaging/nuget/libcouchbase.autopkg +76 -0
- data/ext/libcouchbase/packaging/parse-git-describe.pl +166 -0
- data/ext/libcouchbase/packaging/rpm/libcouchbase.spec.in +108 -0
- data/ext/libcouchbase/packaging/rpm/package.mk +40 -0
- data/ext/libcouchbase/plugins/io/iocp/CMakeLists.txt +9 -0
- data/ext/libcouchbase/plugins/io/iocp/iocp_iops.c +466 -0
- data/ext/libcouchbase/plugins/io/iocp/iocp_iops.h +217 -0
- data/ext/libcouchbase/plugins/io/iocp/iocp_loop.c +295 -0
- data/ext/libcouchbase/plugins/io/iocp/iocp_timer.c +79 -0
- data/ext/libcouchbase/plugins/io/iocp/iocp_util.c +229 -0
- data/ext/libcouchbase/plugins/io/libev/CMakeLists.txt +29 -0
- data/ext/libcouchbase/plugins/io/libev/libev_io_opts.h +65 -0
- data/ext/libcouchbase/plugins/io/libev/plugin-libev.c +289 -0
- data/ext/libcouchbase/plugins/io/libevent/CMakeLists.txt +29 -0
- data/ext/libcouchbase/plugins/io/libevent/libevent_io_opts.h +67 -0
- data/ext/libcouchbase/plugins/io/libevent/plugin-libevent.c +292 -0
- data/ext/libcouchbase/plugins/io/libuv/CMakeLists.txt +42 -0
- data/ext/libcouchbase/plugins/io/libuv/libuv_compat.h +212 -0
- data/ext/libcouchbase/plugins/io/libuv/libuv_io_opts.h +118 -0
- data/ext/libcouchbase/plugins/io/libuv/plugin-internal.h +148 -0
- data/ext/libcouchbase/plugins/io/libuv/plugin-libuv.c +648 -0
- data/ext/libcouchbase/plugins/io/select/CMakeLists.txt +11 -0
- data/ext/libcouchbase/plugins/io/select/plugin-select.c +448 -0
- data/ext/libcouchbase/plugins/io/select/select_io_opts.h +39 -0
- data/ext/libcouchbase/src/README.md +103 -0
- data/ext/libcouchbase/src/aspend.h +106 -0
- data/ext/libcouchbase/src/auth.cc +74 -0
- data/ext/libcouchbase/src/auth.h +54 -0
- data/ext/libcouchbase/src/bootstrap.c +269 -0
- data/ext/libcouchbase/src/bootstrap.h +129 -0
- data/ext/libcouchbase/src/bucketconfig/bc_cccp.c +495 -0
- data/ext/libcouchbase/src/bucketconfig/bc_file.c +347 -0
- data/ext/libcouchbase/src/bucketconfig/bc_http.c +630 -0
- data/ext/libcouchbase/src/bucketconfig/bc_http.h +82 -0
- data/ext/libcouchbase/src/bucketconfig/bc_mcraw.c +150 -0
- data/ext/libcouchbase/src/bucketconfig/clconfig.h +681 -0
- data/ext/libcouchbase/src/bucketconfig/confmon.c +474 -0
- data/ext/libcouchbase/src/callbacks.c +378 -0
- data/ext/libcouchbase/src/cbft.cc +210 -0
- data/ext/libcouchbase/src/cntl.cc +847 -0
- data/ext/libcouchbase/src/config_static.h +159 -0
- data/ext/libcouchbase/src/connspec.cc +462 -0
- data/ext/libcouchbase/src/connspec.h +105 -0
- data/ext/libcouchbase/src/ctx-log-inl.h +27 -0
- data/ext/libcouchbase/src/dump.c +98 -0
- data/ext/libcouchbase/src/getconfig.c +100 -0
- data/ext/libcouchbase/src/gethrtime.c +109 -0
- data/ext/libcouchbase/src/handler.c +922 -0
- data/ext/libcouchbase/src/hashset.c +164 -0
- data/ext/libcouchbase/src/hashset.h +86 -0
- data/ext/libcouchbase/src/hashtable.c +75 -0
- data/ext/libcouchbase/src/hdr_timings.c +92 -0
- data/ext/libcouchbase/src/hostlist.cc +301 -0
- data/ext/libcouchbase/src/hostlist.h +171 -0
- data/ext/libcouchbase/src/http/http-priv.h +307 -0
- data/ext/libcouchbase/src/http/http.cc +633 -0
- data/ext/libcouchbase/src/http/http.h +34 -0
- data/ext/libcouchbase/src/http/http_io.cc +307 -0
- data/ext/libcouchbase/src/instance.cc +722 -0
- data/ext/libcouchbase/src/internal.h +244 -0
- data/ext/libcouchbase/src/iofactory.c +575 -0
- data/ext/libcouchbase/src/jsparse/parser.cc +519 -0
- data/ext/libcouchbase/src/jsparse/parser.h +173 -0
- data/ext/libcouchbase/src/lcbht/lcbht.c +282 -0
- data/ext/libcouchbase/src/lcbht/lcbht.h +199 -0
- data/ext/libcouchbase/src/lcbio/connect.c +557 -0
- data/ext/libcouchbase/src/lcbio/connect.h +364 -0
- data/ext/libcouchbase/src/lcbio/ctx.c +611 -0
- data/ext/libcouchbase/src/lcbio/ctx.h +405 -0
- data/ext/libcouchbase/src/lcbio/iotable.c +290 -0
- data/ext/libcouchbase/src/lcbio/iotable.h +84 -0
- data/ext/libcouchbase/src/lcbio/ioutils.c +350 -0
- data/ext/libcouchbase/src/lcbio/ioutils.h +203 -0
- data/ext/libcouchbase/src/lcbio/lcbio.h +51 -0
- data/ext/libcouchbase/src/lcbio/manager.c +584 -0
- data/ext/libcouchbase/src/lcbio/manager.h +156 -0
- data/ext/libcouchbase/src/lcbio/protoctx.c +84 -0
- data/ext/libcouchbase/src/lcbio/rw-inl.h +115 -0
- data/ext/libcouchbase/src/lcbio/ssl.h +149 -0
- data/ext/libcouchbase/src/lcbio/timer-ng.h +179 -0
- data/ext/libcouchbase/src/lcbio/timer.c +132 -0
- data/ext/libcouchbase/src/legacy.c +430 -0
- data/ext/libcouchbase/src/list.c +144 -0
- data/ext/libcouchbase/src/list.h +127 -0
- data/ext/libcouchbase/src/logging.c +244 -0
- data/ext/libcouchbase/src/logging.h +86 -0
- data/ext/libcouchbase/src/mc/compress.c +90 -0
- data/ext/libcouchbase/src/mc/compress.h +61 -0
- data/ext/libcouchbase/src/mc/forward.c +186 -0
- data/ext/libcouchbase/src/mc/forward.h +90 -0
- data/ext/libcouchbase/src/mc/iovcursor-inl.h +279 -0
- data/ext/libcouchbase/src/mc/iovcursor.h +66 -0
- data/ext/libcouchbase/src/mc/mcreq-flush-inl.h +111 -0
- data/ext/libcouchbase/src/mc/mcreq.c +954 -0
- data/ext/libcouchbase/src/mc/mcreq.h +977 -0
- data/ext/libcouchbase/src/mcserver/mcserver.c +784 -0
- data/ext/libcouchbase/src/mcserver/mcserver.h +121 -0
- data/ext/libcouchbase/src/mcserver/negotiate.c +656 -0
- data/ext/libcouchbase/src/mcserver/negotiate.h +119 -0
- data/ext/libcouchbase/src/n1ql/ixmgmt.cc +860 -0
- data/ext/libcouchbase/src/n1ql/n1ql-internal.h +22 -0
- data/ext/libcouchbase/src/n1ql/n1ql.cc +729 -0
- data/ext/libcouchbase/src/n1ql/params.cc +215 -0
- data/ext/libcouchbase/src/netbuf/netbuf-defs.h +89 -0
- data/ext/libcouchbase/src/netbuf/netbuf-mblock.h +235 -0
- data/ext/libcouchbase/src/netbuf/netbuf.c +929 -0
- data/ext/libcouchbase/src/netbuf/netbuf.h +452 -0
- data/ext/libcouchbase/src/newconfig.c +385 -0
- data/ext/libcouchbase/src/nodeinfo.cc +194 -0
- data/ext/libcouchbase/src/operations/cbflush.c +71 -0
- data/ext/libcouchbase/src/operations/counter.c +116 -0
- data/ext/libcouchbase/src/operations/durability-cas.c +224 -0
- data/ext/libcouchbase/src/operations/durability-seqno.c +157 -0
- data/ext/libcouchbase/src/operations/durability.c +668 -0
- data/ext/libcouchbase/src/operations/durability_internal.h +199 -0
- data/ext/libcouchbase/src/operations/get.c +409 -0
- data/ext/libcouchbase/src/operations/observe-seqno.c +96 -0
- data/ext/libcouchbase/src/operations/observe.c +340 -0
- data/ext/libcouchbase/src/operations/pktfwd.c +86 -0
- data/ext/libcouchbase/src/operations/remove.c +83 -0
- data/ext/libcouchbase/src/operations/stats.c +461 -0
- data/ext/libcouchbase/src/operations/store.c +360 -0
- data/ext/libcouchbase/src/operations/subdoc.cc +510 -0
- data/ext/libcouchbase/src/operations/touch.c +81 -0
- data/ext/libcouchbase/src/packetutils.c +60 -0
- data/ext/libcouchbase/src/packetutils.h +147 -0
- data/ext/libcouchbase/src/probes.d +211 -0
- data/ext/libcouchbase/src/rdb/bigalloc.c +225 -0
- data/ext/libcouchbase/src/rdb/bigalloc.h +73 -0
- data/ext/libcouchbase/src/rdb/chunkalloc.c +174 -0
- data/ext/libcouchbase/src/rdb/libcalloc.c +94 -0
- data/ext/libcouchbase/src/rdb/rope.c +419 -0
- data/ext/libcouchbase/src/rdb/rope.h +488 -0
- data/ext/libcouchbase/src/retrychk.c +113 -0
- data/ext/libcouchbase/src/retryq.c +424 -0
- data/ext/libcouchbase/src/retryq.h +157 -0
- data/ext/libcouchbase/src/ringbuffer.c +442 -0
- data/ext/libcouchbase/src/ringbuffer.h +100 -0
- data/ext/libcouchbase/src/settings.c +95 -0
- data/ext/libcouchbase/src/settings.h +188 -0
- data/ext/libcouchbase/src/simplestring.c +211 -0
- data/ext/libcouchbase/src/simplestring.h +228 -0
- data/ext/libcouchbase/src/sllist-inl.h +197 -0
- data/ext/libcouchbase/src/sllist.h +76 -0
- data/ext/libcouchbase/src/ssl/CMakeLists.txt +23 -0
- data/ext/libcouchbase/src/ssl/ssl_c.c +415 -0
- data/ext/libcouchbase/src/ssl/ssl_common.c +454 -0
- data/ext/libcouchbase/src/ssl/ssl_e.c +408 -0
- data/ext/libcouchbase/src/ssl/ssl_iot_common.h +180 -0
- data/ext/libcouchbase/src/ssobuf.h +82 -0
- data/ext/libcouchbase/src/strcodecs/base64.c +123 -0
- data/ext/libcouchbase/src/strcodecs/strcodecs.h +285 -0
- data/ext/libcouchbase/src/timings.c +208 -0
- data/ext/libcouchbase/src/trace.h +105 -0
- data/ext/libcouchbase/src/utilities.c +171 -0
- data/ext/libcouchbase/src/vbucket/CMakeLists.txt +2 -0
- data/ext/libcouchbase/src/vbucket/aliases.h +35 -0
- data/ext/libcouchbase/src/vbucket/crc32.h +83 -0
- data/ext/libcouchbase/src/vbucket/hash.h +30 -0
- data/ext/libcouchbase/src/vbucket/json-inl.h +112 -0
- data/ext/libcouchbase/src/vbucket/ketama.c +66 -0
- data/ext/libcouchbase/src/vbucket/rfc1321/global.h +32 -0
- data/ext/libcouchbase/src/vbucket/rfc1321/md5.h +35 -0
- data/ext/libcouchbase/src/vbucket/rfc1321/md5c-inl.h +335 -0
- data/ext/libcouchbase/src/vbucket/vbucket.c +1543 -0
- data/ext/libcouchbase/src/views/docreq.c +194 -0
- data/ext/libcouchbase/src/views/docreq.h +83 -0
- data/ext/libcouchbase/src/views/viewreq.c +358 -0
- data/ext/libcouchbase/src/views/viewreq.h +36 -0
- data/ext/libcouchbase/src/wait.c +161 -0
- data/ext/libcouchbase/tests/CMakeLists.txt +140 -0
- data/ext/libcouchbase/tests/basic/t_base64.cc +81 -0
- data/ext/libcouchbase/tests/basic/t_ccbc103.cc +95 -0
- data/ext/libcouchbase/tests/basic/t_connstr.cc +404 -0
- data/ext/libcouchbase/tests/basic/t_creds.cc +32 -0
- data/ext/libcouchbase/tests/basic/t_ctlcodes.cc +92 -0
- data/ext/libcouchbase/tests/basic/t_hashset.cc +262 -0
- data/ext/libcouchbase/tests/basic/t_host.cc +198 -0
- data/ext/libcouchbase/tests/basic/t_jsparse.cc +137 -0
- data/ext/libcouchbase/tests/basic/t_jsparse.h +589 -0
- data/ext/libcouchbase/tests/basic/t_list.cc +155 -0
- data/ext/libcouchbase/tests/basic/t_logger.cc +65 -0
- data/ext/libcouchbase/tests/basic/t_misc.cc +24 -0
- data/ext/libcouchbase/tests/basic/t_n1qlstrings.cc +18 -0
- data/ext/libcouchbase/tests/basic/t_netbuf.cc +446 -0
- data/ext/libcouchbase/tests/basic/t_packet.cc +222 -0
- data/ext/libcouchbase/tests/basic/t_ringbuffer.cc +278 -0
- data/ext/libcouchbase/tests/basic/t_slist.cc +429 -0
- data/ext/libcouchbase/tests/basic/t_strerror.cc +64 -0
- data/ext/libcouchbase/tests/basic/t_string.cc +112 -0
- data/ext/libcouchbase/tests/basic/t_urlencode.cc +132 -0
- data/ext/libcouchbase/tests/check-all.cc +608 -0
- data/ext/libcouchbase/tests/htparse/t_basic.cc +193 -0
- data/ext/libcouchbase/tests/ioserver/connection.cc +166 -0
- data/ext/libcouchbase/tests/ioserver/future.cc +50 -0
- data/ext/libcouchbase/tests/ioserver/ioserver.cc +104 -0
- data/ext/libcouchbase/tests/ioserver/ioserver.h +478 -0
- data/ext/libcouchbase/tests/ioserver/socket.cc +88 -0
- data/ext/libcouchbase/tests/ioserver/ssl_connection.cc +145 -0
- data/ext/libcouchbase/tests/ioserver/threads-pthreads.cc +119 -0
- data/ext/libcouchbase/tests/ioserver/threads-win32.cc +117 -0
- data/ext/libcouchbase/tests/ioserver/threads.h +66 -0
- data/ext/libcouchbase/tests/iotests/iotests.h +15 -0
- data/ext/libcouchbase/tests/iotests/mock-environment.cc +524 -0
- data/ext/libcouchbase/tests/iotests/mock-environment.h +385 -0
- data/ext/libcouchbase/tests/iotests/mock-unit-test.cc +67 -0
- data/ext/libcouchbase/tests/iotests/mock-unit-test.h +61 -0
- data/ext/libcouchbase/tests/iotests/serverparams.h +76 -0
- data/ext/libcouchbase/tests/iotests/t_arithmetic.cc +143 -0
- data/ext/libcouchbase/tests/iotests/t_behavior.cc +226 -0
- data/ext/libcouchbase/tests/iotests/t_configcache.cc +117 -0
- data/ext/libcouchbase/tests/iotests/t_confmon.cc +241 -0
- data/ext/libcouchbase/tests/iotests/t_durability.cc +1059 -0
- data/ext/libcouchbase/tests/iotests/t_forward.cc +110 -0
- data/ext/libcouchbase/tests/iotests/t_get.cc +512 -0
- data/ext/libcouchbase/tests/iotests/t_http.cc +438 -0
- data/ext/libcouchbase/tests/iotests/t_iops.cc +175 -0
- data/ext/libcouchbase/tests/iotests/t_lock.cc +275 -0
- data/ext/libcouchbase/tests/iotests/t_misc.cc +713 -0
- data/ext/libcouchbase/tests/iotests/t_mutate.cc +609 -0
- data/ext/libcouchbase/tests/iotests/t_n1ql.cc +270 -0
- data/ext/libcouchbase/tests/iotests/t_netfail.cc +654 -0
- data/ext/libcouchbase/tests/iotests/t_obseqno.cc +157 -0
- data/ext/libcouchbase/tests/iotests/t_regression.cc +321 -0
- data/ext/libcouchbase/tests/iotests/t_sched.cc +88 -0
- data/ext/libcouchbase/tests/iotests/t_serverops.cc +230 -0
- data/ext/libcouchbase/tests/iotests/t_smoke.cc +528 -0
- data/ext/libcouchbase/tests/iotests/t_subdoc.cc +822 -0
- data/ext/libcouchbase/tests/iotests/t_syncmode.cc +64 -0
- data/ext/libcouchbase/tests/iotests/t_views.cc +405 -0
- data/ext/libcouchbase/tests/iotests/testutil.cc +250 -0
- data/ext/libcouchbase/tests/iotests/testutil.h +163 -0
- data/ext/libcouchbase/tests/mc/mctest.h +119 -0
- data/ext/libcouchbase/tests/mc/pktmaker.h +101 -0
- data/ext/libcouchbase/tests/mc/t_alloc.cc +269 -0
- data/ext/libcouchbase/tests/mc/t_context.cc +100 -0
- data/ext/libcouchbase/tests/mc/t_flush.cc +185 -0
- data/ext/libcouchbase/tests/mc/t_forward.cc +239 -0
- data/ext/libcouchbase/tests/mc/t_ioflush.cc +102 -0
- data/ext/libcouchbase/tests/mc/t_iovcursor.cc +173 -0
- data/ext/libcouchbase/tests/mocksupport/procutil.c +305 -0
- data/ext/libcouchbase/tests/mocksupport/procutil.h +89 -0
- data/ext/libcouchbase/tests/mocksupport/server.c +391 -0
- data/ext/libcouchbase/tests/mocksupport/server.h +72 -0
- data/ext/libcouchbase/tests/mocksupport/timeout.c +69 -0
- data/ext/libcouchbase/tests/nonio_tests.cc +23 -0
- data/ext/libcouchbase/tests/rdb/rdbtest.h +133 -0
- data/ext/libcouchbase/tests/rdb/t_basic.cc +128 -0
- data/ext/libcouchbase/tests/rdb/t_bigalloc.cc +93 -0
- data/ext/libcouchbase/tests/rdb/t_refs.cc +112 -0
- data/ext/libcouchbase/tests/socktests/socktest.cc +347 -0
- data/ext/libcouchbase/tests/socktests/socktest.h +448 -0
- data/ext/libcouchbase/tests/socktests/t_basic.cc +143 -0
- data/ext/libcouchbase/tests/socktests/t_ctx.cc +73 -0
- data/ext/libcouchbase/tests/socktests/t_manager.cc +179 -0
- data/ext/libcouchbase/tests/socktests/t_putex.cc +256 -0
- data/ext/libcouchbase/tests/socktests/t_read.cc +187 -0
- data/ext/libcouchbase/tests/socktests/t_reentrant.cc +143 -0
- data/ext/libcouchbase/tests/socktests/t_ssl.cc +80 -0
- data/ext/libcouchbase/tests/socktests/t_write.cc +95 -0
- data/ext/libcouchbase/tests/start_mock.bat +15 -0
- data/ext/libcouchbase/tests/start_mock.sh +42 -0
- data/ext/libcouchbase/tests/unit_tests.cc +43 -0
- data/ext/libcouchbase/tests/vbucket/confdata/bad.json +101 -0
- data/ext/libcouchbase/tests/vbucket/confdata/full_25.json +363 -0
- data/ext/libcouchbase/tests/vbucket/confdata/memd_25.json +90 -0
- data/ext/libcouchbase/tests/vbucket/confdata/memd_30.json +1 -0
- data/ext/libcouchbase/tests/vbucket/confdata/memd_45.json +1 -0
- data/ext/libcouchbase/tests/vbucket/confdata/terse_25.json +291 -0
- data/ext/libcouchbase/tests/vbucket/confdata/terse_30.json +1 -0
- data/ext/libcouchbase/tests/vbucket/t_config.cc +341 -0
- data/ext/libcouchbase/tools/CMakeLists.txt +51 -0
- data/ext/libcouchbase/tools/cbc-handlers.h +462 -0
- data/ext/libcouchbase/tools/cbc-n1qlback.cc +439 -0
- data/ext/libcouchbase/tools/cbc-pillowfight.cc +822 -0
- data/ext/libcouchbase/tools/cbc.cc +1541 -0
- data/ext/libcouchbase/tools/common/histogram.cc +43 -0
- data/ext/libcouchbase/tools/common/histogram.h +23 -0
- data/ext/libcouchbase/tools/common/my_inttypes.h +22 -0
- data/ext/libcouchbase/tools/common/options.cc +420 -0
- data/ext/libcouchbase/tools/common/options.h +81 -0
- data/ext/libcouchbase/tools/docgen/docgen.h +469 -0
- data/ext/libcouchbase/tools/docgen/loc.h +210 -0
- data/ext/libcouchbase/tools/docgen/placeholders.h +211 -0
- data/ext/libcouchbase/tools/docgen/seqgen.h +94 -0
- data/lib/libcouchbase.rb +36 -0
- data/lib/libcouchbase/bucket.rb +819 -0
- data/lib/libcouchbase/callbacks.rb +72 -0
- data/lib/libcouchbase/connection.rb +790 -0
- data/lib/libcouchbase/design_docs.rb +86 -0
- data/lib/libcouchbase/error.rb +68 -0
- data/lib/libcouchbase/ext/libcouchbase.rb +1135 -0
- data/lib/libcouchbase/ext/libcouchbase/cmdbase.rb +23 -0
- data/lib/libcouchbase/ext/libcouchbase/cmdcounter.rb +36 -0
- data/lib/libcouchbase/ext/libcouchbase/cmdendure.rb +26 -0
- data/lib/libcouchbase/ext/libcouchbase/cmdfts.rb +24 -0
- data/lib/libcouchbase/ext/libcouchbase/cmdget.rb +30 -0
- data/lib/libcouchbase/ext/libcouchbase/cmdgetreplica.rb +49 -0
- data/lib/libcouchbase/ext/libcouchbase/cmdhttp.rb +58 -0
- data/lib/libcouchbase/ext/libcouchbase/cmdn1ql.rb +40 -0
- data/lib/libcouchbase/ext/libcouchbase/cmdobseqno.rb +33 -0
- data/lib/libcouchbase/ext/libcouchbase/cmdobserve.rb +30 -0
- data/lib/libcouchbase/ext/libcouchbase/cmdstore.rb +40 -0
- data/lib/libcouchbase/ext/libcouchbase/cmdstoredur.rb +45 -0
- data/lib/libcouchbase/ext/libcouchbase/cmdsubdoc.rb +49 -0
- data/lib/libcouchbase/ext/libcouchbase/cmdverbosity.rb +29 -0
- data/lib/libcouchbase/ext/libcouchbase/cmdviewquery.rb +61 -0
- data/lib/libcouchbase/ext/libcouchbase/contigbuf.rb +14 -0
- data/lib/libcouchbase/ext/libcouchbase/create_st.rb +15 -0
- data/lib/libcouchbase/ext/libcouchbase/create_st0.rb +23 -0
- data/lib/libcouchbase/ext/libcouchbase/create_st1.rb +26 -0
- data/lib/libcouchbase/ext/libcouchbase/create_st2.rb +32 -0
- data/lib/libcouchbase/ext/libcouchbase/create_st3.rb +26 -0
- data/lib/libcouchbase/ext/libcouchbase/crst_u.rb +20 -0
- data/lib/libcouchbase/ext/libcouchbase/durability_opts_st_v.rb +11 -0
- data/lib/libcouchbase/ext/libcouchbase/durability_opts_t.rb +14 -0
- data/lib/libcouchbase/ext/libcouchbase/durabilityopt_sv0.rb +63 -0
- data/lib/libcouchbase/ext/libcouchbase/enums.rb +991 -0
- data/lib/libcouchbase/ext/libcouchbase/fragbuf.rb +18 -0
- data/lib/libcouchbase/ext/libcouchbase/ftshandle.rb +7 -0
- data/lib/libcouchbase/ext/libcouchbase/histogram.rb +34 -0
- data/lib/libcouchbase/ext/libcouchbase/http_request_t.rb +7 -0
- data/lib/libcouchbase/ext/libcouchbase/keybuf.rb +20 -0
- data/lib/libcouchbase/ext/libcouchbase/multicmd_ctx.rb +30 -0
- data/lib/libcouchbase/ext/libcouchbase/mutation_token.rb +17 -0
- data/lib/libcouchbase/ext/libcouchbase/n1qlhandle.rb +7 -0
- data/lib/libcouchbase/ext/libcouchbase/n1qlparams.rb +7 -0
- data/lib/libcouchbase/ext/libcouchbase/respbase.rb +29 -0
- data/lib/libcouchbase/ext/libcouchbase/respcounter.rb +32 -0
- data/lib/libcouchbase/ext/libcouchbase/respendure.rb +49 -0
- data/lib/libcouchbase/ext/libcouchbase/respfts.rb +40 -0
- data/lib/libcouchbase/ext/libcouchbase/respget.rb +44 -0
- data/lib/libcouchbase/ext/libcouchbase/resphttp.rb +48 -0
- data/lib/libcouchbase/ext/libcouchbase/respmcversion.rb +38 -0
- data/lib/libcouchbase/ext/libcouchbase/respn1ql.rb +41 -0
- data/lib/libcouchbase/ext/libcouchbase/respobseqno.rb +52 -0
- data/lib/libcouchbase/ext/libcouchbase/respobserve.rb +41 -0
- data/lib/libcouchbase/ext/libcouchbase/respserverbase.rb +32 -0
- data/lib/libcouchbase/ext/libcouchbase/respstats.rb +38 -0
- data/lib/libcouchbase/ext/libcouchbase/respstore.rb +32 -0
- data/lib/libcouchbase/ext/libcouchbase/respstoredur.rb +38 -0
- data/lib/libcouchbase/ext/libcouchbase/respsubdoc.rb +35 -0
- data/lib/libcouchbase/ext/libcouchbase/respviewquery.rb +67 -0
- data/lib/libcouchbase/ext/libcouchbase/sdentry.rb +22 -0
- data/lib/libcouchbase/ext/libcouchbase/sdspec.rb +26 -0
- data/lib/libcouchbase/ext/libcouchbase/t.rb +7 -0
- data/lib/libcouchbase/ext/libcouchbase/valbuf.rb +22 -0
- data/lib/libcouchbase/ext/libcouchbase/valbuf_u_buf.rb +14 -0
- data/lib/libcouchbase/ext/libcouchbase/viewhandle.rb +7 -0
- data/lib/libcouchbase/ext/libcouchbase_iocp.rb +26 -0
- data/lib/libcouchbase/ext/libcouchbase_libuv.rb +18 -0
- data/lib/libcouchbase/ext/tasks.rb +87 -0
- data/lib/libcouchbase/n1ql.rb +73 -0
- data/lib/libcouchbase/query_full_text.rb +147 -0
- data/lib/libcouchbase/query_n1ql.rb +121 -0
- data/lib/libcouchbase/query_view.rb +129 -0
- data/lib/libcouchbase/results_fiber.rb +262 -0
- data/lib/libcouchbase/results_native.rb +211 -0
- data/lib/libcouchbase/version.rb +5 -0
- data/libcouchbase.gemspec +61 -0
- data/spec/bucket_spec.rb +270 -0
- data/spec/connection_spec.rb +277 -0
- data/spec/design_docs_spec.rb +23 -0
- data/spec/error_spec.rb +26 -0
- data/spec/fts_spec.rb +129 -0
- data/spec/n1ql_spec.rb +201 -0
- data/spec/results_libuv_spec.rb +229 -0
- data/spec/results_native_spec.rb +259 -0
- data/spec/seed/2016-10-25T043505Z/2016-10-25T043505Z-full/bucket-default/design.json +1 -0
- data/spec/seed/2016-10-25T043505Z/2016-10-25T043505Z-full/bucket-default/node-127.0.0.1%3A8091/data-0000.cbb +0 -0
- data/spec/seed/2016-10-25T043505Z/2016-10-25T043505Z-full/bucket-default/node-127.0.0.1%3A8091/failover.json +1 -0
- data/spec/seed/2016-10-25T043505Z/2016-10-25T043505Z-full/bucket-default/node-127.0.0.1%3A8091/meta.json +1 -0
- data/spec/seed/2016-10-25T043505Z/2016-10-25T043505Z-full/bucket-default/node-127.0.0.1%3A8091/seqno.json +1 -0
- data/spec/seed/2016-10-25T043505Z/2016-10-25T043505Z-full/bucket-default/node-127.0.0.1%3A8091/snapshot_markers.json +1 -0
- data/spec/view_spec.rb +195 -0
- metadata +775 -0
@@ -0,0 +1,382 @@
|
|
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: keith.ray@gmail.com (Keith Ray)
|
31
|
+
|
32
|
+
#include "gtest/gtest-message.h"
|
33
|
+
#include "gtest/internal/gtest-filepath.h"
|
34
|
+
#include "gtest/internal/gtest-port.h"
|
35
|
+
|
36
|
+
#include <stdlib.h>
|
37
|
+
|
38
|
+
#if GTEST_OS_WINDOWS_MOBILE
|
39
|
+
# include <windows.h>
|
40
|
+
#elif GTEST_OS_WINDOWS
|
41
|
+
# include <direct.h>
|
42
|
+
# include <io.h>
|
43
|
+
#elif GTEST_OS_SYMBIAN
|
44
|
+
// Symbian OpenC has PATH_MAX in sys/syslimits.h
|
45
|
+
# include <sys/syslimits.h>
|
46
|
+
#else
|
47
|
+
# include <limits.h>
|
48
|
+
# include <climits> // Some Linux distributions define PATH_MAX here.
|
49
|
+
#endif // GTEST_OS_WINDOWS_MOBILE
|
50
|
+
|
51
|
+
#if GTEST_OS_WINDOWS
|
52
|
+
# define GTEST_PATH_MAX_ _MAX_PATH
|
53
|
+
#elif defined(PATH_MAX)
|
54
|
+
# define GTEST_PATH_MAX_ PATH_MAX
|
55
|
+
#elif defined(_XOPEN_PATH_MAX)
|
56
|
+
# define GTEST_PATH_MAX_ _XOPEN_PATH_MAX
|
57
|
+
#else
|
58
|
+
# define GTEST_PATH_MAX_ _POSIX_PATH_MAX
|
59
|
+
#endif // GTEST_OS_WINDOWS
|
60
|
+
|
61
|
+
#include "gtest/internal/gtest-string.h"
|
62
|
+
|
63
|
+
namespace testing {
|
64
|
+
namespace internal {
|
65
|
+
|
66
|
+
#if GTEST_OS_WINDOWS
|
67
|
+
// On Windows, '\\' is the standard path separator, but many tools and the
|
68
|
+
// Windows API also accept '/' as an alternate path separator. Unless otherwise
|
69
|
+
// noted, a file path can contain either kind of path separators, or a mixture
|
70
|
+
// of them.
|
71
|
+
const char kPathSeparator = '\\';
|
72
|
+
const char kAlternatePathSeparator = '/';
|
73
|
+
const char kPathSeparatorString[] = "\\";
|
74
|
+
const char kAlternatePathSeparatorString[] = "/";
|
75
|
+
# if GTEST_OS_WINDOWS_MOBILE
|
76
|
+
// Windows CE doesn't have a current directory. You should not use
|
77
|
+
// the current directory in tests on Windows CE, but this at least
|
78
|
+
// provides a reasonable fallback.
|
79
|
+
const char kCurrentDirectoryString[] = "\\";
|
80
|
+
// Windows CE doesn't define INVALID_FILE_ATTRIBUTES
|
81
|
+
const DWORD kInvalidFileAttributes = 0xffffffff;
|
82
|
+
# else
|
83
|
+
const char kCurrentDirectoryString[] = ".\\";
|
84
|
+
# endif // GTEST_OS_WINDOWS_MOBILE
|
85
|
+
#else
|
86
|
+
const char kPathSeparator = '/';
|
87
|
+
const char kPathSeparatorString[] = "/";
|
88
|
+
const char kCurrentDirectoryString[] = "./";
|
89
|
+
#endif // GTEST_OS_WINDOWS
|
90
|
+
|
91
|
+
// Returns whether the given character is a valid path separator.
|
92
|
+
static bool IsPathSeparator(char c) {
|
93
|
+
#if GTEST_HAS_ALT_PATH_SEP_
|
94
|
+
return (c == kPathSeparator) || (c == kAlternatePathSeparator);
|
95
|
+
#else
|
96
|
+
return c == kPathSeparator;
|
97
|
+
#endif
|
98
|
+
}
|
99
|
+
|
100
|
+
// Returns the current working directory, or "" if unsuccessful.
|
101
|
+
FilePath FilePath::GetCurrentDir() {
|
102
|
+
#if GTEST_OS_WINDOWS_MOBILE
|
103
|
+
// Windows CE doesn't have a current directory, so we just return
|
104
|
+
// something reasonable.
|
105
|
+
return FilePath(kCurrentDirectoryString);
|
106
|
+
#elif GTEST_OS_WINDOWS
|
107
|
+
char cwd[GTEST_PATH_MAX_ + 1] = { '\0' };
|
108
|
+
return FilePath(_getcwd(cwd, sizeof(cwd)) == NULL ? "" : cwd);
|
109
|
+
#else
|
110
|
+
char cwd[GTEST_PATH_MAX_ + 1] = { '\0' };
|
111
|
+
return FilePath(getcwd(cwd, sizeof(cwd)) == NULL ? "" : cwd);
|
112
|
+
#endif // GTEST_OS_WINDOWS_MOBILE
|
113
|
+
}
|
114
|
+
|
115
|
+
// Returns a copy of the FilePath with the case-insensitive extension removed.
|
116
|
+
// Example: FilePath("dir/file.exe").RemoveExtension("EXE") returns
|
117
|
+
// FilePath("dir/file"). If a case-insensitive extension is not
|
118
|
+
// found, returns a copy of the original FilePath.
|
119
|
+
FilePath FilePath::RemoveExtension(const char* extension) const {
|
120
|
+
const std::string dot_extension = std::string(".") + extension;
|
121
|
+
if (String::EndsWithCaseInsensitive(pathname_, dot_extension)) {
|
122
|
+
return FilePath(pathname_.substr(
|
123
|
+
0, pathname_.length() - dot_extension.length()));
|
124
|
+
}
|
125
|
+
return *this;
|
126
|
+
}
|
127
|
+
|
128
|
+
// Returns a pointer to the last occurence of a valid path separator in
|
129
|
+
// the FilePath. On Windows, for example, both '/' and '\' are valid path
|
130
|
+
// separators. Returns NULL if no path separator was found.
|
131
|
+
const char* FilePath::FindLastPathSeparator() const {
|
132
|
+
const char* const last_sep = strrchr(c_str(), kPathSeparator);
|
133
|
+
#if GTEST_HAS_ALT_PATH_SEP_
|
134
|
+
const char* const last_alt_sep = strrchr(c_str(), kAlternatePathSeparator);
|
135
|
+
// Comparing two pointers of which only one is NULL is undefined.
|
136
|
+
if (last_alt_sep != NULL &&
|
137
|
+
(last_sep == NULL || last_alt_sep > last_sep)) {
|
138
|
+
return last_alt_sep;
|
139
|
+
}
|
140
|
+
#endif
|
141
|
+
return last_sep;
|
142
|
+
}
|
143
|
+
|
144
|
+
// Returns a copy of the FilePath with the directory part removed.
|
145
|
+
// Example: FilePath("path/to/file").RemoveDirectoryName() returns
|
146
|
+
// FilePath("file"). If there is no directory part ("just_a_file"), it returns
|
147
|
+
// the FilePath unmodified. If there is no file part ("just_a_dir/") it
|
148
|
+
// returns an empty FilePath ("").
|
149
|
+
// On Windows platform, '\' is the path separator, otherwise it is '/'.
|
150
|
+
FilePath FilePath::RemoveDirectoryName() const {
|
151
|
+
const char* const last_sep = FindLastPathSeparator();
|
152
|
+
return last_sep ? FilePath(last_sep + 1) : *this;
|
153
|
+
}
|
154
|
+
|
155
|
+
// RemoveFileName returns the directory path with the filename removed.
|
156
|
+
// Example: FilePath("path/to/file").RemoveFileName() returns "path/to/".
|
157
|
+
// If the FilePath is "a_file" or "/a_file", RemoveFileName returns
|
158
|
+
// FilePath("./") or, on Windows, FilePath(".\\"). If the filepath does
|
159
|
+
// not have a file, like "just/a/dir/", it returns the FilePath unmodified.
|
160
|
+
// On Windows platform, '\' is the path separator, otherwise it is '/'.
|
161
|
+
FilePath FilePath::RemoveFileName() const {
|
162
|
+
const char* const last_sep = FindLastPathSeparator();
|
163
|
+
std::string dir;
|
164
|
+
if (last_sep) {
|
165
|
+
dir = std::string(c_str(), last_sep + 1 - c_str());
|
166
|
+
} else {
|
167
|
+
dir = kCurrentDirectoryString;
|
168
|
+
}
|
169
|
+
return FilePath(dir);
|
170
|
+
}
|
171
|
+
|
172
|
+
// Helper functions for naming files in a directory for xml output.
|
173
|
+
|
174
|
+
// Given directory = "dir", base_name = "test", number = 0,
|
175
|
+
// extension = "xml", returns "dir/test.xml". If number is greater
|
176
|
+
// than zero (e.g., 12), returns "dir/test_12.xml".
|
177
|
+
// On Windows platform, uses \ as the separator rather than /.
|
178
|
+
FilePath FilePath::MakeFileName(const FilePath& directory,
|
179
|
+
const FilePath& base_name,
|
180
|
+
int number,
|
181
|
+
const char* extension) {
|
182
|
+
std::string file;
|
183
|
+
if (number == 0) {
|
184
|
+
file = base_name.string() + "." + extension;
|
185
|
+
} else {
|
186
|
+
file = base_name.string() + "_" + StreamableToString(number)
|
187
|
+
+ "." + extension;
|
188
|
+
}
|
189
|
+
return ConcatPaths(directory, FilePath(file));
|
190
|
+
}
|
191
|
+
|
192
|
+
// Given directory = "dir", relative_path = "test.xml", returns "dir/test.xml".
|
193
|
+
// On Windows, uses \ as the separator rather than /.
|
194
|
+
FilePath FilePath::ConcatPaths(const FilePath& directory,
|
195
|
+
const FilePath& relative_path) {
|
196
|
+
if (directory.IsEmpty())
|
197
|
+
return relative_path;
|
198
|
+
const FilePath dir(directory.RemoveTrailingPathSeparator());
|
199
|
+
return FilePath(dir.string() + kPathSeparator + relative_path.string());
|
200
|
+
}
|
201
|
+
|
202
|
+
// Returns true if pathname describes something findable in the file-system,
|
203
|
+
// either a file, directory, or whatever.
|
204
|
+
bool FilePath::FileOrDirectoryExists() const {
|
205
|
+
#if GTEST_OS_WINDOWS_MOBILE
|
206
|
+
LPCWSTR unicode = String::AnsiToUtf16(pathname_.c_str());
|
207
|
+
const DWORD attributes = GetFileAttributes(unicode);
|
208
|
+
delete [] unicode;
|
209
|
+
return attributes != kInvalidFileAttributes;
|
210
|
+
#else
|
211
|
+
posix::StatStruct file_stat;
|
212
|
+
return posix::Stat(pathname_.c_str(), &file_stat) == 0;
|
213
|
+
#endif // GTEST_OS_WINDOWS_MOBILE
|
214
|
+
}
|
215
|
+
|
216
|
+
// Returns true if pathname describes a directory in the file-system
|
217
|
+
// that exists.
|
218
|
+
bool FilePath::DirectoryExists() const {
|
219
|
+
bool result = false;
|
220
|
+
#if GTEST_OS_WINDOWS
|
221
|
+
// Don't strip off trailing separator if path is a root directory on
|
222
|
+
// Windows (like "C:\\").
|
223
|
+
const FilePath& path(IsRootDirectory() ? *this :
|
224
|
+
RemoveTrailingPathSeparator());
|
225
|
+
#else
|
226
|
+
const FilePath& path(*this);
|
227
|
+
#endif
|
228
|
+
|
229
|
+
#if GTEST_OS_WINDOWS_MOBILE
|
230
|
+
LPCWSTR unicode = String::AnsiToUtf16(path.c_str());
|
231
|
+
const DWORD attributes = GetFileAttributes(unicode);
|
232
|
+
delete [] unicode;
|
233
|
+
if ((attributes != kInvalidFileAttributes) &&
|
234
|
+
(attributes & FILE_ATTRIBUTE_DIRECTORY)) {
|
235
|
+
result = true;
|
236
|
+
}
|
237
|
+
#else
|
238
|
+
posix::StatStruct file_stat;
|
239
|
+
result = posix::Stat(path.c_str(), &file_stat) == 0 &&
|
240
|
+
posix::IsDir(file_stat);
|
241
|
+
#endif // GTEST_OS_WINDOWS_MOBILE
|
242
|
+
|
243
|
+
return result;
|
244
|
+
}
|
245
|
+
|
246
|
+
// Returns true if pathname describes a root directory. (Windows has one
|
247
|
+
// root directory per disk drive.)
|
248
|
+
bool FilePath::IsRootDirectory() const {
|
249
|
+
#if GTEST_OS_WINDOWS
|
250
|
+
// TODO(wan@google.com): on Windows a network share like
|
251
|
+
// \\server\share can be a root directory, although it cannot be the
|
252
|
+
// current directory. Handle this properly.
|
253
|
+
return pathname_.length() == 3 && IsAbsolutePath();
|
254
|
+
#else
|
255
|
+
return pathname_.length() == 1 && IsPathSeparator(pathname_.c_str()[0]);
|
256
|
+
#endif
|
257
|
+
}
|
258
|
+
|
259
|
+
// Returns true if pathname describes an absolute path.
|
260
|
+
bool FilePath::IsAbsolutePath() const {
|
261
|
+
const char* const name = pathname_.c_str();
|
262
|
+
#if GTEST_OS_WINDOWS
|
263
|
+
return pathname_.length() >= 3 &&
|
264
|
+
((name[0] >= 'a' && name[0] <= 'z') ||
|
265
|
+
(name[0] >= 'A' && name[0] <= 'Z')) &&
|
266
|
+
name[1] == ':' &&
|
267
|
+
IsPathSeparator(name[2]);
|
268
|
+
#else
|
269
|
+
return IsPathSeparator(name[0]);
|
270
|
+
#endif
|
271
|
+
}
|
272
|
+
|
273
|
+
// Returns a pathname for a file that does not currently exist. The pathname
|
274
|
+
// will be directory/base_name.extension or
|
275
|
+
// directory/base_name_<number>.extension if directory/base_name.extension
|
276
|
+
// already exists. The number will be incremented until a pathname is found
|
277
|
+
// that does not already exist.
|
278
|
+
// Examples: 'dir/foo_test.xml' or 'dir/foo_test_1.xml'.
|
279
|
+
// There could be a race condition if two or more processes are calling this
|
280
|
+
// function at the same time -- they could both pick the same filename.
|
281
|
+
FilePath FilePath::GenerateUniqueFileName(const FilePath& directory,
|
282
|
+
const FilePath& base_name,
|
283
|
+
const char* extension) {
|
284
|
+
FilePath full_pathname;
|
285
|
+
int number = 0;
|
286
|
+
do {
|
287
|
+
full_pathname.Set(MakeFileName(directory, base_name, number++, extension));
|
288
|
+
} while (full_pathname.FileOrDirectoryExists());
|
289
|
+
return full_pathname;
|
290
|
+
}
|
291
|
+
|
292
|
+
// Returns true if FilePath ends with a path separator, which indicates that
|
293
|
+
// it is intended to represent a directory. Returns false otherwise.
|
294
|
+
// This does NOT check that a directory (or file) actually exists.
|
295
|
+
bool FilePath::IsDirectory() const {
|
296
|
+
return !pathname_.empty() &&
|
297
|
+
IsPathSeparator(pathname_.c_str()[pathname_.length() - 1]);
|
298
|
+
}
|
299
|
+
|
300
|
+
// Create directories so that path exists. Returns true if successful or if
|
301
|
+
// the directories already exist; returns false if unable to create directories
|
302
|
+
// for any reason.
|
303
|
+
bool FilePath::CreateDirectoriesRecursively() const {
|
304
|
+
if (!this->IsDirectory()) {
|
305
|
+
return false;
|
306
|
+
}
|
307
|
+
|
308
|
+
if (pathname_.length() == 0 || this->DirectoryExists()) {
|
309
|
+
return true;
|
310
|
+
}
|
311
|
+
|
312
|
+
const FilePath parent(this->RemoveTrailingPathSeparator().RemoveFileName());
|
313
|
+
return parent.CreateDirectoriesRecursively() && this->CreateFolder();
|
314
|
+
}
|
315
|
+
|
316
|
+
// Create the directory so that path exists. Returns true if successful or
|
317
|
+
// if the directory already exists; returns false if unable to create the
|
318
|
+
// directory for any reason, including if the parent directory does not
|
319
|
+
// exist. Not named "CreateDirectory" because that's a macro on Windows.
|
320
|
+
bool FilePath::CreateFolder() const {
|
321
|
+
#if GTEST_OS_WINDOWS_MOBILE
|
322
|
+
FilePath removed_sep(this->RemoveTrailingPathSeparator());
|
323
|
+
LPCWSTR unicode = String::AnsiToUtf16(removed_sep.c_str());
|
324
|
+
int result = CreateDirectory(unicode, NULL) ? 0 : -1;
|
325
|
+
delete [] unicode;
|
326
|
+
#elif GTEST_OS_WINDOWS
|
327
|
+
int result = _mkdir(pathname_.c_str());
|
328
|
+
#else
|
329
|
+
int result = mkdir(pathname_.c_str(), 0777);
|
330
|
+
#endif // GTEST_OS_WINDOWS_MOBILE
|
331
|
+
|
332
|
+
if (result == -1) {
|
333
|
+
return this->DirectoryExists(); // An error is OK if the directory exists.
|
334
|
+
}
|
335
|
+
return true; // No error.
|
336
|
+
}
|
337
|
+
|
338
|
+
// If input name has a trailing separator character, remove it and return the
|
339
|
+
// name, otherwise return the name string unmodified.
|
340
|
+
// On Windows platform, uses \ as the separator, other platforms use /.
|
341
|
+
FilePath FilePath::RemoveTrailingPathSeparator() const {
|
342
|
+
return IsDirectory()
|
343
|
+
? FilePath(pathname_.substr(0, pathname_.length() - 1))
|
344
|
+
: *this;
|
345
|
+
}
|
346
|
+
|
347
|
+
// Removes any redundant separators that might be in the pathname.
|
348
|
+
// For example, "bar///foo" becomes "bar/foo". Does not eliminate other
|
349
|
+
// redundancies that might be in a pathname involving "." or "..".
|
350
|
+
// TODO(wan@google.com): handle Windows network shares (e.g. \\server\share).
|
351
|
+
void FilePath::Normalize() {
|
352
|
+
if (pathname_.c_str() == NULL) {
|
353
|
+
pathname_ = "";
|
354
|
+
return;
|
355
|
+
}
|
356
|
+
const char* src = pathname_.c_str();
|
357
|
+
char* const dest = new char[pathname_.length() + 1];
|
358
|
+
char* dest_ptr = dest;
|
359
|
+
memset(dest_ptr, 0, pathname_.length() + 1);
|
360
|
+
|
361
|
+
while (*src != '\0') {
|
362
|
+
*dest_ptr = *src;
|
363
|
+
if (!IsPathSeparator(*src)) {
|
364
|
+
src++;
|
365
|
+
} else {
|
366
|
+
#if GTEST_HAS_ALT_PATH_SEP_
|
367
|
+
if (*dest_ptr == kAlternatePathSeparator) {
|
368
|
+
*dest_ptr = kPathSeparator;
|
369
|
+
}
|
370
|
+
#endif
|
371
|
+
while (IsPathSeparator(*src))
|
372
|
+
src++;
|
373
|
+
}
|
374
|
+
dest_ptr++;
|
375
|
+
}
|
376
|
+
*dest_ptr = '\0';
|
377
|
+
pathname_ = dest;
|
378
|
+
delete[] dest;
|
379
|
+
}
|
380
|
+
|
381
|
+
} // namespace internal
|
382
|
+
} // namespace testing
|
@@ -0,0 +1,1218 @@
|
|
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
|
+
// Utility functions and classes used by the Google C++ testing framework.
|
31
|
+
//
|
32
|
+
// Author: wan@google.com (Zhanyong Wan)
|
33
|
+
//
|
34
|
+
// This file contains purely Google Test's internal implementation. Please
|
35
|
+
// DO NOT #INCLUDE IT IN A USER PROGRAM.
|
36
|
+
|
37
|
+
#ifndef GTEST_SRC_GTEST_INTERNAL_INL_H_
|
38
|
+
#define GTEST_SRC_GTEST_INTERNAL_INL_H_
|
39
|
+
|
40
|
+
// GTEST_IMPLEMENTATION_ is defined to 1 iff the current translation unit is
|
41
|
+
// part of Google Test's implementation; otherwise it's undefined.
|
42
|
+
#if !GTEST_IMPLEMENTATION_
|
43
|
+
// A user is trying to include this from his code - just say no.
|
44
|
+
# error "gtest-internal-inl.h is part of Google Test's internal implementation."
|
45
|
+
# error "It must not be included except by Google Test itself."
|
46
|
+
#endif // GTEST_IMPLEMENTATION_
|
47
|
+
|
48
|
+
#ifndef _WIN32_WCE
|
49
|
+
# include <errno.h>
|
50
|
+
#endif // !_WIN32_WCE
|
51
|
+
#include <stddef.h>
|
52
|
+
#include <stdlib.h> // For strtoll/_strtoul64/malloc/free.
|
53
|
+
#include <string.h> // For memmove.
|
54
|
+
|
55
|
+
#include <algorithm>
|
56
|
+
#include <string>
|
57
|
+
#include <vector>
|
58
|
+
|
59
|
+
#include "gtest/internal/gtest-port.h"
|
60
|
+
|
61
|
+
#if GTEST_CAN_STREAM_RESULTS_
|
62
|
+
# include <arpa/inet.h> // NOLINT
|
63
|
+
# include <netdb.h> // NOLINT
|
64
|
+
#endif
|
65
|
+
|
66
|
+
#if GTEST_OS_WINDOWS
|
67
|
+
# include <windows.h> // NOLINT
|
68
|
+
#endif // GTEST_OS_WINDOWS
|
69
|
+
|
70
|
+
#include "gtest/gtest.h" // NOLINT
|
71
|
+
#include "gtest/gtest-spi.h"
|
72
|
+
|
73
|
+
namespace testing {
|
74
|
+
|
75
|
+
// Declares the flags.
|
76
|
+
//
|
77
|
+
// We don't want the users to modify this flag in the code, but want
|
78
|
+
// Google Test's own unit tests to be able to access it. Therefore we
|
79
|
+
// declare it here as opposed to in gtest.h.
|
80
|
+
GTEST_DECLARE_bool_(death_test_use_fork);
|
81
|
+
|
82
|
+
namespace internal {
|
83
|
+
|
84
|
+
// The value of GetTestTypeId() as seen from within the Google Test
|
85
|
+
// library. This is solely for testing GetTestTypeId().
|
86
|
+
GTEST_API_ extern const TypeId kTestTypeIdInGoogleTest;
|
87
|
+
|
88
|
+
// Names of the flags (needed for parsing Google Test flags).
|
89
|
+
const char kAlsoRunDisabledTestsFlag[] = "also_run_disabled_tests";
|
90
|
+
const char kBreakOnFailureFlag[] = "break_on_failure";
|
91
|
+
const char kCatchExceptionsFlag[] = "catch_exceptions";
|
92
|
+
const char kColorFlag[] = "color";
|
93
|
+
const char kFilterFlag[] = "filter";
|
94
|
+
const char kListTestsFlag[] = "list_tests";
|
95
|
+
const char kOutputFlag[] = "output";
|
96
|
+
const char kPrintTimeFlag[] = "print_time";
|
97
|
+
const char kRandomSeedFlag[] = "random_seed";
|
98
|
+
const char kRepeatFlag[] = "repeat";
|
99
|
+
const char kShuffleFlag[] = "shuffle";
|
100
|
+
const char kStackTraceDepthFlag[] = "stack_trace_depth";
|
101
|
+
const char kStreamResultToFlag[] = "stream_result_to";
|
102
|
+
const char kThrowOnFailureFlag[] = "throw_on_failure";
|
103
|
+
|
104
|
+
// A valid random seed must be in [1, kMaxRandomSeed].
|
105
|
+
const int kMaxRandomSeed = 99999;
|
106
|
+
|
107
|
+
// g_help_flag is true iff the --help flag or an equivalent form is
|
108
|
+
// specified on the command line.
|
109
|
+
GTEST_API_ extern bool g_help_flag;
|
110
|
+
|
111
|
+
// Returns the current time in milliseconds.
|
112
|
+
GTEST_API_ TimeInMillis GetTimeInMillis();
|
113
|
+
|
114
|
+
// Returns true iff Google Test should use colors in the output.
|
115
|
+
GTEST_API_ bool ShouldUseColor(bool stdout_is_tty);
|
116
|
+
|
117
|
+
// Formats the given time in milliseconds as seconds.
|
118
|
+
GTEST_API_ std::string FormatTimeInMillisAsSeconds(TimeInMillis ms);
|
119
|
+
|
120
|
+
// Converts the given time in milliseconds to a date string in the ISO 8601
|
121
|
+
// format, without the timezone information. N.B.: due to the use the
|
122
|
+
// non-reentrant localtime() function, this function is not thread safe. Do
|
123
|
+
// not use it in any code that can be called from multiple threads.
|
124
|
+
GTEST_API_ std::string FormatEpochTimeInMillisAsIso8601(TimeInMillis ms);
|
125
|
+
|
126
|
+
// Parses a string for an Int32 flag, in the form of "--flag=value".
|
127
|
+
//
|
128
|
+
// On success, stores the value of the flag in *value, and returns
|
129
|
+
// true. On failure, returns false without changing *value.
|
130
|
+
GTEST_API_ bool ParseInt32Flag(
|
131
|
+
const char* str, const char* flag, Int32* value);
|
132
|
+
|
133
|
+
// Returns a random seed in range [1, kMaxRandomSeed] based on the
|
134
|
+
// given --gtest_random_seed flag value.
|
135
|
+
inline int GetRandomSeedFromFlag(Int32 random_seed_flag) {
|
136
|
+
const unsigned int raw_seed = (random_seed_flag == 0) ?
|
137
|
+
static_cast<unsigned int>(GetTimeInMillis()) :
|
138
|
+
static_cast<unsigned int>(random_seed_flag);
|
139
|
+
|
140
|
+
// Normalizes the actual seed to range [1, kMaxRandomSeed] such that
|
141
|
+
// it's easy to type.
|
142
|
+
const int normalized_seed =
|
143
|
+
static_cast<int>((raw_seed - 1U) %
|
144
|
+
static_cast<unsigned int>(kMaxRandomSeed)) + 1;
|
145
|
+
return normalized_seed;
|
146
|
+
}
|
147
|
+
|
148
|
+
// Returns the first valid random seed after 'seed'. The behavior is
|
149
|
+
// undefined if 'seed' is invalid. The seed after kMaxRandomSeed is
|
150
|
+
// considered to be 1.
|
151
|
+
inline int GetNextRandomSeed(int seed) {
|
152
|
+
GTEST_CHECK_(1 <= seed && seed <= kMaxRandomSeed)
|
153
|
+
<< "Invalid random seed " << seed << " - must be in [1, "
|
154
|
+
<< kMaxRandomSeed << "].";
|
155
|
+
const int next_seed = seed + 1;
|
156
|
+
return (next_seed > kMaxRandomSeed) ? 1 : next_seed;
|
157
|
+
}
|
158
|
+
|
159
|
+
// This class saves the values of all Google Test flags in its c'tor, and
|
160
|
+
// restores them in its d'tor.
|
161
|
+
class GTestFlagSaver {
|
162
|
+
public:
|
163
|
+
// The c'tor.
|
164
|
+
GTestFlagSaver() {
|
165
|
+
also_run_disabled_tests_ = GTEST_FLAG(also_run_disabled_tests);
|
166
|
+
break_on_failure_ = GTEST_FLAG(break_on_failure);
|
167
|
+
catch_exceptions_ = GTEST_FLAG(catch_exceptions);
|
168
|
+
color_ = GTEST_FLAG(color);
|
169
|
+
death_test_style_ = GTEST_FLAG(death_test_style);
|
170
|
+
death_test_use_fork_ = GTEST_FLAG(death_test_use_fork);
|
171
|
+
filter_ = GTEST_FLAG(filter);
|
172
|
+
internal_run_death_test_ = GTEST_FLAG(internal_run_death_test);
|
173
|
+
list_tests_ = GTEST_FLAG(list_tests);
|
174
|
+
output_ = GTEST_FLAG(output);
|
175
|
+
print_time_ = GTEST_FLAG(print_time);
|
176
|
+
random_seed_ = GTEST_FLAG(random_seed);
|
177
|
+
repeat_ = GTEST_FLAG(repeat);
|
178
|
+
shuffle_ = GTEST_FLAG(shuffle);
|
179
|
+
stack_trace_depth_ = GTEST_FLAG(stack_trace_depth);
|
180
|
+
stream_result_to_ = GTEST_FLAG(stream_result_to);
|
181
|
+
throw_on_failure_ = GTEST_FLAG(throw_on_failure);
|
182
|
+
}
|
183
|
+
|
184
|
+
// The d'tor is not virtual. DO NOT INHERIT FROM THIS CLASS.
|
185
|
+
~GTestFlagSaver() {
|
186
|
+
GTEST_FLAG(also_run_disabled_tests) = also_run_disabled_tests_;
|
187
|
+
GTEST_FLAG(break_on_failure) = break_on_failure_;
|
188
|
+
GTEST_FLAG(catch_exceptions) = catch_exceptions_;
|
189
|
+
GTEST_FLAG(color) = color_;
|
190
|
+
GTEST_FLAG(death_test_style) = death_test_style_;
|
191
|
+
GTEST_FLAG(death_test_use_fork) = death_test_use_fork_;
|
192
|
+
GTEST_FLAG(filter) = filter_;
|
193
|
+
GTEST_FLAG(internal_run_death_test) = internal_run_death_test_;
|
194
|
+
GTEST_FLAG(list_tests) = list_tests_;
|
195
|
+
GTEST_FLAG(output) = output_;
|
196
|
+
GTEST_FLAG(print_time) = print_time_;
|
197
|
+
GTEST_FLAG(random_seed) = random_seed_;
|
198
|
+
GTEST_FLAG(repeat) = repeat_;
|
199
|
+
GTEST_FLAG(shuffle) = shuffle_;
|
200
|
+
GTEST_FLAG(stack_trace_depth) = stack_trace_depth_;
|
201
|
+
GTEST_FLAG(stream_result_to) = stream_result_to_;
|
202
|
+
GTEST_FLAG(throw_on_failure) = throw_on_failure_;
|
203
|
+
}
|
204
|
+
|
205
|
+
private:
|
206
|
+
// Fields for saving the original values of flags.
|
207
|
+
bool also_run_disabled_tests_;
|
208
|
+
bool break_on_failure_;
|
209
|
+
bool catch_exceptions_;
|
210
|
+
std::string color_;
|
211
|
+
std::string death_test_style_;
|
212
|
+
bool death_test_use_fork_;
|
213
|
+
std::string filter_;
|
214
|
+
std::string internal_run_death_test_;
|
215
|
+
bool list_tests_;
|
216
|
+
std::string output_;
|
217
|
+
bool print_time_;
|
218
|
+
internal::Int32 random_seed_;
|
219
|
+
internal::Int32 repeat_;
|
220
|
+
bool shuffle_;
|
221
|
+
internal::Int32 stack_trace_depth_;
|
222
|
+
std::string stream_result_to_;
|
223
|
+
bool throw_on_failure_;
|
224
|
+
} GTEST_ATTRIBUTE_UNUSED_;
|
225
|
+
|
226
|
+
// Converts a Unicode code point to a narrow string in UTF-8 encoding.
|
227
|
+
// code_point parameter is of type UInt32 because wchar_t may not be
|
228
|
+
// wide enough to contain a code point.
|
229
|
+
// If the code_point is not a valid Unicode code point
|
230
|
+
// (i.e. outside of Unicode range U+0 to U+10FFFF) it will be converted
|
231
|
+
// to "(Invalid Unicode 0xXXXXXXXX)".
|
232
|
+
GTEST_API_ std::string CodePointToUtf8(UInt32 code_point);
|
233
|
+
|
234
|
+
// Converts a wide string to a narrow string in UTF-8 encoding.
|
235
|
+
// The wide string is assumed to have the following encoding:
|
236
|
+
// UTF-16 if sizeof(wchar_t) == 2 (on Windows, Cygwin, Symbian OS)
|
237
|
+
// UTF-32 if sizeof(wchar_t) == 4 (on Linux)
|
238
|
+
// Parameter str points to a null-terminated wide string.
|
239
|
+
// Parameter num_chars may additionally limit the number
|
240
|
+
// of wchar_t characters processed. -1 is used when the entire string
|
241
|
+
// should be processed.
|
242
|
+
// If the string contains code points that are not valid Unicode code points
|
243
|
+
// (i.e. outside of Unicode range U+0 to U+10FFFF) they will be output
|
244
|
+
// as '(Invalid Unicode 0xXXXXXXXX)'. If the string is in UTF16 encoding
|
245
|
+
// and contains invalid UTF-16 surrogate pairs, values in those pairs
|
246
|
+
// will be encoded as individual Unicode characters from Basic Normal Plane.
|
247
|
+
GTEST_API_ std::string WideStringToUtf8(const wchar_t* str, int num_chars);
|
248
|
+
|
249
|
+
// Reads the GTEST_SHARD_STATUS_FILE environment variable, and creates the file
|
250
|
+
// if the variable is present. If a file already exists at this location, this
|
251
|
+
// function will write over it. If the variable is present, but the file cannot
|
252
|
+
// be created, prints an error and exits.
|
253
|
+
void WriteToShardStatusFileIfNeeded();
|
254
|
+
|
255
|
+
// Checks whether sharding is enabled by examining the relevant
|
256
|
+
// environment variable values. If the variables are present,
|
257
|
+
// but inconsistent (e.g., shard_index >= total_shards), prints
|
258
|
+
// an error and exits. If in_subprocess_for_death_test, sharding is
|
259
|
+
// disabled because it must only be applied to the original test
|
260
|
+
// process. Otherwise, we could filter out death tests we intended to execute.
|
261
|
+
GTEST_API_ bool ShouldShard(const char* total_shards_str,
|
262
|
+
const char* shard_index_str,
|
263
|
+
bool in_subprocess_for_death_test);
|
264
|
+
|
265
|
+
// Parses the environment variable var as an Int32. If it is unset,
|
266
|
+
// returns default_val. If it is not an Int32, prints an error and
|
267
|
+
// and aborts.
|
268
|
+
GTEST_API_ Int32 Int32FromEnvOrDie(const char* env_var, Int32 default_val);
|
269
|
+
|
270
|
+
// Given the total number of shards, the shard index, and the test id,
|
271
|
+
// returns true iff the test should be run on this shard. The test id is
|
272
|
+
// some arbitrary but unique non-negative integer assigned to each test
|
273
|
+
// method. Assumes that 0 <= shard_index < total_shards.
|
274
|
+
GTEST_API_ bool ShouldRunTestOnShard(
|
275
|
+
int total_shards, int shard_index, int test_id);
|
276
|
+
|
277
|
+
// STL container utilities.
|
278
|
+
|
279
|
+
// Returns the number of elements in the given container that satisfy
|
280
|
+
// the given predicate.
|
281
|
+
template <class Container, typename Predicate>
|
282
|
+
inline int CountIf(const Container& c, Predicate predicate) {
|
283
|
+
// Implemented as an explicit loop since std::count_if() in libCstd on
|
284
|
+
// Solaris has a non-standard signature.
|
285
|
+
int count = 0;
|
286
|
+
for (typename Container::const_iterator it = c.begin(); it != c.end(); ++it) {
|
287
|
+
if (predicate(*it))
|
288
|
+
++count;
|
289
|
+
}
|
290
|
+
return count;
|
291
|
+
}
|
292
|
+
|
293
|
+
// Applies a function/functor to each element in the container.
|
294
|
+
template <class Container, typename Functor>
|
295
|
+
void ForEach(const Container& c, Functor functor) {
|
296
|
+
std::for_each(c.begin(), c.end(), functor);
|
297
|
+
}
|
298
|
+
|
299
|
+
// Returns the i-th element of the vector, or default_value if i is not
|
300
|
+
// in range [0, v.size()).
|
301
|
+
template <typename E>
|
302
|
+
inline E GetElementOr(const std::vector<E>& v, int i, E default_value) {
|
303
|
+
return (i < 0 || i >= static_cast<int>(v.size())) ? default_value : v[i];
|
304
|
+
}
|
305
|
+
|
306
|
+
// Performs an in-place shuffle of a range of the vector's elements.
|
307
|
+
// 'begin' and 'end' are element indices as an STL-style range;
|
308
|
+
// i.e. [begin, end) are shuffled, where 'end' == size() means to
|
309
|
+
// shuffle to the end of the vector.
|
310
|
+
template <typename E>
|
311
|
+
void ShuffleRange(internal::Random* random, int begin, int end,
|
312
|
+
std::vector<E>* v) {
|
313
|
+
const int size = static_cast<int>(v->size());
|
314
|
+
GTEST_CHECK_(0 <= begin && begin <= size)
|
315
|
+
<< "Invalid shuffle range start " << begin << ": must be in range [0, "
|
316
|
+
<< size << "].";
|
317
|
+
GTEST_CHECK_(begin <= end && end <= size)
|
318
|
+
<< "Invalid shuffle range finish " << end << ": must be in range ["
|
319
|
+
<< begin << ", " << size << "].";
|
320
|
+
|
321
|
+
// Fisher-Yates shuffle, from
|
322
|
+
// http://en.wikipedia.org/wiki/Fisher-Yates_shuffle
|
323
|
+
for (int range_width = end - begin; range_width >= 2; range_width--) {
|
324
|
+
const int last_in_range = begin + range_width - 1;
|
325
|
+
const int selected = begin + random->Generate(range_width);
|
326
|
+
std::swap((*v)[selected], (*v)[last_in_range]);
|
327
|
+
}
|
328
|
+
}
|
329
|
+
|
330
|
+
// Performs an in-place shuffle of the vector's elements.
|
331
|
+
template <typename E>
|
332
|
+
inline void Shuffle(internal::Random* random, std::vector<E>* v) {
|
333
|
+
ShuffleRange(random, 0, static_cast<int>(v->size()), v);
|
334
|
+
}
|
335
|
+
|
336
|
+
// A function for deleting an object. Handy for being used as a
|
337
|
+
// functor.
|
338
|
+
template <typename T>
|
339
|
+
static void Delete(T* x) {
|
340
|
+
delete x;
|
341
|
+
}
|
342
|
+
|
343
|
+
// A predicate that checks the key of a TestProperty against a known key.
|
344
|
+
//
|
345
|
+
// TestPropertyKeyIs is copyable.
|
346
|
+
class TestPropertyKeyIs {
|
347
|
+
public:
|
348
|
+
// Constructor.
|
349
|
+
//
|
350
|
+
// TestPropertyKeyIs has NO default constructor.
|
351
|
+
explicit TestPropertyKeyIs(const std::string& key) : key_(key) {}
|
352
|
+
|
353
|
+
// Returns true iff the test name of test property matches on key_.
|
354
|
+
bool operator()(const TestProperty& test_property) const {
|
355
|
+
return test_property.key() == key_;
|
356
|
+
}
|
357
|
+
|
358
|
+
private:
|
359
|
+
std::string key_;
|
360
|
+
};
|
361
|
+
|
362
|
+
// Class UnitTestOptions.
|
363
|
+
//
|
364
|
+
// This class contains functions for processing options the user
|
365
|
+
// specifies when running the tests. It has only static members.
|
366
|
+
//
|
367
|
+
// In most cases, the user can specify an option using either an
|
368
|
+
// environment variable or a command line flag. E.g. you can set the
|
369
|
+
// test filter using either GTEST_FILTER or --gtest_filter. If both
|
370
|
+
// the variable and the flag are present, the latter overrides the
|
371
|
+
// former.
|
372
|
+
class GTEST_API_ UnitTestOptions {
|
373
|
+
public:
|
374
|
+
// Functions for processing the gtest_output flag.
|
375
|
+
|
376
|
+
// Returns the output format, or "" for normal printed output.
|
377
|
+
static std::string GetOutputFormat();
|
378
|
+
|
379
|
+
// Returns the absolute path of the requested output file, or the
|
380
|
+
// default (test_detail.xml in the original working directory) if
|
381
|
+
// none was explicitly specified.
|
382
|
+
static std::string GetAbsolutePathToOutputFile();
|
383
|
+
|
384
|
+
// Functions for processing the gtest_filter flag.
|
385
|
+
|
386
|
+
// Returns true iff the wildcard pattern matches the string. The
|
387
|
+
// first ':' or '\0' character in pattern marks the end of it.
|
388
|
+
//
|
389
|
+
// This recursive algorithm isn't very efficient, but is clear and
|
390
|
+
// works well enough for matching test names, which are short.
|
391
|
+
static bool PatternMatchesString(const char *pattern, const char *str);
|
392
|
+
|
393
|
+
// Returns true iff the user-specified filter matches the test case
|
394
|
+
// name and the test name.
|
395
|
+
static bool FilterMatchesTest(const std::string &test_case_name,
|
396
|
+
const std::string &test_name);
|
397
|
+
|
398
|
+
#if GTEST_OS_WINDOWS
|
399
|
+
// Function for supporting the gtest_catch_exception flag.
|
400
|
+
|
401
|
+
// Returns EXCEPTION_EXECUTE_HANDLER if Google Test should handle the
|
402
|
+
// given SEH exception, or EXCEPTION_CONTINUE_SEARCH otherwise.
|
403
|
+
// This function is useful as an __except condition.
|
404
|
+
static int GTestShouldProcessSEH(DWORD exception_code);
|
405
|
+
#endif // GTEST_OS_WINDOWS
|
406
|
+
|
407
|
+
// Returns true if "name" matches the ':' separated list of glob-style
|
408
|
+
// filters in "filter".
|
409
|
+
static bool MatchesFilter(const std::string& name, const char* filter);
|
410
|
+
};
|
411
|
+
|
412
|
+
// Returns the current application's name, removing directory path if that
|
413
|
+
// is present. Used by UnitTestOptions::GetOutputFile.
|
414
|
+
GTEST_API_ FilePath GetCurrentExecutableName();
|
415
|
+
|
416
|
+
// The role interface for getting the OS stack trace as a string.
|
417
|
+
class OsStackTraceGetterInterface {
|
418
|
+
public:
|
419
|
+
OsStackTraceGetterInterface() {}
|
420
|
+
virtual ~OsStackTraceGetterInterface() {}
|
421
|
+
|
422
|
+
// Returns the current OS stack trace as an std::string. Parameters:
|
423
|
+
//
|
424
|
+
// max_depth - the maximum number of stack frames to be included
|
425
|
+
// in the trace.
|
426
|
+
// skip_count - the number of top frames to be skipped; doesn't count
|
427
|
+
// against max_depth.
|
428
|
+
virtual string CurrentStackTrace(int max_depth, int skip_count) = 0;
|
429
|
+
|
430
|
+
// UponLeavingGTest() should be called immediately before Google Test calls
|
431
|
+
// user code. It saves some information about the current stack that
|
432
|
+
// CurrentStackTrace() will use to find and hide Google Test stack frames.
|
433
|
+
virtual void UponLeavingGTest() = 0;
|
434
|
+
|
435
|
+
private:
|
436
|
+
GTEST_DISALLOW_COPY_AND_ASSIGN_(OsStackTraceGetterInterface);
|
437
|
+
};
|
438
|
+
|
439
|
+
// A working implementation of the OsStackTraceGetterInterface interface.
|
440
|
+
class OsStackTraceGetter : public OsStackTraceGetterInterface {
|
441
|
+
public:
|
442
|
+
OsStackTraceGetter() : caller_frame_(NULL) {}
|
443
|
+
|
444
|
+
virtual string CurrentStackTrace(int max_depth, int skip_count)
|
445
|
+
GTEST_LOCK_EXCLUDED_(mutex_);
|
446
|
+
|
447
|
+
virtual void UponLeavingGTest() GTEST_LOCK_EXCLUDED_(mutex_);
|
448
|
+
|
449
|
+
// This string is inserted in place of stack frames that are part of
|
450
|
+
// Google Test's implementation.
|
451
|
+
static const char* const kElidedFramesMarker;
|
452
|
+
|
453
|
+
private:
|
454
|
+
Mutex mutex_; // protects all internal state
|
455
|
+
|
456
|
+
// We save the stack frame below the frame that calls user code.
|
457
|
+
// We do this because the address of the frame immediately below
|
458
|
+
// the user code changes between the call to UponLeavingGTest()
|
459
|
+
// and any calls to CurrentStackTrace() from within the user code.
|
460
|
+
void* caller_frame_;
|
461
|
+
|
462
|
+
GTEST_DISALLOW_COPY_AND_ASSIGN_(OsStackTraceGetter);
|
463
|
+
};
|
464
|
+
|
465
|
+
// Information about a Google Test trace point.
|
466
|
+
struct TraceInfo {
|
467
|
+
const char* file;
|
468
|
+
int line;
|
469
|
+
std::string message;
|
470
|
+
};
|
471
|
+
|
472
|
+
// This is the default global test part result reporter used in UnitTestImpl.
|
473
|
+
// This class should only be used by UnitTestImpl.
|
474
|
+
class DefaultGlobalTestPartResultReporter
|
475
|
+
: public TestPartResultReporterInterface {
|
476
|
+
public:
|
477
|
+
explicit DefaultGlobalTestPartResultReporter(UnitTestImpl* unit_test);
|
478
|
+
// Implements the TestPartResultReporterInterface. Reports the test part
|
479
|
+
// result in the current test.
|
480
|
+
virtual void ReportTestPartResult(const TestPartResult& result);
|
481
|
+
|
482
|
+
private:
|
483
|
+
UnitTestImpl* const unit_test_;
|
484
|
+
|
485
|
+
GTEST_DISALLOW_COPY_AND_ASSIGN_(DefaultGlobalTestPartResultReporter);
|
486
|
+
};
|
487
|
+
|
488
|
+
// This is the default per thread test part result reporter used in
|
489
|
+
// UnitTestImpl. This class should only be used by UnitTestImpl.
|
490
|
+
class DefaultPerThreadTestPartResultReporter
|
491
|
+
: public TestPartResultReporterInterface {
|
492
|
+
public:
|
493
|
+
explicit DefaultPerThreadTestPartResultReporter(UnitTestImpl* unit_test);
|
494
|
+
// Implements the TestPartResultReporterInterface. The implementation just
|
495
|
+
// delegates to the current global test part result reporter of *unit_test_.
|
496
|
+
virtual void ReportTestPartResult(const TestPartResult& result);
|
497
|
+
|
498
|
+
private:
|
499
|
+
UnitTestImpl* const unit_test_;
|
500
|
+
|
501
|
+
GTEST_DISALLOW_COPY_AND_ASSIGN_(DefaultPerThreadTestPartResultReporter);
|
502
|
+
};
|
503
|
+
|
504
|
+
// The private implementation of the UnitTest class. We don't protect
|
505
|
+
// the methods under a mutex, as this class is not accessible by a
|
506
|
+
// user and the UnitTest class that delegates work to this class does
|
507
|
+
// proper locking.
|
508
|
+
class GTEST_API_ UnitTestImpl {
|
509
|
+
public:
|
510
|
+
explicit UnitTestImpl(UnitTest* parent);
|
511
|
+
virtual ~UnitTestImpl();
|
512
|
+
|
513
|
+
// There are two different ways to register your own TestPartResultReporter.
|
514
|
+
// You can register your own repoter to listen either only for test results
|
515
|
+
// from the current thread or for results from all threads.
|
516
|
+
// By default, each per-thread test result repoter just passes a new
|
517
|
+
// TestPartResult to the global test result reporter, which registers the
|
518
|
+
// test part result for the currently running test.
|
519
|
+
|
520
|
+
// Returns the global test part result reporter.
|
521
|
+
TestPartResultReporterInterface* GetGlobalTestPartResultReporter();
|
522
|
+
|
523
|
+
// Sets the global test part result reporter.
|
524
|
+
void SetGlobalTestPartResultReporter(
|
525
|
+
TestPartResultReporterInterface* reporter);
|
526
|
+
|
527
|
+
// Returns the test part result reporter for the current thread.
|
528
|
+
TestPartResultReporterInterface* GetTestPartResultReporterForCurrentThread();
|
529
|
+
|
530
|
+
// Sets the test part result reporter for the current thread.
|
531
|
+
void SetTestPartResultReporterForCurrentThread(
|
532
|
+
TestPartResultReporterInterface* reporter);
|
533
|
+
|
534
|
+
// Gets the number of successful test cases.
|
535
|
+
int successful_test_case_count() const;
|
536
|
+
|
537
|
+
// Gets the number of failed test cases.
|
538
|
+
int failed_test_case_count() const;
|
539
|
+
|
540
|
+
// Gets the number of all test cases.
|
541
|
+
int total_test_case_count() const;
|
542
|
+
|
543
|
+
// Gets the number of all test cases that contain at least one test
|
544
|
+
// that should run.
|
545
|
+
int test_case_to_run_count() const;
|
546
|
+
|
547
|
+
// Gets the number of successful tests.
|
548
|
+
int successful_test_count() const;
|
549
|
+
|
550
|
+
// Gets the number of failed tests.
|
551
|
+
int failed_test_count() const;
|
552
|
+
|
553
|
+
// Gets the number of disabled tests that will be reported in the XML report.
|
554
|
+
int reportable_disabled_test_count() const;
|
555
|
+
|
556
|
+
// Gets the number of disabled tests.
|
557
|
+
int disabled_test_count() const;
|
558
|
+
|
559
|
+
// Gets the number of tests to be printed in the XML report.
|
560
|
+
int reportable_test_count() const;
|
561
|
+
|
562
|
+
// Gets the number of all tests.
|
563
|
+
int total_test_count() const;
|
564
|
+
|
565
|
+
// Gets the number of tests that should run.
|
566
|
+
int test_to_run_count() const;
|
567
|
+
|
568
|
+
// Gets the time of the test program start, in ms from the start of the
|
569
|
+
// UNIX epoch.
|
570
|
+
TimeInMillis start_timestamp() const { return start_timestamp_; }
|
571
|
+
|
572
|
+
// Gets the elapsed time, in milliseconds.
|
573
|
+
TimeInMillis elapsed_time() const { return elapsed_time_; }
|
574
|
+
|
575
|
+
// Returns true iff the unit test passed (i.e. all test cases passed).
|
576
|
+
bool Passed() const { return !Failed(); }
|
577
|
+
|
578
|
+
// Returns true iff the unit test failed (i.e. some test case failed
|
579
|
+
// or something outside of all tests failed).
|
580
|
+
bool Failed() const {
|
581
|
+
return failed_test_case_count() > 0 || ad_hoc_test_result()->Failed();
|
582
|
+
}
|
583
|
+
|
584
|
+
// Gets the i-th test case among all the test cases. i can range from 0 to
|
585
|
+
// total_test_case_count() - 1. If i is not in that range, returns NULL.
|
586
|
+
const TestCase* GetTestCase(int i) const {
|
587
|
+
const int index = GetElementOr(test_case_indices_, i, -1);
|
588
|
+
return index < 0 ? NULL : test_cases_[i];
|
589
|
+
}
|
590
|
+
|
591
|
+
// Gets the i-th test case among all the test cases. i can range from 0 to
|
592
|
+
// total_test_case_count() - 1. If i is not in that range, returns NULL.
|
593
|
+
TestCase* GetMutableTestCase(int i) {
|
594
|
+
const int index = GetElementOr(test_case_indices_, i, -1);
|
595
|
+
return index < 0 ? NULL : test_cases_[index];
|
596
|
+
}
|
597
|
+
|
598
|
+
// Provides access to the event listener list.
|
599
|
+
TestEventListeners* listeners() { return &listeners_; }
|
600
|
+
|
601
|
+
// Returns the TestResult for the test that's currently running, or
|
602
|
+
// the TestResult for the ad hoc test if no test is running.
|
603
|
+
TestResult* current_test_result();
|
604
|
+
|
605
|
+
// Returns the TestResult for the ad hoc test.
|
606
|
+
const TestResult* ad_hoc_test_result() const { return &ad_hoc_test_result_; }
|
607
|
+
|
608
|
+
// Sets the OS stack trace getter.
|
609
|
+
//
|
610
|
+
// Does nothing if the input and the current OS stack trace getter
|
611
|
+
// are the same; otherwise, deletes the old getter and makes the
|
612
|
+
// input the current getter.
|
613
|
+
void set_os_stack_trace_getter(OsStackTraceGetterInterface* getter);
|
614
|
+
|
615
|
+
// Returns the current OS stack trace getter if it is not NULL;
|
616
|
+
// otherwise, creates an OsStackTraceGetter, makes it the current
|
617
|
+
// getter, and returns it.
|
618
|
+
OsStackTraceGetterInterface* os_stack_trace_getter();
|
619
|
+
|
620
|
+
// Returns the current OS stack trace as an std::string.
|
621
|
+
//
|
622
|
+
// The maximum number of stack frames to be included is specified by
|
623
|
+
// the gtest_stack_trace_depth flag. The skip_count parameter
|
624
|
+
// specifies the number of top frames to be skipped, which doesn't
|
625
|
+
// count against the number of frames to be included.
|
626
|
+
//
|
627
|
+
// For example, if Foo() calls Bar(), which in turn calls
|
628
|
+
// CurrentOsStackTraceExceptTop(1), Foo() will be included in the
|
629
|
+
// trace but Bar() and CurrentOsStackTraceExceptTop() won't.
|
630
|
+
std::string CurrentOsStackTraceExceptTop(int skip_count) GTEST_NO_INLINE_;
|
631
|
+
|
632
|
+
// Finds and returns a TestCase with the given name. If one doesn't
|
633
|
+
// exist, creates one and returns it.
|
634
|
+
//
|
635
|
+
// Arguments:
|
636
|
+
//
|
637
|
+
// test_case_name: name of the test case
|
638
|
+
// type_param: the name of the test's type parameter, or NULL if
|
639
|
+
// this is not a typed or a type-parameterized test.
|
640
|
+
// set_up_tc: pointer to the function that sets up the test case
|
641
|
+
// tear_down_tc: pointer to the function that tears down the test case
|
642
|
+
TestCase* GetTestCase(const char* test_case_name,
|
643
|
+
const char* type_param,
|
644
|
+
Test::SetUpTestCaseFunc set_up_tc,
|
645
|
+
Test::TearDownTestCaseFunc tear_down_tc);
|
646
|
+
|
647
|
+
// Adds a TestInfo to the unit test.
|
648
|
+
//
|
649
|
+
// Arguments:
|
650
|
+
//
|
651
|
+
// set_up_tc: pointer to the function that sets up the test case
|
652
|
+
// tear_down_tc: pointer to the function that tears down the test case
|
653
|
+
// test_info: the TestInfo object
|
654
|
+
void AddTestInfo(Test::SetUpTestCaseFunc set_up_tc,
|
655
|
+
Test::TearDownTestCaseFunc tear_down_tc,
|
656
|
+
TestInfo* test_info) {
|
657
|
+
// In order to support thread-safe death tests, we need to
|
658
|
+
// remember the original working directory when the test program
|
659
|
+
// was first invoked. We cannot do this in RUN_ALL_TESTS(), as
|
660
|
+
// the user may have changed the current directory before calling
|
661
|
+
// RUN_ALL_TESTS(). Therefore we capture the current directory in
|
662
|
+
// AddTestInfo(), which is called to register a TEST or TEST_F
|
663
|
+
// before main() is reached.
|
664
|
+
if (original_working_dir_.IsEmpty()) {
|
665
|
+
original_working_dir_.Set(FilePath::GetCurrentDir());
|
666
|
+
GTEST_CHECK_(!original_working_dir_.IsEmpty())
|
667
|
+
<< "Failed to get the current working directory.";
|
668
|
+
}
|
669
|
+
|
670
|
+
GetTestCase(test_info->test_case_name(),
|
671
|
+
test_info->type_param(),
|
672
|
+
set_up_tc,
|
673
|
+
tear_down_tc)->AddTestInfo(test_info);
|
674
|
+
}
|
675
|
+
|
676
|
+
#if GTEST_HAS_PARAM_TEST
|
677
|
+
// Returns ParameterizedTestCaseRegistry object used to keep track of
|
678
|
+
// value-parameterized tests and instantiate and register them.
|
679
|
+
internal::ParameterizedTestCaseRegistry& parameterized_test_registry() {
|
680
|
+
return parameterized_test_registry_;
|
681
|
+
}
|
682
|
+
#endif // GTEST_HAS_PARAM_TEST
|
683
|
+
|
684
|
+
// Sets the TestCase object for the test that's currently running.
|
685
|
+
void set_current_test_case(TestCase* a_current_test_case) {
|
686
|
+
current_test_case_ = a_current_test_case;
|
687
|
+
}
|
688
|
+
|
689
|
+
// Sets the TestInfo object for the test that's currently running. If
|
690
|
+
// current_test_info is NULL, the assertion results will be stored in
|
691
|
+
// ad_hoc_test_result_.
|
692
|
+
void set_current_test_info(TestInfo* a_current_test_info) {
|
693
|
+
current_test_info_ = a_current_test_info;
|
694
|
+
}
|
695
|
+
|
696
|
+
// Registers all parameterized tests defined using TEST_P and
|
697
|
+
// INSTANTIATE_TEST_CASE_P, creating regular tests for each test/parameter
|
698
|
+
// combination. This method can be called more then once; it has guards
|
699
|
+
// protecting from registering the tests more then once. If
|
700
|
+
// value-parameterized tests are disabled, RegisterParameterizedTests is
|
701
|
+
// present but does nothing.
|
702
|
+
void RegisterParameterizedTests();
|
703
|
+
|
704
|
+
// Runs all tests in this UnitTest object, prints the result, and
|
705
|
+
// returns true if all tests are successful. If any exception is
|
706
|
+
// thrown during a test, this test is considered to be failed, but
|
707
|
+
// the rest of the tests will still be run.
|
708
|
+
bool RunAllTests();
|
709
|
+
|
710
|
+
// Clears the results of all tests, except the ad hoc tests.
|
711
|
+
void ClearNonAdHocTestResult() {
|
712
|
+
ForEach(test_cases_, TestCase::ClearTestCaseResult);
|
713
|
+
}
|
714
|
+
|
715
|
+
// Clears the results of ad-hoc test assertions.
|
716
|
+
void ClearAdHocTestResult() {
|
717
|
+
ad_hoc_test_result_.Clear();
|
718
|
+
}
|
719
|
+
|
720
|
+
// Adds a TestProperty to the current TestResult object when invoked in a
|
721
|
+
// context of a test or a test case, or to the global property set. If the
|
722
|
+
// result already contains a property with the same key, the value will be
|
723
|
+
// updated.
|
724
|
+
void RecordProperty(const TestProperty& test_property);
|
725
|
+
|
726
|
+
enum ReactionToSharding {
|
727
|
+
HONOR_SHARDING_PROTOCOL,
|
728
|
+
IGNORE_SHARDING_PROTOCOL
|
729
|
+
};
|
730
|
+
|
731
|
+
// Matches the full name of each test against the user-specified
|
732
|
+
// filter to decide whether the test should run, then records the
|
733
|
+
// result in each TestCase and TestInfo object.
|
734
|
+
// If shard_tests == HONOR_SHARDING_PROTOCOL, further filters tests
|
735
|
+
// based on sharding variables in the environment.
|
736
|
+
// Returns the number of tests that should run.
|
737
|
+
int FilterTests(ReactionToSharding shard_tests);
|
738
|
+
|
739
|
+
// Prints the names of the tests matching the user-specified filter flag.
|
740
|
+
void ListTestsMatchingFilter();
|
741
|
+
|
742
|
+
const TestCase* current_test_case() const { return current_test_case_; }
|
743
|
+
TestInfo* current_test_info() { return current_test_info_; }
|
744
|
+
const TestInfo* current_test_info() const { return current_test_info_; }
|
745
|
+
|
746
|
+
// Returns the vector of environments that need to be set-up/torn-down
|
747
|
+
// before/after the tests are run.
|
748
|
+
std::vector<Environment*>& environments() { return environments_; }
|
749
|
+
|
750
|
+
// Getters for the per-thread Google Test trace stack.
|
751
|
+
std::vector<TraceInfo>& gtest_trace_stack() {
|
752
|
+
return *(gtest_trace_stack_.pointer());
|
753
|
+
}
|
754
|
+
const std::vector<TraceInfo>& gtest_trace_stack() const {
|
755
|
+
return gtest_trace_stack_.get();
|
756
|
+
}
|
757
|
+
|
758
|
+
#if GTEST_HAS_DEATH_TEST
|
759
|
+
void InitDeathTestSubprocessControlInfo() {
|
760
|
+
internal_run_death_test_flag_.reset(ParseInternalRunDeathTestFlag());
|
761
|
+
}
|
762
|
+
// Returns a pointer to the parsed --gtest_internal_run_death_test
|
763
|
+
// flag, or NULL if that flag was not specified.
|
764
|
+
// This information is useful only in a death test child process.
|
765
|
+
// Must not be called before a call to InitGoogleTest.
|
766
|
+
const InternalRunDeathTestFlag* internal_run_death_test_flag() const {
|
767
|
+
return internal_run_death_test_flag_.get();
|
768
|
+
}
|
769
|
+
|
770
|
+
// Returns a pointer to the current death test factory.
|
771
|
+
internal::DeathTestFactory* death_test_factory() {
|
772
|
+
return death_test_factory_.get();
|
773
|
+
}
|
774
|
+
|
775
|
+
void SuppressTestEventsIfInSubprocess();
|
776
|
+
|
777
|
+
friend class ReplaceDeathTestFactory;
|
778
|
+
#endif // GTEST_HAS_DEATH_TEST
|
779
|
+
|
780
|
+
// Initializes the event listener performing XML output as specified by
|
781
|
+
// UnitTestOptions. Must not be called before InitGoogleTest.
|
782
|
+
void ConfigureXmlOutput();
|
783
|
+
|
784
|
+
#if GTEST_CAN_STREAM_RESULTS_
|
785
|
+
// Initializes the event listener for streaming test results to a socket.
|
786
|
+
// Must not be called before InitGoogleTest.
|
787
|
+
void ConfigureStreamingOutput();
|
788
|
+
#endif
|
789
|
+
|
790
|
+
// Performs initialization dependent upon flag values obtained in
|
791
|
+
// ParseGoogleTestFlagsOnly. Is called from InitGoogleTest after the call to
|
792
|
+
// ParseGoogleTestFlagsOnly. In case a user neglects to call InitGoogleTest
|
793
|
+
// this function is also called from RunAllTests. Since this function can be
|
794
|
+
// called more than once, it has to be idempotent.
|
795
|
+
void PostFlagParsingInit();
|
796
|
+
|
797
|
+
// Gets the random seed used at the start of the current test iteration.
|
798
|
+
int random_seed() const { return random_seed_; }
|
799
|
+
|
800
|
+
// Gets the random number generator.
|
801
|
+
internal::Random* random() { return &random_; }
|
802
|
+
|
803
|
+
// Shuffles all test cases, and the tests within each test case,
|
804
|
+
// making sure that death tests are still run first.
|
805
|
+
void ShuffleTests();
|
806
|
+
|
807
|
+
// Restores the test cases and tests to their order before the first shuffle.
|
808
|
+
void UnshuffleTests();
|
809
|
+
|
810
|
+
// Returns the value of GTEST_FLAG(catch_exceptions) at the moment
|
811
|
+
// UnitTest::Run() starts.
|
812
|
+
bool catch_exceptions() const { return catch_exceptions_; }
|
813
|
+
|
814
|
+
private:
|
815
|
+
friend class ::testing::UnitTest;
|
816
|
+
|
817
|
+
// Used by UnitTest::Run() to capture the state of
|
818
|
+
// GTEST_FLAG(catch_exceptions) at the moment it starts.
|
819
|
+
void set_catch_exceptions(bool value) { catch_exceptions_ = value; }
|
820
|
+
|
821
|
+
// The UnitTest object that owns this implementation object.
|
822
|
+
UnitTest* const parent_;
|
823
|
+
|
824
|
+
// The working directory when the first TEST() or TEST_F() was
|
825
|
+
// executed.
|
826
|
+
internal::FilePath original_working_dir_;
|
827
|
+
|
828
|
+
// The default test part result reporters.
|
829
|
+
DefaultGlobalTestPartResultReporter default_global_test_part_result_reporter_;
|
830
|
+
DefaultPerThreadTestPartResultReporter
|
831
|
+
default_per_thread_test_part_result_reporter_;
|
832
|
+
|
833
|
+
// Points to (but doesn't own) the global test part result reporter.
|
834
|
+
TestPartResultReporterInterface* global_test_part_result_repoter_;
|
835
|
+
|
836
|
+
// Protects read and write access to global_test_part_result_reporter_.
|
837
|
+
internal::Mutex global_test_part_result_reporter_mutex_;
|
838
|
+
|
839
|
+
// Points to (but doesn't own) the per-thread test part result reporter.
|
840
|
+
internal::ThreadLocal<TestPartResultReporterInterface*>
|
841
|
+
per_thread_test_part_result_reporter_;
|
842
|
+
|
843
|
+
// The vector of environments that need to be set-up/torn-down
|
844
|
+
// before/after the tests are run.
|
845
|
+
std::vector<Environment*> environments_;
|
846
|
+
|
847
|
+
// The vector of TestCases in their original order. It owns the
|
848
|
+
// elements in the vector.
|
849
|
+
std::vector<TestCase*> test_cases_;
|
850
|
+
|
851
|
+
// Provides a level of indirection for the test case list to allow
|
852
|
+
// easy shuffling and restoring the test case order. The i-th
|
853
|
+
// element of this vector is the index of the i-th test case in the
|
854
|
+
// shuffled order.
|
855
|
+
std::vector<int> test_case_indices_;
|
856
|
+
|
857
|
+
#if GTEST_HAS_PARAM_TEST
|
858
|
+
// ParameterizedTestRegistry object used to register value-parameterized
|
859
|
+
// tests.
|
860
|
+
internal::ParameterizedTestCaseRegistry parameterized_test_registry_;
|
861
|
+
|
862
|
+
// Indicates whether RegisterParameterizedTests() has been called already.
|
863
|
+
bool parameterized_tests_registered_;
|
864
|
+
#endif // GTEST_HAS_PARAM_TEST
|
865
|
+
|
866
|
+
// Index of the last death test case registered. Initially -1.
|
867
|
+
int last_death_test_case_;
|
868
|
+
|
869
|
+
// This points to the TestCase for the currently running test. It
|
870
|
+
// changes as Google Test goes through one test case after another.
|
871
|
+
// When no test is running, this is set to NULL and Google Test
|
872
|
+
// stores assertion results in ad_hoc_test_result_. Initially NULL.
|
873
|
+
TestCase* current_test_case_;
|
874
|
+
|
875
|
+
// This points to the TestInfo for the currently running test. It
|
876
|
+
// changes as Google Test goes through one test after another. When
|
877
|
+
// no test is running, this is set to NULL and Google Test stores
|
878
|
+
// assertion results in ad_hoc_test_result_. Initially NULL.
|
879
|
+
TestInfo* current_test_info_;
|
880
|
+
|
881
|
+
// Normally, a user only writes assertions inside a TEST or TEST_F,
|
882
|
+
// or inside a function called by a TEST or TEST_F. Since Google
|
883
|
+
// Test keeps track of which test is current running, it can
|
884
|
+
// associate such an assertion with the test it belongs to.
|
885
|
+
//
|
886
|
+
// If an assertion is encountered when no TEST or TEST_F is running,
|
887
|
+
// Google Test attributes the assertion result to an imaginary "ad hoc"
|
888
|
+
// test, and records the result in ad_hoc_test_result_.
|
889
|
+
TestResult ad_hoc_test_result_;
|
890
|
+
|
891
|
+
// The list of event listeners that can be used to track events inside
|
892
|
+
// Google Test.
|
893
|
+
TestEventListeners listeners_;
|
894
|
+
|
895
|
+
// The OS stack trace getter. Will be deleted when the UnitTest
|
896
|
+
// object is destructed. By default, an OsStackTraceGetter is used,
|
897
|
+
// but the user can set this field to use a custom getter if that is
|
898
|
+
// desired.
|
899
|
+
OsStackTraceGetterInterface* os_stack_trace_getter_;
|
900
|
+
|
901
|
+
// True iff PostFlagParsingInit() has been called.
|
902
|
+
bool post_flag_parse_init_performed_;
|
903
|
+
|
904
|
+
// The random number seed used at the beginning of the test run.
|
905
|
+
int random_seed_;
|
906
|
+
|
907
|
+
// Our random number generator.
|
908
|
+
internal::Random random_;
|
909
|
+
|
910
|
+
// The time of the test program start, in ms from the start of the
|
911
|
+
// UNIX epoch.
|
912
|
+
TimeInMillis start_timestamp_;
|
913
|
+
|
914
|
+
// How long the test took to run, in milliseconds.
|
915
|
+
TimeInMillis elapsed_time_;
|
916
|
+
|
917
|
+
#if GTEST_HAS_DEATH_TEST
|
918
|
+
// The decomposed components of the gtest_internal_run_death_test flag,
|
919
|
+
// parsed when RUN_ALL_TESTS is called.
|
920
|
+
internal::scoped_ptr<InternalRunDeathTestFlag> internal_run_death_test_flag_;
|
921
|
+
internal::scoped_ptr<internal::DeathTestFactory> death_test_factory_;
|
922
|
+
#endif // GTEST_HAS_DEATH_TEST
|
923
|
+
|
924
|
+
// A per-thread stack of traces created by the SCOPED_TRACE() macro.
|
925
|
+
internal::ThreadLocal<std::vector<TraceInfo> > gtest_trace_stack_;
|
926
|
+
|
927
|
+
// The value of GTEST_FLAG(catch_exceptions) at the moment RunAllTests()
|
928
|
+
// starts.
|
929
|
+
bool catch_exceptions_;
|
930
|
+
|
931
|
+
GTEST_DISALLOW_COPY_AND_ASSIGN_(UnitTestImpl);
|
932
|
+
}; // class UnitTestImpl
|
933
|
+
|
934
|
+
// Convenience function for accessing the global UnitTest
|
935
|
+
// implementation object.
|
936
|
+
inline UnitTestImpl* GetUnitTestImpl() {
|
937
|
+
return UnitTest::GetInstance()->impl();
|
938
|
+
}
|
939
|
+
|
940
|
+
#if GTEST_USES_SIMPLE_RE
|
941
|
+
|
942
|
+
// Internal helper functions for implementing the simple regular
|
943
|
+
// expression matcher.
|
944
|
+
GTEST_API_ bool IsInSet(char ch, const char* str);
|
945
|
+
GTEST_API_ bool IsAsciiDigit(char ch);
|
946
|
+
GTEST_API_ bool IsAsciiPunct(char ch);
|
947
|
+
GTEST_API_ bool IsRepeat(char ch);
|
948
|
+
GTEST_API_ bool IsAsciiWhiteSpace(char ch);
|
949
|
+
GTEST_API_ bool IsAsciiWordChar(char ch);
|
950
|
+
GTEST_API_ bool IsValidEscape(char ch);
|
951
|
+
GTEST_API_ bool AtomMatchesChar(bool escaped, char pattern, char ch);
|
952
|
+
GTEST_API_ bool ValidateRegex(const char* regex);
|
953
|
+
GTEST_API_ bool MatchRegexAtHead(const char* regex, const char* str);
|
954
|
+
GTEST_API_ bool MatchRepetitionAndRegexAtHead(
|
955
|
+
bool escaped, char ch, char repeat, const char* regex, const char* str);
|
956
|
+
GTEST_API_ bool MatchRegexAnywhere(const char* regex, const char* str);
|
957
|
+
|
958
|
+
#endif // GTEST_USES_SIMPLE_RE
|
959
|
+
|
960
|
+
// Parses the command line for Google Test flags, without initializing
|
961
|
+
// other parts of Google Test.
|
962
|
+
GTEST_API_ void ParseGoogleTestFlagsOnly(int* argc, char** argv);
|
963
|
+
GTEST_API_ void ParseGoogleTestFlagsOnly(int* argc, wchar_t** argv);
|
964
|
+
|
965
|
+
#if GTEST_HAS_DEATH_TEST
|
966
|
+
|
967
|
+
// Returns the message describing the last system error, regardless of the
|
968
|
+
// platform.
|
969
|
+
GTEST_API_ std::string GetLastErrnoDescription();
|
970
|
+
|
971
|
+
# if GTEST_OS_WINDOWS
|
972
|
+
// Provides leak-safe Windows kernel handle ownership.
|
973
|
+
class AutoHandle {
|
974
|
+
public:
|
975
|
+
AutoHandle() : handle_(INVALID_HANDLE_VALUE) {}
|
976
|
+
explicit AutoHandle(HANDLE handle) : handle_(handle) {}
|
977
|
+
|
978
|
+
~AutoHandle() { Reset(); }
|
979
|
+
|
980
|
+
HANDLE Get() const { return handle_; }
|
981
|
+
void Reset() { Reset(INVALID_HANDLE_VALUE); }
|
982
|
+
void Reset(HANDLE handle) {
|
983
|
+
if (handle != handle_) {
|
984
|
+
if (handle_ != INVALID_HANDLE_VALUE)
|
985
|
+
::CloseHandle(handle_);
|
986
|
+
handle_ = handle;
|
987
|
+
}
|
988
|
+
}
|
989
|
+
|
990
|
+
private:
|
991
|
+
HANDLE handle_;
|
992
|
+
|
993
|
+
GTEST_DISALLOW_COPY_AND_ASSIGN_(AutoHandle);
|
994
|
+
};
|
995
|
+
# endif // GTEST_OS_WINDOWS
|
996
|
+
|
997
|
+
// Attempts to parse a string into a positive integer pointed to by the
|
998
|
+
// number parameter. Returns true if that is possible.
|
999
|
+
// GTEST_HAS_DEATH_TEST implies that we have ::std::string, so we can use
|
1000
|
+
// it here.
|
1001
|
+
template <typename Integer>
|
1002
|
+
bool ParseNaturalNumber(const ::std::string& str, Integer* number) {
|
1003
|
+
// Fail fast if the given string does not begin with a digit;
|
1004
|
+
// this bypasses strtoXXX's "optional leading whitespace and plus
|
1005
|
+
// or minus sign" semantics, which are undesirable here.
|
1006
|
+
if (str.empty() || !IsDigit(str[0])) {
|
1007
|
+
return false;
|
1008
|
+
}
|
1009
|
+
errno = 0;
|
1010
|
+
|
1011
|
+
char* end;
|
1012
|
+
// BiggestConvertible is the largest integer type that system-provided
|
1013
|
+
// string-to-number conversion routines can return.
|
1014
|
+
|
1015
|
+
# if GTEST_OS_WINDOWS && !defined(__GNUC__)
|
1016
|
+
|
1017
|
+
// MSVC and C++ Builder define __int64 instead of the standard long long.
|
1018
|
+
typedef unsigned __int64 BiggestConvertible;
|
1019
|
+
const BiggestConvertible parsed = _strtoui64(str.c_str(), &end, 10);
|
1020
|
+
|
1021
|
+
# else
|
1022
|
+
|
1023
|
+
typedef unsigned long long BiggestConvertible; // NOLINT
|
1024
|
+
const BiggestConvertible parsed = strtoull(str.c_str(), &end, 10);
|
1025
|
+
|
1026
|
+
# endif // GTEST_OS_WINDOWS && !defined(__GNUC__)
|
1027
|
+
|
1028
|
+
const bool parse_success = *end == '\0' && errno == 0;
|
1029
|
+
|
1030
|
+
// TODO(vladl@google.com): Convert this to compile time assertion when it is
|
1031
|
+
// available.
|
1032
|
+
GTEST_CHECK_(sizeof(Integer) <= sizeof(parsed));
|
1033
|
+
|
1034
|
+
const Integer result = static_cast<Integer>(parsed);
|
1035
|
+
if (parse_success && static_cast<BiggestConvertible>(result) == parsed) {
|
1036
|
+
*number = result;
|
1037
|
+
return true;
|
1038
|
+
}
|
1039
|
+
return false;
|
1040
|
+
}
|
1041
|
+
#endif // GTEST_HAS_DEATH_TEST
|
1042
|
+
|
1043
|
+
// TestResult contains some private methods that should be hidden from
|
1044
|
+
// Google Test user but are required for testing. This class allow our tests
|
1045
|
+
// to access them.
|
1046
|
+
//
|
1047
|
+
// This class is supplied only for the purpose of testing Google Test's own
|
1048
|
+
// constructs. Do not use it in user tests, either directly or indirectly.
|
1049
|
+
class TestResultAccessor {
|
1050
|
+
public:
|
1051
|
+
static void RecordProperty(TestResult* test_result,
|
1052
|
+
const std::string& xml_element,
|
1053
|
+
const TestProperty& property) {
|
1054
|
+
test_result->RecordProperty(xml_element, property);
|
1055
|
+
}
|
1056
|
+
|
1057
|
+
static void ClearTestPartResults(TestResult* test_result) {
|
1058
|
+
test_result->ClearTestPartResults();
|
1059
|
+
}
|
1060
|
+
|
1061
|
+
static const std::vector<testing::TestPartResult>& test_part_results(
|
1062
|
+
const TestResult& test_result) {
|
1063
|
+
return test_result.test_part_results();
|
1064
|
+
}
|
1065
|
+
};
|
1066
|
+
|
1067
|
+
#if GTEST_CAN_STREAM_RESULTS_
|
1068
|
+
|
1069
|
+
// Streams test results to the given port on the given host machine.
|
1070
|
+
class StreamingListener : public EmptyTestEventListener {
|
1071
|
+
public:
|
1072
|
+
// Abstract base class for writing strings to a socket.
|
1073
|
+
class AbstractSocketWriter {
|
1074
|
+
public:
|
1075
|
+
virtual ~AbstractSocketWriter() {}
|
1076
|
+
|
1077
|
+
// Sends a string to the socket.
|
1078
|
+
virtual void Send(const string& message) = 0;
|
1079
|
+
|
1080
|
+
// Closes the socket.
|
1081
|
+
virtual void CloseConnection() {}
|
1082
|
+
|
1083
|
+
// Sends a string and a newline to the socket.
|
1084
|
+
void SendLn(const string& message) {
|
1085
|
+
Send(message + "\n");
|
1086
|
+
}
|
1087
|
+
};
|
1088
|
+
|
1089
|
+
// Concrete class for actually writing strings to a socket.
|
1090
|
+
class SocketWriter : public AbstractSocketWriter {
|
1091
|
+
public:
|
1092
|
+
SocketWriter(const string& host, const string& port)
|
1093
|
+
: sockfd_(-1), host_name_(host), port_num_(port) {
|
1094
|
+
MakeConnection();
|
1095
|
+
}
|
1096
|
+
|
1097
|
+
virtual ~SocketWriter() {
|
1098
|
+
if (sockfd_ != -1)
|
1099
|
+
CloseConnection();
|
1100
|
+
}
|
1101
|
+
|
1102
|
+
// Sends a string to the socket.
|
1103
|
+
virtual void Send(const string& message) {
|
1104
|
+
GTEST_CHECK_(sockfd_ != -1)
|
1105
|
+
<< "Send() can be called only when there is a connection.";
|
1106
|
+
|
1107
|
+
const int len = static_cast<int>(message.length());
|
1108
|
+
if (write(sockfd_, message.c_str(), len) != len) {
|
1109
|
+
GTEST_LOG_(WARNING)
|
1110
|
+
<< "stream_result_to: failed to stream to "
|
1111
|
+
<< host_name_ << ":" << port_num_;
|
1112
|
+
}
|
1113
|
+
}
|
1114
|
+
|
1115
|
+
private:
|
1116
|
+
// Creates a client socket and connects to the server.
|
1117
|
+
void MakeConnection();
|
1118
|
+
|
1119
|
+
// Closes the socket.
|
1120
|
+
void CloseConnection() {
|
1121
|
+
GTEST_CHECK_(sockfd_ != -1)
|
1122
|
+
<< "CloseConnection() can be called only when there is a connection.";
|
1123
|
+
|
1124
|
+
close(sockfd_);
|
1125
|
+
sockfd_ = -1;
|
1126
|
+
}
|
1127
|
+
|
1128
|
+
int sockfd_; // socket file descriptor
|
1129
|
+
const string host_name_;
|
1130
|
+
const string port_num_;
|
1131
|
+
|
1132
|
+
GTEST_DISALLOW_COPY_AND_ASSIGN_(SocketWriter);
|
1133
|
+
}; // class SocketWriter
|
1134
|
+
|
1135
|
+
// Escapes '=', '&', '%', and '\n' characters in str as "%xx".
|
1136
|
+
static string UrlEncode(const char* str);
|
1137
|
+
|
1138
|
+
StreamingListener(const string& host, const string& port)
|
1139
|
+
: socket_writer_(new SocketWriter(host, port)) { Start(); }
|
1140
|
+
|
1141
|
+
explicit StreamingListener(AbstractSocketWriter* socket_writer)
|
1142
|
+
: socket_writer_(socket_writer) { Start(); }
|
1143
|
+
|
1144
|
+
void OnTestProgramStart(const UnitTest& /* unit_test */) {
|
1145
|
+
SendLn("event=TestProgramStart");
|
1146
|
+
}
|
1147
|
+
|
1148
|
+
void OnTestProgramEnd(const UnitTest& unit_test) {
|
1149
|
+
// Note that Google Test current only report elapsed time for each
|
1150
|
+
// test iteration, not for the entire test program.
|
1151
|
+
SendLn("event=TestProgramEnd&passed=" + FormatBool(unit_test.Passed()));
|
1152
|
+
|
1153
|
+
// Notify the streaming server to stop.
|
1154
|
+
socket_writer_->CloseConnection();
|
1155
|
+
}
|
1156
|
+
|
1157
|
+
void OnTestIterationStart(const UnitTest& /* unit_test */, int iteration) {
|
1158
|
+
SendLn("event=TestIterationStart&iteration=" +
|
1159
|
+
StreamableToString(iteration));
|
1160
|
+
}
|
1161
|
+
|
1162
|
+
void OnTestIterationEnd(const UnitTest& unit_test, int /* iteration */) {
|
1163
|
+
SendLn("event=TestIterationEnd&passed=" +
|
1164
|
+
FormatBool(unit_test.Passed()) + "&elapsed_time=" +
|
1165
|
+
StreamableToString(unit_test.elapsed_time()) + "ms");
|
1166
|
+
}
|
1167
|
+
|
1168
|
+
void OnTestCaseStart(const TestCase& test_case) {
|
1169
|
+
SendLn(std::string("event=TestCaseStart&name=") + test_case.name());
|
1170
|
+
}
|
1171
|
+
|
1172
|
+
void OnTestCaseEnd(const TestCase& test_case) {
|
1173
|
+
SendLn("event=TestCaseEnd&passed=" + FormatBool(test_case.Passed())
|
1174
|
+
+ "&elapsed_time=" + StreamableToString(test_case.elapsed_time())
|
1175
|
+
+ "ms");
|
1176
|
+
}
|
1177
|
+
|
1178
|
+
void OnTestStart(const TestInfo& test_info) {
|
1179
|
+
SendLn(std::string("event=TestStart&name=") + test_info.name());
|
1180
|
+
}
|
1181
|
+
|
1182
|
+
void OnTestEnd(const TestInfo& test_info) {
|
1183
|
+
SendLn("event=TestEnd&passed=" +
|
1184
|
+
FormatBool((test_info.result())->Passed()) +
|
1185
|
+
"&elapsed_time=" +
|
1186
|
+
StreamableToString((test_info.result())->elapsed_time()) + "ms");
|
1187
|
+
}
|
1188
|
+
|
1189
|
+
void OnTestPartResult(const TestPartResult& test_part_result) {
|
1190
|
+
const char* file_name = test_part_result.file_name();
|
1191
|
+
if (file_name == NULL)
|
1192
|
+
file_name = "";
|
1193
|
+
SendLn("event=TestPartResult&file=" + UrlEncode(file_name) +
|
1194
|
+
"&line=" + StreamableToString(test_part_result.line_number()) +
|
1195
|
+
"&message=" + UrlEncode(test_part_result.message()));
|
1196
|
+
}
|
1197
|
+
|
1198
|
+
private:
|
1199
|
+
// Sends the given message and a newline to the socket.
|
1200
|
+
void SendLn(const string& message) { socket_writer_->SendLn(message); }
|
1201
|
+
|
1202
|
+
// Called at the start of streaming to notify the receiver what
|
1203
|
+
// protocol we are using.
|
1204
|
+
void Start() { SendLn("gtest_streaming_protocol_version=1.0"); }
|
1205
|
+
|
1206
|
+
string FormatBool(bool value) { return value ? "1" : "0"; }
|
1207
|
+
|
1208
|
+
const scoped_ptr<AbstractSocketWriter> socket_writer_;
|
1209
|
+
|
1210
|
+
GTEST_DISALLOW_COPY_AND_ASSIGN_(StreamingListener);
|
1211
|
+
}; // class StreamingListener
|
1212
|
+
|
1213
|
+
#endif // GTEST_CAN_STREAM_RESULTS_
|
1214
|
+
|
1215
|
+
} // namespace internal
|
1216
|
+
} // namespace testing
|
1217
|
+
|
1218
|
+
#endif // GTEST_SRC_GTEST_INTERNAL_INL_H_
|