rn-leveldb 3.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (595) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +92 -0
  3. package/android/.project +34 -0
  4. package/android/.settings/org.eclipse.buildship.core.prefs +13 -0
  5. package/android/CMakeLists.txt +69 -0
  6. package/android/build.gradle +125 -0
  7. package/android/cpp-adapter.cpp +19 -0
  8. package/android/gradle.properties +6 -0
  9. package/android/src/main/AndroidManifest.xml +4 -0
  10. package/android/src/main/java/com/reactnativeleveldb/LeveldbModule.java +57 -0
  11. package/android/src/main/java/com/reactnativeleveldb/LeveldbPackage.java +28 -0
  12. package/cpp/leveldb/.appveyor.yml +36 -0
  13. package/cpp/leveldb/.clang-format +18 -0
  14. package/cpp/leveldb/.travis.yml +88 -0
  15. package/cpp/leveldb/AUTHORS +12 -0
  16. package/cpp/leveldb/CMakeLists.txt +495 -0
  17. package/cpp/leveldb/CONTRIBUTING.md +36 -0
  18. package/cpp/leveldb/LICENSE +27 -0
  19. package/cpp/leveldb/NEWS +17 -0
  20. package/cpp/leveldb/README.md +231 -0
  21. package/cpp/leveldb/TODO +14 -0
  22. package/cpp/leveldb/benchmarks/db_bench.cc +990 -0
  23. package/cpp/leveldb/benchmarks/db_bench_sqlite3.cc +726 -0
  24. package/cpp/leveldb/benchmarks/db_bench_tree_db.cc +531 -0
  25. package/cpp/leveldb/cmake/leveldbConfig.cmake.in +9 -0
  26. package/cpp/leveldb/db/autocompact_test.cc +115 -0
  27. package/cpp/leveldb/db/builder.cc +82 -0
  28. package/cpp/leveldb/db/builder.h +30 -0
  29. package/cpp/leveldb/db/c.cc +562 -0
  30. package/cpp/leveldb/db/c_test.c +384 -0
  31. package/cpp/leveldb/db/corruption_test.cc +367 -0
  32. package/cpp/leveldb/db/db_impl.cc +1554 -0
  33. package/cpp/leveldb/db/db_impl.h +217 -0
  34. package/cpp/leveldb/db/db_iter.cc +318 -0
  35. package/cpp/leveldb/db/db_iter.h +26 -0
  36. package/cpp/leveldb/db/db_test.cc +2305 -0
  37. package/cpp/leveldb/db/dbformat.cc +136 -0
  38. package/cpp/leveldb/db/dbformat.h +224 -0
  39. package/cpp/leveldb/db/dbformat_test.cc +133 -0
  40. package/cpp/leveldb/db/dumpfile.cc +232 -0
  41. package/cpp/leveldb/db/fault_injection_test.cc +555 -0
  42. package/cpp/leveldb/db/filename.cc +141 -0
  43. package/cpp/leveldb/db/filename.h +83 -0
  44. package/cpp/leveldb/db/filename_test.cc +132 -0
  45. package/cpp/leveldb/db/leveldbutil.cc +64 -0
  46. package/cpp/leveldb/db/log_format.h +35 -0
  47. package/cpp/leveldb/db/log_reader.cc +274 -0
  48. package/cpp/leveldb/db/log_reader.h +112 -0
  49. package/cpp/leveldb/db/log_test.cc +563 -0
  50. package/cpp/leveldb/db/log_writer.cc +111 -0
  51. package/cpp/leveldb/db/log_writer.h +54 -0
  52. package/cpp/leveldb/db/memtable.cc +137 -0
  53. package/cpp/leveldb/db/memtable.h +87 -0
  54. package/cpp/leveldb/db/recovery_test.cc +339 -0
  55. package/cpp/leveldb/db/repair.cc +451 -0
  56. package/cpp/leveldb/db/skiplist.h +382 -0
  57. package/cpp/leveldb/db/skiplist_test.cc +373 -0
  58. package/cpp/leveldb/db/snapshot.h +95 -0
  59. package/cpp/leveldb/db/table_cache.cc +120 -0
  60. package/cpp/leveldb/db/table_cache.h +57 -0
  61. package/cpp/leveldb/db/version_edit.cc +257 -0
  62. package/cpp/leveldb/db/version_edit.h +106 -0
  63. package/cpp/leveldb/db/version_edit_test.cc +46 -0
  64. package/cpp/leveldb/db/version_set.cc +1562 -0
  65. package/cpp/leveldb/db/version_set.h +393 -0
  66. package/cpp/leveldb/db/version_set_test.cc +336 -0
  67. package/cpp/leveldb/db/write_batch.cc +150 -0
  68. package/cpp/leveldb/db/write_batch_internal.h +45 -0
  69. package/cpp/leveldb/db/write_batch_test.cc +137 -0
  70. package/cpp/leveldb/doc/benchmark.html +459 -0
  71. package/cpp/leveldb/doc/impl.md +172 -0
  72. package/cpp/leveldb/doc/index.md +523 -0
  73. package/cpp/leveldb/doc/log_format.md +75 -0
  74. package/cpp/leveldb/doc/table_format.md +107 -0
  75. package/cpp/leveldb/helpers/memenv/memenv.cc +390 -0
  76. package/cpp/leveldb/helpers/memenv/memenv.h +22 -0
  77. package/cpp/leveldb/helpers/memenv/memenv_test.cc +264 -0
  78. package/cpp/leveldb/include/leveldb/c.h +270 -0
  79. package/cpp/leveldb/include/leveldb/cache.h +111 -0
  80. package/cpp/leveldb/include/leveldb/comparator.h +64 -0
  81. package/cpp/leveldb/include/leveldb/db.h +167 -0
  82. package/cpp/leveldb/include/leveldb/dumpfile.h +28 -0
  83. package/cpp/leveldb/include/leveldb/env.h +417 -0
  84. package/cpp/leveldb/include/leveldb/export.h +33 -0
  85. package/cpp/leveldb/include/leveldb/filter_policy.h +72 -0
  86. package/cpp/leveldb/include/leveldb/iterator.h +112 -0
  87. package/cpp/leveldb/include/leveldb/options.h +187 -0
  88. package/cpp/leveldb/include/leveldb/slice.h +114 -0
  89. package/cpp/leveldb/include/leveldb/status.h +122 -0
  90. package/cpp/leveldb/include/leveldb/table.h +84 -0
  91. package/cpp/leveldb/include/leveldb/table_builder.h +93 -0
  92. package/cpp/leveldb/include/leveldb/write_batch.h +83 -0
  93. package/cpp/leveldb/issues/issue178_test.cc +90 -0
  94. package/cpp/leveldb/issues/issue200_test.cc +59 -0
  95. package/cpp/leveldb/issues/issue320_test.cc +131 -0
  96. package/cpp/leveldb/port/README.md +10 -0
  97. package/cpp/leveldb/port/port.h +19 -0
  98. package/cpp/leveldb/port/port_config.h.in +33 -0
  99. package/cpp/leveldb/port/port_example.h +100 -0
  100. package/cpp/leveldb/port/port_stdcxx.h +151 -0
  101. package/cpp/leveldb/port/thread_annotations.h +108 -0
  102. package/cpp/leveldb/table/block.cc +267 -0
  103. package/cpp/leveldb/table/block.h +44 -0
  104. package/cpp/leveldb/table/block_builder.cc +107 -0
  105. package/cpp/leveldb/table/block_builder.h +54 -0
  106. package/cpp/leveldb/table/filter_block.cc +106 -0
  107. package/cpp/leveldb/table/filter_block.h +68 -0
  108. package/cpp/leveldb/table/filter_block_test.cc +127 -0
  109. package/cpp/leveldb/table/format.cc +141 -0
  110. package/cpp/leveldb/table/format.h +99 -0
  111. package/cpp/leveldb/table/iterator.cc +76 -0
  112. package/cpp/leveldb/table/iterator_wrapper.h +92 -0
  113. package/cpp/leveldb/table/merger.cc +191 -0
  114. package/cpp/leveldb/table/merger.h +26 -0
  115. package/cpp/leveldb/table/table.cc +271 -0
  116. package/cpp/leveldb/table/table_builder.cc +265 -0
  117. package/cpp/leveldb/table/table_test.cc +834 -0
  118. package/cpp/leveldb/table/two_level_iterator.cc +171 -0
  119. package/cpp/leveldb/table/two_level_iterator.h +31 -0
  120. package/cpp/leveldb/third_party/benchmark/.clang-format +5 -0
  121. package/cpp/leveldb/third_party/benchmark/.github/ISSUE_TEMPLATE/bug_report.md +32 -0
  122. package/cpp/leveldb/third_party/benchmark/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  123. package/cpp/leveldb/third_party/benchmark/.github/workflows/build-and-test.yml +38 -0
  124. package/cpp/leveldb/third_party/benchmark/.github/workflows/pylint.yml +26 -0
  125. package/cpp/leveldb/third_party/benchmark/.github/workflows/test_bindings.yml +24 -0
  126. package/cpp/leveldb/third_party/benchmark/.travis-libcxx-setup.sh +28 -0
  127. package/cpp/leveldb/third_party/benchmark/.travis.yml +231 -0
  128. package/cpp/leveldb/third_party/benchmark/.ycm_extra_conf.py +115 -0
  129. package/cpp/leveldb/third_party/benchmark/AUTHORS +58 -0
  130. package/cpp/leveldb/third_party/benchmark/BUILD.bazel +44 -0
  131. package/cpp/leveldb/third_party/benchmark/CMakeLists.txt +287 -0
  132. package/cpp/leveldb/third_party/benchmark/CONTRIBUTING.md +58 -0
  133. package/cpp/leveldb/third_party/benchmark/CONTRIBUTORS +83 -0
  134. package/cpp/leveldb/third_party/benchmark/LICENSE +202 -0
  135. package/cpp/leveldb/third_party/benchmark/README.md +1323 -0
  136. package/cpp/leveldb/third_party/benchmark/WORKSPACE +51 -0
  137. package/cpp/leveldb/third_party/benchmark/_config.yml +1 -0
  138. package/cpp/leveldb/third_party/benchmark/appveyor.yml +50 -0
  139. package/cpp/leveldb/third_party/benchmark/bindings/python/BUILD +3 -0
  140. package/cpp/leveldb/third_party/benchmark/bindings/python/build_defs.bzl +25 -0
  141. package/cpp/leveldb/third_party/benchmark/bindings/python/google_benchmark/BUILD +38 -0
  142. package/cpp/leveldb/third_party/benchmark/bindings/python/google_benchmark/__init__.py +156 -0
  143. package/cpp/leveldb/third_party/benchmark/bindings/python/google_benchmark/benchmark.cc +180 -0
  144. package/cpp/leveldb/third_party/benchmark/bindings/python/google_benchmark/example.py +136 -0
  145. package/cpp/leveldb/third_party/benchmark/bindings/python/pybind11.BUILD +20 -0
  146. package/cpp/leveldb/third_party/benchmark/bindings/python/python_headers.BUILD +6 -0
  147. package/cpp/leveldb/third_party/benchmark/bindings/python/requirements.txt +2 -0
  148. package/cpp/leveldb/third_party/benchmark/cmake/AddCXXCompilerFlag.cmake +74 -0
  149. package/cpp/leveldb/third_party/benchmark/cmake/CXXFeatureCheck.cmake +69 -0
  150. package/cpp/leveldb/third_party/benchmark/cmake/Config.cmake.in +1 -0
  151. package/cpp/leveldb/third_party/benchmark/cmake/GetGitVersion.cmake +54 -0
  152. package/cpp/leveldb/third_party/benchmark/cmake/GoogleTest.cmake +41 -0
  153. package/cpp/leveldb/third_party/benchmark/cmake/GoogleTest.cmake.in +58 -0
  154. package/cpp/leveldb/third_party/benchmark/cmake/benchmark.pc.in +12 -0
  155. package/cpp/leveldb/third_party/benchmark/cmake/gnu_posix_regex.cpp +12 -0
  156. package/cpp/leveldb/third_party/benchmark/cmake/llvm-toolchain.cmake +8 -0
  157. package/cpp/leveldb/third_party/benchmark/cmake/posix_regex.cpp +14 -0
  158. package/cpp/leveldb/third_party/benchmark/cmake/split_list.cmake +3 -0
  159. package/cpp/leveldb/third_party/benchmark/cmake/std_regex.cpp +10 -0
  160. package/cpp/leveldb/third_party/benchmark/cmake/steady_clock.cpp +7 -0
  161. package/cpp/leveldb/third_party/benchmark/cmake/thread_safety_attributes.cpp +4 -0
  162. package/cpp/leveldb/third_party/benchmark/conan/CMakeLists.txt +7 -0
  163. package/cpp/leveldb/third_party/benchmark/conan/test_package/CMakeLists.txt +10 -0
  164. package/cpp/leveldb/third_party/benchmark/conan/test_package/conanfile.py +19 -0
  165. package/cpp/leveldb/third_party/benchmark/conan/test_package/test_package.cpp +18 -0
  166. package/cpp/leveldb/third_party/benchmark/conanfile.py +79 -0
  167. package/cpp/leveldb/third_party/benchmark/dependencies.md +18 -0
  168. package/cpp/leveldb/third_party/benchmark/docs/AssemblyTests.md +147 -0
  169. package/cpp/leveldb/third_party/benchmark/docs/_config.yml +1 -0
  170. package/cpp/leveldb/third_party/benchmark/docs/releasing.md +16 -0
  171. package/cpp/leveldb/third_party/benchmark/docs/tools.md +203 -0
  172. package/cpp/leveldb/third_party/benchmark/include/benchmark/benchmark.h +1604 -0
  173. package/cpp/leveldb/third_party/benchmark/requirements.txt +2 -0
  174. package/cpp/leveldb/third_party/benchmark/setup.py +140 -0
  175. package/cpp/leveldb/third_party/benchmark/src/CMakeLists.txt +114 -0
  176. package/cpp/leveldb/third_party/benchmark/src/arraysize.h +33 -0
  177. package/cpp/leveldb/third_party/benchmark/src/benchmark.cc +499 -0
  178. package/cpp/leveldb/third_party/benchmark/src/benchmark_api_internal.cc +15 -0
  179. package/cpp/leveldb/third_party/benchmark/src/benchmark_api_internal.h +53 -0
  180. package/cpp/leveldb/third_party/benchmark/src/benchmark_main.cc +17 -0
  181. package/cpp/leveldb/third_party/benchmark/src/benchmark_name.cc +58 -0
  182. package/cpp/leveldb/third_party/benchmark/src/benchmark_register.cc +515 -0
  183. package/cpp/leveldb/third_party/benchmark/src/benchmark_register.h +108 -0
  184. package/cpp/leveldb/third_party/benchmark/src/benchmark_runner.cc +362 -0
  185. package/cpp/leveldb/third_party/benchmark/src/benchmark_runner.h +51 -0
  186. package/cpp/leveldb/third_party/benchmark/src/check.h +82 -0
  187. package/cpp/leveldb/third_party/benchmark/src/colorprint.cc +188 -0
  188. package/cpp/leveldb/third_party/benchmark/src/colorprint.h +33 -0
  189. package/cpp/leveldb/third_party/benchmark/src/commandlineflags.cc +228 -0
  190. package/cpp/leveldb/third_party/benchmark/src/commandlineflags.h +103 -0
  191. package/cpp/leveldb/third_party/benchmark/src/complexity.cc +238 -0
  192. package/cpp/leveldb/third_party/benchmark/src/complexity.h +55 -0
  193. package/cpp/leveldb/third_party/benchmark/src/console_reporter.cc +177 -0
  194. package/cpp/leveldb/third_party/benchmark/src/counter.cc +80 -0
  195. package/cpp/leveldb/third_party/benchmark/src/counter.h +32 -0
  196. package/cpp/leveldb/third_party/benchmark/src/csv_reporter.cc +154 -0
  197. package/cpp/leveldb/third_party/benchmark/src/cycleclock.h +211 -0
  198. package/cpp/leveldb/third_party/benchmark/src/internal_macros.h +102 -0
  199. package/cpp/leveldb/third_party/benchmark/src/json_reporter.cc +255 -0
  200. package/cpp/leveldb/third_party/benchmark/src/log.h +74 -0
  201. package/cpp/leveldb/third_party/benchmark/src/mutex.h +155 -0
  202. package/cpp/leveldb/third_party/benchmark/src/re.h +158 -0
  203. package/cpp/leveldb/third_party/benchmark/src/reporter.cc +105 -0
  204. package/cpp/leveldb/third_party/benchmark/src/sleep.cc +67 -0
  205. package/cpp/leveldb/third_party/benchmark/src/sleep.h +15 -0
  206. package/cpp/leveldb/third_party/benchmark/src/statistics.cc +193 -0
  207. package/cpp/leveldb/third_party/benchmark/src/statistics.h +37 -0
  208. package/cpp/leveldb/third_party/benchmark/src/string_util.cc +255 -0
  209. package/cpp/leveldb/third_party/benchmark/src/string_util.h +59 -0
  210. package/cpp/leveldb/third_party/benchmark/src/sysinfo.cc +716 -0
  211. package/cpp/leveldb/third_party/benchmark/src/thread_manager.h +64 -0
  212. package/cpp/leveldb/third_party/benchmark/src/thread_timer.h +86 -0
  213. package/cpp/leveldb/third_party/benchmark/src/timers.cc +245 -0
  214. package/cpp/leveldb/third_party/benchmark/src/timers.h +48 -0
  215. package/cpp/leveldb/third_party/benchmark/test/AssemblyTests.cmake +46 -0
  216. package/cpp/leveldb/third_party/benchmark/test/BUILD +73 -0
  217. package/cpp/leveldb/third_party/benchmark/test/CMakeLists.txt +263 -0
  218. package/cpp/leveldb/third_party/benchmark/test/args_product_test.cc +77 -0
  219. package/cpp/leveldb/third_party/benchmark/test/basic_test.cc +136 -0
  220. package/cpp/leveldb/third_party/benchmark/test/benchmark_gtest.cc +134 -0
  221. package/cpp/leveldb/third_party/benchmark/test/benchmark_name_gtest.cc +74 -0
  222. package/cpp/leveldb/third_party/benchmark/test/benchmark_test.cc +245 -0
  223. package/cpp/leveldb/third_party/benchmark/test/clobber_memory_assembly_test.cc +64 -0
  224. package/cpp/leveldb/third_party/benchmark/test/commandlineflags_gtest.cc +201 -0
  225. package/cpp/leveldb/third_party/benchmark/test/complexity_test.cc +213 -0
  226. package/cpp/leveldb/third_party/benchmark/test/cxx03_test.cc +63 -0
  227. package/cpp/leveldb/third_party/benchmark/test/diagnostics_test.cc +80 -0
  228. package/cpp/leveldb/third_party/benchmark/test/display_aggregates_only_test.cc +43 -0
  229. package/cpp/leveldb/third_party/benchmark/test/donotoptimize_assembly_test.cc +163 -0
  230. package/cpp/leveldb/third_party/benchmark/test/donotoptimize_test.cc +52 -0
  231. package/cpp/leveldb/third_party/benchmark/test/filter_test.cc +104 -0
  232. package/cpp/leveldb/third_party/benchmark/test/fixture_test.cc +51 -0
  233. package/cpp/leveldb/third_party/benchmark/test/internal_threading_test.cc +184 -0
  234. package/cpp/leveldb/third_party/benchmark/test/link_main_test.cc +8 -0
  235. package/cpp/leveldb/third_party/benchmark/test/map_test.cc +57 -0
  236. package/cpp/leveldb/third_party/benchmark/test/memory_manager_test.cc +44 -0
  237. package/cpp/leveldb/third_party/benchmark/test/multiple_ranges_test.cc +96 -0
  238. package/cpp/leveldb/third_party/benchmark/test/options_test.cc +75 -0
  239. package/cpp/leveldb/third_party/benchmark/test/output_test.h +213 -0
  240. package/cpp/leveldb/third_party/benchmark/test/output_test_helper.cc +515 -0
  241. package/cpp/leveldb/third_party/benchmark/test/register_benchmark_test.cc +184 -0
  242. package/cpp/leveldb/third_party/benchmark/test/report_aggregates_only_test.cc +39 -0
  243. package/cpp/leveldb/third_party/benchmark/test/reporter_output_test.cc +747 -0
  244. package/cpp/leveldb/third_party/benchmark/test/skip_with_error_test.cc +195 -0
  245. package/cpp/leveldb/third_party/benchmark/test/state_assembly_test.cc +68 -0
  246. package/cpp/leveldb/third_party/benchmark/test/statistics_gtest.cc +28 -0
  247. package/cpp/leveldb/third_party/benchmark/test/string_util_gtest.cc +153 -0
  248. package/cpp/leveldb/third_party/benchmark/test/templated_fixture_test.cc +28 -0
  249. package/cpp/leveldb/third_party/benchmark/test/user_counters_tabular_test.cc +285 -0
  250. package/cpp/leveldb/third_party/benchmark/test/user_counters_test.cc +531 -0
  251. package/cpp/leveldb/third_party/benchmark/test/user_counters_thousands_test.cc +173 -0
  252. package/cpp/leveldb/third_party/benchmark/tools/BUILD.bazel +19 -0
  253. package/cpp/leveldb/third_party/benchmark/tools/compare.py +429 -0
  254. package/cpp/leveldb/third_party/benchmark/tools/gbench/Inputs/test1_run1.json +119 -0
  255. package/cpp/leveldb/third_party/benchmark/tools/gbench/Inputs/test1_run2.json +119 -0
  256. package/cpp/leveldb/third_party/benchmark/tools/gbench/Inputs/test2_run.json +81 -0
  257. package/cpp/leveldb/third_party/benchmark/tools/gbench/Inputs/test3_run0.json +65 -0
  258. package/cpp/leveldb/third_party/benchmark/tools/gbench/Inputs/test3_run1.json +65 -0
  259. package/cpp/leveldb/third_party/benchmark/tools/gbench/__init__.py +8 -0
  260. package/cpp/leveldb/third_party/benchmark/tools/gbench/report.py +903 -0
  261. package/cpp/leveldb/third_party/benchmark/tools/gbench/util.py +163 -0
  262. package/cpp/leveldb/third_party/benchmark/tools/requirements.txt +1 -0
  263. package/cpp/leveldb/third_party/benchmark/tools/strip_asm.py +151 -0
  264. package/cpp/leveldb/third_party/googletest/.clang-format +4 -0
  265. package/cpp/leveldb/third_party/googletest/.travis.yml +73 -0
  266. package/cpp/leveldb/third_party/googletest/BUILD.bazel +179 -0
  267. package/cpp/leveldb/third_party/googletest/CMakeLists.txt +36 -0
  268. package/cpp/leveldb/third_party/googletest/CONTRIBUTING.md +142 -0
  269. package/cpp/leveldb/third_party/googletest/LICENSE +28 -0
  270. package/cpp/leveldb/third_party/googletest/README.md +132 -0
  271. package/cpp/leveldb/third_party/googletest/WORKSPACE +23 -0
  272. package/cpp/leveldb/third_party/googletest/appveyor.yml +154 -0
  273. package/cpp/leveldb/third_party/googletest/ci/build-linux-bazel.sh +37 -0
  274. package/cpp/leveldb/third_party/googletest/ci/build-platformio.sh +2 -0
  275. package/cpp/leveldb/third_party/googletest/ci/env-linux.sh +41 -0
  276. package/cpp/leveldb/third_party/googletest/ci/env-osx.sh +47 -0
  277. package/cpp/leveldb/third_party/googletest/ci/get-nprocessors.sh +48 -0
  278. package/cpp/leveldb/third_party/googletest/ci/install-linux.sh +49 -0
  279. package/cpp/leveldb/third_party/googletest/ci/install-osx.sh +40 -0
  280. package/cpp/leveldb/third_party/googletest/ci/install-platformio.sh +5 -0
  281. package/cpp/leveldb/third_party/googletest/ci/log-config.sh +51 -0
  282. package/cpp/leveldb/third_party/googletest/ci/travis.sh +44 -0
  283. package/cpp/leveldb/third_party/googletest/googlemock/CMakeLists.txt +233 -0
  284. package/cpp/leveldb/third_party/googletest/googlemock/CONTRIBUTORS +40 -0
  285. package/cpp/leveldb/third_party/googletest/googlemock/LICENSE +28 -0
  286. package/cpp/leveldb/third_party/googletest/googlemock/README.md +44 -0
  287. package/cpp/leveldb/third_party/googletest/googlemock/cmake/gmock.pc.in +10 -0
  288. package/cpp/leveldb/third_party/googletest/googlemock/cmake/gmock_main.pc.in +10 -0
  289. package/cpp/leveldb/third_party/googletest/googlemock/docs/cheat_sheet.md +770 -0
  290. package/cpp/leveldb/third_party/googletest/googlemock/docs/cook_book.md +4270 -0
  291. package/cpp/leveldb/third_party/googletest/googlemock/docs/for_dummies.md +700 -0
  292. package/cpp/leveldb/third_party/googletest/googlemock/docs/gmock_faq.md +396 -0
  293. package/cpp/leveldb/third_party/googletest/googlemock/docs/pump_manual.md +187 -0
  294. package/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-actions.h +1193 -0
  295. package/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-cardinalities.h +157 -0
  296. package/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-function-mocker.h +276 -0
  297. package/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-generated-actions.h +1884 -0
  298. package/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-generated-actions.h.pump +627 -0
  299. package/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-generated-function-mockers.h +752 -0
  300. package/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-generated-function-mockers.h.pump +227 -0
  301. package/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-generated-matchers.h +1097 -0
  302. package/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-generated-matchers.h.pump +346 -0
  303. package/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h +4591 -0
  304. package/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-more-actions.h +162 -0
  305. package/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-more-matchers.h +92 -0
  306. package/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-nice-strict.h +215 -0
  307. package/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-spec-builders.h +1985 -0
  308. package/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock.h +101 -0
  309. package/cpp/leveldb/third_party/googletest/googlemock/include/gmock/internal/custom/README.md +16 -0
  310. package/cpp/leveldb/third_party/googletest/googlemock/include/gmock/internal/custom/gmock-generated-actions.h +10 -0
  311. package/cpp/leveldb/third_party/googletest/googlemock/include/gmock/internal/custom/gmock-generated-actions.h.pump +12 -0
  312. package/cpp/leveldb/third_party/googletest/googlemock/include/gmock/internal/custom/gmock-matchers.h +36 -0
  313. package/cpp/leveldb/third_party/googletest/googlemock/include/gmock/internal/custom/gmock-port.h +39 -0
  314. package/cpp/leveldb/third_party/googletest/googlemock/include/gmock/internal/gmock-internal-utils.h +472 -0
  315. package/cpp/leveldb/third_party/googletest/googlemock/include/gmock/internal/gmock-port.h +87 -0
  316. package/cpp/leveldb/third_party/googletest/googlemock/include/gmock/internal/gmock-pp.h +271 -0
  317. package/cpp/leveldb/third_party/googletest/googlemock/scripts/README.md +5 -0
  318. package/cpp/leveldb/third_party/googletest/googlemock/scripts/fuse_gmock_files.py +240 -0
  319. package/cpp/leveldb/third_party/googletest/googlemock/scripts/generator/LICENSE +203 -0
  320. package/cpp/leveldb/third_party/googletest/googlemock/scripts/generator/README +34 -0
  321. package/cpp/leveldb/third_party/googletest/googlemock/scripts/generator/README.cppclean +115 -0
  322. package/cpp/leveldb/third_party/googletest/googlemock/scripts/generator/cpp/__init__.py +0 -0
  323. package/cpp/leveldb/third_party/googletest/googlemock/scripts/generator/cpp/ast.py +1761 -0
  324. package/cpp/leveldb/third_party/googletest/googlemock/scripts/generator/cpp/gmock_class.py +248 -0
  325. package/cpp/leveldb/third_party/googletest/googlemock/scripts/generator/cpp/gmock_class_test.py +540 -0
  326. package/cpp/leveldb/third_party/googletest/googlemock/scripts/generator/cpp/keywords.py +56 -0
  327. package/cpp/leveldb/third_party/googletest/googlemock/scripts/generator/cpp/tokenize.py +284 -0
  328. package/cpp/leveldb/third_party/googletest/googlemock/scripts/generator/cpp/utils.py +37 -0
  329. package/cpp/leveldb/third_party/googletest/googlemock/scripts/generator/gmock_gen.py +30 -0
  330. package/cpp/leveldb/third_party/googletest/googlemock/scripts/pump.py +856 -0
  331. package/cpp/leveldb/third_party/googletest/googlemock/src/gmock-all.cc +46 -0
  332. package/cpp/leveldb/third_party/googletest/googlemock/src/gmock-cardinalities.cc +155 -0
  333. package/cpp/leveldb/third_party/googletest/googlemock/src/gmock-internal-utils.cc +200 -0
  334. package/cpp/leveldb/third_party/googletest/googlemock/src/gmock-matchers.cc +462 -0
  335. package/cpp/leveldb/third_party/googletest/googlemock/src/gmock-spec-builders.cc +892 -0
  336. package/cpp/leveldb/third_party/googletest/googlemock/src/gmock.cc +213 -0
  337. package/cpp/leveldb/third_party/googletest/googlemock/src/gmock_main.cc +72 -0
  338. package/cpp/leveldb/third_party/googletest/googlemock/test/BUILD.bazel +110 -0
  339. package/cpp/leveldb/third_party/googletest/googlemock/test/gmock-actions_test.cc +1507 -0
  340. package/cpp/leveldb/third_party/googletest/googlemock/test/gmock-cardinalities_test.cc +429 -0
  341. package/cpp/leveldb/third_party/googletest/googlemock/test/gmock-function-mocker_nc.cc +16 -0
  342. package/cpp/leveldb/third_party/googletest/googlemock/test/gmock-function-mocker_nc_test.py +43 -0
  343. package/cpp/leveldb/third_party/googletest/googlemock/test/gmock-function-mocker_test.cc +696 -0
  344. package/cpp/leveldb/third_party/googletest/googlemock/test/gmock-generated-actions_test.cc +1064 -0
  345. package/cpp/leveldb/third_party/googletest/googlemock/test/gmock-generated-function-mockers_test.cc +659 -0
  346. package/cpp/leveldb/third_party/googletest/googlemock/test/gmock-generated-matchers_test.cc +1323 -0
  347. package/cpp/leveldb/third_party/googletest/googlemock/test/gmock-internal-utils_test.cc +732 -0
  348. package/cpp/leveldb/third_party/googletest/googlemock/test/gmock-matchers_test.cc +6913 -0
  349. package/cpp/leveldb/third_party/googletest/googlemock/test/gmock-more-actions_test.cc +698 -0
  350. package/cpp/leveldb/third_party/googletest/googlemock/test/gmock-nice-strict_test.cc +500 -0
  351. package/cpp/leveldb/third_party/googletest/googlemock/test/gmock-port_test.cc +42 -0
  352. package/cpp/leveldb/third_party/googletest/googlemock/test/gmock-pp-string_test.cc +206 -0
  353. package/cpp/leveldb/third_party/googletest/googlemock/test/gmock-pp_test.cc +83 -0
  354. package/cpp/leveldb/third_party/googletest/googlemock/test/gmock-spec-builders_test.cc +2775 -0
  355. package/cpp/leveldb/third_party/googletest/googlemock/test/gmock_all_test.cc +49 -0
  356. package/cpp/leveldb/third_party/googletest/googlemock/test/gmock_ex_test.cc +80 -0
  357. package/cpp/leveldb/third_party/googletest/googlemock/test/gmock_leak_test.py +104 -0
  358. package/cpp/leveldb/third_party/googletest/googlemock/test/gmock_leak_test_.cc +99 -0
  359. package/cpp/leveldb/third_party/googletest/googlemock/test/gmock_link2_test.cc +39 -0
  360. package/cpp/leveldb/third_party/googletest/googlemock/test/gmock_link_test.cc +39 -0
  361. package/cpp/leveldb/third_party/googletest/googlemock/test/gmock_link_test.h +690 -0
  362. package/cpp/leveldb/third_party/googletest/googlemock/test/gmock_output_test.py +183 -0
  363. package/cpp/leveldb/third_party/googletest/googlemock/test/gmock_output_test_.cc +309 -0
  364. package/cpp/leveldb/third_party/googletest/googlemock/test/gmock_output_test_golden.txt +317 -0
  365. package/cpp/leveldb/third_party/googletest/googlemock/test/gmock_stress_test.cc +240 -0
  366. package/cpp/leveldb/third_party/googletest/googlemock/test/gmock_test.cc +181 -0
  367. package/cpp/leveldb/third_party/googletest/googlemock/test/gmock_test_utils.py +108 -0
  368. package/cpp/leveldb/third_party/googletest/googlemock/test/pump_test.py +182 -0
  369. package/cpp/leveldb/third_party/googletest/googletest/CMakeLists.txt +329 -0
  370. package/cpp/leveldb/third_party/googletest/googletest/CONTRIBUTORS +38 -0
  371. package/cpp/leveldb/third_party/googletest/googletest/LICENSE +28 -0
  372. package/cpp/leveldb/third_party/googletest/googletest/README.md +244 -0
  373. package/cpp/leveldb/third_party/googletest/googletest/cmake/Config.cmake.in +9 -0
  374. package/cpp/leveldb/third_party/googletest/googletest/cmake/gtest.pc.in +9 -0
  375. package/cpp/leveldb/third_party/googletest/googletest/cmake/gtest_main.pc.in +10 -0
  376. package/cpp/leveldb/third_party/googletest/googletest/cmake/internal_utils.cmake +358 -0
  377. package/cpp/leveldb/third_party/googletest/googletest/cmake/libgtest.la.in +21 -0
  378. package/cpp/leveldb/third_party/googletest/googletest/docs/advanced.md +2567 -0
  379. package/cpp/leveldb/third_party/googletest/googletest/docs/faq.md +753 -0
  380. package/cpp/leveldb/third_party/googletest/googletest/docs/pkgconfig.md +219 -0
  381. package/cpp/leveldb/third_party/googletest/googletest/docs/primer.md +579 -0
  382. package/cpp/leveldb/third_party/googletest/googletest/docs/samples.md +22 -0
  383. package/cpp/leveldb/third_party/googletest/googletest/include/gtest/gtest-death-test.h +343 -0
  384. package/cpp/leveldb/third_party/googletest/googletest/include/gtest/gtest-matchers.h +750 -0
  385. package/cpp/leveldb/third_party/googletest/googletest/include/gtest/gtest-message.h +219 -0
  386. package/cpp/leveldb/third_party/googletest/googletest/include/gtest/gtest-param-test.h +514 -0
  387. package/cpp/leveldb/third_party/googletest/googletest/include/gtest/gtest-printers.h +928 -0
  388. package/cpp/leveldb/third_party/googletest/googletest/include/gtest/gtest-spi.h +238 -0
  389. package/cpp/leveldb/third_party/googletest/googletest/include/gtest/gtest-test-part.h +184 -0
  390. package/cpp/leveldb/third_party/googletest/googletest/include/gtest/gtest-typed-test.h +337 -0
  391. package/cpp/leveldb/third_party/googletest/googletest/include/gtest/gtest.h +2477 -0
  392. package/cpp/leveldb/third_party/googletest/googletest/include/gtest/gtest_pred_impl.h +359 -0
  393. package/cpp/leveldb/third_party/googletest/googletest/include/gtest/gtest_prod.h +61 -0
  394. package/cpp/leveldb/third_party/googletest/googletest/include/gtest/internal/custom/README.md +56 -0
  395. package/cpp/leveldb/third_party/googletest/googletest/include/gtest/internal/custom/gtest-port.h +37 -0
  396. package/cpp/leveldb/third_party/googletest/googletest/include/gtest/internal/custom/gtest-printers.h +42 -0
  397. package/cpp/leveldb/third_party/googletest/googletest/include/gtest/internal/custom/gtest.h +37 -0
  398. package/cpp/leveldb/third_party/googletest/googletest/include/gtest/internal/gtest-death-test-internal.h +304 -0
  399. package/cpp/leveldb/third_party/googletest/googletest/include/gtest/internal/gtest-filepath.h +211 -0
  400. package/cpp/leveldb/third_party/googletest/googletest/include/gtest/internal/gtest-internal.h +1411 -0
  401. package/cpp/leveldb/third_party/googletest/googletest/include/gtest/internal/gtest-param-util.h +880 -0
  402. package/cpp/leveldb/third_party/googletest/googletest/include/gtest/internal/gtest-port-arch.h +111 -0
  403. package/cpp/leveldb/third_party/googletest/googletest/include/gtest/internal/gtest-port.h +2227 -0
  404. package/cpp/leveldb/third_party/googletest/googletest/include/gtest/internal/gtest-string.h +171 -0
  405. package/cpp/leveldb/third_party/googletest/googletest/include/gtest/internal/gtest-type-util.h +183 -0
  406. package/cpp/leveldb/third_party/googletest/googletest/samples/prime_tables.h +126 -0
  407. package/cpp/leveldb/third_party/googletest/googletest/samples/sample1.cc +66 -0
  408. package/cpp/leveldb/third_party/googletest/googletest/samples/sample1.h +41 -0
  409. package/cpp/leveldb/third_party/googletest/googletest/samples/sample10_unittest.cc +139 -0
  410. package/cpp/leveldb/third_party/googletest/googletest/samples/sample1_unittest.cc +151 -0
  411. package/cpp/leveldb/third_party/googletest/googletest/samples/sample2.cc +54 -0
  412. package/cpp/leveldb/third_party/googletest/googletest/samples/sample2.h +81 -0
  413. package/cpp/leveldb/third_party/googletest/googletest/samples/sample2_unittest.cc +107 -0
  414. package/cpp/leveldb/third_party/googletest/googletest/samples/sample3-inl.h +172 -0
  415. package/cpp/leveldb/third_party/googletest/googletest/samples/sample3_unittest.cc +149 -0
  416. package/cpp/leveldb/third_party/googletest/googletest/samples/sample4.cc +54 -0
  417. package/cpp/leveldb/third_party/googletest/googletest/samples/sample4.h +53 -0
  418. package/cpp/leveldb/third_party/googletest/googletest/samples/sample4_unittest.cc +53 -0
  419. package/cpp/leveldb/third_party/googletest/googletest/samples/sample5_unittest.cc +196 -0
  420. package/cpp/leveldb/third_party/googletest/googletest/samples/sample6_unittest.cc +224 -0
  421. package/cpp/leveldb/third_party/googletest/googletest/samples/sample7_unittest.cc +117 -0
  422. package/cpp/leveldb/third_party/googletest/googletest/samples/sample8_unittest.cc +154 -0
  423. package/cpp/leveldb/third_party/googletest/googletest/samples/sample9_unittest.cc +156 -0
  424. package/cpp/leveldb/third_party/googletest/googletest/scripts/README.md +5 -0
  425. package/cpp/leveldb/third_party/googletest/googletest/scripts/common.py +83 -0
  426. package/cpp/leveldb/third_party/googletest/googletest/scripts/fuse_gtest_files.py +253 -0
  427. package/cpp/leveldb/third_party/googletest/googletest/scripts/gen_gtest_pred_impl.py +734 -0
  428. package/cpp/leveldb/third_party/googletest/googletest/scripts/gtest-config.in +274 -0
  429. package/cpp/leveldb/third_party/googletest/googletest/scripts/release_docs.py +158 -0
  430. package/cpp/leveldb/third_party/googletest/googletest/scripts/run_with_path.py +32 -0
  431. package/cpp/leveldb/third_party/googletest/googletest/scripts/upload.py +1402 -0
  432. package/cpp/leveldb/third_party/googletest/googletest/scripts/upload_gtest.py +78 -0
  433. package/cpp/leveldb/third_party/googletest/googletest/src/gtest-all.cc +48 -0
  434. package/cpp/leveldb/third_party/googletest/googletest/src/gtest-death-test.cc +1653 -0
  435. package/cpp/leveldb/third_party/googletest/googletest/src/gtest-filepath.cc +382 -0
  436. package/cpp/leveldb/third_party/googletest/googletest/src/gtest-internal-inl.h +1211 -0
  437. package/cpp/leveldb/third_party/googletest/googletest/src/gtest-matchers.cc +97 -0
  438. package/cpp/leveldb/third_party/googletest/googletest/src/gtest-port.cc +1399 -0
  439. package/cpp/leveldb/third_party/googletest/googletest/src/gtest-printers.cc +442 -0
  440. package/cpp/leveldb/third_party/googletest/googletest/src/gtest-test-part.cc +108 -0
  441. package/cpp/leveldb/third_party/googletest/googletest/src/gtest-typed-test.cc +118 -0
  442. package/cpp/leveldb/third_party/googletest/googletest/src/gtest.cc +6180 -0
  443. package/cpp/leveldb/third_party/googletest/googletest/src/gtest_main.cc +54 -0
  444. package/cpp/leveldb/third_party/googletest/googletest/test/BUILD.bazel +529 -0
  445. package/cpp/leveldb/third_party/googletest/googletest/test/googletest-break-on-failure-unittest.py +208 -0
  446. package/cpp/leveldb/third_party/googletest/googletest/test/googletest-break-on-failure-unittest_.cc +86 -0
  447. package/cpp/leveldb/third_party/googletest/googletest/test/googletest-catch-exceptions-test.py +236 -0
  448. package/cpp/leveldb/third_party/googletest/googletest/test/googletest-catch-exceptions-test_.cc +293 -0
  449. package/cpp/leveldb/third_party/googletest/googletest/test/googletest-color-test.py +127 -0
  450. package/cpp/leveldb/third_party/googletest/googletest/test/googletest-color-test_.cc +62 -0
  451. package/cpp/leveldb/third_party/googletest/googletest/test/googletest-death-test-test.cc +1516 -0
  452. package/cpp/leveldb/third_party/googletest/googletest/test/googletest-death-test_ex_test.cc +92 -0
  453. package/cpp/leveldb/third_party/googletest/googletest/test/googletest-env-var-test.py +117 -0
  454. package/cpp/leveldb/third_party/googletest/googletest/test/googletest-env-var-test_.cc +122 -0
  455. package/cpp/leveldb/third_party/googletest/googletest/test/googletest-filepath-test.cc +649 -0
  456. package/cpp/leveldb/third_party/googletest/googletest/test/googletest-filter-unittest.py +639 -0
  457. package/cpp/leveldb/third_party/googletest/googletest/test/googletest-filter-unittest_.cc +137 -0
  458. package/cpp/leveldb/third_party/googletest/googletest/test/googletest-json-outfiles-test.py +191 -0
  459. package/cpp/leveldb/third_party/googletest/googletest/test/googletest-json-output-unittest.py +778 -0
  460. package/cpp/leveldb/third_party/googletest/googletest/test/googletest-list-tests-unittest.py +205 -0
  461. package/cpp/leveldb/third_party/googletest/googletest/test/googletest-list-tests-unittest_.cc +156 -0
  462. package/cpp/leveldb/third_party/googletest/googletest/test/googletest-listener-test.cc +518 -0
  463. package/cpp/leveldb/third_party/googletest/googletest/test/googletest-message-test.cc +158 -0
  464. package/cpp/leveldb/third_party/googletest/googletest/test/googletest-options-test.cc +216 -0
  465. package/cpp/leveldb/third_party/googletest/googletest/test/googletest-output-test-golden-lin.txt +1137 -0
  466. package/cpp/leveldb/third_party/googletest/googletest/test/googletest-output-test.py +346 -0
  467. package/cpp/leveldb/third_party/googletest/googletest/test/googletest-output-test_.cc +1149 -0
  468. package/cpp/leveldb/third_party/googletest/googletest/test/googletest-param-test-invalid-name1-test.py +63 -0
  469. package/cpp/leveldb/third_party/googletest/googletest/test/googletest-param-test-invalid-name1-test_.cc +50 -0
  470. package/cpp/leveldb/third_party/googletest/googletest/test/googletest-param-test-invalid-name2-test.py +62 -0
  471. package/cpp/leveldb/third_party/googletest/googletest/test/googletest-param-test-invalid-name2-test_.cc +55 -0
  472. package/cpp/leveldb/third_party/googletest/googletest/test/googletest-param-test-test.cc +1086 -0
  473. package/cpp/leveldb/third_party/googletest/googletest/test/googletest-param-test-test.h +51 -0
  474. package/cpp/leveldb/third_party/googletest/googletest/test/googletest-param-test2-test.cc +61 -0
  475. package/cpp/leveldb/third_party/googletest/googletest/test/googletest-port-test.cc +1272 -0
  476. package/cpp/leveldb/third_party/googletest/googletest/test/googletest-printers-test.cc +1619 -0
  477. package/cpp/leveldb/third_party/googletest/googletest/test/googletest-shuffle-test.py +323 -0
  478. package/cpp/leveldb/third_party/googletest/googletest/test/googletest-shuffle-test_.cc +101 -0
  479. package/cpp/leveldb/third_party/googletest/googletest/test/googletest-test-part-test.cc +230 -0
  480. package/cpp/leveldb/third_party/googletest/googletest/test/googletest-test2_test.cc +61 -0
  481. package/cpp/leveldb/third_party/googletest/googletest/test/googletest-throw-on-failure-test.py +168 -0
  482. package/cpp/leveldb/third_party/googletest/googletest/test/googletest-throw-on-failure-test_.cc +71 -0
  483. package/cpp/leveldb/third_party/googletest/googletest/test/googletest-uninitialized-test.py +67 -0
  484. package/cpp/leveldb/third_party/googletest/googletest/test/googletest-uninitialized-test_.cc +42 -0
  485. package/cpp/leveldb/third_party/googletest/googletest/test/gtest-typed-test2_test.cc +44 -0
  486. package/cpp/leveldb/third_party/googletest/googletest/test/gtest-typed-test_test.cc +462 -0
  487. package/cpp/leveldb/third_party/googletest/googletest/test/gtest-typed-test_test.h +65 -0
  488. package/cpp/leveldb/third_party/googletest/googletest/test/gtest-unittest-api_test.cc +341 -0
  489. package/cpp/leveldb/third_party/googletest/googletest/test/gtest_all_test.cc +46 -0
  490. package/cpp/leveldb/third_party/googletest/googletest/test/gtest_assert_by_exception_test.cc +116 -0
  491. package/cpp/leveldb/third_party/googletest/googletest/test/gtest_environment_test.cc +188 -0
  492. package/cpp/leveldb/third_party/googletest/googletest/test/gtest_help_test.py +170 -0
  493. package/cpp/leveldb/third_party/googletest/googletest/test/gtest_help_test_.cc +45 -0
  494. package/cpp/leveldb/third_party/googletest/googletest/test/gtest_json_test_utils.py +60 -0
  495. package/cpp/leveldb/third_party/googletest/googletest/test/gtest_list_output_unittest.py +141 -0
  496. package/cpp/leveldb/third_party/googletest/googletest/test/gtest_list_output_unittest_.cc +51 -0
  497. package/cpp/leveldb/third_party/googletest/googletest/test/gtest_main_unittest.cc +44 -0
  498. package/cpp/leveldb/third_party/googletest/googletest/test/gtest_no_test_unittest.cc +54 -0
  499. package/cpp/leveldb/third_party/googletest/googletest/test/gtest_pred_impl_unittest.cc +2427 -0
  500. package/cpp/leveldb/third_party/googletest/googletest/test/gtest_premature_exit_test.cc +126 -0
  501. package/cpp/leveldb/third_party/googletest/googletest/test/gtest_prod_test.cc +56 -0
  502. package/cpp/leveldb/third_party/googletest/googletest/test/gtest_repeat_test.cc +233 -0
  503. package/cpp/leveldb/third_party/googletest/googletest/test/gtest_skip_check_output_test.py +59 -0
  504. package/cpp/leveldb/third_party/googletest/googletest/test/gtest_skip_environment_check_output_test.py +54 -0
  505. package/cpp/leveldb/third_party/googletest/googletest/test/gtest_skip_in_environment_setup_test.cc +49 -0
  506. package/cpp/leveldb/third_party/googletest/googletest/test/gtest_skip_test.cc +55 -0
  507. package/cpp/leveldb/third_party/googletest/googletest/test/gtest_sole_header_test.cc +56 -0
  508. package/cpp/leveldb/third_party/googletest/googletest/test/gtest_stress_test.cc +248 -0
  509. package/cpp/leveldb/third_party/googletest/googletest/test/gtest_test_macro_stack_footprint_test.cc +89 -0
  510. package/cpp/leveldb/third_party/googletest/googletest/test/gtest_test_utils.py +314 -0
  511. package/cpp/leveldb/third_party/googletest/googletest/test/gtest_testbridge_test.py +63 -0
  512. package/cpp/leveldb/third_party/googletest/googletest/test/gtest_testbridge_test_.cc +43 -0
  513. package/cpp/leveldb/third_party/googletest/googletest/test/gtest_throw_on_failure_ex_test.cc +90 -0
  514. package/cpp/leveldb/third_party/googletest/googletest/test/gtest_unittest.cc +7496 -0
  515. package/cpp/leveldb/third_party/googletest/googletest/test/gtest_xml_outfile1_test_.cc +43 -0
  516. package/cpp/leveldb/third_party/googletest/googletest/test/gtest_xml_outfile2_test_.cc +43 -0
  517. package/cpp/leveldb/third_party/googletest/googletest/test/gtest_xml_outfiles_test.py +135 -0
  518. package/cpp/leveldb/third_party/googletest/googletest/test/gtest_xml_output_unittest.py +389 -0
  519. package/cpp/leveldb/third_party/googletest/googletest/test/gtest_xml_output_unittest_.cc +188 -0
  520. package/cpp/leveldb/third_party/googletest/googletest/test/gtest_xml_test_utils.py +196 -0
  521. package/cpp/leveldb/third_party/googletest/googletest/test/production.cc +35 -0
  522. package/cpp/leveldb/third_party/googletest/googletest/test/production.h +54 -0
  523. package/cpp/leveldb/third_party/googletest/library.json +66 -0
  524. package/cpp/leveldb/third_party/googletest/platformio.ini +47 -0
  525. package/cpp/leveldb/util/arena.cc +66 -0
  526. package/cpp/leveldb/util/arena.h +71 -0
  527. package/cpp/leveldb/util/arena_test.cc +66 -0
  528. package/cpp/leveldb/util/bloom.cc +92 -0
  529. package/cpp/leveldb/util/bloom_test.cc +159 -0
  530. package/cpp/leveldb/util/cache.cc +401 -0
  531. package/cpp/leveldb/util/cache_test.cc +229 -0
  532. package/cpp/leveldb/util/coding.cc +166 -0
  533. package/cpp/leveldb/util/coding.h +122 -0
  534. package/cpp/leveldb/util/coding_test.cc +198 -0
  535. package/cpp/leveldb/util/comparator.cc +75 -0
  536. package/cpp/leveldb/util/crc32c.cc +380 -0
  537. package/cpp/leveldb/util/crc32c.h +43 -0
  538. package/cpp/leveldb/util/crc32c_test.cc +61 -0
  539. package/cpp/leveldb/util/env.cc +108 -0
  540. package/cpp/leveldb/util/env_posix.cc +893 -0
  541. package/cpp/leveldb/util/env_posix_test.cc +353 -0
  542. package/cpp/leveldb/util/env_posix_test_helper.h +28 -0
  543. package/cpp/leveldb/util/env_test.cc +240 -0
  544. package/cpp/leveldb/util/env_windows.cc +796 -0
  545. package/cpp/leveldb/util/env_windows_test.cc +65 -0
  546. package/cpp/leveldb/util/env_windows_test_helper.h +25 -0
  547. package/cpp/leveldb/util/filter_policy.cc +11 -0
  548. package/cpp/leveldb/util/hash.cc +55 -0
  549. package/cpp/leveldb/util/hash.h +19 -0
  550. package/cpp/leveldb/util/hash_test.cc +46 -0
  551. package/cpp/leveldb/util/histogram.cc +272 -0
  552. package/cpp/leveldb/util/histogram.h +44 -0
  553. package/cpp/leveldb/util/logging.cc +82 -0
  554. package/cpp/leveldb/util/logging.h +44 -0
  555. package/cpp/leveldb/util/logging_test.cc +145 -0
  556. package/cpp/leveldb/util/mutexlock.h +39 -0
  557. package/cpp/leveldb/util/no_destructor.h +46 -0
  558. package/cpp/leveldb/util/no_destructor_test.cc +49 -0
  559. package/cpp/leveldb/util/options.cc +14 -0
  560. package/cpp/leveldb/util/posix_logger.h +130 -0
  561. package/cpp/leveldb/util/random.h +63 -0
  562. package/cpp/leveldb/util/status.cc +77 -0
  563. package/cpp/leveldb/util/status_test.cc +44 -0
  564. package/cpp/leveldb/util/testutil.cc +51 -0
  565. package/cpp/leveldb/util/testutil.h +82 -0
  566. package/cpp/leveldb/util/windows_logger.h +124 -0
  567. package/cpp/react-native-leveldb.cpp +694 -0
  568. package/cpp/react-native-leveldb.h +4 -0
  569. package/ios/Leveldb.h +9 -0
  570. package/ios/Leveldb.mm +35 -0
  571. package/ios/Leveldb.xcodeproj/project.pbxproj +288 -0
  572. package/lib/commonjs/fake.js +181 -0
  573. package/lib/commonjs/fake.js.map +1 -0
  574. package/lib/commonjs/fake.test.js +30 -0
  575. package/lib/commonjs/fake.test.js.map +1 -0
  576. package/lib/commonjs/index.js +172 -0
  577. package/lib/commonjs/index.js.map +1 -0
  578. package/lib/commonjs/package.json +1 -0
  579. package/lib/module/fake.js +171 -0
  580. package/lib/module/fake.js.map +1 -0
  581. package/lib/module/fake.test.js +30 -0
  582. package/lib/module/fake.test.js.map +1 -0
  583. package/lib/module/index.js +165 -0
  584. package/lib/module/index.js.map +1 -0
  585. package/lib/typescript/fake.d.ts +34 -0
  586. package/lib/typescript/fake.d.ts.map +1 -0
  587. package/lib/typescript/fake.test.d.ts +2 -0
  588. package/lib/typescript/fake.test.d.ts.map +1 -0
  589. package/lib/typescript/index.d.ts +72 -0
  590. package/lib/typescript/index.d.ts.map +1 -0
  591. package/package.json +157 -0
  592. package/rn-leveldb.podspec +30 -0
  593. package/src/fake.test.ts +37 -0
  594. package/src/fake.ts +203 -0
  595. package/src/index.ts +291 -0
@@ -0,0 +1,4591 @@
1
+ // Copyright 2007, 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
+
31
+ // Google Mock - a framework for writing C++ mock classes.
32
+ //
33
+ // This file implements some commonly used argument matchers. More
34
+ // matchers can be defined by the user implementing the
35
+ // MatcherInterface<T> interface if necessary.
36
+ //
37
+ // See googletest/include/gtest/gtest-matchers.h for the definition of class
38
+ // Matcher, class MatcherInterface, and others.
39
+
40
+ // GOOGLETEST_CM0002 DO NOT DELETE
41
+
42
+ #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_
43
+ #define GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_
44
+
45
+ #include <algorithm>
46
+ #include <cmath>
47
+ #include <initializer_list>
48
+ #include <iterator>
49
+ #include <limits>
50
+ #include <memory>
51
+ #include <ostream> // NOLINT
52
+ #include <sstream>
53
+ #include <string>
54
+ #include <type_traits>
55
+ #include <utility>
56
+ #include <vector>
57
+
58
+ #include "gmock/internal/gmock-internal-utils.h"
59
+ #include "gmock/internal/gmock-port.h"
60
+ #include "gtest/gtest.h"
61
+
62
+ // MSVC warning C5046 is new as of VS2017 version 15.8.
63
+ #if defined(_MSC_VER) && _MSC_VER >= 1915
64
+ #define GMOCK_MAYBE_5046_ 5046
65
+ #else
66
+ #define GMOCK_MAYBE_5046_
67
+ #endif
68
+
69
+ GTEST_DISABLE_MSC_WARNINGS_PUSH_(
70
+ 4251 GMOCK_MAYBE_5046_ /* class A needs to have dll-interface to be used by
71
+ clients of class B */
72
+ /* Symbol involving type with internal linkage not defined */)
73
+
74
+ namespace testing {
75
+
76
+ // To implement a matcher Foo for type T, define:
77
+ // 1. a class FooMatcherImpl that implements the
78
+ // MatcherInterface<T> interface, and
79
+ // 2. a factory function that creates a Matcher<T> object from a
80
+ // FooMatcherImpl*.
81
+ //
82
+ // The two-level delegation design makes it possible to allow a user
83
+ // to write "v" instead of "Eq(v)" where a Matcher is expected, which
84
+ // is impossible if we pass matchers by pointers. It also eases
85
+ // ownership management as Matcher objects can now be copied like
86
+ // plain values.
87
+
88
+ // A match result listener that stores the explanation in a string.
89
+ class StringMatchResultListener : public MatchResultListener {
90
+ public:
91
+ StringMatchResultListener() : MatchResultListener(&ss_) {}
92
+
93
+ // Returns the explanation accumulated so far.
94
+ std::string str() const { return ss_.str(); }
95
+
96
+ // Clears the explanation accumulated so far.
97
+ void Clear() { ss_.str(""); }
98
+
99
+ private:
100
+ ::std::stringstream ss_;
101
+
102
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(StringMatchResultListener);
103
+ };
104
+
105
+ // Anything inside the 'internal' namespace IS INTERNAL IMPLEMENTATION
106
+ // and MUST NOT BE USED IN USER CODE!!!
107
+ namespace internal {
108
+
109
+ // The MatcherCastImpl class template is a helper for implementing
110
+ // MatcherCast(). We need this helper in order to partially
111
+ // specialize the implementation of MatcherCast() (C++ allows
112
+ // class/struct templates to be partially specialized, but not
113
+ // function templates.).
114
+
115
+ // This general version is used when MatcherCast()'s argument is a
116
+ // polymorphic matcher (i.e. something that can be converted to a
117
+ // Matcher but is not one yet; for example, Eq(value)) or a value (for
118
+ // example, "hello").
119
+ template <typename T, typename M>
120
+ class MatcherCastImpl {
121
+ public:
122
+ static Matcher<T> Cast(const M& polymorphic_matcher_or_value) {
123
+ // M can be a polymorphic matcher, in which case we want to use
124
+ // its conversion operator to create Matcher<T>. Or it can be a value
125
+ // that should be passed to the Matcher<T>'s constructor.
126
+ //
127
+ // We can't call Matcher<T>(polymorphic_matcher_or_value) when M is a
128
+ // polymorphic matcher because it'll be ambiguous if T has an implicit
129
+ // constructor from M (this usually happens when T has an implicit
130
+ // constructor from any type).
131
+ //
132
+ // It won't work to unconditionally implict_cast
133
+ // polymorphic_matcher_or_value to Matcher<T> because it won't trigger
134
+ // a user-defined conversion from M to T if one exists (assuming M is
135
+ // a value).
136
+ return CastImpl(polymorphic_matcher_or_value,
137
+ std::is_convertible<M, Matcher<T>>{},
138
+ std::is_convertible<M, T>{});
139
+ }
140
+
141
+ private:
142
+ template <bool Ignore>
143
+ static Matcher<T> CastImpl(const M& polymorphic_matcher_or_value,
144
+ std::true_type /* convertible_to_matcher */,
145
+ std::integral_constant<bool, Ignore>) {
146
+ // M is implicitly convertible to Matcher<T>, which means that either
147
+ // M is a polymorphic matcher or Matcher<T> has an implicit constructor
148
+ // from M. In both cases using the implicit conversion will produce a
149
+ // matcher.
150
+ //
151
+ // Even if T has an implicit constructor from M, it won't be called because
152
+ // creating Matcher<T> would require a chain of two user-defined conversions
153
+ // (first to create T from M and then to create Matcher<T> from T).
154
+ return polymorphic_matcher_or_value;
155
+ }
156
+
157
+ // M can't be implicitly converted to Matcher<T>, so M isn't a polymorphic
158
+ // matcher. It's a value of a type implicitly convertible to T. Use direct
159
+ // initialization to create a matcher.
160
+ static Matcher<T> CastImpl(const M& value,
161
+ std::false_type /* convertible_to_matcher */,
162
+ std::true_type /* convertible_to_T */) {
163
+ return Matcher<T>(ImplicitCast_<T>(value));
164
+ }
165
+
166
+ // M can't be implicitly converted to either Matcher<T> or T. Attempt to use
167
+ // polymorphic matcher Eq(value) in this case.
168
+ //
169
+ // Note that we first attempt to perform an implicit cast on the value and
170
+ // only fall back to the polymorphic Eq() matcher afterwards because the
171
+ // latter calls bool operator==(const Lhs& lhs, const Rhs& rhs) in the end
172
+ // which might be undefined even when Rhs is implicitly convertible to Lhs
173
+ // (e.g. std::pair<const int, int> vs. std::pair<int, int>).
174
+ //
175
+ // We don't define this method inline as we need the declaration of Eq().
176
+ static Matcher<T> CastImpl(const M& value,
177
+ std::false_type /* convertible_to_matcher */,
178
+ std::false_type /* convertible_to_T */);
179
+ };
180
+
181
+ // This more specialized version is used when MatcherCast()'s argument
182
+ // is already a Matcher. This only compiles when type T can be
183
+ // statically converted to type U.
184
+ template <typename T, typename U>
185
+ class MatcherCastImpl<T, Matcher<U> > {
186
+ public:
187
+ static Matcher<T> Cast(const Matcher<U>& source_matcher) {
188
+ return Matcher<T>(new Impl(source_matcher));
189
+ }
190
+
191
+ private:
192
+ class Impl : public MatcherInterface<T> {
193
+ public:
194
+ explicit Impl(const Matcher<U>& source_matcher)
195
+ : source_matcher_(source_matcher) {}
196
+
197
+ // We delegate the matching logic to the source matcher.
198
+ bool MatchAndExplain(T x, MatchResultListener* listener) const override {
199
+ using FromType = typename std::remove_cv<typename std::remove_pointer<
200
+ typename std::remove_reference<T>::type>::type>::type;
201
+ using ToType = typename std::remove_cv<typename std::remove_pointer<
202
+ typename std::remove_reference<U>::type>::type>::type;
203
+ // Do not allow implicitly converting base*/& to derived*/&.
204
+ static_assert(
205
+ // Do not trigger if only one of them is a pointer. That implies a
206
+ // regular conversion and not a down_cast.
207
+ (std::is_pointer<typename std::remove_reference<T>::type>::value !=
208
+ std::is_pointer<typename std::remove_reference<U>::type>::value) ||
209
+ std::is_same<FromType, ToType>::value ||
210
+ !std::is_base_of<FromType, ToType>::value,
211
+ "Can't implicitly convert from <base> to <derived>");
212
+
213
+ return source_matcher_.MatchAndExplain(static_cast<U>(x), listener);
214
+ }
215
+
216
+ void DescribeTo(::std::ostream* os) const override {
217
+ source_matcher_.DescribeTo(os);
218
+ }
219
+
220
+ void DescribeNegationTo(::std::ostream* os) const override {
221
+ source_matcher_.DescribeNegationTo(os);
222
+ }
223
+
224
+ private:
225
+ const Matcher<U> source_matcher_;
226
+
227
+ GTEST_DISALLOW_ASSIGN_(Impl);
228
+ };
229
+ };
230
+
231
+ // This even more specialized version is used for efficiently casting
232
+ // a matcher to its own type.
233
+ template <typename T>
234
+ class MatcherCastImpl<T, Matcher<T> > {
235
+ public:
236
+ static Matcher<T> Cast(const Matcher<T>& matcher) { return matcher; }
237
+ };
238
+
239
+ } // namespace internal
240
+
241
+ // In order to be safe and clear, casting between different matcher
242
+ // types is done explicitly via MatcherCast<T>(m), which takes a
243
+ // matcher m and returns a Matcher<T>. It compiles only when T can be
244
+ // statically converted to the argument type of m.
245
+ template <typename T, typename M>
246
+ inline Matcher<T> MatcherCast(const M& matcher) {
247
+ return internal::MatcherCastImpl<T, M>::Cast(matcher);
248
+ }
249
+
250
+ // Implements SafeMatcherCast().
251
+ //
252
+ // FIXME: The intermediate SafeMatcherCastImpl class was introduced as a
253
+ // workaround for a compiler bug, and can now be removed.
254
+ template <typename T>
255
+ class SafeMatcherCastImpl {
256
+ public:
257
+ // This overload handles polymorphic matchers and values only since
258
+ // monomorphic matchers are handled by the next one.
259
+ template <typename M>
260
+ static inline Matcher<T> Cast(const M& polymorphic_matcher_or_value) {
261
+ return internal::MatcherCastImpl<T, M>::Cast(polymorphic_matcher_or_value);
262
+ }
263
+
264
+ // This overload handles monomorphic matchers.
265
+ //
266
+ // In general, if type T can be implicitly converted to type U, we can
267
+ // safely convert a Matcher<U> to a Matcher<T> (i.e. Matcher is
268
+ // contravariant): just keep a copy of the original Matcher<U>, convert the
269
+ // argument from type T to U, and then pass it to the underlying Matcher<U>.
270
+ // The only exception is when U is a reference and T is not, as the
271
+ // underlying Matcher<U> may be interested in the argument's address, which
272
+ // is not preserved in the conversion from T to U.
273
+ template <typename U>
274
+ static inline Matcher<T> Cast(const Matcher<U>& matcher) {
275
+ // Enforce that T can be implicitly converted to U.
276
+ GTEST_COMPILE_ASSERT_((std::is_convertible<T, U>::value),
277
+ "T must be implicitly convertible to U");
278
+ // Enforce that we are not converting a non-reference type T to a reference
279
+ // type U.
280
+ GTEST_COMPILE_ASSERT_(
281
+ std::is_reference<T>::value || !std::is_reference<U>::value,
282
+ cannot_convert_non_reference_arg_to_reference);
283
+ // In case both T and U are arithmetic types, enforce that the
284
+ // conversion is not lossy.
285
+ typedef GTEST_REMOVE_REFERENCE_AND_CONST_(T) RawT;
286
+ typedef GTEST_REMOVE_REFERENCE_AND_CONST_(U) RawU;
287
+ const bool kTIsOther = GMOCK_KIND_OF_(RawT) == internal::kOther;
288
+ const bool kUIsOther = GMOCK_KIND_OF_(RawU) == internal::kOther;
289
+ GTEST_COMPILE_ASSERT_(
290
+ kTIsOther || kUIsOther ||
291
+ (internal::LosslessArithmeticConvertible<RawT, RawU>::value),
292
+ conversion_of_arithmetic_types_must_be_lossless);
293
+ return MatcherCast<T>(matcher);
294
+ }
295
+ };
296
+
297
+ template <typename T, typename M>
298
+ inline Matcher<T> SafeMatcherCast(const M& polymorphic_matcher) {
299
+ return SafeMatcherCastImpl<T>::Cast(polymorphic_matcher);
300
+ }
301
+
302
+ // A<T>() returns a matcher that matches any value of type T.
303
+ template <typename T>
304
+ Matcher<T> A();
305
+
306
+ // Anything inside the 'internal' namespace IS INTERNAL IMPLEMENTATION
307
+ // and MUST NOT BE USED IN USER CODE!!!
308
+ namespace internal {
309
+
310
+ // If the explanation is not empty, prints it to the ostream.
311
+ inline void PrintIfNotEmpty(const std::string& explanation,
312
+ ::std::ostream* os) {
313
+ if (explanation != "" && os != nullptr) {
314
+ *os << ", " << explanation;
315
+ }
316
+ }
317
+
318
+ // Returns true if the given type name is easy to read by a human.
319
+ // This is used to decide whether printing the type of a value might
320
+ // be helpful.
321
+ inline bool IsReadableTypeName(const std::string& type_name) {
322
+ // We consider a type name readable if it's short or doesn't contain
323
+ // a template or function type.
324
+ return (type_name.length() <= 20 ||
325
+ type_name.find_first_of("<(") == std::string::npos);
326
+ }
327
+
328
+ // Matches the value against the given matcher, prints the value and explains
329
+ // the match result to the listener. Returns the match result.
330
+ // 'listener' must not be NULL.
331
+ // Value cannot be passed by const reference, because some matchers take a
332
+ // non-const argument.
333
+ template <typename Value, typename T>
334
+ bool MatchPrintAndExplain(Value& value, const Matcher<T>& matcher,
335
+ MatchResultListener* listener) {
336
+ if (!listener->IsInterested()) {
337
+ // If the listener is not interested, we do not need to construct the
338
+ // inner explanation.
339
+ return matcher.Matches(value);
340
+ }
341
+
342
+ StringMatchResultListener inner_listener;
343
+ const bool match = matcher.MatchAndExplain(value, &inner_listener);
344
+
345
+ UniversalPrint(value, listener->stream());
346
+ #if GTEST_HAS_RTTI
347
+ const std::string& type_name = GetTypeName<Value>();
348
+ if (IsReadableTypeName(type_name))
349
+ *listener->stream() << " (of type " << type_name << ")";
350
+ #endif
351
+ PrintIfNotEmpty(inner_listener.str(), listener->stream());
352
+
353
+ return match;
354
+ }
355
+
356
+ // An internal helper class for doing compile-time loop on a tuple's
357
+ // fields.
358
+ template <size_t N>
359
+ class TuplePrefix {
360
+ public:
361
+ // TuplePrefix<N>::Matches(matcher_tuple, value_tuple) returns true
362
+ // if and only if the first N fields of matcher_tuple matches
363
+ // the first N fields of value_tuple, respectively.
364
+ template <typename MatcherTuple, typename ValueTuple>
365
+ static bool Matches(const MatcherTuple& matcher_tuple,
366
+ const ValueTuple& value_tuple) {
367
+ return TuplePrefix<N - 1>::Matches(matcher_tuple, value_tuple) &&
368
+ std::get<N - 1>(matcher_tuple).Matches(std::get<N - 1>(value_tuple));
369
+ }
370
+
371
+ // TuplePrefix<N>::ExplainMatchFailuresTo(matchers, values, os)
372
+ // describes failures in matching the first N fields of matchers
373
+ // against the first N fields of values. If there is no failure,
374
+ // nothing will be streamed to os.
375
+ template <typename MatcherTuple, typename ValueTuple>
376
+ static void ExplainMatchFailuresTo(const MatcherTuple& matchers,
377
+ const ValueTuple& values,
378
+ ::std::ostream* os) {
379
+ // First, describes failures in the first N - 1 fields.
380
+ TuplePrefix<N - 1>::ExplainMatchFailuresTo(matchers, values, os);
381
+
382
+ // Then describes the failure (if any) in the (N - 1)-th (0-based)
383
+ // field.
384
+ typename std::tuple_element<N - 1, MatcherTuple>::type matcher =
385
+ std::get<N - 1>(matchers);
386
+ typedef typename std::tuple_element<N - 1, ValueTuple>::type Value;
387
+ const Value& value = std::get<N - 1>(values);
388
+ StringMatchResultListener listener;
389
+ if (!matcher.MatchAndExplain(value, &listener)) {
390
+ *os << " Expected arg #" << N - 1 << ": ";
391
+ std::get<N - 1>(matchers).DescribeTo(os);
392
+ *os << "\n Actual: ";
393
+ // We remove the reference in type Value to prevent the
394
+ // universal printer from printing the address of value, which
395
+ // isn't interesting to the user most of the time. The
396
+ // matcher's MatchAndExplain() method handles the case when
397
+ // the address is interesting.
398
+ internal::UniversalPrint(value, os);
399
+ PrintIfNotEmpty(listener.str(), os);
400
+ *os << "\n";
401
+ }
402
+ }
403
+ };
404
+
405
+ // The base case.
406
+ template <>
407
+ class TuplePrefix<0> {
408
+ public:
409
+ template <typename MatcherTuple, typename ValueTuple>
410
+ static bool Matches(const MatcherTuple& /* matcher_tuple */,
411
+ const ValueTuple& /* value_tuple */) {
412
+ return true;
413
+ }
414
+
415
+ template <typename MatcherTuple, typename ValueTuple>
416
+ static void ExplainMatchFailuresTo(const MatcherTuple& /* matchers */,
417
+ const ValueTuple& /* values */,
418
+ ::std::ostream* /* os */) {}
419
+ };
420
+
421
+ // TupleMatches(matcher_tuple, value_tuple) returns true if and only if
422
+ // all matchers in matcher_tuple match the corresponding fields in
423
+ // value_tuple. It is a compiler error if matcher_tuple and
424
+ // value_tuple have different number of fields or incompatible field
425
+ // types.
426
+ template <typename MatcherTuple, typename ValueTuple>
427
+ bool TupleMatches(const MatcherTuple& matcher_tuple,
428
+ const ValueTuple& value_tuple) {
429
+ // Makes sure that matcher_tuple and value_tuple have the same
430
+ // number of fields.
431
+ GTEST_COMPILE_ASSERT_(std::tuple_size<MatcherTuple>::value ==
432
+ std::tuple_size<ValueTuple>::value,
433
+ matcher_and_value_have_different_numbers_of_fields);
434
+ return TuplePrefix<std::tuple_size<ValueTuple>::value>::Matches(matcher_tuple,
435
+ value_tuple);
436
+ }
437
+
438
+ // Describes failures in matching matchers against values. If there
439
+ // is no failure, nothing will be streamed to os.
440
+ template <typename MatcherTuple, typename ValueTuple>
441
+ void ExplainMatchFailureTupleTo(const MatcherTuple& matchers,
442
+ const ValueTuple& values,
443
+ ::std::ostream* os) {
444
+ TuplePrefix<std::tuple_size<MatcherTuple>::value>::ExplainMatchFailuresTo(
445
+ matchers, values, os);
446
+ }
447
+
448
+ // TransformTupleValues and its helper.
449
+ //
450
+ // TransformTupleValuesHelper hides the internal machinery that
451
+ // TransformTupleValues uses to implement a tuple traversal.
452
+ template <typename Tuple, typename Func, typename OutIter>
453
+ class TransformTupleValuesHelper {
454
+ private:
455
+ typedef ::std::tuple_size<Tuple> TupleSize;
456
+
457
+ public:
458
+ // For each member of tuple 't', taken in order, evaluates '*out++ = f(t)'.
459
+ // Returns the final value of 'out' in case the caller needs it.
460
+ static OutIter Run(Func f, const Tuple& t, OutIter out) {
461
+ return IterateOverTuple<Tuple, TupleSize::value>()(f, t, out);
462
+ }
463
+
464
+ private:
465
+ template <typename Tup, size_t kRemainingSize>
466
+ struct IterateOverTuple {
467
+ OutIter operator() (Func f, const Tup& t, OutIter out) const {
468
+ *out++ = f(::std::get<TupleSize::value - kRemainingSize>(t));
469
+ return IterateOverTuple<Tup, kRemainingSize - 1>()(f, t, out);
470
+ }
471
+ };
472
+ template <typename Tup>
473
+ struct IterateOverTuple<Tup, 0> {
474
+ OutIter operator() (Func /* f */, const Tup& /* t */, OutIter out) const {
475
+ return out;
476
+ }
477
+ };
478
+ };
479
+
480
+ // Successively invokes 'f(element)' on each element of the tuple 't',
481
+ // appending each result to the 'out' iterator. Returns the final value
482
+ // of 'out'.
483
+ template <typename Tuple, typename Func, typename OutIter>
484
+ OutIter TransformTupleValues(Func f, const Tuple& t, OutIter out) {
485
+ return TransformTupleValuesHelper<Tuple, Func, OutIter>::Run(f, t, out);
486
+ }
487
+
488
+ // Implements A<T>().
489
+ template <typename T>
490
+ class AnyMatcherImpl : public MatcherInterface<const T&> {
491
+ public:
492
+ bool MatchAndExplain(const T& /* x */,
493
+ MatchResultListener* /* listener */) const override {
494
+ return true;
495
+ }
496
+ void DescribeTo(::std::ostream* os) const override { *os << "is anything"; }
497
+ void DescribeNegationTo(::std::ostream* os) const override {
498
+ // This is mostly for completeness' safe, as it's not very useful
499
+ // to write Not(A<bool>()). However we cannot completely rule out
500
+ // such a possibility, and it doesn't hurt to be prepared.
501
+ *os << "never matches";
502
+ }
503
+ };
504
+
505
+ // Implements _, a matcher that matches any value of any
506
+ // type. This is a polymorphic matcher, so we need a template type
507
+ // conversion operator to make it appearing as a Matcher<T> for any
508
+ // type T.
509
+ class AnythingMatcher {
510
+ public:
511
+ template <typename T>
512
+ operator Matcher<T>() const { return A<T>(); }
513
+ };
514
+
515
+ // Implements the polymorphic IsNull() matcher, which matches any raw or smart
516
+ // pointer that is NULL.
517
+ class IsNullMatcher {
518
+ public:
519
+ template <typename Pointer>
520
+ bool MatchAndExplain(const Pointer& p,
521
+ MatchResultListener* /* listener */) const {
522
+ return p == nullptr;
523
+ }
524
+
525
+ void DescribeTo(::std::ostream* os) const { *os << "is NULL"; }
526
+ void DescribeNegationTo(::std::ostream* os) const {
527
+ *os << "isn't NULL";
528
+ }
529
+ };
530
+
531
+ // Implements the polymorphic NotNull() matcher, which matches any raw or smart
532
+ // pointer that is not NULL.
533
+ class NotNullMatcher {
534
+ public:
535
+ template <typename Pointer>
536
+ bool MatchAndExplain(const Pointer& p,
537
+ MatchResultListener* /* listener */) const {
538
+ return p != nullptr;
539
+ }
540
+
541
+ void DescribeTo(::std::ostream* os) const { *os << "isn't NULL"; }
542
+ void DescribeNegationTo(::std::ostream* os) const {
543
+ *os << "is NULL";
544
+ }
545
+ };
546
+
547
+ // Ref(variable) matches any argument that is a reference to
548
+ // 'variable'. This matcher is polymorphic as it can match any
549
+ // super type of the type of 'variable'.
550
+ //
551
+ // The RefMatcher template class implements Ref(variable). It can
552
+ // only be instantiated with a reference type. This prevents a user
553
+ // from mistakenly using Ref(x) to match a non-reference function
554
+ // argument. For example, the following will righteously cause a
555
+ // compiler error:
556
+ //
557
+ // int n;
558
+ // Matcher<int> m1 = Ref(n); // This won't compile.
559
+ // Matcher<int&> m2 = Ref(n); // This will compile.
560
+ template <typename T>
561
+ class RefMatcher;
562
+
563
+ template <typename T>
564
+ class RefMatcher<T&> {
565
+ // Google Mock is a generic framework and thus needs to support
566
+ // mocking any function types, including those that take non-const
567
+ // reference arguments. Therefore the template parameter T (and
568
+ // Super below) can be instantiated to either a const type or a
569
+ // non-const type.
570
+ public:
571
+ // RefMatcher() takes a T& instead of const T&, as we want the
572
+ // compiler to catch using Ref(const_value) as a matcher for a
573
+ // non-const reference.
574
+ explicit RefMatcher(T& x) : object_(x) {} // NOLINT
575
+
576
+ template <typename Super>
577
+ operator Matcher<Super&>() const {
578
+ // By passing object_ (type T&) to Impl(), which expects a Super&,
579
+ // we make sure that Super is a super type of T. In particular,
580
+ // this catches using Ref(const_value) as a matcher for a
581
+ // non-const reference, as you cannot implicitly convert a const
582
+ // reference to a non-const reference.
583
+ return MakeMatcher(new Impl<Super>(object_));
584
+ }
585
+
586
+ private:
587
+ template <typename Super>
588
+ class Impl : public MatcherInterface<Super&> {
589
+ public:
590
+ explicit Impl(Super& x) : object_(x) {} // NOLINT
591
+
592
+ // MatchAndExplain() takes a Super& (as opposed to const Super&)
593
+ // in order to match the interface MatcherInterface<Super&>.
594
+ bool MatchAndExplain(Super& x,
595
+ MatchResultListener* listener) const override {
596
+ *listener << "which is located @" << static_cast<const void*>(&x);
597
+ return &x == &object_;
598
+ }
599
+
600
+ void DescribeTo(::std::ostream* os) const override {
601
+ *os << "references the variable ";
602
+ UniversalPrinter<Super&>::Print(object_, os);
603
+ }
604
+
605
+ void DescribeNegationTo(::std::ostream* os) const override {
606
+ *os << "does not reference the variable ";
607
+ UniversalPrinter<Super&>::Print(object_, os);
608
+ }
609
+
610
+ private:
611
+ const Super& object_;
612
+
613
+ GTEST_DISALLOW_ASSIGN_(Impl);
614
+ };
615
+
616
+ T& object_;
617
+
618
+ GTEST_DISALLOW_ASSIGN_(RefMatcher);
619
+ };
620
+
621
+ // Polymorphic helper functions for narrow and wide string matchers.
622
+ inline bool CaseInsensitiveCStringEquals(const char* lhs, const char* rhs) {
623
+ return String::CaseInsensitiveCStringEquals(lhs, rhs);
624
+ }
625
+
626
+ inline bool CaseInsensitiveCStringEquals(const wchar_t* lhs,
627
+ const wchar_t* rhs) {
628
+ return String::CaseInsensitiveWideCStringEquals(lhs, rhs);
629
+ }
630
+
631
+ // String comparison for narrow or wide strings that can have embedded NUL
632
+ // characters.
633
+ template <typename StringType>
634
+ bool CaseInsensitiveStringEquals(const StringType& s1,
635
+ const StringType& s2) {
636
+ // Are the heads equal?
637
+ if (!CaseInsensitiveCStringEquals(s1.c_str(), s2.c_str())) {
638
+ return false;
639
+ }
640
+
641
+ // Skip the equal heads.
642
+ const typename StringType::value_type nul = 0;
643
+ const size_t i1 = s1.find(nul), i2 = s2.find(nul);
644
+
645
+ // Are we at the end of either s1 or s2?
646
+ if (i1 == StringType::npos || i2 == StringType::npos) {
647
+ return i1 == i2;
648
+ }
649
+
650
+ // Are the tails equal?
651
+ return CaseInsensitiveStringEquals(s1.substr(i1 + 1), s2.substr(i2 + 1));
652
+ }
653
+
654
+ // String matchers.
655
+
656
+ // Implements equality-based string matchers like StrEq, StrCaseNe, and etc.
657
+ template <typename StringType>
658
+ class StrEqualityMatcher {
659
+ public:
660
+ StrEqualityMatcher(const StringType& str, bool expect_eq,
661
+ bool case_sensitive)
662
+ : string_(str), expect_eq_(expect_eq), case_sensitive_(case_sensitive) {}
663
+
664
+ #if GTEST_HAS_ABSL
665
+ bool MatchAndExplain(const absl::string_view& s,
666
+ MatchResultListener* listener) const {
667
+ // This should fail to compile if absl::string_view is used with wide
668
+ // strings.
669
+ const StringType& str = std::string(s);
670
+ return MatchAndExplain(str, listener);
671
+ }
672
+ #endif // GTEST_HAS_ABSL
673
+
674
+ // Accepts pointer types, particularly:
675
+ // const char*
676
+ // char*
677
+ // const wchar_t*
678
+ // wchar_t*
679
+ template <typename CharType>
680
+ bool MatchAndExplain(CharType* s, MatchResultListener* listener) const {
681
+ if (s == nullptr) {
682
+ return !expect_eq_;
683
+ }
684
+ return MatchAndExplain(StringType(s), listener);
685
+ }
686
+
687
+ // Matches anything that can convert to StringType.
688
+ //
689
+ // This is a template, not just a plain function with const StringType&,
690
+ // because absl::string_view has some interfering non-explicit constructors.
691
+ template <typename MatcheeStringType>
692
+ bool MatchAndExplain(const MatcheeStringType& s,
693
+ MatchResultListener* /* listener */) const {
694
+ const StringType& s2(s);
695
+ const bool eq = case_sensitive_ ? s2 == string_ :
696
+ CaseInsensitiveStringEquals(s2, string_);
697
+ return expect_eq_ == eq;
698
+ }
699
+
700
+ void DescribeTo(::std::ostream* os) const {
701
+ DescribeToHelper(expect_eq_, os);
702
+ }
703
+
704
+ void DescribeNegationTo(::std::ostream* os) const {
705
+ DescribeToHelper(!expect_eq_, os);
706
+ }
707
+
708
+ private:
709
+ void DescribeToHelper(bool expect_eq, ::std::ostream* os) const {
710
+ *os << (expect_eq ? "is " : "isn't ");
711
+ *os << "equal to ";
712
+ if (!case_sensitive_) {
713
+ *os << "(ignoring case) ";
714
+ }
715
+ UniversalPrint(string_, os);
716
+ }
717
+
718
+ const StringType string_;
719
+ const bool expect_eq_;
720
+ const bool case_sensitive_;
721
+
722
+ GTEST_DISALLOW_ASSIGN_(StrEqualityMatcher);
723
+ };
724
+
725
+ // Implements the polymorphic HasSubstr(substring) matcher, which
726
+ // can be used as a Matcher<T> as long as T can be converted to a
727
+ // string.
728
+ template <typename StringType>
729
+ class HasSubstrMatcher {
730
+ public:
731
+ explicit HasSubstrMatcher(const StringType& substring)
732
+ : substring_(substring) {}
733
+
734
+ #if GTEST_HAS_ABSL
735
+ bool MatchAndExplain(const absl::string_view& s,
736
+ MatchResultListener* listener) const {
737
+ // This should fail to compile if absl::string_view is used with wide
738
+ // strings.
739
+ const StringType& str = std::string(s);
740
+ return MatchAndExplain(str, listener);
741
+ }
742
+ #endif // GTEST_HAS_ABSL
743
+
744
+ // Accepts pointer types, particularly:
745
+ // const char*
746
+ // char*
747
+ // const wchar_t*
748
+ // wchar_t*
749
+ template <typename CharType>
750
+ bool MatchAndExplain(CharType* s, MatchResultListener* listener) const {
751
+ return s != nullptr && MatchAndExplain(StringType(s), listener);
752
+ }
753
+
754
+ // Matches anything that can convert to StringType.
755
+ //
756
+ // This is a template, not just a plain function with const StringType&,
757
+ // because absl::string_view has some interfering non-explicit constructors.
758
+ template <typename MatcheeStringType>
759
+ bool MatchAndExplain(const MatcheeStringType& s,
760
+ MatchResultListener* /* listener */) const {
761
+ return StringType(s).find(substring_) != StringType::npos;
762
+ }
763
+
764
+ // Describes what this matcher matches.
765
+ void DescribeTo(::std::ostream* os) const {
766
+ *os << "has substring ";
767
+ UniversalPrint(substring_, os);
768
+ }
769
+
770
+ void DescribeNegationTo(::std::ostream* os) const {
771
+ *os << "has no substring ";
772
+ UniversalPrint(substring_, os);
773
+ }
774
+
775
+ private:
776
+ const StringType substring_;
777
+
778
+ GTEST_DISALLOW_ASSIGN_(HasSubstrMatcher);
779
+ };
780
+
781
+ // Implements the polymorphic StartsWith(substring) matcher, which
782
+ // can be used as a Matcher<T> as long as T can be converted to a
783
+ // string.
784
+ template <typename StringType>
785
+ class StartsWithMatcher {
786
+ public:
787
+ explicit StartsWithMatcher(const StringType& prefix) : prefix_(prefix) {
788
+ }
789
+
790
+ #if GTEST_HAS_ABSL
791
+ bool MatchAndExplain(const absl::string_view& s,
792
+ MatchResultListener* listener) const {
793
+ // This should fail to compile if absl::string_view is used with wide
794
+ // strings.
795
+ const StringType& str = std::string(s);
796
+ return MatchAndExplain(str, listener);
797
+ }
798
+ #endif // GTEST_HAS_ABSL
799
+
800
+ // Accepts pointer types, particularly:
801
+ // const char*
802
+ // char*
803
+ // const wchar_t*
804
+ // wchar_t*
805
+ template <typename CharType>
806
+ bool MatchAndExplain(CharType* s, MatchResultListener* listener) const {
807
+ return s != nullptr && MatchAndExplain(StringType(s), listener);
808
+ }
809
+
810
+ // Matches anything that can convert to StringType.
811
+ //
812
+ // This is a template, not just a plain function with const StringType&,
813
+ // because absl::string_view has some interfering non-explicit constructors.
814
+ template <typename MatcheeStringType>
815
+ bool MatchAndExplain(const MatcheeStringType& s,
816
+ MatchResultListener* /* listener */) const {
817
+ const StringType& s2(s);
818
+ return s2.length() >= prefix_.length() &&
819
+ s2.substr(0, prefix_.length()) == prefix_;
820
+ }
821
+
822
+ void DescribeTo(::std::ostream* os) const {
823
+ *os << "starts with ";
824
+ UniversalPrint(prefix_, os);
825
+ }
826
+
827
+ void DescribeNegationTo(::std::ostream* os) const {
828
+ *os << "doesn't start with ";
829
+ UniversalPrint(prefix_, os);
830
+ }
831
+
832
+ private:
833
+ const StringType prefix_;
834
+
835
+ GTEST_DISALLOW_ASSIGN_(StartsWithMatcher);
836
+ };
837
+
838
+ // Implements the polymorphic EndsWith(substring) matcher, which
839
+ // can be used as a Matcher<T> as long as T can be converted to a
840
+ // string.
841
+ template <typename StringType>
842
+ class EndsWithMatcher {
843
+ public:
844
+ explicit EndsWithMatcher(const StringType& suffix) : suffix_(suffix) {}
845
+
846
+ #if GTEST_HAS_ABSL
847
+ bool MatchAndExplain(const absl::string_view& s,
848
+ MatchResultListener* listener) const {
849
+ // This should fail to compile if absl::string_view is used with wide
850
+ // strings.
851
+ const StringType& str = std::string(s);
852
+ return MatchAndExplain(str, listener);
853
+ }
854
+ #endif // GTEST_HAS_ABSL
855
+
856
+ // Accepts pointer types, particularly:
857
+ // const char*
858
+ // char*
859
+ // const wchar_t*
860
+ // wchar_t*
861
+ template <typename CharType>
862
+ bool MatchAndExplain(CharType* s, MatchResultListener* listener) const {
863
+ return s != nullptr && MatchAndExplain(StringType(s), listener);
864
+ }
865
+
866
+ // Matches anything that can convert to StringType.
867
+ //
868
+ // This is a template, not just a plain function with const StringType&,
869
+ // because absl::string_view has some interfering non-explicit constructors.
870
+ template <typename MatcheeStringType>
871
+ bool MatchAndExplain(const MatcheeStringType& s,
872
+ MatchResultListener* /* listener */) const {
873
+ const StringType& s2(s);
874
+ return s2.length() >= suffix_.length() &&
875
+ s2.substr(s2.length() - suffix_.length()) == suffix_;
876
+ }
877
+
878
+ void DescribeTo(::std::ostream* os) const {
879
+ *os << "ends with ";
880
+ UniversalPrint(suffix_, os);
881
+ }
882
+
883
+ void DescribeNegationTo(::std::ostream* os) const {
884
+ *os << "doesn't end with ";
885
+ UniversalPrint(suffix_, os);
886
+ }
887
+
888
+ private:
889
+ const StringType suffix_;
890
+
891
+ GTEST_DISALLOW_ASSIGN_(EndsWithMatcher);
892
+ };
893
+
894
+ // Implements a matcher that compares the two fields of a 2-tuple
895
+ // using one of the ==, <=, <, etc, operators. The two fields being
896
+ // compared don't have to have the same type.
897
+ //
898
+ // The matcher defined here is polymorphic (for example, Eq() can be
899
+ // used to match a std::tuple<int, short>, a std::tuple<const long&, double>,
900
+ // etc). Therefore we use a template type conversion operator in the
901
+ // implementation.
902
+ template <typename D, typename Op>
903
+ class PairMatchBase {
904
+ public:
905
+ template <typename T1, typename T2>
906
+ operator Matcher<::std::tuple<T1, T2>>() const {
907
+ return Matcher<::std::tuple<T1, T2>>(new Impl<const ::std::tuple<T1, T2>&>);
908
+ }
909
+ template <typename T1, typename T2>
910
+ operator Matcher<const ::std::tuple<T1, T2>&>() const {
911
+ return MakeMatcher(new Impl<const ::std::tuple<T1, T2>&>);
912
+ }
913
+
914
+ private:
915
+ static ::std::ostream& GetDesc(::std::ostream& os) { // NOLINT
916
+ return os << D::Desc();
917
+ }
918
+
919
+ template <typename Tuple>
920
+ class Impl : public MatcherInterface<Tuple> {
921
+ public:
922
+ bool MatchAndExplain(Tuple args,
923
+ MatchResultListener* /* listener */) const override {
924
+ return Op()(::std::get<0>(args), ::std::get<1>(args));
925
+ }
926
+ void DescribeTo(::std::ostream* os) const override {
927
+ *os << "are " << GetDesc;
928
+ }
929
+ void DescribeNegationTo(::std::ostream* os) const override {
930
+ *os << "aren't " << GetDesc;
931
+ }
932
+ };
933
+ };
934
+
935
+ class Eq2Matcher : public PairMatchBase<Eq2Matcher, AnyEq> {
936
+ public:
937
+ static const char* Desc() { return "an equal pair"; }
938
+ };
939
+ class Ne2Matcher : public PairMatchBase<Ne2Matcher, AnyNe> {
940
+ public:
941
+ static const char* Desc() { return "an unequal pair"; }
942
+ };
943
+ class Lt2Matcher : public PairMatchBase<Lt2Matcher, AnyLt> {
944
+ public:
945
+ static const char* Desc() { return "a pair where the first < the second"; }
946
+ };
947
+ class Gt2Matcher : public PairMatchBase<Gt2Matcher, AnyGt> {
948
+ public:
949
+ static const char* Desc() { return "a pair where the first > the second"; }
950
+ };
951
+ class Le2Matcher : public PairMatchBase<Le2Matcher, AnyLe> {
952
+ public:
953
+ static const char* Desc() { return "a pair where the first <= the second"; }
954
+ };
955
+ class Ge2Matcher : public PairMatchBase<Ge2Matcher, AnyGe> {
956
+ public:
957
+ static const char* Desc() { return "a pair where the first >= the second"; }
958
+ };
959
+
960
+ // Implements the Not(...) matcher for a particular argument type T.
961
+ // We do not nest it inside the NotMatcher class template, as that
962
+ // will prevent different instantiations of NotMatcher from sharing
963
+ // the same NotMatcherImpl<T> class.
964
+ template <typename T>
965
+ class NotMatcherImpl : public MatcherInterface<const T&> {
966
+ public:
967
+ explicit NotMatcherImpl(const Matcher<T>& matcher)
968
+ : matcher_(matcher) {}
969
+
970
+ bool MatchAndExplain(const T& x,
971
+ MatchResultListener* listener) const override {
972
+ return !matcher_.MatchAndExplain(x, listener);
973
+ }
974
+
975
+ void DescribeTo(::std::ostream* os) const override {
976
+ matcher_.DescribeNegationTo(os);
977
+ }
978
+
979
+ void DescribeNegationTo(::std::ostream* os) const override {
980
+ matcher_.DescribeTo(os);
981
+ }
982
+
983
+ private:
984
+ const Matcher<T> matcher_;
985
+
986
+ GTEST_DISALLOW_ASSIGN_(NotMatcherImpl);
987
+ };
988
+
989
+ // Implements the Not(m) matcher, which matches a value that doesn't
990
+ // match matcher m.
991
+ template <typename InnerMatcher>
992
+ class NotMatcher {
993
+ public:
994
+ explicit NotMatcher(InnerMatcher matcher) : matcher_(matcher) {}
995
+
996
+ // This template type conversion operator allows Not(m) to be used
997
+ // to match any type m can match.
998
+ template <typename T>
999
+ operator Matcher<T>() const {
1000
+ return Matcher<T>(new NotMatcherImpl<T>(SafeMatcherCast<T>(matcher_)));
1001
+ }
1002
+
1003
+ private:
1004
+ InnerMatcher matcher_;
1005
+
1006
+ GTEST_DISALLOW_ASSIGN_(NotMatcher);
1007
+ };
1008
+
1009
+ // Implements the AllOf(m1, m2) matcher for a particular argument type
1010
+ // T. We do not nest it inside the BothOfMatcher class template, as
1011
+ // that will prevent different instantiations of BothOfMatcher from
1012
+ // sharing the same BothOfMatcherImpl<T> class.
1013
+ template <typename T>
1014
+ class AllOfMatcherImpl : public MatcherInterface<const T&> {
1015
+ public:
1016
+ explicit AllOfMatcherImpl(std::vector<Matcher<T> > matchers)
1017
+ : matchers_(std::move(matchers)) {}
1018
+
1019
+ void DescribeTo(::std::ostream* os) const override {
1020
+ *os << "(";
1021
+ for (size_t i = 0; i < matchers_.size(); ++i) {
1022
+ if (i != 0) *os << ") and (";
1023
+ matchers_[i].DescribeTo(os);
1024
+ }
1025
+ *os << ")";
1026
+ }
1027
+
1028
+ void DescribeNegationTo(::std::ostream* os) const override {
1029
+ *os << "(";
1030
+ for (size_t i = 0; i < matchers_.size(); ++i) {
1031
+ if (i != 0) *os << ") or (";
1032
+ matchers_[i].DescribeNegationTo(os);
1033
+ }
1034
+ *os << ")";
1035
+ }
1036
+
1037
+ bool MatchAndExplain(const T& x,
1038
+ MatchResultListener* listener) const override {
1039
+ // If either matcher1_ or matcher2_ doesn't match x, we only need
1040
+ // to explain why one of them fails.
1041
+ std::string all_match_result;
1042
+
1043
+ for (size_t i = 0; i < matchers_.size(); ++i) {
1044
+ StringMatchResultListener slistener;
1045
+ if (matchers_[i].MatchAndExplain(x, &slistener)) {
1046
+ if (all_match_result.empty()) {
1047
+ all_match_result = slistener.str();
1048
+ } else {
1049
+ std::string result = slistener.str();
1050
+ if (!result.empty()) {
1051
+ all_match_result += ", and ";
1052
+ all_match_result += result;
1053
+ }
1054
+ }
1055
+ } else {
1056
+ *listener << slistener.str();
1057
+ return false;
1058
+ }
1059
+ }
1060
+
1061
+ // Otherwise we need to explain why *both* of them match.
1062
+ *listener << all_match_result;
1063
+ return true;
1064
+ }
1065
+
1066
+ private:
1067
+ const std::vector<Matcher<T> > matchers_;
1068
+
1069
+ GTEST_DISALLOW_ASSIGN_(AllOfMatcherImpl);
1070
+ };
1071
+
1072
+ // VariadicMatcher is used for the variadic implementation of
1073
+ // AllOf(m_1, m_2, ...) and AnyOf(m_1, m_2, ...).
1074
+ // CombiningMatcher<T> is used to recursively combine the provided matchers
1075
+ // (of type Args...).
1076
+ template <template <typename T> class CombiningMatcher, typename... Args>
1077
+ class VariadicMatcher {
1078
+ public:
1079
+ VariadicMatcher(const Args&... matchers) // NOLINT
1080
+ : matchers_(matchers...) {
1081
+ static_assert(sizeof...(Args) > 0, "Must have at least one matcher.");
1082
+ }
1083
+
1084
+ // This template type conversion operator allows an
1085
+ // VariadicMatcher<Matcher1, Matcher2...> object to match any type that
1086
+ // all of the provided matchers (Matcher1, Matcher2, ...) can match.
1087
+ template <typename T>
1088
+ operator Matcher<T>() const {
1089
+ std::vector<Matcher<T> > values;
1090
+ CreateVariadicMatcher<T>(&values, std::integral_constant<size_t, 0>());
1091
+ return Matcher<T>(new CombiningMatcher<T>(std::move(values)));
1092
+ }
1093
+
1094
+ private:
1095
+ template <typename T, size_t I>
1096
+ void CreateVariadicMatcher(std::vector<Matcher<T> >* values,
1097
+ std::integral_constant<size_t, I>) const {
1098
+ values->push_back(SafeMatcherCast<T>(std::get<I>(matchers_)));
1099
+ CreateVariadicMatcher<T>(values, std::integral_constant<size_t, I + 1>());
1100
+ }
1101
+
1102
+ template <typename T>
1103
+ void CreateVariadicMatcher(
1104
+ std::vector<Matcher<T> >*,
1105
+ std::integral_constant<size_t, sizeof...(Args)>) const {}
1106
+
1107
+ std::tuple<Args...> matchers_;
1108
+
1109
+ GTEST_DISALLOW_ASSIGN_(VariadicMatcher);
1110
+ };
1111
+
1112
+ template <typename... Args>
1113
+ using AllOfMatcher = VariadicMatcher<AllOfMatcherImpl, Args...>;
1114
+
1115
+ // Implements the AnyOf(m1, m2) matcher for a particular argument type
1116
+ // T. We do not nest it inside the AnyOfMatcher class template, as
1117
+ // that will prevent different instantiations of AnyOfMatcher from
1118
+ // sharing the same EitherOfMatcherImpl<T> class.
1119
+ template <typename T>
1120
+ class AnyOfMatcherImpl : public MatcherInterface<const T&> {
1121
+ public:
1122
+ explicit AnyOfMatcherImpl(std::vector<Matcher<T> > matchers)
1123
+ : matchers_(std::move(matchers)) {}
1124
+
1125
+ void DescribeTo(::std::ostream* os) const override {
1126
+ *os << "(";
1127
+ for (size_t i = 0; i < matchers_.size(); ++i) {
1128
+ if (i != 0) *os << ") or (";
1129
+ matchers_[i].DescribeTo(os);
1130
+ }
1131
+ *os << ")";
1132
+ }
1133
+
1134
+ void DescribeNegationTo(::std::ostream* os) const override {
1135
+ *os << "(";
1136
+ for (size_t i = 0; i < matchers_.size(); ++i) {
1137
+ if (i != 0) *os << ") and (";
1138
+ matchers_[i].DescribeNegationTo(os);
1139
+ }
1140
+ *os << ")";
1141
+ }
1142
+
1143
+ bool MatchAndExplain(const T& x,
1144
+ MatchResultListener* listener) const override {
1145
+ std::string no_match_result;
1146
+
1147
+ // If either matcher1_ or matcher2_ matches x, we just need to
1148
+ // explain why *one* of them matches.
1149
+ for (size_t i = 0; i < matchers_.size(); ++i) {
1150
+ StringMatchResultListener slistener;
1151
+ if (matchers_[i].MatchAndExplain(x, &slistener)) {
1152
+ *listener << slistener.str();
1153
+ return true;
1154
+ } else {
1155
+ if (no_match_result.empty()) {
1156
+ no_match_result = slistener.str();
1157
+ } else {
1158
+ std::string result = slistener.str();
1159
+ if (!result.empty()) {
1160
+ no_match_result += ", and ";
1161
+ no_match_result += result;
1162
+ }
1163
+ }
1164
+ }
1165
+ }
1166
+
1167
+ // Otherwise we need to explain why *both* of them fail.
1168
+ *listener << no_match_result;
1169
+ return false;
1170
+ }
1171
+
1172
+ private:
1173
+ const std::vector<Matcher<T> > matchers_;
1174
+
1175
+ GTEST_DISALLOW_ASSIGN_(AnyOfMatcherImpl);
1176
+ };
1177
+
1178
+ // AnyOfMatcher is used for the variadic implementation of AnyOf(m_1, m_2, ...).
1179
+ template <typename... Args>
1180
+ using AnyOfMatcher = VariadicMatcher<AnyOfMatcherImpl, Args...>;
1181
+
1182
+ // Wrapper for implementation of Any/AllOfArray().
1183
+ template <template <class> class MatcherImpl, typename T>
1184
+ class SomeOfArrayMatcher {
1185
+ public:
1186
+ // Constructs the matcher from a sequence of element values or
1187
+ // element matchers.
1188
+ template <typename Iter>
1189
+ SomeOfArrayMatcher(Iter first, Iter last) : matchers_(first, last) {}
1190
+
1191
+ template <typename U>
1192
+ operator Matcher<U>() const { // NOLINT
1193
+ using RawU = typename std::decay<U>::type;
1194
+ std::vector<Matcher<RawU>> matchers;
1195
+ for (const auto& matcher : matchers_) {
1196
+ matchers.push_back(MatcherCast<RawU>(matcher));
1197
+ }
1198
+ return Matcher<U>(new MatcherImpl<RawU>(std::move(matchers)));
1199
+ }
1200
+
1201
+ private:
1202
+ const ::std::vector<T> matchers_;
1203
+
1204
+ GTEST_DISALLOW_ASSIGN_(SomeOfArrayMatcher);
1205
+ };
1206
+
1207
+ template <typename T>
1208
+ using AllOfArrayMatcher = SomeOfArrayMatcher<AllOfMatcherImpl, T>;
1209
+
1210
+ template <typename T>
1211
+ using AnyOfArrayMatcher = SomeOfArrayMatcher<AnyOfMatcherImpl, T>;
1212
+
1213
+ // Used for implementing Truly(pred), which turns a predicate into a
1214
+ // matcher.
1215
+ template <typename Predicate>
1216
+ class TrulyMatcher {
1217
+ public:
1218
+ explicit TrulyMatcher(Predicate pred) : predicate_(pred) {}
1219
+
1220
+ // This method template allows Truly(pred) to be used as a matcher
1221
+ // for type T where T is the argument type of predicate 'pred'. The
1222
+ // argument is passed by reference as the predicate may be
1223
+ // interested in the address of the argument.
1224
+ template <typename T>
1225
+ bool MatchAndExplain(T& x, // NOLINT
1226
+ MatchResultListener* /* listener */) const {
1227
+ // Without the if-statement, MSVC sometimes warns about converting
1228
+ // a value to bool (warning 4800).
1229
+ //
1230
+ // We cannot write 'return !!predicate_(x);' as that doesn't work
1231
+ // when predicate_(x) returns a class convertible to bool but
1232
+ // having no operator!().
1233
+ if (predicate_(x))
1234
+ return true;
1235
+ return false;
1236
+ }
1237
+
1238
+ void DescribeTo(::std::ostream* os) const {
1239
+ *os << "satisfies the given predicate";
1240
+ }
1241
+
1242
+ void DescribeNegationTo(::std::ostream* os) const {
1243
+ *os << "doesn't satisfy the given predicate";
1244
+ }
1245
+
1246
+ private:
1247
+ Predicate predicate_;
1248
+
1249
+ GTEST_DISALLOW_ASSIGN_(TrulyMatcher);
1250
+ };
1251
+
1252
+ // Used for implementing Matches(matcher), which turns a matcher into
1253
+ // a predicate.
1254
+ template <typename M>
1255
+ class MatcherAsPredicate {
1256
+ public:
1257
+ explicit MatcherAsPredicate(M matcher) : matcher_(matcher) {}
1258
+
1259
+ // This template operator() allows Matches(m) to be used as a
1260
+ // predicate on type T where m is a matcher on type T.
1261
+ //
1262
+ // The argument x is passed by reference instead of by value, as
1263
+ // some matcher may be interested in its address (e.g. as in
1264
+ // Matches(Ref(n))(x)).
1265
+ template <typename T>
1266
+ bool operator()(const T& x) const {
1267
+ // We let matcher_ commit to a particular type here instead of
1268
+ // when the MatcherAsPredicate object was constructed. This
1269
+ // allows us to write Matches(m) where m is a polymorphic matcher
1270
+ // (e.g. Eq(5)).
1271
+ //
1272
+ // If we write Matcher<T>(matcher_).Matches(x) here, it won't
1273
+ // compile when matcher_ has type Matcher<const T&>; if we write
1274
+ // Matcher<const T&>(matcher_).Matches(x) here, it won't compile
1275
+ // when matcher_ has type Matcher<T>; if we just write
1276
+ // matcher_.Matches(x), it won't compile when matcher_ is
1277
+ // polymorphic, e.g. Eq(5).
1278
+ //
1279
+ // MatcherCast<const T&>() is necessary for making the code work
1280
+ // in all of the above situations.
1281
+ return MatcherCast<const T&>(matcher_).Matches(x);
1282
+ }
1283
+
1284
+ private:
1285
+ M matcher_;
1286
+
1287
+ GTEST_DISALLOW_ASSIGN_(MatcherAsPredicate);
1288
+ };
1289
+
1290
+ // For implementing ASSERT_THAT() and EXPECT_THAT(). The template
1291
+ // argument M must be a type that can be converted to a matcher.
1292
+ template <typename M>
1293
+ class PredicateFormatterFromMatcher {
1294
+ public:
1295
+ explicit PredicateFormatterFromMatcher(M m) : matcher_(std::move(m)) {}
1296
+
1297
+ // This template () operator allows a PredicateFormatterFromMatcher
1298
+ // object to act as a predicate-formatter suitable for using with
1299
+ // Google Test's EXPECT_PRED_FORMAT1() macro.
1300
+ template <typename T>
1301
+ AssertionResult operator()(const char* value_text, const T& x) const {
1302
+ // We convert matcher_ to a Matcher<const T&> *now* instead of
1303
+ // when the PredicateFormatterFromMatcher object was constructed,
1304
+ // as matcher_ may be polymorphic (e.g. NotNull()) and we won't
1305
+ // know which type to instantiate it to until we actually see the
1306
+ // type of x here.
1307
+ //
1308
+ // We write SafeMatcherCast<const T&>(matcher_) instead of
1309
+ // Matcher<const T&>(matcher_), as the latter won't compile when
1310
+ // matcher_ has type Matcher<T> (e.g. An<int>()).
1311
+ // We don't write MatcherCast<const T&> either, as that allows
1312
+ // potentially unsafe downcasting of the matcher argument.
1313
+ const Matcher<const T&> matcher = SafeMatcherCast<const T&>(matcher_);
1314
+
1315
+ // The expected path here is that the matcher should match (i.e. that most
1316
+ // tests pass) so optimize for this case.
1317
+ if (matcher.Matches(x)) {
1318
+ return AssertionSuccess();
1319
+ }
1320
+
1321
+ ::std::stringstream ss;
1322
+ ss << "Value of: " << value_text << "\n"
1323
+ << "Expected: ";
1324
+ matcher.DescribeTo(&ss);
1325
+
1326
+ // Rerun the matcher to "PrintAndExplain" the failure.
1327
+ StringMatchResultListener listener;
1328
+ if (MatchPrintAndExplain(x, matcher, &listener)) {
1329
+ ss << "\n The matcher failed on the initial attempt; but passed when "
1330
+ "rerun to generate the explanation.";
1331
+ }
1332
+ ss << "\n Actual: " << listener.str();
1333
+ return AssertionFailure() << ss.str();
1334
+ }
1335
+
1336
+ private:
1337
+ const M matcher_;
1338
+
1339
+ GTEST_DISALLOW_ASSIGN_(PredicateFormatterFromMatcher);
1340
+ };
1341
+
1342
+ // A helper function for converting a matcher to a predicate-formatter
1343
+ // without the user needing to explicitly write the type. This is
1344
+ // used for implementing ASSERT_THAT() and EXPECT_THAT().
1345
+ // Implementation detail: 'matcher' is received by-value to force decaying.
1346
+ template <typename M>
1347
+ inline PredicateFormatterFromMatcher<M>
1348
+ MakePredicateFormatterFromMatcher(M matcher) {
1349
+ return PredicateFormatterFromMatcher<M>(std::move(matcher));
1350
+ }
1351
+
1352
+ // Implements the polymorphic IsNan() matcher, which matches any floating type
1353
+ // value that is Nan.
1354
+ class IsNanMatcher {
1355
+ public:
1356
+ template <typename FloatType>
1357
+ bool MatchAndExplain(const FloatType& f,
1358
+ MatchResultListener* /* listener */) const {
1359
+ return (::std::isnan)(f);
1360
+ }
1361
+
1362
+ void DescribeTo(::std::ostream* os) const { *os << "is NaN"; }
1363
+ void DescribeNegationTo(::std::ostream* os) const {
1364
+ *os << "isn't NaN";
1365
+ }
1366
+ };
1367
+
1368
+ // Implements the polymorphic floating point equality matcher, which matches
1369
+ // two float values using ULP-based approximation or, optionally, a
1370
+ // user-specified epsilon. The template is meant to be instantiated with
1371
+ // FloatType being either float or double.
1372
+ template <typename FloatType>
1373
+ class FloatingEqMatcher {
1374
+ public:
1375
+ // Constructor for FloatingEqMatcher.
1376
+ // The matcher's input will be compared with expected. The matcher treats two
1377
+ // NANs as equal if nan_eq_nan is true. Otherwise, under IEEE standards,
1378
+ // equality comparisons between NANs will always return false. We specify a
1379
+ // negative max_abs_error_ term to indicate that ULP-based approximation will
1380
+ // be used for comparison.
1381
+ FloatingEqMatcher(FloatType expected, bool nan_eq_nan) :
1382
+ expected_(expected), nan_eq_nan_(nan_eq_nan), max_abs_error_(-1) {
1383
+ }
1384
+
1385
+ // Constructor that supports a user-specified max_abs_error that will be used
1386
+ // for comparison instead of ULP-based approximation. The max absolute
1387
+ // should be non-negative.
1388
+ FloatingEqMatcher(FloatType expected, bool nan_eq_nan,
1389
+ FloatType max_abs_error)
1390
+ : expected_(expected),
1391
+ nan_eq_nan_(nan_eq_nan),
1392
+ max_abs_error_(max_abs_error) {
1393
+ GTEST_CHECK_(max_abs_error >= 0)
1394
+ << ", where max_abs_error is" << max_abs_error;
1395
+ }
1396
+
1397
+ // Implements floating point equality matcher as a Matcher<T>.
1398
+ template <typename T>
1399
+ class Impl : public MatcherInterface<T> {
1400
+ public:
1401
+ Impl(FloatType expected, bool nan_eq_nan, FloatType max_abs_error)
1402
+ : expected_(expected),
1403
+ nan_eq_nan_(nan_eq_nan),
1404
+ max_abs_error_(max_abs_error) {}
1405
+
1406
+ bool MatchAndExplain(T value,
1407
+ MatchResultListener* listener) const override {
1408
+ const FloatingPoint<FloatType> actual(value), expected(expected_);
1409
+
1410
+ // Compares NaNs first, if nan_eq_nan_ is true.
1411
+ if (actual.is_nan() || expected.is_nan()) {
1412
+ if (actual.is_nan() && expected.is_nan()) {
1413
+ return nan_eq_nan_;
1414
+ }
1415
+ // One is nan; the other is not nan.
1416
+ return false;
1417
+ }
1418
+ if (HasMaxAbsError()) {
1419
+ // We perform an equality check so that inf will match inf, regardless
1420
+ // of error bounds. If the result of value - expected_ would result in
1421
+ // overflow or if either value is inf, the default result is infinity,
1422
+ // which should only match if max_abs_error_ is also infinity.
1423
+ if (value == expected_) {
1424
+ return true;
1425
+ }
1426
+
1427
+ const FloatType diff = value - expected_;
1428
+ if (::std::fabs(diff) <= max_abs_error_) {
1429
+ return true;
1430
+ }
1431
+
1432
+ if (listener->IsInterested()) {
1433
+ *listener << "which is " << diff << " from " << expected_;
1434
+ }
1435
+ return false;
1436
+ } else {
1437
+ return actual.AlmostEquals(expected);
1438
+ }
1439
+ }
1440
+
1441
+ void DescribeTo(::std::ostream* os) const override {
1442
+ // os->precision() returns the previously set precision, which we
1443
+ // store to restore the ostream to its original configuration
1444
+ // after outputting.
1445
+ const ::std::streamsize old_precision = os->precision(
1446
+ ::std::numeric_limits<FloatType>::digits10 + 2);
1447
+ if (FloatingPoint<FloatType>(expected_).is_nan()) {
1448
+ if (nan_eq_nan_) {
1449
+ *os << "is NaN";
1450
+ } else {
1451
+ *os << "never matches";
1452
+ }
1453
+ } else {
1454
+ *os << "is approximately " << expected_;
1455
+ if (HasMaxAbsError()) {
1456
+ *os << " (absolute error <= " << max_abs_error_ << ")";
1457
+ }
1458
+ }
1459
+ os->precision(old_precision);
1460
+ }
1461
+
1462
+ void DescribeNegationTo(::std::ostream* os) const override {
1463
+ // As before, get original precision.
1464
+ const ::std::streamsize old_precision = os->precision(
1465
+ ::std::numeric_limits<FloatType>::digits10 + 2);
1466
+ if (FloatingPoint<FloatType>(expected_).is_nan()) {
1467
+ if (nan_eq_nan_) {
1468
+ *os << "isn't NaN";
1469
+ } else {
1470
+ *os << "is anything";
1471
+ }
1472
+ } else {
1473
+ *os << "isn't approximately " << expected_;
1474
+ if (HasMaxAbsError()) {
1475
+ *os << " (absolute error > " << max_abs_error_ << ")";
1476
+ }
1477
+ }
1478
+ // Restore original precision.
1479
+ os->precision(old_precision);
1480
+ }
1481
+
1482
+ private:
1483
+ bool HasMaxAbsError() const {
1484
+ return max_abs_error_ >= 0;
1485
+ }
1486
+
1487
+ const FloatType expected_;
1488
+ const bool nan_eq_nan_;
1489
+ // max_abs_error will be used for value comparison when >= 0.
1490
+ const FloatType max_abs_error_;
1491
+
1492
+ GTEST_DISALLOW_ASSIGN_(Impl);
1493
+ };
1494
+
1495
+ // The following 3 type conversion operators allow FloatEq(expected) and
1496
+ // NanSensitiveFloatEq(expected) to be used as a Matcher<float>, a
1497
+ // Matcher<const float&>, or a Matcher<float&>, but nothing else.
1498
+ // (While Google's C++ coding style doesn't allow arguments passed
1499
+ // by non-const reference, we may see them in code not conforming to
1500
+ // the style. Therefore Google Mock needs to support them.)
1501
+ operator Matcher<FloatType>() const {
1502
+ return MakeMatcher(
1503
+ new Impl<FloatType>(expected_, nan_eq_nan_, max_abs_error_));
1504
+ }
1505
+
1506
+ operator Matcher<const FloatType&>() const {
1507
+ return MakeMatcher(
1508
+ new Impl<const FloatType&>(expected_, nan_eq_nan_, max_abs_error_));
1509
+ }
1510
+
1511
+ operator Matcher<FloatType&>() const {
1512
+ return MakeMatcher(
1513
+ new Impl<FloatType&>(expected_, nan_eq_nan_, max_abs_error_));
1514
+ }
1515
+
1516
+ private:
1517
+ const FloatType expected_;
1518
+ const bool nan_eq_nan_;
1519
+ // max_abs_error will be used for value comparison when >= 0.
1520
+ const FloatType max_abs_error_;
1521
+
1522
+ GTEST_DISALLOW_ASSIGN_(FloatingEqMatcher);
1523
+ };
1524
+
1525
+ // A 2-tuple ("binary") wrapper around FloatingEqMatcher:
1526
+ // FloatingEq2Matcher() matches (x, y) by matching FloatingEqMatcher(x, false)
1527
+ // against y, and FloatingEq2Matcher(e) matches FloatingEqMatcher(x, false, e)
1528
+ // against y. The former implements "Eq", the latter "Near". At present, there
1529
+ // is no version that compares NaNs as equal.
1530
+ template <typename FloatType>
1531
+ class FloatingEq2Matcher {
1532
+ public:
1533
+ FloatingEq2Matcher() { Init(-1, false); }
1534
+
1535
+ explicit FloatingEq2Matcher(bool nan_eq_nan) { Init(-1, nan_eq_nan); }
1536
+
1537
+ explicit FloatingEq2Matcher(FloatType max_abs_error) {
1538
+ Init(max_abs_error, false);
1539
+ }
1540
+
1541
+ FloatingEq2Matcher(FloatType max_abs_error, bool nan_eq_nan) {
1542
+ Init(max_abs_error, nan_eq_nan);
1543
+ }
1544
+
1545
+ template <typename T1, typename T2>
1546
+ operator Matcher<::std::tuple<T1, T2>>() const {
1547
+ return MakeMatcher(
1548
+ new Impl<::std::tuple<T1, T2>>(max_abs_error_, nan_eq_nan_));
1549
+ }
1550
+ template <typename T1, typename T2>
1551
+ operator Matcher<const ::std::tuple<T1, T2>&>() const {
1552
+ return MakeMatcher(
1553
+ new Impl<const ::std::tuple<T1, T2>&>(max_abs_error_, nan_eq_nan_));
1554
+ }
1555
+
1556
+ private:
1557
+ static ::std::ostream& GetDesc(::std::ostream& os) { // NOLINT
1558
+ return os << "an almost-equal pair";
1559
+ }
1560
+
1561
+ template <typename Tuple>
1562
+ class Impl : public MatcherInterface<Tuple> {
1563
+ public:
1564
+ Impl(FloatType max_abs_error, bool nan_eq_nan) :
1565
+ max_abs_error_(max_abs_error),
1566
+ nan_eq_nan_(nan_eq_nan) {}
1567
+
1568
+ bool MatchAndExplain(Tuple args,
1569
+ MatchResultListener* listener) const override {
1570
+ if (max_abs_error_ == -1) {
1571
+ FloatingEqMatcher<FloatType> fm(::std::get<0>(args), nan_eq_nan_);
1572
+ return static_cast<Matcher<FloatType>>(fm).MatchAndExplain(
1573
+ ::std::get<1>(args), listener);
1574
+ } else {
1575
+ FloatingEqMatcher<FloatType> fm(::std::get<0>(args), nan_eq_nan_,
1576
+ max_abs_error_);
1577
+ return static_cast<Matcher<FloatType>>(fm).MatchAndExplain(
1578
+ ::std::get<1>(args), listener);
1579
+ }
1580
+ }
1581
+ void DescribeTo(::std::ostream* os) const override {
1582
+ *os << "are " << GetDesc;
1583
+ }
1584
+ void DescribeNegationTo(::std::ostream* os) const override {
1585
+ *os << "aren't " << GetDesc;
1586
+ }
1587
+
1588
+ private:
1589
+ FloatType max_abs_error_;
1590
+ const bool nan_eq_nan_;
1591
+ };
1592
+
1593
+ void Init(FloatType max_abs_error_val, bool nan_eq_nan_val) {
1594
+ max_abs_error_ = max_abs_error_val;
1595
+ nan_eq_nan_ = nan_eq_nan_val;
1596
+ }
1597
+ FloatType max_abs_error_;
1598
+ bool nan_eq_nan_;
1599
+ };
1600
+
1601
+ // Implements the Pointee(m) matcher for matching a pointer whose
1602
+ // pointee matches matcher m. The pointer can be either raw or smart.
1603
+ template <typename InnerMatcher>
1604
+ class PointeeMatcher {
1605
+ public:
1606
+ explicit PointeeMatcher(const InnerMatcher& matcher) : matcher_(matcher) {}
1607
+
1608
+ // This type conversion operator template allows Pointee(m) to be
1609
+ // used as a matcher for any pointer type whose pointee type is
1610
+ // compatible with the inner matcher, where type Pointer can be
1611
+ // either a raw pointer or a smart pointer.
1612
+ //
1613
+ // The reason we do this instead of relying on
1614
+ // MakePolymorphicMatcher() is that the latter is not flexible
1615
+ // enough for implementing the DescribeTo() method of Pointee().
1616
+ template <typename Pointer>
1617
+ operator Matcher<Pointer>() const {
1618
+ return Matcher<Pointer>(new Impl<const Pointer&>(matcher_));
1619
+ }
1620
+
1621
+ private:
1622
+ // The monomorphic implementation that works for a particular pointer type.
1623
+ template <typename Pointer>
1624
+ class Impl : public MatcherInterface<Pointer> {
1625
+ public:
1626
+ typedef typename PointeeOf<GTEST_REMOVE_REFERENCE_AND_CONST_(Pointer)>::type
1627
+ Pointee;
1628
+
1629
+ explicit Impl(const InnerMatcher& matcher)
1630
+ : matcher_(MatcherCast<const Pointee&>(matcher)) {}
1631
+
1632
+ void DescribeTo(::std::ostream* os) const override {
1633
+ *os << "points to a value that ";
1634
+ matcher_.DescribeTo(os);
1635
+ }
1636
+
1637
+ void DescribeNegationTo(::std::ostream* os) const override {
1638
+ *os << "does not point to a value that ";
1639
+ matcher_.DescribeTo(os);
1640
+ }
1641
+
1642
+ bool MatchAndExplain(Pointer pointer,
1643
+ MatchResultListener* listener) const override {
1644
+ if (GetRawPointer(pointer) == nullptr) return false;
1645
+
1646
+ *listener << "which points to ";
1647
+ return MatchPrintAndExplain(*pointer, matcher_, listener);
1648
+ }
1649
+
1650
+ private:
1651
+ const Matcher<const Pointee&> matcher_;
1652
+
1653
+ GTEST_DISALLOW_ASSIGN_(Impl);
1654
+ };
1655
+
1656
+ const InnerMatcher matcher_;
1657
+
1658
+ GTEST_DISALLOW_ASSIGN_(PointeeMatcher);
1659
+ };
1660
+
1661
+ #if GTEST_HAS_RTTI
1662
+ // Implements the WhenDynamicCastTo<T>(m) matcher that matches a pointer or
1663
+ // reference that matches inner_matcher when dynamic_cast<T> is applied.
1664
+ // The result of dynamic_cast<To> is forwarded to the inner matcher.
1665
+ // If To is a pointer and the cast fails, the inner matcher will receive NULL.
1666
+ // If To is a reference and the cast fails, this matcher returns false
1667
+ // immediately.
1668
+ template <typename To>
1669
+ class WhenDynamicCastToMatcherBase {
1670
+ public:
1671
+ explicit WhenDynamicCastToMatcherBase(const Matcher<To>& matcher)
1672
+ : matcher_(matcher) {}
1673
+
1674
+ void DescribeTo(::std::ostream* os) const {
1675
+ GetCastTypeDescription(os);
1676
+ matcher_.DescribeTo(os);
1677
+ }
1678
+
1679
+ void DescribeNegationTo(::std::ostream* os) const {
1680
+ GetCastTypeDescription(os);
1681
+ matcher_.DescribeNegationTo(os);
1682
+ }
1683
+
1684
+ protected:
1685
+ const Matcher<To> matcher_;
1686
+
1687
+ static std::string GetToName() {
1688
+ return GetTypeName<To>();
1689
+ }
1690
+
1691
+ private:
1692
+ static void GetCastTypeDescription(::std::ostream* os) {
1693
+ *os << "when dynamic_cast to " << GetToName() << ", ";
1694
+ }
1695
+
1696
+ GTEST_DISALLOW_ASSIGN_(WhenDynamicCastToMatcherBase);
1697
+ };
1698
+
1699
+ // Primary template.
1700
+ // To is a pointer. Cast and forward the result.
1701
+ template <typename To>
1702
+ class WhenDynamicCastToMatcher : public WhenDynamicCastToMatcherBase<To> {
1703
+ public:
1704
+ explicit WhenDynamicCastToMatcher(const Matcher<To>& matcher)
1705
+ : WhenDynamicCastToMatcherBase<To>(matcher) {}
1706
+
1707
+ template <typename From>
1708
+ bool MatchAndExplain(From from, MatchResultListener* listener) const {
1709
+ To to = dynamic_cast<To>(from);
1710
+ return MatchPrintAndExplain(to, this->matcher_, listener);
1711
+ }
1712
+ };
1713
+
1714
+ // Specialize for references.
1715
+ // In this case we return false if the dynamic_cast fails.
1716
+ template <typename To>
1717
+ class WhenDynamicCastToMatcher<To&> : public WhenDynamicCastToMatcherBase<To&> {
1718
+ public:
1719
+ explicit WhenDynamicCastToMatcher(const Matcher<To&>& matcher)
1720
+ : WhenDynamicCastToMatcherBase<To&>(matcher) {}
1721
+
1722
+ template <typename From>
1723
+ bool MatchAndExplain(From& from, MatchResultListener* listener) const {
1724
+ // We don't want an std::bad_cast here, so do the cast with pointers.
1725
+ To* to = dynamic_cast<To*>(&from);
1726
+ if (to == nullptr) {
1727
+ *listener << "which cannot be dynamic_cast to " << this->GetToName();
1728
+ return false;
1729
+ }
1730
+ return MatchPrintAndExplain(*to, this->matcher_, listener);
1731
+ }
1732
+ };
1733
+ #endif // GTEST_HAS_RTTI
1734
+
1735
+ // Implements the Field() matcher for matching a field (i.e. member
1736
+ // variable) of an object.
1737
+ template <typename Class, typename FieldType>
1738
+ class FieldMatcher {
1739
+ public:
1740
+ FieldMatcher(FieldType Class::*field,
1741
+ const Matcher<const FieldType&>& matcher)
1742
+ : field_(field), matcher_(matcher), whose_field_("whose given field ") {}
1743
+
1744
+ FieldMatcher(const std::string& field_name, FieldType Class::*field,
1745
+ const Matcher<const FieldType&>& matcher)
1746
+ : field_(field),
1747
+ matcher_(matcher),
1748
+ whose_field_("whose field `" + field_name + "` ") {}
1749
+
1750
+ void DescribeTo(::std::ostream* os) const {
1751
+ *os << "is an object " << whose_field_;
1752
+ matcher_.DescribeTo(os);
1753
+ }
1754
+
1755
+ void DescribeNegationTo(::std::ostream* os) const {
1756
+ *os << "is an object " << whose_field_;
1757
+ matcher_.DescribeNegationTo(os);
1758
+ }
1759
+
1760
+ template <typename T>
1761
+ bool MatchAndExplain(const T& value, MatchResultListener* listener) const {
1762
+ // FIXME: The dispatch on std::is_pointer was introduced as a workaround for
1763
+ // a compiler bug, and can now be removed.
1764
+ return MatchAndExplainImpl(
1765
+ typename std::is_pointer<typename std::remove_const<T>::type>::type(),
1766
+ value, listener);
1767
+ }
1768
+
1769
+ private:
1770
+ bool MatchAndExplainImpl(std::false_type /* is_not_pointer */,
1771
+ const Class& obj,
1772
+ MatchResultListener* listener) const {
1773
+ *listener << whose_field_ << "is ";
1774
+ return MatchPrintAndExplain(obj.*field_, matcher_, listener);
1775
+ }
1776
+
1777
+ bool MatchAndExplainImpl(std::true_type /* is_pointer */, const Class* p,
1778
+ MatchResultListener* listener) const {
1779
+ if (p == nullptr) return false;
1780
+
1781
+ *listener << "which points to an object ";
1782
+ // Since *p has a field, it must be a class/struct/union type and
1783
+ // thus cannot be a pointer. Therefore we pass false_type() as
1784
+ // the first argument.
1785
+ return MatchAndExplainImpl(std::false_type(), *p, listener);
1786
+ }
1787
+
1788
+ const FieldType Class::*field_;
1789
+ const Matcher<const FieldType&> matcher_;
1790
+
1791
+ // Contains either "whose given field " if the name of the field is unknown
1792
+ // or "whose field `name_of_field` " if the name is known.
1793
+ const std::string whose_field_;
1794
+
1795
+ GTEST_DISALLOW_ASSIGN_(FieldMatcher);
1796
+ };
1797
+
1798
+ // Implements the Property() matcher for matching a property
1799
+ // (i.e. return value of a getter method) of an object.
1800
+ //
1801
+ // Property is a const-qualified member function of Class returning
1802
+ // PropertyType.
1803
+ template <typename Class, typename PropertyType, typename Property>
1804
+ class PropertyMatcher {
1805
+ public:
1806
+ typedef const PropertyType& RefToConstProperty;
1807
+
1808
+ PropertyMatcher(Property property, const Matcher<RefToConstProperty>& matcher)
1809
+ : property_(property),
1810
+ matcher_(matcher),
1811
+ whose_property_("whose given property ") {}
1812
+
1813
+ PropertyMatcher(const std::string& property_name, Property property,
1814
+ const Matcher<RefToConstProperty>& matcher)
1815
+ : property_(property),
1816
+ matcher_(matcher),
1817
+ whose_property_("whose property `" + property_name + "` ") {}
1818
+
1819
+ void DescribeTo(::std::ostream* os) const {
1820
+ *os << "is an object " << whose_property_;
1821
+ matcher_.DescribeTo(os);
1822
+ }
1823
+
1824
+ void DescribeNegationTo(::std::ostream* os) const {
1825
+ *os << "is an object " << whose_property_;
1826
+ matcher_.DescribeNegationTo(os);
1827
+ }
1828
+
1829
+ template <typename T>
1830
+ bool MatchAndExplain(const T&value, MatchResultListener* listener) const {
1831
+ return MatchAndExplainImpl(
1832
+ typename std::is_pointer<typename std::remove_const<T>::type>::type(),
1833
+ value, listener);
1834
+ }
1835
+
1836
+ private:
1837
+ bool MatchAndExplainImpl(std::false_type /* is_not_pointer */,
1838
+ const Class& obj,
1839
+ MatchResultListener* listener) const {
1840
+ *listener << whose_property_ << "is ";
1841
+ // Cannot pass the return value (for example, int) to MatchPrintAndExplain,
1842
+ // which takes a non-const reference as argument.
1843
+ RefToConstProperty result = (obj.*property_)();
1844
+ return MatchPrintAndExplain(result, matcher_, listener);
1845
+ }
1846
+
1847
+ bool MatchAndExplainImpl(std::true_type /* is_pointer */, const Class* p,
1848
+ MatchResultListener* listener) const {
1849
+ if (p == nullptr) return false;
1850
+
1851
+ *listener << "which points to an object ";
1852
+ // Since *p has a property method, it must be a class/struct/union
1853
+ // type and thus cannot be a pointer. Therefore we pass
1854
+ // false_type() as the first argument.
1855
+ return MatchAndExplainImpl(std::false_type(), *p, listener);
1856
+ }
1857
+
1858
+ Property property_;
1859
+ const Matcher<RefToConstProperty> matcher_;
1860
+
1861
+ // Contains either "whose given property " if the name of the property is
1862
+ // unknown or "whose property `name_of_property` " if the name is known.
1863
+ const std::string whose_property_;
1864
+
1865
+ GTEST_DISALLOW_ASSIGN_(PropertyMatcher);
1866
+ };
1867
+
1868
+ // Type traits specifying various features of different functors for ResultOf.
1869
+ // The default template specifies features for functor objects.
1870
+ template <typename Functor>
1871
+ struct CallableTraits {
1872
+ typedef Functor StorageType;
1873
+
1874
+ static void CheckIsValid(Functor /* functor */) {}
1875
+
1876
+ template <typename T>
1877
+ static auto Invoke(Functor f, const T& arg) -> decltype(f(arg)) {
1878
+ return f(arg);
1879
+ }
1880
+ };
1881
+
1882
+ // Specialization for function pointers.
1883
+ template <typename ArgType, typename ResType>
1884
+ struct CallableTraits<ResType(*)(ArgType)> {
1885
+ typedef ResType ResultType;
1886
+ typedef ResType(*StorageType)(ArgType);
1887
+
1888
+ static void CheckIsValid(ResType(*f)(ArgType)) {
1889
+ GTEST_CHECK_(f != nullptr)
1890
+ << "NULL function pointer is passed into ResultOf().";
1891
+ }
1892
+ template <typename T>
1893
+ static ResType Invoke(ResType(*f)(ArgType), T arg) {
1894
+ return (*f)(arg);
1895
+ }
1896
+ };
1897
+
1898
+ // Implements the ResultOf() matcher for matching a return value of a
1899
+ // unary function of an object.
1900
+ template <typename Callable, typename InnerMatcher>
1901
+ class ResultOfMatcher {
1902
+ public:
1903
+ ResultOfMatcher(Callable callable, InnerMatcher matcher)
1904
+ : callable_(std::move(callable)), matcher_(std::move(matcher)) {
1905
+ CallableTraits<Callable>::CheckIsValid(callable_);
1906
+ }
1907
+
1908
+ template <typename T>
1909
+ operator Matcher<T>() const {
1910
+ return Matcher<T>(new Impl<const T&>(callable_, matcher_));
1911
+ }
1912
+
1913
+ private:
1914
+ typedef typename CallableTraits<Callable>::StorageType CallableStorageType;
1915
+
1916
+ template <typename T>
1917
+ class Impl : public MatcherInterface<T> {
1918
+ using ResultType = decltype(CallableTraits<Callable>::template Invoke<T>(
1919
+ std::declval<CallableStorageType>(), std::declval<T>()));
1920
+
1921
+ public:
1922
+ template <typename M>
1923
+ Impl(const CallableStorageType& callable, const M& matcher)
1924
+ : callable_(callable), matcher_(MatcherCast<ResultType>(matcher)) {}
1925
+
1926
+ void DescribeTo(::std::ostream* os) const override {
1927
+ *os << "is mapped by the given callable to a value that ";
1928
+ matcher_.DescribeTo(os);
1929
+ }
1930
+
1931
+ void DescribeNegationTo(::std::ostream* os) const override {
1932
+ *os << "is mapped by the given callable to a value that ";
1933
+ matcher_.DescribeNegationTo(os);
1934
+ }
1935
+
1936
+ bool MatchAndExplain(T obj, MatchResultListener* listener) const override {
1937
+ *listener << "which is mapped by the given callable to ";
1938
+ // Cannot pass the return value directly to MatchPrintAndExplain, which
1939
+ // takes a non-const reference as argument.
1940
+ // Also, specifying template argument explicitly is needed because T could
1941
+ // be a non-const reference (e.g. Matcher<Uncopyable&>).
1942
+ ResultType result =
1943
+ CallableTraits<Callable>::template Invoke<T>(callable_, obj);
1944
+ return MatchPrintAndExplain(result, matcher_, listener);
1945
+ }
1946
+
1947
+ private:
1948
+ // Functors often define operator() as non-const method even though
1949
+ // they are actually stateless. But we need to use them even when
1950
+ // 'this' is a const pointer. It's the user's responsibility not to
1951
+ // use stateful callables with ResultOf(), which doesn't guarantee
1952
+ // how many times the callable will be invoked.
1953
+ mutable CallableStorageType callable_;
1954
+ const Matcher<ResultType> matcher_;
1955
+
1956
+ GTEST_DISALLOW_ASSIGN_(Impl);
1957
+ }; // class Impl
1958
+
1959
+ const CallableStorageType callable_;
1960
+ const InnerMatcher matcher_;
1961
+
1962
+ GTEST_DISALLOW_ASSIGN_(ResultOfMatcher);
1963
+ };
1964
+
1965
+ // Implements a matcher that checks the size of an STL-style container.
1966
+ template <typename SizeMatcher>
1967
+ class SizeIsMatcher {
1968
+ public:
1969
+ explicit SizeIsMatcher(const SizeMatcher& size_matcher)
1970
+ : size_matcher_(size_matcher) {
1971
+ }
1972
+
1973
+ template <typename Container>
1974
+ operator Matcher<Container>() const {
1975
+ return Matcher<Container>(new Impl<const Container&>(size_matcher_));
1976
+ }
1977
+
1978
+ template <typename Container>
1979
+ class Impl : public MatcherInterface<Container> {
1980
+ public:
1981
+ using SizeType = decltype(std::declval<Container>().size());
1982
+ explicit Impl(const SizeMatcher& size_matcher)
1983
+ : size_matcher_(MatcherCast<SizeType>(size_matcher)) {}
1984
+
1985
+ void DescribeTo(::std::ostream* os) const override {
1986
+ *os << "size ";
1987
+ size_matcher_.DescribeTo(os);
1988
+ }
1989
+ void DescribeNegationTo(::std::ostream* os) const override {
1990
+ *os << "size ";
1991
+ size_matcher_.DescribeNegationTo(os);
1992
+ }
1993
+
1994
+ bool MatchAndExplain(Container container,
1995
+ MatchResultListener* listener) const override {
1996
+ SizeType size = container.size();
1997
+ StringMatchResultListener size_listener;
1998
+ const bool result = size_matcher_.MatchAndExplain(size, &size_listener);
1999
+ *listener
2000
+ << "whose size " << size << (result ? " matches" : " doesn't match");
2001
+ PrintIfNotEmpty(size_listener.str(), listener->stream());
2002
+ return result;
2003
+ }
2004
+
2005
+ private:
2006
+ const Matcher<SizeType> size_matcher_;
2007
+ GTEST_DISALLOW_ASSIGN_(Impl);
2008
+ };
2009
+
2010
+ private:
2011
+ const SizeMatcher size_matcher_;
2012
+ GTEST_DISALLOW_ASSIGN_(SizeIsMatcher);
2013
+ };
2014
+
2015
+ // Implements a matcher that checks the begin()..end() distance of an STL-style
2016
+ // container.
2017
+ template <typename DistanceMatcher>
2018
+ class BeginEndDistanceIsMatcher {
2019
+ public:
2020
+ explicit BeginEndDistanceIsMatcher(const DistanceMatcher& distance_matcher)
2021
+ : distance_matcher_(distance_matcher) {}
2022
+
2023
+ template <typename Container>
2024
+ operator Matcher<Container>() const {
2025
+ return Matcher<Container>(new Impl<const Container&>(distance_matcher_));
2026
+ }
2027
+
2028
+ template <typename Container>
2029
+ class Impl : public MatcherInterface<Container> {
2030
+ public:
2031
+ typedef internal::StlContainerView<
2032
+ GTEST_REMOVE_REFERENCE_AND_CONST_(Container)> ContainerView;
2033
+ typedef typename std::iterator_traits<
2034
+ typename ContainerView::type::const_iterator>::difference_type
2035
+ DistanceType;
2036
+ explicit Impl(const DistanceMatcher& distance_matcher)
2037
+ : distance_matcher_(MatcherCast<DistanceType>(distance_matcher)) {}
2038
+
2039
+ void DescribeTo(::std::ostream* os) const override {
2040
+ *os << "distance between begin() and end() ";
2041
+ distance_matcher_.DescribeTo(os);
2042
+ }
2043
+ void DescribeNegationTo(::std::ostream* os) const override {
2044
+ *os << "distance between begin() and end() ";
2045
+ distance_matcher_.DescribeNegationTo(os);
2046
+ }
2047
+
2048
+ bool MatchAndExplain(Container container,
2049
+ MatchResultListener* listener) const override {
2050
+ using std::begin;
2051
+ using std::end;
2052
+ DistanceType distance = std::distance(begin(container), end(container));
2053
+ StringMatchResultListener distance_listener;
2054
+ const bool result =
2055
+ distance_matcher_.MatchAndExplain(distance, &distance_listener);
2056
+ *listener << "whose distance between begin() and end() " << distance
2057
+ << (result ? " matches" : " doesn't match");
2058
+ PrintIfNotEmpty(distance_listener.str(), listener->stream());
2059
+ return result;
2060
+ }
2061
+
2062
+ private:
2063
+ const Matcher<DistanceType> distance_matcher_;
2064
+ GTEST_DISALLOW_ASSIGN_(Impl);
2065
+ };
2066
+
2067
+ private:
2068
+ const DistanceMatcher distance_matcher_;
2069
+ GTEST_DISALLOW_ASSIGN_(BeginEndDistanceIsMatcher);
2070
+ };
2071
+
2072
+ // Implements an equality matcher for any STL-style container whose elements
2073
+ // support ==. This matcher is like Eq(), but its failure explanations provide
2074
+ // more detailed information that is useful when the container is used as a set.
2075
+ // The failure message reports elements that are in one of the operands but not
2076
+ // the other. The failure messages do not report duplicate or out-of-order
2077
+ // elements in the containers (which don't properly matter to sets, but can
2078
+ // occur if the containers are vectors or lists, for example).
2079
+ //
2080
+ // Uses the container's const_iterator, value_type, operator ==,
2081
+ // begin(), and end().
2082
+ template <typename Container>
2083
+ class ContainerEqMatcher {
2084
+ public:
2085
+ typedef internal::StlContainerView<Container> View;
2086
+ typedef typename View::type StlContainer;
2087
+ typedef typename View::const_reference StlContainerReference;
2088
+
2089
+ static_assert(!std::is_const<Container>::value,
2090
+ "Container type must not be const");
2091
+ static_assert(!std::is_reference<Container>::value,
2092
+ "Container type must not be a reference");
2093
+
2094
+ // We make a copy of expected in case the elements in it are modified
2095
+ // after this matcher is created.
2096
+ explicit ContainerEqMatcher(const Container& expected)
2097
+ : expected_(View::Copy(expected)) {}
2098
+
2099
+ void DescribeTo(::std::ostream* os) const {
2100
+ *os << "equals ";
2101
+ UniversalPrint(expected_, os);
2102
+ }
2103
+ void DescribeNegationTo(::std::ostream* os) const {
2104
+ *os << "does not equal ";
2105
+ UniversalPrint(expected_, os);
2106
+ }
2107
+
2108
+ template <typename LhsContainer>
2109
+ bool MatchAndExplain(const LhsContainer& lhs,
2110
+ MatchResultListener* listener) const {
2111
+ typedef internal::StlContainerView<
2112
+ typename std::remove_const<LhsContainer>::type>
2113
+ LhsView;
2114
+ typedef typename LhsView::type LhsStlContainer;
2115
+ StlContainerReference lhs_stl_container = LhsView::ConstReference(lhs);
2116
+ if (lhs_stl_container == expected_)
2117
+ return true;
2118
+
2119
+ ::std::ostream* const os = listener->stream();
2120
+ if (os != nullptr) {
2121
+ // Something is different. Check for extra values first.
2122
+ bool printed_header = false;
2123
+ for (typename LhsStlContainer::const_iterator it =
2124
+ lhs_stl_container.begin();
2125
+ it != lhs_stl_container.end(); ++it) {
2126
+ if (internal::ArrayAwareFind(expected_.begin(), expected_.end(), *it) ==
2127
+ expected_.end()) {
2128
+ if (printed_header) {
2129
+ *os << ", ";
2130
+ } else {
2131
+ *os << "which has these unexpected elements: ";
2132
+ printed_header = true;
2133
+ }
2134
+ UniversalPrint(*it, os);
2135
+ }
2136
+ }
2137
+
2138
+ // Now check for missing values.
2139
+ bool printed_header2 = false;
2140
+ for (typename StlContainer::const_iterator it = expected_.begin();
2141
+ it != expected_.end(); ++it) {
2142
+ if (internal::ArrayAwareFind(
2143
+ lhs_stl_container.begin(), lhs_stl_container.end(), *it) ==
2144
+ lhs_stl_container.end()) {
2145
+ if (printed_header2) {
2146
+ *os << ", ";
2147
+ } else {
2148
+ *os << (printed_header ? ",\nand" : "which")
2149
+ << " doesn't have these expected elements: ";
2150
+ printed_header2 = true;
2151
+ }
2152
+ UniversalPrint(*it, os);
2153
+ }
2154
+ }
2155
+ }
2156
+
2157
+ return false;
2158
+ }
2159
+
2160
+ private:
2161
+ const StlContainer expected_;
2162
+
2163
+ GTEST_DISALLOW_ASSIGN_(ContainerEqMatcher);
2164
+ };
2165
+
2166
+ // A comparator functor that uses the < operator to compare two values.
2167
+ struct LessComparator {
2168
+ template <typename T, typename U>
2169
+ bool operator()(const T& lhs, const U& rhs) const { return lhs < rhs; }
2170
+ };
2171
+
2172
+ // Implements WhenSortedBy(comparator, container_matcher).
2173
+ template <typename Comparator, typename ContainerMatcher>
2174
+ class WhenSortedByMatcher {
2175
+ public:
2176
+ WhenSortedByMatcher(const Comparator& comparator,
2177
+ const ContainerMatcher& matcher)
2178
+ : comparator_(comparator), matcher_(matcher) {}
2179
+
2180
+ template <typename LhsContainer>
2181
+ operator Matcher<LhsContainer>() const {
2182
+ return MakeMatcher(new Impl<LhsContainer>(comparator_, matcher_));
2183
+ }
2184
+
2185
+ template <typename LhsContainer>
2186
+ class Impl : public MatcherInterface<LhsContainer> {
2187
+ public:
2188
+ typedef internal::StlContainerView<
2189
+ GTEST_REMOVE_REFERENCE_AND_CONST_(LhsContainer)> LhsView;
2190
+ typedef typename LhsView::type LhsStlContainer;
2191
+ typedef typename LhsView::const_reference LhsStlContainerReference;
2192
+ // Transforms std::pair<const Key, Value> into std::pair<Key, Value>
2193
+ // so that we can match associative containers.
2194
+ typedef typename RemoveConstFromKey<
2195
+ typename LhsStlContainer::value_type>::type LhsValue;
2196
+
2197
+ Impl(const Comparator& comparator, const ContainerMatcher& matcher)
2198
+ : comparator_(comparator), matcher_(matcher) {}
2199
+
2200
+ void DescribeTo(::std::ostream* os) const override {
2201
+ *os << "(when sorted) ";
2202
+ matcher_.DescribeTo(os);
2203
+ }
2204
+
2205
+ void DescribeNegationTo(::std::ostream* os) const override {
2206
+ *os << "(when sorted) ";
2207
+ matcher_.DescribeNegationTo(os);
2208
+ }
2209
+
2210
+ bool MatchAndExplain(LhsContainer lhs,
2211
+ MatchResultListener* listener) const override {
2212
+ LhsStlContainerReference lhs_stl_container = LhsView::ConstReference(lhs);
2213
+ ::std::vector<LhsValue> sorted_container(lhs_stl_container.begin(),
2214
+ lhs_stl_container.end());
2215
+ ::std::sort(
2216
+ sorted_container.begin(), sorted_container.end(), comparator_);
2217
+
2218
+ if (!listener->IsInterested()) {
2219
+ // If the listener is not interested, we do not need to
2220
+ // construct the inner explanation.
2221
+ return matcher_.Matches(sorted_container);
2222
+ }
2223
+
2224
+ *listener << "which is ";
2225
+ UniversalPrint(sorted_container, listener->stream());
2226
+ *listener << " when sorted";
2227
+
2228
+ StringMatchResultListener inner_listener;
2229
+ const bool match = matcher_.MatchAndExplain(sorted_container,
2230
+ &inner_listener);
2231
+ PrintIfNotEmpty(inner_listener.str(), listener->stream());
2232
+ return match;
2233
+ }
2234
+
2235
+ private:
2236
+ const Comparator comparator_;
2237
+ const Matcher<const ::std::vector<LhsValue>&> matcher_;
2238
+
2239
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(Impl);
2240
+ };
2241
+
2242
+ private:
2243
+ const Comparator comparator_;
2244
+ const ContainerMatcher matcher_;
2245
+
2246
+ GTEST_DISALLOW_ASSIGN_(WhenSortedByMatcher);
2247
+ };
2248
+
2249
+ // Implements Pointwise(tuple_matcher, rhs_container). tuple_matcher
2250
+ // must be able to be safely cast to Matcher<std::tuple<const T1&, const
2251
+ // T2&> >, where T1 and T2 are the types of elements in the LHS
2252
+ // container and the RHS container respectively.
2253
+ template <typename TupleMatcher, typename RhsContainer>
2254
+ class PointwiseMatcher {
2255
+ GTEST_COMPILE_ASSERT_(
2256
+ !IsHashTable<GTEST_REMOVE_REFERENCE_AND_CONST_(RhsContainer)>::value,
2257
+ use_UnorderedPointwise_with_hash_tables);
2258
+
2259
+ public:
2260
+ typedef internal::StlContainerView<RhsContainer> RhsView;
2261
+ typedef typename RhsView::type RhsStlContainer;
2262
+ typedef typename RhsStlContainer::value_type RhsValue;
2263
+
2264
+ static_assert(!std::is_const<RhsContainer>::value,
2265
+ "RhsContainer type must not be const");
2266
+ static_assert(!std::is_reference<RhsContainer>::value,
2267
+ "RhsContainer type must not be a reference");
2268
+
2269
+ // Like ContainerEq, we make a copy of rhs in case the elements in
2270
+ // it are modified after this matcher is created.
2271
+ PointwiseMatcher(const TupleMatcher& tuple_matcher, const RhsContainer& rhs)
2272
+ : tuple_matcher_(tuple_matcher), rhs_(RhsView::Copy(rhs)) {}
2273
+
2274
+ template <typename LhsContainer>
2275
+ operator Matcher<LhsContainer>() const {
2276
+ GTEST_COMPILE_ASSERT_(
2277
+ !IsHashTable<GTEST_REMOVE_REFERENCE_AND_CONST_(LhsContainer)>::value,
2278
+ use_UnorderedPointwise_with_hash_tables);
2279
+
2280
+ return Matcher<LhsContainer>(
2281
+ new Impl<const LhsContainer&>(tuple_matcher_, rhs_));
2282
+ }
2283
+
2284
+ template <typename LhsContainer>
2285
+ class Impl : public MatcherInterface<LhsContainer> {
2286
+ public:
2287
+ typedef internal::StlContainerView<
2288
+ GTEST_REMOVE_REFERENCE_AND_CONST_(LhsContainer)> LhsView;
2289
+ typedef typename LhsView::type LhsStlContainer;
2290
+ typedef typename LhsView::const_reference LhsStlContainerReference;
2291
+ typedef typename LhsStlContainer::value_type LhsValue;
2292
+ // We pass the LHS value and the RHS value to the inner matcher by
2293
+ // reference, as they may be expensive to copy. We must use tuple
2294
+ // instead of pair here, as a pair cannot hold references (C++ 98,
2295
+ // 20.2.2 [lib.pairs]).
2296
+ typedef ::std::tuple<const LhsValue&, const RhsValue&> InnerMatcherArg;
2297
+
2298
+ Impl(const TupleMatcher& tuple_matcher, const RhsStlContainer& rhs)
2299
+ // mono_tuple_matcher_ holds a monomorphic version of the tuple matcher.
2300
+ : mono_tuple_matcher_(SafeMatcherCast<InnerMatcherArg>(tuple_matcher)),
2301
+ rhs_(rhs) {}
2302
+
2303
+ void DescribeTo(::std::ostream* os) const override {
2304
+ *os << "contains " << rhs_.size()
2305
+ << " values, where each value and its corresponding value in ";
2306
+ UniversalPrinter<RhsStlContainer>::Print(rhs_, os);
2307
+ *os << " ";
2308
+ mono_tuple_matcher_.DescribeTo(os);
2309
+ }
2310
+ void DescribeNegationTo(::std::ostream* os) const override {
2311
+ *os << "doesn't contain exactly " << rhs_.size()
2312
+ << " values, or contains a value x at some index i"
2313
+ << " where x and the i-th value of ";
2314
+ UniversalPrint(rhs_, os);
2315
+ *os << " ";
2316
+ mono_tuple_matcher_.DescribeNegationTo(os);
2317
+ }
2318
+
2319
+ bool MatchAndExplain(LhsContainer lhs,
2320
+ MatchResultListener* listener) const override {
2321
+ LhsStlContainerReference lhs_stl_container = LhsView::ConstReference(lhs);
2322
+ const size_t actual_size = lhs_stl_container.size();
2323
+ if (actual_size != rhs_.size()) {
2324
+ *listener << "which contains " << actual_size << " values";
2325
+ return false;
2326
+ }
2327
+
2328
+ typename LhsStlContainer::const_iterator left = lhs_stl_container.begin();
2329
+ typename RhsStlContainer::const_iterator right = rhs_.begin();
2330
+ for (size_t i = 0; i != actual_size; ++i, ++left, ++right) {
2331
+ if (listener->IsInterested()) {
2332
+ StringMatchResultListener inner_listener;
2333
+ // Create InnerMatcherArg as a temporarily object to avoid it outlives
2334
+ // *left and *right. Dereference or the conversion to `const T&` may
2335
+ // return temp objects, e.g for vector<bool>.
2336
+ if (!mono_tuple_matcher_.MatchAndExplain(
2337
+ InnerMatcherArg(ImplicitCast_<const LhsValue&>(*left),
2338
+ ImplicitCast_<const RhsValue&>(*right)),
2339
+ &inner_listener)) {
2340
+ *listener << "where the value pair (";
2341
+ UniversalPrint(*left, listener->stream());
2342
+ *listener << ", ";
2343
+ UniversalPrint(*right, listener->stream());
2344
+ *listener << ") at index #" << i << " don't match";
2345
+ PrintIfNotEmpty(inner_listener.str(), listener->stream());
2346
+ return false;
2347
+ }
2348
+ } else {
2349
+ if (!mono_tuple_matcher_.Matches(
2350
+ InnerMatcherArg(ImplicitCast_<const LhsValue&>(*left),
2351
+ ImplicitCast_<const RhsValue&>(*right))))
2352
+ return false;
2353
+ }
2354
+ }
2355
+
2356
+ return true;
2357
+ }
2358
+
2359
+ private:
2360
+ const Matcher<InnerMatcherArg> mono_tuple_matcher_;
2361
+ const RhsStlContainer rhs_;
2362
+
2363
+ GTEST_DISALLOW_ASSIGN_(Impl);
2364
+ };
2365
+
2366
+ private:
2367
+ const TupleMatcher tuple_matcher_;
2368
+ const RhsStlContainer rhs_;
2369
+
2370
+ GTEST_DISALLOW_ASSIGN_(PointwiseMatcher);
2371
+ };
2372
+
2373
+ // Holds the logic common to ContainsMatcherImpl and EachMatcherImpl.
2374
+ template <typename Container>
2375
+ class QuantifierMatcherImpl : public MatcherInterface<Container> {
2376
+ public:
2377
+ typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
2378
+ typedef StlContainerView<RawContainer> View;
2379
+ typedef typename View::type StlContainer;
2380
+ typedef typename View::const_reference StlContainerReference;
2381
+ typedef typename StlContainer::value_type Element;
2382
+
2383
+ template <typename InnerMatcher>
2384
+ explicit QuantifierMatcherImpl(InnerMatcher inner_matcher)
2385
+ : inner_matcher_(
2386
+ testing::SafeMatcherCast<const Element&>(inner_matcher)) {}
2387
+
2388
+ // Checks whether:
2389
+ // * All elements in the container match, if all_elements_should_match.
2390
+ // * Any element in the container matches, if !all_elements_should_match.
2391
+ bool MatchAndExplainImpl(bool all_elements_should_match,
2392
+ Container container,
2393
+ MatchResultListener* listener) const {
2394
+ StlContainerReference stl_container = View::ConstReference(container);
2395
+ size_t i = 0;
2396
+ for (typename StlContainer::const_iterator it = stl_container.begin();
2397
+ it != stl_container.end(); ++it, ++i) {
2398
+ StringMatchResultListener inner_listener;
2399
+ const bool matches = inner_matcher_.MatchAndExplain(*it, &inner_listener);
2400
+
2401
+ if (matches != all_elements_should_match) {
2402
+ *listener << "whose element #" << i
2403
+ << (matches ? " matches" : " doesn't match");
2404
+ PrintIfNotEmpty(inner_listener.str(), listener->stream());
2405
+ return !all_elements_should_match;
2406
+ }
2407
+ }
2408
+ return all_elements_should_match;
2409
+ }
2410
+
2411
+ protected:
2412
+ const Matcher<const Element&> inner_matcher_;
2413
+
2414
+ GTEST_DISALLOW_ASSIGN_(QuantifierMatcherImpl);
2415
+ };
2416
+
2417
+ // Implements Contains(element_matcher) for the given argument type Container.
2418
+ // Symmetric to EachMatcherImpl.
2419
+ template <typename Container>
2420
+ class ContainsMatcherImpl : public QuantifierMatcherImpl<Container> {
2421
+ public:
2422
+ template <typename InnerMatcher>
2423
+ explicit ContainsMatcherImpl(InnerMatcher inner_matcher)
2424
+ : QuantifierMatcherImpl<Container>(inner_matcher) {}
2425
+
2426
+ // Describes what this matcher does.
2427
+ void DescribeTo(::std::ostream* os) const override {
2428
+ *os << "contains at least one element that ";
2429
+ this->inner_matcher_.DescribeTo(os);
2430
+ }
2431
+
2432
+ void DescribeNegationTo(::std::ostream* os) const override {
2433
+ *os << "doesn't contain any element that ";
2434
+ this->inner_matcher_.DescribeTo(os);
2435
+ }
2436
+
2437
+ bool MatchAndExplain(Container container,
2438
+ MatchResultListener* listener) const override {
2439
+ return this->MatchAndExplainImpl(false, container, listener);
2440
+ }
2441
+
2442
+ private:
2443
+ GTEST_DISALLOW_ASSIGN_(ContainsMatcherImpl);
2444
+ };
2445
+
2446
+ // Implements Each(element_matcher) for the given argument type Container.
2447
+ // Symmetric to ContainsMatcherImpl.
2448
+ template <typename Container>
2449
+ class EachMatcherImpl : public QuantifierMatcherImpl<Container> {
2450
+ public:
2451
+ template <typename InnerMatcher>
2452
+ explicit EachMatcherImpl(InnerMatcher inner_matcher)
2453
+ : QuantifierMatcherImpl<Container>(inner_matcher) {}
2454
+
2455
+ // Describes what this matcher does.
2456
+ void DescribeTo(::std::ostream* os) const override {
2457
+ *os << "only contains elements that ";
2458
+ this->inner_matcher_.DescribeTo(os);
2459
+ }
2460
+
2461
+ void DescribeNegationTo(::std::ostream* os) const override {
2462
+ *os << "contains some element that ";
2463
+ this->inner_matcher_.DescribeNegationTo(os);
2464
+ }
2465
+
2466
+ bool MatchAndExplain(Container container,
2467
+ MatchResultListener* listener) const override {
2468
+ return this->MatchAndExplainImpl(true, container, listener);
2469
+ }
2470
+
2471
+ private:
2472
+ GTEST_DISALLOW_ASSIGN_(EachMatcherImpl);
2473
+ };
2474
+
2475
+ // Implements polymorphic Contains(element_matcher).
2476
+ template <typename M>
2477
+ class ContainsMatcher {
2478
+ public:
2479
+ explicit ContainsMatcher(M m) : inner_matcher_(m) {}
2480
+
2481
+ template <typename Container>
2482
+ operator Matcher<Container>() const {
2483
+ return Matcher<Container>(
2484
+ new ContainsMatcherImpl<const Container&>(inner_matcher_));
2485
+ }
2486
+
2487
+ private:
2488
+ const M inner_matcher_;
2489
+
2490
+ GTEST_DISALLOW_ASSIGN_(ContainsMatcher);
2491
+ };
2492
+
2493
+ // Implements polymorphic Each(element_matcher).
2494
+ template <typename M>
2495
+ class EachMatcher {
2496
+ public:
2497
+ explicit EachMatcher(M m) : inner_matcher_(m) {}
2498
+
2499
+ template <typename Container>
2500
+ operator Matcher<Container>() const {
2501
+ return Matcher<Container>(
2502
+ new EachMatcherImpl<const Container&>(inner_matcher_));
2503
+ }
2504
+
2505
+ private:
2506
+ const M inner_matcher_;
2507
+
2508
+ GTEST_DISALLOW_ASSIGN_(EachMatcher);
2509
+ };
2510
+
2511
+ struct Rank1 {};
2512
+ struct Rank0 : Rank1 {};
2513
+
2514
+ namespace pair_getters {
2515
+ using std::get;
2516
+ template <typename T>
2517
+ auto First(T& x, Rank1) -> decltype(get<0>(x)) { // NOLINT
2518
+ return get<0>(x);
2519
+ }
2520
+ template <typename T>
2521
+ auto First(T& x, Rank0) -> decltype((x.first)) { // NOLINT
2522
+ return x.first;
2523
+ }
2524
+
2525
+ template <typename T>
2526
+ auto Second(T& x, Rank1) -> decltype(get<1>(x)) { // NOLINT
2527
+ return get<1>(x);
2528
+ }
2529
+ template <typename T>
2530
+ auto Second(T& x, Rank0) -> decltype((x.second)) { // NOLINT
2531
+ return x.second;
2532
+ }
2533
+ } // namespace pair_getters
2534
+
2535
+ // Implements Key(inner_matcher) for the given argument pair type.
2536
+ // Key(inner_matcher) matches an std::pair whose 'first' field matches
2537
+ // inner_matcher. For example, Contains(Key(Ge(5))) can be used to match an
2538
+ // std::map that contains at least one element whose key is >= 5.
2539
+ template <typename PairType>
2540
+ class KeyMatcherImpl : public MatcherInterface<PairType> {
2541
+ public:
2542
+ typedef GTEST_REMOVE_REFERENCE_AND_CONST_(PairType) RawPairType;
2543
+ typedef typename RawPairType::first_type KeyType;
2544
+
2545
+ template <typename InnerMatcher>
2546
+ explicit KeyMatcherImpl(InnerMatcher inner_matcher)
2547
+ : inner_matcher_(
2548
+ testing::SafeMatcherCast<const KeyType&>(inner_matcher)) {
2549
+ }
2550
+
2551
+ // Returns true if and only if 'key_value.first' (the key) matches the inner
2552
+ // matcher.
2553
+ bool MatchAndExplain(PairType key_value,
2554
+ MatchResultListener* listener) const override {
2555
+ StringMatchResultListener inner_listener;
2556
+ const bool match = inner_matcher_.MatchAndExplain(
2557
+ pair_getters::First(key_value, Rank0()), &inner_listener);
2558
+ const std::string explanation = inner_listener.str();
2559
+ if (explanation != "") {
2560
+ *listener << "whose first field is a value " << explanation;
2561
+ }
2562
+ return match;
2563
+ }
2564
+
2565
+ // Describes what this matcher does.
2566
+ void DescribeTo(::std::ostream* os) const override {
2567
+ *os << "has a key that ";
2568
+ inner_matcher_.DescribeTo(os);
2569
+ }
2570
+
2571
+ // Describes what the negation of this matcher does.
2572
+ void DescribeNegationTo(::std::ostream* os) const override {
2573
+ *os << "doesn't have a key that ";
2574
+ inner_matcher_.DescribeTo(os);
2575
+ }
2576
+
2577
+ private:
2578
+ const Matcher<const KeyType&> inner_matcher_;
2579
+
2580
+ GTEST_DISALLOW_ASSIGN_(KeyMatcherImpl);
2581
+ };
2582
+
2583
+ // Implements polymorphic Key(matcher_for_key).
2584
+ template <typename M>
2585
+ class KeyMatcher {
2586
+ public:
2587
+ explicit KeyMatcher(M m) : matcher_for_key_(m) {}
2588
+
2589
+ template <typename PairType>
2590
+ operator Matcher<PairType>() const {
2591
+ return Matcher<PairType>(
2592
+ new KeyMatcherImpl<const PairType&>(matcher_for_key_));
2593
+ }
2594
+
2595
+ private:
2596
+ const M matcher_for_key_;
2597
+
2598
+ GTEST_DISALLOW_ASSIGN_(KeyMatcher);
2599
+ };
2600
+
2601
+ // Implements Pair(first_matcher, second_matcher) for the given argument pair
2602
+ // type with its two matchers. See Pair() function below.
2603
+ template <typename PairType>
2604
+ class PairMatcherImpl : public MatcherInterface<PairType> {
2605
+ public:
2606
+ typedef GTEST_REMOVE_REFERENCE_AND_CONST_(PairType) RawPairType;
2607
+ typedef typename RawPairType::first_type FirstType;
2608
+ typedef typename RawPairType::second_type SecondType;
2609
+
2610
+ template <typename FirstMatcher, typename SecondMatcher>
2611
+ PairMatcherImpl(FirstMatcher first_matcher, SecondMatcher second_matcher)
2612
+ : first_matcher_(
2613
+ testing::SafeMatcherCast<const FirstType&>(first_matcher)),
2614
+ second_matcher_(
2615
+ testing::SafeMatcherCast<const SecondType&>(second_matcher)) {
2616
+ }
2617
+
2618
+ // Describes what this matcher does.
2619
+ void DescribeTo(::std::ostream* os) const override {
2620
+ *os << "has a first field that ";
2621
+ first_matcher_.DescribeTo(os);
2622
+ *os << ", and has a second field that ";
2623
+ second_matcher_.DescribeTo(os);
2624
+ }
2625
+
2626
+ // Describes what the negation of this matcher does.
2627
+ void DescribeNegationTo(::std::ostream* os) const override {
2628
+ *os << "has a first field that ";
2629
+ first_matcher_.DescribeNegationTo(os);
2630
+ *os << ", or has a second field that ";
2631
+ second_matcher_.DescribeNegationTo(os);
2632
+ }
2633
+
2634
+ // Returns true if and only if 'a_pair.first' matches first_matcher and
2635
+ // 'a_pair.second' matches second_matcher.
2636
+ bool MatchAndExplain(PairType a_pair,
2637
+ MatchResultListener* listener) const override {
2638
+ if (!listener->IsInterested()) {
2639
+ // If the listener is not interested, we don't need to construct the
2640
+ // explanation.
2641
+ return first_matcher_.Matches(pair_getters::First(a_pair, Rank0())) &&
2642
+ second_matcher_.Matches(pair_getters::Second(a_pair, Rank0()));
2643
+ }
2644
+ StringMatchResultListener first_inner_listener;
2645
+ if (!first_matcher_.MatchAndExplain(pair_getters::First(a_pair, Rank0()),
2646
+ &first_inner_listener)) {
2647
+ *listener << "whose first field does not match";
2648
+ PrintIfNotEmpty(first_inner_listener.str(), listener->stream());
2649
+ return false;
2650
+ }
2651
+ StringMatchResultListener second_inner_listener;
2652
+ if (!second_matcher_.MatchAndExplain(pair_getters::Second(a_pair, Rank0()),
2653
+ &second_inner_listener)) {
2654
+ *listener << "whose second field does not match";
2655
+ PrintIfNotEmpty(second_inner_listener.str(), listener->stream());
2656
+ return false;
2657
+ }
2658
+ ExplainSuccess(first_inner_listener.str(), second_inner_listener.str(),
2659
+ listener);
2660
+ return true;
2661
+ }
2662
+
2663
+ private:
2664
+ void ExplainSuccess(const std::string& first_explanation,
2665
+ const std::string& second_explanation,
2666
+ MatchResultListener* listener) const {
2667
+ *listener << "whose both fields match";
2668
+ if (first_explanation != "") {
2669
+ *listener << ", where the first field is a value " << first_explanation;
2670
+ }
2671
+ if (second_explanation != "") {
2672
+ *listener << ", ";
2673
+ if (first_explanation != "") {
2674
+ *listener << "and ";
2675
+ } else {
2676
+ *listener << "where ";
2677
+ }
2678
+ *listener << "the second field is a value " << second_explanation;
2679
+ }
2680
+ }
2681
+
2682
+ const Matcher<const FirstType&> first_matcher_;
2683
+ const Matcher<const SecondType&> second_matcher_;
2684
+
2685
+ GTEST_DISALLOW_ASSIGN_(PairMatcherImpl);
2686
+ };
2687
+
2688
+ // Implements polymorphic Pair(first_matcher, second_matcher).
2689
+ template <typename FirstMatcher, typename SecondMatcher>
2690
+ class PairMatcher {
2691
+ public:
2692
+ PairMatcher(FirstMatcher first_matcher, SecondMatcher second_matcher)
2693
+ : first_matcher_(first_matcher), second_matcher_(second_matcher) {}
2694
+
2695
+ template <typename PairType>
2696
+ operator Matcher<PairType> () const {
2697
+ return Matcher<PairType>(
2698
+ new PairMatcherImpl<const PairType&>(first_matcher_, second_matcher_));
2699
+ }
2700
+
2701
+ private:
2702
+ const FirstMatcher first_matcher_;
2703
+ const SecondMatcher second_matcher_;
2704
+
2705
+ GTEST_DISALLOW_ASSIGN_(PairMatcher);
2706
+ };
2707
+
2708
+ // Implements ElementsAre() and ElementsAreArray().
2709
+ template <typename Container>
2710
+ class ElementsAreMatcherImpl : public MatcherInterface<Container> {
2711
+ public:
2712
+ typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
2713
+ typedef internal::StlContainerView<RawContainer> View;
2714
+ typedef typename View::type StlContainer;
2715
+ typedef typename View::const_reference StlContainerReference;
2716
+ typedef typename StlContainer::value_type Element;
2717
+
2718
+ // Constructs the matcher from a sequence of element values or
2719
+ // element matchers.
2720
+ template <typename InputIter>
2721
+ ElementsAreMatcherImpl(InputIter first, InputIter last) {
2722
+ while (first != last) {
2723
+ matchers_.push_back(MatcherCast<const Element&>(*first++));
2724
+ }
2725
+ }
2726
+
2727
+ // Describes what this matcher does.
2728
+ void DescribeTo(::std::ostream* os) const override {
2729
+ if (count() == 0) {
2730
+ *os << "is empty";
2731
+ } else if (count() == 1) {
2732
+ *os << "has 1 element that ";
2733
+ matchers_[0].DescribeTo(os);
2734
+ } else {
2735
+ *os << "has " << Elements(count()) << " where\n";
2736
+ for (size_t i = 0; i != count(); ++i) {
2737
+ *os << "element #" << i << " ";
2738
+ matchers_[i].DescribeTo(os);
2739
+ if (i + 1 < count()) {
2740
+ *os << ",\n";
2741
+ }
2742
+ }
2743
+ }
2744
+ }
2745
+
2746
+ // Describes what the negation of this matcher does.
2747
+ void DescribeNegationTo(::std::ostream* os) const override {
2748
+ if (count() == 0) {
2749
+ *os << "isn't empty";
2750
+ return;
2751
+ }
2752
+
2753
+ *os << "doesn't have " << Elements(count()) << ", or\n";
2754
+ for (size_t i = 0; i != count(); ++i) {
2755
+ *os << "element #" << i << " ";
2756
+ matchers_[i].DescribeNegationTo(os);
2757
+ if (i + 1 < count()) {
2758
+ *os << ", or\n";
2759
+ }
2760
+ }
2761
+ }
2762
+
2763
+ bool MatchAndExplain(Container container,
2764
+ MatchResultListener* listener) const override {
2765
+ // To work with stream-like "containers", we must only walk
2766
+ // through the elements in one pass.
2767
+
2768
+ const bool listener_interested = listener->IsInterested();
2769
+
2770
+ // explanations[i] is the explanation of the element at index i.
2771
+ ::std::vector<std::string> explanations(count());
2772
+ StlContainerReference stl_container = View::ConstReference(container);
2773
+ typename StlContainer::const_iterator it = stl_container.begin();
2774
+ size_t exam_pos = 0;
2775
+ bool mismatch_found = false; // Have we found a mismatched element yet?
2776
+
2777
+ // Go through the elements and matchers in pairs, until we reach
2778
+ // the end of either the elements or the matchers, or until we find a
2779
+ // mismatch.
2780
+ for (; it != stl_container.end() && exam_pos != count(); ++it, ++exam_pos) {
2781
+ bool match; // Does the current element match the current matcher?
2782
+ if (listener_interested) {
2783
+ StringMatchResultListener s;
2784
+ match = matchers_[exam_pos].MatchAndExplain(*it, &s);
2785
+ explanations[exam_pos] = s.str();
2786
+ } else {
2787
+ match = matchers_[exam_pos].Matches(*it);
2788
+ }
2789
+
2790
+ if (!match) {
2791
+ mismatch_found = true;
2792
+ break;
2793
+ }
2794
+ }
2795
+ // If mismatch_found is true, 'exam_pos' is the index of the mismatch.
2796
+
2797
+ // Find how many elements the actual container has. We avoid
2798
+ // calling size() s.t. this code works for stream-like "containers"
2799
+ // that don't define size().
2800
+ size_t actual_count = exam_pos;
2801
+ for (; it != stl_container.end(); ++it) {
2802
+ ++actual_count;
2803
+ }
2804
+
2805
+ if (actual_count != count()) {
2806
+ // The element count doesn't match. If the container is empty,
2807
+ // there's no need to explain anything as Google Mock already
2808
+ // prints the empty container. Otherwise we just need to show
2809
+ // how many elements there actually are.
2810
+ if (listener_interested && (actual_count != 0)) {
2811
+ *listener << "which has " << Elements(actual_count);
2812
+ }
2813
+ return false;
2814
+ }
2815
+
2816
+ if (mismatch_found) {
2817
+ // The element count matches, but the exam_pos-th element doesn't match.
2818
+ if (listener_interested) {
2819
+ *listener << "whose element #" << exam_pos << " doesn't match";
2820
+ PrintIfNotEmpty(explanations[exam_pos], listener->stream());
2821
+ }
2822
+ return false;
2823
+ }
2824
+
2825
+ // Every element matches its expectation. We need to explain why
2826
+ // (the obvious ones can be skipped).
2827
+ if (listener_interested) {
2828
+ bool reason_printed = false;
2829
+ for (size_t i = 0; i != count(); ++i) {
2830
+ const std::string& s = explanations[i];
2831
+ if (!s.empty()) {
2832
+ if (reason_printed) {
2833
+ *listener << ",\nand ";
2834
+ }
2835
+ *listener << "whose element #" << i << " matches, " << s;
2836
+ reason_printed = true;
2837
+ }
2838
+ }
2839
+ }
2840
+ return true;
2841
+ }
2842
+
2843
+ private:
2844
+ static Message Elements(size_t count) {
2845
+ return Message() << count << (count == 1 ? " element" : " elements");
2846
+ }
2847
+
2848
+ size_t count() const { return matchers_.size(); }
2849
+
2850
+ ::std::vector<Matcher<const Element&> > matchers_;
2851
+
2852
+ GTEST_DISALLOW_ASSIGN_(ElementsAreMatcherImpl);
2853
+ };
2854
+
2855
+ // Connectivity matrix of (elements X matchers), in element-major order.
2856
+ // Initially, there are no edges.
2857
+ // Use NextGraph() to iterate over all possible edge configurations.
2858
+ // Use Randomize() to generate a random edge configuration.
2859
+ class GTEST_API_ MatchMatrix {
2860
+ public:
2861
+ MatchMatrix(size_t num_elements, size_t num_matchers)
2862
+ : num_elements_(num_elements),
2863
+ num_matchers_(num_matchers),
2864
+ matched_(num_elements_* num_matchers_, 0) {
2865
+ }
2866
+
2867
+ size_t LhsSize() const { return num_elements_; }
2868
+ size_t RhsSize() const { return num_matchers_; }
2869
+ bool HasEdge(size_t ilhs, size_t irhs) const {
2870
+ return matched_[SpaceIndex(ilhs, irhs)] == 1;
2871
+ }
2872
+ void SetEdge(size_t ilhs, size_t irhs, bool b) {
2873
+ matched_[SpaceIndex(ilhs, irhs)] = b ? 1 : 0;
2874
+ }
2875
+
2876
+ // Treating the connectivity matrix as a (LhsSize()*RhsSize())-bit number,
2877
+ // adds 1 to that number; returns false if incrementing the graph left it
2878
+ // empty.
2879
+ bool NextGraph();
2880
+
2881
+ void Randomize();
2882
+
2883
+ std::string DebugString() const;
2884
+
2885
+ private:
2886
+ size_t SpaceIndex(size_t ilhs, size_t irhs) const {
2887
+ return ilhs * num_matchers_ + irhs;
2888
+ }
2889
+
2890
+ size_t num_elements_;
2891
+ size_t num_matchers_;
2892
+
2893
+ // Each element is a char interpreted as bool. They are stored as a
2894
+ // flattened array in lhs-major order, use 'SpaceIndex()' to translate
2895
+ // a (ilhs, irhs) matrix coordinate into an offset.
2896
+ ::std::vector<char> matched_;
2897
+ };
2898
+
2899
+ typedef ::std::pair<size_t, size_t> ElementMatcherPair;
2900
+ typedef ::std::vector<ElementMatcherPair> ElementMatcherPairs;
2901
+
2902
+ // Returns a maximum bipartite matching for the specified graph 'g'.
2903
+ // The matching is represented as a vector of {element, matcher} pairs.
2904
+ GTEST_API_ ElementMatcherPairs
2905
+ FindMaxBipartiteMatching(const MatchMatrix& g);
2906
+
2907
+ struct UnorderedMatcherRequire {
2908
+ enum Flags {
2909
+ Superset = 1 << 0,
2910
+ Subset = 1 << 1,
2911
+ ExactMatch = Superset | Subset,
2912
+ };
2913
+ };
2914
+
2915
+ // Untyped base class for implementing UnorderedElementsAre. By
2916
+ // putting logic that's not specific to the element type here, we
2917
+ // reduce binary bloat and increase compilation speed.
2918
+ class GTEST_API_ UnorderedElementsAreMatcherImplBase {
2919
+ protected:
2920
+ explicit UnorderedElementsAreMatcherImplBase(
2921
+ UnorderedMatcherRequire::Flags matcher_flags)
2922
+ : match_flags_(matcher_flags) {}
2923
+
2924
+ // A vector of matcher describers, one for each element matcher.
2925
+ // Does not own the describers (and thus can be used only when the
2926
+ // element matchers are alive).
2927
+ typedef ::std::vector<const MatcherDescriberInterface*> MatcherDescriberVec;
2928
+
2929
+ // Describes this UnorderedElementsAre matcher.
2930
+ void DescribeToImpl(::std::ostream* os) const;
2931
+
2932
+ // Describes the negation of this UnorderedElementsAre matcher.
2933
+ void DescribeNegationToImpl(::std::ostream* os) const;
2934
+
2935
+ bool VerifyMatchMatrix(const ::std::vector<std::string>& element_printouts,
2936
+ const MatchMatrix& matrix,
2937
+ MatchResultListener* listener) const;
2938
+
2939
+ bool FindPairing(const MatchMatrix& matrix,
2940
+ MatchResultListener* listener) const;
2941
+
2942
+ MatcherDescriberVec& matcher_describers() {
2943
+ return matcher_describers_;
2944
+ }
2945
+
2946
+ static Message Elements(size_t n) {
2947
+ return Message() << n << " element" << (n == 1 ? "" : "s");
2948
+ }
2949
+
2950
+ UnorderedMatcherRequire::Flags match_flags() const { return match_flags_; }
2951
+
2952
+ private:
2953
+ UnorderedMatcherRequire::Flags match_flags_;
2954
+ MatcherDescriberVec matcher_describers_;
2955
+
2956
+ GTEST_DISALLOW_ASSIGN_(UnorderedElementsAreMatcherImplBase);
2957
+ };
2958
+
2959
+ // Implements UnorderedElementsAre, UnorderedElementsAreArray, IsSubsetOf, and
2960
+ // IsSupersetOf.
2961
+ template <typename Container>
2962
+ class UnorderedElementsAreMatcherImpl
2963
+ : public MatcherInterface<Container>,
2964
+ public UnorderedElementsAreMatcherImplBase {
2965
+ public:
2966
+ typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
2967
+ typedef internal::StlContainerView<RawContainer> View;
2968
+ typedef typename View::type StlContainer;
2969
+ typedef typename View::const_reference StlContainerReference;
2970
+ typedef typename StlContainer::const_iterator StlContainerConstIterator;
2971
+ typedef typename StlContainer::value_type Element;
2972
+
2973
+ template <typename InputIter>
2974
+ UnorderedElementsAreMatcherImpl(UnorderedMatcherRequire::Flags matcher_flags,
2975
+ InputIter first, InputIter last)
2976
+ : UnorderedElementsAreMatcherImplBase(matcher_flags) {
2977
+ for (; first != last; ++first) {
2978
+ matchers_.push_back(MatcherCast<const Element&>(*first));
2979
+ matcher_describers().push_back(matchers_.back().GetDescriber());
2980
+ }
2981
+ }
2982
+
2983
+ // Describes what this matcher does.
2984
+ void DescribeTo(::std::ostream* os) const override {
2985
+ return UnorderedElementsAreMatcherImplBase::DescribeToImpl(os);
2986
+ }
2987
+
2988
+ // Describes what the negation of this matcher does.
2989
+ void DescribeNegationTo(::std::ostream* os) const override {
2990
+ return UnorderedElementsAreMatcherImplBase::DescribeNegationToImpl(os);
2991
+ }
2992
+
2993
+ bool MatchAndExplain(Container container,
2994
+ MatchResultListener* listener) const override {
2995
+ StlContainerReference stl_container = View::ConstReference(container);
2996
+ ::std::vector<std::string> element_printouts;
2997
+ MatchMatrix matrix =
2998
+ AnalyzeElements(stl_container.begin(), stl_container.end(),
2999
+ &element_printouts, listener);
3000
+
3001
+ if (matrix.LhsSize() == 0 && matrix.RhsSize() == 0) {
3002
+ return true;
3003
+ }
3004
+
3005
+ if (match_flags() == UnorderedMatcherRequire::ExactMatch) {
3006
+ if (matrix.LhsSize() != matrix.RhsSize()) {
3007
+ // The element count doesn't match. If the container is empty,
3008
+ // there's no need to explain anything as Google Mock already
3009
+ // prints the empty container. Otherwise we just need to show
3010
+ // how many elements there actually are.
3011
+ if (matrix.LhsSize() != 0 && listener->IsInterested()) {
3012
+ *listener << "which has " << Elements(matrix.LhsSize());
3013
+ }
3014
+ return false;
3015
+ }
3016
+ }
3017
+
3018
+ return VerifyMatchMatrix(element_printouts, matrix, listener) &&
3019
+ FindPairing(matrix, listener);
3020
+ }
3021
+
3022
+ private:
3023
+ template <typename ElementIter>
3024
+ MatchMatrix AnalyzeElements(ElementIter elem_first, ElementIter elem_last,
3025
+ ::std::vector<std::string>* element_printouts,
3026
+ MatchResultListener* listener) const {
3027
+ element_printouts->clear();
3028
+ ::std::vector<char> did_match;
3029
+ size_t num_elements = 0;
3030
+ DummyMatchResultListener dummy;
3031
+ for (; elem_first != elem_last; ++num_elements, ++elem_first) {
3032
+ if (listener->IsInterested()) {
3033
+ element_printouts->push_back(PrintToString(*elem_first));
3034
+ }
3035
+ for (size_t irhs = 0; irhs != matchers_.size(); ++irhs) {
3036
+ did_match.push_back(
3037
+ matchers_[irhs].MatchAndExplain(*elem_first, &dummy));
3038
+ }
3039
+ }
3040
+
3041
+ MatchMatrix matrix(num_elements, matchers_.size());
3042
+ ::std::vector<char>::const_iterator did_match_iter = did_match.begin();
3043
+ for (size_t ilhs = 0; ilhs != num_elements; ++ilhs) {
3044
+ for (size_t irhs = 0; irhs != matchers_.size(); ++irhs) {
3045
+ matrix.SetEdge(ilhs, irhs, *did_match_iter++ != 0);
3046
+ }
3047
+ }
3048
+ return matrix;
3049
+ }
3050
+
3051
+ ::std::vector<Matcher<const Element&> > matchers_;
3052
+
3053
+ GTEST_DISALLOW_ASSIGN_(UnorderedElementsAreMatcherImpl);
3054
+ };
3055
+
3056
+ // Functor for use in TransformTuple.
3057
+ // Performs MatcherCast<Target> on an input argument of any type.
3058
+ template <typename Target>
3059
+ struct CastAndAppendTransform {
3060
+ template <typename Arg>
3061
+ Matcher<Target> operator()(const Arg& a) const {
3062
+ return MatcherCast<Target>(a);
3063
+ }
3064
+ };
3065
+
3066
+ // Implements UnorderedElementsAre.
3067
+ template <typename MatcherTuple>
3068
+ class UnorderedElementsAreMatcher {
3069
+ public:
3070
+ explicit UnorderedElementsAreMatcher(const MatcherTuple& args)
3071
+ : matchers_(args) {}
3072
+
3073
+ template <typename Container>
3074
+ operator Matcher<Container>() const {
3075
+ typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
3076
+ typedef typename internal::StlContainerView<RawContainer>::type View;
3077
+ typedef typename View::value_type Element;
3078
+ typedef ::std::vector<Matcher<const Element&> > MatcherVec;
3079
+ MatcherVec matchers;
3080
+ matchers.reserve(::std::tuple_size<MatcherTuple>::value);
3081
+ TransformTupleValues(CastAndAppendTransform<const Element&>(), matchers_,
3082
+ ::std::back_inserter(matchers));
3083
+ return Matcher<Container>(
3084
+ new UnorderedElementsAreMatcherImpl<const Container&>(
3085
+ UnorderedMatcherRequire::ExactMatch, matchers.begin(),
3086
+ matchers.end()));
3087
+ }
3088
+
3089
+ private:
3090
+ const MatcherTuple matchers_;
3091
+ GTEST_DISALLOW_ASSIGN_(UnorderedElementsAreMatcher);
3092
+ };
3093
+
3094
+ // Implements ElementsAre.
3095
+ template <typename MatcherTuple>
3096
+ class ElementsAreMatcher {
3097
+ public:
3098
+ explicit ElementsAreMatcher(const MatcherTuple& args) : matchers_(args) {}
3099
+
3100
+ template <typename Container>
3101
+ operator Matcher<Container>() const {
3102
+ GTEST_COMPILE_ASSERT_(
3103
+ !IsHashTable<GTEST_REMOVE_REFERENCE_AND_CONST_(Container)>::value ||
3104
+ ::std::tuple_size<MatcherTuple>::value < 2,
3105
+ use_UnorderedElementsAre_with_hash_tables);
3106
+
3107
+ typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
3108
+ typedef typename internal::StlContainerView<RawContainer>::type View;
3109
+ typedef typename View::value_type Element;
3110
+ typedef ::std::vector<Matcher<const Element&> > MatcherVec;
3111
+ MatcherVec matchers;
3112
+ matchers.reserve(::std::tuple_size<MatcherTuple>::value);
3113
+ TransformTupleValues(CastAndAppendTransform<const Element&>(), matchers_,
3114
+ ::std::back_inserter(matchers));
3115
+ return Matcher<Container>(new ElementsAreMatcherImpl<const Container&>(
3116
+ matchers.begin(), matchers.end()));
3117
+ }
3118
+
3119
+ private:
3120
+ const MatcherTuple matchers_;
3121
+ GTEST_DISALLOW_ASSIGN_(ElementsAreMatcher);
3122
+ };
3123
+
3124
+ // Implements UnorderedElementsAreArray(), IsSubsetOf(), and IsSupersetOf().
3125
+ template <typename T>
3126
+ class UnorderedElementsAreArrayMatcher {
3127
+ public:
3128
+ template <typename Iter>
3129
+ UnorderedElementsAreArrayMatcher(UnorderedMatcherRequire::Flags match_flags,
3130
+ Iter first, Iter last)
3131
+ : match_flags_(match_flags), matchers_(first, last) {}
3132
+
3133
+ template <typename Container>
3134
+ operator Matcher<Container>() const {
3135
+ return Matcher<Container>(
3136
+ new UnorderedElementsAreMatcherImpl<const Container&>(
3137
+ match_flags_, matchers_.begin(), matchers_.end()));
3138
+ }
3139
+
3140
+ private:
3141
+ UnorderedMatcherRequire::Flags match_flags_;
3142
+ ::std::vector<T> matchers_;
3143
+
3144
+ GTEST_DISALLOW_ASSIGN_(UnorderedElementsAreArrayMatcher);
3145
+ };
3146
+
3147
+ // Implements ElementsAreArray().
3148
+ template <typename T>
3149
+ class ElementsAreArrayMatcher {
3150
+ public:
3151
+ template <typename Iter>
3152
+ ElementsAreArrayMatcher(Iter first, Iter last) : matchers_(first, last) {}
3153
+
3154
+ template <typename Container>
3155
+ operator Matcher<Container>() const {
3156
+ GTEST_COMPILE_ASSERT_(
3157
+ !IsHashTable<GTEST_REMOVE_REFERENCE_AND_CONST_(Container)>::value,
3158
+ use_UnorderedElementsAreArray_with_hash_tables);
3159
+
3160
+ return Matcher<Container>(new ElementsAreMatcherImpl<const Container&>(
3161
+ matchers_.begin(), matchers_.end()));
3162
+ }
3163
+
3164
+ private:
3165
+ const ::std::vector<T> matchers_;
3166
+
3167
+ GTEST_DISALLOW_ASSIGN_(ElementsAreArrayMatcher);
3168
+ };
3169
+
3170
+ // Given a 2-tuple matcher tm of type Tuple2Matcher and a value second
3171
+ // of type Second, BoundSecondMatcher<Tuple2Matcher, Second>(tm,
3172
+ // second) is a polymorphic matcher that matches a value x if and only if
3173
+ // tm matches tuple (x, second). Useful for implementing
3174
+ // UnorderedPointwise() in terms of UnorderedElementsAreArray().
3175
+ //
3176
+ // BoundSecondMatcher is copyable and assignable, as we need to put
3177
+ // instances of this class in a vector when implementing
3178
+ // UnorderedPointwise().
3179
+ template <typename Tuple2Matcher, typename Second>
3180
+ class BoundSecondMatcher {
3181
+ public:
3182
+ BoundSecondMatcher(const Tuple2Matcher& tm, const Second& second)
3183
+ : tuple2_matcher_(tm), second_value_(second) {}
3184
+
3185
+ template <typename T>
3186
+ operator Matcher<T>() const {
3187
+ return MakeMatcher(new Impl<T>(tuple2_matcher_, second_value_));
3188
+ }
3189
+
3190
+ // We have to define this for UnorderedPointwise() to compile in
3191
+ // C++98 mode, as it puts BoundSecondMatcher instances in a vector,
3192
+ // which requires the elements to be assignable in C++98. The
3193
+ // compiler cannot generate the operator= for us, as Tuple2Matcher
3194
+ // and Second may not be assignable.
3195
+ //
3196
+ // However, this should never be called, so the implementation just
3197
+ // need to assert.
3198
+ void operator=(const BoundSecondMatcher& /*rhs*/) {
3199
+ GTEST_LOG_(FATAL) << "BoundSecondMatcher should never be assigned.";
3200
+ }
3201
+
3202
+ private:
3203
+ template <typename T>
3204
+ class Impl : public MatcherInterface<T> {
3205
+ public:
3206
+ typedef ::std::tuple<T, Second> ArgTuple;
3207
+
3208
+ Impl(const Tuple2Matcher& tm, const Second& second)
3209
+ : mono_tuple2_matcher_(SafeMatcherCast<const ArgTuple&>(tm)),
3210
+ second_value_(second) {}
3211
+
3212
+ void DescribeTo(::std::ostream* os) const override {
3213
+ *os << "and ";
3214
+ UniversalPrint(second_value_, os);
3215
+ *os << " ";
3216
+ mono_tuple2_matcher_.DescribeTo(os);
3217
+ }
3218
+
3219
+ bool MatchAndExplain(T x, MatchResultListener* listener) const override {
3220
+ return mono_tuple2_matcher_.MatchAndExplain(ArgTuple(x, second_value_),
3221
+ listener);
3222
+ }
3223
+
3224
+ private:
3225
+ const Matcher<const ArgTuple&> mono_tuple2_matcher_;
3226
+ const Second second_value_;
3227
+
3228
+ GTEST_DISALLOW_ASSIGN_(Impl);
3229
+ };
3230
+
3231
+ const Tuple2Matcher tuple2_matcher_;
3232
+ const Second second_value_;
3233
+ };
3234
+
3235
+ // Given a 2-tuple matcher tm and a value second,
3236
+ // MatcherBindSecond(tm, second) returns a matcher that matches a
3237
+ // value x if and only if tm matches tuple (x, second). Useful for
3238
+ // implementing UnorderedPointwise() in terms of UnorderedElementsAreArray().
3239
+ template <typename Tuple2Matcher, typename Second>
3240
+ BoundSecondMatcher<Tuple2Matcher, Second> MatcherBindSecond(
3241
+ const Tuple2Matcher& tm, const Second& second) {
3242
+ return BoundSecondMatcher<Tuple2Matcher, Second>(tm, second);
3243
+ }
3244
+
3245
+ // Returns the description for a matcher defined using the MATCHER*()
3246
+ // macro where the user-supplied description string is "", if
3247
+ // 'negation' is false; otherwise returns the description of the
3248
+ // negation of the matcher. 'param_values' contains a list of strings
3249
+ // that are the print-out of the matcher's parameters.
3250
+ GTEST_API_ std::string FormatMatcherDescription(bool negation,
3251
+ const char* matcher_name,
3252
+ const Strings& param_values);
3253
+
3254
+ // Implements a matcher that checks the value of a optional<> type variable.
3255
+ template <typename ValueMatcher>
3256
+ class OptionalMatcher {
3257
+ public:
3258
+ explicit OptionalMatcher(const ValueMatcher& value_matcher)
3259
+ : value_matcher_(value_matcher) {}
3260
+
3261
+ template <typename Optional>
3262
+ operator Matcher<Optional>() const {
3263
+ return Matcher<Optional>(new Impl<const Optional&>(value_matcher_));
3264
+ }
3265
+
3266
+ template <typename Optional>
3267
+ class Impl : public MatcherInterface<Optional> {
3268
+ public:
3269
+ typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Optional) OptionalView;
3270
+ typedef typename OptionalView::value_type ValueType;
3271
+ explicit Impl(const ValueMatcher& value_matcher)
3272
+ : value_matcher_(MatcherCast<ValueType>(value_matcher)) {}
3273
+
3274
+ void DescribeTo(::std::ostream* os) const override {
3275
+ *os << "value ";
3276
+ value_matcher_.DescribeTo(os);
3277
+ }
3278
+
3279
+ void DescribeNegationTo(::std::ostream* os) const override {
3280
+ *os << "value ";
3281
+ value_matcher_.DescribeNegationTo(os);
3282
+ }
3283
+
3284
+ bool MatchAndExplain(Optional optional,
3285
+ MatchResultListener* listener) const override {
3286
+ if (!optional) {
3287
+ *listener << "which is not engaged";
3288
+ return false;
3289
+ }
3290
+ const ValueType& value = *optional;
3291
+ StringMatchResultListener value_listener;
3292
+ const bool match = value_matcher_.MatchAndExplain(value, &value_listener);
3293
+ *listener << "whose value " << PrintToString(value)
3294
+ << (match ? " matches" : " doesn't match");
3295
+ PrintIfNotEmpty(value_listener.str(), listener->stream());
3296
+ return match;
3297
+ }
3298
+
3299
+ private:
3300
+ const Matcher<ValueType> value_matcher_;
3301
+ GTEST_DISALLOW_ASSIGN_(Impl);
3302
+ };
3303
+
3304
+ private:
3305
+ const ValueMatcher value_matcher_;
3306
+ GTEST_DISALLOW_ASSIGN_(OptionalMatcher);
3307
+ };
3308
+
3309
+ namespace variant_matcher {
3310
+ // Overloads to allow VariantMatcher to do proper ADL lookup.
3311
+ template <typename T>
3312
+ void holds_alternative() {}
3313
+ template <typename T>
3314
+ void get() {}
3315
+
3316
+ // Implements a matcher that checks the value of a variant<> type variable.
3317
+ template <typename T>
3318
+ class VariantMatcher {
3319
+ public:
3320
+ explicit VariantMatcher(::testing::Matcher<const T&> matcher)
3321
+ : matcher_(std::move(matcher)) {}
3322
+
3323
+ template <typename Variant>
3324
+ bool MatchAndExplain(const Variant& value,
3325
+ ::testing::MatchResultListener* listener) const {
3326
+ using std::get;
3327
+ if (!listener->IsInterested()) {
3328
+ return holds_alternative<T>(value) && matcher_.Matches(get<T>(value));
3329
+ }
3330
+
3331
+ if (!holds_alternative<T>(value)) {
3332
+ *listener << "whose value is not of type '" << GetTypeName() << "'";
3333
+ return false;
3334
+ }
3335
+
3336
+ const T& elem = get<T>(value);
3337
+ StringMatchResultListener elem_listener;
3338
+ const bool match = matcher_.MatchAndExplain(elem, &elem_listener);
3339
+ *listener << "whose value " << PrintToString(elem)
3340
+ << (match ? " matches" : " doesn't match");
3341
+ PrintIfNotEmpty(elem_listener.str(), listener->stream());
3342
+ return match;
3343
+ }
3344
+
3345
+ void DescribeTo(std::ostream* os) const {
3346
+ *os << "is a variant<> with value of type '" << GetTypeName()
3347
+ << "' and the value ";
3348
+ matcher_.DescribeTo(os);
3349
+ }
3350
+
3351
+ void DescribeNegationTo(std::ostream* os) const {
3352
+ *os << "is a variant<> with value of type other than '" << GetTypeName()
3353
+ << "' or the value ";
3354
+ matcher_.DescribeNegationTo(os);
3355
+ }
3356
+
3357
+ private:
3358
+ static std::string GetTypeName() {
3359
+ #if GTEST_HAS_RTTI
3360
+ GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(
3361
+ return internal::GetTypeName<T>());
3362
+ #endif
3363
+ return "the element type";
3364
+ }
3365
+
3366
+ const ::testing::Matcher<const T&> matcher_;
3367
+ };
3368
+
3369
+ } // namespace variant_matcher
3370
+
3371
+ namespace any_cast_matcher {
3372
+
3373
+ // Overloads to allow AnyCastMatcher to do proper ADL lookup.
3374
+ template <typename T>
3375
+ void any_cast() {}
3376
+
3377
+ // Implements a matcher that any_casts the value.
3378
+ template <typename T>
3379
+ class AnyCastMatcher {
3380
+ public:
3381
+ explicit AnyCastMatcher(const ::testing::Matcher<const T&>& matcher)
3382
+ : matcher_(matcher) {}
3383
+
3384
+ template <typename AnyType>
3385
+ bool MatchAndExplain(const AnyType& value,
3386
+ ::testing::MatchResultListener* listener) const {
3387
+ if (!listener->IsInterested()) {
3388
+ const T* ptr = any_cast<T>(&value);
3389
+ return ptr != nullptr && matcher_.Matches(*ptr);
3390
+ }
3391
+
3392
+ const T* elem = any_cast<T>(&value);
3393
+ if (elem == nullptr) {
3394
+ *listener << "whose value is not of type '" << GetTypeName() << "'";
3395
+ return false;
3396
+ }
3397
+
3398
+ StringMatchResultListener elem_listener;
3399
+ const bool match = matcher_.MatchAndExplain(*elem, &elem_listener);
3400
+ *listener << "whose value " << PrintToString(*elem)
3401
+ << (match ? " matches" : " doesn't match");
3402
+ PrintIfNotEmpty(elem_listener.str(), listener->stream());
3403
+ return match;
3404
+ }
3405
+
3406
+ void DescribeTo(std::ostream* os) const {
3407
+ *os << "is an 'any' type with value of type '" << GetTypeName()
3408
+ << "' and the value ";
3409
+ matcher_.DescribeTo(os);
3410
+ }
3411
+
3412
+ void DescribeNegationTo(std::ostream* os) const {
3413
+ *os << "is an 'any' type with value of type other than '" << GetTypeName()
3414
+ << "' or the value ";
3415
+ matcher_.DescribeNegationTo(os);
3416
+ }
3417
+
3418
+ private:
3419
+ static std::string GetTypeName() {
3420
+ #if GTEST_HAS_RTTI
3421
+ GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(
3422
+ return internal::GetTypeName<T>());
3423
+ #endif
3424
+ return "the element type";
3425
+ }
3426
+
3427
+ const ::testing::Matcher<const T&> matcher_;
3428
+ };
3429
+
3430
+ } // namespace any_cast_matcher
3431
+
3432
+ // Implements the Args() matcher.
3433
+ template <class ArgsTuple, size_t... k>
3434
+ class ArgsMatcherImpl : public MatcherInterface<ArgsTuple> {
3435
+ public:
3436
+ using RawArgsTuple = typename std::decay<ArgsTuple>::type;
3437
+ using SelectedArgs =
3438
+ std::tuple<typename std::tuple_element<k, RawArgsTuple>::type...>;
3439
+ using MonomorphicInnerMatcher = Matcher<const SelectedArgs&>;
3440
+
3441
+ template <typename InnerMatcher>
3442
+ explicit ArgsMatcherImpl(const InnerMatcher& inner_matcher)
3443
+ : inner_matcher_(SafeMatcherCast<const SelectedArgs&>(inner_matcher)) {}
3444
+
3445
+ bool MatchAndExplain(ArgsTuple args,
3446
+ MatchResultListener* listener) const override {
3447
+ // Workaround spurious C4100 on MSVC<=15.7 when k is empty.
3448
+ (void)args;
3449
+ const SelectedArgs& selected_args =
3450
+ std::forward_as_tuple(std::get<k>(args)...);
3451
+ if (!listener->IsInterested()) return inner_matcher_.Matches(selected_args);
3452
+
3453
+ PrintIndices(listener->stream());
3454
+ *listener << "are " << PrintToString(selected_args);
3455
+
3456
+ StringMatchResultListener inner_listener;
3457
+ const bool match =
3458
+ inner_matcher_.MatchAndExplain(selected_args, &inner_listener);
3459
+ PrintIfNotEmpty(inner_listener.str(), listener->stream());
3460
+ return match;
3461
+ }
3462
+
3463
+ void DescribeTo(::std::ostream* os) const override {
3464
+ *os << "are a tuple ";
3465
+ PrintIndices(os);
3466
+ inner_matcher_.DescribeTo(os);
3467
+ }
3468
+
3469
+ void DescribeNegationTo(::std::ostream* os) const override {
3470
+ *os << "are a tuple ";
3471
+ PrintIndices(os);
3472
+ inner_matcher_.DescribeNegationTo(os);
3473
+ }
3474
+
3475
+ private:
3476
+ // Prints the indices of the selected fields.
3477
+ static void PrintIndices(::std::ostream* os) {
3478
+ *os << "whose fields (";
3479
+ const char* sep = "";
3480
+ // Workaround spurious C4189 on MSVC<=15.7 when k is empty.
3481
+ (void)sep;
3482
+ const char* dummy[] = {"", (*os << sep << "#" << k, sep = ", ")...};
3483
+ (void)dummy;
3484
+ *os << ") ";
3485
+ }
3486
+
3487
+ MonomorphicInnerMatcher inner_matcher_;
3488
+ };
3489
+
3490
+ template <class InnerMatcher, size_t... k>
3491
+ class ArgsMatcher {
3492
+ public:
3493
+ explicit ArgsMatcher(InnerMatcher inner_matcher)
3494
+ : inner_matcher_(std::move(inner_matcher)) {}
3495
+
3496
+ template <typename ArgsTuple>
3497
+ operator Matcher<ArgsTuple>() const { // NOLINT
3498
+ return MakeMatcher(new ArgsMatcherImpl<ArgsTuple, k...>(inner_matcher_));
3499
+ }
3500
+
3501
+ private:
3502
+ InnerMatcher inner_matcher_;
3503
+ };
3504
+
3505
+ } // namespace internal
3506
+
3507
+ // ElementsAreArray(iterator_first, iterator_last)
3508
+ // ElementsAreArray(pointer, count)
3509
+ // ElementsAreArray(array)
3510
+ // ElementsAreArray(container)
3511
+ // ElementsAreArray({ e1, e2, ..., en })
3512
+ //
3513
+ // The ElementsAreArray() functions are like ElementsAre(...), except
3514
+ // that they are given a homogeneous sequence rather than taking each
3515
+ // element as a function argument. The sequence can be specified as an
3516
+ // array, a pointer and count, a vector, an initializer list, or an
3517
+ // STL iterator range. In each of these cases, the underlying sequence
3518
+ // can be either a sequence of values or a sequence of matchers.
3519
+ //
3520
+ // All forms of ElementsAreArray() make a copy of the input matcher sequence.
3521
+
3522
+ template <typename Iter>
3523
+ inline internal::ElementsAreArrayMatcher<
3524
+ typename ::std::iterator_traits<Iter>::value_type>
3525
+ ElementsAreArray(Iter first, Iter last) {
3526
+ typedef typename ::std::iterator_traits<Iter>::value_type T;
3527
+ return internal::ElementsAreArrayMatcher<T>(first, last);
3528
+ }
3529
+
3530
+ template <typename T>
3531
+ inline internal::ElementsAreArrayMatcher<T> ElementsAreArray(
3532
+ const T* pointer, size_t count) {
3533
+ return ElementsAreArray(pointer, pointer + count);
3534
+ }
3535
+
3536
+ template <typename T, size_t N>
3537
+ inline internal::ElementsAreArrayMatcher<T> ElementsAreArray(
3538
+ const T (&array)[N]) {
3539
+ return ElementsAreArray(array, N);
3540
+ }
3541
+
3542
+ template <typename Container>
3543
+ inline internal::ElementsAreArrayMatcher<typename Container::value_type>
3544
+ ElementsAreArray(const Container& container) {
3545
+ return ElementsAreArray(container.begin(), container.end());
3546
+ }
3547
+
3548
+ template <typename T>
3549
+ inline internal::ElementsAreArrayMatcher<T>
3550
+ ElementsAreArray(::std::initializer_list<T> xs) {
3551
+ return ElementsAreArray(xs.begin(), xs.end());
3552
+ }
3553
+
3554
+ // UnorderedElementsAreArray(iterator_first, iterator_last)
3555
+ // UnorderedElementsAreArray(pointer, count)
3556
+ // UnorderedElementsAreArray(array)
3557
+ // UnorderedElementsAreArray(container)
3558
+ // UnorderedElementsAreArray({ e1, e2, ..., en })
3559
+ //
3560
+ // UnorderedElementsAreArray() verifies that a bijective mapping onto a
3561
+ // collection of matchers exists.
3562
+ //
3563
+ // The matchers can be specified as an array, a pointer and count, a container,
3564
+ // an initializer list, or an STL iterator range. In each of these cases, the
3565
+ // underlying matchers can be either values or matchers.
3566
+
3567
+ template <typename Iter>
3568
+ inline internal::UnorderedElementsAreArrayMatcher<
3569
+ typename ::std::iterator_traits<Iter>::value_type>
3570
+ UnorderedElementsAreArray(Iter first, Iter last) {
3571
+ typedef typename ::std::iterator_traits<Iter>::value_type T;
3572
+ return internal::UnorderedElementsAreArrayMatcher<T>(
3573
+ internal::UnorderedMatcherRequire::ExactMatch, first, last);
3574
+ }
3575
+
3576
+ template <typename T>
3577
+ inline internal::UnorderedElementsAreArrayMatcher<T>
3578
+ UnorderedElementsAreArray(const T* pointer, size_t count) {
3579
+ return UnorderedElementsAreArray(pointer, pointer + count);
3580
+ }
3581
+
3582
+ template <typename T, size_t N>
3583
+ inline internal::UnorderedElementsAreArrayMatcher<T>
3584
+ UnorderedElementsAreArray(const T (&array)[N]) {
3585
+ return UnorderedElementsAreArray(array, N);
3586
+ }
3587
+
3588
+ template <typename Container>
3589
+ inline internal::UnorderedElementsAreArrayMatcher<
3590
+ typename Container::value_type>
3591
+ UnorderedElementsAreArray(const Container& container) {
3592
+ return UnorderedElementsAreArray(container.begin(), container.end());
3593
+ }
3594
+
3595
+ template <typename T>
3596
+ inline internal::UnorderedElementsAreArrayMatcher<T>
3597
+ UnorderedElementsAreArray(::std::initializer_list<T> xs) {
3598
+ return UnorderedElementsAreArray(xs.begin(), xs.end());
3599
+ }
3600
+
3601
+ // _ is a matcher that matches anything of any type.
3602
+ //
3603
+ // This definition is fine as:
3604
+ //
3605
+ // 1. The C++ standard permits using the name _ in a namespace that
3606
+ // is not the global namespace or ::std.
3607
+ // 2. The AnythingMatcher class has no data member or constructor,
3608
+ // so it's OK to create global variables of this type.
3609
+ // 3. c-style has approved of using _ in this case.
3610
+ const internal::AnythingMatcher _ = {};
3611
+ // Creates a matcher that matches any value of the given type T.
3612
+ template <typename T>
3613
+ inline Matcher<T> A() {
3614
+ return Matcher<T>(new internal::AnyMatcherImpl<T>());
3615
+ }
3616
+
3617
+ // Creates a matcher that matches any value of the given type T.
3618
+ template <typename T>
3619
+ inline Matcher<T> An() { return A<T>(); }
3620
+
3621
+ template <typename T, typename M>
3622
+ Matcher<T> internal::MatcherCastImpl<T, M>::CastImpl(
3623
+ const M& value, std::false_type /* convertible_to_matcher */,
3624
+ std::false_type /* convertible_to_T */) {
3625
+ return Eq(value);
3626
+ }
3627
+
3628
+ // Creates a polymorphic matcher that matches any NULL pointer.
3629
+ inline PolymorphicMatcher<internal::IsNullMatcher > IsNull() {
3630
+ return MakePolymorphicMatcher(internal::IsNullMatcher());
3631
+ }
3632
+
3633
+ // Creates a polymorphic matcher that matches any non-NULL pointer.
3634
+ // This is convenient as Not(NULL) doesn't compile (the compiler
3635
+ // thinks that that expression is comparing a pointer with an integer).
3636
+ inline PolymorphicMatcher<internal::NotNullMatcher > NotNull() {
3637
+ return MakePolymorphicMatcher(internal::NotNullMatcher());
3638
+ }
3639
+
3640
+ // Creates a polymorphic matcher that matches any argument that
3641
+ // references variable x.
3642
+ template <typename T>
3643
+ inline internal::RefMatcher<T&> Ref(T& x) { // NOLINT
3644
+ return internal::RefMatcher<T&>(x);
3645
+ }
3646
+
3647
+ // Creates a polymorphic matcher that matches any NaN floating point.
3648
+ inline PolymorphicMatcher<internal::IsNanMatcher> IsNan() {
3649
+ return MakePolymorphicMatcher(internal::IsNanMatcher());
3650
+ }
3651
+
3652
+ // Creates a matcher that matches any double argument approximately
3653
+ // equal to rhs, where two NANs are considered unequal.
3654
+ inline internal::FloatingEqMatcher<double> DoubleEq(double rhs) {
3655
+ return internal::FloatingEqMatcher<double>(rhs, false);
3656
+ }
3657
+
3658
+ // Creates a matcher that matches any double argument approximately
3659
+ // equal to rhs, including NaN values when rhs is NaN.
3660
+ inline internal::FloatingEqMatcher<double> NanSensitiveDoubleEq(double rhs) {
3661
+ return internal::FloatingEqMatcher<double>(rhs, true);
3662
+ }
3663
+
3664
+ // Creates a matcher that matches any double argument approximately equal to
3665
+ // rhs, up to the specified max absolute error bound, where two NANs are
3666
+ // considered unequal. The max absolute error bound must be non-negative.
3667
+ inline internal::FloatingEqMatcher<double> DoubleNear(
3668
+ double rhs, double max_abs_error) {
3669
+ return internal::FloatingEqMatcher<double>(rhs, false, max_abs_error);
3670
+ }
3671
+
3672
+ // Creates a matcher that matches any double argument approximately equal to
3673
+ // rhs, up to the specified max absolute error bound, including NaN values when
3674
+ // rhs is NaN. The max absolute error bound must be non-negative.
3675
+ inline internal::FloatingEqMatcher<double> NanSensitiveDoubleNear(
3676
+ double rhs, double max_abs_error) {
3677
+ return internal::FloatingEqMatcher<double>(rhs, true, max_abs_error);
3678
+ }
3679
+
3680
+ // Creates a matcher that matches any float argument approximately
3681
+ // equal to rhs, where two NANs are considered unequal.
3682
+ inline internal::FloatingEqMatcher<float> FloatEq(float rhs) {
3683
+ return internal::FloatingEqMatcher<float>(rhs, false);
3684
+ }
3685
+
3686
+ // Creates a matcher that matches any float argument approximately
3687
+ // equal to rhs, including NaN values when rhs is NaN.
3688
+ inline internal::FloatingEqMatcher<float> NanSensitiveFloatEq(float rhs) {
3689
+ return internal::FloatingEqMatcher<float>(rhs, true);
3690
+ }
3691
+
3692
+ // Creates a matcher that matches any float argument approximately equal to
3693
+ // rhs, up to the specified max absolute error bound, where two NANs are
3694
+ // considered unequal. The max absolute error bound must be non-negative.
3695
+ inline internal::FloatingEqMatcher<float> FloatNear(
3696
+ float rhs, float max_abs_error) {
3697
+ return internal::FloatingEqMatcher<float>(rhs, false, max_abs_error);
3698
+ }
3699
+
3700
+ // Creates a matcher that matches any float argument approximately equal to
3701
+ // rhs, up to the specified max absolute error bound, including NaN values when
3702
+ // rhs is NaN. The max absolute error bound must be non-negative.
3703
+ inline internal::FloatingEqMatcher<float> NanSensitiveFloatNear(
3704
+ float rhs, float max_abs_error) {
3705
+ return internal::FloatingEqMatcher<float>(rhs, true, max_abs_error);
3706
+ }
3707
+
3708
+ // Creates a matcher that matches a pointer (raw or smart) that points
3709
+ // to a value that matches inner_matcher.
3710
+ template <typename InnerMatcher>
3711
+ inline internal::PointeeMatcher<InnerMatcher> Pointee(
3712
+ const InnerMatcher& inner_matcher) {
3713
+ return internal::PointeeMatcher<InnerMatcher>(inner_matcher);
3714
+ }
3715
+
3716
+ #if GTEST_HAS_RTTI
3717
+ // Creates a matcher that matches a pointer or reference that matches
3718
+ // inner_matcher when dynamic_cast<To> is applied.
3719
+ // The result of dynamic_cast<To> is forwarded to the inner matcher.
3720
+ // If To is a pointer and the cast fails, the inner matcher will receive NULL.
3721
+ // If To is a reference and the cast fails, this matcher returns false
3722
+ // immediately.
3723
+ template <typename To>
3724
+ inline PolymorphicMatcher<internal::WhenDynamicCastToMatcher<To> >
3725
+ WhenDynamicCastTo(const Matcher<To>& inner_matcher) {
3726
+ return MakePolymorphicMatcher(
3727
+ internal::WhenDynamicCastToMatcher<To>(inner_matcher));
3728
+ }
3729
+ #endif // GTEST_HAS_RTTI
3730
+
3731
+ // Creates a matcher that matches an object whose given field matches
3732
+ // 'matcher'. For example,
3733
+ // Field(&Foo::number, Ge(5))
3734
+ // matches a Foo object x if and only if x.number >= 5.
3735
+ template <typename Class, typename FieldType, typename FieldMatcher>
3736
+ inline PolymorphicMatcher<
3737
+ internal::FieldMatcher<Class, FieldType> > Field(
3738
+ FieldType Class::*field, const FieldMatcher& matcher) {
3739
+ return MakePolymorphicMatcher(
3740
+ internal::FieldMatcher<Class, FieldType>(
3741
+ field, MatcherCast<const FieldType&>(matcher)));
3742
+ // The call to MatcherCast() is required for supporting inner
3743
+ // matchers of compatible types. For example, it allows
3744
+ // Field(&Foo::bar, m)
3745
+ // to compile where bar is an int32 and m is a matcher for int64.
3746
+ }
3747
+
3748
+ // Same as Field() but also takes the name of the field to provide better error
3749
+ // messages.
3750
+ template <typename Class, typename FieldType, typename FieldMatcher>
3751
+ inline PolymorphicMatcher<internal::FieldMatcher<Class, FieldType> > Field(
3752
+ const std::string& field_name, FieldType Class::*field,
3753
+ const FieldMatcher& matcher) {
3754
+ return MakePolymorphicMatcher(internal::FieldMatcher<Class, FieldType>(
3755
+ field_name, field, MatcherCast<const FieldType&>(matcher)));
3756
+ }
3757
+
3758
+ // Creates a matcher that matches an object whose given property
3759
+ // matches 'matcher'. For example,
3760
+ // Property(&Foo::str, StartsWith("hi"))
3761
+ // matches a Foo object x if and only if x.str() starts with "hi".
3762
+ template <typename Class, typename PropertyType, typename PropertyMatcher>
3763
+ inline PolymorphicMatcher<internal::PropertyMatcher<
3764
+ Class, PropertyType, PropertyType (Class::*)() const> >
3765
+ Property(PropertyType (Class::*property)() const,
3766
+ const PropertyMatcher& matcher) {
3767
+ return MakePolymorphicMatcher(
3768
+ internal::PropertyMatcher<Class, PropertyType,
3769
+ PropertyType (Class::*)() const>(
3770
+ property, MatcherCast<const PropertyType&>(matcher)));
3771
+ // The call to MatcherCast() is required for supporting inner
3772
+ // matchers of compatible types. For example, it allows
3773
+ // Property(&Foo::bar, m)
3774
+ // to compile where bar() returns an int32 and m is a matcher for int64.
3775
+ }
3776
+
3777
+ // Same as Property() above, but also takes the name of the property to provide
3778
+ // better error messages.
3779
+ template <typename Class, typename PropertyType, typename PropertyMatcher>
3780
+ inline PolymorphicMatcher<internal::PropertyMatcher<
3781
+ Class, PropertyType, PropertyType (Class::*)() const> >
3782
+ Property(const std::string& property_name,
3783
+ PropertyType (Class::*property)() const,
3784
+ const PropertyMatcher& matcher) {
3785
+ return MakePolymorphicMatcher(
3786
+ internal::PropertyMatcher<Class, PropertyType,
3787
+ PropertyType (Class::*)() const>(
3788
+ property_name, property, MatcherCast<const PropertyType&>(matcher)));
3789
+ }
3790
+
3791
+ // The same as above but for reference-qualified member functions.
3792
+ template <typename Class, typename PropertyType, typename PropertyMatcher>
3793
+ inline PolymorphicMatcher<internal::PropertyMatcher<
3794
+ Class, PropertyType, PropertyType (Class::*)() const &> >
3795
+ Property(PropertyType (Class::*property)() const &,
3796
+ const PropertyMatcher& matcher) {
3797
+ return MakePolymorphicMatcher(
3798
+ internal::PropertyMatcher<Class, PropertyType,
3799
+ PropertyType (Class::*)() const&>(
3800
+ property, MatcherCast<const PropertyType&>(matcher)));
3801
+ }
3802
+
3803
+ // Three-argument form for reference-qualified member functions.
3804
+ template <typename Class, typename PropertyType, typename PropertyMatcher>
3805
+ inline PolymorphicMatcher<internal::PropertyMatcher<
3806
+ Class, PropertyType, PropertyType (Class::*)() const &> >
3807
+ Property(const std::string& property_name,
3808
+ PropertyType (Class::*property)() const &,
3809
+ const PropertyMatcher& matcher) {
3810
+ return MakePolymorphicMatcher(
3811
+ internal::PropertyMatcher<Class, PropertyType,
3812
+ PropertyType (Class::*)() const&>(
3813
+ property_name, property, MatcherCast<const PropertyType&>(matcher)));
3814
+ }
3815
+
3816
+ // Creates a matcher that matches an object if and only if the result of
3817
+ // applying a callable to x matches 'matcher'. For example,
3818
+ // ResultOf(f, StartsWith("hi"))
3819
+ // matches a Foo object x if and only if f(x) starts with "hi".
3820
+ // `callable` parameter can be a function, function pointer, or a functor. It is
3821
+ // required to keep no state affecting the results of the calls on it and make
3822
+ // no assumptions about how many calls will be made. Any state it keeps must be
3823
+ // protected from the concurrent access.
3824
+ template <typename Callable, typename InnerMatcher>
3825
+ internal::ResultOfMatcher<Callable, InnerMatcher> ResultOf(
3826
+ Callable callable, InnerMatcher matcher) {
3827
+ return internal::ResultOfMatcher<Callable, InnerMatcher>(
3828
+ std::move(callable), std::move(matcher));
3829
+ }
3830
+
3831
+ // String matchers.
3832
+
3833
+ // Matches a string equal to str.
3834
+ inline PolymorphicMatcher<internal::StrEqualityMatcher<std::string> > StrEq(
3835
+ const std::string& str) {
3836
+ return MakePolymorphicMatcher(
3837
+ internal::StrEqualityMatcher<std::string>(str, true, true));
3838
+ }
3839
+
3840
+ // Matches a string not equal to str.
3841
+ inline PolymorphicMatcher<internal::StrEqualityMatcher<std::string> > StrNe(
3842
+ const std::string& str) {
3843
+ return MakePolymorphicMatcher(
3844
+ internal::StrEqualityMatcher<std::string>(str, false, true));
3845
+ }
3846
+
3847
+ // Matches a string equal to str, ignoring case.
3848
+ inline PolymorphicMatcher<internal::StrEqualityMatcher<std::string> > StrCaseEq(
3849
+ const std::string& str) {
3850
+ return MakePolymorphicMatcher(
3851
+ internal::StrEqualityMatcher<std::string>(str, true, false));
3852
+ }
3853
+
3854
+ // Matches a string not equal to str, ignoring case.
3855
+ inline PolymorphicMatcher<internal::StrEqualityMatcher<std::string> > StrCaseNe(
3856
+ const std::string& str) {
3857
+ return MakePolymorphicMatcher(
3858
+ internal::StrEqualityMatcher<std::string>(str, false, false));
3859
+ }
3860
+
3861
+ // Creates a matcher that matches any string, std::string, or C string
3862
+ // that contains the given substring.
3863
+ inline PolymorphicMatcher<internal::HasSubstrMatcher<std::string> > HasSubstr(
3864
+ const std::string& substring) {
3865
+ return MakePolymorphicMatcher(
3866
+ internal::HasSubstrMatcher<std::string>(substring));
3867
+ }
3868
+
3869
+ // Matches a string that starts with 'prefix' (case-sensitive).
3870
+ inline PolymorphicMatcher<internal::StartsWithMatcher<std::string> > StartsWith(
3871
+ const std::string& prefix) {
3872
+ return MakePolymorphicMatcher(
3873
+ internal::StartsWithMatcher<std::string>(prefix));
3874
+ }
3875
+
3876
+ // Matches a string that ends with 'suffix' (case-sensitive).
3877
+ inline PolymorphicMatcher<internal::EndsWithMatcher<std::string> > EndsWith(
3878
+ const std::string& suffix) {
3879
+ return MakePolymorphicMatcher(internal::EndsWithMatcher<std::string>(suffix));
3880
+ }
3881
+
3882
+ #if GTEST_HAS_STD_WSTRING
3883
+ // Wide string matchers.
3884
+
3885
+ // Matches a string equal to str.
3886
+ inline PolymorphicMatcher<internal::StrEqualityMatcher<std::wstring> > StrEq(
3887
+ const std::wstring& str) {
3888
+ return MakePolymorphicMatcher(
3889
+ internal::StrEqualityMatcher<std::wstring>(str, true, true));
3890
+ }
3891
+
3892
+ // Matches a string not equal to str.
3893
+ inline PolymorphicMatcher<internal::StrEqualityMatcher<std::wstring> > StrNe(
3894
+ const std::wstring& str) {
3895
+ return MakePolymorphicMatcher(
3896
+ internal::StrEqualityMatcher<std::wstring>(str, false, true));
3897
+ }
3898
+
3899
+ // Matches a string equal to str, ignoring case.
3900
+ inline PolymorphicMatcher<internal::StrEqualityMatcher<std::wstring> >
3901
+ StrCaseEq(const std::wstring& str) {
3902
+ return MakePolymorphicMatcher(
3903
+ internal::StrEqualityMatcher<std::wstring>(str, true, false));
3904
+ }
3905
+
3906
+ // Matches a string not equal to str, ignoring case.
3907
+ inline PolymorphicMatcher<internal::StrEqualityMatcher<std::wstring> >
3908
+ StrCaseNe(const std::wstring& str) {
3909
+ return MakePolymorphicMatcher(
3910
+ internal::StrEqualityMatcher<std::wstring>(str, false, false));
3911
+ }
3912
+
3913
+ // Creates a matcher that matches any ::wstring, std::wstring, or C wide string
3914
+ // that contains the given substring.
3915
+ inline PolymorphicMatcher<internal::HasSubstrMatcher<std::wstring> > HasSubstr(
3916
+ const std::wstring& substring) {
3917
+ return MakePolymorphicMatcher(
3918
+ internal::HasSubstrMatcher<std::wstring>(substring));
3919
+ }
3920
+
3921
+ // Matches a string that starts with 'prefix' (case-sensitive).
3922
+ inline PolymorphicMatcher<internal::StartsWithMatcher<std::wstring> >
3923
+ StartsWith(const std::wstring& prefix) {
3924
+ return MakePolymorphicMatcher(
3925
+ internal::StartsWithMatcher<std::wstring>(prefix));
3926
+ }
3927
+
3928
+ // Matches a string that ends with 'suffix' (case-sensitive).
3929
+ inline PolymorphicMatcher<internal::EndsWithMatcher<std::wstring> > EndsWith(
3930
+ const std::wstring& suffix) {
3931
+ return MakePolymorphicMatcher(
3932
+ internal::EndsWithMatcher<std::wstring>(suffix));
3933
+ }
3934
+
3935
+ #endif // GTEST_HAS_STD_WSTRING
3936
+
3937
+ // Creates a polymorphic matcher that matches a 2-tuple where the
3938
+ // first field == the second field.
3939
+ inline internal::Eq2Matcher Eq() { return internal::Eq2Matcher(); }
3940
+
3941
+ // Creates a polymorphic matcher that matches a 2-tuple where the
3942
+ // first field >= the second field.
3943
+ inline internal::Ge2Matcher Ge() { return internal::Ge2Matcher(); }
3944
+
3945
+ // Creates a polymorphic matcher that matches a 2-tuple where the
3946
+ // first field > the second field.
3947
+ inline internal::Gt2Matcher Gt() { return internal::Gt2Matcher(); }
3948
+
3949
+ // Creates a polymorphic matcher that matches a 2-tuple where the
3950
+ // first field <= the second field.
3951
+ inline internal::Le2Matcher Le() { return internal::Le2Matcher(); }
3952
+
3953
+ // Creates a polymorphic matcher that matches a 2-tuple where the
3954
+ // first field < the second field.
3955
+ inline internal::Lt2Matcher Lt() { return internal::Lt2Matcher(); }
3956
+
3957
+ // Creates a polymorphic matcher that matches a 2-tuple where the
3958
+ // first field != the second field.
3959
+ inline internal::Ne2Matcher Ne() { return internal::Ne2Matcher(); }
3960
+
3961
+ // Creates a polymorphic matcher that matches a 2-tuple where
3962
+ // FloatEq(first field) matches the second field.
3963
+ inline internal::FloatingEq2Matcher<float> FloatEq() {
3964
+ return internal::FloatingEq2Matcher<float>();
3965
+ }
3966
+
3967
+ // Creates a polymorphic matcher that matches a 2-tuple where
3968
+ // DoubleEq(first field) matches the second field.
3969
+ inline internal::FloatingEq2Matcher<double> DoubleEq() {
3970
+ return internal::FloatingEq2Matcher<double>();
3971
+ }
3972
+
3973
+ // Creates a polymorphic matcher that matches a 2-tuple where
3974
+ // FloatEq(first field) matches the second field with NaN equality.
3975
+ inline internal::FloatingEq2Matcher<float> NanSensitiveFloatEq() {
3976
+ return internal::FloatingEq2Matcher<float>(true);
3977
+ }
3978
+
3979
+ // Creates a polymorphic matcher that matches a 2-tuple where
3980
+ // DoubleEq(first field) matches the second field with NaN equality.
3981
+ inline internal::FloatingEq2Matcher<double> NanSensitiveDoubleEq() {
3982
+ return internal::FloatingEq2Matcher<double>(true);
3983
+ }
3984
+
3985
+ // Creates a polymorphic matcher that matches a 2-tuple where
3986
+ // FloatNear(first field, max_abs_error) matches the second field.
3987
+ inline internal::FloatingEq2Matcher<float> FloatNear(float max_abs_error) {
3988
+ return internal::FloatingEq2Matcher<float>(max_abs_error);
3989
+ }
3990
+
3991
+ // Creates a polymorphic matcher that matches a 2-tuple where
3992
+ // DoubleNear(first field, max_abs_error) matches the second field.
3993
+ inline internal::FloatingEq2Matcher<double> DoubleNear(double max_abs_error) {
3994
+ return internal::FloatingEq2Matcher<double>(max_abs_error);
3995
+ }
3996
+
3997
+ // Creates a polymorphic matcher that matches a 2-tuple where
3998
+ // FloatNear(first field, max_abs_error) matches the second field with NaN
3999
+ // equality.
4000
+ inline internal::FloatingEq2Matcher<float> NanSensitiveFloatNear(
4001
+ float max_abs_error) {
4002
+ return internal::FloatingEq2Matcher<float>(max_abs_error, true);
4003
+ }
4004
+
4005
+ // Creates a polymorphic matcher that matches a 2-tuple where
4006
+ // DoubleNear(first field, max_abs_error) matches the second field with NaN
4007
+ // equality.
4008
+ inline internal::FloatingEq2Matcher<double> NanSensitiveDoubleNear(
4009
+ double max_abs_error) {
4010
+ return internal::FloatingEq2Matcher<double>(max_abs_error, true);
4011
+ }
4012
+
4013
+ // Creates a matcher that matches any value of type T that m doesn't
4014
+ // match.
4015
+ template <typename InnerMatcher>
4016
+ inline internal::NotMatcher<InnerMatcher> Not(InnerMatcher m) {
4017
+ return internal::NotMatcher<InnerMatcher>(m);
4018
+ }
4019
+
4020
+ // Returns a matcher that matches anything that satisfies the given
4021
+ // predicate. The predicate can be any unary function or functor
4022
+ // whose return type can be implicitly converted to bool.
4023
+ template <typename Predicate>
4024
+ inline PolymorphicMatcher<internal::TrulyMatcher<Predicate> >
4025
+ Truly(Predicate pred) {
4026
+ return MakePolymorphicMatcher(internal::TrulyMatcher<Predicate>(pred));
4027
+ }
4028
+
4029
+ // Returns a matcher that matches the container size. The container must
4030
+ // support both size() and size_type which all STL-like containers provide.
4031
+ // Note that the parameter 'size' can be a value of type size_type as well as
4032
+ // matcher. For instance:
4033
+ // EXPECT_THAT(container, SizeIs(2)); // Checks container has 2 elements.
4034
+ // EXPECT_THAT(container, SizeIs(Le(2)); // Checks container has at most 2.
4035
+ template <typename SizeMatcher>
4036
+ inline internal::SizeIsMatcher<SizeMatcher>
4037
+ SizeIs(const SizeMatcher& size_matcher) {
4038
+ return internal::SizeIsMatcher<SizeMatcher>(size_matcher);
4039
+ }
4040
+
4041
+ // Returns a matcher that matches the distance between the container's begin()
4042
+ // iterator and its end() iterator, i.e. the size of the container. This matcher
4043
+ // can be used instead of SizeIs with containers such as std::forward_list which
4044
+ // do not implement size(). The container must provide const_iterator (with
4045
+ // valid iterator_traits), begin() and end().
4046
+ template <typename DistanceMatcher>
4047
+ inline internal::BeginEndDistanceIsMatcher<DistanceMatcher>
4048
+ BeginEndDistanceIs(const DistanceMatcher& distance_matcher) {
4049
+ return internal::BeginEndDistanceIsMatcher<DistanceMatcher>(distance_matcher);
4050
+ }
4051
+
4052
+ // Returns a matcher that matches an equal container.
4053
+ // This matcher behaves like Eq(), but in the event of mismatch lists the
4054
+ // values that are included in one container but not the other. (Duplicate
4055
+ // values and order differences are not explained.)
4056
+ template <typename Container>
4057
+ inline PolymorphicMatcher<internal::ContainerEqMatcher<
4058
+ typename std::remove_const<Container>::type>>
4059
+ ContainerEq(const Container& rhs) {
4060
+ // This following line is for working around a bug in MSVC 8.0,
4061
+ // which causes Container to be a const type sometimes.
4062
+ typedef typename std::remove_const<Container>::type RawContainer;
4063
+ return MakePolymorphicMatcher(
4064
+ internal::ContainerEqMatcher<RawContainer>(rhs));
4065
+ }
4066
+
4067
+ // Returns a matcher that matches a container that, when sorted using
4068
+ // the given comparator, matches container_matcher.
4069
+ template <typename Comparator, typename ContainerMatcher>
4070
+ inline internal::WhenSortedByMatcher<Comparator, ContainerMatcher>
4071
+ WhenSortedBy(const Comparator& comparator,
4072
+ const ContainerMatcher& container_matcher) {
4073
+ return internal::WhenSortedByMatcher<Comparator, ContainerMatcher>(
4074
+ comparator, container_matcher);
4075
+ }
4076
+
4077
+ // Returns a matcher that matches a container that, when sorted using
4078
+ // the < operator, matches container_matcher.
4079
+ template <typename ContainerMatcher>
4080
+ inline internal::WhenSortedByMatcher<internal::LessComparator, ContainerMatcher>
4081
+ WhenSorted(const ContainerMatcher& container_matcher) {
4082
+ return
4083
+ internal::WhenSortedByMatcher<internal::LessComparator, ContainerMatcher>(
4084
+ internal::LessComparator(), container_matcher);
4085
+ }
4086
+
4087
+ // Matches an STL-style container or a native array that contains the
4088
+ // same number of elements as in rhs, where its i-th element and rhs's
4089
+ // i-th element (as a pair) satisfy the given pair matcher, for all i.
4090
+ // TupleMatcher must be able to be safely cast to Matcher<std::tuple<const
4091
+ // T1&, const T2&> >, where T1 and T2 are the types of elements in the
4092
+ // LHS container and the RHS container respectively.
4093
+ template <typename TupleMatcher, typename Container>
4094
+ inline internal::PointwiseMatcher<TupleMatcher,
4095
+ typename std::remove_const<Container>::type>
4096
+ Pointwise(const TupleMatcher& tuple_matcher, const Container& rhs) {
4097
+ // This following line is for working around a bug in MSVC 8.0,
4098
+ // which causes Container to be a const type sometimes (e.g. when
4099
+ // rhs is a const int[])..
4100
+ typedef typename std::remove_const<Container>::type RawContainer;
4101
+ return internal::PointwiseMatcher<TupleMatcher, RawContainer>(
4102
+ tuple_matcher, rhs);
4103
+ }
4104
+
4105
+
4106
+ // Supports the Pointwise(m, {a, b, c}) syntax.
4107
+ template <typename TupleMatcher, typename T>
4108
+ inline internal::PointwiseMatcher<TupleMatcher, std::vector<T> > Pointwise(
4109
+ const TupleMatcher& tuple_matcher, std::initializer_list<T> rhs) {
4110
+ return Pointwise(tuple_matcher, std::vector<T>(rhs));
4111
+ }
4112
+
4113
+
4114
+ // UnorderedPointwise(pair_matcher, rhs) matches an STL-style
4115
+ // container or a native array that contains the same number of
4116
+ // elements as in rhs, where in some permutation of the container, its
4117
+ // i-th element and rhs's i-th element (as a pair) satisfy the given
4118
+ // pair matcher, for all i. Tuple2Matcher must be able to be safely
4119
+ // cast to Matcher<std::tuple<const T1&, const T2&> >, where T1 and T2 are
4120
+ // the types of elements in the LHS container and the RHS container
4121
+ // respectively.
4122
+ //
4123
+ // This is like Pointwise(pair_matcher, rhs), except that the element
4124
+ // order doesn't matter.
4125
+ template <typename Tuple2Matcher, typename RhsContainer>
4126
+ inline internal::UnorderedElementsAreArrayMatcher<
4127
+ typename internal::BoundSecondMatcher<
4128
+ Tuple2Matcher,
4129
+ typename internal::StlContainerView<
4130
+ typename std::remove_const<RhsContainer>::type>::type::value_type>>
4131
+ UnorderedPointwise(const Tuple2Matcher& tuple2_matcher,
4132
+ const RhsContainer& rhs_container) {
4133
+ // This following line is for working around a bug in MSVC 8.0,
4134
+ // which causes RhsContainer to be a const type sometimes (e.g. when
4135
+ // rhs_container is a const int[]).
4136
+ typedef typename std::remove_const<RhsContainer>::type RawRhsContainer;
4137
+
4138
+ // RhsView allows the same code to handle RhsContainer being a
4139
+ // STL-style container and it being a native C-style array.
4140
+ typedef typename internal::StlContainerView<RawRhsContainer> RhsView;
4141
+ typedef typename RhsView::type RhsStlContainer;
4142
+ typedef typename RhsStlContainer::value_type Second;
4143
+ const RhsStlContainer& rhs_stl_container =
4144
+ RhsView::ConstReference(rhs_container);
4145
+
4146
+ // Create a matcher for each element in rhs_container.
4147
+ ::std::vector<internal::BoundSecondMatcher<Tuple2Matcher, Second> > matchers;
4148
+ for (typename RhsStlContainer::const_iterator it = rhs_stl_container.begin();
4149
+ it != rhs_stl_container.end(); ++it) {
4150
+ matchers.push_back(
4151
+ internal::MatcherBindSecond(tuple2_matcher, *it));
4152
+ }
4153
+
4154
+ // Delegate the work to UnorderedElementsAreArray().
4155
+ return UnorderedElementsAreArray(matchers);
4156
+ }
4157
+
4158
+
4159
+ // Supports the UnorderedPointwise(m, {a, b, c}) syntax.
4160
+ template <typename Tuple2Matcher, typename T>
4161
+ inline internal::UnorderedElementsAreArrayMatcher<
4162
+ typename internal::BoundSecondMatcher<Tuple2Matcher, T> >
4163
+ UnorderedPointwise(const Tuple2Matcher& tuple2_matcher,
4164
+ std::initializer_list<T> rhs) {
4165
+ return UnorderedPointwise(tuple2_matcher, std::vector<T>(rhs));
4166
+ }
4167
+
4168
+
4169
+ // Matches an STL-style container or a native array that contains at
4170
+ // least one element matching the given value or matcher.
4171
+ //
4172
+ // Examples:
4173
+ // ::std::set<int> page_ids;
4174
+ // page_ids.insert(3);
4175
+ // page_ids.insert(1);
4176
+ // EXPECT_THAT(page_ids, Contains(1));
4177
+ // EXPECT_THAT(page_ids, Contains(Gt(2)));
4178
+ // EXPECT_THAT(page_ids, Not(Contains(4)));
4179
+ //
4180
+ // ::std::map<int, size_t> page_lengths;
4181
+ // page_lengths[1] = 100;
4182
+ // EXPECT_THAT(page_lengths,
4183
+ // Contains(::std::pair<const int, size_t>(1, 100)));
4184
+ //
4185
+ // const char* user_ids[] = { "joe", "mike", "tom" };
4186
+ // EXPECT_THAT(user_ids, Contains(Eq(::std::string("tom"))));
4187
+ template <typename M>
4188
+ inline internal::ContainsMatcher<M> Contains(M matcher) {
4189
+ return internal::ContainsMatcher<M>(matcher);
4190
+ }
4191
+
4192
+ // IsSupersetOf(iterator_first, iterator_last)
4193
+ // IsSupersetOf(pointer, count)
4194
+ // IsSupersetOf(array)
4195
+ // IsSupersetOf(container)
4196
+ // IsSupersetOf({e1, e2, ..., en})
4197
+ //
4198
+ // IsSupersetOf() verifies that a surjective partial mapping onto a collection
4199
+ // of matchers exists. In other words, a container matches
4200
+ // IsSupersetOf({e1, ..., en}) if and only if there is a permutation
4201
+ // {y1, ..., yn} of some of the container's elements where y1 matches e1,
4202
+ // ..., and yn matches en. Obviously, the size of the container must be >= n
4203
+ // in order to have a match. Examples:
4204
+ //
4205
+ // - {1, 2, 3} matches IsSupersetOf({Ge(3), Ne(0)}), as 3 matches Ge(3) and
4206
+ // 1 matches Ne(0).
4207
+ // - {1, 2} doesn't match IsSupersetOf({Eq(1), Lt(2)}), even though 1 matches
4208
+ // both Eq(1) and Lt(2). The reason is that different matchers must be used
4209
+ // for elements in different slots of the container.
4210
+ // - {1, 1, 2} matches IsSupersetOf({Eq(1), Lt(2)}), as (the first) 1 matches
4211
+ // Eq(1) and (the second) 1 matches Lt(2).
4212
+ // - {1, 2, 3} matches IsSupersetOf(Gt(1), Gt(1)), as 2 matches (the first)
4213
+ // Gt(1) and 3 matches (the second) Gt(1).
4214
+ //
4215
+ // The matchers can be specified as an array, a pointer and count, a container,
4216
+ // an initializer list, or an STL iterator range. In each of these cases, the
4217
+ // underlying matchers can be either values or matchers.
4218
+
4219
+ template <typename Iter>
4220
+ inline internal::UnorderedElementsAreArrayMatcher<
4221
+ typename ::std::iterator_traits<Iter>::value_type>
4222
+ IsSupersetOf(Iter first, Iter last) {
4223
+ typedef typename ::std::iterator_traits<Iter>::value_type T;
4224
+ return internal::UnorderedElementsAreArrayMatcher<T>(
4225
+ internal::UnorderedMatcherRequire::Superset, first, last);
4226
+ }
4227
+
4228
+ template <typename T>
4229
+ inline internal::UnorderedElementsAreArrayMatcher<T> IsSupersetOf(
4230
+ const T* pointer, size_t count) {
4231
+ return IsSupersetOf(pointer, pointer + count);
4232
+ }
4233
+
4234
+ template <typename T, size_t N>
4235
+ inline internal::UnorderedElementsAreArrayMatcher<T> IsSupersetOf(
4236
+ const T (&array)[N]) {
4237
+ return IsSupersetOf(array, N);
4238
+ }
4239
+
4240
+ template <typename Container>
4241
+ inline internal::UnorderedElementsAreArrayMatcher<
4242
+ typename Container::value_type>
4243
+ IsSupersetOf(const Container& container) {
4244
+ return IsSupersetOf(container.begin(), container.end());
4245
+ }
4246
+
4247
+ template <typename T>
4248
+ inline internal::UnorderedElementsAreArrayMatcher<T> IsSupersetOf(
4249
+ ::std::initializer_list<T> xs) {
4250
+ return IsSupersetOf(xs.begin(), xs.end());
4251
+ }
4252
+
4253
+ // IsSubsetOf(iterator_first, iterator_last)
4254
+ // IsSubsetOf(pointer, count)
4255
+ // IsSubsetOf(array)
4256
+ // IsSubsetOf(container)
4257
+ // IsSubsetOf({e1, e2, ..., en})
4258
+ //
4259
+ // IsSubsetOf() verifies that an injective mapping onto a collection of matchers
4260
+ // exists. In other words, a container matches IsSubsetOf({e1, ..., en}) if and
4261
+ // only if there is a subset of matchers {m1, ..., mk} which would match the
4262
+ // container using UnorderedElementsAre. Obviously, the size of the container
4263
+ // must be <= n in order to have a match. Examples:
4264
+ //
4265
+ // - {1} matches IsSubsetOf({Gt(0), Lt(0)}), as 1 matches Gt(0).
4266
+ // - {1, -1} matches IsSubsetOf({Lt(0), Gt(0)}), as 1 matches Gt(0) and -1
4267
+ // matches Lt(0).
4268
+ // - {1, 2} doesn't matches IsSubsetOf({Gt(0), Lt(0)}), even though 1 and 2 both
4269
+ // match Gt(0). The reason is that different matchers must be used for
4270
+ // elements in different slots of the container.
4271
+ //
4272
+ // The matchers can be specified as an array, a pointer and count, a container,
4273
+ // an initializer list, or an STL iterator range. In each of these cases, the
4274
+ // underlying matchers can be either values or matchers.
4275
+
4276
+ template <typename Iter>
4277
+ inline internal::UnorderedElementsAreArrayMatcher<
4278
+ typename ::std::iterator_traits<Iter>::value_type>
4279
+ IsSubsetOf(Iter first, Iter last) {
4280
+ typedef typename ::std::iterator_traits<Iter>::value_type T;
4281
+ return internal::UnorderedElementsAreArrayMatcher<T>(
4282
+ internal::UnorderedMatcherRequire::Subset, first, last);
4283
+ }
4284
+
4285
+ template <typename T>
4286
+ inline internal::UnorderedElementsAreArrayMatcher<T> IsSubsetOf(
4287
+ const T* pointer, size_t count) {
4288
+ return IsSubsetOf(pointer, pointer + count);
4289
+ }
4290
+
4291
+ template <typename T, size_t N>
4292
+ inline internal::UnorderedElementsAreArrayMatcher<T> IsSubsetOf(
4293
+ const T (&array)[N]) {
4294
+ return IsSubsetOf(array, N);
4295
+ }
4296
+
4297
+ template <typename Container>
4298
+ inline internal::UnorderedElementsAreArrayMatcher<
4299
+ typename Container::value_type>
4300
+ IsSubsetOf(const Container& container) {
4301
+ return IsSubsetOf(container.begin(), container.end());
4302
+ }
4303
+
4304
+ template <typename T>
4305
+ inline internal::UnorderedElementsAreArrayMatcher<T> IsSubsetOf(
4306
+ ::std::initializer_list<T> xs) {
4307
+ return IsSubsetOf(xs.begin(), xs.end());
4308
+ }
4309
+
4310
+ // Matches an STL-style container or a native array that contains only
4311
+ // elements matching the given value or matcher.
4312
+ //
4313
+ // Each(m) is semantically equivalent to Not(Contains(Not(m))). Only
4314
+ // the messages are different.
4315
+ //
4316
+ // Examples:
4317
+ // ::std::set<int> page_ids;
4318
+ // // Each(m) matches an empty container, regardless of what m is.
4319
+ // EXPECT_THAT(page_ids, Each(Eq(1)));
4320
+ // EXPECT_THAT(page_ids, Each(Eq(77)));
4321
+ //
4322
+ // page_ids.insert(3);
4323
+ // EXPECT_THAT(page_ids, Each(Gt(0)));
4324
+ // EXPECT_THAT(page_ids, Not(Each(Gt(4))));
4325
+ // page_ids.insert(1);
4326
+ // EXPECT_THAT(page_ids, Not(Each(Lt(2))));
4327
+ //
4328
+ // ::std::map<int, size_t> page_lengths;
4329
+ // page_lengths[1] = 100;
4330
+ // page_lengths[2] = 200;
4331
+ // page_lengths[3] = 300;
4332
+ // EXPECT_THAT(page_lengths, Not(Each(Pair(1, 100))));
4333
+ // EXPECT_THAT(page_lengths, Each(Key(Le(3))));
4334
+ //
4335
+ // const char* user_ids[] = { "joe", "mike", "tom" };
4336
+ // EXPECT_THAT(user_ids, Not(Each(Eq(::std::string("tom")))));
4337
+ template <typename M>
4338
+ inline internal::EachMatcher<M> Each(M matcher) {
4339
+ return internal::EachMatcher<M>(matcher);
4340
+ }
4341
+
4342
+ // Key(inner_matcher) matches an std::pair whose 'first' field matches
4343
+ // inner_matcher. For example, Contains(Key(Ge(5))) can be used to match an
4344
+ // std::map that contains at least one element whose key is >= 5.
4345
+ template <typename M>
4346
+ inline internal::KeyMatcher<M> Key(M inner_matcher) {
4347
+ return internal::KeyMatcher<M>(inner_matcher);
4348
+ }
4349
+
4350
+ // Pair(first_matcher, second_matcher) matches a std::pair whose 'first' field
4351
+ // matches first_matcher and whose 'second' field matches second_matcher. For
4352
+ // example, EXPECT_THAT(map_type, ElementsAre(Pair(Ge(5), "foo"))) can be used
4353
+ // to match a std::map<int, string> that contains exactly one element whose key
4354
+ // is >= 5 and whose value equals "foo".
4355
+ template <typename FirstMatcher, typename SecondMatcher>
4356
+ inline internal::PairMatcher<FirstMatcher, SecondMatcher>
4357
+ Pair(FirstMatcher first_matcher, SecondMatcher second_matcher) {
4358
+ return internal::PairMatcher<FirstMatcher, SecondMatcher>(
4359
+ first_matcher, second_matcher);
4360
+ }
4361
+
4362
+ // Returns a predicate that is satisfied by anything that matches the
4363
+ // given matcher.
4364
+ template <typename M>
4365
+ inline internal::MatcherAsPredicate<M> Matches(M matcher) {
4366
+ return internal::MatcherAsPredicate<M>(matcher);
4367
+ }
4368
+
4369
+ // Returns true if and only if the value matches the matcher.
4370
+ template <typename T, typename M>
4371
+ inline bool Value(const T& value, M matcher) {
4372
+ return testing::Matches(matcher)(value);
4373
+ }
4374
+
4375
+ // Matches the value against the given matcher and explains the match
4376
+ // result to listener.
4377
+ template <typename T, typename M>
4378
+ inline bool ExplainMatchResult(
4379
+ M matcher, const T& value, MatchResultListener* listener) {
4380
+ return SafeMatcherCast<const T&>(matcher).MatchAndExplain(value, listener);
4381
+ }
4382
+
4383
+ // Returns a string representation of the given matcher. Useful for description
4384
+ // strings of matchers defined using MATCHER_P* macros that accept matchers as
4385
+ // their arguments. For example:
4386
+ //
4387
+ // MATCHER_P(XAndYThat, matcher,
4388
+ // "X that " + DescribeMatcher<int>(matcher, negation) +
4389
+ // " and Y that " + DescribeMatcher<double>(matcher, negation)) {
4390
+ // return ExplainMatchResult(matcher, arg.x(), result_listener) &&
4391
+ // ExplainMatchResult(matcher, arg.y(), result_listener);
4392
+ // }
4393
+ template <typename T, typename M>
4394
+ std::string DescribeMatcher(const M& matcher, bool negation = false) {
4395
+ ::std::stringstream ss;
4396
+ Matcher<T> monomorphic_matcher = SafeMatcherCast<T>(matcher);
4397
+ if (negation) {
4398
+ monomorphic_matcher.DescribeNegationTo(&ss);
4399
+ } else {
4400
+ monomorphic_matcher.DescribeTo(&ss);
4401
+ }
4402
+ return ss.str();
4403
+ }
4404
+
4405
+ template <typename... Args>
4406
+ internal::ElementsAreMatcher<
4407
+ std::tuple<typename std::decay<const Args&>::type...>>
4408
+ ElementsAre(const Args&... matchers) {
4409
+ return internal::ElementsAreMatcher<
4410
+ std::tuple<typename std::decay<const Args&>::type...>>(
4411
+ std::make_tuple(matchers...));
4412
+ }
4413
+
4414
+ template <typename... Args>
4415
+ internal::UnorderedElementsAreMatcher<
4416
+ std::tuple<typename std::decay<const Args&>::type...>>
4417
+ UnorderedElementsAre(const Args&... matchers) {
4418
+ return internal::UnorderedElementsAreMatcher<
4419
+ std::tuple<typename std::decay<const Args&>::type...>>(
4420
+ std::make_tuple(matchers...));
4421
+ }
4422
+
4423
+ // Define variadic matcher versions.
4424
+ template <typename... Args>
4425
+ internal::AllOfMatcher<typename std::decay<const Args&>::type...> AllOf(
4426
+ const Args&... matchers) {
4427
+ return internal::AllOfMatcher<typename std::decay<const Args&>::type...>(
4428
+ matchers...);
4429
+ }
4430
+
4431
+ template <typename... Args>
4432
+ internal::AnyOfMatcher<typename std::decay<const Args&>::type...> AnyOf(
4433
+ const Args&... matchers) {
4434
+ return internal::AnyOfMatcher<typename std::decay<const Args&>::type...>(
4435
+ matchers...);
4436
+ }
4437
+
4438
+ // AnyOfArray(array)
4439
+ // AnyOfArray(pointer, count)
4440
+ // AnyOfArray(container)
4441
+ // AnyOfArray({ e1, e2, ..., en })
4442
+ // AnyOfArray(iterator_first, iterator_last)
4443
+ //
4444
+ // AnyOfArray() verifies whether a given value matches any member of a
4445
+ // collection of matchers.
4446
+ //
4447
+ // AllOfArray(array)
4448
+ // AllOfArray(pointer, count)
4449
+ // AllOfArray(container)
4450
+ // AllOfArray({ e1, e2, ..., en })
4451
+ // AllOfArray(iterator_first, iterator_last)
4452
+ //
4453
+ // AllOfArray() verifies whether a given value matches all members of a
4454
+ // collection of matchers.
4455
+ //
4456
+ // The matchers can be specified as an array, a pointer and count, a container,
4457
+ // an initializer list, or an STL iterator range. In each of these cases, the
4458
+ // underlying matchers can be either values or matchers.
4459
+
4460
+ template <typename Iter>
4461
+ inline internal::AnyOfArrayMatcher<
4462
+ typename ::std::iterator_traits<Iter>::value_type>
4463
+ AnyOfArray(Iter first, Iter last) {
4464
+ return internal::AnyOfArrayMatcher<
4465
+ typename ::std::iterator_traits<Iter>::value_type>(first, last);
4466
+ }
4467
+
4468
+ template <typename Iter>
4469
+ inline internal::AllOfArrayMatcher<
4470
+ typename ::std::iterator_traits<Iter>::value_type>
4471
+ AllOfArray(Iter first, Iter last) {
4472
+ return internal::AllOfArrayMatcher<
4473
+ typename ::std::iterator_traits<Iter>::value_type>(first, last);
4474
+ }
4475
+
4476
+ template <typename T>
4477
+ inline internal::AnyOfArrayMatcher<T> AnyOfArray(const T* ptr, size_t count) {
4478
+ return AnyOfArray(ptr, ptr + count);
4479
+ }
4480
+
4481
+ template <typename T>
4482
+ inline internal::AllOfArrayMatcher<T> AllOfArray(const T* ptr, size_t count) {
4483
+ return AllOfArray(ptr, ptr + count);
4484
+ }
4485
+
4486
+ template <typename T, size_t N>
4487
+ inline internal::AnyOfArrayMatcher<T> AnyOfArray(const T (&array)[N]) {
4488
+ return AnyOfArray(array, N);
4489
+ }
4490
+
4491
+ template <typename T, size_t N>
4492
+ inline internal::AllOfArrayMatcher<T> AllOfArray(const T (&array)[N]) {
4493
+ return AllOfArray(array, N);
4494
+ }
4495
+
4496
+ template <typename Container>
4497
+ inline internal::AnyOfArrayMatcher<typename Container::value_type> AnyOfArray(
4498
+ const Container& container) {
4499
+ return AnyOfArray(container.begin(), container.end());
4500
+ }
4501
+
4502
+ template <typename Container>
4503
+ inline internal::AllOfArrayMatcher<typename Container::value_type> AllOfArray(
4504
+ const Container& container) {
4505
+ return AllOfArray(container.begin(), container.end());
4506
+ }
4507
+
4508
+ template <typename T>
4509
+ inline internal::AnyOfArrayMatcher<T> AnyOfArray(
4510
+ ::std::initializer_list<T> xs) {
4511
+ return AnyOfArray(xs.begin(), xs.end());
4512
+ }
4513
+
4514
+ template <typename T>
4515
+ inline internal::AllOfArrayMatcher<T> AllOfArray(
4516
+ ::std::initializer_list<T> xs) {
4517
+ return AllOfArray(xs.begin(), xs.end());
4518
+ }
4519
+
4520
+ // Args<N1, N2, ..., Nk>(a_matcher) matches a tuple if the selected
4521
+ // fields of it matches a_matcher. C++ doesn't support default
4522
+ // arguments for function templates, so we have to overload it.
4523
+ template <size_t... k, typename InnerMatcher>
4524
+ internal::ArgsMatcher<typename std::decay<InnerMatcher>::type, k...> Args(
4525
+ InnerMatcher&& matcher) {
4526
+ return internal::ArgsMatcher<typename std::decay<InnerMatcher>::type, k...>(
4527
+ std::forward<InnerMatcher>(matcher));
4528
+ }
4529
+
4530
+ // AllArgs(m) is a synonym of m. This is useful in
4531
+ //
4532
+ // EXPECT_CALL(foo, Bar(_, _)).With(AllArgs(Eq()));
4533
+ //
4534
+ // which is easier to read than
4535
+ //
4536
+ // EXPECT_CALL(foo, Bar(_, _)).With(Eq());
4537
+ template <typename InnerMatcher>
4538
+ inline InnerMatcher AllArgs(const InnerMatcher& matcher) { return matcher; }
4539
+
4540
+ // Returns a matcher that matches the value of an optional<> type variable.
4541
+ // The matcher implementation only uses '!arg' and requires that the optional<>
4542
+ // type has a 'value_type' member type and that '*arg' is of type 'value_type'
4543
+ // and is printable using 'PrintToString'. It is compatible with
4544
+ // std::optional/std::experimental::optional.
4545
+ // Note that to compare an optional type variable against nullopt you should
4546
+ // use Eq(nullopt) and not Optional(Eq(nullopt)). The latter implies that the
4547
+ // optional value contains an optional itself.
4548
+ template <typename ValueMatcher>
4549
+ inline internal::OptionalMatcher<ValueMatcher> Optional(
4550
+ const ValueMatcher& value_matcher) {
4551
+ return internal::OptionalMatcher<ValueMatcher>(value_matcher);
4552
+ }
4553
+
4554
+ // Returns a matcher that matches the value of a absl::any type variable.
4555
+ template <typename T>
4556
+ PolymorphicMatcher<internal::any_cast_matcher::AnyCastMatcher<T> > AnyWith(
4557
+ const Matcher<const T&>& matcher) {
4558
+ return MakePolymorphicMatcher(
4559
+ internal::any_cast_matcher::AnyCastMatcher<T>(matcher));
4560
+ }
4561
+
4562
+ // Returns a matcher that matches the value of a variant<> type variable.
4563
+ // The matcher implementation uses ADL to find the holds_alternative and get
4564
+ // functions.
4565
+ // It is compatible with std::variant.
4566
+ template <typename T>
4567
+ PolymorphicMatcher<internal::variant_matcher::VariantMatcher<T> > VariantWith(
4568
+ const Matcher<const T&>& matcher) {
4569
+ return MakePolymorphicMatcher(
4570
+ internal::variant_matcher::VariantMatcher<T>(matcher));
4571
+ }
4572
+
4573
+ // These macros allow using matchers to check values in Google Test
4574
+ // tests. ASSERT_THAT(value, matcher) and EXPECT_THAT(value, matcher)
4575
+ // succeed if and only if the value matches the matcher. If the assertion
4576
+ // fails, the value and the description of the matcher will be printed.
4577
+ #define ASSERT_THAT(value, matcher) ASSERT_PRED_FORMAT1(\
4578
+ ::testing::internal::MakePredicateFormatterFromMatcher(matcher), value)
4579
+ #define EXPECT_THAT(value, matcher) EXPECT_PRED_FORMAT1(\
4580
+ ::testing::internal::MakePredicateFormatterFromMatcher(matcher), value)
4581
+
4582
+ } // namespace testing
4583
+
4584
+ GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251 5046
4585
+
4586
+ // Include any custom callback matchers added by the local installation.
4587
+ // We must include this header at the end to make sure it can use the
4588
+ // declarations from this file.
4589
+ #include "gmock/internal/custom/gmock-matchers.h"
4590
+
4591
+ #endif // GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_