From 1904f9129609ef62e7b27fd9d271e4ae33ddea8b Mon Sep 17 00:00:00 2001 From: jLynx Date: Wed, 8 Apr 2026 21:49:00 +1200 Subject: [PATCH 1/3] feat: add DSD (Digital Speech Decoder) support with WASM integration - Introduced DSD types and constants in `src/client/worker/dsd/types.ts`. - Implemented lazy loading for the mbelib WASM module in `src/client/worker/mbelib-init.ts`. - Enhanced RX stream handling to include DSD status updates in `src/client/worker/rx-stream.ts`. - Updated worker types to accommodate DSD decoder and audio resampling in `src/client/worker/types.ts`. - Modified Vite configuration to include mbelib WASM files during the build process. --- .gitignore | 3 +- mbelib-wasm/build.sh | 51 + mbelib-wasm/mbelib/.gitignore | 4 + mbelib-wasm/mbelib/.travis.yml | 13 + mbelib-wasm/mbelib/CHANGELOG | 52 + mbelib-wasm/mbelib/CMakeLists.txt | 56 + mbelib-wasm/mbelib/COPYRIGHT | 14 + mbelib-wasm/mbelib/README.md | 28 + mbelib-wasm/mbelib/ambe3600x2400.c | 747 +++ mbelib-wasm/mbelib/ambe3600x2400_const.h | 884 +++ mbelib-wasm/mbelib/ambe3600x2450.c | 682 +++ mbelib-wasm/mbelib/ambe3600x2450_const.h | 971 ++++ mbelib-wasm/mbelib/cmake_uninstall.cmake.in | 23 + mbelib-wasm/mbelib/config.h | 24 + mbelib-wasm/mbelib/debian/changelog | 5 + mbelib-wasm/mbelib/debian/compat | 1 + mbelib-wasm/mbelib/debian/control | 34 + mbelib-wasm/mbelib/debian/copyright | 14 + mbelib-wasm/mbelib/debian/libmbe-dev.install | 4 + mbelib-wasm/mbelib/debian/libmbe1.install | 1 + mbelib-wasm/mbelib/debian/rules | 4 + mbelib-wasm/mbelib/debian/source/format | 1 + mbelib-wasm/mbelib/ecc.c | 172 + mbelib-wasm/mbelib/ecc_const.h | 112 + mbelib-wasm/mbelib/imbe7100x4400.c | 345 ++ mbelib-wasm/mbelib/imbe7200x4400.c | 584 ++ mbelib-wasm/mbelib/imbe7200x4400_const.h | 898 +++ mbelib-wasm/mbelib/libmbe.pc.in | 10 + mbelib-wasm/mbelib/mbelib.c | 500 ++ mbelib-wasm/mbelib/mbelib.h | 113 + mbelib-wasm/mbelib/mbelib_Author.pgp | 30 + mbelib-wasm/mbelib/mbelib_const.h | 371 ++ mbelib-wasm/mbelib/test/CMakeLists.txt | 19 + mbelib-wasm/mbelib/test/gmock/CMakeLists.txt | 45 + .../test/gmock/include/gmock/gmock-actions.h | 1078 ++++ .../gmock/include/gmock/gmock-cardinalities.h | 147 + .../include/gmock/gmock-generated-actions.h | 2415 ++++++++ .../gmock/gmock-generated-actions.h.pump | 821 +++ .../gmock/gmock-generated-function-mockers.h | 991 ++++ .../gmock-generated-function-mockers.h.pump | 265 + .../include/gmock/gmock-generated-matchers.h | 2190 +++++++ .../gmock/gmock-generated-matchers.h.pump | 674 +++ .../gmock/gmock-generated-nice-strict.h | 397 ++ .../gmock/gmock-generated-nice-strict.h.pump | 161 + .../test/gmock/include/gmock/gmock-matchers.h | 3986 +++++++++++++ .../gmock/include/gmock/gmock-more-actions.h | 233 + .../gmock/include/gmock/gmock-more-matchers.h | 58 + .../gmock/include/gmock/gmock-spec-builders.h | 1791 ++++++ .../mbelib/test/gmock/include/gmock/gmock.h | 94 + .../internal/gmock-generated-internal-utils.h | 279 + .../gmock-generated-internal-utils.h.pump | 136 + .../gmock/internal/gmock-internal-utils.h | 498 ++ .../gmock/include/gmock/internal/gmock-port.h | 78 + .../mbelib/test/gmock/src/gmock-all.cc | 47 + .../test/gmock/src/gmock-cardinalities.cc | 156 + .../test/gmock/src/gmock-internal-utils.cc | 174 + .../mbelib/test/gmock/src/gmock-matchers.cc | 498 ++ .../test/gmock/src/gmock-spec-builders.cc | 813 +++ mbelib-wasm/mbelib/test/gmock/src/gmock.cc | 182 + .../mbelib/test/gmock/src/gmock_main.cc | 54 + mbelib-wasm/mbelib/test/gtest/CMakeLists.txt | 69 + .../test/gtest/cmake/internal_utils.cmake | 227 + .../gtest/include/gtest/gtest-death-test.h | 294 + .../test/gtest/include/gtest/gtest-message.h | 250 + .../gtest/include/gtest/gtest-param-test.h | 1421 +++++ .../include/gtest/gtest-param-test.h.pump | 487 ++ .../test/gtest/include/gtest/gtest-printers.h | 855 +++ .../test/gtest/include/gtest/gtest-spi.h | 232 + .../gtest/include/gtest/gtest-test-part.h | 179 + .../gtest/include/gtest/gtest-typed-test.h | 259 + .../mbelib/test/gtest/include/gtest/gtest.h | 2291 ++++++++ .../gtest/include/gtest/gtest_pred_impl.h | 358 ++ .../test/gtest/include/gtest/gtest_prod.h | 58 + .../internal/gtest-death-test-internal.h | 319 + .../include/gtest/internal/gtest-filepath.h | 206 + .../include/gtest/internal/gtest-internal.h | 1158 ++++ .../include/gtest/internal/gtest-linked_ptr.h | 233 + .../internal/gtest-param-util-generated.h | 5143 +++++++++++++++++ .../gtest-param-util-generated.h.pump | 301 + .../include/gtest/internal/gtest-param-util.h | 619 ++ .../gtest/include/gtest/internal/gtest-port.h | 1947 +++++++ .../include/gtest/internal/gtest-string.h | 167 + .../include/gtest/internal/gtest-tuple.h | 1012 ++++ .../include/gtest/internal/gtest-tuple.h.pump | 339 ++ .../include/gtest/internal/gtest-type-util.h | 3331 +++++++++++ .../gtest/internal/gtest-type-util.h.pump | 297 + .../mbelib/test/gtest/src/gtest-all.cc | 48 + .../mbelib/test/gtest/src/gtest-death-test.cc | 1344 +++++ .../mbelib/test/gtest/src/gtest-filepath.cc | 382 ++ .../test/gtest/src/gtest-internal-inl.h | 1218 ++++ .../mbelib/test/gtest/src/gtest-port.cc | 805 +++ .../mbelib/test/gtest/src/gtest-printers.cc | 363 ++ .../mbelib/test/gtest/src/gtest-test-part.cc | 110 + .../mbelib/test/gtest/src/gtest-typed-test.cc | 110 + mbelib-wasm/mbelib/test/gtest/src/gtest.cc | 5015 ++++++++++++++++ .../mbelib/test/gtest/src/gtest_main.cc | 38 + mbelib-wasm/mbelib/test/mbe-test.cpp | 37 + mbelib-wasm/mbelib/test/test.cpp | 7 + mbelib-wasm/wrapper.c | 109 + public/lib/mbelib/mbelib.js | 2 + public/lib/mbelib/mbelib.wasm | Bin 0 -> 101550 bytes src/client/app/connection.ts | 3 +- src/client/app/constants.ts | 1 + src/client/app/dsd.ts | 12 + src/client/app/main.ts | 2 + src/client/app/state.ts | 1 + src/client/dsp-worker.ts | 80 + src/client/env.d.ts | 6 + src/client/index.html | 49 +- src/client/worker/backend.ts | 4 +- src/client/worker/dsd/dsd-decoder.ts | 504 ++ src/client/worker/dsd/dsd-dmr.ts | 221 + src/client/worker/dsd/dsd-dsp.ts | 286 + src/client/worker/dsd/dsd-dstar.ts | 141 + src/client/worker/dsd/dsd-nxdn.ts | 81 + src/client/worker/dsd/dsd-p25.ts | 388 ++ src/client/worker/dsd/ecc/golay.ts | 246 + src/client/worker/dsd/ecc/hamming.ts | 158 + src/client/worker/dsd/ecc/reed-solomon.ts | 316 + src/client/worker/dsd/types.ts | 389 ++ src/client/worker/mbelib-init.ts | 105 + src/client/worker/rx-stream.ts | 5 +- src/client/worker/types.ts | 9 + vite.config.ts | 14 +- 124 files changed, 59684 insertions(+), 8 deletions(-) create mode 100644 mbelib-wasm/build.sh create mode 100644 mbelib-wasm/mbelib/.gitignore create mode 100644 mbelib-wasm/mbelib/.travis.yml create mode 100644 mbelib-wasm/mbelib/CHANGELOG create mode 100644 mbelib-wasm/mbelib/CMakeLists.txt create mode 100644 mbelib-wasm/mbelib/COPYRIGHT create mode 100644 mbelib-wasm/mbelib/README.md create mode 100644 mbelib-wasm/mbelib/ambe3600x2400.c create mode 100644 mbelib-wasm/mbelib/ambe3600x2400_const.h create mode 100644 mbelib-wasm/mbelib/ambe3600x2450.c create mode 100644 mbelib-wasm/mbelib/ambe3600x2450_const.h create mode 100644 mbelib-wasm/mbelib/cmake_uninstall.cmake.in create mode 100644 mbelib-wasm/mbelib/config.h create mode 100644 mbelib-wasm/mbelib/debian/changelog create mode 100644 mbelib-wasm/mbelib/debian/compat create mode 100644 mbelib-wasm/mbelib/debian/control create mode 100644 mbelib-wasm/mbelib/debian/copyright create mode 100644 mbelib-wasm/mbelib/debian/libmbe-dev.install create mode 100644 mbelib-wasm/mbelib/debian/libmbe1.install create mode 100644 mbelib-wasm/mbelib/debian/rules create mode 100644 mbelib-wasm/mbelib/debian/source/format create mode 100644 mbelib-wasm/mbelib/ecc.c create mode 100644 mbelib-wasm/mbelib/ecc_const.h create mode 100644 mbelib-wasm/mbelib/imbe7100x4400.c create mode 100644 mbelib-wasm/mbelib/imbe7200x4400.c create mode 100644 mbelib-wasm/mbelib/imbe7200x4400_const.h create mode 100644 mbelib-wasm/mbelib/libmbe.pc.in create mode 100644 mbelib-wasm/mbelib/mbelib.c create mode 100644 mbelib-wasm/mbelib/mbelib.h create mode 100644 mbelib-wasm/mbelib/mbelib_Author.pgp create mode 100644 mbelib-wasm/mbelib/mbelib_const.h create mode 100644 mbelib-wasm/mbelib/test/CMakeLists.txt create mode 100644 mbelib-wasm/mbelib/test/gmock/CMakeLists.txt create mode 100644 mbelib-wasm/mbelib/test/gmock/include/gmock/gmock-actions.h create mode 100644 mbelib-wasm/mbelib/test/gmock/include/gmock/gmock-cardinalities.h create mode 100644 mbelib-wasm/mbelib/test/gmock/include/gmock/gmock-generated-actions.h create mode 100644 mbelib-wasm/mbelib/test/gmock/include/gmock/gmock-generated-actions.h.pump create mode 100644 mbelib-wasm/mbelib/test/gmock/include/gmock/gmock-generated-function-mockers.h create mode 100644 mbelib-wasm/mbelib/test/gmock/include/gmock/gmock-generated-function-mockers.h.pump create mode 100644 mbelib-wasm/mbelib/test/gmock/include/gmock/gmock-generated-matchers.h create mode 100644 mbelib-wasm/mbelib/test/gmock/include/gmock/gmock-generated-matchers.h.pump create mode 100644 mbelib-wasm/mbelib/test/gmock/include/gmock/gmock-generated-nice-strict.h create mode 100644 mbelib-wasm/mbelib/test/gmock/include/gmock/gmock-generated-nice-strict.h.pump create mode 100644 mbelib-wasm/mbelib/test/gmock/include/gmock/gmock-matchers.h create mode 100644 mbelib-wasm/mbelib/test/gmock/include/gmock/gmock-more-actions.h create mode 100644 mbelib-wasm/mbelib/test/gmock/include/gmock/gmock-more-matchers.h create mode 100644 mbelib-wasm/mbelib/test/gmock/include/gmock/gmock-spec-builders.h create mode 100644 mbelib-wasm/mbelib/test/gmock/include/gmock/gmock.h create mode 100644 mbelib-wasm/mbelib/test/gmock/include/gmock/internal/gmock-generated-internal-utils.h create mode 100644 mbelib-wasm/mbelib/test/gmock/include/gmock/internal/gmock-generated-internal-utils.h.pump create mode 100644 mbelib-wasm/mbelib/test/gmock/include/gmock/internal/gmock-internal-utils.h create mode 100644 mbelib-wasm/mbelib/test/gmock/include/gmock/internal/gmock-port.h create mode 100644 mbelib-wasm/mbelib/test/gmock/src/gmock-all.cc create mode 100644 mbelib-wasm/mbelib/test/gmock/src/gmock-cardinalities.cc create mode 100644 mbelib-wasm/mbelib/test/gmock/src/gmock-internal-utils.cc create mode 100644 mbelib-wasm/mbelib/test/gmock/src/gmock-matchers.cc create mode 100644 mbelib-wasm/mbelib/test/gmock/src/gmock-spec-builders.cc create mode 100644 mbelib-wasm/mbelib/test/gmock/src/gmock.cc create mode 100644 mbelib-wasm/mbelib/test/gmock/src/gmock_main.cc create mode 100644 mbelib-wasm/mbelib/test/gtest/CMakeLists.txt create mode 100644 mbelib-wasm/mbelib/test/gtest/cmake/internal_utils.cmake create mode 100644 mbelib-wasm/mbelib/test/gtest/include/gtest/gtest-death-test.h create mode 100644 mbelib-wasm/mbelib/test/gtest/include/gtest/gtest-message.h create mode 100644 mbelib-wasm/mbelib/test/gtest/include/gtest/gtest-param-test.h create mode 100644 mbelib-wasm/mbelib/test/gtest/include/gtest/gtest-param-test.h.pump create mode 100644 mbelib-wasm/mbelib/test/gtest/include/gtest/gtest-printers.h create mode 100644 mbelib-wasm/mbelib/test/gtest/include/gtest/gtest-spi.h create mode 100644 mbelib-wasm/mbelib/test/gtest/include/gtest/gtest-test-part.h create mode 100644 mbelib-wasm/mbelib/test/gtest/include/gtest/gtest-typed-test.h create mode 100644 mbelib-wasm/mbelib/test/gtest/include/gtest/gtest.h create mode 100644 mbelib-wasm/mbelib/test/gtest/include/gtest/gtest_pred_impl.h create mode 100644 mbelib-wasm/mbelib/test/gtest/include/gtest/gtest_prod.h create mode 100644 mbelib-wasm/mbelib/test/gtest/include/gtest/internal/gtest-death-test-internal.h create mode 100644 mbelib-wasm/mbelib/test/gtest/include/gtest/internal/gtest-filepath.h create mode 100644 mbelib-wasm/mbelib/test/gtest/include/gtest/internal/gtest-internal.h create mode 100644 mbelib-wasm/mbelib/test/gtest/include/gtest/internal/gtest-linked_ptr.h create mode 100644 mbelib-wasm/mbelib/test/gtest/include/gtest/internal/gtest-param-util-generated.h create mode 100644 mbelib-wasm/mbelib/test/gtest/include/gtest/internal/gtest-param-util-generated.h.pump create mode 100644 mbelib-wasm/mbelib/test/gtest/include/gtest/internal/gtest-param-util.h create mode 100644 mbelib-wasm/mbelib/test/gtest/include/gtest/internal/gtest-port.h create mode 100644 mbelib-wasm/mbelib/test/gtest/include/gtest/internal/gtest-string.h create mode 100644 mbelib-wasm/mbelib/test/gtest/include/gtest/internal/gtest-tuple.h create mode 100644 mbelib-wasm/mbelib/test/gtest/include/gtest/internal/gtest-tuple.h.pump create mode 100644 mbelib-wasm/mbelib/test/gtest/include/gtest/internal/gtest-type-util.h create mode 100644 mbelib-wasm/mbelib/test/gtest/include/gtest/internal/gtest-type-util.h.pump create mode 100644 mbelib-wasm/mbelib/test/gtest/src/gtest-all.cc create mode 100644 mbelib-wasm/mbelib/test/gtest/src/gtest-death-test.cc create mode 100644 mbelib-wasm/mbelib/test/gtest/src/gtest-filepath.cc create mode 100644 mbelib-wasm/mbelib/test/gtest/src/gtest-internal-inl.h create mode 100644 mbelib-wasm/mbelib/test/gtest/src/gtest-port.cc create mode 100644 mbelib-wasm/mbelib/test/gtest/src/gtest-printers.cc create mode 100644 mbelib-wasm/mbelib/test/gtest/src/gtest-test-part.cc create mode 100644 mbelib-wasm/mbelib/test/gtest/src/gtest-typed-test.cc create mode 100644 mbelib-wasm/mbelib/test/gtest/src/gtest.cc create mode 100644 mbelib-wasm/mbelib/test/gtest/src/gtest_main.cc create mode 100644 mbelib-wasm/mbelib/test/mbe-test.cpp create mode 100644 mbelib-wasm/mbelib/test/test.cpp create mode 100644 mbelib-wasm/wrapper.c create mode 100644 public/lib/mbelib/mbelib.js create mode 100644 public/lib/mbelib/mbelib.wasm create mode 100644 src/client/app/dsd.ts create mode 100644 src/client/worker/dsd/dsd-decoder.ts create mode 100644 src/client/worker/dsd/dsd-dmr.ts create mode 100644 src/client/worker/dsd/dsd-dsp.ts create mode 100644 src/client/worker/dsd/dsd-dstar.ts create mode 100644 src/client/worker/dsd/dsd-nxdn.ts create mode 100644 src/client/worker/dsd/dsd-p25.ts create mode 100644 src/client/worker/dsd/ecc/golay.ts create mode 100644 src/client/worker/dsd/ecc/hamming.ts create mode 100644 src/client/worker/dsd/ecc/reed-solomon.ts create mode 100644 src/client/worker/dsd/types.ts create mode 100644 src/client/worker/mbelib-init.ts diff --git a/.gitignore b/.gitignore index bf71240..662fb54 100644 --- a/.gitignore +++ b/.gitignore @@ -37,4 +37,5 @@ Thumbs.db .cache *.tsbuildinfo *.tgz -.claude \ No newline at end of file +.claude +.emsdk diff --git a/mbelib-wasm/build.sh b/mbelib-wasm/build.sh new file mode 100644 index 0000000..381b621 --- /dev/null +++ b/mbelib-wasm/build.sh @@ -0,0 +1,51 @@ +#!/bin/bash +# Build mbelib as WASM module for BrowSDR DSD decoder. +# +# Prerequisites: Emscripten SDK (emcc) must be in PATH. +# Install: https://emscripten.org/docs/getting_started/downloads.html +# +# Usage: cd mbelib-wasm && bash build.sh +# +# Output: ../public/lib/mbelib/mbelib.js + mbelib.wasm + +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +OUT_DIR="$SCRIPT_DIR/../public/lib/mbelib" +MBELIB_DIR="$SCRIPT_DIR/mbelib" + +# Clone mbelib if not present +if [ ! -d "$MBELIB_DIR" ]; then + echo "Downloading mbelib source..." + curl -sL "https://github.com/szechyjs/mbelib/archive/9a04ed5c78176a9965f3d43f7aa1b1f5330e771f.tar.gz" | tar xz -C "$SCRIPT_DIR" + mv "$SCRIPT_DIR/mbelib-9a04ed5c78176a9965f3d43f7aa1b1f5330e771f" "$MBELIB_DIR" + echo "mbelib source downloaded." +fi + +mkdir -p "$OUT_DIR" + +echo "Building mbelib WASM..." +emcc -O3 \ + -s WASM=1 \ + -s MODULARIZE=1 \ + -s EXPORT_NAME='MbelibModule' \ + -s EXPORTED_FUNCTIONS='["_mbelib_init","_mbelib_reset","_mbelib_decode_ambe","_mbelib_decode_imbe","_mbelib_get_err_str","_mbelib_get_errs","_mbelib_get_errs2","_malloc","_free"]' \ + -s EXPORTED_RUNTIME_METHODS='["ccall","cwrap","getValue","setValue","UTF8ToString","HEAPF32","HEAP8"]' \ + -s ALLOW_MEMORY_GROWTH=1 \ + -s INITIAL_MEMORY=1048576 \ + -s ENVIRONMENT='web,worker' \ + -s FILESYSTEM=0 \ + -s ASSERTIONS=0 \ + -I"$MBELIB_DIR" \ + -o "$OUT_DIR/mbelib.js" \ + "$SCRIPT_DIR/wrapper.c" \ + "$MBELIB_DIR/ambe3600x2400.c" \ + "$MBELIB_DIR/ambe3600x2450.c" \ + "$MBELIB_DIR/ecc.c" \ + "$MBELIB_DIR/imbe7100x4400.c" \ + "$MBELIB_DIR/imbe7200x4400.c" \ + "$MBELIB_DIR/mbelib.c" + +echo "Build complete: $OUT_DIR/mbelib.js + mbelib.wasm" +echo "File sizes:" +ls -lh "$OUT_DIR"/mbelib.* diff --git a/mbelib-wasm/mbelib/.gitignore b/mbelib-wasm/mbelib/.gitignore new file mode 100644 index 0000000..e83ed1c --- /dev/null +++ b/mbelib-wasm/mbelib/.gitignore @@ -0,0 +1,4 @@ +*.[ao] +*.so* +*.dylib +build diff --git a/mbelib-wasm/mbelib/.travis.yml b/mbelib-wasm/mbelib/.travis.yml new file mode 100644 index 0000000..41fccd4 --- /dev/null +++ b/mbelib-wasm/mbelib/.travis.yml @@ -0,0 +1,13 @@ +language: c + +compiler: + - gcc + +before_script: + - mkdir build + - cd build + - cmake .. + +script: + - make + - make test diff --git a/mbelib-wasm/mbelib/CHANGELOG b/mbelib-wasm/mbelib/CHANGELOG new file mode 100644 index 0000000..b8e9d61 --- /dev/null +++ b/mbelib-wasm/mbelib/CHANGELOG @@ -0,0 +1,52 @@ +1.3.0: + Initial DSTAR AMBE support + Fixed random number generator + Several bug fixes and optimizations + +1.2.5 Use CMake: + The cross platform building was getting hard to maintain, + removed Makefile in favor of CMake. + +1.2.4 Fixed bugs: + Makefile cleanup + Readme file improvements + fix golayMatrix + bug in imbe7100x4400 + +1.2.3 Fixed bugs: + Cik array in mbe_decodeAmbe2250Parms was too small + +1.2.2 Fixed bugs: + uninitialized variable in SpectralAmpEnhance() + +1.2.1 New Features: + + Improved unvoiced speech synthesis + + Fixed bugs: + bug in spectralAmpEnhance() + +1.2 New features: + Support for imbe7100x4400 vocoder + Improved audio quality + + Fixed bugs: + error in hamming ecc + +1.1 New features: + new synthesizer functions with floating point output buffer. + original short output buffer function stubs for compatibility. + audio gain and clipping is no longer done during synthesis + except within the compatibility functions. + +1.0.2 Fixed bugs: + fixed several problems in synthesizer causing clicks + reduced error -> repeat thresholds for reduced noise bursts + ambe3600x2250 now correctly handles "Silence" frames + ambe Tone and Erasure frames are now indicated with T and E in errorbars + +1.0.1 Fixed bugs: + cur_mp->repeat was not being copied to prev_mp + logic to check for bad mbe frames was incorrect + +1.0 First release diff --git a/mbelib-wasm/mbelib/CMakeLists.txt b/mbelib-wasm/mbelib/CMakeLists.txt new file mode 100644 index 0000000..82c0c90 --- /dev/null +++ b/mbelib-wasm/mbelib/CMakeLists.txt @@ -0,0 +1,56 @@ +project(mbe) +cmake_minimum_required(VERSION 2.6) + +if(MSVC) + # needed for M_PI macro + add_definitions(-D_USE_MATH_DEFINES) +endif() + +FILE(GLOB SRCS *.c) + +include_directories("${PROJECT_SOURCE_DIR}") + +ADD_LIBRARY(mbe-static STATIC ${SRCS}) +ADD_LIBRARY(mbe-shared SHARED ${SRCS}) +if(NOT WIN32) + TARGET_LINK_LIBRARIES(mbe-static m) + TARGET_LINK_LIBRARIES(mbe-shared m) +endif() + +include(GNUInstallDirs) + +set_target_properties(mbe-static mbe-shared + PROPERTIES + OUTPUT_NAME mbe + VERSION 1.3 + SOVERSION 1 + INSTALL_NAME_DIR ${CMAKE_INSTALL_FULL_LIBDIR} + PUBLIC_HEADER "mbelib.h") + +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/libmbe.pc.in" + "${CMAKE_CURRENT_BINARY_DIR}/libmbe.pc" + @ONLY) + +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libmbe.pc" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") + +install(TARGETS mbe-static mbe-shared + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) + +# uninstall target +configure_file( + "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" + IMMEDIATE @ONLY) + +add_custom_target(uninstall + COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) + +option(DISABLE_TEST "Disable building of test framework." OFF) + +if (NOT DISABLE_TEST) + enable_testing() + add_subdirectory(test) +endif() diff --git a/mbelib-wasm/mbelib/COPYRIGHT b/mbelib-wasm/mbelib/COPYRIGHT new file mode 100644 index 0000000..12be944 --- /dev/null +++ b/mbelib-wasm/mbelib/COPYRIGHT @@ -0,0 +1,14 @@ +Copyright (C) 2010 mbelib Author +GPG Key ID: 0xEA5EFE2C (9E7A 5527 9CDC EBF7 BF1B D772 4F98 E863 EA5E FE2C) + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THIS SOFTWARE. diff --git a/mbelib-wasm/mbelib/README.md b/mbelib-wasm/mbelib/README.md new file mode 100644 index 0000000..db8cf29 --- /dev/null +++ b/mbelib-wasm/mbelib/README.md @@ -0,0 +1,28 @@ +[![Build Status](https://travis-ci.org/szechyjs/mbelib.png?branch=master)](https://travis-ci.org/szechyjs/mbelib) + +PATENT NOTICE + + This source code is provided for educational purposes only. It is + a written description of how certain voice encoding/decoding + algorythims could be implemented. Executable objects compiled or + derived from this package may be covered by one or more patents. + Readers are strongly advised to check for any patent restrictions or + licencing requirements before compiling or using this source code. + +mbelib 1.3.0 + + mbelib supports the 7200x4400 bit/s codec used in P25 Phase 1, + the 7100x4400 bit/s codec used in ProVoice and the "Half Rate" + 3600x2250 bit/s vocoder used in various radio systems. + +Example building instructions on Ubuntu: + + sudo apt-get update + sudo apt-get install git make cmake # Update packages + git clone # Something like: git@github.com:USERNAME/mbelib.git + cd mbelib # Move into source folder + mkdir build # Create build directory + cd build # Move to build directory + cmake .. # Create Makefile for current system + make # Compiles the library + sudo make install # Library is installed into computer diff --git a/mbelib-wasm/mbelib/ambe3600x2400.c b/mbelib-wasm/mbelib/ambe3600x2400.c new file mode 100644 index 0000000..c4ed4c2 --- /dev/null +++ b/mbelib-wasm/mbelib/ambe3600x2400.c @@ -0,0 +1,747 @@ +/* + * Copyright (C) 2010 mbelib Author + * GPG Key ID: 0xEA5EFE2C (9E7A 5527 9CDC EBF7 BF1B D772 4F98 E863 EA5E FE2C) + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include +#include + +#include "mbelib.h" +#include "ambe3600x2400_const.h" + +void +mbe_dumpAmbe2400Data (char *ambe_d) +{ + + int i; + char *ambe; + + ambe = ambe_d; + for (i = 0; i < 49; i++) + { + printf ("%i", *ambe); + ambe++; + } + printf (" "); +} + +void +mbe_dumpAmbe3600x2400Frame (char ambe_fr[4][24]) +{ + + int j; + + // c0 + printf ("ambe_fr c0: "); + for (j = 23; j >= 0; j--) + { + printf ("%i", ambe_fr[0][j]); + } + printf (" "); + // c1 + printf ("ambe_fr c1: "); + for (j = 22; j >= 0; j--) + { + printf ("%i", ambe_fr[1][j]); + } + printf (" "); + // c2 + printf ("ambe_fr c2: "); + for (j = 10; j >= 0; j--) + { + printf ("%i", ambe_fr[2][j]); + } + printf (" "); + // c3 + printf ("ambe_fr c3: "); + for (j = 13; j >= 0; j--) + { + printf ("%i", ambe_fr[3][j]); + } + printf (" "); +} + +int +mbe_eccAmbe3600x2400C0 (char ambe_fr[4][24]) +{ + + int j, errs; + char in[23], out[23]; + + for (j = 0; j < 23; j++) + { + in[j] = ambe_fr[0][j + 1]; + } + errs = mbe_golay2312 (in, out); + // ambe_fr[0][0] should be the C0 golay24 parity bit. + // TODO: actually test that here... + for (j = 0; j < 23; j++) + { + ambe_fr[0][j + 1] = out[j]; + } + + return (errs); +} + +int +mbe_eccAmbe3600x2400Data (char ambe_fr[4][24], char *ambe_d) +{ + + int j, errs; + char *ambe, gin[24], gout[24]; + + ambe = ambe_d; + // just copy C0 + for (j = 23; j > 11; j--) + { + *ambe = ambe_fr[0][j]; + ambe++; + } + + // ecc and copy C1 + for (j = 0; j < 23; j++) + { + gin[j] = ambe_fr[1][j]; + } + errs = mbe_golay2312 (gin, gout); + for (j = 22; j > 10; j--) + { + *ambe = gout[j]; + ambe++; + } + + // just copy C2 + for (j = 10; j >= 0; j--) + { + *ambe = ambe_fr[2][j]; + ambe++; + } + + // just copy C3 + for (j = 13; j >= 0; j--) + { + *ambe = ambe_fr[3][j]; + ambe++; + } + + return (errs); +} + +int +mbe_decodeAmbe2400Parms (char *ambe_d, mbe_parms * cur_mp, mbe_parms * prev_mp) +{ + + int ji, i, j, k, l, L, L9, m, am, ak; + int intkl[57]; + int b0, b1, b2, b3, b4, b5, b6, b7, b8; + float f0, Cik[5][18], flokl[57], deltal[57]; + float Sum42, Sum43, Tl[57], Gm[9], Ri[9], sum, c1, c2; + int silence; + int Ji[5], jl; + float deltaGamma, BigGamma; + float unvc, rconst; + + silence = 0; + +#ifdef AMBE_DEBUG + printf ("\n"); +#endif + + // copy repeat from prev_mp + cur_mp->repeat = prev_mp->repeat; + + // check if frame is tone or other; this matches section 7.2 on the P25 Half rate vocoder annex doc + b0 = 0; + b0 |= ambe_d[0]<<6; + b0 |= ambe_d[1]<<5; + b0 |= ambe_d[2]<<4; + b0 |= ambe_d[3]<<3; + b0 |= ambe_d[4]<<2; + b0 |= ambe_d[5]<<1; + b0 |= ambe_d[48]; + + if ((b0&0x7E) == 0x7E) // frame is tone + { + // find tone index + // Cx# 0000000000001111111111112222222222233333333333333 + // + // IDX 0000000000111111111122222222223333333333444444444 + // idx 0123456789012345678901234567890123456789012345678 + // exm 1111110101001110100000001000000000000000001100000 : t=0111100 + // ex2 1111110110101110100000000000000000000000000000000 : t=1100010 + // ex3 1111110010101110110000001000000000000000000110000 : t=0000110 + // tt1 1111110010011110100000001000000000000000000101000 : t=0000101 + // tt3 1111110010011110000000001000000000000000000101000 + // ton HHHHHHDEF410======......P.................32==... + // vol 765430 21 + //DEF indexes the following tables for tone bits 5-7 + int t7tab[8] = {1,0,0,0,0,1,1,1}; + int t6tab[8] = {0,0,0,1,1,1,1,0}; + int t5tab[8] = {0,0,1,0,1,1,0,1}; + // V V V V V G G G V = verified, G = guessed (and unused by all normal tone indices) + b1 = 0; + b1 |= t7tab[((ambe_d[6]<<2)|(ambe_d[7]<<1)|ambe_d[8])]<<7; //t7 128 + b1 |= t6tab[((ambe_d[6]<<2)|(ambe_d[7]<<1)|ambe_d[8])]<<6; //t6 64 + b1 |= t5tab[((ambe_d[6]<<2)|(ambe_d[7]<<1)|ambe_d[8])]<<5; //t5 32 + b1 |= ambe_d[9]<<4; //t4 16 e verified + b1 |= ambe_d[42]<<3; //t3 8 d verified + b1 |= ambe_d[43]<<2; //t2 4 c verified + b1 |= ambe_d[10]<<1; //t1 2 b verified + b1 |= ambe_d[11]; //t0 1 a verified + + b2 = 0; + b2 |= ambe_d[12]<<7; //v7 128 h verified + b2 |= ambe_d[13]<<6; //v6 64 g verified + b2 |= ambe_d[14]<<5; //v5 32 f verified + b2 |= ambe_d[15]<<4; //v4 16 e guess based on data + b2 |= ambe_d[16]<<3; //v3 8 d guess based on data + b2 |= ambe_d[44]<<2; //v2 4 c guess based on data + b2 |= ambe_d[45]<<1; //v1 2 b guess based on data + b2 |= ambe_d[17]; //v0 1 a guess based on data + // the order of the last 3 bits may really be 17,44,45 not 44,45,17 as above + + fprintf(stderr,"Tone volume: %d; ", b2); + if (b1 < 5) + { + fprintf(stderr, "index: %d, was <5, invalid!\n", b1); + silence = 1; + } + else if ((b1 >= 5) && (b1 <= 122)) + { + fprintf(stderr, "index: %d, Single tone hz: %f\n", b1, (float)b1*31.25); + } + else if ((b1 > 122) && (b1 < 128)) + { + fprintf(stderr, "index: %d, was >122 and <128, invalid!\n", b1); + silence = 1; + } + else if ((b1 >= 128) && (b1 <= 163)) + { + fprintf(stderr, "index: %d, Dual tone\n", b1); + // note: dual tone index is different on ambe(dstar) and ambe2+ + } + else + { + fprintf(stderr, "index: %d, was >163, invalid!\n", b1); + silence = 1; + } + + if(silence == 1) + { +#ifdef AMBE_DEBUG + printf ("Silence Frame\n"); +#endif + cur_mp->w0 = ((float) 2 * M_PI) / (float) 32; + f0 = (float) 1 / (float) 32; + L = 14; + cur_mp->L = 14; + for (l = 1; l <= L; l++) + { + cur_mp->Vl[l] = 0; + } + } +#ifdef AMBE_DEBUG + printf ("Tone Frame\n"); +#endif + return (3); + } + //fprintf(stderr,"Voice Frame, Pitch = %f\n", powf(2, ((float)b0+195.626)/-46.368)*8000); // was 45.368 + //fprintf(stderr,"Voice Frame, rawPitch = %02d, Pitch = %f\n", b0, powf(2, ((-1*(float)(17661/((int)1<<12))) - (2.1336e-2 * ((float)b0+0.5))))*8000); + //fprintf(stderr,"Voice Frame, Pitch = %f, ", powf(2, (-4.311767578125 - (2.1336e-2 * ((float)b0+0.5))))*8000); + + // decode fundamental frequency w0 from b0 is already done + + if (silence == 0) + { + // w0 from specification document + //f0 = AmbeW0table[b0]; + //cur_mp->w0 = f0 * (float) 2 *M_PI; + // w0 from patent filings + //f0 = powf (2, ((float) b0 + (float) 195.626) / -(float) 46.368); // was 45.368 + // w0 guess + f0 = powf(2, (-4.311767578125 - (2.1336e-2 * ((float)b0+0.5)))); + cur_mp->w0 = f0 * (float) 2 *M_PI; + } + + unvc = (float) 0.2046 / sqrtf (cur_mp->w0); + //unvc = (float) 1; + //unvc = (float) 0.2046 / sqrtf (f0); + + // decode L + if (silence == 0) + { + // L from specification document + // lookup L in tabl3 + L = AmbePlusLtable[b0]; + // L formula from patent filings + //L=(int)((float)0.4627 / f0); + cur_mp->L = L; + } + L9 = L - 9; + + // decode V/UV parameters + // load b1 from ambe_d + //TODO: use correct table (i.e. 0x0000 0x0005 0x0050 0x0055 etc) + b1 = 0; + b1 |= ambe_d[38]<<3; + b1 |= ambe_d[39]<<2; + b1 |= ambe_d[40]<<1; + b1 |= ambe_d[41]; + //fprintf(stderr,"V/UV = %d, ", b1); + for (l = 1; l <= L; l++) + { + // jl from specification document + jl = (int) ((float) l * (float) 16.0 * f0); + // jl from patent filings? + //jl = (int)(((float)l * (float)16.0 * f0) + 0.25); + + if (silence == 0) + { + cur_mp->Vl[l] = AmbePlusVuv[b1][jl]; + } +#ifdef AMBE_DEBUG + printf ("jl[%i]:%i Vl[%i]:%i\n", l, jl, l, cur_mp->Vl[l]); +#endif + } +#ifdef AMBE_DEBUG + printf ("\nb0:%i w0:%f L:%i b1:%i\n", b0, cur_mp->w0, L, b1); +#endif + + // decode gain vector + // load b2 from ambe_d + b2 = 0; + b2 |= ambe_d[6]<<5; + b2 |= ambe_d[7]<<4; + b2 |= ambe_d[8]<<3; + b2 |= ambe_d[9]<<2; + b2 |= ambe_d[42]<<1; + b2 |= ambe_d[43]; + //fprintf(stderr,"Gain = %d,\n", b2); + deltaGamma = AmbePlusDg[b2]; + cur_mp->gamma = deltaGamma + ((float) 0.5 * prev_mp->gamma); +#ifdef AMBE_DEBUG + printf ("b2: %i, deltaGamma: %f gamma: %f gamma-1: %f\n", b2, deltaGamma, cur_mp->gamma, prev_mp->gamma); +#endif + + + // decode PRBA vectors + Gm[1] = 0; + + // load b3 from ambe_d + b3 = 0; + b3 |= ambe_d[10]<<8; + b3 |= ambe_d[11]<<7; + b3 |= ambe_d[12]<<6; + b3 |= ambe_d[13]<<5; + b3 |= ambe_d[14]<<4; + b3 |= ambe_d[15]<<3; + b3 |= ambe_d[16]<<2; + b3 |= ambe_d[44]<<1; + b3 |= ambe_d[45]; + Gm[2] = AmbePlusPRBA24[b3][0]; + Gm[3] = AmbePlusPRBA24[b3][1]; + Gm[4] = AmbePlusPRBA24[b3][2]; + + // load b4 from ambe_d + b4 = 0; + b4 |= ambe_d[17]<<6; + b4 |= ambe_d[18]<<5; + b4 |= ambe_d[19]<<4; + b4 |= ambe_d[20]<<3; + b4 |= ambe_d[21]<<2; + b4 |= ambe_d[46]<<1; + b4 |= ambe_d[47]; + Gm[5] = AmbePlusPRBA58[b4][0]; + Gm[6] = AmbePlusPRBA58[b4][1]; + Gm[7] = AmbePlusPRBA58[b4][2]; + Gm[8] = AmbePlusPRBA58[b4][3]; + +#ifdef AMBE_DEBUG + printf ("b3: %i Gm[2]: %f Gm[3]: %f Gm[4]: %f b4: %i Gm[5]: %f Gm[6]: %f Gm[7]: %f Gm[8]: %f\n", b3, Gm[2], Gm[3], Gm[4], b4, Gm[5], Gm[6], Gm[7], Gm[8]); +#endif + + // compute Ri + for (i = 1; i <= 8; i++) + { + sum = 0; + for (m = 1; m <= 8; m++) + { + if (m == 1) + { + am = 1; + } + else + { + am = 2; + } + sum = sum + ((float) am * Gm[m] * cosf ((M_PI * (float) (m - 1) * ((float) i - (float) 0.5)) / (float) 8)); + } + Ri[i] = sum; +#ifdef AMBE_DEBUG + printf ("R%i: %f ", i, Ri[i]); +#endif + } +#ifdef AMBE_DEBUG + printf ("\n"); +#endif + + // generate first to elements of each Ci,k block from PRBA vector + rconst = ((float) 1 / ((float) 2 * M_SQRT2)); + Cik[1][1] = (float) 0.5 *(Ri[1] + Ri[2]); + Cik[1][2] = rconst * (Ri[1] - Ri[2]); + Cik[2][1] = (float) 0.5 *(Ri[3] + Ri[4]); + Cik[2][2] = rconst * (Ri[3] - Ri[4]); + Cik[3][1] = (float) 0.5 *(Ri[5] + Ri[6]); + Cik[3][2] = rconst * (Ri[5] - Ri[6]); + Cik[4][1] = (float) 0.5 *(Ri[7] + Ri[8]); + Cik[4][2] = rconst * (Ri[7] - Ri[8]); + + // decode HOC + + // load b5 from ambe_d + b5 = 0; + b5 |= ambe_d[22]<<3; + b5 |= ambe_d[23]<<2; + b5 |= ambe_d[25]<<1; + b5 |= ambe_d[26]; + + // load b6 from ambe_d + b6 = 0; + b6 |= ambe_d[27]<<3; + b6 |= ambe_d[28]<<2; + b6 |= ambe_d[29]<<1; + b6 |= ambe_d[30]; + + // load b7 from ambe_d + b7 = 0; + b7 |= ambe_d[31]<<3; + b7 |= ambe_d[32]<<2; + b7 |= ambe_d[33]<<1; + b7 |= ambe_d[34]; + + // load b8 from ambe_d + b8 = 0; + b8 |= ambe_d[35]<<3; + b8 |= ambe_d[36]<<2; + b8 |= ambe_d[37]<<1; + //b8 |= 0; // least significant bit of hoc3 unused here, and according to the patent is forced to 0 when not used + + // lookup Ji + Ji[1] = AmbePlusLmprbl[L][0]; + Ji[2] = AmbePlusLmprbl[L][1]; + Ji[3] = AmbePlusLmprbl[L][2]; + Ji[4] = AmbePlusLmprbl[L][3]; +#ifdef AMBE_DEBUG + printf ("Ji[1]: %i Ji[2]: %i Ji[3]: %i Ji[4]: %i\n", Ji[1], Ji[2], Ji[3], Ji[4]); + printf ("b5: %i b6: %i b7: %i b8: %i\n", b5, b6, b7, b8); +#endif + + // Load Ci,k with the values from the HOC tables + // there appear to be a couple typos in eq. 37 so we will just do what makes sense + // (3 <= k <= Ji and k<=6) + for (k = 3; k <= Ji[1]; k++) + { + if (k > 6) + { + Cik[1][k] = 0; + } + else + { + Cik[1][k] = AmbePlusHOCb5[b5][k - 3]; +#ifdef AMBE_DEBUG + printf ("C1,%i: %f ", k, Cik[1][k]); +#endif + } + } + for (k = 3; k <= Ji[2]; k++) + { + if (k > 6) + { + Cik[2][k] = 0; + } + else + { + Cik[2][k] = AmbePlusHOCb6[b6][k - 3]; +#ifdef AMBE_DEBUG + printf ("C2,%i: %f ", k, Cik[2][k]); +#endif + } + } + for (k = 3; k <= Ji[3]; k++) + { + if (k > 6) + { + Cik[3][k] = 0; + } + else + { + Cik[3][k] = AmbePlusHOCb7[b7][k - 3]; +#ifdef AMBE_DEBUG + printf ("C3,%i: %f ", k, Cik[3][k]); +#endif + } + } + for (k = 3; k <= Ji[4]; k++) + { + if (k > 6) + { + Cik[4][k] = 0; + } + else + { + Cik[4][k] = AmbePlusHOCb8[b8][k - 3]; +#ifdef AMBE_DEBUG + printf ("C4,%i: %f ", k, Cik[4][k]); +#endif + } + } +#ifdef AMBE_DEBUG + printf ("\n"); +#endif + + // inverse DCT each Ci,k to give ci,j (Tl) + l = 1; + for (i = 1; i <= 4; i++) + { + ji = Ji[i]; + for (j = 1; j <= ji; j++) + { + sum = 0; + for (k = 1; k <= ji; k++) + { + if (k == 1) + { + ak = 1; + } + else + { + ak = 2; + } +#ifdef AMBE_DEBUG + printf ("j: %i Cik[%i][%i]: %f ", j, i, k, Cik[i][k]); +#endif + sum = sum + ((float) ak * Cik[i][k] * cosf ((M_PI * (float) (k - 1) * ((float) j - (float) 0.5)) / (float) ji)); + } + Tl[l] = sum; +#ifdef AMBE_DEBUG + printf ("Tl[%i]: %f\n", l, Tl[l]); +#endif + l++; + } + } + + // determine log2Ml by applying ci,j to previous log2Ml + + // fix for when L > L(-1) + if (cur_mp->L > prev_mp->L) + { + for (l = (prev_mp->L) + 1; l <= cur_mp->L; l++) + { + prev_mp->Ml[l] = prev_mp->Ml[prev_mp->L]; + prev_mp->log2Ml[l] = prev_mp->log2Ml[prev_mp->L]; + } + } + prev_mp->log2Ml[0] = prev_mp->log2Ml[1]; + prev_mp->Ml[0] = prev_mp->Ml[1]; + + // Part 1 + Sum43 = 0; + for (l = 1; l <= cur_mp->L; l++) + { + + // eq. 40 + flokl[l] = ((float) prev_mp->L / (float) cur_mp->L) * (float) l; + intkl[l] = (int) (flokl[l]); +#ifdef AMBE_DEBUG + printf ("flok%i: %f, intk%i: %i ", l, flokl[l], l, intkl[l]); +#endif + // eq. 41 + deltal[l] = flokl[l] - (float) intkl[l]; +#ifdef AMBE_DEBUG + printf ("delta%i: %f ", l, deltal[l]); +#endif + // eq 43 + Sum43 = Sum43 + ((((float) 1 - deltal[l]) * prev_mp->log2Ml[intkl[l]]) + (deltal[l] * prev_mp->log2Ml[intkl[l] + 1])); + } + Sum43 = (((float) 0.65 / (float) cur_mp->L) * Sum43); +#ifdef AMBE_DEBUG + printf ("\n"); + printf ("Sum43: %f\n", Sum43); +#endif + + // Part 2 + Sum42 = 0; + for (l = 1; l <= cur_mp->L; l++) + { + Sum42 += Tl[l]; + } + Sum42 = Sum42 / (float) cur_mp->L; + BigGamma = cur_mp->gamma - ((float) 0.5 * (log ((float) cur_mp->L) / log ((float) 2))) - Sum42; + //BigGamma=cur_mp->gamma - ((float)0.5 * log((float)cur_mp->L)) - Sum42; + + // Part 3 + for (l = 1; l <= cur_mp->L; l++) + { + c1 = ((float) 0.65 * ((float) 1 - deltal[l]) * prev_mp->log2Ml[intkl[l]]); + c2 = ((float) 0.65 * deltal[l] * prev_mp->log2Ml[intkl[l] + 1]); + cur_mp->log2Ml[l] = Tl[l] + c1 + c2 - Sum43 + BigGamma; + // inverse log to generate spectral amplitudes + if (cur_mp->Vl[l] == 1) + { + cur_mp->Ml[l] = exp ((float) 0.693 * cur_mp->log2Ml[l]); + } + else + { + cur_mp->Ml[l] = unvc * exp ((float) 0.693 * cur_mp->log2Ml[l]); + } +#ifdef AMBE_DEBUG + printf ("flokl[%i]: %f, intkl[%i]: %i ", l, flokl[l], l, intkl[l]); + printf ("deltal[%i]: %f ", l, deltal[l]); + printf ("prev_mp->log2Ml[%i]: %f\n", l, prev_mp->log2Ml[intkl[l]]); + printf ("BigGamma: %f c1: %f c2: %f Sum43: %f Tl[%i]: %f log2Ml[%i]: %f Ml[%i]: %f\n", BigGamma, c1, c2, Sum43, l, Tl[l], l, cur_mp->log2Ml[l], l, cur_mp->Ml[l]); +#endif + } + + return (0); +} + +void +mbe_demodulateAmbe3600x2400Data (char ambe_fr[4][24]) +{ + int i, j, k; + unsigned short pr[115]; + unsigned short foo = 0; + + // create pseudo-random modulator + for (i = 23; i >= 12; i--) + { + foo <<= 1; + foo |= ambe_fr[0][i]; + } + pr[0] = (16 * foo); + for (i = 1; i < 24; i++) + { + pr[i] = (173 * pr[i - 1]) + 13849 - (65536 * (((173 * pr[i - 1]) + 13849) / 65536)); + } + for (i = 1; i < 24; i++) + { + pr[i] = pr[i] / 32768; + } + + // demodulate ambe_fr with pr + k = 1; + for (j = 22; j >= 0; j--) + { + ambe_fr[1][j] = ((ambe_fr[1][j]) ^ pr[k]); + k++; + } +} + +void +mbe_processAmbe2400Dataf (float *aout_buf, int *errs, int *errs2, char *err_str, char ambe_d[49], mbe_parms * cur_mp, mbe_parms * prev_mp, mbe_parms * prev_mp_enhanced, int uvquality) +{ + + int i, bad; + + for (i = 0; i < *errs2; i++) + { + *err_str = '='; + err_str++; + } + + bad = mbe_decodeAmbe2400Parms (ambe_d, cur_mp, prev_mp); + if (bad == 2) + { + // Erasure frame + *err_str = 'E'; + err_str++; + cur_mp->repeat = 0; + } + else if (bad == 3) + { + // Tone Frame + *err_str = 'T'; + err_str++; + cur_mp->repeat = 0; + } + else if (*errs2 > 3) + { + mbe_useLastMbeParms (cur_mp, prev_mp); + cur_mp->repeat++; + *err_str = 'R'; + err_str++; + } + else + { + cur_mp->repeat = 0; + } + + if (bad == 0) + { + if (cur_mp->repeat <= 3) + { + mbe_moveMbeParms (cur_mp, prev_mp); + mbe_spectralAmpEnhance (cur_mp); + mbe_synthesizeSpeechf (aout_buf, cur_mp, prev_mp_enhanced, uvquality); + mbe_moveMbeParms (cur_mp, prev_mp_enhanced); + } + else + { + *err_str = 'M'; + err_str++; + mbe_synthesizeSilencef (aout_buf); + mbe_initMbeParms (cur_mp, prev_mp, prev_mp_enhanced); + } + } + else + { + mbe_synthesizeSilencef (aout_buf); + mbe_initMbeParms (cur_mp, prev_mp, prev_mp_enhanced); + } + *err_str = 0; +} + +void +mbe_processAmbe2400Data (short *aout_buf, int *errs, int *errs2, char *err_str, char ambe_d[49], mbe_parms * cur_mp, mbe_parms * prev_mp, mbe_parms * prev_mp_enhanced, int uvquality) +{ + float float_buf[160]; + + mbe_processAmbe2400Dataf (float_buf, errs, errs2, err_str, ambe_d, cur_mp, prev_mp, prev_mp_enhanced, uvquality); + mbe_floattoshort (float_buf, aout_buf); +} + +void +mbe_processAmbe3600x2400Framef (float *aout_buf, int *errs, int *errs2, char *err_str, char ambe_fr[4][24], char ambe_d[49], mbe_parms * cur_mp, mbe_parms * prev_mp, mbe_parms * prev_mp_enhanced, int uvquality) +{ + + *errs = 0; + *errs2 = 0; + *errs = mbe_eccAmbe3600x2400C0 (ambe_fr); + mbe_demodulateAmbe3600x2400Data (ambe_fr); + *errs2 = *errs; + *errs2 += mbe_eccAmbe3600x2400Data (ambe_fr, ambe_d); + + mbe_processAmbe2400Dataf (aout_buf, errs, errs2, err_str, ambe_d, cur_mp, prev_mp, prev_mp_enhanced, uvquality); +} + +void +mbe_processAmbe3600x2400Frame (short *aout_buf, int *errs, int *errs2, char *err_str, char ambe_fr[4][24], char ambe_d[49], mbe_parms * cur_mp, mbe_parms * prev_mp, mbe_parms * prev_mp_enhanced, int uvquality) +{ + float float_buf[160]; + + mbe_processAmbe3600x2400Framef (float_buf, errs, errs2, err_str, ambe_fr, ambe_d, cur_mp, prev_mp, prev_mp_enhanced, uvquality); + mbe_floattoshort (float_buf, aout_buf); +} diff --git a/mbelib-wasm/mbelib/ambe3600x2400_const.h b/mbelib-wasm/mbelib/ambe3600x2400_const.h new file mode 100644 index 0000000..ff1ec24 --- /dev/null +++ b/mbelib-wasm/mbelib/ambe3600x2400_const.h @@ -0,0 +1,884 @@ +/* + * Copyright (C) 2010 mbelib Author + * GPG Key ID: 0xEA5EFE2C (9E7A 5527 9CDC EBF7 BF1B D772 4F98 E863 EA5E FE2C) + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _AMBE3600x2400_CONST_H +#define _AMBE3600x2400_CONST_H + + +const float AmbePlusLtable[126] = { + 9, 9, 9, 9, 9, 9, + 10, 10, 10, 10, 10, 10, + 11, 11, 11, 11, 11, 11, + 12, 12, 12, 12, 12, 13, + 13, 13, 13, 13, 14, 14, + 14, 14, 15, 15, 15, 15, + 16, 16, 16, 16, 17, 17, + 17, 17, 18, 18, 18, 18, + 19, 19, 19, 20, 20, 20, + 21, 21, 21, 22, 22, 22, + 23, 23, 23, 24, 24, 24, + 25, 25, 26, 26, 26, 27, + 27, 28, 28, 29, 29, 30, + 30, 30, 31, 31, 32, 32, + 33, 33, 34, 34, 35, 36, + 36, 37, 37, 38, 38, 39, + 40, 40, 41, 42, 42, 43, + 43, 44, 45, 46, 46, 47, + 48, 48, 49, 50, 51, 52, + 52, 53, 54, 55, 56, 56, + 56, 56, 56, 56, 56, 56 // last line is padded +}; + +/* + * V/UV Quantization Vectors + */ +const int AmbePlusVuv[16][8] = { + {0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 1, 1}, + {0, 0, 0, 0, 1, 1, 0, 0}, + {0, 0, 0, 0, 1, 1, 1, 1}, + {0, 0, 1, 1, 0, 0, 0, 0}, + {0, 0, 1, 1, 0, 0, 1, 1}, + {0, 0, 1, 1, 1, 1, 0, 0}, + {0, 0, 1, 1, 1, 1, 1, 1}, + {1, 1, 0, 0, 0, 0, 0, 0}, + {1, 1, 0, 0, 0, 0, 1, 1}, + {1, 1, 0, 0, 1, 1, 0, 0}, + {1, 1, 0, 0, 1, 1, 1, 1}, + {1, 1, 1, 1, 0, 0, 0, 0}, + {1, 1, 1, 1, 0, 0, 1, 1}, + {1, 1, 1, 1, 1, 1, 0, 0}, + {1, 1, 1, 1, 1, 1, 1, 1} +}; + +/* + * Log Magnitude Prediction Residual Block Lengths + */ +const int AmbePlusLmprbl[57][4] = { + {0, 0, 0, 0,}, + {0, 0, 0, 0,}, + {0, 0, 0, 0,}, + {0, 0, 0, 0,}, + {0, 0, 0, 0,}, + {0, 0, 0, 0,}, + {0, 0, 0, 0,}, + {0, 0, 0, 0,}, + {0, 0, 0, 0,}, + {2, 2, 2, 3,}, + {2, 2, 3, 3,}, + {2, 3, 3, 3,}, + {2, 3, 3, 4,}, + {3, 3, 3, 4,}, + {3, 3, 4, 4,}, + {3, 3, 4, 5,}, + {3, 4, 4, 5,}, + {3, 4, 5, 5,}, + {4, 4, 5, 5,}, + {4, 4, 5, 6,}, + {4, 4, 6, 6,}, + {4, 5, 6, 6,}, + {4, 5, 6, 7,}, + {5, 5, 6, 7,}, + {5, 5, 7, 7,}, + {5, 6, 7, 7,}, + {5, 6, 7, 8,}, + {5, 6, 8, 8,}, + {6, 6, 8, 8,}, + {6, 6, 8, 9,}, + {6, 7, 8, 9,}, + {6, 7, 9, 9,}, + {6, 7, 9, 10,}, + {7, 7, 9, 10,}, + {7, 8, 9, 10,}, + {7, 8, 10, 10,}, + {7, 8, 10, 11,}, + {8, 8, 10, 11,}, + {8, 9, 10, 11,}, + {8, 9, 11, 11,}, + {8, 9, 11, 12,}, + {8, 9, 11, 13,}, + {8, 9, 12, 13,}, + {8, 10, 12, 13,}, + {9, 10, 12, 13,}, + {9, 10, 12, 14,}, + {9, 10, 13, 14,}, + {9, 11, 13, 14,}, + {10, 11, 13, 14,}, + {10, 11, 13, 15,}, + {10, 11, 14, 15,}, + {10, 12, 14, 15,}, + {10, 12, 14, 16,}, + {11, 12, 14, 16,}, + {11, 12, 15, 16,}, + {11, 12, 15, 17,}, + {11, 13, 15, 17} +}; + +/* + * Gain Quantizer Levels + */ +const float AmbePlusDg[64] = { +0.000000, 0.118200, 0.215088, 0.421167, 0.590088, 0.749075, 0.879395, 0.996388, +1.092285, 1.171577, 1.236572, 1.313450, 1.376465, 1.453342, 1.516357, 1.600346, +1.669189, 1.742847, 1.803223, 1.880234, 1.943359, 2.025067, 2.092041, 2.178042, +2.248535, 2.331718, 2.399902, 2.492343, 2.568115, 2.658677, 2.732910, 2.816496, +2.885010, 2.956386, 3.014893, 3.078890, 3.131348, 3.206615, 3.268311, 3.344785, +3.407471, 3.484885, 3.548340, 3.623339, 3.684814, 3.764509, 3.829834, 3.915298, +3.985352, 4.072560, 4.144043, 4.231251, 4.302734, 4.399066, 4.478027, 4.572883, +4.650635, 4.760785, 4.851074, 4.972361, 5.071777, 5.226203, 5.352783, 5.352783}; + +/* + * PRBA24 Vector Quantizer Levels + */ +const float AmbePlusPRBA24[512][3] = { + {-1.250000, -0.312500, -0.625000}, + {-0.750000, -0.437500, -0.437500}, + {-0.437500, -0.375000, -0.312500}, + {-0.437500, -0.625000, -0.500000}, + {-1.000000, -0.187500, -0.187500}, + {-0.625000, -0.625000, -0.125000}, + {-0.500000, -0.187500, -0.187500}, + {-0.375000, -0.437500, -0.187500}, + {-1.062500, -0.750000, -0.125000}, + {-0.625000, -0.312500, -0.062500}, + {-0.500000, -1.000000, -0.062500}, + {-0.375000, -0.312500, -0.062500}, + {-0.687500, -0.250000, 0.187500}, + {-0.437500, -0.500000, 0.375000}, + {-0.375000, -0.375000, 0.062500}, + {-0.312500, -0.187500, 0.000000}, + {-0.625000, -0.187500, -0.187500}, + {-0.500000, -0.062500, -0.250000}, + {-0.500000, -0.125000, -0.437500}, + {-0.312500, -0.062500, -0.312500}, + {-0.562500, -0.187500, -0.062500}, + {-0.375000, -0.187500, -0.062500}, + {-0.375000, -0.125000, -0.187500}, + {-0.312500, -0.187500, -0.125000}, + {-0.562500, 0.000000, 0.125000}, + {-0.437500, 0.000000, 0.062500}, + {-0.312500, -0.125000, 0.125000}, + {-0.312500, -0.062500, 0.000000}, + {-0.937500, -0.062500, 0.125000}, + {-0.750000, -0.125000, 0.375000}, + {-0.437500, -0.062500, 0.250000}, + {-0.375000, -0.062500, 0.625000}, + {-0.875000, 0.062500, -0.312500}, + {-0.500000, 0.125000, -0.375000}, + {-0.312500, 0.062500, -0.250000}, + {-0.312500, 0.000000, -0.312500}, + {-0.687500, 0.125000, -0.187500}, + {-0.437500, 0.062500, -0.062500}, + {-0.375000, 0.125000, -0.125000}, + {-0.312500, 0.062500, -0.125000}, + {-0.687500, 0.062500, -0.062500}, + {-0.437500, 0.187500, 0.062500}, + {-0.312500, 0.062500, 0.000000}, + {-0.250000, 0.000000, 0.125000}, + {-1.312500, 0.062500, 0.312500}, + {-0.562500, 0.125000, 0.250000}, + {-0.375000, 0.062500, 0.375000}, + {-0.312500, 0.125000, 0.125000}, + {-1.250000, 0.187500, -0.250000}, + {-0.687500, 0.437500, -0.375000}, + {-0.562500, 0.250000, -0.250000}, + {-0.312500, 0.375000, -0.562500}, + {-0.812500, 0.437500, -0.062500}, + {-0.625000, 0.187500, -0.062500}, + {-0.500000, 0.375000, -0.062500}, + {-0.375000, 0.375000, -0.250000}, + {-0.812500, 0.187500, 0.187500}, + {-0.562500, 0.625000, 0.062500}, + {-0.500000, 0.312500, 0.125000}, + {-0.312500, 0.312500, 0.062500}, + {-0.500000, 0.250000, 0.625000}, + {-0.375000, 0.250000, 0.312500}, + {-0.312500, 0.500000, 0.500000}, + {-0.312500, 0.500000, 0.250000}, + {-0.250000, -0.437500, -0.375000}, + {-0.250000, -0.250000, -0.312500}, + {-0.250000, -0.687500, -0.312500}, + {-0.125000, -0.500000, -0.250000}, + {-0.250000, -0.375000, -0.125000}, + {-0.125000, -0.312500, -0.187500}, + {-0.125000, -0.250000, -0.250000}, + {-0.062500, -0.187500, -0.125000}, + {-0.187500, -0.187500, -0.062500}, + {-0.187500, -0.500000, 0.000000}, + {-0.125000, -0.375000, -0.062500}, + {-0.062500, -0.250000, 0.000000}, + {-0.250000, -0.312500, 0.250000}, + {-0.187500, -0.250000, 0.125000}, + {-0.187500, -0.250000, 0.000000}, + {-0.125000, -0.625000, 0.187500}, + {-0.187500, -0.062500, -0.250000}, + {-0.125000, -0.062500, -0.187500}, + {-0.062500, 0.000000, -0.312500}, + {-0.062500, 0.000000, -0.812500}, + {-0.250000, -0.125000, -0.062500}, + {-0.250000, -0.062500, -0.125000}, + {-0.187500, 0.000000, -0.062500}, + {-0.125000, -0.062500, -0.062500}, + {-0.187500, 0.000000, 0.125000}, + {-0.187500, -0.062500, 0.062500}, + {-0.125000, -0.125000, 0.125000}, + {-0.125000, -0.187500, 0.062500}, + {-0.187500, -0.062500, 0.437500}, + {-0.187500, -0.125000, 0.187500}, + {-0.125000, 0.000000, 0.187500}, + {-0.062500, 0.000000, 0.375000}, + {-0.187500, 0.000000, -0.187500}, + {-0.187500, 0.125000, -0.125000}, + {-0.187500, 0.125000, -0.187500}, + {-0.125000, 0.125000, -0.375000}, + {-0.250000, 0.187500, 0.000000}, + {-0.125000, 0.000000, -0.125000}, + {-0.062500, 0.000000, -0.062500}, + {-0.062500, 0.125000, -0.062500}, + {-0.187500, 0.125000, 0.125000}, + {-0.187500, 0.062500, 0.000000}, + {-0.125000, 0.125000, 0.062500}, + {-0.062500, 0.000000, 0.000000}, + {-0.250000, 0.062500, 0.250000}, + {-0.125000, 0.125000, 0.312500}, + {-0.125000, 0.125000, 0.125000}, + {-0.062500, 0.000000, 0.125000}, + {-0.250000, 0.250000, -0.187500}, + {-0.187500, 0.687500, -0.187500}, + {-0.125000, 0.250000, -0.125000}, + {-0.062500, 0.375000, -0.312500}, + {-0.187500, 0.187500, -0.062500}, + {-0.187500, 0.437500, -0.062500}, + {-0.125000, 0.375000, 0.062500}, + {-0.062500, 0.500000, 0.000000}, + {-0.250000, 0.250000, 0.187500}, + {-0.125000, 0.562500, 0.250000}, + {-0.125000, 0.437500, 0.125000}, + {-0.062500, 0.312500, 0.125000}, + {-0.250000, 0.187500, 0.437500}, + {-0.187500, 0.250000, 0.312500}, + {-0.062500, 0.312500, 0.250000}, + {-0.062500, 0.437500, 0.562500}, + {-0.062500, -0.375000, -0.250000}, + {0.000000, -0.250000, -0.375000}, + {0.062500, -0.250000, -0.312500}, + {0.062500, -0.375000, -0.312500}, + {0.000000, -0.312500, -0.125000}, + {0.000000, -0.250000, -0.062500}, + {0.062500, -0.500000, -0.125000}, + {0.062500, -0.250000, -0.187500}, + {0.000000, -0.437500, 0.000000}, + {0.000000, -0.250000, 0.000000}, + {0.000000, -0.187500, 0.062500}, + {0.062500, -0.375000, 0.000000}, + {-0.062500, -0.187500, 0.125000}, + {-0.062500, -0.375000, 0.062500}, + {0.000000, -0.250000, 0.187500}, + {0.000000, -0.312500, 0.125000}, + {-0.062500, -0.125000, -0.250000}, + {0.000000, -0.125000, -0.500000}, + {0.000000, -0.062500, -0.250000}, + {0.062500, -0.187500, -0.187500}, + {-0.062500, -0.125000, -0.062500}, + {-0.062500, -0.187500, 0.000000}, + {0.000000, -0.125000, -0.125000}, + {0.000000, -0.187500, -0.125000}, + {-0.062500, -0.062500, 0.125000}, + {0.000000, -0.125000, 0.000000}, + {0.062500, -0.062500, 0.000000}, + {0.062500, -0.125000, 0.000000}, + {-0.062500, -0.125000, 0.437500}, + {0.000000, -0.062500, 0.250000}, + {0.000000, -0.125000, 0.187500}, + {0.062500, -0.187500, 0.312500}, + {-0.062500, 0.062500, -0.187500}, + {-0.062500, 0.000000, -0.125000}, + {0.062500, 0.062500, -0.125000}, + {0.062500, 0.062500, -0.312500}, + {0.000000, 0.062500, -0.062500}, + {0.000000, 0.000000, 0.000000}, + {0.062500, 0.000000, -0.125000}, + {0.062500, 0.125000, -0.125000}, + {0.000000, 0.062500, 0.125000}, + {0.000000, 0.125000, 0.062500}, + {0.062500, 0.000000, 0.125000}, + {0.062500, 0.062500, 0.000000}, + {-0.062500, 0.062500, 0.187500}, + {-0.062500, 0.062500, 0.437500}, + {0.000000, 0.062500, 0.250000}, + {0.062500, 0.125000, 0.187500}, + {0.000000, 0.250000, -0.250000}, + {0.000000, 0.375000, -0.062500}, + {0.000000, 0.187500, -0.125000}, + {0.062500, 0.500000, -0.187500}, + {0.000000, 0.250000, 0.000000}, + {0.000000, 0.187500, 0.062500}, + {0.062500, 0.312500, 0.062500}, + {0.062500, 0.187500, 0.000000}, + {-0.062500, 0.187500, 0.187500}, + {0.000000, 0.250000, 0.125000}, + {0.062500, 0.375000, 0.187500}, + {0.062500, 0.250000, 0.250000}, + {-0.062500, 0.187500, 0.500000}, + {0.000000, 0.312500, 0.375000}, + {0.000000, 0.125000, 0.312500}, + {0.062500, 0.187500, 0.250000}, + {0.125000, -0.125000, -0.312500}, + {0.125000, -0.312500, -0.187500}, + {0.187500, -0.375000, -0.250000}, + {0.187500, -0.187500, -0.125000}, + {0.125000, -0.187500, -0.062500}, + {0.125000, -0.687500, -0.062500}, + {0.125000, -0.187500, -0.062500}, + {0.187500, -0.375000, -0.062500}, + {0.062500, -0.250000, 0.062500}, + {0.125000, -0.187500, 0.000000}, + {0.125000, -0.187500, 0.125000}, + {0.187500, -0.250000, 0.125000}, + {0.062500, -0.187500, 0.187500}, + {0.125000, -0.312500, 0.250000}, + {0.125000, -0.375000, 0.125000}, + {0.187500, -0.187500, 0.187500}, + {0.062500, -0.125000, -0.125000}, + {0.062500, 0.000000, -0.187500}, + {0.125000, -0.062500, -0.187500}, + {0.125000, -0.125000, -0.062500}, + {0.062500, -0.062500, 0.062500}, + {0.125000, -0.062500, 0.000000}, + {0.125000, -0.125000, 0.000000}, + {0.187500, -0.062500, 0.000000}, + {0.062500, 0.000000, 0.187500}, + {0.125000, -0.125000, 0.125000}, + {0.125000, -0.062500, 0.125000}, + {0.187500, -0.125000, 0.125000}, + {0.062500, -0.062500, 0.250000}, + {0.062500, 0.000000, 0.437500}, + {0.187500, -0.125000, 0.375000}, + {0.187500, -0.125000, 0.250000}, + {0.062500, 0.125000, -0.500000}, + {0.125000, 0.125000, -0.125000}, + {0.125000, 0.000000, -0.125000}, + {0.187500, 0.000000, -0.312500}, + {0.062500, 0.062500, 0.062500}, + {0.062500, 0.125000, 0.000000}, + {0.187500, 0.062500, -0.062500}, + {0.187500, 0.125000, 0.062500}, + {0.125000, 0.125000, 0.125000}, + {0.125000, 0.000000, 0.125000}, + {0.187500, 0.000000, 0.062500}, + {0.187500, 0.125000, 0.125000}, + {0.062500, 0.125000, 0.375000}, + {0.125000, 0.062500, 0.687500}, + {0.125000, 0.062500, 0.187500}, + {0.125000, 0.000000, 0.250000}, + {0.062500, 0.187500, -0.125000}, + {0.125000, 0.187500, -0.250000}, + {0.187500, 0.312500, -0.312500}, + {0.187500, 0.250000, -0.125000}, + {0.062500, 0.437500, 0.000000}, + {0.125000, 0.250000, 0.000000}, + {0.187500, 0.187500, 0.062500}, + {0.187500, 0.187500, -0.062500}, + {0.062500, 0.187500, 0.187500}, + {0.125000, 0.375000, 0.062500}, + {0.187500, 0.250000, 0.125000}, + {0.187500, 0.250000, 0.187500}, + {0.125000, 0.312500, 0.375000}, + {0.187500, 0.687500, 0.312500}, + {0.187500, 0.187500, 0.250000}, + {0.187500, 0.312500, 0.250000}, + {0.187500, -0.562500, -0.250000}, + {0.187500, -0.937500, -0.687500}, + {0.312500, -0.312500, -0.375000}, + {0.312500, -0.500000, -0.625000}, + {0.187500, -0.312500, 0.000000}, + {0.187500, -0.250000, -0.250000}, + {0.250000, -0.312500, -0.125000}, + {0.312500, -0.187500, 0.000000}, + {0.187500, -0.437500, 0.062500}, + {0.250000, -0.250000, 0.000000}, + {0.250000, -0.312500, 0.125000}, + {0.250000, -1.000000, 0.125000}, + {0.187500, -0.312500, 0.437500}, + {0.187500, -0.625000, 0.187500}, + {0.187500, -0.250000, 0.187500}, + {0.312500, -0.312500, 0.250000}, + {0.187500, -0.062500, -0.187500}, + {0.187500, -0.125000, -0.437500}, + {0.250000, -0.187500, -0.125000}, + {0.250000, -0.125000, -0.250000}, + {0.250000, -0.187500, -0.062500}, + {0.250000, -0.062500, -0.062500}, + {0.250000, -0.062500, -0.125000}, + {0.312500, -0.125000, -0.062500}, + {0.187500, -0.187500, 0.062500}, + {0.250000, -0.062500, 0.000000}, + {0.250000, -0.125000, 0.000000}, + {0.250000, -0.125000, 0.125000}, + {0.250000, -0.062500, 0.312500}, + {0.250000, -0.187500, 0.312500}, + {0.250000, -0.062500, 0.250000}, + {0.312500, -0.187500, 0.187500}, + {0.187500, 0.125000, -0.187500}, + {0.187500, 0.062500, -0.125000}, + {0.312500, 0.062500, -0.312500}, + {0.312500, 0.062500, -0.187500}, + {0.250000, -0.062500, 0.062500}, + {0.250000, 0.000000, -0.062500}, + {0.250000, 0.062500, 0.000000}, + {0.312500, 0.000000, 0.000000}, + {0.187500, 0.000000, 0.187500}, + {0.187500, 0.062500, 0.125000}, + {0.312500, 0.000000, 0.125000}, + {0.312500, 0.062500, 0.187500}, + {0.187500, 0.062500, 0.187500}, + {0.250000, 0.062500, 0.312500}, + {0.250000, 0.000000, 0.250000}, + {0.250000, 0.062500, 0.437500}, + {0.250000, 0.250000, -0.187500}, + {0.250000, 0.250000, -0.062500}, + {0.250000, 0.125000, -0.062500}, + {0.312500, 0.625000, -0.062500}, + {0.187500, 0.312500, 0.062500}, + {0.250000, 0.375000, -0.062500}, + {0.250000, 0.125000, 0.062500}, + {0.312500, 0.187500, -0.062500}, + {0.250000, 0.437500, 0.125000}, + {0.250000, 0.187500, 0.187500}, + {0.250000, 0.187500, 0.062500}, + {0.312500, 0.250000, 0.187500}, + {0.187500, 0.187500, 0.375000}, + {0.250000, 0.187500, 0.250000}, + {0.250000, 0.312500, 0.437500}, + {0.250000, 0.375000, 0.625000}, + {0.312500, -0.250000, -0.125000}, + {0.312500, -0.312500, -0.187500}, + {0.312500, -0.187500, -0.062500}, + {0.437500, -0.625000, -0.250000}, + {0.312500, -0.312500, 0.062500}, + {0.312500, -0.312500, 0.000000}, + {0.312500, -0.375000, -0.062500}, + {0.375000, -0.250000, 0.062500}, + {0.312500, -0.437500, 0.187500}, + {0.312500, -0.187500, 0.062500}, + {0.312500, -0.312500, 0.125000}, + {0.375000, -0.250000, 0.125000}, + {0.375000, -0.375000, 0.375000}, + {0.375000, -0.250000, 0.437500}, + {0.375000, -0.250000, 0.250000}, + {0.375000, -0.312500, 0.625000}, + {0.375000, -0.125000, -0.062500}, + {0.375000, -0.125000, -0.125000}, + {0.375000, -0.062500, -0.125000}, + {0.437500, 0.000000, -0.312500}, + {0.312500, -0.125000, 0.062500}, + {0.312500, 0.000000, 0.000000}, + {0.375000, -0.062500, 0.000000}, + {0.375000, -0.187500, 0.000000}, + {0.312500, -0.062500, 0.062500}, + {0.375000, -0.062500, 0.187500}, + {0.375000, -0.125000, 0.125000}, + {0.437500, -0.062500, 0.062500}, + {0.312500, -0.125000, 0.312500}, + {0.375000, -0.062500, 0.562500}, + {0.375000, -0.187500, 0.250000}, + {0.437500, -0.062500, 0.187500}, + {0.312500, 0.000000, -0.187500}, + {0.312500, 0.000000, -0.062500}, + {0.375000, 0.062500, -0.187500}, + {0.375000, 0.125000, -0.250000}, + {0.312500, 0.062500, -0.062500}, + {0.375000, 0.062500, 0.000000}, + {0.375000, 0.125000, 0.000000}, + {0.437500, 0.000000, 0.000000}, + {0.312500, 0.062500, 0.062500}, + {0.312500, 0.125000, 0.125000}, + {0.375000, 0.000000, 0.062500}, + {0.437500, 0.125000, 0.062500}, + {0.312500, 0.062500, 0.250000}, + {0.375000, 0.000000, 0.312500}, + {0.375000, 0.000000, 0.187500}, + {0.375000, 0.125000, 0.187500}, + {0.312500, 0.187500, -0.437500}, + {0.312500, 0.187500, -0.250000}, + {0.437500, 0.500000, -0.375000}, + {0.437500, 0.250000, -0.187500}, + {0.312500, 0.250000, -0.125000}, + {0.312500, 0.187500, 0.062500}, + {0.312500, 0.312500, 0.000000}, + {0.375000, 0.125000, -0.125000}, + {0.312500, 0.250000, 0.062500}, + {0.375000, 0.312500, 0.125000}, + {0.375000, 0.187500, 0.125000}, + {0.437500, 0.312500, 0.250000}, + {0.312500, 0.437500, 0.312500}, + {0.375000, 0.125000, 0.375000}, + {0.375000, 0.750000, 0.687500}, + {0.437500, 0.125000, 0.625000}, + {0.437500, -0.250000, -0.312500}, + {0.437500, -0.250000, -0.187500}, + {0.500000, -0.375000, -0.312500}, + {0.562500, -0.250000, -0.125000}, + {0.437500, -0.250000, 0.000000}, + {0.500000, -0.500000, -0.062500}, + {0.500000, -0.312500, -0.125000}, + {0.562500, -0.375000, 0.000000}, + {0.437500, -0.312500, 0.187500}, + {0.437500, -0.375000, 0.125000}, + {0.500000, -0.187500, 0.062500}, + {0.625000, -0.250000, 0.187500}, + {0.437500, -0.375000, 0.312500}, + {0.500000, -0.250000, 0.375000}, + {0.562500, -0.562500, 0.312500}, + {0.625000, -0.437500, 0.187500}, + {0.437500, -0.187500, -0.250000}, + {0.437500, -0.187500, -0.062500}, + {0.437500, -0.062500, -0.125000}, + {0.625000, -0.187500, -0.125000}, + {0.437500, -0.125000, 0.000000}, + {0.500000, -0.125000, -0.062500}, + {0.562500, -0.125000, 0.000000}, + {0.562500, -0.062500, -0.062500}, + {0.437500, -0.062500, 0.125000}, + {0.500000, -0.187500, 0.125000}, + {0.562500, -0.062500, 0.125000}, + {0.625000, -0.187500, 0.187500}, + {0.437500, -0.062500, 0.375000}, + {0.500000, -0.125000, 0.187500}, + {0.562500, -0.125000, 0.562500}, + {0.562500, -0.125000, 0.250000}, + {0.437500, 0.062500, -0.187500}, + {0.500000, 0.125000, -0.187500}, + {0.562500, 0.000000, -0.187500}, + {0.625000, 0.000000, -0.312500}, + {0.437500, 0.062500, -0.062500}, + {0.500000, 0.062500, 0.000000}, + {0.500000, 0.125000, -0.062500}, + {0.500000, -0.062500, 0.000000}, + {0.437500, 0.062500, 0.187500}, + {0.500000, 0.000000, 0.125000}, + {0.500000, 0.062500, 0.125000}, + {0.562500, 0.125000, 0.000000}, + {0.437500, 0.062500, 0.500000}, + {0.500000, -0.062500, 0.312500}, + {0.562500, 0.000000, 0.250000}, + {0.562500, 0.062500, 0.375000}, + {0.437500, 0.312500, -0.125000}, + {0.437500, 0.187500, -0.125000}, + {0.562500, 0.500000, -0.125000}, + {0.562500, 0.312500, -0.125000}, + {0.437500, 0.250000, -0.062500}, + {0.437500, 0.250000, 0.062500}, + {0.500000, 0.250000, -0.062500}, + {0.625000, 0.125000, -0.125000}, + {0.500000, 0.375000, 0.062500}, + {0.500000, 0.125000, 0.125000}, + {0.500000, 0.562500, 0.125000}, + {0.562500, 0.187500, 0.125000}, + {0.500000, 0.187500, 0.250000}, + {0.500000, 0.625000, 0.375000}, + {0.500000, 0.250000, 0.187500}, + {0.562500, 0.312500, 0.375000}, + {0.625000, -0.312500, -0.187500}, + {0.625000, -0.187500, -0.312500}, + {0.812500, -0.437500, -0.437500}, + {1.375000, -0.187500, -0.375000}, + {0.687500, -0.312500, -0.062500}, + {0.875000, -0.250000, -0.062500}, + {1.062500, -0.187500, 0.062500}, + {1.062500, -0.437500, -0.062500}, + {0.625000, -0.250000, 0.125000}, + {0.750000, -0.125000, 0.062500}, + {0.812500, -0.312500, 0.125000}, + {1.187500, -0.125000, 0.312500}, + {0.625000, -0.312500, 0.562500}, + {0.812500, -0.250000, 0.312500}, + {0.875000, -0.500000, 0.312500}, + {1.000000, -0.312500, 0.500000}, + {0.625000, -0.062500, -0.187500}, + {0.687500, 0.062500, -0.187500}, + {0.812500, -0.062500, -0.187500}, + {1.062500, -0.125000, -0.187500}, + {0.625000, 0.062500, -0.062500}, + {0.687500, -0.125000, -0.062500}, + {0.875000, -0.125000, 0.000000}, + {1.437500, 0.000000, 0.000000}, + {0.625000, 0.000000, 0.062500}, + {0.687500, -0.062500, 0.187500}, + {0.750000, 0.062500, 0.000000}, + {0.812500, 0.000000, 0.125000}, + {0.625000, 0.062500, 0.250000}, + {0.687500, -0.062500, 0.375000}, + {0.687500, 0.000000, 0.500000}, + {0.937500, -0.062500, 0.250000}, + {0.687500, 0.187500, -0.312500}, + {0.750000, 0.187500, -0.500000}, + {1.000000, 0.187500, -0.312500}, + {1.750000, 0.125000, -0.250000}, + {0.750000, 0.187500, -0.125000}, + {0.875000, 0.187500, -0.062500}, + {0.937500, 0.125000, 0.000000}, + {1.187500, 0.187500, -0.187500}, + {0.625000, 0.187500, 0.250000}, + {0.625000, 0.187500, 0.125000}, + {0.687500, 0.187500, 0.000000}, + {0.937500, 0.250000, 0.250000}, + {0.687500, 0.187500, 0.437500}, + {0.750000, 0.062500, 0.312500}, + {0.937500, 0.125000, 0.437500}, + {1.437500, 0.187500, 0.437500}, + {0.625000, 0.250000, -0.062500}, + {0.687500, 0.375000, 0.000000}, + {1.062500, 0.937500, -0.250000}, + {1.375000, 0.375000, -0.250000}, + {0.812500, 0.312500, 0.125000}, + {0.875000, 0.500000, 0.000000}, + {1.062500, 0.375000, 0.062500}, + {1.500000, 0.437500, 0.125000}, + {0.625000, 0.375000, 0.250000}, + {0.875000, 0.375000, 0.312500}, + {1.125000, 0.625000, 0.187500}, + {1.187500, 0.250000, 0.187500}, + {0.687500, 0.437500, 0.437500}, + {0.750000, 0.375000, 0.687500}, + {0.937500, 0.750000, 0.500000}, + {1.312500, 0.687500, 0.625000} +}; + +/* + * PRBA58 Vector Quantizer Levels + */ +const float AmbePlusPRBA58[128][4] = { + {-0.460938, -0.265625, -0.281250, -0.062500}, + {-0.367188, -0.117188, -0.078125, -0.054688}, + {-0.250000, -0.312500, -0.164063, -0.101563}, + {-0.156250, -0.078125, -0.085938, -0.203125}, + {-0.468750, -0.085938, -0.171875, 0.164063}, + {-0.210938, -0.039063, -0.117188, 0.085938}, + {-0.187500, -0.156250, -0.289063, 0.070313}, + {-0.179688, -0.117188, -0.148438, -0.046875}, + {-0.320313, -0.031250, 0.140625, -0.132813}, + {-0.289063, -0.140625, 0.179688, 0.015625}, + {-0.179688, -0.226563, -0.007813, -0.101563}, + {-0.156250, -0.031250, 0.015625, -0.093750}, + {-0.390625, -0.273438, 0.046875, 0.031250}, + {-0.195313, -0.203125, -0.070313, 0.039063}, + {-0.171875, -0.156250, -0.039063, 0.171875}, + {-0.156250, -0.085938, 0.085938, 0.125000}, + {-0.304688, 0.054688, -0.210938, -0.085938}, + {-0.265625, 0.140625, -0.031250, -0.132813}, + {-0.242188, 0.078125, -0.031250, 0.015625}, + {-0.203125, 0.000000, -0.085938, -0.070313}, + {-0.453125, 0.171875, -0.062500, 0.031250}, + {-0.289063, 0.125000, -0.156250, 0.093750}, + {-0.179688, 0.257813, -0.054688, 0.273438}, + {-0.171875, 0.226563, -0.109375, 0.015625}, + {-0.312500, -0.007813, 0.000000, 0.085938}, + {-0.265625, 0.265625, 0.046875, 0.101563}, + {-0.234375, 0.109375, 0.125000, -0.046875}, + {-0.171875, -0.015625, 0.093750, 0.007813}, + {-0.414063, 0.046875, 0.101563, 0.203125}, + {-0.179688, 0.093750, 0.210938, 0.125000}, + {-0.179688, -0.007813, 0.007813, 0.273438}, + {-0.171875, 0.085938, 0.007813, 0.132813}, + {-0.062500, -0.117188, -0.257813, -0.156250}, + {-0.054688, -0.226563, -0.109375, -0.015625}, + {-0.046875, -0.164063, -0.070313, -0.117188}, + {-0.039063, -0.031250, -0.093750, -0.085938}, + {-0.156250, -0.031250, -0.015625, 0.039063}, + {-0.085938, 0.015625, -0.179688, 0.164063}, + {-0.078125, -0.078125, -0.070313, 0.046875}, + {-0.046875, -0.195313, -0.062500, 0.109375}, + {-0.093750, -0.046875, 0.109375, -0.101563}, + {-0.054688, -0.007813, 0.007813, -0.007813}, + {-0.039063, -0.132813, 0.031250, -0.031250}, + {-0.023438, -0.148438, 0.195313, -0.085938}, + {-0.148438, -0.109375, 0.023438, 0.000000}, + {-0.039063, -0.085938, 0.031250, 0.085938}, + {-0.039063, -0.226563, 0.117188, 0.070313}, + {-0.015625, -0.015625, 0.156250, 0.156250}, + {-0.109375, 0.132813, -0.109375, -0.140625}, + {-0.093750, 0.023438, -0.187500, -0.007813}, + {-0.093750, 0.382813, -0.062500, -0.101563}, + {-0.023438, 0.101563, -0.062500, -0.007813}, + {-0.140625, 0.195313, -0.273438, 0.132813}, + {-0.109375, 0.125000, -0.117188, 0.062500}, + {-0.085938, 0.015625, -0.078125, 0.031250}, + {-0.031250, 0.203125, -0.023438, 0.125000}, + {-0.125000, 0.156250, 0.078125, -0.140625}, + {-0.117188, 0.085938, 0.312500, -0.101563}, + {-0.093750, 0.062500, 0.007813, -0.078125}, + {-0.046875, 0.046875, 0.148438, -0.023438}, + {-0.125000, 0.148438, 0.007813, 0.015625}, + {-0.085938, 0.046875, 0.054688, 0.039063}, + {-0.054688, 0.140625, 0.117188, 0.101563}, + {-0.054688, 0.039063, -0.015625, 0.109375}, + {0.046875, -0.062500, -0.054688, -0.226563}, + {0.062500, -0.132813, -0.093750, -0.101563}, + {0.078125, -0.015625, -0.132813, -0.023438}, + {0.085938, -0.421875, -0.140625, -0.062500}, + {-0.007813, -0.054688, -0.054688, 0.179688}, + {0.015625, -0.078125, -0.203125, 0.054688}, + {0.015625, -0.093750, -0.078125, 0.023438}, + {0.062500, -0.179688, -0.187500, 0.148438}, + {0.007813, -0.039063, 0.046875, -0.093750}, + {0.023438, 0.031250, 0.117188, -0.179688}, + {0.101563, -0.171875, 0.093750, -0.171875}, + {0.101563, -0.023438, -0.023438, -0.125000}, + {-0.007813, -0.039063, 0.109375, 0.023438}, + {0.046875, -0.015625, 0.015625, 0.078125}, + {0.054688, -0.046875, -0.023438, -0.023438}, + {0.070313, -0.140625, 0.062500, -0.015625}, + {0.007813, 0.070313, -0.031250, -0.210938}, + {0.015625, 0.140625, -0.179688, -0.046875}, + {0.023438, 0.039063, -0.039063, -0.039063}, + {0.054688, 0.117188, -0.007813, -0.101563}, + {0.015625, 0.046875, -0.117188, 0.078125}, + {0.054688, 0.054688, -0.281250, 0.164063}, + {0.062500, 0.273438, -0.125000, 0.085938}, + {0.093750, 0.101563, -0.070313, 0.046875}, + {-0.015625, 0.125000, 0.046875, -0.031250}, + {-0.007813, 0.273438, 0.054688, 0.000000}, + {0.070313, 0.039063, 0.070313, -0.023438}, + {0.109375, 0.195313, 0.093750, -0.218750}, + {0.046875, 0.078125, 0.039063, 0.070313}, + {0.054688, 0.101563, 0.023438, 0.265625}, + {0.070313, 0.125000, 0.273438, 0.031250}, + {0.093750, 0.335938, 0.164063, 0.132813}, + {0.195313, -0.101563, 0.015625, -0.046875}, + {0.234375, -0.171875, -0.164063, -0.125000}, + {0.296875, -0.085938, -0.117188, 0.031250}, + {0.507813, -0.179688, -0.117188, 0.015625}, + {0.109375, -0.179688, -0.046875, 0.046875}, + {0.132813, -0.054688, -0.039063, 0.070313}, + {0.171875, 0.007813, -0.117188, 0.179688}, + {0.429688, 0.015625, -0.039063, 0.218750}, + {0.132813, -0.015625, 0.156250, -0.085938}, + {0.140625, -0.125000, 0.218750, 0.000000}, + {0.265625, -0.250000, 0.101563, -0.085938}, + {0.382813, -0.109375, 0.101563, -0.125000}, + {0.117188, -0.078125, 0.085938, 0.195313}, + {0.218750, -0.210938, 0.054688, 0.140625}, + {0.265625, -0.031250, 0.054688, 0.148438}, + {0.304688, 0.007813, 0.250000, 0.023438}, + {0.117188, 0.289063, -0.226563, -0.109375}, + {0.132813, 0.023438, -0.195313, -0.132813}, + {0.164063, 0.187500, -0.070313, -0.078125}, + {0.281250, 0.046875, -0.101563, -0.250000}, + {0.164063, 0.023438, -0.023438, -0.039063}, + {0.171875, 0.148438, -0.265625, 0.046875}, + {0.210938, 0.031250, -0.156250, 0.000000}, + {0.390625, 0.179688, -0.101563, -0.031250}, + {0.234375, 0.085938, 0.031250, -0.148438}, + {0.250000, 0.265625, 0.156250, -0.070313}, + {0.312500, 0.054688, 0.093750, -0.007813}, + {0.531250, 0.210938, 0.085938, -0.015625}, + {0.117188, 0.179688, 0.054688, 0.031250}, + {0.132813, 0.039063, 0.140625, 0.070313}, + {0.218750, 0.070313, 0.007813, 0.039063}, + {0.226563, 0.242188, 0.007813, 0.148438} +}; + +/* + * Higher Order Coefficients + */ +const float AmbePlusHOCb5[16][4] = { + {-0.617188, -0.015625, 0.015625, -0.023438}, + {-0.507813, -0.382813, -0.312500, -0.117188}, + {-0.328125, 0.046875, 0.007813, -0.015625}, + {-0.320313, -0.281250, -0.023438, -0.023438}, + {-0.171875, 0.140625, -0.179688, -0.007813}, + {-0.148438, 0.226563, 0.039063, -0.039063}, + {-0.140625, -0.007813, -0.007813, -0.015625}, + {-0.109375, -0.101563, 0.179688, -0.062500}, + {-0.109375, -0.109375, -0.031250, 0.187500}, + {-0.109375, -0.218750, -0.273438, -0.140625}, + {0.007813, -0.007813, -0.015625, -0.015625}, + {0.078125, -0.265625, -0.007813, 0.007813}, + {0.101563, 0.054688, -0.210938, -0.007813}, + {0.164063, 0.242188, 0.093750, 0.039063}, + {0.179688, -0.023438, 0.007813, -0.007813}, + {0.460938, 0.015625, -0.015625, 0.007813} +}; + +/* + * Higher Order Coefficients + */ +const float AmbePlusHOCb6[16][4] = { + {-0.429688, -0.046875, 0.039063, 0.000000}, + {-0.296875, 0.187500, 0.125000, 0.015625}, + {-0.203125, -0.218750, -0.039063, -0.007813}, + {-0.179688, 0.007813, -0.007813, 0.000000}, + {-0.171875, 0.265625, -0.085938, -0.039063}, + {-0.046875, -0.070313, 0.203125, -0.023438}, + {-0.023438, 0.125000, 0.031250, -0.023438}, + {-0.007813, 0.000000, -0.195313, -0.007813}, + {0.007813, -0.046875, -0.007813, -0.015625}, + {0.015625, -0.031250, 0.039063, 0.195313}, + {0.031250, -0.273438, -0.015625, -0.007813}, + {0.140625, 0.257813, 0.015625, 0.007813}, + {0.164063, 0.015625, 0.007813, -0.023438}, + {0.210938, -0.148438, -0.187500, 0.039063}, + {0.273438, -0.179688, 0.054688, -0.007813}, + {0.421875, 0.054688, -0.039063, 0.000000} +}; + +/* + * Higher Order Coefficients + */ +const float AmbePlusHOCb7[16][4] = { + {-0.382813, -0.101563, 0.007813, 0.015625}, + {-0.335938, 0.226563, 0.015625, -0.007813}, + {-0.156250, 0.031250, -0.039063, -0.054688}, + {-0.156250, -0.015625, 0.187500, -0.015625}, + {-0.085938, -0.257813, 0.023438, -0.007813}, + {-0.070313, -0.148438, -0.203125, -0.023438}, + {-0.031250, 0.187500, -0.156250, 0.007813}, + {-0.023438, -0.007813, -0.015625, 0.179688}, + {-0.015625, 0.203125, 0.070313, -0.023438}, + {0.000000, -0.039063, -0.007813, -0.023438}, + {0.140625, -0.078125, 0.179688, -0.007813}, + {0.164063, 0.023438, -0.007813, -0.015625}, + {0.187500, -0.007813, -0.218750, -0.007813}, + {0.218750, 0.242188, 0.023438, 0.031250}, + {0.234375, -0.234375, -0.039063, 0.007813}, + {0.445313, 0.054688, -0.007813, 0.000000} +}; + +/* + * Higher Order Coefficients + */ +const float AmbePlusHOCb8[16][4] = { + {-0.453125, 0.179688, 0.078125, -0.015625}, + {-0.414063, -0.179688, -0.031250, 0.015625}, + {-0.281250, 0.187500, -0.203125, 0.046875}, + {-0.210938, -0.007813, -0.031250, -0.031250}, + {-0.148438, -0.031250, 0.218750, -0.054688}, + {-0.140625, -0.085938, 0.039063, 0.187500}, + {-0.117188, 0.234375, 0.031250, -0.054688}, + {-0.062500, -0.273438, -0.007813, -0.015625}, + {-0.054688, 0.093750, -0.078125, 0.078125}, + {-0.023438, -0.062500, -0.210938, -0.054688}, + {0.023438, 0.000000, 0.023438, -0.046875}, + {0.125000, 0.234375, -0.187500, -0.015625}, + {0.164063, -0.054688, -0.093750, 0.070313}, + {0.187500, 0.179688, 0.093750, 0.015625}, + {0.203125, -0.171875, 0.140625, -0.015625}, + {0.421875, -0.039063, -0.046875, -0.007813} +}; + +#endif diff --git a/mbelib-wasm/mbelib/ambe3600x2450.c b/mbelib-wasm/mbelib/ambe3600x2450.c new file mode 100644 index 0000000..020dc8f --- /dev/null +++ b/mbelib-wasm/mbelib/ambe3600x2450.c @@ -0,0 +1,682 @@ +/* + * Copyright (C) 2010 mbelib Author + * GPG Key ID: 0xEA5EFE2C (9E7A 5527 9CDC EBF7 BF1B D772 4F98 E863 EA5E FE2C) + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include +#include + +#include "mbelib.h" +#include "ambe3600x2450_const.h" + +void +mbe_dumpAmbe2450Data (char *ambe_d) +{ + + int i; + char *ambe; + + ambe = ambe_d; + for (i = 0; i < 49; i++) + { + printf ("%i", *ambe); + ambe++; + } + printf (" "); +} + +void +mbe_dumpAmbe3600x2450Frame (char ambe_fr[4][24]) +{ + + int j; + + // c0 + printf ("ambe_fr c0: "); + for (j = 23; j >= 0; j--) + { + printf ("%i", ambe_fr[0][j]); + } + printf (" "); + // c1 + printf ("ambe_fr c1: "); + for (j = 22; j >= 0; j--) + { + printf ("%i", ambe_fr[1][j]); + } + printf (" "); + // c2 + printf ("ambe_fr c2: "); + for (j = 10; j >= 0; j--) + { + printf ("%i", ambe_fr[2][j]); + } + printf (" "); + // c3 + printf ("ambe_fr c3: "); + for (j = 13; j >= 0; j--) + { + printf ("%i", ambe_fr[3][j]); + } + printf (" "); +} + +int +mbe_eccAmbe3600x2450C0 (char ambe_fr[4][24]) +{ + + int j, errs; + char in[23], out[23]; + + for (j = 0; j < 23; j++) + { + in[j] = ambe_fr[0][j + 1]; + } + errs = mbe_golay2312 (in, out); + // ambe_fr[0][0] should be the C0 golay24 parity bit. + // TODO: actually test that here... + for (j = 0; j < 23; j++) + { + ambe_fr[0][j + 1] = out[j]; + } + + return (errs); +} + +int +mbe_eccAmbe3600x2450Data (char ambe_fr[4][24], char *ambe_d) +{ + + int j, errs; + char *ambe, gin[24], gout[24]; + + ambe = ambe_d; + // just copy C0 + for (j = 23; j > 11; j--) + { + *ambe = ambe_fr[0][j]; + ambe++; + } + + // ecc and copy C1 + for (j = 0; j < 23; j++) + { + gin[j] = ambe_fr[1][j]; + } + errs = mbe_golay2312 (gin, gout); + for (j = 22; j > 10; j--) + { + *ambe = gout[j]; + ambe++; + } + + // just copy C2 + for (j = 10; j >= 0; j--) + { + *ambe = ambe_fr[2][j]; + ambe++; + } + + // just copy C3 + for (j = 13; j >= 0; j--) + { + *ambe = ambe_fr[3][j]; + ambe++; + } + + return (errs); +} + +int +mbe_decodeAmbe2450Parms (char *ambe_d, mbe_parms * cur_mp, mbe_parms * prev_mp) +{ + + int ji, i, j, k, l, L, L9, m, am, ak; + int intkl[57]; + int b0, b1, b2, b3, b4, b5, b6, b7, b8; + float f0, Cik[5][18], flokl[57], deltal[57]; + float Sum42, Sum43, Tl[57], Gm[9], Ri[9], sum, c1, c2; + int silence; + int Ji[5], jl; + float deltaGamma, BigGamma; + float unvc, rconst; + + silence = 0; + +#ifdef AMBE_DEBUG + printf ("\n"); +#endif + + // copy repeat from prev_mp + cur_mp->repeat = prev_mp->repeat; + + // decode fundamental frequency w0 from b0 + b0 = 0; + b0 |= ambe_d[0]<<6; + b0 |= ambe_d[1]<<5; + b0 |= ambe_d[2]<<4; + b0 |= ambe_d[3]<<3; + b0 |= ambe_d[37]<<2; + b0 |= ambe_d[38]<<1; + b0 |= ambe_d[39]; + if ((b0 >= 120) && (b0 <= 123)) // if w0 bits are 1111000, 1111001, 1111010 or 1111011, frame is erasure + { +#ifdef AMBE_DEBUG + printf ("Erasure Frame\n"); +#endif + return (2); + } + else if ((b0 == 124) || (b0 == 125)) // if w0 bits are 1111100 or 1111101, frame is silence + { +#ifdef AMBE_DEBUG + printf ("Silence Frame\n"); +#endif + silence = 1; + cur_mp->w0 = ((float) 2 * M_PI) / (float) 32; + f0 = (float) 1 / (float) 32; + L = 14; + cur_mp->L = 14; + for (l = 1; l <= L; l++) + { + cur_mp->Vl[l] = 0; + } + } + else if ((b0 == 126) || (b0 == 127)) // if w0 bits are 1111110 or 1111111, frame is tone + { +#ifdef AMBE_DEBUG + printf ("Tone Frame\n"); +#endif + return (3); + } + + if (silence == 0) + { + // w0 from specification document + f0 = AmbeW0table[b0]; + cur_mp->w0 = f0 * (float) 2 *M_PI; + // w0 from patent filings + //f0 = powf (2, ((float) b0 + (float) 195.626) / -(float) 45.368); + //cur_mp->w0 = f0 * (float) 2 *M_PI; + } + + unvc = (float) 0.2046 / sqrtf (cur_mp->w0); + //unvc = (float) 1; + //unvc = (float) 0.2046 / sqrtf (f0); + + // decode L + if (silence == 0) + { + // L from specification document + // lookup L in tabl3 + L = AmbeLtable[b0]; + // L formula from patent filings + //L=(int)((float)0.4627 / f0); + cur_mp->L = L; + } + L9 = L - 9; + + // decode V/UV parameters + // load b1 from ambe_d + b1 = 0; + b1 |= ambe_d[4]<<4; + b1 |= ambe_d[5]<<3; + b1 |= ambe_d[6]<<2; + b1 |= ambe_d[7]<<1; + b1 |= ambe_d[35]; + + for (l = 1; l <= L; l++) + { + // jl from specification document + jl = (int) ((float) l * (float) 16.0 * f0); + // jl from patent filings? + //jl = (int)(((float)l * (float)16.0 * f0) + 0.25); + + if (silence == 0) + { + cur_mp->Vl[l] = AmbeVuv[b1][jl]; + } +#ifdef AMBE_DEBUG + printf ("jl[%i]:%i Vl[%i]:%i\n", l, jl, l, cur_mp->Vl[l]); +#endif + } +#ifdef AMBE_DEBUG + printf ("\nb0:%i w0:%f L:%i b1:%i\n", b0, cur_mp->w0, L, b1); +#endif + + // decode gain vector + // load b2 from ambe_d + b2 = 0; + b2 |= ambe_d[8]<<4; + b2 |= ambe_d[9]<<3; + b2 |= ambe_d[10]<<2; + b2 |= ambe_d[11]<<1; + b2 |= ambe_d[36]; + + deltaGamma = AmbeDg[b2]; + cur_mp->gamma = deltaGamma + ((float) 0.5 * prev_mp->gamma); +#ifdef AMBE_DEBUG + printf ("b2: %i, deltaGamma: %f gamma: %f gamma-1: %f\n", b2, deltaGamma, cur_mp->gamma, prev_mp->gamma); +#endif + + + // decode PRBA vectors + Gm[1] = 0; + + // load b3 from ambe_d + b3 = 0; + b3 |= ambe_d[12]<<8; + b3 |= ambe_d[13]<<7; + b3 |= ambe_d[14]<<6; + b3 |= ambe_d[15]<<5; + b3 |= ambe_d[16]<<4; + b3 |= ambe_d[17]<<3; + b3 |= ambe_d[18]<<2; + b3 |= ambe_d[19]<<1; + b3 |= ambe_d[40]; + Gm[2] = AmbePRBA24[b3][0]; + Gm[3] = AmbePRBA24[b3][1]; + Gm[4] = AmbePRBA24[b3][2]; + + // load b4 from ambe_d + b4 = 0; + b4 |= ambe_d[20]<<6; + b4 |= ambe_d[21]<<5; + b4 |= ambe_d[22]<<4; + b4 |= ambe_d[23]<<3; + b4 |= ambe_d[41]<<2; + b4 |= ambe_d[42]<<1; + b4 |= ambe_d[43]; + Gm[5] = AmbePRBA58[b4][0]; + Gm[6] = AmbePRBA58[b4][1]; + Gm[7] = AmbePRBA58[b4][2]; + Gm[8] = AmbePRBA58[b4][3]; + +#ifdef AMBE_DEBUG + printf ("b3: %i Gm[2]: %f Gm[3]: %f Gm[4]: %f b4: %i Gm[5]: %f Gm[6]: %f Gm[7]: %f Gm[8]: %f\n", b3, Gm[2], Gm[3], Gm[4], b4, Gm[5], Gm[6], Gm[7], Gm[8]); +#endif + + // compute Ri + for (i = 1; i <= 8; i++) + { + sum = 0; + for (m = 1; m <= 8; m++) + { + if (m == 1) + { + am = 1; + } + else + { + am = 2; + } + sum = sum + ((float) am * Gm[m] * cosf ((M_PI * (float) (m - 1) * ((float) i - (float) 0.5)) / (float) 8)); + } + Ri[i] = sum; +#ifdef AMBE_DEBUG + printf ("R%i: %f ", i, Ri[i]); +#endif + } +#ifdef AMBE_DEBUG + printf ("\n"); +#endif + + // generate first to elements of each Ci,k block from PRBA vector + rconst = ((float) 1 / ((float) 2 * M_SQRT2)); + Cik[1][1] = (float) 0.5 *(Ri[1] + Ri[2]); + Cik[1][2] = rconst * (Ri[1] - Ri[2]); + Cik[2][1] = (float) 0.5 *(Ri[3] + Ri[4]); + Cik[2][2] = rconst * (Ri[3] - Ri[4]); + Cik[3][1] = (float) 0.5 *(Ri[5] + Ri[6]); + Cik[3][2] = rconst * (Ri[5] - Ri[6]); + Cik[4][1] = (float) 0.5 *(Ri[7] + Ri[8]); + Cik[4][2] = rconst * (Ri[7] - Ri[8]); + + // decode HOC + + // load b5 from ambe_d + b5 = 0; + b5 |= ambe_d[24]<<4; + b5 |= ambe_d[25]<<3; + b5 |= ambe_d[26]<<2; + b5 |= ambe_d[27]<<1; + b5 |= ambe_d[44]; + + // load b6 from ambe_d + b6 = 0; + b6 |= ambe_d[28]<<3; + b6 |= ambe_d[29]<<2; + b6 |= ambe_d[30]<<1; + b6 |= ambe_d[45]; + + // load b7 from ambe_d + b7 = 0; + b7 |= ambe_d[31]<<3; + b7 |= ambe_d[32]<<2; + b7 |= ambe_d[33]<<1; + b7 |= ambe_d[46]; + + // load b8 from ambe_d + b8 = 0; + b8 |= ambe_d[34]<<2; + b8 |= ambe_d[47]<<1; + b8 |= ambe_d[48]; + + // lookup Ji + Ji[1] = AmbeLmprbl[L][0]; + Ji[2] = AmbeLmprbl[L][1]; + Ji[3] = AmbeLmprbl[L][2]; + Ji[4] = AmbeLmprbl[L][3]; +#ifdef AMBE_DEBUG + printf ("Ji[1]: %i Ji[2]: %i Ji[3]: %i Ji[4]: %i\n", Ji[1], Ji[2], Ji[3], Ji[4]); + printf ("b5: %i b6: %i b7: %i b8: %i\n", b5, b6, b7, b8); +#endif + + // Load Ci,k with the values from the HOC tables + // there appear to be a couple typos in eq. 37 so we will just do what makes sense + // (3 <= k <= Ji and k<=6) + for (k = 3; k <= Ji[1]; k++) + { + if (k > 6) + { + Cik[1][k] = 0; + } + else + { + Cik[1][k] = AmbeHOCb5[b5][k - 3]; +#ifdef AMBE_DEBUG + printf ("C1,%i: %f ", k, Cik[1][k]); +#endif + } + } + for (k = 3; k <= Ji[2]; k++) + { + if (k > 6) + { + Cik[2][k] = 0; + } + else + { + Cik[2][k] = AmbeHOCb6[b6][k - 3]; +#ifdef AMBE_DEBUG + printf ("C2,%i: %f ", k, Cik[2][k]); +#endif + } + } + for (k = 3; k <= Ji[3]; k++) + { + if (k > 6) + { + Cik[3][k] = 0; + } + else + { + Cik[3][k] = AmbeHOCb7[b7][k - 3]; +#ifdef AMBE_DEBUG + printf ("C3,%i: %f ", k, Cik[3][k]); +#endif + } + } + for (k = 3; k <= Ji[4]; k++) + { + if (k > 6) + { + Cik[4][k] = 0; + } + else + { + Cik[4][k] = AmbeHOCb8[b8][k - 3]; +#ifdef AMBE_DEBUG + printf ("C4,%i: %f ", k, Cik[4][k]); +#endif + } + } +#ifdef AMBE_DEBUG + printf ("\n"); +#endif + + // inverse DCT each Ci,k to give ci,j (Tl) + l = 1; + for (i = 1; i <= 4; i++) + { + ji = Ji[i]; + for (j = 1; j <= ji; j++) + { + sum = 0; + for (k = 1; k <= ji; k++) + { + if (k == 1) + { + ak = 1; + } + else + { + ak = 2; + } +#ifdef AMBE_DEBUG + printf ("j: %i Cik[%i][%i]: %f ", j, i, k, Cik[i][k]); +#endif + sum = sum + ((float) ak * Cik[i][k] * cosf ((M_PI * (float) (k - 1) * ((float) j - (float) 0.5)) / (float) ji)); + } + Tl[l] = sum; +#ifdef AMBE_DEBUG + printf ("Tl[%i]: %f\n", l, Tl[l]); +#endif + l++; + } + } + + // determine log2Ml by applying ci,j to previous log2Ml + + // fix for when L > L(-1) + if (cur_mp->L > prev_mp->L) + { + for (l = (prev_mp->L) + 1; l <= cur_mp->L; l++) + { + prev_mp->Ml[l] = prev_mp->Ml[prev_mp->L]; + prev_mp->log2Ml[l] = prev_mp->log2Ml[prev_mp->L]; + } + } + prev_mp->log2Ml[0] = prev_mp->log2Ml[1]; + prev_mp->Ml[0] = prev_mp->Ml[1]; + + // Part 1 + Sum43 = 0; + for (l = 1; l <= cur_mp->L; l++) + { + + // eq. 40 + flokl[l] = ((float) prev_mp->L / (float) cur_mp->L) * (float) l; + intkl[l] = (int) (flokl[l]); +#ifdef AMBE_DEBUG + printf ("flok%i: %f, intk%i: %i ", l, flokl[l], l, intkl[l]); +#endif + // eq. 41 + deltal[l] = flokl[l] - (float) intkl[l]; +#ifdef AMBE_DEBUG + printf ("delta%i: %f ", l, deltal[l]); +#endif + // eq 43 + Sum43 = Sum43 + ((((float) 1 - deltal[l]) * prev_mp->log2Ml[intkl[l]]) + (deltal[l] * prev_mp->log2Ml[intkl[l] + 1])); + } + Sum43 = (((float) 0.65 / (float) cur_mp->L) * Sum43); +#ifdef AMBE_DEBUG + printf ("\n"); + printf ("Sum43: %f\n", Sum43); +#endif + + // Part 2 + Sum42 = 0; + for (l = 1; l <= cur_mp->L; l++) + { + Sum42 += Tl[l]; + } + Sum42 = Sum42 / (float) cur_mp->L; + BigGamma = cur_mp->gamma - ((float) 0.5 * (log ((float) cur_mp->L) / log ((float) 2))) - Sum42; + //BigGamma=cur_mp->gamma - ((float)0.5 * log((float)cur_mp->L)) - Sum42; + + // Part 3 + for (l = 1; l <= cur_mp->L; l++) + { + c1 = ((float) 0.65 * ((float) 1 - deltal[l]) * prev_mp->log2Ml[intkl[l]]); + c2 = ((float) 0.65 * deltal[l] * prev_mp->log2Ml[intkl[l] + 1]); + cur_mp->log2Ml[l] = Tl[l] + c1 + c2 - Sum43 + BigGamma; + // inverse log to generate spectral amplitudes + if (cur_mp->Vl[l] == 1) + { + cur_mp->Ml[l] = exp ((float) 0.693 * cur_mp->log2Ml[l]); + } + else + { + cur_mp->Ml[l] = unvc * exp ((float) 0.693 * cur_mp->log2Ml[l]); + } +#ifdef AMBE_DEBUG + printf ("flokl[%i]: %f, intkl[%i]: %i ", l, flokl[l], l, intkl[l]); + printf ("deltal[%i]: %f ", l, deltal[l]); + printf ("prev_mp->log2Ml[%i]: %f\n", l, prev_mp->log2Ml[intkl[l]]); + printf ("BigGamma: %f c1: %f c2: %f Sum43: %f Tl[%i]: %f log2Ml[%i]: %f Ml[%i]: %f\n", BigGamma, c1, c2, Sum43, l, Tl[l], l, cur_mp->log2Ml[l], l, cur_mp->Ml[l]); +#endif + } + + return (0); +} + +void +mbe_demodulateAmbe3600x2450Data (char ambe_fr[4][24]) +{ + int i, j, k; + unsigned short pr[115]; + unsigned short foo = 0; + + // create pseudo-random modulator + for (i = 23; i >= 12; i--) + { + foo <<= 1; + foo |= ambe_fr[0][i]; + } + pr[0] = (16 * foo); + for (i = 1; i < 24; i++) + { + pr[i] = (173 * pr[i - 1]) + 13849 - (65536 * (((173 * pr[i - 1]) + 13849) / 65536)); + } + for (i = 1; i < 24; i++) + { + pr[i] = pr[i] / 32768; + } + + // demodulate ambe_fr with pr + k = 1; + for (j = 22; j >= 0; j--) + { + ambe_fr[1][j] = ((ambe_fr[1][j]) ^ pr[k]); + k++; + } +} + +void +mbe_processAmbe2450Dataf (float *aout_buf, int *errs, int *errs2, char *err_str, char ambe_d[49], mbe_parms * cur_mp, mbe_parms * prev_mp, mbe_parms * prev_mp_enhanced, int uvquality) +{ + + int i, bad; + + for (i = 0; i < *errs2; i++) + { + *err_str = '='; + err_str++; + } + + bad = mbe_decodeAmbe2450Parms (ambe_d, cur_mp, prev_mp); + if (bad == 2) + { + // Erasure frame + *err_str = 'E'; + err_str++; + cur_mp->repeat = 0; + } + else if (bad == 3) + { + // Tone Frame + *err_str = 'T'; + err_str++; + cur_mp->repeat = 0; + } + else if (*errs2 > 3) + { + mbe_useLastMbeParms (cur_mp, prev_mp); + cur_mp->repeat++; + *err_str = 'R'; + err_str++; + } + else + { + cur_mp->repeat = 0; + } + + if (bad == 0) + { + if (cur_mp->repeat <= 3) + { + mbe_moveMbeParms (cur_mp, prev_mp); + mbe_spectralAmpEnhance (cur_mp); + mbe_synthesizeSpeechf (aout_buf, cur_mp, prev_mp_enhanced, uvquality); + mbe_moveMbeParms (cur_mp, prev_mp_enhanced); + } + else + { + *err_str = 'M'; + err_str++; + mbe_synthesizeSilencef (aout_buf); + mbe_initMbeParms (cur_mp, prev_mp, prev_mp_enhanced); + } + } + else + { + mbe_synthesizeSilencef (aout_buf); + mbe_initMbeParms (cur_mp, prev_mp, prev_mp_enhanced); + } + *err_str = 0; +} + +void +mbe_processAmbe2450Data (short *aout_buf, int *errs, int *errs2, char *err_str, char ambe_d[49], mbe_parms * cur_mp, mbe_parms * prev_mp, mbe_parms * prev_mp_enhanced, int uvquality) +{ + float float_buf[160]; + + mbe_processAmbe2450Dataf (float_buf, errs, errs2, err_str, ambe_d, cur_mp, prev_mp, prev_mp_enhanced, uvquality); + mbe_floattoshort (float_buf, aout_buf); +} + +void +mbe_processAmbe3600x2450Framef (float *aout_buf, int *errs, int *errs2, char *err_str, char ambe_fr[4][24], char ambe_d[49], mbe_parms * cur_mp, mbe_parms * prev_mp, mbe_parms * prev_mp_enhanced, int uvquality) +{ + + *errs = 0; + *errs2 = 0; + *errs = mbe_eccAmbe3600x2450C0 (ambe_fr); + mbe_demodulateAmbe3600x2450Data (ambe_fr); + *errs2 = *errs; + *errs2 += mbe_eccAmbe3600x2450Data (ambe_fr, ambe_d); + + mbe_processAmbe2450Dataf (aout_buf, errs, errs2, err_str, ambe_d, cur_mp, prev_mp, prev_mp_enhanced, uvquality); +} + +void +mbe_processAmbe3600x2450Frame (short *aout_buf, int *errs, int *errs2, char *err_str, char ambe_fr[4][24], char ambe_d[49], mbe_parms * cur_mp, mbe_parms * prev_mp, mbe_parms * prev_mp_enhanced, int uvquality) +{ + float float_buf[160]; + + mbe_processAmbe3600x2450Framef (float_buf, errs, errs2, err_str, ambe_fr, ambe_d, cur_mp, prev_mp, prev_mp_enhanced, uvquality); + mbe_floattoshort (float_buf, aout_buf); +} diff --git a/mbelib-wasm/mbelib/ambe3600x2450_const.h b/mbelib-wasm/mbelib/ambe3600x2450_const.h new file mode 100644 index 0000000..2788785 --- /dev/null +++ b/mbelib-wasm/mbelib/ambe3600x2450_const.h @@ -0,0 +1,971 @@ +/* + * Copyright (C) 2010 mbelib Author + * GPG Key ID: 0xEA5EFE2C (9E7A 5527 9CDC EBF7 BF1B D772 4F98 E863 EA5E FE2C) + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _AMBE3600x2450_CONST_H +#define _AMBE3600x2450_CONST_H + +/* + * Fundamental Frequency Quanitization Table + */ + +const float AmbeW0table[120] = { + 0.049971, 0.049215, 0.048471, 0.047739, 0.047010, 0.046299, + 0.045601, 0.044905, 0.044226, 0.043558, 0.042900, 0.042246, + 0.041609, 0.040979, 0.040356, 0.039747, 0.039148, 0.038559, + 0.037971, 0.037399, 0.036839, 0.036278, 0.035732, 0.035198, + 0.034672, 0.034145, 0.033636, 0.033133, 0.032635, 0.032148, + 0.031670, 0.031122, 0.030647, 0.030184, 0.029728, 0.029272, + 0.028831, 0.028395, 0.027966, 0.027538, + 0.027122, 0.026712, 0.026304, 0.025906, 0.025515, 0.025129, + 0.024746, 0.024372, 0.024002, 0.023636, 0.023279, 0.022926, + 0.022581, 0.022236, 0.021900, 0.021570, 0.021240, 0.020920, + 0.020605, 0.020294, 0.019983, 0.019684, 0.019386, 0.019094, + 0.018805, 0.018520, 0.018242, 0.017965, 0.017696, 0.017431, + 0.017170, 0.016911, 0.016657, 0.016409, 0.016163, 0.015923, + 0.015686, 0.015411, 0.015177, 0.014946, + 0.014721, 0.014496, 0.014277, 0.014061, 0.013847, 0.013636, + 0.013430, 0.013227, 0.013025, 0.012829, 0.012634, 0.012444, + 0.012253, 0.012068, 0.011887, 0.011703, 0.011528, 0.011353, + 0.011183, 0.011011, 0.010845, 0.010681, 0.010517, 0.010359, + 0.010202, 0.010050, 0.009895, 0.009747, 0.009600, 0.009453, + 0.009312, 0.009172, 0.009033, 0.008896, 0.008762, 0.008633, + 0.008501, 0.008375, 0.008249, 0.008125 +}; + +const float AmbeLtable[120] = { + 9, 9, 9, 9, 9, 9, + 10, 10, 10, 10, 10, 10, + 11, 11, 11, 11, 11, 11, + 12, 12, 12, 12, 12, 13, + 13, 13, 13, 13, 14, 14, + 14, 14, 15, 15, 15, 15, + 16, 16, 16, 16, 17, 17, + 17, 17, 18, 18, 18, 18, + 19, 19, 19, 20, 20, 20, + 21, 21, 21, 22, 22, 22, + 23, 23, 23, 24, 24, 24, + 25, 25, 26, 26, 26, 27, + 27, 28, 28, 29, 29, 30, + 30, 30, 31, 31, 32, 32, + 33, 33, 34, 34, 35, 36, + 36, 37, 37, 38, 38, 39, + 40, 40, 41, 42, 42, 43, + 43, 44, 45, 46, 46, 47, + 48, 48, 49, 50, 51, 52, + 52, 53, 54, 55, 56, 56 +}; + +/* + * V/UV Quantization Vectors + */ +const int AmbeVuv[32][8] = { + {1, 1, 1, 1, 1, 1, 1, 1}, + {1, 1, 1, 1, 1, 1, 1, 1}, + {1, 1, 1, 1, 1, 1, 1, 0}, + {1, 1, 1, 1, 1, 1, 1, 1}, + {1, 1, 1, 1, 1, 1, 0, 0}, + {1, 1, 0, 1, 1, 1, 1, 1}, + {1, 1, 1, 0, 1, 1, 1, 1}, + {1, 1, 1, 1, 1, 0, 1, 1}, + {1, 1, 1, 1, 0, 0, 0, 0}, + {1, 1, 1, 1, 1, 0, 0, 0}, + {1, 1, 1, 0, 0, 0, 0, 0}, + {1, 1, 1, 0, 0, 0, 0, 1}, + {1, 1, 0, 0, 0, 0, 0, 0}, + {1, 1, 1, 0, 0, 0, 0, 0}, + {1, 0, 0, 0, 0, 0, 0, 0}, + {1, 1, 1, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0} +}; + +/* + * V/UV Quantization Vectors + * alternate version + */ +/* +const int AmbeVuv[32][8] = { + {1, 1, 1, 1, 1, 1, 1, 1}, + {1, 1, 1, 1, 1, 1, 1, 1}, + {1, 1, 1, 1, 1, 1, 1, 0}, + {1, 1, 1, 1, 1, 1, 1, 0}, + {1, 1, 1, 1, 1, 1, 0, 0}, + {1, 1, 0, 1, 1, 1, 1, 1}, + {1, 1, 1, 0, 1, 1, 1, 1}, + {1, 1, 1, 1, 1, 0, 1, 1}, + {1, 1, 1, 1, 0, 0, 0, 0}, + {1, 1, 1, 1, 1, 0, 0, 0}, + {1, 1, 1, 0, 0, 0, 0, 0}, + {1, 1, 1, 0, 0, 0, 0, 1}, + {1, 1, 0, 0, 0, 0, 0, 0}, + {1, 1, 0, 0, 0, 0, 0, 0}, + {1, 0, 0, 0, 0, 0, 0, 0}, + {1, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0} +}; +*/ + +/* + * Log Magnitude Prediction Residual Block Lengths + */ +const int AmbeLmprbl[57][4] = { + {0, 0, 0, 0,}, + {0, 0, 0, 0,}, + {0, 0, 0, 0,}, + {0, 0, 0, 0,}, + {0, 0, 0, 0,}, + {0, 0, 0, 0,}, + {0, 0, 0, 0,}, + {0, 0, 0, 0,}, + {0, 0, 0, 0,}, + {2, 2, 2, 3,}, + {2, 2, 3, 3,}, + {2, 3, 3, 3,}, + {2, 3, 3, 4,}, + {3, 3, 3, 4,}, + {3, 3, 4, 4,}, + {3, 3, 4, 5,}, + {3, 4, 4, 5,}, + {3, 4, 5, 5,}, + {4, 4, 5, 5,}, + {4, 4, 5, 6,}, + {4, 4, 6, 6,}, + {4, 5, 6, 6,}, + {4, 5, 6, 7,}, + {5, 5, 6, 7,}, + {5, 5, 7, 7,}, + {5, 6, 7, 7,}, + {5, 6, 7, 8,}, + {5, 6, 8, 8,}, + {6, 6, 8, 8,}, + {6, 6, 8, 9,}, + {6, 7, 8, 9,}, + {6, 7, 9, 9,}, + {6, 7, 9, 10,}, + {7, 7, 9, 10,}, + {7, 8, 9, 10,}, + {7, 8, 10, 10,}, + {7, 8, 10, 11,}, + {8, 8, 10, 11,}, + {8, 9, 10, 11,}, + {8, 9, 11, 11,}, + {8, 9, 11, 12,}, + {8, 9, 11, 13,}, + {8, 9, 12, 13,}, + {8, 10, 12, 13,}, + {9, 10, 12, 13,}, + {9, 10, 12, 14,}, + {9, 10, 13, 14,}, + {9, 11, 13, 14,}, + {10, 11, 13, 14,}, + {10, 11, 13, 15,}, + {10, 11, 14, 15,}, + {10, 12, 14, 15,}, + {10, 12, 14, 16,}, + {11, 12, 14, 16,}, + {11, 12, 15, 16,}, + {11, 12, 15, 17,}, + {11, 13, 15, 17} +}; + +/* + * Gain Quantizer Levels + */ +const float AmbeDg[32] = { -2.0, -0.67, 0.297941, 0.663728, 1.036829, 1.438136, 1.890077, 2.227970, + 2.478289, 2.667544, 2.793619, 2.893261, 3.020630, 3.138586, 3.237579, 3.322570, + 3.432367, 3.571863, 3.696650, 3.814917, 3.920932, 4.022503, 4.123569, 4.228291, + 4.370569, 4.543700, 4.707695, 4.848879, 5.056757, 5.326468, 5.777581, 6.874496 +}; + +/* + * PRBA24 Vector Quantizer Levels + */ +const float AmbePRBA24[512][3] = { + {0.526055, -0.328567, -0.304727}, + {0.441044, -0.303127, -0.201114}, + {1.030896, -0.324730, -0.397204}, + {0.839696, -0.351933, -0.224909}, + {0.272958, -0.176118, -0.098893}, + {0.221466, -0.160045, -0.061026}, + {0.496555, -0.211499, 0.047305}, + {0.424376, -0.223752, 0.069911}, + {0.264531, -0.353355, -0.330505}, + {0.273650, -0.253004, -0.250241}, + {0.484531, -0.297627, -0.071051}, + {0.410814, -0.224961, -0.084998}, + {0.039519, -0.252904, -0.115128}, + {0.017423, -0.296519, -0.045921}, + {0.225113, -0.224371, 0.037882}, + {0.183424, -0.260492, 0.050491}, + {0.308704, -0.073205, -0.405880}, + {0.213125, -0.101632, -0.333208}, + {0.617735, -0.137299, -0.213670}, + {0.514382, -0.126485, -0.170204}, + {0.130009, -0.076955, -0.229303}, + {0.061740, -0.108259, -0.203887}, + {0.244473, -0.110094, -0.051689}, + {0.230452, -0.076147, -0.028190}, + {0.059837, -0.254595, -0.562704}, + {0.011630, -0.135223, -0.432791}, + {0.207077, -0.152248, -0.148391}, + {0.158078, -0.128800, -0.122150}, + {-0.265982, -0.144742, -0.199894}, + {-0.356479, -0.204740, -0.156465}, + {0.000324, -0.139549, -0.066471}, + {0.001888, -0.170557, -0.025025}, + {0.402913, -0.581478, -0.274626}, + {0.191289, -0.540335, -0.193040}, + {0.632914, -0.401410, -0.006636}, + {0.471086, -0.463144, 0.061489}, + {0.044829, -0.438487, 0.033433}, + {0.015513, -0.539475, -0.006719}, + {0.336218, -0.351311, 0.214087}, + {0.239967, -0.380836, 0.157681}, + {0.347609, -0.901619, -0.688432}, + {0.064067, -0.826753, -0.492089}, + {0.303089, -0.396757, -0.108446}, + {0.235590, -0.446122, 0.006437}, + {-0.236964, -0.652532, -0.135520}, + {-0.418285, -0.793014, -0.034730}, + {-0.038262, -0.516984, 0.273681}, + {-0.037419, -0.958198, 0.214749}, + {0.061624, -0.238233, -0.237184}, + {-0.013944, -0.235704, -0.204811}, + {0.286428, -0.210542, -0.029587}, + {0.257656, -0.261837, -0.056566}, + {-0.235852, -0.310760, -0.165147}, + {-0.334949, -0.385870, -0.197362}, + {0.094870, -0.241144, 0.059122}, + {0.060177, -0.225884, 0.031140}, + {-0.301184, -0.306545, -0.446189}, + {-0.293528, -0.504146, -0.429844}, + {-0.055084, -0.379015, -0.125887}, + {-0.115434, -0.375008, -0.059939}, + {-0.777425, -0.592163, -0.107585}, + {-0.950500, -0.893847, -0.181762}, + {-0.259402, -0.396726, 0.010357}, + {-0.368905, -0.449026, 0.038299}, + {0.279719, -0.063196, -0.184628}, + {0.255265, -0.067248, -0.121124}, + {0.458433, -0.103777, 0.010074}, + {0.437231, -0.092496, -0.031028}, + {0.082265, -0.028050, -0.041262}, + {0.045920, -0.051719, -0.030155}, + {0.271149, -0.043613, 0.112085}, + {0.246881, -0.065274, 0.105436}, + {0.056590, -0.117773, -0.142283}, + {0.058824, -0.104418, -0.099608}, + {0.213781, -0.111974, 0.031269}, + {0.187554, -0.070340, 0.011834}, + {-0.185701, -0.081106, -0.073803}, + {-0.266112, -0.074133, -0.085370}, + {-0.029368, -0.046490, 0.124679}, + {-0.017378, -0.102882, 0.140482}, + {0.114700, 0.092738, -0.244271}, + {0.072922, 0.007863, -0.231476}, + {0.270022, 0.031819, -0.094208}, + {0.254403, 0.024805, -0.050389}, + {-0.182905, 0.021629, -0.168481}, + {-0.225864, -0.010109, -0.130374}, + {0.040089, 0.013969, 0.016028}, + {0.001442, 0.010551, 0.032942}, + {-0.287472, -0.036130, -0.296798}, + {-0.332344, -0.108862, -0.342196}, + {0.012700, 0.022917, -0.052501}, + {-0.040681, -0.001805, -0.050548}, + {-0.718522, -0.061234, -0.278820}, + {-0.879205, -0.213588, -0.303508}, + {-0.234102, -0.065407, 0.013686}, + {-0.281223, -0.076139, 0.046830}, + {0.141967, -0.193679, -0.055697}, + {0.100318, -0.161222, -0.063062}, + {0.265859, -0.132747, 0.078209}, + {0.244805, -0.139776, 0.122123}, + {-0.121802, -0.179976, 0.031732}, + {-0.185318, -0.214011, 0.018117}, + {0.047014, -0.153961, 0.218068}, + {0.047305, -0.187402, 0.282114}, + {-0.027533, -0.415868, -0.333841}, + {-0.125886, -0.334492, -0.290317}, + {-0.030602, -0.190918, 0.097454}, + {-0.054936, -0.209948, 0.158977}, + {-0.507223, -0.295876, -0.217183}, + {-0.581733, -0.403194, -0.208936}, + {-0.299719, -0.289679, 0.297101}, + {-0.363169, -0.362718, 0.436529}, + {-0.124627, -0.042100, -0.157011}, + {-0.161571, -0.092846, -0.183636}, + {0.084520, -0.100217, -0.000901}, + {0.055655, -0.136381, 0.032764}, + {-0.545087, -0.197713, -0.026888}, + {-0.662772, -0.179815, 0.026419}, + {-0.165583, -0.148913, 0.090382}, + {-0.240772, -0.182830, 0.105474}, + {-0.576315, -0.359473, -0.456844}, + {-0.713430, -0.554156, -0.476739}, + {-0.275628, -0.223640, -0.051584}, + {-0.359501, -0.230758, -0.027006}, + {-1.282559, -0.284807, -0.233743}, + {-1.060476, -0.399911, -0.562698}, + {-0.871952, -0.272197, 0.016126}, + {-0.747922, -0.329404, 0.276696}, + {0.643086, 0.046175, -0.660078}, + {0.738204, -0.127844, -0.433708}, + {1.158072, 0.025571, -0.177856}, + {0.974840, -0.009417, -0.112337}, + {0.418014, 0.032741, -0.124545}, + {0.381422, -0.001557, -0.085504}, + {0.768280, 0.056085, 0.095375}, + {0.680004, 0.052035, 0.152318}, + {0.473182, 0.012560, -0.264221}, + {0.345153, 0.036627, -0.248756}, + {0.746238, -0.025880, -0.106050}, + {0.644319, -0.058256, -0.095133}, + {0.185924, -0.022230, -0.070540}, + {0.146068, -0.009550, -0.057871}, + {0.338488, 0.013022, 0.069961}, + {0.298969, 0.047403, 0.052598}, + {0.346002, 0.256253, -0.380261}, + {0.313092, 0.163821, -0.314004}, + {0.719154, 0.103108, -0.252648}, + {0.621429, 0.172423, -0.265180}, + {0.240461, 0.104684, -0.202582}, + {0.206946, 0.139642, -0.138016}, + {0.359915, 0.101273, -0.052997}, + {0.318117, 0.125888, -0.003486}, + {0.150452, 0.050219, -0.409155}, + {0.188753, 0.091894, -0.325733}, + {0.334922, 0.029098, -0.098587}, + {0.324508, 0.015809, -0.135408}, + {-0.042506, 0.038667, -0.208535}, + {-0.083003, 0.094758, -0.174054}, + {0.094773, 0.102653, -0.025701}, + {0.063284, 0.118703, -0.000071}, + {0.355965, -0.139239, -0.191705}, + {0.392742, -0.105496, -0.132103}, + {0.663678, -0.204627, -0.031242}, + {0.609381, -0.146914, 0.079610}, + {0.151855, -0.132843, -0.007125}, + {0.146404, -0.161917, 0.024842}, + {0.400524, -0.135221, 0.232289}, + {0.324931, -0.116605, 0.253458}, + {0.169066, -0.215132, -0.185604}, + {0.128681, -0.189394, -0.160279}, + {0.356194, -0.116992, -0.038381}, + {0.342866, -0.144687, 0.020265}, + {-0.065545, -0.202593, -0.043688}, + {-0.124296, -0.260225, -0.035370}, + {0.083224, -0.235149, 0.153301}, + {0.046256, -0.309608, 0.190944}, + {0.187385, -0.008168, -0.198575}, + {0.190401, -0.018699, -0.136858}, + {0.398009, -0.025700, -0.007458}, + {0.346948, -0.022258, -0.020905}, + {-0.047064, -0.085629, -0.080677}, + {-0.067523, -0.128972, -0.119538}, + {0.186086, -0.016828, 0.070014}, + {0.187364, 0.017133, 0.075949}, + {-0.112669, -0.037433, -0.298944}, + {-0.068276, -0.114504, -0.265795}, + {0.147510, -0.040616, -0.013687}, + {0.133084, -0.062849, -0.032637}, + {-0.416571, -0.041544, -0.125088}, + {-0.505337, -0.044193, -0.157651}, + {-0.154132, -0.075106, 0.050466}, + {-0.148036, -0.059719, 0.121516}, + {0.490555, 0.157659, -0.222208}, + {0.436700, 0.120500, -0.205869}, + {0.754525, 0.269323, 0.045810}, + {0.645077, 0.271923, 0.013942}, + {0.237023, 0.115337, -0.026429}, + {0.204895, 0.121020, -0.008541}, + {0.383999, 0.153963, 0.171763}, + {0.385026, 0.222074, 0.239731}, + {0.198232, 0.072972, -0.108179}, + {0.147882, 0.074743, -0.123341}, + {0.390929, 0.075205, 0.081828}, + {0.341623, 0.089405, 0.069389}, + {-0.003381, 0.159694, -0.016026}, + {-0.043653, 0.206860, -0.040729}, + {0.135515, 0.107824, 0.179310}, + {0.081086, 0.119673, 0.174282}, + {0.192637, 0.400335, -0.341906}, + {0.171196, 0.284921, -0.221516}, + {0.377807, 0.359087, -0.151523}, + {0.411052, 0.297925, -0.099774}, + {-0.010060, 0.261887, -0.149567}, + {-0.107877, 0.287756, -0.116982}, + {0.158003, 0.209727, 0.077988}, + {0.109710, 0.232272, 0.088135}, + {0.000698, 0.209353, -0.395208}, + {-0.094015, 0.230322, -0.279928}, + {0.137355, 0.230881, -0.124115}, + {0.103058, 0.166855, -0.100386}, + {-0.305058, 0.305422, -0.176026}, + {-0.422049, 0.337137, -0.293297}, + {-0.121744, 0.185124, 0.048115}, + {-0.171052, 0.200312, 0.052812}, + {0.224091, -0.010673, -0.019727}, + {0.200266, -0.020167, 0.001798}, + {0.382742, 0.032362, 0.161665}, + {0.345631, -0.019705, 0.164451}, + {0.029431, 0.045010, 0.071518}, + {0.031940, 0.010876, 0.087037}, + {0.181935, 0.039112, 0.202316}, + {0.181810, 0.033189, 0.253435}, + {-0.008677, -0.066679, -0.144737}, + {-0.021768, -0.021288, -0.125903}, + {0.136766, 0.000100, 0.059449}, + {0.135405, -0.020446, 0.103793}, + {-0.289115, 0.039747, -0.012256}, + {-0.338683, 0.025909, -0.034058}, + {-0.016515, 0.048584, 0.197981}, + {-0.046790, 0.011816, 0.199964}, + {0.094214, 0.127422, -0.169936}, + {0.048279, 0.096189, -0.148153}, + {0.217391, 0.081732, 0.013677}, + {0.179656, 0.084671, 0.031434}, + {-0.227367, 0.118176, -0.039803}, + {-0.327096, 0.159747, -0.018931}, + {0.000834, 0.113118, 0.125325}, + {-0.014617, 0.128924, 0.163776}, + {-0.254570, 0.154329, -0.232018}, + {-0.353068, 0.124341, -0.174409}, + {-0.061004, 0.107744, 0.037257}, + {-0.100991, 0.080302, 0.062701}, + {-0.927022, 0.285660, -0.240549}, + {-1.153224, 0.277232, -0.322538}, + {-0.569012, 0.108135, 0.172634}, + {-0.555273, 0.131461, 0.325930}, + {0.518847, 0.065683, -0.132877}, + {0.501324, -0.006585, -0.094884}, + {1.066190, -0.150380, 0.201791}, + {0.858377, -0.166415, 0.081686}, + {0.320584, -0.031499, 0.039534}, + {0.311442, -0.075120, 0.026013}, + {0.625829, -0.019856, 0.346041}, + {0.525271, -0.003948, 0.284868}, + {0.312594, -0.075673, -0.066642}, + {0.295732, -0.057895, -0.042207}, + {0.550446, -0.029110, 0.046850}, + {0.465467, -0.068987, 0.096167}, + {0.122669, -0.051786, 0.044283}, + {0.079669, -0.044145, 0.045805}, + {0.238778, -0.031835, 0.171694}, + {0.200734, -0.072619, 0.178726}, + {0.342512, 0.131270, -0.163021}, + {0.294028, 0.111759, -0.125793}, + {0.589523, 0.121808, -0.049372}, + {0.550506, 0.132318, 0.017485}, + {0.164280, 0.047560, -0.058383}, + {0.120110, 0.049242, -0.052403}, + {0.269181, 0.035000, 0.103494}, + {0.297466, 0.038517, 0.139289}, + {0.094549, -0.030880, -0.153376}, + {0.080363, 0.024359, -0.127578}, + {0.281351, 0.055178, 0.000155}, + {0.234900, 0.039477, 0.013957}, + {-0.118161, 0.011976, -0.034270}, + {-0.157654, 0.027765, -0.005010}, + {0.102631, 0.027283, 0.099723}, + {0.077285, 0.052532, 0.115583}, + {0.329398, -0.278552, 0.016316}, + {0.305993, -0.267896, 0.094952}, + {0.775270, -0.394995, 0.290748}, + {0.583180, -0.252159, 0.285391}, + {0.192226, -0.182242, 0.126859}, + {0.185908, -0.245779, 0.159940}, + {0.346293, -0.250404, 0.355682}, + {0.354160, -0.364521, 0.472337}, + {0.134942, -0.313666, -0.115181}, + {0.126077, -0.286568, -0.039927}, + {0.405618, -0.211792, 0.199095}, + {0.312099, -0.213642, 0.190972}, + {-0.071392, -0.297366, 0.081426}, + {-0.165839, -0.301986, 0.160640}, + {0.147808, -0.290712, 0.298198}, + {0.063302, -0.310149, 0.396302}, + {0.141444, -0.081377, -0.076621}, + {0.115936, -0.104440, -0.039885}, + {0.367023, -0.087281, 0.096390}, + {0.330038, -0.117958, 0.127050}, + {0.002897, -0.062454, 0.025151}, + {-0.052404, -0.082200, 0.041975}, + {0.181553, -0.137004, 0.230489}, + {0.140768, -0.094604, 0.265928}, + {-0.101763, -0.209566, -0.135964}, + {-0.159056, -0.191005, -0.095509}, + {0.045016, -0.081562, 0.075942}, + {0.016808, -0.112482, 0.068593}, + {-0.408578, -0.132377, 0.079163}, + {-0.431534, -0.214646, 0.157714}, + {-0.096931, -0.101938, 0.200304}, + {-0.167867, -0.114851, 0.262964}, + {0.393882, 0.086002, 0.008961}, + {0.338747, 0.048405, -0.004187}, + {0.877844, 0.374373, 0.171008}, + {0.740790, 0.324525, 0.242248}, + {0.200218, 0.070150, 0.085891}, + {0.171760, 0.090531, 0.102579}, + {0.314263, 0.126417, 0.322833}, + {0.313523, 0.065445, 0.403855}, + {0.164261, 0.057745, -0.005490}, + {0.122141, 0.024122, 0.009190}, + {0.308248, 0.078401, 0.180577}, + {0.251222, 0.073868, 0.160457}, + {-0.047526, 0.023725, 0.086336}, + {-0.091643, 0.005539, 0.093179}, + {0.079339, 0.044135, 0.206697}, + {0.104213, 0.011277, 0.240060}, + {0.226607, 0.186234, -0.056881}, + {0.173281, 0.158131, -0.059413}, + {0.339400, 0.214501, 0.052905}, + {0.309166, 0.188181, 0.058028}, + {0.014442, 0.194715, 0.048945}, + {-0.028793, 0.194766, 0.089078}, + {0.069564, 0.206743, 0.193568}, + {0.091532, 0.202786, 0.269680}, + {-0.071196, 0.135604, -0.103744}, + {-0.118288, 0.152837, -0.060151}, + {0.146856, 0.143174, 0.061789}, + {0.104379, 0.143672, 0.056797}, + {-0.541832, 0.250034, -0.017602}, + {-0.641583, 0.278411, -0.111909}, + {-0.094447, 0.159393, 0.164848}, + {-0.113612, 0.120702, 0.221656}, + {0.204918, -0.078894, 0.075524}, + {0.161232, -0.090256, 0.088701}, + {0.378460, -0.033687, 0.309964}, + {0.311701, -0.049984, 0.316881}, + {0.019311, -0.050048, 0.212387}, + {0.002473, -0.062855, 0.278462}, + {0.151448, -0.090652, 0.410031}, + {0.162778, -0.071291, 0.531252}, + {-0.083704, -0.076839, -0.020798}, + {-0.092832, -0.043492, 0.029202}, + {0.136844, -0.077791, 0.186493}, + {0.089536, -0.086826, 0.184711}, + {-0.270255, -0.058858, 0.173048}, + {-0.350416, -0.009219, 0.273260}, + {-0.105248, -0.205534, 0.425159}, + {-0.135030, -0.197464, 0.623550}, + {-0.051717, 0.069756, -0.043829}, + {-0.081050, 0.056947, -0.000205}, + {0.190388, 0.016366, 0.145922}, + {0.142662, 0.002575, 0.159182}, + {-0.352890, 0.011117, 0.091040}, + {-0.367374, 0.056547, 0.147209}, + {-0.003179, 0.026570, 0.282541}, + {-0.069934, -0.005171, 0.337678}, + {-0.496181, 0.026464, 0.019432}, + {-0.690384, 0.069313, -0.004175}, + {-0.146138, 0.046372, 0.161839}, + {-0.197581, 0.034093, 0.241003}, + {-0.989567, 0.040993, 0.049384}, + {-1.151075, 0.210556, 0.237374}, + {-0.335366, -0.058208, 0.480168}, + {-0.502419, -0.093761, 0.675240}, + {0.862548, 0.264137, -0.294905}, + {0.782668, 0.251324, -0.122108}, + {1.597797, 0.463818, -0.133153}, + {1.615756, 0.060653, 0.084764}, + {0.435588, 0.209832, 0.095050}, + {0.431013, 0.165328, 0.047909}, + {1.248164, 0.265923, 0.488086}, + {1.009933, 0.345440, 0.473702}, + {0.477017, 0.194237, -0.058012}, + {0.401362, 0.186915, -0.054137}, + {1.202158, 0.284782, -0.066531}, + {1.064907, 0.203766, 0.046383}, + {0.255848, 0.133398, 0.046049}, + {0.218680, 0.128833, 0.065326}, + {0.490817, 0.182041, 0.286583}, + {0.440714, 0.106576, 0.301120}, + {0.604263, 0.522925, -0.238629}, + {0.526329, 0.377577, -0.198100}, + {1.038632, 0.606242, -0.121253}, + {0.995283, 0.552202, 0.110700}, + {0.262232, 0.313664, -0.086909}, + {0.230835, 0.273385, -0.054268}, + {0.548466, 0.490721, 0.278201}, + {0.466984, 0.355859, 0.289160}, + {0.367137, 0.236160, -0.228114}, + {0.309359, 0.233843, -0.171325}, + {0.465268, 0.276569, 0.010951}, + {0.378124, 0.250237, 0.011131}, + {0.061885, 0.296810, -0.011420}, + {0.000125, 0.350029, -0.011277}, + {0.163815, 0.261191, 0.175863}, + {0.165132, 0.308797, 0.227800}, + {0.461418, 0.052075, -0.016543}, + {0.472372, 0.046962, 0.045746}, + {0.856406, 0.136415, 0.245074}, + {0.834616, 0.003254, 0.372643}, + {0.337869, 0.036994, 0.232513}, + {0.267414, 0.027593, 0.252779}, + {0.584983, 0.113046, 0.583119}, + {0.475406, -0.024234, 0.655070}, + {0.264823, -0.029292, 0.004270}, + {0.246071, -0.019109, 0.030048}, + {0.477401, 0.021039, 0.155448}, + {0.458453, -0.043959, 0.187850}, + {0.067059, -0.061227, 0.126904}, + {0.044608, -0.034575, 0.150205}, + {0.191304, -0.003810, 0.316776}, + {0.153078, 0.029915, 0.361303}, + {0.320704, 0.178950, -0.088835}, + {0.300866, 0.137645, -0.056893}, + {0.553442, 0.162339, 0.131987}, + {0.490083, 0.123682, 0.146163}, + {0.118950, 0.083109, 0.034052}, + {0.099344, 0.066212, 0.054329}, + {0.228325, 0.122445, 0.309219}, + {0.172093, 0.135754, 0.323361}, + {0.064213, 0.063405, -0.058243}, + {0.011906, 0.088795, -0.069678}, + {0.194232, 0.129185, 0.125708}, + {0.155182, 0.174013, 0.144099}, + {-0.217068, 0.112731, 0.093497}, + {-0.307590, 0.171146, 0.110735}, + {-0.014897, 0.138094, 0.232455}, + {-0.036936, 0.170135, 0.279166}, + {0.681886, 0.437121, 0.078458}, + {0.548559, 0.376914, 0.092485}, + {1.259194, 0.901494, 0.256085}, + {1.296139, 0.607949, 0.302184}, + {0.319619, 0.307231, 0.099647}, + {0.287232, 0.359355, 0.186844}, + {0.751306, 0.676688, 0.499386}, + {0.479609, 0.553030, 0.560447}, + {0.276377, 0.214032, -0.003661}, + {0.238146, 0.223595, 0.028806}, + {0.542688, 0.266205, 0.171393}, + {0.460188, 0.283979, 0.158288}, + {0.057385, 0.309853, 0.144517}, + {-0.006881, 0.348152, 0.097310}, + {0.244434, 0.247298, 0.322601}, + {0.253992, 0.335420, 0.402241}, + {0.354006, 0.579776, -0.130176}, + {0.267043, 0.461976, -0.058178}, + {0.534049, 0.626549, 0.046747}, + {0.441835, 0.468260, 0.057556}, + {0.110477, 0.628795, 0.102950}, + {0.031409, 0.489068, 0.090605}, + {0.229564, 0.525640, 0.325454}, + {0.105570, 0.582151, 0.509738}, + {0.005690, 0.521474, -0.157885}, + {0.104463, 0.424022, -0.080647}, + {0.223784, 0.389860, 0.060904}, + {0.159806, 0.340571, 0.062061}, + {-0.173976, 0.573425, 0.027383}, + {-0.376008, 0.587868, 0.133042}, + {-0.051773, 0.348339, 0.231923}, + {-0.122571, 0.473049, 0.251159}, + {0.324321, 0.148510, 0.116006}, + {0.282263, 0.121730, 0.114016}, + {0.690108, 0.256346, 0.418128}, + {0.542523, 0.294427, 0.461973}, + {0.056944, 0.107667, 0.281797}, + {0.027844, 0.106858, 0.355071}, + {0.160456, 0.177656, 0.528819}, + {0.227537, 0.177976, 0.689465}, + {0.111585, 0.097896, 0.109244}, + {0.083994, 0.133245, 0.115789}, + {0.208740, 0.142084, 0.208953}, + {0.156072, 0.143303, 0.231368}, + {-0.185830, 0.214347, 0.309774}, + {-0.311053, 0.240517, 0.328512}, + {-0.041749, 0.090901, 0.511373}, + {-0.156164, 0.098486, 0.478020}, + {0.151543, 0.263073, -0.033471}, + {0.126322, 0.213004, -0.007014}, + {0.245313, 0.217564, 0.120210}, + {0.259136, 0.225542, 0.176601}, + {-0.190632, 0.260214, 0.141755}, + {-0.189271, 0.331768, 0.170606}, + {0.054763, 0.294766, 0.357775}, + {-0.033724, 0.257645, 0.365069}, + {-0.184971, 0.396532, 0.057728}, + {-0.293313, 0.400259, 0.001123}, + {-0.015219, 0.232287, 0.177913}, + {-0.022524, 0.244724, 0.240753}, + {-0.520342, 0.347950, 0.249265}, + {-0.671997, 0.410782, 0.153434}, + {-0.253089, 0.412356, 0.489854}, + {-0.410922, 0.562454, 0.543891} +}; + +/* + * PRBA58 Vector Quantizer Levels + */ +const float AmbePRBA58[128][4] = { + {-0.103660, 0.094597, -0.013149, 0.081501}, + {-0.170709, 0.129958, -0.057316, 0.112324}, + {-0.095113, 0.080892, -0.027554, 0.003371}, + {-0.154153, 0.113437, -0.074522, 0.003446}, + {-0.109553, 0.153519, 0.006858, 0.040930}, + {-0.181931, 0.217882, -0.019042, 0.040049}, + {-0.096246, 0.144191, -0.024147, -0.035120}, + {-0.174811, 0.193357, -0.054261, -0.071700}, + {-0.183241, -0.052840, 0.117923, 0.030960}, + {-0.242634, 0.009075, 0.098007, 0.091643}, + {-0.143847, -0.028529, 0.040171, -0.002812}, + {-0.198809, 0.006990, 0.020668, 0.026641}, + {-0.233172, -0.028793, 0.140130, -0.071927}, + {-0.309313, 0.056873, 0.108262, -0.018930}, + {-0.172782, -0.002037, 0.048755, -0.087065}, + {-0.242901, 0.036076, 0.015064, -0.064366}, + {0.077107, 0.172685, 0.159939, 0.097456}, + {0.024820, 0.209676, 0.087347, 0.105204}, + {0.085113, 0.151639, 0.084272, 0.022747}, + {0.047975, 0.196695, 0.038770, 0.029953}, + {0.113925, 0.236813, 0.176121, 0.016635}, + {0.009708, 0.267969, 0.127660, 0.015872}, + {0.114044, 0.202311, 0.096892, -0.043071}, + {0.047219, 0.260395, 0.050952, -0.046996}, + {-0.055095, 0.034041, 0.200464, 0.039050}, + {-0.061582, 0.069566, 0.113048, 0.027511}, + {-0.025469, 0.040440, 0.132777, -0.039098}, + {-0.031388, 0.064010, 0.067559, -0.017117}, + {-0.074386, 0.086579, 0.228232, -0.055461}, + {-0.107352, 0.120874, 0.137364, -0.030252}, + {-0.036897, 0.089972, 0.155831, -0.128475}, + {-0.059070, 0.097879, 0.084489, -0.075821}, + {-0.050865, -0.025167, -0.086636, 0.011256}, + {-0.051426, 0.013301, -0.144665, 0.038541}, + {-0.073831, -0.028917, -0.142416, -0.025268}, + {-0.083910, 0.015004, -0.227113, -0.002808}, + {-0.030840, -0.009326, -0.070517, -0.041304}, + {-0.022018, 0.029381, -0.124961, -0.031624}, + {-0.064222, -0.014640, -0.108798, -0.092342}, + {-0.038801, 0.038133, -0.188992, -0.094221}, + {-0.154059, -0.183932, -0.019894, 0.082105}, + {-0.188022, -0.113072, -0.117380, 0.090911}, + {-0.243301, -0.207086, -0.053735, -0.001975}, + {-0.275931, -0.121035, -0.161261, 0.004231}, + {-0.118142, -0.157537, -0.036594, -0.008679}, + {-0.153627, -0.111372, -0.103095, -0.009460}, + {-0.173458, -0.180158, -0.057130, -0.103198}, + {-0.208509, -0.127679, -0.149336, -0.109289}, + {0.096310, 0.047927, -0.024094, -0.057018}, + {0.044289, 0.075486, -0.008505, -0.067635}, + {0.076751, 0.025560, -0.066428, -0.102991}, + {0.025215, 0.090417, -0.058616, -0.114284}, + {0.125980, 0.070078, 0.016282, -0.112355}, + {0.070859, 0.118988, 0.001180, -0.116359}, + {0.097520, 0.059219, -0.026821, -0.172850}, + {0.048226, 0.145459, -0.050093, -0.188853}, + {0.007242, -0.135796, 0.147832, -0.034080}, + {0.012843, -0.069616, 0.077139, -0.047909}, + {-0.050911, -0.116323, 0.082521, -0.056362}, + {-0.039630, -0.055678, 0.036066, -0.067992}, + {0.042694, -0.091527, 0.150940, -0.124225}, + {0.029225, -0.039401, 0.071664, -0.113665}, + {-0.025085, -0.099013, 0.074622, -0.138674}, + {-0.031220, -0.035717, 0.020870, -0.143376}, + {0.040638, 0.087903, -0.049500, 0.094607}, + {0.026860, 0.125924, -0.103449, 0.140882}, + {0.075166, 0.110186, -0.115173, 0.067330}, + {0.036642, 0.163193, -0.188762, 0.103724}, + {0.028179, 0.095124, -0.053258, 0.028900}, + {0.002307, 0.148211, -0.096037, 0.046189}, + {0.072227, 0.137595, -0.095629, 0.001339}, + {0.033308, 0.221480, -0.152201, 0.012125}, + {0.003458, -0.085112, 0.041850, 0.113836}, + {-0.040610, -0.044880, 0.029732, 0.177011}, + {0.011404, -0.054324, -0.012426, 0.077815}, + {-0.042413, -0.030930, -0.034844, 0.122946}, + {-0.002206, -0.045698, 0.050651, 0.054886}, + {-0.041729, -0.016110, 0.048005, 0.102125}, + {0.013963, -0.022204, 0.001613, 0.028997}, + {-0.030218, -0.002052, -0.004365, 0.065343}, + {0.299049, 0.046260, 0.076320, 0.070784}, + {0.250160, 0.098440, 0.012590, 0.137479}, + {0.254170, 0.095310, 0.018749, 0.004288}, + {0.218892, 0.145554, -0.035161, 0.069784}, + {0.303486, 0.101424, 0.135996, -0.013096}, + {0.262919, 0.165133, 0.077237, 0.071721}, + {0.319358, 0.170283, 0.054554, -0.072210}, + {0.272983, 0.231181, -0.014471, 0.011689}, + {0.134116, -0.026693, 0.161400, 0.110292}, + {0.100379, 0.026517, 0.086236, 0.130478}, + {0.144718, -0.000895, 0.093767, 0.044514}, + {0.114943, 0.022145, 0.035871, 0.069193}, + {0.122051, 0.011043, 0.192803, 0.022796}, + {0.079482, 0.026156, 0.117725, 0.056565}, + {0.124641, 0.027387, 0.122956, -0.025369}, + {0.090708, 0.027357, 0.064450, 0.013058}, + {0.159781, -0.055202, -0.090597, 0.151598}, + {0.084577, -0.037203, -0.126698, 0.119739}, + {0.192484, -0.100195, -0.162066, 0.104148}, + {0.114579, -0.046270, -0.219547, 0.100067}, + {0.153083, -0.010127, -0.086266, 0.068648}, + {0.088202, -0.010515, -0.102196, 0.046281}, + {0.164494, -0.057325, -0.132860, 0.024093}, + {0.109419, -0.013999, -0.169596, 0.020412}, + {0.039180, -0.209168, -0.035872, 0.087949}, + {0.012790, -0.177723, -0.129986, 0.073364}, + {0.045261, -0.256694, -0.088186, 0.004212}, + {-0.005314, -0.231202, -0.191671, -0.002628}, + {0.037963, -0.153227, -0.045364, 0.003322}, + {0.030800, -0.126452, -0.114266, -0.010414}, + {0.044125, -0.184146, -0.081400, -0.077341}, + {0.029204, -0.157393, -0.172017, -0.089814}, + {0.393519, -0.043228, -0.111365, -0.000740}, + {0.289581, 0.018928, -0.123140, 0.000713}, + {0.311229, -0.059735, -0.198982, -0.081664}, + {0.258659, 0.052505, -0.211913, -0.034928}, + {0.300693, 0.011381, -0.083545, -0.086683}, + {0.214523, 0.053878, -0.101199, -0.061018}, + {0.253422, 0.028496, -0.156752, -0.163342}, + {0.199123, 0.113877, -0.166220, -0.102584}, + {0.249134, -0.165135, 0.028917, 0.051838}, + {0.156434, -0.123708, 0.017053, 0.043043}, + {0.214763, -0.101243, -0.005581, -0.020703}, + {0.140554, -0.072067, -0.015063, -0.011165}, + {0.241791, -0.152048, 0.106403, -0.046857}, + {0.142316, -0.131899, 0.054076, -0.026485}, + {0.206535, -0.086116, 0.046640, -0.097615}, + {0.129759, -0.081874, 0.004693, -0.073169} +}; + +/* + * Higher Order Coefficients + */ +const float AmbeHOCb5[32][4] = { + {0.264108, 0.045976, -0.200999, -0.122344}, + {0.479006, 0.227924, -0.016114, -0.006835}, + {0.077297, 0.080775, -0.068936, 0.041733}, + {0.185486, 0.231840, 0.182410, 0.101613}, + {-0.012442, 0.223718, -0.277803, -0.034370}, + {-0.059507, 0.139621, -0.024708, -0.104205}, + {-0.248676, 0.255502, -0.134894, -0.058338}, + {-0.055122, 0.427253, 0.025059, -0.045051}, + {-0.058898, -0.061945, 0.028030, -0.022242}, + {0.084153, 0.025327, 0.066780, -0.180839}, + {-0.193125, -0.082632, 0.140899, -0.089559}, + {0.000000, 0.033758, 0.276623, 0.002493}, + {-0.396582, -0.049543, -0.118100, -0.208305}, + {-0.287112, 0.096620, 0.049650, -0.079312}, + {-0.543760, 0.171107, -0.062173, -0.010483}, + {-0.353572, 0.227440, 0.230128, -0.032089}, + {0.248579, -0.279824, -0.209589, 0.070903}, + {0.377604, -0.119639, 0.008463, -0.005589}, + {0.102127, -0.093666, -0.061325, 0.052082}, + {0.154134, -0.105724, 0.099317, 0.187972}, + {-0.139232, -0.091146, -0.275479, -0.038435}, + {-0.144169, 0.034314, -0.030840, 0.022207}, + {-0.143985, 0.079414, -0.194701, 0.175312}, + {-0.195329, 0.087467, 0.067711, 0.186783}, + {-0.123515, -0.377873, -0.209929, -0.212677}, + {0.068698, -0.255933, 0.120463, -0.095629}, + {-0.106810, -0.319964, -0.089322, 0.106947}, + {-0.158605, -0.309606, 0.190900, 0.089340}, + {-0.489162, -0.432784, -0.151215, -0.005786}, + {-0.370883, -0.154342, -0.022545, 0.114054}, + {-0.742866, -0.204364, -0.123865, -0.038888}, + {-0.573077, -0.115287, 0.208879, -0.027698} +}; + +/* + * Higher Order Coefficients + */ +const float AmbeHOCb6[16][4] = { + {-0.143886, 0.235528, -0.116707, 0.025541}, + {-0.170182, -0.063822, -0.096934, 0.109704}, + {0.232915, 0.269793, 0.047064, -0.032761}, + {0.153458, 0.068130, -0.033513, 0.126553}, + {-0.440712, 0.132952, 0.081378, -0.013210}, + {-0.480433, -0.249687, -0.012280, 0.007112}, + {-0.088001, 0.167609, 0.148323, -0.119892}, + {-0.104628, 0.102639, 0.183560, 0.121674}, + {0.047408, -0.000908, -0.214196, -0.109372}, + {0.113418, -0.240340, -0.121420, 0.041117}, + {0.385609, 0.042913, -0.184584, -0.017851}, + {0.453830, -0.180745, 0.050455, 0.030984}, + {-0.155984, -0.144212, 0.018226, -0.146356}, + {-0.104028, -0.260377, 0.146472, 0.101389}, + {0.012376, -0.000267, 0.006657, -0.013941}, + {0.165852, -0.103467, 0.119713, -0.075455} +}; + +/* + * Higher Order Coefficients + */ +const float AmbeHOCb7[16][4] = { + {0.182478, 0.271794, -0.057639, 0.026115}, + {0.110795, 0.092854, 0.078125, -0.082726}, + {0.057964, 0.000833, 0.176048, 0.135404}, + {-0.027315, 0.098668, -0.065801, 0.116421}, + {-0.222796, 0.062967, 0.201740, -0.089975}, + {-0.193571, 0.309225, -0.014101, -0.034574}, + {-0.389053, -0.181476, 0.107682, 0.050169}, + {-0.345604, 0.064900, -0.065014, 0.065642}, + {0.319393, -0.055491, -0.220727, -0.067499}, + {0.460572, 0.084686, 0.048453, -0.011050}, + {0.201623, -0.068994, -0.067101, 0.108320}, + {0.227528, -0.173900, 0.092417, -0.066515}, + {-0.016927, 0.047757, -0.177686, -0.102163}, + {-0.052553, -0.065689, 0.019328, -0.033060}, + {-0.144910, -0.238617, -0.195206, -0.063917}, + {-0.024159, -0.338822, 0.003581, 0.060995} +}; + +/* + * Higher Order Coefficients + */ +const float AmbeHOCb8[8][4] = { + {0.323968, 0.008964, -0.063117, 0.027909}, + {0.010900, -0.004030, -0.125016, -0.080818}, + {0.109969, 0.256272, 0.042470, 0.000749}, + {-0.135446, 0.201769, -0.083426, 0.093888}, + {-0.441995, 0.038159, 0.022784, 0.003943}, + {-0.155951, 0.032467, 0.145309, -0.041725}, + {-0.149182, -0.223356, -0.065793, 0.075016}, + {0.096949, -0.096400, 0.083194, 0.049306} +}; + +#endif /* _AMBE3600x2450_CONST_H */ diff --git a/mbelib-wasm/mbelib/cmake_uninstall.cmake.in b/mbelib-wasm/mbelib/cmake_uninstall.cmake.in new file mode 100644 index 0000000..4dc1b63 --- /dev/null +++ b/mbelib-wasm/mbelib/cmake_uninstall.cmake.in @@ -0,0 +1,23 @@ +if (NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") + message(FATAL_ERROR "Cannot find install manifest: \"@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt\"") +endif(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") + +file(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files) +string(REGEX REPLACE "\n" ";" files "${files}") +cmake_policy(SET CMP0007 OLD) +list(REVERSE files) +foreach (file ${files}) + message(STATUS "Uninstalling \"$ENV{DESTDIR}${file}\"") + if (EXISTS "$ENV{DESTDIR}${file}") + execute_process( + COMMAND @CMAKE_COMMAND@ -E remove "$ENV{DESTDIR}${file}" + OUTPUT_VARIABLE rm_out + RESULT_VARIABLE rm_retval + ) + if(NOT ${rm_retval} EQUAL 0) + message(FATAL_ERROR "Problem when removing \"$ENV{DESTDIR}${file}\"") + endif (NOT ${rm_retval} EQUAL 0) + else (EXISTS "$ENV{DESTDIR}${file}") + message(STATUS "File \"$ENV{DESTDIR}${file}\" does not exist.") + endif (EXISTS "$ENV{DESTDIR}${file}") +endforeach(file) \ No newline at end of file diff --git a/mbelib-wasm/mbelib/config.h b/mbelib-wasm/mbelib/config.h new file mode 100644 index 0000000..4442f41 --- /dev/null +++ b/mbelib-wasm/mbelib/config.h @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2010 mbelib Author + * GPG Key ID: 0xEA5EFE2C (9E7A 5527 9CDC EBF7 BF1B D772 4F98 E863 EA5E FE2C) + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +/* + * very noisy debug/developer options + */ + +//#define MBE_DEBUG +//#define IMBE_DEBUG +//#define AMBE_DEBUG diff --git a/mbelib-wasm/mbelib/debian/changelog b/mbelib-wasm/mbelib/debian/changelog new file mode 100644 index 0000000..8e804cb --- /dev/null +++ b/mbelib-wasm/mbelib/debian/changelog @@ -0,0 +1,5 @@ +libmbe (1.3.0) bionic; urgency=low + + * Initial upload! + + -- Jared Szechy Wed, 27 Jun 2018 23:00:00 -0400 diff --git a/mbelib-wasm/mbelib/debian/compat b/mbelib-wasm/mbelib/debian/compat new file mode 100644 index 0000000..f11c82a --- /dev/null +++ b/mbelib-wasm/mbelib/debian/compat @@ -0,0 +1 @@ +9 \ No newline at end of file diff --git a/mbelib-wasm/mbelib/debian/control b/mbelib-wasm/mbelib/debian/control new file mode 100644 index 0000000..40227eb --- /dev/null +++ b/mbelib-wasm/mbelib/debian/control @@ -0,0 +1,34 @@ +Source: libmbe +Section: libs +Priority: optional +Maintainer: Jared Szechy +Build-Depends: debhelper (>= 9), cmake +Standards-Version: 4.1.4 +Homepage: https://github.com/szechyjs/mbelib +Vcs-Git: https://github.com/szechyjs/mbelib.git +Vcs-Browser: https://github.com/szechyjs/mbelib + +Package: libmbe-dev +Section: libdevel +Architecture: any +Multi-Arch: same +Depends: libmbe1 (= ${binary:Version}), ${misc:Depends} +Description: P25 Phase 1 and ProVoice vocoder - development kit + libMBE supports the 7200x4400 bit/s codec used in P25 Phase 1, + the 7100x4400 bit/s codec used in ProVoice and the "Half Rate" + 3600x2250 bit/s vocoder used in various radio systems. + . + This package contains the development files for libmbe. + +Package: libmbe1 +Section: libs +Architecture: any +Multi-Arch: same +Pre-Depends: ${misc:Pre-Depends} +Depends: ${shlibs:Depends}, ${misc:Depends} +Description: P25 Phase 1 and ProVoice vocoder - runtime library + libMBE supports the 7200x4400 bit/s codec used in P25 Phase 1, + the 7100x4400 bit/s codec used in ProVoice and the "Half Rate" + 3600x2250 bit/s vocoder used in various radio systems. + . + This package contains the libmbe library used by applications. \ No newline at end of file diff --git a/mbelib-wasm/mbelib/debian/copyright b/mbelib-wasm/mbelib/debian/copyright new file mode 100644 index 0000000..12be944 --- /dev/null +++ b/mbelib-wasm/mbelib/debian/copyright @@ -0,0 +1,14 @@ +Copyright (C) 2010 mbelib Author +GPG Key ID: 0xEA5EFE2C (9E7A 5527 9CDC EBF7 BF1B D772 4F98 E863 EA5E FE2C) + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THIS SOFTWARE. diff --git a/mbelib-wasm/mbelib/debian/libmbe-dev.install b/mbelib-wasm/mbelib/debian/libmbe-dev.install new file mode 100644 index 0000000..4cc6806 --- /dev/null +++ b/mbelib-wasm/mbelib/debian/libmbe-dev.install @@ -0,0 +1,4 @@ +usr/include +usr/lib/*/*.so +usr/lib/*/*.a +usr/lib/*/pkgconfig \ No newline at end of file diff --git a/mbelib-wasm/mbelib/debian/libmbe1.install b/mbelib-wasm/mbelib/debian/libmbe1.install new file mode 100644 index 0000000..a451edd --- /dev/null +++ b/mbelib-wasm/mbelib/debian/libmbe1.install @@ -0,0 +1 @@ +/usr/lib/*/*.so.* diff --git a/mbelib-wasm/mbelib/debian/rules b/mbelib-wasm/mbelib/debian/rules new file mode 100644 index 0000000..ed7f152 --- /dev/null +++ b/mbelib-wasm/mbelib/debian/rules @@ -0,0 +1,4 @@ +#!/usr/bin/make -f + +%: + dh $@ \ No newline at end of file diff --git a/mbelib-wasm/mbelib/debian/source/format b/mbelib-wasm/mbelib/debian/source/format new file mode 100644 index 0000000..9f67427 --- /dev/null +++ b/mbelib-wasm/mbelib/debian/source/format @@ -0,0 +1 @@ +3.0 (native) \ No newline at end of file diff --git a/mbelib-wasm/mbelib/ecc.c b/mbelib-wasm/mbelib/ecc.c new file mode 100644 index 0000000..4a2e41d --- /dev/null +++ b/mbelib-wasm/mbelib/ecc.c @@ -0,0 +1,172 @@ +/* + * Copyright (C) 2010 mbelib Author + * GPG Key ID: 0xEA5EFE2C (9E7A 5527 9CDC EBF7 BF1B D772 4F98 E863 EA5E FE2C) + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include "ecc_const.h" + +void +mbe_checkGolayBlock (long int *block) +{ + + static int i, syndrome, eccexpected, eccbits, databits; + long int mask, block_l; + + block_l = *block; + + mask = 0x400000l; + eccexpected = 0; + for (i = 0; i < 12; i++) + { + if ((block_l & mask) != 0l) + { + eccexpected ^= golayGenerator[i]; + } + mask = mask >> 1; + } + eccbits = (int) (block_l & 0x7ffl); + syndrome = eccexpected ^ eccbits; + + databits = (int) (block_l >> 11); + databits = databits ^ golayMatrix[syndrome]; + + *block = (long) databits; +} + +int +mbe_golay2312 (char *in, char *out) +{ + + int i, errs; + long block; + + block = 0; + for (i = 22; i >= 0; i--) + { + block = block << 1; + block = block + in[i]; + } + + mbe_checkGolayBlock (&block); + + for (i = 22; i >= 11; i--) + { + out[i] = (block & 2048) >> 11; + block = block << 1; + } + for (i = 10; i >= 0; i--) + { + out[i] = in[i]; + } + + errs = 0; + for (i = 22; i >= 11; i--) + { + if (out[i] != in[i]) + { + errs++; + } + } + return (errs); +} + +int +mbe_hamming1511 (char *in, char *out) +{ + int i, j, errs, block, syndrome, stmp, stmp2; + + errs = 0; + + block = 0; + for (i = 14; i >= 0; i--) + { + block <<= 1; + block |= in[i]; + } + + syndrome = 0; + for (i = 0; i < 4; i++) + { + syndrome <<= 1; + stmp = block; + stmp &= hammingGenerator[i]; + + stmp2 = (stmp % 2); + for (j = 0; j < 14; j++) + { + stmp >>= 1; + stmp2 ^= (stmp % 2); + } + + syndrome |= stmp2; + } + if (syndrome > 0) + { + errs++; + block ^= hammingMatrix[syndrome]; + } + + for (i = 14; i >= 0; i--) + { + out[i] = (block & 0x4000) >> 14; + block = block << 1; + } + return (errs); +} + +int +mbe_7100x4400hamming1511 (char *in, char *out) +{ + int i, j, errs, block, syndrome, stmp, stmp2; + + errs = 0; + + block = 0; + for (i = 14; i >= 0; i--) + { + block <<= 1; + block |= in[i]; + } + + syndrome = 0; + for (i = 0; i < 4; i++) + { + syndrome <<= 1; + stmp = block; + stmp &= imbe7100x4400hammingGenerator[i]; + + stmp2 = (stmp % 2); + for (j = 0; j < 14; j++) + { + stmp >>= 1; + stmp2 ^= (stmp % 2); + } + + syndrome |= stmp2; + } + if (syndrome > 0) + { + errs++; + block ^= hammingMatrix[syndrome]; + } + + for (i = 14; i >= 0; i--) + { + out[i] = (block & 0x4000) >> 14; + block = block << 1; + } + return (errs); +} diff --git a/mbelib-wasm/mbelib/ecc_const.h b/mbelib-wasm/mbelib/ecc_const.h new file mode 100644 index 0000000..e602f3a --- /dev/null +++ b/mbelib-wasm/mbelib/ecc_const.h @@ -0,0 +1,112 @@ +/* + * Copyright (C) 2010 mbelib Author + * GPG Key ID: 0xEA5EFE2C (9E7A 5527 9CDC EBF7 BF1B D772 4F98 E863 EA5E FE2C) + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +/* + * constants for ecc.c + */ +#ifndef _ECC_H +#define _ECC_H + +const int hammingGenerator[4] = { + 0x7f08, 0x78e4, 0x66d2, 0x55b1 +}; + +const int imbe7100x4400hammingGenerator[4] = { + 0x7ac8, 0x3d64, 0x1eb2, 0x7591 +}; + +const int hammingMatrix[16] = { + 0x0, 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80, 0x100, 0x200, 0x400, 0x800, 0x1000, 0x2000, 0x4000 +}; + +const int golayGenerator[12] = { + 0x63a, 0x31d, 0x7b4, 0x3da, 0x1ed, 0x6cc, 0x366, 0x1b3, 0x6e3, 0x54b, 0x49f, 0x475 +}; + +const int golayMatrix[2048] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 72, 0, 0, 0, 0, 0, 0, 0, 2084, 0, 0, 0, 769, 0, 1024, 144, + 2, 0, 0, 0, 0, 0, 0, 0, 72, 0, 0, 0, 72, 0, 72, 72, 72, 0, 0, 0, 16, 0, 1, 1538, 384, 0, 134, 2048, 1056, 288, + 2576, 5, 72, 0, 0, 0, 0, 0, 0, 0, 1280, 0, 0, 0, 4, 0, 546, 144, 2049, 0, 0, 0, 66, 0, 1, 144, 520, 0, 2056, 144, + 1056, 144, 324, 144, 144, 0, 0, 0, 2688, 0, 1, 32, 22, 0, 272, 3, 1056, 3076, 128, 768, 72, 0, 1, 268, 1056, 1, 1, 2112, 1, 576, + 1056, 1056, 1056, 10, 1, 144, 1056, 0, 0, 0, 0, 0, 0, 0, 1280, 0, 0, 0, 160, 0, 21, 2560, 2, 0, 0, 0, 16, 0, 704, 9, + 2, 0, 2056, 1092, 2, 288, 2, 2, 2, 0, 0, 0, 16, 0, 2050, 132, 545, 0, 1536, 3, 2308, 288, 128, 1040, 72, 0, 16, 16, 16, 288, + 1036, 2112, 16, 288, 65, 648, 16, 288, 288, 288, 2, 0, 0, 0, 1280, 0, 1280, 1280, 1280, 0, 2056, 3, 592, 64, 128, 44, 1280, 0, 2056, 544, + 133, 6, 48, 2112, 1280, 2056, 2056, 256, 2056, 1537, 2056, 144, 2, 0, 100, 3, 8, 536, 128, 2112, 1280, 3, 128, 3, 3, 128, 128, 3, 128, 1152, + 770, 2112, 16, 2112, 1, 2112, 2112, 20, 2056, 3, 1056, 288, 128, 2112, 516, 0, 0, 0, 0, 0, 0, 0, 131, 0, 0, 0, 4, 0, 1024, 2560, + 304, 0, 0, 0, 16, 0, 1024, 320, 520, 0, 1024, 42, 2240, 1024, 1024, 5, 1024, 0, 0, 0, 16, 0, 772, 32, 3072, 0, 2081, 1408, 514, 18, + 128, 5, 72, 0, 16, 16, 16, 2184, 98, 5, 16, 576, 264, 5, 16, 5, 1024, 5, 5, 0, 0, 0, 4, 0, 2128, 32, 520, 0, 4, 4, + 4, 265, 128, 1090, 4, 0, 416, 3073, 520, 6, 520, 520, 520, 576, 19, 256, 4, 2080, 1024, 144, 520, 0, 1034, 32, 321, 32, 128, 32, 32, 576, + 128, 2072, 4, 128, 128, 32, 128, 576, 2052, 130, 16, 1296, 1, 32, 520, 576, 576, 576, 1056, 576, 128, 5, 2306, 0, 0, 0, 16, 0, 40, 2560, + 68, 0, 322, 2560, 1033, 2560, 128, 2560, 2560, 0, 16, 16, 16, 6, 2305, 1184, 16, 129, 548, 256, 16, 88, 1024, 2560, 2, 0, 16, 16, 16, 1089, + 128, 266, 16, 12, 128, 96, 16, 128, 128, 2560, 128, 16, 16, 16, 16, 512, 16, 16, 16, 3074, 16, 16, 16, 288, 128, 5, 16, 0, 513, 200, + 2082, 6, 128, 17, 1280, 1072, 128, 256, 4, 128, 128, 2560, 128, 6, 1088, 256, 16, 6, 6, 6, 520, 256, 2056, 256, 256, 6, 128, 256, 97, 2304, + 128, 1540, 16, 128, 128, 32, 128, 128, 128, 3, 128, 128, 128, 128, 128, 41, 16, 16, 16, 6, 128, 2112, 16, 576, 128, 256, 16, 128, 128, 1032, + 128, 0, 0, 0, 0, 0, 0, 0, 528, 0, 0, 0, 160, 0, 1024, 262, 2049, 0, 0, 0, 66, 0, 1024, 9, 384, 0, 1024, 2048, 28, 1024, + 1024, 608, 1024, 0, 0, 0, 1029, 0, 2050, 32, 384, 0, 272, 2048, 514, 641, 36, 1040, 72, 0, 552, 2048, 384, 84, 384, 384, 384, 2048, 65, 2048, + 2048, 10, 1024, 2048, 384, 0, 0, 0, 66, 0, 140, 32, 2049, 0, 272, 1544, 2049, 64, 2049, 2049, 2049, 0, 66, 66, 66, 2816, 48, 1028, 66, 37, + 640, 256, 66, 10, 1024, 144, 2049, 0, 272, 32, 8, 32, 1600, 32, 32, 272, 272, 196, 272, 10, 272, 32, 2049, 1152, 2052, 529, 66, 10, 1, 32, + 384, 10, 272, 2048, 1056, 10, 10, 10, 516, 0, 0, 0, 160, 0, 2050, 9, 68, 0, 160, 160, 160, 64, 776, 1040, 160, 0, 260, 9, 3584, 9, + 48, 9, 9, 530, 65, 256, 160, 2180, 1024, 9, 2, 0, 2050, 832, 8, 2050, 2050, 1040, 2050, 12, 65, 1040, 160, 1040, 2050, 1040, 1040, 1152, 65, 38, + 16, 512, 2050, 9, 384, 65, 65, 2048, 65, 288, 65, 1040, 516, 0, 513, 2068, 8, 64, 48, 642, 1280, 64, 1030, 256, 160, 64, 64, 64, 2049, 1152, + 48, 256, 66, 48, 48, 9, 48, 256, 2056, 256, 256, 64, 48, 256, 516, 1152, 8, 8, 8, 261, 2050, 32, 8, 2592, 272, 3, 8, 64, 128, 1040, + 516, 1152, 1152, 1152, 8, 1152, 48, 2112, 516, 1152, 65, 256, 516, 10, 516, 516, 516, 0, 0, 0, 2312, 0, 1024, 32, 68, 0, 1024, 81, 514, 1024, + 1024, 136, 1024, 0, 1024, 644, 33, 1024, 1024, 2066, 1024, 1024, 1024, 256, 1024, 1024, 1024, 1024, 1024, 0, 192, 32, 514, 32, 25, 32, 32, 12, 514, 514, + 514, 2368, 1024, 32, 514, 259, 2052, 1096, 16, 512, 1024, 32, 384, 176, 1024, 2048, 514, 1024, 1024, 5, 1024, 0, 513, 32, 1168, 32, 258, 32, 32, 2178, + 104, 256, 4, 532, 1024, 32, 2049, 24, 2052, 256, 66, 193, 1024, 32, 520, 256, 1024, 256, 256, 1024, 1024, 256, 1024, 32, 2052, 32, 32, 32, 32, 32, + 32, 1025, 272, 32, 514, 32, 128, 32, 32, 2052, 2052, 32, 2052, 32, 2052, 32, 32, 576, 2052, 256, 137, 10, 1024, 32, 80, 0, 513, 1026, 68, 400, + 68, 68, 68, 12, 2064, 256, 160, 35, 1024, 2560, 68, 2144, 138, 256, 16, 512, 1024, 9, 68, 256, 1024, 256, 256, 1024, 1024, 256, 1024, 12, 1312, 2177, + 16, 512, 2050, 32, 68, 12, 12, 12, 514, 12, 128, 1040, 257, 512, 16, 16, 16, 512, 512, 512, 16, 12, 65, 256, 16, 512, 1024, 194, 2088, 513, + 513, 256, 513, 3080, 513, 32, 68, 256, 513, 256, 256, 64, 128, 256, 26, 256, 513, 256, 256, 6, 48, 256, 2176, 256, 256, 256, 256, 256, 1024, 256, + 256, 82, 513, 32, 8, 32, 128, 32, 32, 12, 128, 256, 3136, 128, 128, 32, 128, 1152, 2052, 256, 16, 512, 328, 32, 1027, 256, 34, 256, 256, 2065, + 128, 256, 516, 0, 0, 0, 0, 0, 0, 0, 528, 0, 0, 0, 4, 0, 2432, 1057, 2, 0, 0, 0, 1160, 0, 1, 320, 2, 0, 112, 2048, + 2, 524, 2, 2, 2, 0, 0, 0, 290, 0, 1, 132, 3072, 0, 1536, 2048, 145, 18, 36, 768, 72, 0, 1, 2048, 580, 1, 1, 56, 1, 2048, + 264, 2048, 2048, 1216, 1, 2048, 2, 0, 0, 0, 4, 0, 1, 2058, 224, 0, 4, 4, 4, 64, 1048, 768, 4, 0, 1, 544, 2320, 1, 1, 1028, + 1, 1282, 640, 73, 4, 2080, 1, 144, 2, 0, 1, 1104, 8, 1, 1, 768, 1, 168, 2114, 768, 4, 768, 1, 768, 768, 1, 1, 130, 1, 1, + 1, 1, 1, 20, 1, 2048, 1056, 1, 1, 768, 1, 0, 0, 0, 2113, 0, 40, 132, 2, 0, 1536, 280, 2, 64, 2, 2, 2, 0, 260, 544, + 2, 3088, 2, 2, 2, 129, 2, 2, 2, 2, 2, 2, 2, 0, 1536, 132, 8, 132, 336, 132, 132, 1536, 1536, 96, 1536, 2057, 1536, 132, 2, 74, + 2208, 1281, 16, 512, 1, 132, 2, 20, 1536, 2048, 2, 288, 2, 2, 2, 0, 146, 544, 8, 64, 2564, 17, 1280, 64, 289, 3200, 4, 64, 64, 64, + 2, 544, 1088, 544, 544, 392, 1, 544, 2, 20, 2056, 544, 2, 64, 2, 2, 2, 2304, 8, 8, 8, 1058, 1, 132, 8, 20, 1536, 3, 8, 64, + 128, 768, 2096, 20, 1, 544, 8, 1, 1, 2112, 1, 20, 20, 20, 448, 20, 1, 1032, 2, 0, 0, 0, 4, 0, 40, 320, 3072, 0, 4, 4, + 4, 18, 577, 136, 4, 0, 2562, 320, 33, 320, 148, 320, 320, 129, 264, 1552, 4, 2080, 1024, 320, 2, 0, 192, 521, 3072, 18, 3072, 3072, 3072, 18, + 264, 96, 4, 18, 18, 18, 3072, 1060, 264, 130, 16, 512, 1, 320, 3072, 264, 264, 2048, 264, 18, 264, 5, 672, 0, 4, 4, 4, 1664, 258, 17, + 4, 4, 4, 4, 4, 2080, 4, 4, 4, 24, 1088, 130, 4, 2080, 1, 320, 520, 2080, 4, 4, 4, 2080, 2080, 2080, 4, 2304, 560, 130, 4, 76, + 1, 32, 3072, 1025, 4, 4, 4, 18, 128, 768, 4, 130, 1, 130, 130, 1, 1, 130, 1, 576, 264, 130, 4, 2080, 1, 1032, 80, 0, 40, 1026, + 896, 40, 40, 17, 40, 129, 2064, 96, 4, 1284, 40, 2560, 2, 129, 1088, 2060, 16, 512, 40, 320, 2, 129, 129, 129, 2, 129, 2, 2, 2, 2304, + 7, 96, 16, 512, 40, 132, 3072, 96, 1536, 96, 96, 18, 128, 96, 257, 512, 16, 16, 16, 512, 512, 512, 16, 129, 264, 96, 16, 512, 2116, 1032, + 2, 2304, 1088, 17, 4, 17, 40, 17, 17, 522, 4, 4, 4, 64, 128, 17, 4, 1088, 1088, 544, 1088, 6, 1088, 17, 2176, 129, 1088, 256, 4, 2080, + 784, 1032, 2, 2304, 2304, 2304, 8, 2304, 128, 17, 578, 2304, 128, 96, 4, 128, 128, 1032, 128, 2304, 1088, 130, 16, 512, 1, 1032, 292, 20, 34, 1032, + 2561, 1032, 128, 1032, 1032, 0, 0, 0, 528, 0, 528, 528, 528, 0, 11, 2048, 1344, 64, 36, 136, 528, 0, 260, 2048, 33, 162, 2120, 1028, 528, 2048, + 640, 2048, 2048, 273, 1024, 2048, 2, 0, 192, 2048, 8, 1288, 36, 67, 528, 2048, 36, 2048, 2048, 36, 36, 2048, 36, 2048, 1042, 2048, 2048, 512, 1, 2048, + 384, 2048, 2048, 2048, 2048, 2048, 36, 2048, 2048, 0, 3104, 385, 8, 64, 258, 1028, 528, 64, 640, 50, 4, 64, 64, 64, 2049, 24, 640, 1028, 66, 1028, + 1, 1028, 1028, 640, 640, 2048, 640, 64, 640, 1028, 296, 518, 8, 8, 8, 2192, 1, 32, 8, 1025, 272, 2048, 8, 64, 36, 768, 1154, 352, 1, 2048, + 8, 1, 1, 1028, 1, 2048, 640, 2048, 2048, 10, 1, 2048, 80, 0, 260, 1026, 8, 64, 1153, 2336, 528, 64, 2064, 517, 160, 64, 64, 64, 2, 260, + 260, 208, 260, 512, 260, 9, 2, 1064, 260, 2048, 2, 64, 2, 2, 2, 49, 8, 8, 8, 512, 2050, 132, 8, 386, 1536, 2048, 8, 64, 36, 1040, + 257, 512, 260, 2048, 8, 512, 512, 512, 1120, 2048, 65, 2048, 2048, 512, 152, 2048, 2, 64, 8, 8, 8, 64, 64, 64, 8, 64, 64, 64, 8, 64, + 64, 64, 64, 2051, 260, 544, 8, 64, 48, 1028, 2176, 64, 640, 256, 1041, 64, 64, 64, 2, 8, 8, 8, 8, 64, 8, 8, 8, 64, 8, 8, + 8, 64, 64, 64, 8, 1152, 8, 8, 8, 512, 1, 274, 8, 20, 34, 2048, 8, 64, 3328, 161, 516, 0, 192, 1026, 33, 2053, 258, 136, 528, 800, + 2064, 136, 4, 136, 1024, 136, 136, 24, 33, 33, 33, 512, 1024, 320, 33, 70, 1024, 2048, 33, 1024, 1024, 136, 1024, 192, 192, 276, 192, 512, 192, 32, + 3072, 1025, 192, 2048, 514, 18, 36, 136, 257, 512, 192, 2048, 33, 512, 512, 512, 14, 2048, 264, 2048, 2048, 512, 1024, 2048, 80, 24, 258, 2624, 4, 258, + 258, 32, 258, 1025, 4, 4, 4, 64, 258, 136, 4, 24, 24, 24, 33, 24, 258, 1028, 2176, 24, 640, 256, 4, 2080, 1024, 515, 80, 1025, 192, 32, + 8, 32, 258, 32, 32, 1025, 1025, 1025, 4, 1025, 2568, 32, 80, 24, 2052, 130, 1792, 512, 1, 32, 80, 1025, 34, 2048, 80, 388, 80, 80, 80, 1026, + 2064, 1026, 1026, 512, 40, 1026, 68, 2064, 2064, 1026, 2064, 64, 2064, 136, 257, 512, 260, 1026, 33, 512, 512, 512, 2176, 129, 2064, 256, 584, 512, 1024, 52, + 2, 512, 192, 1026, 8, 512, 512, 512, 257, 12, 2064, 96, 257, 512, 257, 257, 257, 512, 512, 512, 16, 512, 512, 512, 512, 512, 34, 2048, 1156, 512, + 512, 512, 257, 164, 513, 1026, 8, 64, 258, 17, 2176, 64, 2064, 256, 4, 64, 64, 64, 1568, 24, 1088, 256, 2176, 512, 2176, 2176, 2176, 256, 34, 256, + 256, 64, 13, 256, 2176, 2304, 8, 8, 8, 512, 1044, 32, 8, 1025, 34, 656, 8, 64, 128, 2054, 257, 512, 34, 69, 8, 512, 512, 512, 2176, 34, + 34, 256, 34, 512, 34, 1032, 80 +}; + +#endif diff --git a/mbelib-wasm/mbelib/imbe7100x4400.c b/mbelib-wasm/mbelib/imbe7100x4400.c new file mode 100644 index 0000000..fce99c0 --- /dev/null +++ b/mbelib-wasm/mbelib/imbe7100x4400.c @@ -0,0 +1,345 @@ +/* + * Copyright (C) 2010 mbelib Author + * GPG Key ID: 0xEA5EFE2C (9E7A 5527 9CDC EBF7 BF1B D772 4F98 E863 EA5E FE2C) + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include +#include + +#include "mbelib.h" + +void +mbe_dumpImbe7100x4400Data (char *imbe_d) +{ + + int i; + char *imbe; + + imbe = imbe_d; + for (i = 0; i < 88; i++) + { + if ((i == 7) || (i == 19) || (i == 31) || (i == 43) || (i == 54) || (i == 65)) + { + printf (" "); + } + printf ("%i", *imbe); + imbe++; + } +} + + +void +mbe_dumpImbe7100x4400Frame (char imbe_fr[7][24]) +{ + + int i, j; + + for (j = 18; j >= 0; j--) + { + if (j == 11) + { + printf (" "); + } + printf ("%i", imbe_fr[0][j]); + } + printf (" "); + + for (j = 23; j >= 0; j--) + { + if (j == 11) + { + printf (" "); + } + printf ("%i", imbe_fr[1][j]); + } + printf (" "); + + for (i = 2; i < 4; i++) + { + for (j = 22; j >= 0; j--) + { + if (j == 10) + { + printf (" "); + } + printf ("%i", imbe_fr[i][j]); + } + printf (" "); + } + for (i = 4; i < 6; i++) + { + for (j = 14; j >= 0; j--) + { + if (j == 3) + { + printf (" "); + } + printf ("%i", imbe_fr[i][j]); + } + printf (" "); + } + for (j = 22; j >= 0; j--) + { + printf ("%i", imbe_fr[6][j]); + } +} + +int +mbe_eccImbe7100x4400C0 (char imbe_fr[7][24]) +{ + + int j, errs; + char in[23], out[23]; + + for (j = 0; j < 18; j++) + { + in[j] = imbe_fr[0][j + 1]; + } + for (j = 18; j < 23; j++) + { + in[j] = 0; + } + + errs = mbe_golay2312 (in, out); + for (j = 0; j < 18; j++) + { + imbe_fr[0][j + 1] = out[j]; + } + + return (errs); + +} + +int +mbe_eccImbe7100x4400Data (char imbe_fr[7][24], char *imbe_d) +{ + + int i, j, errs; + char *imbe, gin[23], gout[23], hin[15], hout[15]; + + errs = 0; + imbe = imbe_d; + + // just copy C0 + for (j = 18; j > 11; j--) + { + *imbe = imbe_fr[0][j]; + imbe++; + } + + // ecc and copy C1 + for (j = 0; j < 23; j++) + { + gin[j] = imbe_fr[1][j + 1]; + } + errs = mbe_golay2312 (gin, gout); + for (j = 22; j > 10; j--) + { + *imbe = gout[j]; + imbe++; + } + + // ecc and copy C2, C3 + for (i = 2; i < 4; i++) + { + for (j = 0; j < 23; j++) + { + gin[j] = imbe_fr[i][j]; + } + errs += mbe_golay2312 (gin, gout); + for (j = 22; j > 10; j--) + { + *imbe = gout[j]; + imbe++; + } + } + // ecc and copy C4, C5 + for (i = 4; i < 6; i++) + { + for (j = 0; j < 15; j++) + { + hin[j] = imbe_fr[i][j]; + } + errs += mbe_7100x4400hamming1511 (hin, hout); + for (j = 14; j >= 4; j--) + { + *imbe = hout[j]; + imbe++; + } + } + + // just copy C6 + for (j = 22; j >= 0; j--) + { + *imbe = imbe_fr[6][j]; + imbe++; + } + + return (errs); +} + +void +mbe_demodulateImbe7100x4400Data (char imbe[7][24]) +{ + + int i, j, k; + unsigned short pr[115]; + unsigned short seed; + char tmpstr[24]; + + // create pseudo-random modulator + j = 0; + tmpstr[7] = 0; + for (i = 18; i > 11; i--) + { + tmpstr[j] = (imbe[0][i] + 48); + j++; + } + seed = strtol (tmpstr, NULL, 2); + pr[0] = (16 * seed); + for (i = 1; i < 101; i++) + { + pr[i] = (173 * pr[i - 1]) + 13849 - (65536 * (((173 * pr[i - 1]) + 13849) / 65536)); + } + seed = pr[100]; + for (i = 1; i < 101; i++) + { + pr[i] = pr[i] / 32768; + } + + // demodulate imbe with pr + k = 1; + for (j = 23; j >= 0; j--) + { + imbe[1][j] = ((imbe[1][j]) ^ pr[k]); + k++; + } + + for (i = 2; i < 4; i++) + { + for (j = 22; j >= 0; j--) + { + imbe[i][j] = ((imbe[i][j]) ^ pr[k]); + k++; + } + } + + for (i = 4; i < 6; i++) + { + for (j = 14; j >= 0; j--) + { + imbe[i][j] = ((imbe[i][j]) ^ pr[k]); + k++; + } + } +} + +void +mbe_convertImbe7100to7200 (char *imbe_d) +{ + + int i, j, k, K, L, b0; + char tmpstr[9]; + char tmp_imbe[88]; + float w0; + + // decode fundamental frequency w0 from b0 + tmpstr[8] = 0; + tmpstr[0] = imbe_d[1] + 48; + tmpstr[1] = imbe_d[2] + 48; + tmpstr[2] = imbe_d[3] + 48; + tmpstr[3] = imbe_d[4] + 48; + tmpstr[4] = imbe_d[5] + 48; + tmpstr[5] = imbe_d[6] + 48; + tmpstr[6] = imbe_d[86] + 48; + tmpstr[7] = imbe_d[87] + 48; + b0 = strtol (tmpstr, NULL, 2); + w0 = ((float) (4 * M_PI) / (float) ((float) b0 + 39.5)); + + // decode L from w0 + L = (int) (0.9254 * (int) ((M_PI / w0) + 0.25)); + + // decode K from L + if (L < 37) + { + K = (int) ((float) (L + 2) / (float) 3); + } + else + { + K = 12; + } + + // rearrange bits from imbe7100x4400 format to imbe7200x4400 format + tmp_imbe[87] = imbe_d[0]; // "status"/zero bit + tmp_imbe[48 + K] = imbe_d[42]; // b2.2 + tmp_imbe[49 + K] = imbe_d[43]; // b2.1 + + k = 44; + j = 48; + for (i = 0; i < K; i++) + { + tmp_imbe[j] = imbe_d[k]; // b1 + j++; + k++; + } + + j = 0; + k = 1; + while (j < 87) + { + tmp_imbe[j] = imbe_d[k]; + if (++j == 48) + { + j += (K + 2); // skip over b1, b2.2, b2.1 on dest + } + if (++k == 42) + { + k += (K + 2); // skip over b2.2, b2.1, b1 on src + } + } + + //copy new format back to imbe_d + + for (i = 0; i < 88; i++) + { + imbe_d[i] = tmp_imbe[i]; + } + +} + +void +mbe_processImbe7100x4400Framef (float *aout_buf, int *errs, int *errs2, char *err_str, char imbe_fr[7][24], char imbe_d[88], mbe_parms * cur_mp, mbe_parms * prev_mp, mbe_parms * prev_mp_enhanced, int uvquality) +{ + + *errs = 0; + *errs2 = 0; + *errs = mbe_eccImbe7100x4400C0 (imbe_fr); + mbe_demodulateImbe7100x4400Data (imbe_fr); + *errs2 = *errs; + *errs2 += mbe_eccImbe7100x4400Data (imbe_fr, imbe_d); + mbe_convertImbe7100to7200 (imbe_d); + + mbe_processImbe4400Dataf (aout_buf, errs, errs2, err_str, imbe_d, cur_mp, prev_mp, prev_mp_enhanced, uvquality); +} + +void +mbe_processImbe7100x4400Frame (short *aout_buf, int *errs, int *errs2, char *err_str, char imbe_fr[7][24], char imbe_d[88], mbe_parms * cur_mp, mbe_parms * prev_mp, mbe_parms * prev_mp_enhanced, int uvquality) +{ + + float float_buf[160]; + mbe_processImbe7100x4400Framef (float_buf, errs, errs2, err_str, imbe_fr, imbe_d, cur_mp, prev_mp, prev_mp_enhanced, uvquality); + mbe_floattoshort (float_buf, aout_buf); +} diff --git a/mbelib-wasm/mbelib/imbe7200x4400.c b/mbelib-wasm/mbelib/imbe7200x4400.c new file mode 100644 index 0000000..a93726f --- /dev/null +++ b/mbelib-wasm/mbelib/imbe7200x4400.c @@ -0,0 +1,584 @@ +/* + * Copyright (C) 2010 mbelib Author + * GPG Key ID: 0xEA5EFE2C (9E7A 5527 9CDC EBF7 BF1B D772 4F98 E863 EA5E FE2C) + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include +#include + +#include "mbelib.h" +#include "imbe7200x4400_const.h" + +void +mbe_dumpImbe4400Data (char *imbe_d) +{ + + int i; + char *imbe; + + imbe = imbe_d; + for (i = 0; i < 88; i++) + { + printf ("%i", *imbe); + imbe++; + } +} + +void +mbe_dumpImbe7200x4400Data (char *imbe_d) +{ + + int i; + char *imbe; + + imbe = imbe_d; + for (i = 0; i < 88; i++) + { + if ((i == 12) || (i == 24) || (i == 36) || (i == 48) || (i == 59) || (i == 70) || (i == 81)) + { + printf (" "); + } + printf ("%i", *imbe); + imbe++; + } +} + + +void +mbe_dumpImbe7200x4400Frame (char imbe_fr[8][23]) +{ + + int i, j; + + for (i = 0; i < 4; i++) + { + for (j = 22; j >= 0; j--) + { + printf ("%i", imbe_fr[i][j]); + } + printf (" "); + } + for (i = 4; i < 7; i++) + { + for (j = 14; j >= 0; j--) + { + printf ("%i", imbe_fr[i][j]); + } + printf (" "); + } + for (j = 6; j >= 0; j--) + { + printf ("%i", imbe_fr[7][j]); + } +} + + +int +mbe_eccImbe7200x4400C0 (char imbe_fr[8][23]) +{ + + int j, errs; + char in[23], out[23]; + + for (j = 0; j < 23; j++) + { + in[j] = imbe_fr[0][j]; + } + errs = mbe_golay2312 (in, out); + for (j = 0; j < 23; j++) + { + imbe_fr[0][j] = out[j]; + } + + return (errs); + +} + +int +mbe_eccImbe7200x4400Data (char imbe_fr[8][23], char *imbe_d) +{ + + int i, j, errs; + char *imbe, gin[23], gout[23], hin[15], hout[15]; + + errs = 0; + imbe = imbe_d; + for (i = 0; i < 4; i++) + { + if (i > 0) + { + for (j = 0; j < 23; j++) + { + gin[j] = imbe_fr[i][j]; + } + errs += mbe_golay2312 (gin, gout); + for (j = 22; j > 10; j--) + { + *imbe = gout[j]; + imbe++; + } + } + else + { + for (j = 22; j > 10; j--) + { + *imbe = imbe_fr[i][j]; + imbe++; + } + } + } + for (i = 4; i < 7; i++) + { + for (j = 0; j < 15; j++) + { + hin[j] = imbe_fr[i][j]; + } + errs += mbe_hamming1511 (hin, hout); + for (j = 14; j >= 4; j--) + { + *imbe = hout[j]; + imbe++; + } + } + for (j = 6; j >= 0; j--) + { + *imbe = imbe_fr[7][j]; + imbe++; + } + + return (errs); +} + +int +mbe_decodeImbe4400Parms (char *imbe_d, mbe_parms * cur_mp, mbe_parms * prev_mp) +{ + + int Bm, ji, b, i, j, k, l, L, K, L9, m, am, ak; + int intkl[57]; + int b0, b2, bm; + float Cik[7][11], rho, flokl[57], deltal[57]; + float Sum77, Tl[57], Gm[7], Ri[7], sum, c1, c2; + const float *ba1, *ba2; + char tmpstr[13]; + const int *bo1, *bo2; + char bb[58][12]; + + + // copy repeat from prev_mp + cur_mp->repeat = prev_mp->repeat; + + // decode fundamental frequency w0 from b0 + tmpstr[8] = 0; + tmpstr[0] = imbe_d[0] + 48; + tmpstr[1] = imbe_d[1] + 48; + tmpstr[2] = imbe_d[2] + 48; + tmpstr[3] = imbe_d[3] + 48; + tmpstr[4] = imbe_d[4] + 48; + tmpstr[5] = imbe_d[5] + 48; + tmpstr[6] = imbe_d[85] + 48; + tmpstr[7] = imbe_d[86] + 48; + b0 = strtol (tmpstr, NULL, 2); + if (b0 > 207) + { + if ((b0 >= 216) && (b0 <= 219)) + { +#ifdef IMBE_DEBUG + printf ("Silence\n"); +#endif + } + else + { +#ifdef IMBE_DEBUG + printf ("Invalid fundamental frequency\n"); +#endif + } + return (1); + } + + cur_mp->w0 = ((float) (4 * M_PI) / (float) ((float) b0 + 39.5)); + + // decode L from w0 + L = (int) (0.9254 * (int) ((M_PI / cur_mp->w0) + 0.25)); + if ((L > 56) || (L < 9)) + { +#ifdef IMBE_DEBUG + printf ("invalid L: %i\n", L); +#endif + return (1); + } + cur_mp->L = L; + L9 = L - 9; + + // decode K from L + if (L < 37) + { + K = (int) ((float) (L + 2) / (float) 3); + cur_mp->K = K; + } + else + { + K = 12; + cur_mp->K = 12; + } + +#ifdef IMBE_DEBUG + printf ("b0:%i L:%i K:%i\n", b0, L, K); +#endif + + // read bits from imbe_d into b0..bL+1 + bo1 = bo[L9][0]; + bo2 = bo1 + 1; + for (i = 6; i < 85; i++) + { + bb[*bo1][*bo2] = imbe_d[i]; +#ifdef IMBE_DEBUG + printf ("bo1: %i,bo2: %i, ", *bo1, *bo2); +#endif + bo1 += 2; + bo2 += 2; + } + + // Vl + j = 1; + k = (K - 1); + for (i = 1; i <= L; i++) + { + cur_mp->Vl[i] = bb[1][k]; + if (j == 3) + { + j = 1; + if (k > 0) + { + k--; + } + else + { + k = 0; + } + } + else + { + j++; + } + } + + //decode G1 from b2 + tmpstr[6] = 0; + tmpstr[0] = bb[2][5] + 48; + tmpstr[1] = bb[2][4] + 48; + tmpstr[2] = bb[2][3] + 48; + tmpstr[3] = bb[2][2] + 48; + tmpstr[4] = bb[2][1] + 48; + tmpstr[5] = bb[2][0] + 48; + b2 = strtol (tmpstr, NULL, 2); + Gm[1] = B2[b2]; +#ifdef IMBE_DEBUG + printf ("G1: %e, %s, %i\n", Gm[1], tmpstr, b2); +#endif + +#ifdef IMBE_DEBUG + printf ("tmpstr: %s b2: %i g1: %e\n", tmpstr, b2, Gm[1]); +#endif + + // decode G2..G6 (from b3..b7) with annex E + // equation 68 + ba1 = ba[L9][0]; + ba2 = ba1 + 1; + + for (i = 2; i < 7; i++) + { + tmpstr[(int) *ba1] = 0; + k = 0; + for (j = ((int) *ba1 - 1); j >= 0; j--) + { + tmpstr[k] = bb[i + 1][j] + 48; + k++; + } + bm = strtol (tmpstr, NULL, 2); + Gm[i] = (*ba2 * ((float) bm - powf (2, (*ba1 - 1)) + (float) 0.5)); +#ifdef IMBE_DEBUG + printf ("G%i: %e, %s, %i, ba1: %e, ba2: %e\n", i, Gm[i], tmpstr, bm, *ba1, *ba2); +#endif + ba1 += 2; + ba2 += 2; + } + + // inverse DCT Gi to give Ri (also known as Ci,1) + for (i = 1; i <= 6; i++) + { + sum = 0; + for (m = 1; m <= 6; m++) + { + if (m == 1) + { + am = 1; + } + else + { + am = 2; + } + sum = sum + ((float) am * Gm[m] * cosf ((M_PI * (float) (m - 1) * ((float) i - 0.5)) / (float) 6)); +#ifdef IMBE_DEBUG + printf ("sum: %e ", sum); +#endif + } + Ri[i] = sum; +#ifdef IMBE_DEBUG + printf ("R%i: %e\n", i, Ri[i]); +#endif + } +#ifdef IMBE_DEBUG + printf ("R1: %e\n", Ri[1]); +#endif + + // load b8..bL+1 into Ci,k + m = 8; + for (i = 1; i <= 6; i++) + { + Cik[i][1] = Ri[i]; + for (k = 2; k <= ImbeJi[L9][i - 1]; k++) + { + Bm = hoba[L9][m - 8]; + for (b = 0; b < Bm; b++) + { + tmpstr[b] = bb[m][(Bm - b) - 1] + 48; + } + if (Bm == 0) + { + Cik[i][k] = 0; + } + else + { + tmpstr[Bm] = 0; + bm = strtol (tmpstr, NULL, 2); + Cik[i][k] = ((quantstep[Bm - 1] * standdev[k - 2]) * (((float) bm - powf (2, (Bm - 1))) + 0.5)); + } + m++; + } + } + + // inverse DCT each Ci,k to give ci,j (Tl) + l = 1; + for (i = 1; i <= 6; i++) + { + ji = ImbeJi[L9][i - 1]; + for (j = 1; j <= ji; j++) + { + sum = 0; + for (k = 1; k <= ji; k++) + { + if (k == 1) + { + ak = 1; + } + else + { + ak = 2; + } + sum = sum + ((float) ak * Cik[i][k] * cosf ((M_PI * (float) (k - 1) * ((float) j - 0.5)) / (float) ji)); + } + Tl[l] = sum; + l++; + } + } +#ifdef IMBE_DEBUG + printf ("T1: %e\n", Tl[1]); +#endif + + // determine log2Ml by applying ci,j to previous log2Ml + if (cur_mp->L <= 15) + { + rho = 0.4; + } + else if (cur_mp->L <= 24) + { + rho = (0.03 * (float) cur_mp->L) - 0.05; + } + else + { + rho = 0.7; + } + + // fix for when L > L(-1) + if (cur_mp->L > prev_mp->L) + { + for (l = prev_mp->L + 1; l <= cur_mp->L; l++) + { + prev_mp->Ml[l] = prev_mp->Ml[prev_mp->L]; + prev_mp->log2Ml[l] = prev_mp->log2Ml[prev_mp->L]; + } + } + + // Part 1 + Sum77 = 0; + for (l = 1; l <= cur_mp->L; l++) + { + + // eq. 75 + flokl[l] = ((float) prev_mp->L / (float) cur_mp->L) * (float) l; + intkl[l] = (int) (flokl[l]); +#ifdef IMBE_DEBUG + printf ("flokl: %e, intkl: %i ", flokl[l], intkl[l]); +#endif + // eq. 76 + deltal[l] = flokl[l] - (float) intkl[l]; +#ifdef IMBE_DEBUG + printf ("deltal: %e ", deltal[l]); +#endif + // eq 77 + Sum77 = Sum77 + ((((float) 1 - deltal[l]) * prev_mp->log2Ml[intkl[l]]) + (deltal[l] * prev_mp->log2Ml[intkl[l] + 1])); + } + Sum77 = ((rho / (float) cur_mp->L) * Sum77); + +#ifdef IMBE_DEBUG + printf ("Sum77: %e\n", Sum77); +#endif + + // Part 2 + for (l = 1; l <= cur_mp->L; l++) + { + c1 = (rho * ((float) 1 - deltal[l]) * prev_mp->log2Ml[intkl[l]]); + c2 = (rho * deltal[l] * prev_mp->log2Ml[intkl[l] + 1]); + cur_mp->log2Ml[l] = Tl[l] + c1 + c2 - Sum77; + cur_mp->Ml[l] = powf (2, cur_mp->log2Ml[l]); +#ifdef IMBE_DEBUG + printf ("rho: %e c1: %e c2: %e Sum77: %e T%i: %e log2M%i: %e M%i: %e\n", rho, c1, c2, Sum77, l, Tl[l], l, cur_mp->log2Ml[l], l, cur_mp->Ml[l]); +#endif + } + + return (0); +} + +void +mbe_demodulateImbe7200x4400Data (char imbe[8][23]) +{ + + int i, j, k; + unsigned short pr[115]; + unsigned short foo; + char tmpstr[24]; + + // create pseudo-random modulator + j = 0; + tmpstr[12] = 0; + for (i = 22; i >= 11; i--) + { + tmpstr[j] = (imbe[0][i] + 48); + j++; + } + foo = strtol (tmpstr, NULL, 2); + pr[0] = (16 * foo); + for (i = 1; i < 115; i++) + { + pr[i] = (173 * pr[i - 1]) + 13849 - (65536 * (((173 * pr[i - 1]) + 13849) / 65536)); + } + for (i = 1; i < 115; i++) + { + pr[i] = pr[i] / 32768; + } + + // demodulate imbe with pr + k = 1; + for (i = 1; i < 4; i++) + { + for (j = 22; j >= 0; j--) + { + imbe[i][j] = ((imbe[i][j]) ^ pr[k]); + k++; + } + } + for (i = 4; i < 7; i++) + { + for (j = 14; j >= 0; j--) + { + imbe[i][j] = ((imbe[i][j]) ^ pr[k]); + k++; + } + } +} + +void +mbe_processImbe4400Dataf (float *aout_buf, int *errs, int *errs2, char *err_str, char imbe_d[88], mbe_parms * cur_mp, mbe_parms * prev_mp, mbe_parms * prev_mp_enhanced, int uvquality) +{ + + int i, bad; + + for (i = 0; i < *errs2; i++) + { + *err_str = '='; + err_str++; + } + + bad = mbe_decodeImbe4400Parms (imbe_d, cur_mp, prev_mp); + if ((bad == 1) || (*errs2 > 5)) + { + mbe_useLastMbeParms (cur_mp, prev_mp); + cur_mp->repeat++; + *err_str = 'R'; + err_str++; + } + else + { + cur_mp->repeat = 0; + } + if (cur_mp->repeat <= 3) + { + mbe_moveMbeParms (cur_mp, prev_mp); + mbe_spectralAmpEnhance (cur_mp); + mbe_synthesizeSpeechf (aout_buf, cur_mp, prev_mp_enhanced, uvquality); + mbe_moveMbeParms (cur_mp, prev_mp_enhanced); + } + else + { + *err_str = 'M'; + err_str++; + mbe_synthesizeSilencef (aout_buf); + mbe_initMbeParms (cur_mp, prev_mp, prev_mp_enhanced); + } + *err_str = 0; +} + +void +mbe_processImbe4400Data (short *aout_buf, int *errs, int *errs2, char *err_str, char imbe_d[88], mbe_parms * cur_mp, mbe_parms * prev_mp, mbe_parms * prev_mp_enhanced, int uvquality) +{ + float float_buf[160]; + + mbe_processImbe4400Dataf (float_buf, errs, errs2, err_str, imbe_d, cur_mp, prev_mp, prev_mp_enhanced, uvquality); + mbe_floattoshort (float_buf, aout_buf); +} + +void +mbe_processImbe7200x4400Framef (float *aout_buf, int *errs, int *errs2, char *err_str, char imbe_fr[8][23], char imbe_d[88], mbe_parms * cur_mp, mbe_parms * prev_mp, mbe_parms * prev_mp_enhanced, int uvquality) +{ + + *errs = 0; + *errs2 = 0; + *errs = mbe_eccImbe7200x4400C0 (imbe_fr); + mbe_demodulateImbe7200x4400Data (imbe_fr); + *errs2 = *errs; + *errs2 += mbe_eccImbe7200x4400Data (imbe_fr, imbe_d); + + mbe_processImbe4400Dataf (aout_buf, errs, errs2, err_str, imbe_d, cur_mp, prev_mp, prev_mp_enhanced, uvquality); +} + +void +mbe_processImbe7200x4400Frame (short *aout_buf, int *errs, int *errs2, char *err_str, char imbe_fr[8][23], char imbe_d[88], mbe_parms * cur_mp, mbe_parms * prev_mp, mbe_parms * prev_mp_enhanced, int uvquality) +{ + + float float_buf[160]; + mbe_processImbe7200x4400Framef (float_buf, errs, errs2, err_str, imbe_fr, imbe_d, cur_mp, prev_mp, prev_mp_enhanced, uvquality); + mbe_floattoshort (float_buf, aout_buf); +} diff --git a/mbelib-wasm/mbelib/imbe7200x4400_const.h b/mbelib-wasm/mbelib/imbe7200x4400_const.h new file mode 100644 index 0000000..0b6c308 --- /dev/null +++ b/mbelib-wasm/mbelib/imbe7200x4400_const.h @@ -0,0 +1,898 @@ +/* + * Copyright (C) 2010 mbelib Author + * GPG Key ID: 0xEA5EFE2C (9E7A 5527 9CDC EBF7 BF1B D772 4F98 E863 EA5E FE2C) + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _IMBE7200X4400_CONST_H +#define _IMBE7200X4400_CONST_H + +/* + * Quantizer step size for higher order DCT coefficients + */ +const float quantstep[11] = { + 1.2, 0.85, 0.65, 0.40, 0.28, 0.15, 0.08, 0.04, 0.02, 0.01 +}; + +/* + * Standard Dev. for higer order DCT coefficients + */ +const float standdev[9] = { + 0.307, 0.241, 0.207, 0.190, 0.179, 0.173, 0.165, 0.170, 0.170 +}; + +/* + * + */ +const float B2[64] = { + -2.842205, -2.694235, -2.558260, -2.382850, + -2.221042, -2.095574, -1.980845, -1.836058, + -1.645556, -1.417658, -1.261301, -1.125631, + -0.958207, -0.781591, -0.555837, -0.346976, + -0.147249, 0.027755, 0.211495, 0.388380, + 0.552873, 0.737223, 0.932197, 1.139032, + 1.320955, 1.483433, 1.648297, 1.801447, + 1.942731, 2.118613, 2.321486, 2.504443, + 2.653909, 2.780654, 2.925355, 3.076390, + 3.220825, 3.402869, 3.585096, 3.784606, + 3.955521, 4.155636, 4.314009, 4.444150, + 4.577542, 4.735552, 4.909493, 5.085264, + 5.254767, 5.411894, 5.568094, 5.738523, + 5.919215, 6.087701, 6.280685, 6.464201, + 6.647736, 6.834672, 7.022583, 7.211777, + 7.471016, 7.738948, 8.124863, 8.695827 +}; + +/* + * bit allocation and step size for transformed gain vector + */ +const float ba[48][5][2] = { + + // L=9 + 10, 0.003100, 9, 0.004020, 9, 0.003360, 9, 0.002900, 9, 0.002640, + // L=10 + 9, 0.006200, 9, 0.004020, 8, 0.006720, 8, 0.005800, 8, 0.005280, + // L=11 + 8, 0.012400, 8, 0.008040, 8, 0.006720, 7, 0.011600, 7, 0.010560, + // L=12 + 8, 0.012400, 7, 0.016080, 7, 0.013440, 7, 0.011600, 7, 0.010560, + // L=13 + 7, 0.024800, 7, 0.016080, 7, 0.013440, 6, 0.021750, 6, 0.019800, + // L=14 + 7, 0.024800, 6, 0.030150, 6, 0.025200, 6, 0.021750, 6, 0.019800, + // L=15 + 7, 0.024800, 6, 0.030150, 6, 0.025200, 6, 0.021750, 5, 0.036960, + // L=16 + 6, 0.046500, 6, 0.030150, 6, 0.025200, 5, 0.040600, 5, 0.036960, + // L=17 + 6, 0.046500, 6, 0.030150, 5, 0.047040, 5, 0.040600, 5, 0.036960, + // L=18 + 6, 0.046500, 5, 0.056280, 5, 0.047040, 5, 0.040600, 5, 0.036960, + // L=19 + 6, 0.046500, 5, 0.056280, 5, 0.047040, 4, 0.058000, 4, 0.052800, + // L=20 + 6, 0.046500, 5, 0.056280, 5, 0.047040, 4, 0.058000, 4, 0.052800, + // L=21 + 5, 0.086800, 5, 0.056280, 5, 0.047040, 4, 0.058000, 4, 0.052800, + // L=22 + 5, 0.086800, 5, 0.056280, 4, 0.067200, 4, 0.058000, 4, 0.052800, + // L=23 + 5, 0.086800, 4, 0.080400, 4, 0.067200, 4, 0.068000, 4, 0.052800, + // L=24 + 5, 0.086800, 4, 0.080400, 4, 0.067200, 4, 0.058000, 4, 0.052800, + // L=25 + 5, 0.086800, 4, 0.080400, 4, 0.067200, 4, 0.058000, 3, 0.085800, + // L=26 + 5, 0.086800, 4, 0.080400, 4, 0.067200, 3, 0.094250, 3, 0.085800, + // L=27 + 5, 0.086800, 4, 0.080400, 4, 0.067200, 3, 0.094250, 3, 0.085800, + // L=28 + 4, 0.124000, 4, 0.080400, 4, 0.067200, 3, 0.094250, 3, 0.085800, + // L=29 + 4, 0.124000, 4, 0.080400, 4, 0.067200, 3, 0.094250, 3, 0.085800, + // L=30 + 4, 0.124000, 4, 0.080400, 4, 0.067200, 3, 0.094250, 3, 0.085800, + // L=31 + 4, 0.124000, 4, 0.080400, 3, 0.109200, 3, 0.094250, 3, 0.085800, + // L=32 + 4, 0.124000, 4, 0.080400, 3, 0.109200, 3, 0.094250, 3, 0.085800, + // L=33 + 4, 0.124000, 3, 0.130650, 3, 0.109200, 3, 0.094250, 3, 0.085800, + // L=34 + 4, 0.124000, 3, 0.130650, 3, 0.109200, 3, 0.094250, 3, 0.085800, + // L=35 + 4, 0.124000, 3, 0.130650, 3, 0.109200, 3, 0.094250, 3, 0.085800, + // L=36 + 4, 0.124000, 3, 0.130650, 3, 0.109200, 3, 0.094250, 3, 0.085800, + // L=37 + 4, 0.124000, 3, 0.130650, 3, 0.109200, 3, 0.094250, 2, 0.112200, + // L=38 + 4, 0.124000, 3, 0.130650, 3, 0.109200, 3, 0.094250, 2, 0.112200, + // L=39 + 4, 0.124000, 3, 0.130650, 3, 0.109200, 3, 0.094250, 2, 0.112200, + // L=40 + 4, 0.124000, 3, 0.130650, 3, 0.109200, 3, 0.094250, 2, 0.112200, + // L=41 + 4, 0.124000, 3, 0.130650, 3, 0.109200, 2, 0.123250, 2, 0.112200, + // L=42 + 4, 0.124000, 3, 0.130650, 3, 0.109200, 2, 0.123250, 2, 0.112200, + // L=43 + 4, 0.124000, 3, 0.130650, 3, 0.109200, 2, 0.123250, 2, 0.112200, + // L=44 + 4, 0.124000, 3, 0.130650, 3, 0.109200, 2, 0.123250, 2, 0.112200, + // L=45 + 4, 0.124000, 3, 0.130650, 3, 0.109200, 2, 0.123250, 2, 0.112200, + // L=46 + 3, 0.201500, 3, 0.130650, 3, 0.109200, 2, 0.123250, 2, 0.112200, + // L=47 + 3, 0.201500, 3, 0.130650, 3, 0.109200, 2, 0.123250, 2, 0.112200, + // L=48 + 3, 0.201500, 3, 0.130650, 3, 0.109200, 2, 0.123250, 2, 0.112200, + // L=49 + 3, 0.201500, 3, 0.130650, 3, 0.109200, 2, 0.123250, 2, 0.112200, + // L=50 + 3, 0.201500, 3, 0.130650, 3, 0.109200, 2, 0.123250, 2, 0.112200, + // L=51 + 3, 0.201500, 3, 0.130650, 3, 0.109200, 2, 0.123250, 2, 0.112200, + // L=52 + 3, 0.201500, 3, 0.130650, 2, 0.142800, 2, 0.123250, 2, 0.112200, + // L=53 + 3, 0.201500, 3, 0.130650, 2, 0.142800, 2, 0.123250, 2, 0.112200, + // L=54 + 3, 0.201500, 3, 0.130650, 2, 0.142800, 2, 0.123250, 2, 0.112200, + // L=55 + 3, 0.201500, 3, 0.130650, 2, 0.142800, 2, 0.123250, 2, 0.112200, + // L=56 + 3, 0.201500, 3, 0.130650, 2, 0.142800, 2, 0.123250, 2, 0.112200 +}; + +/* + * Bit allocation for higher Order DCT Coefficients + */ +const int hoba[48][50] = { + // L=9 + {9, 8, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + // L=10 + {9, 7, 6, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + // L=11 + {9, 7, 6, 5, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + // L=12 + {8, 7, 6, 5, 4, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + // L=13 + {7, 7, 6, 5, 4, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + // L=14 + {7, 7, 5, 4, 4, 3, 4, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + // L=15 + {6, 7, 5, 4, 4, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + // L=16 + {6, 6, 5, 4, 4, 3, 3, 3, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + // L=17 + {5, 5, 5, 4, 4, 4, 3, 3, 2, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + // L=18 + {5, 4, 5, 5, 4, 3, 3, 3, 3, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + // L=19 + {5, 4, 5, 4, 4, 3, 3, 3, 3, 2, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + // L=20 + {5, 4, 5, 4, 4, 3, 3, 2, 3, 2, 1, 3, 2, 1, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + // L=21 + {4, 4, 5, 4, 4, 3, 3, 2, 2, 3, 2, 1, 3, 2, 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + // L=22 + {4, 4, 4, 4, 4, 3, 2, 3, 2, 2, 3, 2, 1, 2, 2, 1, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + // L=23 + {4, 3, 4, 4, 3, 4, 3, 2, 3, 2, 2, 2, 2, 1, 2, 2, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + // L=24 + {4, 3, 3, 4, 3, 3, 3, 3, 2, 3, 2, 1, 2, 2, 1, 2, 2, 1, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + // L=25 + {4, 3, 3, 4, 3, 3, 3, 3, 2, 3, 2, 1, 2, 2, 1, 2, 1, 1, 1, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + // L=26 + {4, 3, 3, 4, 3, 3, 3, 2, 2, 3, 2, 1, 2, 2, 1, 1, 2, 2, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + // L=27 + {4, 3, 2, 4, 3, 2, 3, 2, 2, 3, 2, 2, 1, 2, 2, 1, 1, 2, 2, 1, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + // L=28 + {4, 3, 2, 4, 3, 2, 3, 2, 2, 2, 3, 2, 1, 1, 2, 2, 1, 1, 2, 1, + 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + // L=29 + {3, 3, 2, 4, 3, 2, 2, 3, 2, 2, 2, 3, 2, 1, 1, 2, 1, 1, 1, 2, + 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + // L=30 + {3, 3, 2, 2, 3, 3, 2, 2, 3, 2, 2, 1, 3, 2, 1, 1, 2, 1, 1, 1, + 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + // L=31 + {3, 3, 2, 2, 3, 3, 2, 2, 3, 2, 2, 1, 2, 2, 1, 1, 2, 1, 1, 1, + 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + // L=32 + {3, 3, 2, 2, 3, 3, 2, 2, 3, 2, 2, 1, 2, 2, 1, 1, 2, 1, 1, 1, + 1, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + // L=33 + {3, 3, 2, 2, 3, 3, 2, 2, 3, 2, 1, 1, 2, 2, 1, 1, 1, 2, 1, 1, + 1, 1, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + // L=34 + {3, 2, 2, 2, 3, 2, 2, 2, 3, 2, 2, 1, 1, 2, 2, 1, 1, 1, 2, 1, + 1, 1, 1, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + // L=35 + {3, 2, 2, 2, 3, 2, 2, 2, 2, 3, 2, 1, 1, 1, 2, 2, 1, 1, 1, 2, + 1, 1, 1, 0, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + // L=36 + {3, 2, 2, 2, 1, 3, 2, 2, 2, 1, 3, 2, 1, 1, 1, 2, 2, 1, 1, 1, + 2, 1, 1, 1, 0, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + // L=37 + {3, 2, 2, 2, 1, 3, 2, 2, 2, 2, 3, 2, 1, 1, 1, 2, 1, 1, 1, 1, + 2, 1, 1, 1, 0, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + // L=38 + {3, 2, 2, 2, 1, 3, 2, 2, 2, 1, 3, 2, 1, 1, 1, 2, 1, 1, 1, 1, + 2, 1, 1, 1, 1, 0, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + // L=39 + {3, 2, 2, 2, 1, 3, 2, 2, 2, 1, 3, 2, 1, 1, 1, 2, 2, 1, 1, 1, + 0, 2, 1, 1, 1, 1, 0, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + // L=40 + {3, 2, 2, 2, 1, 3, 2, 2, 1, 1, 3, 2, 1, 1, 1, 1, 2, 2, 1, 1, + 1, 0, 2, 1, 1, 1, 1, 0, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + // L=41 + {3, 2, 2, 1, 1, 3, 2, 2, 2, 1, 1, 3, 2, 1, 1, 1, 1, 2, 2, 1, + 1, 1, 0, 2, 1, 1, 1, 1, 0, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + // L=42 + {3, 2, 2, 2, 1, 1, 3, 2, 2, 2, 1, 1, 2, 2, 1, 1, 1, 1, 2, 2, + 1, 1, 1, 0, 2, 1, 1, 1, 0, 0, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + // L=43 + {3, 2, 2, 2, 1, 1, 3, 2, 2, 2, 1, 1, 2, 2, 1, 1, 1, 1, 2, 1, + 1, 1, 1, 0, 2, 1, 1, 1, 0, 0, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + // L=44 + {3, 2, 2, 1, 1, 1, 3, 2, 2, 2, 1, 1, 2, 2, 1, 1, 1, 1, 2, 1, + 1, 1, 1, 0, 2, 1, 1, 1, 1, 0, 0, 2, 1, 1, 1, 1, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + // L=45 + {3, 2, 2, 1, 1, 1, 3, 2, 2, 1, 1, 1, 2, 2, 1, 1, 1, 1, 2, 2, + 1, 1, 1, 0, 0, 2, 1, 1, 1, 1, 0, 0, 2, 1, 1, 1, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + // L=46 + {3, 2, 2, 1, 1, 1, 3, 2, 2, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 2, + 2, 1, 1, 1, 0, 0, 2, 1, 1, 1, 1, 0, 0, 2, 1, 1, 1, 1, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + // L=47 + {3, 2, 2, 1, 1, 1, 3, 2, 2, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, + 2, 2, 1, 1, 1, 0, 0, 2, 1, 1, 1, 1, 0, 0, 2, 1, 1, 1, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + // L=48 + {3, 2, 2, 1, 1, 1, 1, 3, 2, 2, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, + 1, 2, 2, 1, 1, 1, 0, 0, 2, 1, 1, 1, 0, 0, 0, 2, 1, 1, 1, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + // L=49 + {3, 2, 2, 1, 1, 1, 1, 3, 2, 2, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, + 0, 2, 2, 1, 1, 1, 0, 0, 2, 1, 1, 1, 0, 0, 0, 2, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + // L=50 + {3, 2, 2, 1, 1, 1, 1, 3, 2, 2, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, + 0, 2, 2, 1, 1, 1, 0, 0, 2, 1, 1, 1, 1, 0, 0, 0, 2, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + // L=51 + {3, 2, 2, 1, 1, 1, 1, 3, 2, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, + 0, 2, 2, 1, 1, 1, 0, 0, 0, 2, 1, 1, 1, 1, 0, 0, 0, 2, 1, 1, + 1, 1, 0, 0, 0, 0, 0, 0, 0, 0}, + // L=52 + {3, 2, 1, 1, 1, 1, 1, 3, 2, 2, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, + 1, 0, 2, 2, 1, 1, 1, 0, 0, 0, 2, 1, 1, 1, 1, 0, 0, 0, 2, 1, + 1, 1, 1, 0, 0, 0, 0, 0, 0, 0}, + // L=53 + {3, 2, 1, 1, 1, 1, 1, 3, 2, 2, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, + 1, 1, 0, 2, 2, 1, 1, 1, 0, 0, 0, 2, 1, 1, 1, 1, 0, 0, 0, 2, + 1, 1, 1, 0, 0, 0, 0, 0, 0, 0}, + // L=54 + {3, 2, 2, 1, 1, 1, 1, 0, 3, 2, 2, 1, 1, 1, 1, 0, 2, 2, 1, 1, + 1, 1, 1, 0, 2, 2, 1, 1, 1, 0, 0, 0, 2, 1, 1, 1, 1, 0, 0, 0, + 2, 1, 1, 1, 0, 0, 0, 0, 0, 0}, + // L=55 + {3, 2, 2, 1, 1, 1, 1, 0, 3, 2, 2, 1, 1, 1, 1, 0, 2, 2, 1, 1, + 1, 1, 1, 0, 2, 2, 1, 1, 1, 0, 0, 0, 2, 1, 1, 1, 0, 0, 0, 0, + 2, 1, 1, 1, 1, 0, 0, 0, 0, 0}, + // L=56 + {3, 2, 2, 1, 1, 1, 1, 0, 3, 2, 2, 1, 1, 1, 1, 0, 2, 2, 1, 1, + 1, 1, 1, 0, 2, 2, 1, 1, 1, 0, 0, 0, 2, 1, 1, 1, 1, 0, 0, 0, + 0, 2, 1, 1, 1, 0, 0, 0, 0, 0} +}; + + +/* + * bit order for reading data out of imbe data + */ + + // L=9 +const int bo[48][79][2] = { 2, 5, 2, 4, 2, 3, 3, 9, 3, 8, 4, 8, + 5, 8, 6, 8, 7, 8, 8, 8, 3, 7, 4, 7, 5, 7, 6, 7, 7, 7, 8, 7, 9, 7, 3, 6, + 4, 6, 5, 6, 6, 6, 7, 6, 8, 6, 9, 6, 10, 6, 3, 5, 4, 5, 5, 5, 6, 5, 7, 5, + 8, 5, 9, 5, 10, 5, 3, 4, 4, 4, 5, 4, 6, 4, 7, 4, 8, 4, 9, 4, 10, 4, 3, 3, + 1, 2, 1, 1, 1, 0, 2, 2, 2, 1, 4, 3, 5, 3, 6, 3, 7, 3, 8, 3, 9, 3, + 10, 3, 3, 2, 4, 2, 5, 2, 6, 2, 7, 2, 8, 2, 9, 2, 10, 2, 3, 1, 4, 1, + 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, + 8, 0, 9, 0, 10, 0, 2, 0, + + // L=10 + 2, 5, 2, 4, 2, 3, 3, 8, 4, 8, 8, 8, + 3, 7, 4, 7, 5, 7, 6, 7, 7, 7, 8, 7, 3, 6, 4, 6, 5, 6, 6, 6, 7, 6, 8, 6, + 9, 6, 3, 5, 4, 5, 5, 5, 6, 5, 7, 5, 8, 5, 9, 5, 10, 5, 3, 4, 4, 4, 5, 4, + 6, 4, 7, 4, 8, 4, 9, 4, 10, 4, 11, 4, 3, 3, 4, 3, 5, 3, 6, 3, 7, 3, 8, 3, + 1, 3, 1, 2, 1, 1, 1, 0, 2, 2, 2, 1, 9, 3, 10, 3, 11, 3, 3, 2, 4, 2, + 5, 2, 6, 2, 7, 2, 8, 2, 9, 2, 10, 2, 11, 2, 3, 1, 4, 1, 5, 1, 6, 1, + 7, 1, 8, 1, 9, 1, 10, 1, 11, 1, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, + 9, 0, 10, 0, 11, 0, 2, 0, + + // L=11 + 2, 5, 2, 4, 2, 3, 8, 8, 3, 7, 4, 7, + 5, 7, 8, 7, 3, 6, 4, 6, 5, 6, 6, 6, 7, 6, 8, 6, 9, 6, 3, 5, 4, 5, 5, 5, + 6, 5, 7, 5, 8, 5, 9, 5, 10, 5, 3, 4, 4, 4, 5, 4, 6, 4, 7, 4, 8, 4, 9, 4, + 10, 4, 11, 4, 3, 3, 4, 3, 5, 3, 6, 3, 7, 3, 8, 3, 9, 3, 10, 3, 11, 3, 12, 3, + 1, 3, 1, 2, 1, 1, 1, 0, 2, 2, 2, 1, 3, 2, 4, 2, 5, 2, 6, 2, 7, 2, + 8, 2, 9, 2, 10, 2, 11, 2, 12, 2, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, + 9, 1, 10, 1, 11, 1, 12, 1, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, + 10, 0, 11, 0, 12, 0, 2, 0, + + // L=12 + 2, 5, 2, 4, 2, 3, 3, 7, 8, 7, 3, 6, + 4, 6, 5, 6, 6, 6, 7, 6, 8, 6, 9, 6, 3, 5, 4, 5, 5, 5, 6, 5, 7, 5, 8, 5, + 9, 5, 10, 5, 3, 4, 4, 4, 5, 4, 6, 4, 7, 4, 8, 4, 9, 4, 10, 4, 11, 4, 3, 3, + 4, 3, 5, 3, 6, 3, 7, 3, 8, 3, 9, 3, 10, 3, 11, 3, 12, 3, 3, 2, 4, 2, 5, 2, + 1, 3, 1, 2, 1, 1, 1, 0, 2, 2, 2, 1, 6, 2, 7, 2, 8, 2, 9, 2, 10, 2, + 11, 2, 12, 2, 13, 2, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, + 11, 1, 12, 1, 13, 1, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10, 0, + 11, 0, 12, 0, 13, 0, 2, 0, + + // L=13 + 2, 5, 2, 4, 2, 3, 3, 6, 4, 6, 5, 6, + 8, 6, 9, 6, 3, 5, 4, 5, 5, 5, 6, 5, 7, 5, 8, 5, 9, 5, 10, 5, 3, 4, 4, 4, + 5, 4, 6, 4, 7, 4, 8, 4, 9, 4, 10, 4, 11, 4, 3, 3, 4, 3, 5, 3, 6, 3, 7, 3, + 8, 3, 9, 3, 10, 3, 11, 3, 12, 3, 3, 2, 4, 2, 5, 2, 6, 2, 7, 2, 8, 2, 9, 2, + 1, 4, 1, 3, 1, 2, 1, 1, 1, 0, 2, 2, 2, 1, 10, 2, 11, 2, 12, 2, 13, 2, + 14, 2, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, 11, 1, 12, 1, + 13, 1, 14, 1, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10, 0, 11, 0, + 12, 0, 13, 0, 14, 0, 2, 0, + + // L=14 + 2, 5, 2, 4, 2, 3, 3, 6, 8, 6, 9, 6, + 3, 5, 4, 5, 5, 5, 6, 5, 7, 5, 8, 5, 9, 5, 3, 4, 4, 4, 5, 4, 6, 4, 7, 4, + 8, 4, 9, 4, 10, 4, 3, 3, 4, 3, 5, 3, 6, 3, 7, 3, 8, 3, 9, 3, 10, 3, 11, 3, + 12, 3, 14, 3, 3, 2, 4, 2, 5, 2, 6, 2, 7, 2, 8, 2, 9, 2, 10, 2, 11, 2, 12, 2, + 1, 4, 1, 3, 1, 2, 1, 1, 1, 0, 2, 2, 2, 1, 13, 2, 14, 2, 15, 2, 3, 1, + 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, 11, 1, 12, 1, 13, 1, 14, 1, + 15, 1, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, + 13, 0, 14, 0, 15, 0, 2, 0, + + // L=15 + 2, 5, 2, 4, 2, 3, 3, 6, 9, 6, 3, 5, + 4, 5, 5, 5, 6, 5, 8, 5, 9, 5, 3, 4, 4, 4, 5, 4, 6, 4, 7, 4, 8, 4, 9, 4, + 10, 4, 3, 3, 4, 3, 5, 3, 6, 3, 7, 3, 8, 3, 9, 3, 10, 3, 11, 3, 12, 3, 3, 2, + 4, 2, 5, 2, 6, 2, 7, 2, 8, 2, 9, 2, 10, 2, 11, 2, 12, 2, 13, 2, 14, 2, 15, 2, + 1, 4, 1, 3, 1, 2, 1, 1, 1, 0, 2, 2, 2, 1, 16, 2, 3, 1, 4, 1, 5, 1, + 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, 11, 1, 12, 1, 13, 1, 14, 1, 15, 1, 16, 1, + 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, + 14, 0, 15, 0, 16, 0, 2, 0, + + // L=16 + 2, 5, 2, 4, 2, 3, 3, 5, 4, 5, 5, 5, + 8, 5, 9, 5, 3, 4, 4, 4, 5, 4, 6, 4, 7, 4, 8, 4, 9, 4, 10, 4, 3, 3, 4, 3, + 5, 3, 6, 3, 7, 3, 8, 3, 9, 3, 10, 3, 11, 3, 12, 3, 3, 2, 4, 2, 5, 2, 6, 2, + 7, 2, 8, 2, 9, 2, 10, 2, 11, 2, 12, 2, 13, 2, 14, 2, 15, 2, 16, 2, 3, 1, 4, 1, + 1, 5, 1, 4, 1, 3, 1, 2, 1, 1, 1, 0, 2, 2, 2, 1, 5, 1, 6, 1, 7, 1, + 8, 1, 9, 1, 10, 1, 11, 1, 12, 1, 13, 1, 14, 1, 15, 1, 16, 1, 17, 1, 3, 0, + 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, + 15, 0, 16, 0, 17, 0, 2, 0, + + // L=17 + 2, 5, 2, 4, 2, 3, 3, 5, 4, 5, 3, 4, + 4, 4, 5, 4, 6, 4, 7, 4, 8, 4, 9, 4, 10, 4, 3, 3, 4, 3, 5, 3, 6, 3, 7, 3, + 8, 3, 9, 3, 10, 3, 11, 3, 12, 3, 13, 3, 3, 2, 4, 2, 5, 2, 6, 2, 7, 2, 8, 2, + 9, 2, 10, 2, 11, 2, 12, 2, 13, 2, 14, 2, 15, 2, 17, 2, 3, 1, 4, 1, 5, 1, 6, 1, + 1, 5, 1, 4, 1, 3, 1, 2, 1, 1, 1, 0, 2, 2, 2, 1, 7, 1, 8, 1, 9, 1, + 10, 1, 11, 1, 12, 1, 13, 1, 14, 1, 15, 1, 16, 1, 17, 1, 18, 1, 3, 0, 4, 0, + 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0, + 16, 0, 17, 0, 18, 0, 2, 0, + + // L=18 + 2, 5, 2, 4, 2, 3, 3, 5, 3, 4, 4, 4, + 5, 4, 6, 4, 7, 4, 8, 4, 10, 4, 11, 4, 3, 3, 4, 3, 5, 3, 6, 3, 7, 3, 8, 3, + 9, 3, 10, 3, 11, 3, 12, 3, 3, 2, 4, 2, 5, 2, 6, 2, 7, 2, 8, 2, 9, 2, 10, 2, + 11, 2, 12, 2, 13, 2, 14, 2, 15, 2, 16, 2, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, + 1, 5, 1, 4, 1, 3, 1, 2, 1, 1, 1, 0, 2, 2, 2, 1, 9, 1, 10, 1, 11, 1, + 12, 1, 13, 1, 14, 1, 15, 1, 16, 1, 17, 1, 18, 1, 19, 1, 3, 0, 4, 0, 5, 0, + 6, 0, 7, 0, 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0, 16, 0, + 17, 0, 18, 0, 19, 0, 2, 0, + + // L=19 + 2, 5, 2, 4, 2, 3, 3, 5, 3, 4, 4, 4, + 5, 4, 8, 4, 10, 4, 3, 3, 4, 3, 5, 3, 6, 3, 7, 3, 8, 3, 9, 3, 10, 3, 11, 3, + 12, 3, 3, 2, 4, 2, 5, 2, 6, 2, 7, 2, 8, 2, 9, 2, 10, 2, 11, 2, 12, 2, 13, 2, + 14, 2, 15, 2, 16, 2, 18, 2, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, + 1, 6, 1, 5, 1, 4, 1, 3, 1, 2, 1, 1, 1, 0, 2, 2, 2, 1, 11, 1, 12, 1, + 13, 1, 14, 1, 15, 1, 16, 1, 17, 1, 18, 1, 19, 1, 3, 0, 4, 0, 5, 0, 6, 0, + 7, 0, 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0, 16, 0, 17, 0, + 18, 0, 19, 0, 20, 0, 2, 0, + + // L=20 + 2, 5, 2, 4, 2, 3, 3, 5, 3, 4, 4, 4, + 5, 4, 8, 4, 10, 4, 3, 3, 4, 3, 5, 3, 6, 3, 7, 3, 8, 3, 9, 3, 10, 3, 11, 3, + 12, 3, 3, 2, 4, 2, 5, 2, 6, 2, 7, 2, 8, 2, 9, 2, 10, 2, 11, 2, 12, 2, 13, 2, + 14, 2, 16, 2, 19, 2, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, 11, 1, + 1, 6, 1, 5, 1, 4, 1, 3, 1, 2, 1, 1, 1, 0, 2, 2, 2, 1, 12, 1, 13, 1, + 14, 1, 15, 1, 16, 1, 17, 1, 19, 1, 20, 1, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, + 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0, 16, 0, 17, 0, 18, 0, + 19, 0, 20, 0, 21, 0, 2, 0, + + // L=21 + 2, 5, 2, 4, 2, 3, 3, 4, 4, 4, 5, 4, + 10, 4, 3, 3, 4, 3, 5, 3, 6, 3, 7, 3, 8, 3, 9, 3, 10, 3, 11, 3, 12, 3, 3, 2, + 4, 2, 5, 2, 6, 2, 7, 2, 8, 2, 9, 2, 10, 2, 11, 2, 12, 2, 13, 2, 14, 2, 17, 2, + 20, 2, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, 11, 1, 12, 1, 13, 1, + 1, 6, 1, 5, 1, 4, 1, 3, 1, 2, 1, 1, 1, 0, 2, 2, 2, 1, 14, 1, 15, 1, + 16, 1, 17, 1, 18, 1, 20, 1, 21, 1, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, + 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0, 16, 0, 17, 0, 18, 0, 19, 0, + 20, 0, 21, 0, 22, 0, 2, 0, + + // L=22 + 2, 5, 2, 4, 2, 3, 3, 4, 4, 4, 3, 3, + 4, 3, 5, 3, 6, 3, 7, 3, 8, 3, 9, 3, 10, 3, 11, 3, 12, 3, 3, 2, 4, 2, 5, 2, + 6, 2, 7, 2, 8, 2, 9, 2, 10, 2, 11, 2, 12, 2, 13, 2, 15, 2, 18, 2, 3, 1, 4, 1, + 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, 11, 1, 12, 1, 13, 1, 14, 1, 15, 1, 16, 1, + 1, 7, 1, 6, 1, 5, 1, 4, 1, 3, 1, 2, 1, 1, 1, 0, 2, 2, 2, 1, 17, 1, + 18, 1, 19, 1, 21, 1, 22, 1, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, + 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0, 16, 0, 17, 0, 18, 0, 19, 0, 20, 0, + 21, 0, 22, 0, 23, 0, 2, 0, + + // L=23 + 2, 5, 2, 4, 2, 3, 3, 4, 3, 3, 4, 3, + 5, 3, 6, 3, 7, 3, 8, 3, 10, 3, 11, 3, 13, 3, 3, 2, 4, 2, 5, 2, 6, 2, 7, 2, + 8, 2, 9, 2, 10, 2, 11, 2, 12, 2, 13, 2, 14, 2, 16, 2, 3, 1, 4, 1, 5, 1, 6, 1, + 7, 1, 8, 1, 9, 1, 10, 1, 11, 1, 12, 1, 13, 1, 14, 1, 15, 1, 16, 1, 17, 1, 18, 1, + 1, 7, 1, 6, 1, 5, 1, 4, 1, 3, 1, 2, 1, 1, 1, 0, 2, 2, 2, 1, 19, 1, + 20, 1, 22, 1, 23, 1, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10, 0, + 11, 0, 12, 0, 13, 0, 14, 0, 15, 0, 16, 0, 17, 0, 18, 0, 19, 0, 20, 0, 21, 0, + 22, 0, 23, 0, 24, 0, 2, 0, + + // L=24 + 2, 5, 2, 4, 2, 3, 3, 4, 3, 3, 4, 3, + 5, 3, 6, 3, 7, 3, 8, 3, 11, 3, 3, 2, 4, 2, 5, 2, 6, 2, 7, 2, 8, 2, 9, 2, + 10, 2, 11, 2, 12, 2, 13, 2, 14, 2, 15, 2, 17, 2, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, + 8, 1, 9, 1, 10, 1, 11, 1, 12, 1, 13, 1, 14, 1, 15, 1, 16, 1, 17, 1, 18, 1, 20, 1, + 1, 7, 1, 6, 1, 5, 1, 4, 1, 3, 1, 2, 1, 1, 1, 0, 2, 2, 2, 1, 21, 1, + 23, 1, 24, 1, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10, 0, 11, 0, + 12, 0, 13, 0, 14, 0, 15, 0, 16, 0, 17, 0, 18, 0, 19, 0, 20, 0, 21, 0, 22, 0, + 23, 0, 24, 0, 25, 0, 2, 0, + + // L=25 + 2, 5, 2, 4, 2, 3, 3, 4, 3, 3, 4, 3, + 5, 3, 6, 3, 8, 3, 11, 3, 3, 2, 4, 2, 5, 2, 6, 2, 7, 2, 8, 2, 9, 2, 10, 2, + 11, 2, 12, 2, 13, 2, 14, 2, 15, 2, 17, 2, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, + 9, 1, 10, 1, 11, 1, 12, 1, 13, 1, 14, 1, 15, 1, 16, 1, 17, 1, 18, 1, 20, 1, 21, 1, + 1, 8, 1, 7, 1, 6, 1, 5, 1, 4, 1, 3, 1, 2, 1, 1, 1, 0, 2, 2, 2, 1, + 23, 1, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, + 13, 0, 14, 0, 15, 0, 16, 0, 17, 0, 18, 0, 19, 0, 20, 0, 21, 0, 22, 0, 23, 0, + 24, 0, 25, 0, 26, 0, 2, 0, + + // L=26 + 2, 5, 2, 4, 2, 3, 3, 4, 3, 3, 4, 3, + 5, 3, 8, 3, 11, 3, 3, 2, 4, 2, 5, 2, 6, 2, 7, 2, 8, 2, 9, 2, 10, 2, 11, 2, + 12, 2, 13, 2, 14, 2, 17, 2, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, + 11, 1, 12, 1, 13, 1, 14, 1, 15, 1, 16, 1, 17, 1, 18, 1, 20, 1, 21, 1, 24, 1, 25, 1, + 1, 8, 1, 7, 1, 6, 1, 5, 1, 4, 1, 3, 1, 2, 1, 1, 1, 0, 2, 2, 2, 1, + 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, + 14, 0, 15, 0, 16, 0, 17, 0, 18, 0, 19, 0, 20, 0, 21, 0, 22, 0, 23, 0, 24, 0, + 25, 0, 26, 0, 27, 0, 2, 0, + + // L=27 + 2, 5, 2, 4, 2, 3, 3, 4, 3, 3, 4, 3, + 5, 3, 8, 3, 11, 3, 3, 2, 4, 2, 5, 2, 6, 2, 7, 2, 8, 2, 9, 2, 11, 2, 12, 2, + 14, 2, 17, 2, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, 11, 1, 12, 1, + 13, 1, 14, 1, 15, 1, 16, 1, 17, 1, 18, 1, 19, 1, 21, 1, 22, 1, 25, 1, 26, 1, 3, 0, + 1, 8, 1, 7, 1, 6, 1, 5, 1, 4, 1, 3, 1, 2, 1, 1, 1, 0, 2, 2, 2, 1, + 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, + 15, 0, 16, 0, 17, 0, 18, 0, 19, 0, 20, 0, 21, 0, 22, 0, 23, 0, 24, 0, 25, 0, + 26, 0, 27, 0, 28, 0, 2, 0, + + // L=28 + 2, 5, 2, 4, 2, 3, 3, 3, 4, 3, 5, 3, + 8, 3, 11, 3, 3, 2, 4, 2, 5, 2, 6, 2, 7, 2, 8, 2, 9, 2, 11, 2, 12, 2, 14, 2, + 18, 2, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, 11, 1, 12, 1, 13, 1, + 14, 1, 15, 1, 16, 1, 17, 1, 18, 1, 19, 1, 22, 1, 23, 1, 26, 1, 3, 0, 4, 0, 5, 0, + 1, 9, 1, 8, 1, 7, 1, 6, 1, 5, 1, 4, 1, 3, 1, 2, 1, 1, 1, 0, 2, 2, + 2, 1, 6, 0, 7, 0, 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0, + 16, 0, 17, 0, 18, 0, 19, 0, 20, 0, 21, 0, 22, 0, 23, 0, 24, 0, 25, 0, 26, 0, + 27, 0, 28, 0, 29, 0, 2, 0, + + // L=29 + 2, 5, 2, 4, 2, 3, 3, 3, 4, 3, 5, 3, + 11, 3, 3, 2, 4, 2, 5, 2, 6, 2, 7, 2, 8, 2, 9, 2, 11, 2, 12, 2, 15, 2, 19, 2, + 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, 11, 1, 12, 1, 13, 1, 14, 1, + 15, 1, 16, 1, 17, 1, 18, 1, 19, 1, 20, 1, 23, 1, 27, 1, 3, 0, 4, 0, 5, 0, 6, 0, + 1, 9, 1, 8, 1, 7, 1, 6, 1, 5, 1, 4, 1, 3, 1, 2, 1, 1, 1, 0, 2, 2, + 2, 1, 7, 0, 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0, 16, 0, + 17, 0, 18, 0, 19, 0, 20, 0, 21, 0, 22, 0, 23, 0, 24, 0, 25, 0, 26, 0, 27, 0, + 28, 0, 29, 0, 30, 0, 2, 0, + + // L=30 + 2, 5, 2, 4, 2, 3, 3, 3, 4, 3, 5, 3, + 3, 2, 4, 2, 5, 2, 6, 2, 7, 2, 8, 2, 9, 2, 12, 2, 13, 2, 16, 2, 20, 2, 3, 1, + 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, 11, 1, 12, 1, 13, 1, 14, 1, 15, 1, + 16, 1, 17, 1, 18, 1, 20, 1, 21, 1, 24, 1, 28, 1, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, + 1, 9, 1, 8, 1, 7, 1, 6, 1, 5, 1, 4, 1, 3, 1, 2, 1, 1, 1, 0, 2, 2, + 2, 1, 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0, 16, 0, 17, 0, + 18, 0, 19, 0, 20, 0, 21, 0, 22, 0, 23, 0, 24, 0, 25, 0, 26, 0, 27, 0, 28, 0, + 29, 0, 30, 0, 31, 0, 2, 0, + + // L=31 + 2, 5, 2, 4, 2, 3, 3, 3, 4, 3, 3, 2, + 4, 2, 5, 2, 6, 2, 7, 2, 8, 2, 9, 2, 12, 2, 13, 2, 16, 2, 3, 1, 4, 1, 5, 1, + 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, 11, 1, 12, 1, 13, 1, 14, 1, 15, 1, 16, 1, 17, 1, + 18, 1, 20, 1, 21, 1, 24, 1, 28, 1, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, + 1, 10, 1, 9, 1, 8, 1, 7, 1, 6, 1, 5, 1, 4, 1, 3, 1, 2, 1, 1, 1, 0, + 2, 2, 2, 1, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0, 16, 0, 17, 0, 18, 0, + 19, 0, 20, 0, 21, 0, 22, 0, 23, 0, 24, 0, 25, 0, 26, 0, 27, 0, 28, 0, 29, 0, + 30, 0, 31, 0, 32, 0, 2, 0, + + // L=32 + 2, 5, 2, 4, 2, 3, 3, 3, 4, 3, 3, 2, + 4, 2, 5, 2, 6, 2, 7, 2, 8, 2, 9, 2, 12, 2, 13, 2, 16, 2, 3, 1, 4, 1, 5, 1, + 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, 11, 1, 12, 1, 13, 1, 14, 1, 15, 1, 16, 1, 17, 1, + 18, 1, 20, 1, 21, 1, 24, 1, 29, 1, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, + 1, 10, 1, 9, 1, 8, 1, 7, 1, 6, 1, 5, 1, 4, 1, 3, 1, 2, 1, 1, 1, 0, + 2, 2, 2, 1, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0, 16, 0, 17, 0, 18, 0, + 19, 0, 20, 0, 21, 0, 22, 0, 23, 0, 24, 0, 25, 0, 26, 0, 27, 0, 28, 0, 29, 0, + 30, 0, 31, 0, 32, 0, 2, 0, + + // L=33 + 2, 5, 2, 4, 2, 3, 3, 3, 3, 2, 4, 2, + 5, 2, 6, 2, 7, 2, 8, 2, 9, 2, 12, 2, 13, 2, 16, 2, 3, 1, 4, 1, 5, 1, 6, 1, + 7, 1, 8, 1, 9, 1, 10, 1, 11, 1, 12, 1, 13, 1, 14, 1, 15, 1, 16, 1, 17, 1, 20, 1, + 21, 1, 25, 1, 30, 1, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10, 0, 11, 0, + 1, 10, 1, 9, 1, 8, 1, 7, 1, 6, 1, 5, 1, 4, 1, 3, 1, 2, 1, 1, 1, 0, + 2, 2, 2, 1, 12, 0, 13, 0, 14, 0, 15, 0, 16, 0, 17, 0, 18, 0, 19, 0, 20, 0, + 21, 0, 22, 0, 23, 0, 24, 0, 25, 0, 26, 0, 27, 0, 28, 0, 29, 0, 30, 0, 31, 0, + 32, 0, 33, 0, 34, 0, 2, 0, + + // L=34 + 2, 5, 2, 4, 2, 3, 3, 3, 3, 2, 4, 2, + 5, 2, 6, 2, 7, 2, 8, 2, 12, 2, 16, 2, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, + 9, 1, 10, 1, 11, 1, 12, 1, 13, 1, 14, 1, 15, 1, 16, 1, 17, 1, 18, 1, 21, 1, 22, 1, + 26, 1, 31, 1, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, + 1, 11, 1, 10, 1, 9, 1, 8, 1, 7, 1, 6, 1, 5, 1, 4, 1, 3, 1, 2, 1, 1, + 1, 0, 2, 2, 2, 1, 13, 0, 14, 0, 15, 0, 16, 0, 17, 0, 18, 0, 19, 0, 20, 0, + 21, 0, 22, 0, 23, 0, 24, 0, 25, 0, 26, 0, 27, 0, 28, 0, 29, 0, 30, 0, 31, 0, + 32, 0, 33, 0, 34, 0, 2, 0, + + // L=35 + 2, 5, 2, 4, 2, 3, 3, 3, 3, 2, 4, 2, + 5, 2, 6, 2, 7, 2, 8, 2, 12, 2, 17, 2, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, + 9, 1, 10, 1, 11, 1, 12, 1, 13, 1, 14, 1, 15, 1, 16, 1, 17, 1, 18, 1, 22, 1, 23, 1, + 27, 1, 32, 1, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, + 1, 11, 1, 10, 1, 9, 1, 8, 1, 7, 1, 6, 1, 5, 1, 4, 1, 3, 1, 2, 1, 1, + 1, 0, 2, 2, 2, 1, 13, 0, 14, 0, 15, 0, 16, 0, 17, 0, 18, 0, 19, 0, 20, 0, + 21, 0, 22, 0, 23, 0, 24, 0, 25, 0, 26, 0, 27, 0, 28, 0, 29, 0, 30, 0, 32, 0, + 33, 0, 34, 0, 35, 0, 2, 0, + + // L=36 + 2, 5, 2, 4, 2, 3, 3, 3, 3, 2, 4, 2, + 5, 2, 6, 2, 7, 2, 8, 2, 13, 2, 18, 2, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, + 9, 1, 10, 1, 11, 1, 13, 1, 14, 1, 15, 1, 16, 1, 18, 1, 19, 1, 23, 1, 24, 1, 28, 1, + 33, 1, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, + 1, 11, 1, 10, 1, 9, 1, 8, 1, 7, 1, 6, 1, 5, 1, 4, 1, 3, 1, 2, 1, 1, + 1, 0, 2, 2, 2, 1, 14, 0, 15, 0, 16, 0, 17, 0, 18, 0, 19, 0, 20, 0, 21, 0, + 22, 0, 23, 0, 24, 0, 25, 0, 26, 0, 27, 0, 28, 0, 29, 0, 30, 0, 31, 0, 33, 0, + 34, 0, 35, 0, 36, 0, 2, 0, + + // L=37 + 2, 5, 2, 4, 2, 3, 3, 3, 3, 2, 4, 2, + 5, 2, 6, 2, 8, 2, 13, 2, 18, 2, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, + 10, 1, 11, 1, 13, 1, 14, 1, 15, 1, 16, 1, 17, 1, 18, 1, 19, 1, 23, 1, 28, 1, 33, 1, + 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, + 1, 11, 1, 10, 1, 9, 1, 8, 1, 7, 1, 6, 1, 5, 1, 4, 1, 3, 1, 2, 1, 1, + 1, 0, 2, 2, 2, 1, 15, 0, 16, 0, 17, 0, 18, 0, 19, 0, 20, 0, 21, 0, 22, 0, + 23, 0, 24, 0, 25, 0, 26, 0, 27, 0, 28, 0, 29, 0, 30, 0, 31, 0, 33, 0, 34, 0, + 35, 0, 36, 0, 37, 0, 2, 0, + + // L=38 + 2, 5, 2, 4, 2, 3, 3, 3, 3, 2, 4, 2, + 5, 2, 6, 2, 8, 2, 13, 2, 18, 2, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, + 10, 1, 11, 1, 13, 1, 14, 1, 15, 1, 16, 1, 18, 1, 19, 1, 23, 1, 28, 1, 34, 1, 3, 0, + 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0, + 1, 11, 1, 10, 1, 9, 1, 8, 1, 7, 1, 6, 1, 5, 1, 4, 1, 3, 1, 2, 1, 1, + 1, 0, 2, 2, 2, 1, 16, 0, 17, 0, 18, 0, 19, 0, 20, 0, 21, 0, 22, 0, 23, 0, + 24, 0, 25, 0, 26, 0, 27, 0, 28, 0, 29, 0, 30, 0, 31, 0, 32, 0, 34, 0, 35, 0, + 36, 0, 37, 0, 38, 0, 2, 0, + + // L=39 + 2, 5, 2, 4, 2, 3, 3, 3, 3, 2, 4, 2, + 5, 2, 6, 2, 8, 2, 13, 2, 18, 2, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, + 10, 1, 11, 1, 13, 1, 14, 1, 15, 1, 16, 1, 18, 1, 19, 1, 23, 1, 24, 1, 29, 1, 35, 1, + 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, + 1, 11, 1, 10, 1, 9, 1, 8, 1, 7, 1, 6, 1, 5, 1, 4, 1, 3, 1, 2, 1, 1, + 1, 0, 2, 2, 2, 1, 15, 0, 16, 0, 17, 0, 18, 0, 19, 0, 20, 0, 21, 0, 22, 0, + 23, 0, 24, 0, 25, 0, 26, 0, 27, 0, 29, 0, 30, 0, 31, 0, 32, 0, 33, 0, 35, 0, + 36, 0, 37, 0, 38, 0, 2, 0, + + // L=40 + 2, 5, 2, 4, 2, 3, 3, 3, 3, 2, 4, 2, + 5, 2, 6, 2, 8, 2, 13, 2, 18, 2, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, + 10, 1, 11, 1, 13, 1, 14, 1, 15, 1, 18, 1, 19, 1, 24, 1, 25, 1, 30, 1, 36, 1, 3, 0, + 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0, + 1, 11, 1, 10, 1, 9, 1, 8, 1, 7, 1, 6, 1, 5, 1, 4, 1, 3, 1, 2, 1, 1, + 1, 0, 2, 2, 2, 1, 16, 0, 17, 0, 18, 0, 19, 0, 20, 0, 21, 0, 22, 0, 23, 0, + 24, 0, 25, 0, 26, 0, 27, 0, 28, 0, 30, 0, 31, 0, 32, 0, 33, 0, 34, 0, 36, 0, + 37, 0, 38, 0, 39, 0, 2, 0, + + // L=41 + 2, 5, 2, 4, 2, 3, 3, 3, 3, 2, 4, 2, + 5, 2, 8, 2, 13, 2, 19, 2, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, + 13, 1, 14, 1, 15, 1, 16, 1, 19, 1, 20, 1, 25, 1, 26, 1, 31, 1, 37, 1, 3, 0, 4, 0, + 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0, 16, 0, + 1, 11, 1, 10, 1, 9, 1, 8, 1, 7, 1, 6, 1, 5, 1, 4, 1, 3, 1, 2, 1, 1, + 1, 0, 2, 2, 2, 1, 17, 0, 18, 0, 19, 0, 20, 0, 21, 0, 22, 0, 23, 0, 24, 0, + 25, 0, 26, 0, 27, 0, 28, 0, 29, 0, 31, 0, 32, 0, 33, 0, 34, 0, 35, 0, 37, 0, + 38, 0, 39, 0, 40, 0, 2, 0, + + // L=42 + 2, 5, 2, 4, 2, 3, 3, 3, 3, 2, 4, 2, + 5, 2, 8, 2, 14, 2, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, 11, 1, + 14, 1, 15, 1, 16, 1, 17, 1, 20, 1, 21, 1, 26, 1, 27, 1, 32, 1, 38, 1, 3, 0, 4, 0, + 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0, 16, 0, + 1, 11, 1, 10, 1, 9, 1, 8, 1, 7, 1, 6, 1, 5, 1, 4, 1, 3, 1, 2, 1, 1, + 1, 0, 2, 2, 2, 1, 17, 0, 18, 0, 19, 0, 20, 0, 21, 0, 22, 0, 23, 0, 24, 0, + 25, 0, 26, 0, 27, 0, 28, 0, 29, 0, 30, 0, 32, 0, 33, 0, 34, 0, 35, 0, 38, 0, + 39, 0, 40, 0, 41, 0, 2, 0, + + // L=43 + 2, 5, 2, 4, 2, 3, 3, 3, 3, 2, 4, 2, + 5, 2, 8, 2, 14, 2, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, 11, 1, + 14, 1, 15, 1, 16, 1, 17, 1, 20, 1, 21, 1, 26, 1, 32, 1, 38, 1, 3, 0, 4, 0, 5, 0, + 6, 0, 7, 0, 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0, 16, 0, 17, 0, + 1, 11, 1, 10, 1, 9, 1, 8, 1, 7, 1, 6, 1, 5, 1, 4, 1, 3, 1, 2, 1, 1, + 1, 0, 2, 2, 2, 1, 18, 0, 19, 0, 20, 0, 21, 0, 22, 0, 23, 0, 24, 0, 25, 0, + 26, 0, 27, 0, 28, 0, 29, 0, 30, 0, 32, 0, 33, 0, 34, 0, 35, 0, 38, 0, 39, 0, + 40, 0, 41, 0, 42, 0, 2, 0, + + // L=44 + 2, 5, 2, 4, 2, 3, 3, 3, 3, 2, 4, 2, + 5, 2, 8, 2, 14, 2, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, 14, 1, + 15, 1, 16, 1, 17, 1, 20, 1, 21, 1, 26, 1, 32, 1, 39, 1, 3, 0, 4, 0, 5, 0, 6, 0, + 7, 0, 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0, 16, 0, 17, 0, 18, 0, + 1, 11, 1, 10, 1, 9, 1, 8, 1, 7, 1, 6, 1, 5, 1, 4, 1, 3, 1, 2, 1, 1, + 1, 0, 2, 2, 2, 1, 19, 0, 20, 0, 21, 0, 22, 0, 23, 0, 24, 0, 25, 0, 26, 0, + 27, 0, 28, 0, 29, 0, 30, 0, 32, 0, 33, 0, 34, 0, 35, 0, 36, 0, 39, 0, 40, 0, + 41, 0, 42, 0, 43, 0, 2, 0, + + // L=45 + 2, 5, 2, 4, 2, 3, 3, 3, 3, 2, 4, 2, + 5, 2, 8, 2, 14, 2, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, 14, 1, + 15, 1, 16, 1, 20, 1, 21, 1, 26, 1, 27, 1, 33, 1, 40, 1, 3, 0, 4, 0, 5, 0, 6, 0, + 7, 0, 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0, 16, 0, 17, 0, 18, 0, + 1, 11, 1, 10, 1, 9, 1, 8, 1, 7, 1, 6, 1, 5, 1, 4, 1, 3, 1, 2, 1, 1, + 1, 0, 2, 2, 2, 1, 19, 0, 20, 0, 21, 0, 22, 0, 23, 0, 24, 0, 25, 0, 26, 0, + 27, 0, 28, 0, 29, 0, 30, 0, 33, 0, 34, 0, 35, 0, 36, 0, 37, 0, 40, 0, 41, 0, + 42, 0, 43, 0, 44, 0, 2, 0, + + // L=46 + 2, 5, 2, 4, 2, 3, 3, 2, 4, 2, 5, 2, + 8, 2, 14, 2, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, 14, 1, 15, 1, + 16, 1, 20, 1, 21, 1, 27, 1, 28, 1, 34, 1, 41, 1, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, + 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0, 16, 0, 17, 0, 18, 0, 19, 0, + 1, 11, 1, 10, 1, 9, 1, 8, 1, 7, 1, 6, 1, 5, 1, 4, 1, 3, 1, 2, 1, 1, + 1, 0, 2, 2, 2, 1, 20, 0, 21, 0, 22, 0, 23, 0, 24, 0, 25, 0, 26, 0, 27, 0, + 28, 0, 29, 0, 30, 0, 31, 0, 34, 0, 35, 0, 36, 0, 37, 0, 38, 0, 41, 0, 42, 0, + 43, 0, 44, 0, 45, 0, 2, 0, + + // L=47 + 2, 5, 2, 4, 2, 3, 3, 2, 4, 2, 5, 2, + 8, 2, 14, 2, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, 14, 1, 15, 1, + 16, 1, 21, 1, 22, 1, 28, 1, 29, 1, 35, 1, 42, 1, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, + 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0, 16, 0, 17, 0, 18, 0, 19, 0, + 1, 11, 1, 10, 1, 9, 1, 8, 1, 7, 1, 6, 1, 5, 1, 4, 1, 3, 1, 2, 1, 1, + 1, 0, 2, 2, 2, 1, 20, 0, 21, 0, 22, 0, 23, 0, 24, 0, 25, 0, 26, 0, 27, 0, + 28, 0, 29, 0, 30, 0, 31, 0, 32, 0, 35, 0, 36, 0, 37, 0, 38, 0, 39, 0, 42, 0, + 43, 0, 44, 0, 45, 0, 2, 0, + + // L=48 + 2, 5, 2, 4, 2, 3, 3, 2, 4, 2, 5, 2, + 8, 2, 15, 2, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, 15, 1, 16, 1, + 17, 1, 22, 1, 23, 1, 29, 1, 30, 1, 36, 1, 43, 1, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, + 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0, 16, 0, 17, 0, 18, 0, 19, 0, + 1, 11, 1, 10, 1, 9, 1, 8, 1, 7, 1, 6, 1, 5, 1, 4, 1, 3, 1, 2, 1, 1, + 1, 0, 2, 2, 2, 1, 20, 0, 21, 0, 22, 0, 23, 0, 24, 0, 25, 0, 26, 0, 27, 0, + 28, 0, 29, 0, 30, 0, 31, 0, 32, 0, 33, 0, 36, 0, 37, 0, 38, 0, 39, 0, 43, 0, + 44, 0, 45, 0, 46, 0, 2, 0, + + // L=49 + 2, 5, 2, 4, 2, 3, 3, 2, 4, 2, 5, 2, + 8, 2, 15, 2, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, 15, 1, 16, 1, + 17, 1, 22, 1, 23, 1, 29, 1, 30, 1, 36, 1, 43, 1, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, + 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0, 16, 0, 17, 0, 18, 0, 19, 0, + 1, 11, 1, 10, 1, 9, 1, 8, 1, 7, 1, 6, 1, 5, 1, 4, 1, 3, 1, 2, 1, 1, + 1, 0, 2, 2, 2, 1, 20, 0, 21, 0, 22, 0, 23, 0, 24, 0, 25, 0, 26, 0, 27, 0, + 29, 0, 30, 0, 31, 0, 32, 0, 33, 0, 36, 0, 37, 0, 38, 0, 39, 0, 43, 0, 44, 0, + 45, 0, 46, 0, 47, 0, 2, 0, + + // L=50 + 2, 5, 2, 4, 2, 3, 3, 2, 4, 2, 5, 2, + 8, 2, 15, 2, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, 15, 1, 16, 1, + 17, 1, 22, 1, 23, 1, 29, 1, 30, 1, 36, 1, 44, 1, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, + 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0, 16, 0, 17, 0, 18, 0, 19, 0, + 1, 11, 1, 10, 1, 9, 1, 8, 1, 7, 1, 6, 1, 5, 1, 4, 1, 3, 1, 2, 1, 1, + 1, 0, 2, 2, 2, 1, 20, 0, 21, 0, 22, 0, 23, 0, 24, 0, 25, 0, 26, 0, 27, 0, + 29, 0, 30, 0, 31, 0, 32, 0, 33, 0, 36, 0, 37, 0, 38, 0, 39, 0, 40, 0, 44, 0, + 45, 0, 46, 0, 47, 0, 2, 0, + + // L=51 + 2, 5, 2, 4, 2, 3, 3, 2, 4, 2, 5, 2, + 8, 2, 15, 2, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, 15, 1, 16, 1, + 22, 1, 23, 1, 29, 1, 30, 1, 37, 1, 45, 1, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, + 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0, 16, 0, 17, 0, 18, 0, 19, 0, 20, 0, + 1, 11, 1, 10, 1, 9, 1, 8, 1, 7, 1, 6, 1, 5, 1, 4, 1, 3, 1, 2, 1, 1, + 1, 0, 2, 2, 2, 1, 21, 0, 22, 0, 23, 0, 24, 0, 25, 0, 26, 0, 27, 0, 29, 0, + 30, 0, 31, 0, 32, 0, 33, 0, 37, 0, 38, 0, 39, 0, 40, 0, 41, 0, 45, 0, 46, 0, + 47, 0, 48, 0, 49, 0, 2, 0, + + // L=52 + 2, 5, 2, 4, 2, 3, 3, 2, 4, 2, 8, 2, + 15, 2, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 15, 1, 16, 1, 17, 1, 22, 1, + 23, 1, 30, 1, 31, 1, 38, 1, 46, 1, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, + 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0, 16, 0, 17, 0, 18, 0, 19, 0, 20, 0, 21, 0, + 1, 11, 1, 10, 1, 9, 1, 8, 1, 7, 1, 6, 1, 5, 1, 4, 1, 3, 1, 2, 1, 1, + 1, 0, 2, 2, 2, 1, 22, 0, 23, 0, 24, 0, 25, 0, 26, 0, 27, 0, 28, 0, 30, 0, + 31, 0, 32, 0, 33, 0, 34, 0, 38, 0, 39, 0, 40, 0, 41, 0, 42, 0, 46, 0, 47, 0, + 48, 0, 49, 0, 50, 0, 2, 0, + + // L=53 + 2, 5, 2, 4, 2, 3, 3, 2, 4, 2, 8, 2, + 15, 2, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 15, 1, 16, 1, 17, 1, 23, 1, + 24, 1, 31, 1, 32, 1, 39, 1, 47, 1, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, + 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0, 16, 0, 17, 0, 18, 0, 19, 0, 20, 0, 21, 0, + 1, 11, 1, 10, 1, 9, 1, 8, 1, 7, 1, 6, 1, 5, 1, 4, 1, 3, 1, 2, 1, 1, + 1, 0, 2, 2, 2, 1, 22, 0, 23, 0, 24, 0, 25, 0, 26, 0, 27, 0, 28, 0, 29, 0, + 31, 0, 32, 0, 33, 0, 34, 0, 35, 0, 39, 0, 40, 0, 41, 0, 42, 0, 43, 0, 47, 0, + 48, 0, 49, 0, 50, 0, 2, 0, + + // L=54 + 2, 5, 2, 4, 2, 3, 3, 2, 4, 2, 8, 2, + 16, 2, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, 16, 1, 17, 1, 18, 1, + 24, 1, 25, 1, 32, 1, 33, 1, 40, 1, 48, 1, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, + 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 16, 0, 17, 0, 18, 0, 19, 0, 20, 0, 21, 0, + 1, 11, 1, 10, 1, 9, 1, 8, 1, 7, 1, 6, 1, 5, 1, 4, 1, 3, 1, 2, 1, 1, + 1, 0, 2, 2, 2, 1, 22, 0, 24, 0, 25, 0, 26, 0, 27, 0, 28, 0, 29, 0, 30, 0, + 32, 0, 33, 0, 34, 0, 35, 0, 36, 0, 40, 0, 41, 0, 42, 0, 43, 0, 44, 0, 48, 0, + 49, 0, 50, 0, 51, 0, 2, 0, + + // L=55 + 2, 5, 2, 4, 2, 3, 3, 2, 4, 2, 8, 2, + 16, 2, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, 16, 1, 17, 1, 18, 1, + 24, 1, 25, 1, 32, 1, 33, 1, 40, 1, 48, 1, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, + 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 16, 0, 17, 0, 18, 0, 19, 0, 20, 0, 21, 0, + 1, 11, 1, 10, 1, 9, 1, 8, 1, 7, 1, 6, 1, 5, 1, 4, 1, 3, 1, 2, 1, 1, + 1, 0, 2, 2, 2, 1, 22, 0, 24, 0, 25, 0, 26, 0, 27, 0, 28, 0, 29, 0, 30, 0, + 32, 0, 33, 0, 34, 0, 35, 0, 36, 0, 40, 0, 41, 0, 42, 0, 43, 0, 48, 0, 49, 0, + 50, 0, 51, 0, 52, 0, 2, 0, + + // L=56 + 2, 5, 2, 4, 2, 3, 3, 2, 4, 2, 8, 2, + 16, 2, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, 16, 1, 17, 1, 18, 1, + 24, 1, 25, 1, 32, 1, 33, 1, 40, 1, 49, 1, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, + 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 16, 0, 17, 0, 18, 0, 19, 0, 20, 0, 21, 0, + 1, 11, 1, 10, 1, 9, 1, 8, 1, 7, 1, 6, 1, 5, 1, 4, 1, 3, 1, 2, 1, 1, + 1, 0, 2, 2, 2, 1, 22, 0, 24, 0, 25, 0, 26, 0, 27, 0, 28, 0, 29, 0, 30, 0, + 32, 0, 33, 0, 34, 0, 35, 0, 36, 0, 40, 0, 41, 0, 42, 0, 43, 0, 44, 0, 49, 0, + 50, 0, 51, 0, 52, 0, 2, 0 +}; + +/* + * log magnitude residual block lengths + */ +const int ImbeJi[48][6] = { + {1, 1, 1, 2, 2, 2}, + {1, 1, 2, 2, 2, 2}, + {1, 2, 2, 2, 2, 2}, + {2, 2, 2, 2, 2, 2}, + {2, 2, 2, 2, 2, 3}, + {2, 2, 2, 2, 3, 3}, + {2, 2, 2, 3, 3, 3}, + {2, 2, 3, 3, 3, 3}, + {2, 3, 3, 3, 3, 3}, + {3, 3, 3, 3, 3, 3}, + {3, 3, 3, 3, 3, 4}, + {3, 3, 3, 3, 4, 4}, + {3, 3, 3, 4, 4, 4}, + {3, 3, 4, 4, 4, 4}, + {3, 4, 4, 4, 4, 4}, + {4, 4, 4, 4, 4, 4}, + {4, 4, 4, 4, 4, 5}, + {4, 4, 4, 4, 5, 5}, + {4, 4, 4, 5, 5, 5}, + {4, 4, 5, 5, 5, 5}, + {4, 5, 5, 5, 5, 5}, + {5, 5, 5, 5, 5, 5}, + {5, 5, 5, 5, 5, 6}, + {5, 5, 5, 5, 6, 6}, + {5, 5, 5, 6, 6, 6}, + {5, 5, 6, 6, 6, 6}, + {5, 6, 6, 6, 6, 6}, + {6, 6, 6, 6, 6, 6}, + {6, 6, 6, 6, 6, 7}, + {6, 6, 6, 6, 7, 7}, + {6, 6, 6, 7, 7, 7}, + {6, 6, 7, 7, 7, 7}, + {6, 7, 7, 7, 7, 7}, + {7, 7, 7, 7, 7, 7}, + {7, 7, 7, 7, 7, 8}, + {7, 7, 7, 7, 8, 8}, + {7, 7, 7, 8, 8, 8}, + {7, 7, 8, 8, 8, 8}, + {7, 8, 8, 8, 8, 8}, + {8, 8, 8, 8, 8, 8}, + {8, 8, 8, 8, 8, 9}, + {8, 8, 8, 8, 9, 9}, + {8, 8, 8, 9, 9, 9}, + {8, 8, 9, 9, 9, 9}, + {8, 9, 9, 9, 9, 9}, + {9, 9, 9, 9, 9, 9}, + {9, 9, 9, 9, 9, 10}, + {9, 9, 9, 9, 10, 10} +}; + +#endif diff --git a/mbelib-wasm/mbelib/libmbe.pc.in b/mbelib-wasm/mbelib/libmbe.pc.in new file mode 100644 index 0000000..c99f845 --- /dev/null +++ b/mbelib-wasm/mbelib/libmbe.pc.in @@ -0,0 +1,10 @@ +libdir=@CMAKE_INSTALL_FULL_LIBDIR@ +includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ + +Name: libMBE +Description: P25 Phase 1 and ProVoice vocoder +Version: 1.3.0 + +Libs: -L${libdir} -lmbe +Libs.private: -lm +Cflags: -I${includedir} \ No newline at end of file diff --git a/mbelib-wasm/mbelib/mbelib.c b/mbelib-wasm/mbelib/mbelib.c new file mode 100644 index 0000000..d43dd7c --- /dev/null +++ b/mbelib-wasm/mbelib/mbelib.c @@ -0,0 +1,500 @@ +/* + * Copyright (C) 2010 mbelib Author + * GPG Key ID: 0xEA5EFE2C (9E7A 5527 9CDC EBF7 BF1B D772 4F98 E863 EA5E FE2C) + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include +#include + +#include "mbelib.h" +#include "mbelib_const.h" + +/** + * \return A pseudo-random float between [0.0, 1.0]. + * See http://www.azillionmonkeys.com/qed/random.html for further improvements + */ +static float +mbe_rand() +{ + return ((float) rand () / (float) RAND_MAX); +} + +/** + * \return A pseudo-random float between [-pi, +pi]. + */ +static float +mbe_rand_phase() +{ + return mbe_rand() * (((float)M_PI) * 2.0F) - ((float)M_PI); +} + +void +mbe_printVersion (char *str) +{ + sprintf (str, "%s", MBELIB_VERSION); +} + +void +mbe_moveMbeParms (mbe_parms * cur_mp, mbe_parms * prev_mp) +{ + + int l; + + prev_mp->w0 = cur_mp->w0; + prev_mp->L = cur_mp->L; + prev_mp->K = cur_mp->K; // necessary? + prev_mp->Ml[0] = (float) 0; + prev_mp->gamma = cur_mp->gamma; + prev_mp->repeat = cur_mp->repeat; + for (l = 0; l <= 56; l++) + { + prev_mp->Ml[l] = cur_mp->Ml[l]; + prev_mp->Vl[l] = cur_mp->Vl[l]; + prev_mp->log2Ml[l] = cur_mp->log2Ml[l]; + prev_mp->PHIl[l] = cur_mp->PHIl[l]; + prev_mp->PSIl[l] = cur_mp->PSIl[l]; + } +} + +void +mbe_useLastMbeParms (mbe_parms * cur_mp, mbe_parms * prev_mp) +{ + + int l; + + cur_mp->w0 = prev_mp->w0; + cur_mp->L = prev_mp->L; + cur_mp->K = prev_mp->K; // necessary? + cur_mp->Ml[0] = (float) 0; + cur_mp->gamma = prev_mp->gamma; + cur_mp->repeat = prev_mp->repeat; + for (l = 0; l <= 56; l++) + { + cur_mp->Ml[l] = prev_mp->Ml[l]; + cur_mp->Vl[l] = prev_mp->Vl[l]; + cur_mp->log2Ml[l] = prev_mp->log2Ml[l]; + cur_mp->PHIl[l] = prev_mp->PHIl[l]; + cur_mp->PSIl[l] = prev_mp->PSIl[l]; + } +} + +void +mbe_initMbeParms (mbe_parms * cur_mp, mbe_parms * prev_mp, mbe_parms * prev_mp_enhanced) +{ + + int l; + + prev_mp->w0 = 0.09378; + prev_mp->L = 30; + prev_mp->K = 10; + prev_mp->gamma = (float) 0; + for (l = 0; l <= 56; l++) + { + prev_mp->Ml[l] = (float) 0; + prev_mp->Vl[l] = 0; + prev_mp->log2Ml[l] = (float) 0; // log2 of 1 == 0 + prev_mp->PHIl[l] = (float) 0; + prev_mp->PSIl[l] = (M_PI / (float) 2); + } + prev_mp->repeat = 0; + mbe_moveMbeParms (prev_mp, cur_mp); + mbe_moveMbeParms (prev_mp, prev_mp_enhanced); +} + +void +mbe_spectralAmpEnhance (mbe_parms * cur_mp) +{ + + float Rm0, Rm1, R2m0, R2m1, Wl[57]; + int l; + float sum, gamma, M; + + Rm0 = 0; + Rm1 = 0; + for (l = 1; l <= cur_mp->L; l++) + { + Rm0 = Rm0 + (cur_mp->Ml[l] * cur_mp->Ml[l]); + Rm1 = Rm1 + ((cur_mp->Ml[l] * cur_mp->Ml[l]) * cosf (cur_mp->w0 * (float) l)); + } + + R2m0 = (Rm0*Rm0); + R2m1 = (Rm1*Rm1); + + for (l = 1; l <= cur_mp->L; l++) + { + if (cur_mp->Ml[l] != 0) + { + Wl[l] = sqrtf (cur_mp->Ml[l]) * powf ((((float) 0.96 * M_PI * ((R2m0 + R2m1) - ((float) 2 * Rm0 * Rm1 * cosf (cur_mp->w0 * (float) l)))) / (cur_mp->w0 * Rm0 * (R2m0 - R2m1))), (float) 0.25); + + if ((8 * l) <= cur_mp->L) + { + } + else if (Wl[l] > 1.2) + { + cur_mp->Ml[l] = 1.2 * cur_mp->Ml[l]; + } + else if (Wl[l] < 0.5) + { + cur_mp->Ml[l] = 0.5 * cur_mp->Ml[l]; + } + else + { + cur_mp->Ml[l] = Wl[l] * cur_mp->Ml[l]; + } + } + } + + // generate scaling factor + sum = 0; + for (l = 1; l <= cur_mp->L; l++) + { + M = cur_mp->Ml[l]; + if (M < 0) + { + M = -M; + } + sum += (M*M); + } + if (sum == 0) + { + gamma = (float) 1.0; + } + else + { + gamma = sqrtf (Rm0 / sum); + } + + // apply scaling factor + for (l = 1; l <= cur_mp->L; l++) + { + cur_mp->Ml[l] = gamma * cur_mp->Ml[l]; + } +} + +void +mbe_synthesizeSilencef (float *aout_buf) +{ + + int n; + float *aout_buf_p; + + aout_buf_p = aout_buf; + for (n = 0; n < 160; n++) + { + *aout_buf_p = (float) 0; + aout_buf_p++; + } +} + +void +mbe_synthesizeSilence (short *aout_buf) +{ + + int n; + short *aout_buf_p; + + aout_buf_p = aout_buf; + for (n = 0; n < 160; n++) + { + *aout_buf_p = (short) 0; + aout_buf_p++; + } +} + +void +mbe_synthesizeSpeechf (float *aout_buf, mbe_parms * cur_mp, mbe_parms * prev_mp, int uvquality) +{ + + int i, l, n, maxl; + float *Ss, loguvquality; + float C1, C2, C3, C4; + float deltaphil, deltawl, thetaln, aln; + int numUv; + float cw0, pw0, cw0l, pw0l; + float uvsine, uvrand, uvthreshold, uvthresholdf; + float uvstep, uvoffset; + float qfactor; + float rphase[64], rphase2[64]; + + const int N = 160; + + uvthresholdf = (float) 2700; + uvthreshold = ((uvthresholdf * M_PI) / (float) 4000); + + // voiced/unvoiced/gain settings + uvsine = (float) 1.3591409 *M_E; + uvrand = (float) 2.0; + + if ((uvquality < 1) || (uvquality > 64)) + { + printf ("\nmbelib: Error - uvquality must be within the range 1 - 64, setting to default value of 3\n"); + uvquality = 3; + } + + // calculate loguvquality + if (uvquality == 1) + { + loguvquality = (float) 1 / M_E; + } + else + { + loguvquality = log ((float) uvquality) / (float) uvquality; + } + + // calculate unvoiced step and offset values + uvstep = (float) 1.0 / (float) uvquality; + qfactor = loguvquality; + uvoffset = (uvstep * (float) (uvquality - 1)) / (float) 2; + + // count number of unvoiced bands + numUv = 0; + for (l = 1; l <= cur_mp->L; l++) + { + if (cur_mp->Vl[l] == 0) + { + numUv++; + } + } + + cw0 = cur_mp->w0; + pw0 = prev_mp->w0; + + // init aout_buf + Ss = aout_buf; + for (n = 0; n < N; n++) + { + *Ss = (float) 0; + Ss++; + } + + // eq 128 and 129 + if (cur_mp->L > prev_mp->L) + { + maxl = cur_mp->L; + for (l = prev_mp->L + 1; l <= maxl; l++) + { + prev_mp->Ml[l] = (float) 0; + prev_mp->Vl[l] = 1; + } + } + else + { + maxl = prev_mp->L; + for (l = cur_mp->L + 1; l <= maxl; l++) + { + cur_mp->Ml[l] = (float) 0; + cur_mp->Vl[l] = 1; + } + } + + // update phil from eq 139,140 + for (l = 1; l <= 56; l++) + { + cur_mp->PSIl[l] = prev_mp->PSIl[l] + ((pw0 + cw0) * ((float) (l * N) / (float) 2)); + if (l <= (int) (cur_mp->L / 4)) + { + cur_mp->PHIl[l] = cur_mp->PSIl[l]; + } + else + { + cur_mp->PHIl[l] = cur_mp->PSIl[l] + ((numUv * mbe_rand_phase()) / cur_mp->L); + } + } + + for (l = 1; l <= maxl; l++) + { + cw0l = (cw0 * (float) l); + pw0l = (pw0 * (float) l); + if ((cur_mp->Vl[l] == 0) && (prev_mp->Vl[l] == 1)) + { + Ss = aout_buf; + // init random phase + for (i = 0; i < uvquality; i++) + { + rphase[i] = mbe_rand_phase(); + } + for (n = 0; n < N; n++) + { + C1 = 0; + // eq 131 + C1 = Ws[n + N] * prev_mp->Ml[l] * cosf ((pw0l * (float) n) + prev_mp->PHIl[l]); + C3 = 0; + // unvoiced multisine mix + for (i = 0; i < uvquality; i++) + { + C3 = C3 + cosf ((cw0 * (float) n * ((float) l + ((float) i * uvstep) - uvoffset)) + rphase[i]); + if (cw0l > uvthreshold) + { + C3 = C3 + ((cw0l - uvthreshold) * uvrand * mbe_rand()); + } + } + C3 = C3 * uvsine * Ws[n] * cur_mp->Ml[l] * qfactor; + *Ss = *Ss + C1 + C3; + Ss++; + } + } + else if ((cur_mp->Vl[l] == 1) && (prev_mp->Vl[l] == 0)) + { + Ss = aout_buf; + // init random phase + for (i = 0; i < uvquality; i++) + { + rphase[i] = mbe_rand_phase(); + } + for (n = 0; n < N; n++) + { + C1 = 0; + // eq 132 + C1 = Ws[n] * cur_mp->Ml[l] * cosf ((cw0l * (float) (n - N)) + cur_mp->PHIl[l]); + C3 = 0; + // unvoiced multisine mix + for (i = 0; i < uvquality; i++) + { + C3 = C3 + cosf ((pw0 * (float) n * ((float) l + ((float) i * uvstep) - uvoffset)) + rphase[i]); + if (pw0l > uvthreshold) + { + C3 = C3 + ((pw0l - uvthreshold) * uvrand * mbe_rand()); + } + } + C3 = C3 * uvsine * Ws[n + N] * prev_mp->Ml[l] * qfactor; + *Ss = *Ss + C1 + C3; + Ss++; + } + } +// else if (((cur_mp->Vl[l] == 1) || (prev_mp->Vl[l] == 1)) && ((l >= 8) || (fabsf (cw0 - pw0) >= ((float) 0.1 * cw0)))) + else if ((cur_mp->Vl[l] == 1) || (prev_mp->Vl[l] == 1)) + { + Ss = aout_buf; + for (n = 0; n < N; n++) + { + C1 = 0; + // eq 133-1 + C1 = Ws[n + N] * prev_mp->Ml[l] * cosf ((pw0l * (float) n) + prev_mp->PHIl[l]); + C2 = 0; + // eq 133-2 + C2 = Ws[n] * cur_mp->Ml[l] * cosf ((cw0l * (float) (n - N)) + cur_mp->PHIl[l]); + *Ss = *Ss + C1 + C2; + Ss++; + } + } +/* + // expensive and unnecessary? + else if ((cur_mp->Vl[l] == 1) || (prev_mp->Vl[l] == 1)) + { + Ss = aout_buf; + // eq 137 + deltaphil = cur_mp->PHIl[l] - prev_mp->PHIl[l] - (((pw0 + cw0) * (float) (l * N)) / (float) 2); + // eq 138 + deltawl = ((float) 1 / (float) N) * (deltaphil - ((float) 2 * M_PI * (int) ((deltaphil + M_PI) / (M_PI * (float) 2)))); + for (n = 0; n < N; n++) + { + // eq 136 + thetaln = prev_mp->PHIl[l] + ((pw0l + deltawl) * (float) n) + (((cw0 - pw0) * ((float) (l * n * n)) / (float) (2 * N))); + // eq 135 + aln = prev_mp->Ml[l] + (((float) n / (float) N) * (cur_mp->Ml[l] - prev_mp->Ml[l])); + // eq 134 + *Ss = *Ss + (aln * cosf (thetaln)); + Ss++; + } + } +*/ + else + { + Ss = aout_buf; + // init random phase + for (i = 0; i < uvquality; i++) + { + rphase[i] = mbe_rand_phase(); + } + // init random phase + for (i = 0; i < uvquality; i++) + { + rphase2[i] = mbe_rand_phase(); + } + for (n = 0; n < N; n++) + { + C3 = 0; + // unvoiced multisine mix + for (i = 0; i < uvquality; i++) + { + C3 = C3 + cosf ((pw0 * (float) n * ((float) l + ((float) i * uvstep) - uvoffset)) + rphase[i]); + if (pw0l > uvthreshold) + { + C3 = C3 + ((pw0l - uvthreshold) * uvrand * mbe_rand()); + } + } + C3 = C3 * uvsine * Ws[n + N] * prev_mp->Ml[l] * qfactor; + C4 = 0; + // unvoiced multisine mix + for (i = 0; i < uvquality; i++) + { + C4 = C4 + cosf ((cw0 * (float) n * ((float) l + ((float) i * uvstep) - uvoffset)) + rphase2[i]); + if (cw0l > uvthreshold) + { + C4 = C4 + ((cw0l - uvthreshold) * uvrand * mbe_rand()); + } + } + C4 = C4 * uvsine * Ws[n] * cur_mp->Ml[l] * qfactor; + *Ss = *Ss + C3 + C4; + Ss++; + } + } + } +} + +void +mbe_synthesizeSpeech (short *aout_buf, mbe_parms * cur_mp, mbe_parms * prev_mp, int uvquality) +{ + float float_buf[160]; + + mbe_synthesizeSpeechf (float_buf, cur_mp, prev_mp, uvquality); + mbe_floattoshort (float_buf, aout_buf); +} + +void +mbe_floattoshort (float *float_buf, short *aout_buf) +{ + + short *aout_buf_p; + float *float_buf_p; + int i, again; + float audio; + + again = 7; + aout_buf_p = aout_buf; + float_buf_p = float_buf; + for (i = 0; i < 160; i++) + { + audio = again * *float_buf_p; + if (audio > 32760) + { +#ifdef MBE_DEBUG + printf ("audio clip: %f\n", audio); +#endif + audio = 32760; + } + else if (audio < -32760) + { +#ifdef MBE_DEBUG + printf ("audio clip: %f\n", audio); +#endif + audio = -32760; + } + *aout_buf_p = (short) (audio); + aout_buf_p++; + float_buf_p++; + } +} diff --git a/mbelib-wasm/mbelib/mbelib.h b/mbelib-wasm/mbelib/mbelib.h new file mode 100644 index 0000000..cf0f402 --- /dev/null +++ b/mbelib-wasm/mbelib/mbelib.h @@ -0,0 +1,113 @@ +/* + * Copyright (C) 2010 mbelib Author + * GPG Key ID: 0xEA5EFE2C (9E7A 5527 9CDC EBF7 BF1B D772 4F98 E863 EA5E FE2C) + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _MBELIB_H +#define _MBELIB_H + +#define MBELIB_VERSION "1.3.0" + +struct mbe_parameters +{ + float w0; + int L; + int K; + int Vl[57]; + float Ml[57]; + float log2Ml[57]; + float PHIl[57]; + float PSIl[57]; + float gamma; + int un; + int repeat; +}; + +typedef struct mbe_parameters mbe_parms; + +/* + * Prototypes from ecc.c + */ +void mbe_checkGolayBlock (long int *block); +int mbe_golay2312 (char *in, char *out); +int mbe_hamming1511 (char *in, char *out); +int mbe_7100x4400hamming1511 (char *in, char *out); + +/* + * Prototypes from ambe3600x2400.c + */ +int mbe_eccAmbe3600x2400C0 (char ambe_fr[4][24]); +int mbe_eccAmbe3600x2400Data (char ambe_fr[4][24], char *ambe_d); +int mbe_decodeAmbe2400Parms (char *ambe_d, mbe_parms * cur_mp, mbe_parms * prev_mp); +void mbe_demodulateAmbe3600x2400Data (char ambe_fr[4][24]); +void mbe_processAmbe2400Dataf (float *aout_buf, int *errs, int *errs2, char *err_str, char ambe_d[49], mbe_parms * cur_mp, mbe_parms * prev_mp, mbe_parms * prev_mp_enhanced, int uvquality); +void mbe_processAmbe2400Data (short *aout_buf, int *errs, int *errs2, char *err_str, char ambe_d[49], mbe_parms * cur_mp, mbe_parms * prev_mp, mbe_parms * prev_mp_enhanced, int uvquality); +void mbe_processAmbe3600x2400Framef (float *aout_buf, int *errs, int *errs2, char *err_str, char ambe_fr[4][24], char ambe_d[49], mbe_parms * cur_mp, mbe_parms * prev_mp, mbe_parms * prev_mp_enhanced, int uvquality); +void mbe_processAmbe3600x2400Frame (short *aout_buf, int *errs, int *errs2, char *err_str, char ambe_fr[4][24], char ambe_d[49], mbe_parms * cur_mp, mbe_parms * prev_mp, mbe_parms * prev_mp_enhanced, int uvquality); + +/* + * Prototypes from ambe3600x2450.c + */ +int mbe_eccAmbe3600x2450C0 (char ambe_fr[4][24]); +int mbe_eccAmbe3600x2450Data (char ambe_fr[4][24], char *ambe_d); +int mbe_decodeAmbe2450Parms (char *ambe_d, mbe_parms * cur_mp, mbe_parms * prev_mp); +void mbe_demodulateAmbe3600x2450Data (char ambe_fr[4][24]); +void mbe_processAmbe2450Dataf (float *aout_buf, int *errs, int *errs2, char *err_str, char ambe_d[49], mbe_parms * cur_mp, mbe_parms * prev_mp, mbe_parms * prev_mp_enhanced, int uvquality); +void mbe_processAmbe2450Data (short *aout_buf, int *errs, int *errs2, char *err_str, char ambe_d[49], mbe_parms * cur_mp, mbe_parms * prev_mp, mbe_parms * prev_mp_enhanced, int uvquality); +void mbe_processAmbe3600x2450Framef (float *aout_buf, int *errs, int *errs2, char *err_str, char ambe_fr[4][24], char ambe_d[49], mbe_parms * cur_mp, mbe_parms * prev_mp, mbe_parms * prev_mp_enhanced, int uvquality); +void mbe_processAmbe3600x2450Frame (short *aout_buf, int *errs, int *errs2, char *err_str, char ambe_fr[4][24], char ambe_d[49], mbe_parms * cur_mp, mbe_parms * prev_mp, mbe_parms * prev_mp_enhanced, int uvquality); + +/* + * Prototypes from imbe7200x4400.c + */ +void mbe_dumpImbe4400Data (char *imbe_d); +void mbe_dumpImbe7200x4400Data (char *imbe_d); +void mbe_dumpImbe7200x4400Frame (char imbe_fr[8][23]); +int mbe_eccImbe7200x4400C0 (char imbe_fr[8][23]); +int mbe_eccImbe7200x4400Data (char imbe_fr[8][23], char *imbe_d); +int mbe_decodeImbe4400Parms (char *imbe_d, mbe_parms * cur_mp, mbe_parms * prev_mp); +void mbe_demodulateImbe7200x4400Data (char imbe[8][23]); +void mbe_processImbe4400Dataf (float *aout_buf, int *errs, int *errs2, char *err_str, char imbe_d[88], mbe_parms * cur_mp, mbe_parms * prev_mp, mbe_parms * prev_mp_enhanced, int uvquality); +void mbe_processImbe4400Data (short *aout_buf, int *errs, int *errs2, char *err_str, char imbe_d[88], mbe_parms * cur_mp, mbe_parms * prev_mp, mbe_parms * prev_mp_enhanced, int uvquality); +void mbe_processImbe7200x4400Framef (float *aout_buf, int *errs, int *errs2, char *err_str, char imbe_fr[8][23], char imbe_d[88], mbe_parms * cur_mp, mbe_parms * prev_mp, mbe_parms * prev_mp_enhanced, int uvquality); +void mbe_processImbe7200x4400Frame (short *aout_buf, int *errs, int *errs2, char *err_str, char imbe_fr[8][23], char imbe_d[88], mbe_parms * cur_mp, mbe_parms * prev_mp, mbe_parms * prev_mp_enhanced, int uvquality); + +/* + * Prototypes from imbe7100x4400.c + */ +void mbe_dumpImbe7100x4400Data (char *imbe_d); +void mbe_dumpImbe7100x4400Frame (char imbe_fr[7][24]); +int mbe_eccImbe7100x4400C0 (char imbe_fr[7][24]); +int mbe_eccImbe7100x4400Data (char imbe_fr[7][24], char *imbe_d); +void mbe_demodulateImbe7100x4400Data (char imbe[7][24]); +void mbe_convertImbe7100to7200 (char *imbe_d); +void mbe_processImbe7100x4400Framef (float *aout_buf, int *errs, int *errs2, char *err_str, char imbe_fr[7][24], char imbe_d[88], mbe_parms * cur_mp, mbe_parms * prev_mp, mbe_parms * prev_mp_enhanced, int uvquality); +void mbe_processImbe7100x4400Frame (short *aout_buf, int *errs, int *errs2, char *err_str, char imbe_fr[7][24], char imbe_d[88], mbe_parms * cur_mp, mbe_parms * prev_mp, mbe_parms * prev_mp_enhanced, int uvquality); + +/* + * Prototypes from mbelib.c + */ +void mbe_printVersion (char *str); +void mbe_moveMbeParms (mbe_parms * cur_mp, mbe_parms * prev_mp); +void mbe_useLastMbeParms (mbe_parms * cur_mp, mbe_parms * prev_mp); +void mbe_initMbeParms (mbe_parms * cur_mp, mbe_parms * prev_mp, mbe_parms * prev_mp_enhanced); +void mbe_spectralAmpEnhance (mbe_parms * cur_mp); +void mbe_synthesizeSilencef (float *aout_buf); +void mbe_synthesizeSilence (short *aout_buf); +void mbe_synthesizeSpeechf (float *aout_buf, mbe_parms * cur_mp, mbe_parms * prev_mp, int uvquality); +void mbe_synthesizeSpeech (short *aout_buf, mbe_parms * cur_mp, mbe_parms * prev_mp, int uvquality); +void mbe_floattoshort (float *float_buf, short *aout_buf); + +#endif diff --git a/mbelib-wasm/mbelib/mbelib_Author.pgp b/mbelib-wasm/mbelib/mbelib_Author.pgp new file mode 100644 index 0000000..2303a46 --- /dev/null +++ b/mbelib-wasm/mbelib/mbelib_Author.pgp @@ -0,0 +1,30 @@ +-----BEGIN PGP PUBLIC KEY BLOCK----- +Version: GnuPG v1.4.10 + +mQENBEufusYBCADN1SNkRkQzdLM02MCjen8KQmfuA38MrQIV0dZLpPJcn1+hsvZZ +KWvpUiWCNw1ClGRsJAT5cjonndi1PV7tpzQz+CyMqSP5OwR40eTJBoZhl74hdmU8 +QvcKkJ32khSsOXMo60NHk5iIMDELzOGqq57NHhbunj6NtYog2mR5+WT37JLCvF/q +dvYl2KkRwEHD76/b/O1CyheiiqNMGBb13zPN0qO/PRlENSgViLcDh9qVj4ETNNS6 +zMlP4D4pa07iED4Ua31wiXI04ReznnmvMqzQb8uFbg7d98F3bZpsbNURbmsFHMhj +c9qw65nzaMa3OHfZ3Qwl4XRlNqEzZrclIZADABEBAAG0DW1iZWxpYiBBdXRob3KJ +ATgEEwECACIFAkufusYCGwMGCwkIBwMCBhUIAgkKCwQWAgMBAh4BAheAAAoJEE+Y +6GPqXv4sI/4H/RsumInT5GtDdBTgxt3lERqc5GF8tI5CAQX9DUMMkKxQ306Fgb4M +ISYdepgL6BlbtSyMdKpKsDLScNA6YXER4gMU1nhhyBulqj41kAfsVbG8hiTBy5Ri +FTo36HrC//Zj1MlaTCB8Rl6B6IftAHIb1U+Gda3WnLDe+R5Pym/76TqeYx23PnJl +V+qfrkjbNyOb2bttyko2iccm9DSq/I1OF0Ufz3P60ssUwHW/b2S6WOXRxiZIq0sz +8pAweUFCxIMWo+XYlSpRtwpebfx+JoHJKdW1cSCgY9jwVsOZO1zxc8P+jr3ByiIR +ZPd0PfBt/AHuC6Hmw9nC12e49+4qsHkj50S5AQ0ES5+6xgEIALf60WjqHm552FIX +KqmG0TIrXpCsYoTWzDdO5j0Ro6fmg9U48BqDH5aS4YRvuyPE7q6DGYEnXF5EIPtU +FhUk4FMmez5eMg91UW4Qjqx8M3reoBROYocM5Nfbc9w7St8+3oRS6rUBIh/B6o4O +kEjkoW3R7O3uFpC53Oi9IVhx/joWxhi430RrUTig5CQzuPFTAHd3xJVE6Pv44nsY +/PsOhBLu2Z3kRkvjcGbsGDlAl2bDEobzQdsqXDD8gJkF5W4IeBKvRC54SE0FSm57 +G1gadhZ7vT4DWQZvYYKXR+AE7FTcopoAFHdapYokOGLHCguabyeZ5q7+s7J4nddL +p5yq8ikAEQEAAYkBHwQYAQIACQUCS5+6xgIbDAAKCRBPmOhj6l7+LPi6B/sEkDkm +Qs/aTz9HDANBAbTuDZTY4WBbkPdFos3xxC2Z/TH5m4bfHEkvNk5WD+j+vYB3exAc +uBi7ZiqibRpap4kiAiKKCRXOyvmEmrjKB5wOWbRpkdTeEdPcpsQ4dDDw1ZUKwzjN +1jI/9GOgq49nAGdlU59f3IdPut6oQNq9vrtanTq2xHVN/rOhV9GLE6gLX1YWkpIH +zYSUheGPsnv4sWRsQDTB7xmF+6RZzjmauKNwsGFscX1TenOWtUbYb9qFCwvNMOSk +51sEaD6PK6wWTXMqQlgjaoGqh1ZaePgT0QTh1W/bvOD0fL5NEToJl2h/lBSvO+ez +R9B++dt5JX9BMxAH +=puA7 +-----END PGP PUBLIC KEY BLOCK----- diff --git a/mbelib-wasm/mbelib/mbelib_const.h b/mbelib-wasm/mbelib/mbelib_const.h new file mode 100644 index 0000000..6258ab1 --- /dev/null +++ b/mbelib-wasm/mbelib/mbelib_const.h @@ -0,0 +1,371 @@ +/* + * Copyright (C) 2010 mbelib Author + * GPG Key ID: 0xEA5EFE2C (9E7A 5527 9CDC EBF7 BF1B D772 4F98 E863 EA5E FE2C) + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _MBELIB_CONST_H +#define _MBELIB_CONST_H + +/* + * Speech Synthesis Window 8k version + */ +const float Ws[321] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, + 0, 0.02, 0.04, 0.06, 0.08, 0.1, 0.12, 0.14, 0.16, 0.18, + 0.2, 0.22, 0.24, 0.26, 0.28, 0.3, 0.32, 0.34, 0.36, 0.38, + 0.4, 0.42, 0.44, 0.46, 0.48, 0.5, 0.52, 0.54, 0.56, 0.58, + 0.6, 0.62, 0.64, 0.66, 0.68, 0.7, 0.72, 0.74, 0.76, 0.78, + 0.8, 0.82, 0.84, 0.86, 0.88, 0.9, 0.92, 0.94, 0.96, 0.98, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0.98, 0.96, 0.94, 0.92, 0.9, 0.88, 0.86, 0.84, 0.82, 0.8, + 0.78, 0.76, 0.74, 0.72, 0.7, 0.68, 0.66, 0.64, 0.62, 0.6, + 0.58, 0.56, 0.54, 0.52, 0.5, 0.48, 0.46, 0.44, 0.42, 0.4, + 0.38, 0.36, 0.34, 0.32, 0.3, 0.28, 0.26, 0.24, 0.22, 0.2, + 0.18, 0.16, 0.14, 0.12, 0.1, 0.08, 0.06, 0.04, 0.02, 0, + 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; + +/* + * Speech Synthesis Window, 48k version + */ +/* +const float Ws48k[1926] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, + 0.000, 0.003, 0.007, + 0.010, 0.013, 0.017, + 0.020, 0.023, 0.027, + 0.030, 0.033, 0.037, + 0.040, 0.043, 0.047, + 0.050, 0.053, 0.057, + 0.060, 0.063, 0.067, + 0.070, 0.073, 0.077, + 0.080, 0.083, 0.087, + 0.090, 0.093, 0.097, + 0.100, 0.103, 0.107, + 0.110, 0.113, 0.117, + 0.120, 0.123, 0.127, + 0.130, 0.133, 0.137, + 0.140, 0.143, 0.147, + 0.150, 0.153, 0.157, + 0.160, 0.163, 0.167, + 0.170, 0.173, 0.177, + 0.180, 0.183, 0.187, + 0.190, 0.193, 0.197, + 0.200, 0.203, 0.207, + 0.210, 0.213, 0.217, + 0.220, 0.223, 0.227, + 0.230, 0.233, 0.237, + 0.240, 0.243, 0.247, + 0.250, 0.253, 0.257, + 0.260, 0.263, 0.267, + 0.270, 0.273, 0.277, + 0.280, 0.283, 0.287, + 0.290, 0.293, 0.297, + 0.300, 0.303, 0.307, + 0.310, 0.313, 0.317, + 0.320, 0.323, 0.327, + 0.330, 0.333, 0.337, + 0.340, 0.343, 0.347, + 0.350, 0.353, 0.357, + 0.360, 0.363, 0.367, + 0.370, 0.373, 0.377, + 0.380, 0.383, 0.387, + 0.390, 0.393, 0.397, + 0.400, 0.403, 0.407, + 0.410, 0.413, 0.417, + 0.420, 0.423, 0.427, + 0.430, 0.433, 0.437, + 0.440, 0.443, 0.447, + 0.450, 0.453, 0.457, + 0.460, 0.463, 0.467, + 0.470, 0.473, 0.477, + 0.480, 0.483, 0.487, + 0.490, 0.493, 0.497, + 0.500, 0.503, 0.507, + 0.510, 0.513, 0.517, + 0.520, 0.523, 0.527, + 0.530, 0.533, 0.537, + 0.540, 0.543, 0.547, + 0.550, 0.553, 0.557, + 0.560, 0.563, 0.567, + 0.570, 0.573, 0.577, + 0.580, 0.583, 0.587, + 0.590, 0.593, 0.597, + 0.600, 0.603, 0.607, + 0.610, 0.613, 0.617, + 0.620, 0.623, 0.627, + 0.630, 0.633, 0.637, + 0.640, 0.643, 0.647, + 0.650, 0.653, 0.657, + 0.660, 0.663, 0.667, + 0.670, 0.673, 0.677, + 0.680, 0.683, 0.687, + 0.690, 0.693, 0.697, + 0.700, 0.703, 0.707, + 0.710, 0.713, 0.717, + 0.720, 0.723, 0.727, + 0.730, 0.733, 0.737, + 0.740, 0.743, 0.747, + 0.750, 0.753, 0.757, + 0.760, 0.763, 0.767, + 0.770, 0.773, 0.777, + 0.780, 0.783, 0.787, + 0.790, 0.793, 0.797, + 0.800, 0.803, 0.807, + 0.810, 0.813, 0.817, + 0.820, 0.823, 0.827, + 0.830, 0.833, 0.837, + 0.840, 0.843, 0.847, + 0.850, 0.853, 0.857, + 0.860, 0.863, 0.867, + 0.870, 0.873, 0.877, + 0.880, 0.883, 0.887, + 0.890, 0.893, 0.897, + 0.900, 0.903, 0.907, + 0.910, 0.913, 0.917, + 0.920, 0.923, 0.927, + 0.930, 0.933, 0.937, + 0.940, 0.943, 0.947, + 0.950, 0.953, 0.957, + 0.960, 0.963, 0.967, + 0.970, 0.973, 0.977, + 0.980, 0.983, 0.987, + 0.990, 0.993, 0.997, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0.997, 0.993, 0.990, + 0.987, 0.983, 0.980, + 0.977, 0.973, 0.970, + 0.967, 0.963, 0.960, + 0.957, 0.953, 0.950, + 0.947, 0.943, 0.940, + 0.937, 0.933, 0.930, + 0.927, 0.923, 0.920, + 0.917, 0.913, 0.910, + 0.907, 0.903, 0.900, + 0.897, 0.893, 0.890, + 0.887, 0.883, 0.880, + 0.877, 0.873, 0.870, + 0.867, 0.863, 0.860, + 0.857, 0.853, 0.850, + 0.847, 0.843, 0.840, + 0.837, 0.833, 0.830, + 0.827, 0.823, 0.820, + 0.817, 0.813, 0.810, + 0.807, 0.803, 0.800, + 0.797, 0.793, 0.790, + 0.787, 0.783, 0.780, + 0.777, 0.773, 0.770, + 0.767, 0.763, 0.760, + 0.757, 0.753, 0.750, + 0.747, 0.743, 0.740, + 0.737, 0.733, 0.730, + 0.727, 0.723, 0.720, + 0.717, 0.713, 0.710, + 0.707, 0.703, 0.700, + 0.697, 0.693, 0.690, + 0.687, 0.683, 0.680, + 0.677, 0.673, 0.670, + 0.667, 0.663, 0.660, + 0.657, 0.653, 0.650, + 0.647, 0.643, 0.640, + 0.637, 0.633, 0.630, + 0.627, 0.623, 0.620, + 0.617, 0.613, 0.610, + 0.607, 0.603, 0.600, + 0.597, 0.593, 0.590, + 0.587, 0.583, 0.580, + 0.577, 0.573, 0.570, + 0.567, 0.563, 0.560, + 0.557, 0.553, 0.550, + 0.547, 0.543, 0.540, + 0.537, 0.533, 0.530, + 0.527, 0.523, 0.520, + 0.517, 0.513, 0.510, + 0.507, 0.503, 0.500, + 0.497, 0.493, 0.490, + 0.487, 0.483, 0.480, + 0.477, 0.473, 0.470, + 0.467, 0.463, 0.460, + 0.457, 0.453, 0.450, + 0.447, 0.443, 0.440, + 0.437, 0.433, 0.430, + 0.427, 0.423, 0.420, + 0.417, 0.413, 0.410, + 0.407, 0.403, 0.400, + 0.397, 0.393, 0.390, + 0.387, 0.383, 0.380, + 0.377, 0.373, 0.370, + 0.367, 0.363, 0.360, + 0.357, 0.353, 0.350, + 0.347, 0.343, 0.340, + 0.337, 0.333, 0.330, + 0.327, 0.323, 0.320, + 0.317, 0.313, 0.310, + 0.307, 0.303, 0.300, + 0.297, 0.293, 0.290, + 0.287, 0.283, 0.280, + 0.277, 0.273, 0.270, + 0.267, 0.263, 0.260, + 0.257, 0.253, 0.250, + 0.247, 0.243, 0.240, + 0.237, 0.233, 0.230, + 0.227, 0.223, 0.220, + 0.217, 0.213, 0.210, + 0.207, 0.203, 0.200, + 0.197, 0.193, 0.190, + 0.187, 0.183, 0.180, + 0.177, 0.173, 0.170, + 0.167, 0.163, 0.160, + 0.157, 0.153, 0.150, + 0.147, 0.143, 0.140, + 0.137, 0.133, 0.130, + 0.127, 0.123, 0.120, + 0.117, 0.113, 0.110, + 0.107, 0.103, 0.100, + 0.097, 0.093, 0.090, + 0.087, 0.083, 0.080, + 0.077, 0.073, 0.070, + 0.067, 0.063, 0.060, + 0.057, 0.053, 0.050, + 0.047, 0.043, 0.040, + 0.037, 0.033, 0.030, + 0.027, 0.023, 0.020, + 0.017, 0.013, 0.010, + 0.007, 0.003, 0.000, + 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; +*/ + +#endif diff --git a/mbelib-wasm/mbelib/test/CMakeLists.txt b/mbelib-wasm/mbelib/test/CMakeLists.txt new file mode 100644 index 0000000..347676a --- /dev/null +++ b/mbelib-wasm/mbelib/test/CMakeLists.txt @@ -0,0 +1,19 @@ +project(mbetest) + +add_subdirectory(gtest) +add_subdirectory(gmock) + +FILE(GLOB SRCS *.cpp) + +include_directories( + ${PROJECT_SOURCE_DIR}/gtest/include + ${PROJECT_SOURCE_DIR}/gmock/include + ${mbe_SOURCE_DIR} +) + +link_directories( ${mbe_BINARY_DIR} ) + +ADD_EXECUTABLE(mbetest ${SRCS}) +TARGET_LINK_LIBRARIES(mbetest mbe gmock gtest) + +add_test(gtest mbetest) diff --git a/mbelib-wasm/mbelib/test/gmock/CMakeLists.txt b/mbelib-wasm/mbelib/test/gmock/CMakeLists.txt new file mode 100644 index 0000000..ae4dfc6 --- /dev/null +++ b/mbelib-wasm/mbelib/test/gmock/CMakeLists.txt @@ -0,0 +1,45 @@ +######################################################################## +# CMake build script for Google Mock. +# +# To run the tests for Google Mock itself on Linux, use 'make test' or +# ctest. You can select which tests to run using 'ctest -R regex'. +# For more options, run 'ctest --help'. + +# BUILD_SHARED_LIBS is a standard CMake variable, but we declare it here to +# make it prominent in the GUI. +option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)." OFF) + +######################################################################## +# +# Project-wide settings + +# Name of the project. +# +# CMake files in this project can refer to the root source directory +# as ${gmock_SOURCE_DIR} and to the root binary directory as +# ${gmock_BINARY_DIR}. +# Language "C" is required for find_package(Threads). +project(gmock CXX C) +cmake_minimum_required(VERSION 2.6.2) + +# Adds Google Mock's and Google Test's header directories to the search path. +include_directories("${gmock_SOURCE_DIR}/include" + "${gmock_SOURCE_DIR}" + "${gtest_SOURCE_DIR}/include") + +######################################################################## +# +# Defines the gmock & gmock_main libraries. User tests should link +# with one of them. + +# Google Mock libraries. We build them using more strict warnings than what +# are used for other targets, to ensure that Google Mock can be compiled by +# a user aggressive about warnings. +cxx_library(gmock + "${cxx_strict}" + src/gmock-all.cc) + +cxx_library(gmock_main + "${cxx_strict}" + src/gmock-all.cc + src/gmock_main.cc) diff --git a/mbelib-wasm/mbelib/test/gmock/include/gmock/gmock-actions.h b/mbelib-wasm/mbelib/test/gmock/include/gmock/gmock-actions.h new file mode 100644 index 0000000..7e9708e --- /dev/null +++ b/mbelib-wasm/mbelib/test/gmock/include/gmock/gmock-actions.h @@ -0,0 +1,1078 @@ +// Copyright 2007, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Author: wan@google.com (Zhanyong Wan) + +// Google Mock - a framework for writing C++ mock classes. +// +// This file implements some commonly used actions. + +#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_ +#define GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_ + +#ifndef _WIN32_WCE +# include +#endif + +#include +#include + +#include "gmock/internal/gmock-internal-utils.h" +#include "gmock/internal/gmock-port.h" + +namespace testing { + +// To implement an action Foo, define: +// 1. a class FooAction that implements the ActionInterface interface, and +// 2. a factory function that creates an Action object from a +// const FooAction*. +// +// The two-level delegation design follows that of Matcher, providing +// consistency for extension developers. It also eases ownership +// management as Action objects can now be copied like plain values. + +namespace internal { + +template +class ActionAdaptor; + +// BuiltInDefaultValue::Get() returns the "built-in" default +// value for type T, which is NULL when T is a pointer type, 0 when T +// is a numeric type, false when T is bool, or "" when T is string or +// std::string. For any other type T, this value is undefined and the +// function will abort the process. +template +class BuiltInDefaultValue { + public: + // This function returns true iff type T has a built-in default value. + static bool Exists() { return false; } + static T Get() { + Assert(false, __FILE__, __LINE__, + "Default action undefined for the function return type."); + return internal::Invalid(); + // The above statement will never be reached, but is required in + // order for this function to compile. + } +}; + +// This partial specialization says that we use the same built-in +// default value for T and const T. +template +class BuiltInDefaultValue { + public: + static bool Exists() { return BuiltInDefaultValue::Exists(); } + static T Get() { return BuiltInDefaultValue::Get(); } +}; + +// This partial specialization defines the default values for pointer +// types. +template +class BuiltInDefaultValue { + public: + static bool Exists() { return true; } + static T* Get() { return NULL; } +}; + +// The following specializations define the default values for +// specific types we care about. +#define GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(type, value) \ + template <> \ + class BuiltInDefaultValue { \ + public: \ + static bool Exists() { return true; } \ + static type Get() { return value; } \ + } + +GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(void, ); // NOLINT +#if GTEST_HAS_GLOBAL_STRING +GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(::string, ""); +#endif // GTEST_HAS_GLOBAL_STRING +GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(::std::string, ""); +GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(bool, false); +GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned char, '\0'); +GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed char, '\0'); +GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(char, '\0'); + +// There's no need for a default action for signed wchar_t, as that +// type is the same as wchar_t for gcc, and invalid for MSVC. +// +// There's also no need for a default action for unsigned wchar_t, as +// that type is the same as unsigned int for gcc, and invalid for +// MSVC. +#if GMOCK_WCHAR_T_IS_NATIVE_ +GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(wchar_t, 0U); // NOLINT +#endif + +GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned short, 0U); // NOLINT +GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed short, 0); // NOLINT +GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned int, 0U); +GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed int, 0); +GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned long, 0UL); // NOLINT +GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed long, 0L); // NOLINT +GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(UInt64, 0); +GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(Int64, 0); +GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(float, 0); +GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(double, 0); + +#undef GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_ + +} // namespace internal + +// When an unexpected function call is encountered, Google Mock will +// let it return a default value if the user has specified one for its +// return type, or if the return type has a built-in default value; +// otherwise Google Mock won't know what value to return and will have +// to abort the process. +// +// The DefaultValue class allows a user to specify the +// default value for a type T that is both copyable and publicly +// destructible (i.e. anything that can be used as a function return +// type). The usage is: +// +// // Sets the default value for type T to be foo. +// DefaultValue::Set(foo); +template +class DefaultValue { + public: + // Sets the default value for type T; requires T to be + // copy-constructable and have a public destructor. + static void Set(T x) { + delete value_; + value_ = new T(x); + } + + // Unsets the default value for type T. + static void Clear() { + delete value_; + value_ = NULL; + } + + // Returns true iff the user has set the default value for type T. + static bool IsSet() { return value_ != NULL; } + + // Returns true if T has a default return value set by the user or there + // exists a built-in default value. + static bool Exists() { + return IsSet() || internal::BuiltInDefaultValue::Exists(); + } + + // Returns the default value for type T if the user has set one; + // otherwise returns the built-in default value if there is one; + // otherwise aborts the process. + static T Get() { + return value_ == NULL ? + internal::BuiltInDefaultValue::Get() : *value_; + } + + private: + static const T* value_; +}; + +// This partial specialization allows a user to set default values for +// reference types. +template +class DefaultValue { + public: + // Sets the default value for type T&. + static void Set(T& x) { // NOLINT + address_ = &x; + } + + // Unsets the default value for type T&. + static void Clear() { + address_ = NULL; + } + + // Returns true iff the user has set the default value for type T&. + static bool IsSet() { return address_ != NULL; } + + // Returns true if T has a default return value set by the user or there + // exists a built-in default value. + static bool Exists() { + return IsSet() || internal::BuiltInDefaultValue::Exists(); + } + + // Returns the default value for type T& if the user has set one; + // otherwise returns the built-in default value if there is one; + // otherwise aborts the process. + static T& Get() { + return address_ == NULL ? + internal::BuiltInDefaultValue::Get() : *address_; + } + + private: + static T* address_; +}; + +// This specialization allows DefaultValue::Get() to +// compile. +template <> +class DefaultValue { + public: + static bool Exists() { return true; } + static void Get() {} +}; + +// Points to the user-set default value for type T. +template +const T* DefaultValue::value_ = NULL; + +// Points to the user-set default value for type T&. +template +T* DefaultValue::address_ = NULL; + +// Implement this interface to define an action for function type F. +template +class ActionInterface { + public: + typedef typename internal::Function::Result Result; + typedef typename internal::Function::ArgumentTuple ArgumentTuple; + + ActionInterface() {} + virtual ~ActionInterface() {} + + // Performs the action. This method is not const, as in general an + // action can have side effects and be stateful. For example, a + // get-the-next-element-from-the-collection action will need to + // remember the current element. + virtual Result Perform(const ArgumentTuple& args) = 0; + + private: + GTEST_DISALLOW_COPY_AND_ASSIGN_(ActionInterface); +}; + +// An Action is a copyable and IMMUTABLE (except by assignment) +// object that represents an action to be taken when a mock function +// of type F is called. The implementation of Action is just a +// linked_ptr to const ActionInterface, so copying is fairly cheap. +// Don't inherit from Action! +// +// You can view an object implementing ActionInterface as a +// concrete action (including its current state), and an Action +// object as a handle to it. +template +class Action { + public: + typedef typename internal::Function::Result Result; + typedef typename internal::Function::ArgumentTuple ArgumentTuple; + + // Constructs a null Action. Needed for storing Action objects in + // STL containers. + Action() : impl_(NULL) {} + + // Constructs an Action from its implementation. A NULL impl is + // used to represent the "do-default" action. + explicit Action(ActionInterface* impl) : impl_(impl) {} + + // Copy constructor. + Action(const Action& action) : impl_(action.impl_) {} + + // This constructor allows us to turn an Action object into an + // Action, as long as F's arguments can be implicitly converted + // to Func's and Func's return type can be implicitly converted to + // F's. + template + explicit Action(const Action& action); + + // Returns true iff this is the DoDefault() action. + bool IsDoDefault() const { return impl_.get() == NULL; } + + // Performs the action. Note that this method is const even though + // the corresponding method in ActionInterface is not. The reason + // is that a const Action means that it cannot be re-bound to + // another concrete action, not that the concrete action it binds to + // cannot change state. (Think of the difference between a const + // pointer and a pointer to const.) + Result Perform(const ArgumentTuple& args) const { + internal::Assert( + !IsDoDefault(), __FILE__, __LINE__, + "You are using DoDefault() inside a composite action like " + "DoAll() or WithArgs(). This is not supported for technical " + "reasons. Please instead spell out the default action, or " + "assign the default action to an Action variable and use " + "the variable in various places."); + return impl_->Perform(args); + } + + private: + template + friend class internal::ActionAdaptor; + + internal::linked_ptr > impl_; +}; + +// The PolymorphicAction class template makes it easy to implement a +// polymorphic action (i.e. an action that can be used in mock +// functions of than one type, e.g. Return()). +// +// To define a polymorphic action, a user first provides a COPYABLE +// implementation class that has a Perform() method template: +// +// class FooAction { +// public: +// template +// Result Perform(const ArgumentTuple& args) const { +// // Processes the arguments and returns a result, using +// // tr1::get(args) to get the N-th (0-based) argument in the tuple. +// } +// ... +// }; +// +// Then the user creates the polymorphic action using +// MakePolymorphicAction(object) where object has type FooAction. See +// the definition of Return(void) and SetArgumentPointee(value) for +// complete examples. +template +class PolymorphicAction { + public: + explicit PolymorphicAction(const Impl& impl) : impl_(impl) {} + + template + operator Action() const { + return Action(new MonomorphicImpl(impl_)); + } + + private: + template + class MonomorphicImpl : public ActionInterface { + public: + typedef typename internal::Function::Result Result; + typedef typename internal::Function::ArgumentTuple ArgumentTuple; + + explicit MonomorphicImpl(const Impl& impl) : impl_(impl) {} + + virtual Result Perform(const ArgumentTuple& args) { + return impl_.template Perform(args); + } + + private: + Impl impl_; + + GTEST_DISALLOW_ASSIGN_(MonomorphicImpl); + }; + + Impl impl_; + + GTEST_DISALLOW_ASSIGN_(PolymorphicAction); +}; + +// Creates an Action from its implementation and returns it. The +// created Action object owns the implementation. +template +Action MakeAction(ActionInterface* impl) { + return Action(impl); +} + +// Creates a polymorphic action from its implementation. This is +// easier to use than the PolymorphicAction constructor as it +// doesn't require you to explicitly write the template argument, e.g. +// +// MakePolymorphicAction(foo); +// vs +// PolymorphicAction(foo); +template +inline PolymorphicAction MakePolymorphicAction(const Impl& impl) { + return PolymorphicAction(impl); +} + +namespace internal { + +// Allows an Action object to pose as an Action, as long as F2 +// and F1 are compatible. +template +class ActionAdaptor : public ActionInterface { + public: + typedef typename internal::Function::Result Result; + typedef typename internal::Function::ArgumentTuple ArgumentTuple; + + explicit ActionAdaptor(const Action& from) : impl_(from.impl_) {} + + virtual Result Perform(const ArgumentTuple& args) { + return impl_->Perform(args); + } + + private: + const internal::linked_ptr > impl_; + + GTEST_DISALLOW_ASSIGN_(ActionAdaptor); +}; + +// Implements the polymorphic Return(x) action, which can be used in +// any function that returns the type of x, regardless of the argument +// types. +// +// Note: The value passed into Return must be converted into +// Function::Result when this action is cast to Action rather than +// when that action is performed. This is important in scenarios like +// +// MOCK_METHOD1(Method, T(U)); +// ... +// { +// Foo foo; +// X x(&foo); +// EXPECT_CALL(mock, Method(_)).WillOnce(Return(x)); +// } +// +// In the example above the variable x holds reference to foo which leaves +// scope and gets destroyed. If copying X just copies a reference to foo, +// that copy will be left with a hanging reference. If conversion to T +// makes a copy of foo, the above code is safe. To support that scenario, we +// need to make sure that the type conversion happens inside the EXPECT_CALL +// statement, and conversion of the result of Return to Action is a +// good place for that. +// +template +class ReturnAction { + public: + // Constructs a ReturnAction object from the value to be returned. + // 'value' is passed by value instead of by const reference in order + // to allow Return("string literal") to compile. + explicit ReturnAction(R value) : value_(value) {} + + // This template type conversion operator allows Return(x) to be + // used in ANY function that returns x's type. + template + operator Action() const { + // Assert statement belongs here because this is the best place to verify + // conditions on F. It produces the clearest error messages + // in most compilers. + // Impl really belongs in this scope as a local class but can't + // because MSVC produces duplicate symbols in different translation units + // in this case. Until MS fixes that bug we put Impl into the class scope + // and put the typedef both here (for use in assert statement) and + // in the Impl class. But both definitions must be the same. + typedef typename Function::Result Result; + GTEST_COMPILE_ASSERT_( + !internal::is_reference::value, + use_ReturnRef_instead_of_Return_to_return_a_reference); + return Action(new Impl(value_)); + } + + private: + // Implements the Return(x) action for a particular function type F. + template + class Impl : public ActionInterface { + public: + typedef typename Function::Result Result; + typedef typename Function::ArgumentTuple ArgumentTuple; + + // The implicit cast is necessary when Result has more than one + // single-argument constructor (e.g. Result is std::vector) and R + // has a type conversion operator template. In that case, value_(value) + // won't compile as the compiler doesn't known which constructor of + // Result to call. ImplicitCast_ forces the compiler to convert R to + // Result without considering explicit constructors, thus resolving the + // ambiguity. value_ is then initialized using its copy constructor. + explicit Impl(R value) + : value_(::testing::internal::ImplicitCast_(value)) {} + + virtual Result Perform(const ArgumentTuple&) { return value_; } + + private: + GTEST_COMPILE_ASSERT_(!internal::is_reference::value, + Result_cannot_be_a_reference_type); + Result value_; + + GTEST_DISALLOW_ASSIGN_(Impl); + }; + + R value_; + + GTEST_DISALLOW_ASSIGN_(ReturnAction); +}; + +// Implements the ReturnNull() action. +class ReturnNullAction { + public: + // Allows ReturnNull() to be used in any pointer-returning function. + template + static Result Perform(const ArgumentTuple&) { + GTEST_COMPILE_ASSERT_(internal::is_pointer::value, + ReturnNull_can_be_used_to_return_a_pointer_only); + return NULL; + } +}; + +// Implements the Return() action. +class ReturnVoidAction { + public: + // Allows Return() to be used in any void-returning function. + template + static void Perform(const ArgumentTuple&) { + CompileAssertTypesEqual(); + } +}; + +// Implements the polymorphic ReturnRef(x) action, which can be used +// in any function that returns a reference to the type of x, +// regardless of the argument types. +template +class ReturnRefAction { + public: + // Constructs a ReturnRefAction object from the reference to be returned. + explicit ReturnRefAction(T& ref) : ref_(ref) {} // NOLINT + + // This template type conversion operator allows ReturnRef(x) to be + // used in ANY function that returns a reference to x's type. + template + operator Action() const { + typedef typename Function::Result Result; + // Asserts that the function return type is a reference. This + // catches the user error of using ReturnRef(x) when Return(x) + // should be used, and generates some helpful error message. + GTEST_COMPILE_ASSERT_(internal::is_reference::value, + use_Return_instead_of_ReturnRef_to_return_a_value); + return Action(new Impl(ref_)); + } + + private: + // Implements the ReturnRef(x) action for a particular function type F. + template + class Impl : public ActionInterface { + public: + typedef typename Function::Result Result; + typedef typename Function::ArgumentTuple ArgumentTuple; + + explicit Impl(T& ref) : ref_(ref) {} // NOLINT + + virtual Result Perform(const ArgumentTuple&) { + return ref_; + } + + private: + T& ref_; + + GTEST_DISALLOW_ASSIGN_(Impl); + }; + + T& ref_; + + GTEST_DISALLOW_ASSIGN_(ReturnRefAction); +}; + +// Implements the polymorphic ReturnRefOfCopy(x) action, which can be +// used in any function that returns a reference to the type of x, +// regardless of the argument types. +template +class ReturnRefOfCopyAction { + public: + // Constructs a ReturnRefOfCopyAction object from the reference to + // be returned. + explicit ReturnRefOfCopyAction(const T& value) : value_(value) {} // NOLINT + + // This template type conversion operator allows ReturnRefOfCopy(x) to be + // used in ANY function that returns a reference to x's type. + template + operator Action() const { + typedef typename Function::Result Result; + // Asserts that the function return type is a reference. This + // catches the user error of using ReturnRefOfCopy(x) when Return(x) + // should be used, and generates some helpful error message. + GTEST_COMPILE_ASSERT_( + internal::is_reference::value, + use_Return_instead_of_ReturnRefOfCopy_to_return_a_value); + return Action(new Impl(value_)); + } + + private: + // Implements the ReturnRefOfCopy(x) action for a particular function type F. + template + class Impl : public ActionInterface { + public: + typedef typename Function::Result Result; + typedef typename Function::ArgumentTuple ArgumentTuple; + + explicit Impl(const T& value) : value_(value) {} // NOLINT + + virtual Result Perform(const ArgumentTuple&) { + return value_; + } + + private: + T value_; + + GTEST_DISALLOW_ASSIGN_(Impl); + }; + + const T value_; + + GTEST_DISALLOW_ASSIGN_(ReturnRefOfCopyAction); +}; + +// Implements the polymorphic DoDefault() action. +class DoDefaultAction { + public: + // This template type conversion operator allows DoDefault() to be + // used in any function. + template + operator Action() const { return Action(NULL); } +}; + +// Implements the Assign action to set a given pointer referent to a +// particular value. +template +class AssignAction { + public: + AssignAction(T1* ptr, T2 value) : ptr_(ptr), value_(value) {} + + template + void Perform(const ArgumentTuple& /* args */) const { + *ptr_ = value_; + } + + private: + T1* const ptr_; + const T2 value_; + + GTEST_DISALLOW_ASSIGN_(AssignAction); +}; + +#if !GTEST_OS_WINDOWS_MOBILE + +// Implements the SetErrnoAndReturn action to simulate return from +// various system calls and libc functions. +template +class SetErrnoAndReturnAction { + public: + SetErrnoAndReturnAction(int errno_value, T result) + : errno_(errno_value), + result_(result) {} + template + Result Perform(const ArgumentTuple& /* args */) const { + errno = errno_; + return result_; + } + + private: + const int errno_; + const T result_; + + GTEST_DISALLOW_ASSIGN_(SetErrnoAndReturnAction); +}; + +#endif // !GTEST_OS_WINDOWS_MOBILE + +// Implements the SetArgumentPointee(x) action for any function +// whose N-th argument (0-based) is a pointer to x's type. The +// template parameter kIsProto is true iff type A is ProtocolMessage, +// proto2::Message, or a sub-class of those. +template +class SetArgumentPointeeAction { + public: + // Constructs an action that sets the variable pointed to by the + // N-th function argument to 'value'. + explicit SetArgumentPointeeAction(const A& value) : value_(value) {} + + template + void Perform(const ArgumentTuple& args) const { + CompileAssertTypesEqual(); + *::std::tr1::get(args) = value_; + } + + private: + const A value_; + + GTEST_DISALLOW_ASSIGN_(SetArgumentPointeeAction); +}; + +template +class SetArgumentPointeeAction { + public: + // Constructs an action that sets the variable pointed to by the + // N-th function argument to 'proto'. Both ProtocolMessage and + // proto2::Message have the CopyFrom() method, so the same + // implementation works for both. + explicit SetArgumentPointeeAction(const Proto& proto) : proto_(new Proto) { + proto_->CopyFrom(proto); + } + + template + void Perform(const ArgumentTuple& args) const { + CompileAssertTypesEqual(); + ::std::tr1::get(args)->CopyFrom(*proto_); + } + + private: + const internal::linked_ptr proto_; + + GTEST_DISALLOW_ASSIGN_(SetArgumentPointeeAction); +}; + +// Implements the InvokeWithoutArgs(f) action. The template argument +// FunctionImpl is the implementation type of f, which can be either a +// function pointer or a functor. InvokeWithoutArgs(f) can be used as an +// Action as long as f's type is compatible with F (i.e. f can be +// assigned to a tr1::function). +template +class InvokeWithoutArgsAction { + public: + // The c'tor makes a copy of function_impl (either a function + // pointer or a functor). + explicit InvokeWithoutArgsAction(FunctionImpl function_impl) + : function_impl_(function_impl) {} + + // Allows InvokeWithoutArgs(f) to be used as any action whose type is + // compatible with f. + template + Result Perform(const ArgumentTuple&) { return function_impl_(); } + + private: + FunctionImpl function_impl_; + + GTEST_DISALLOW_ASSIGN_(InvokeWithoutArgsAction); +}; + +// Implements the InvokeWithoutArgs(object_ptr, &Class::Method) action. +template +class InvokeMethodWithoutArgsAction { + public: + InvokeMethodWithoutArgsAction(Class* obj_ptr, MethodPtr method_ptr) + : obj_ptr_(obj_ptr), method_ptr_(method_ptr) {} + + template + Result Perform(const ArgumentTuple&) const { + return (obj_ptr_->*method_ptr_)(); + } + + private: + Class* const obj_ptr_; + const MethodPtr method_ptr_; + + GTEST_DISALLOW_ASSIGN_(InvokeMethodWithoutArgsAction); +}; + +// Implements the IgnoreResult(action) action. +template +class IgnoreResultAction { + public: + explicit IgnoreResultAction(const A& action) : action_(action) {} + + template + operator Action() const { + // Assert statement belongs here because this is the best place to verify + // conditions on F. It produces the clearest error messages + // in most compilers. + // Impl really belongs in this scope as a local class but can't + // because MSVC produces duplicate symbols in different translation units + // in this case. Until MS fixes that bug we put Impl into the class scope + // and put the typedef both here (for use in assert statement) and + // in the Impl class. But both definitions must be the same. + typedef typename internal::Function::Result Result; + + // Asserts at compile time that F returns void. + CompileAssertTypesEqual(); + + return Action(new Impl(action_)); + } + + private: + template + class Impl : public ActionInterface { + public: + typedef typename internal::Function::Result Result; + typedef typename internal::Function::ArgumentTuple ArgumentTuple; + + explicit Impl(const A& action) : action_(action) {} + + virtual void Perform(const ArgumentTuple& args) { + // Performs the action and ignores its result. + action_.Perform(args); + } + + private: + // Type OriginalFunction is the same as F except that its return + // type is IgnoredValue. + typedef typename internal::Function::MakeResultIgnoredValue + OriginalFunction; + + const Action action_; + + GTEST_DISALLOW_ASSIGN_(Impl); + }; + + const A action_; + + GTEST_DISALLOW_ASSIGN_(IgnoreResultAction); +}; + +// A ReferenceWrapper object represents a reference to type T, +// which can be either const or not. It can be explicitly converted +// from, and implicitly converted to, a T&. Unlike a reference, +// ReferenceWrapper can be copied and can survive template type +// inference. This is used to support by-reference arguments in the +// InvokeArgument(...) action. The idea was from "reference +// wrappers" in tr1, which we don't have in our source tree yet. +template +class ReferenceWrapper { + public: + // Constructs a ReferenceWrapper object from a T&. + explicit ReferenceWrapper(T& l_value) : pointer_(&l_value) {} // NOLINT + + // Allows a ReferenceWrapper object to be implicitly converted to + // a T&. + operator T&() const { return *pointer_; } + private: + T* pointer_; +}; + +// Allows the expression ByRef(x) to be printed as a reference to x. +template +void PrintTo(const ReferenceWrapper& ref, ::std::ostream* os) { + T& value = ref; + UniversalPrinter::Print(value, os); +} + +// Does two actions sequentially. Used for implementing the DoAll(a1, +// a2, ...) action. +template +class DoBothAction { + public: + DoBothAction(Action1 action1, Action2 action2) + : action1_(action1), action2_(action2) {} + + // This template type conversion operator allows DoAll(a1, ..., a_n) + // to be used in ANY function of compatible type. + template + operator Action() const { + return Action(new Impl(action1_, action2_)); + } + + private: + // Implements the DoAll(...) action for a particular function type F. + template + class Impl : public ActionInterface { + public: + typedef typename Function::Result Result; + typedef typename Function::ArgumentTuple ArgumentTuple; + typedef typename Function::MakeResultVoid VoidResult; + + Impl(const Action& action1, const Action& action2) + : action1_(action1), action2_(action2) {} + + virtual Result Perform(const ArgumentTuple& args) { + action1_.Perform(args); + return action2_.Perform(args); + } + + private: + const Action action1_; + const Action action2_; + + GTEST_DISALLOW_ASSIGN_(Impl); + }; + + Action1 action1_; + Action2 action2_; + + GTEST_DISALLOW_ASSIGN_(DoBothAction); +}; + +} // namespace internal + +// An Unused object can be implicitly constructed from ANY value. +// This is handy when defining actions that ignore some or all of the +// mock function arguments. For example, given +// +// MOCK_METHOD3(Foo, double(const string& label, double x, double y)); +// MOCK_METHOD3(Bar, double(int index, double x, double y)); +// +// instead of +// +// double DistanceToOriginWithLabel(const string& label, double x, double y) { +// return sqrt(x*x + y*y); +// } +// double DistanceToOriginWithIndex(int index, double x, double y) { +// return sqrt(x*x + y*y); +// } +// ... +// EXEPCT_CALL(mock, Foo("abc", _, _)) +// .WillOnce(Invoke(DistanceToOriginWithLabel)); +// EXEPCT_CALL(mock, Bar(5, _, _)) +// .WillOnce(Invoke(DistanceToOriginWithIndex)); +// +// you could write +// +// // We can declare any uninteresting argument as Unused. +// double DistanceToOrigin(Unused, double x, double y) { +// return sqrt(x*x + y*y); +// } +// ... +// EXEPCT_CALL(mock, Foo("abc", _, _)).WillOnce(Invoke(DistanceToOrigin)); +// EXEPCT_CALL(mock, Bar(5, _, _)).WillOnce(Invoke(DistanceToOrigin)); +typedef internal::IgnoredValue Unused; + +// This constructor allows us to turn an Action object into an +// Action, as long as To's arguments can be implicitly converted +// to From's and From's return type cann be implicitly converted to +// To's. +template +template +Action::Action(const Action& from) + : impl_(new internal::ActionAdaptor(from)) {} + +// Creates an action that returns 'value'. 'value' is passed by value +// instead of const reference - otherwise Return("string literal") +// will trigger a compiler error about using array as initializer. +template +internal::ReturnAction Return(R value) { + return internal::ReturnAction(value); +} + +// Creates an action that returns NULL. +inline PolymorphicAction ReturnNull() { + return MakePolymorphicAction(internal::ReturnNullAction()); +} + +// Creates an action that returns from a void function. +inline PolymorphicAction Return() { + return MakePolymorphicAction(internal::ReturnVoidAction()); +} + +// Creates an action that returns the reference to a variable. +template +inline internal::ReturnRefAction ReturnRef(R& x) { // NOLINT + return internal::ReturnRefAction(x); +} + +// Creates an action that returns the reference to a copy of the +// argument. The copy is created when the action is constructed and +// lives as long as the action. +template +inline internal::ReturnRefOfCopyAction ReturnRefOfCopy(const R& x) { + return internal::ReturnRefOfCopyAction(x); +} + +// Creates an action that does the default action for the give mock function. +inline internal::DoDefaultAction DoDefault() { + return internal::DoDefaultAction(); +} + +// Creates an action that sets the variable pointed by the N-th +// (0-based) function argument to 'value'. +template +PolymorphicAction< + internal::SetArgumentPointeeAction< + N, T, internal::IsAProtocolMessage::value> > +SetArgPointee(const T& x) { + return MakePolymorphicAction(internal::SetArgumentPointeeAction< + N, T, internal::IsAProtocolMessage::value>(x)); +} + +#if !((GTEST_GCC_VER_ && GTEST_GCC_VER_ < 40000) || GTEST_OS_SYMBIAN) +// This overload allows SetArgPointee() to accept a string literal. +// GCC prior to the version 4.0 and Symbian C++ compiler cannot distinguish +// this overload from the templated version and emit a compile error. +template +PolymorphicAction< + internal::SetArgumentPointeeAction > +SetArgPointee(const char* p) { + return MakePolymorphicAction(internal::SetArgumentPointeeAction< + N, const char*, false>(p)); +} + +template +PolymorphicAction< + internal::SetArgumentPointeeAction > +SetArgPointee(const wchar_t* p) { + return MakePolymorphicAction(internal::SetArgumentPointeeAction< + N, const wchar_t*, false>(p)); +} +#endif + +// The following version is DEPRECATED. +template +PolymorphicAction< + internal::SetArgumentPointeeAction< + N, T, internal::IsAProtocolMessage::value> > +SetArgumentPointee(const T& x) { + return MakePolymorphicAction(internal::SetArgumentPointeeAction< + N, T, internal::IsAProtocolMessage::value>(x)); +} + +// Creates an action that sets a pointer referent to a given value. +template +PolymorphicAction > Assign(T1* ptr, T2 val) { + return MakePolymorphicAction(internal::AssignAction(ptr, val)); +} + +#if !GTEST_OS_WINDOWS_MOBILE + +// Creates an action that sets errno and returns the appropriate error. +template +PolymorphicAction > +SetErrnoAndReturn(int errval, T result) { + return MakePolymorphicAction( + internal::SetErrnoAndReturnAction(errval, result)); +} + +#endif // !GTEST_OS_WINDOWS_MOBILE + +// Various overloads for InvokeWithoutArgs(). + +// Creates an action that invokes 'function_impl' with no argument. +template +PolymorphicAction > +InvokeWithoutArgs(FunctionImpl function_impl) { + return MakePolymorphicAction( + internal::InvokeWithoutArgsAction(function_impl)); +} + +// Creates an action that invokes the given method on the given object +// with no argument. +template +PolymorphicAction > +InvokeWithoutArgs(Class* obj_ptr, MethodPtr method_ptr) { + return MakePolymorphicAction( + internal::InvokeMethodWithoutArgsAction( + obj_ptr, method_ptr)); +} + +// Creates an action that performs an_action and throws away its +// result. In other words, it changes the return type of an_action to +// void. an_action MUST NOT return void, or the code won't compile. +template +inline internal::IgnoreResultAction IgnoreResult(const A& an_action) { + return internal::IgnoreResultAction(an_action); +} + +// Creates a reference wrapper for the given L-value. If necessary, +// you can explicitly specify the type of the reference. For example, +// suppose 'derived' is an object of type Derived, ByRef(derived) +// would wrap a Derived&. If you want to wrap a const Base& instead, +// where Base is a base class of Derived, just write: +// +// ByRef(derived) +template +inline internal::ReferenceWrapper ByRef(T& l_value) { // NOLINT + return internal::ReferenceWrapper(l_value); +} + +} // namespace testing + +#endif // GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_ diff --git a/mbelib-wasm/mbelib/test/gmock/include/gmock/gmock-cardinalities.h b/mbelib-wasm/mbelib/test/gmock/include/gmock/gmock-cardinalities.h new file mode 100644 index 0000000..fc315f9 --- /dev/null +++ b/mbelib-wasm/mbelib/test/gmock/include/gmock/gmock-cardinalities.h @@ -0,0 +1,147 @@ +// Copyright 2007, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Author: wan@google.com (Zhanyong Wan) + +// Google Mock - a framework for writing C++ mock classes. +// +// This file implements some commonly used cardinalities. More +// cardinalities can be defined by the user implementing the +// CardinalityInterface interface if necessary. + +#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_ +#define GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_ + +#include +#include // NOLINT +#include "gmock/internal/gmock-port.h" +#include "gtest/gtest.h" + +namespace testing { + +// To implement a cardinality Foo, define: +// 1. a class FooCardinality that implements the +// CardinalityInterface interface, and +// 2. a factory function that creates a Cardinality object from a +// const FooCardinality*. +// +// The two-level delegation design follows that of Matcher, providing +// consistency for extension developers. It also eases ownership +// management as Cardinality objects can now be copied like plain values. + +// The implementation of a cardinality. +class CardinalityInterface { + public: + virtual ~CardinalityInterface() {} + + // Conservative estimate on the lower/upper bound of the number of + // calls allowed. + virtual int ConservativeLowerBound() const { return 0; } + virtual int ConservativeUpperBound() const { return INT_MAX; } + + // Returns true iff call_count calls will satisfy this cardinality. + virtual bool IsSatisfiedByCallCount(int call_count) const = 0; + + // Returns true iff call_count calls will saturate this cardinality. + virtual bool IsSaturatedByCallCount(int call_count) const = 0; + + // Describes self to an ostream. + virtual void DescribeTo(::std::ostream* os) const = 0; +}; + +// A Cardinality is a copyable and IMMUTABLE (except by assignment) +// object that specifies how many times a mock function is expected to +// be called. The implementation of Cardinality is just a linked_ptr +// to const CardinalityInterface, so copying is fairly cheap. +// Don't inherit from Cardinality! +class GTEST_API_ Cardinality { + public: + // Constructs a null cardinality. Needed for storing Cardinality + // objects in STL containers. + Cardinality() {} + + // Constructs a Cardinality from its implementation. + explicit Cardinality(const CardinalityInterface* impl) : impl_(impl) {} + + // Conservative estimate on the lower/upper bound of the number of + // calls allowed. + int ConservativeLowerBound() const { return impl_->ConservativeLowerBound(); } + int ConservativeUpperBound() const { return impl_->ConservativeUpperBound(); } + + // Returns true iff call_count calls will satisfy this cardinality. + bool IsSatisfiedByCallCount(int call_count) const { + return impl_->IsSatisfiedByCallCount(call_count); + } + + // Returns true iff call_count calls will saturate this cardinality. + bool IsSaturatedByCallCount(int call_count) const { + return impl_->IsSaturatedByCallCount(call_count); + } + + // Returns true iff call_count calls will over-saturate this + // cardinality, i.e. exceed the maximum number of allowed calls. + bool IsOverSaturatedByCallCount(int call_count) const { + return impl_->IsSaturatedByCallCount(call_count) && + !impl_->IsSatisfiedByCallCount(call_count); + } + + // Describes self to an ostream + void DescribeTo(::std::ostream* os) const { impl_->DescribeTo(os); } + + // Describes the given actual call count to an ostream. + static void DescribeActualCallCountTo(int actual_call_count, + ::std::ostream* os); + + private: + internal::linked_ptr impl_; +}; + +// Creates a cardinality that allows at least n calls. +GTEST_API_ Cardinality AtLeast(int n); + +// Creates a cardinality that allows at most n calls. +GTEST_API_ Cardinality AtMost(int n); + +// Creates a cardinality that allows any number of calls. +GTEST_API_ Cardinality AnyNumber(); + +// Creates a cardinality that allows between min and max calls. +GTEST_API_ Cardinality Between(int min, int max); + +// Creates a cardinality that allows exactly n calls. +GTEST_API_ Cardinality Exactly(int n); + +// Creates a cardinality from its implementation. +inline Cardinality MakeCardinality(const CardinalityInterface* c) { + return Cardinality(c); +} + +} // namespace testing + +#endif // GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_ diff --git a/mbelib-wasm/mbelib/test/gmock/include/gmock/gmock-generated-actions.h b/mbelib-wasm/mbelib/test/gmock/include/gmock/gmock-generated-actions.h new file mode 100644 index 0000000..2327393 --- /dev/null +++ b/mbelib-wasm/mbelib/test/gmock/include/gmock/gmock-generated-actions.h @@ -0,0 +1,2415 @@ +// This file was GENERATED by a script. DO NOT EDIT BY HAND!!! + +// Copyright 2007, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Author: wan@google.com (Zhanyong Wan) + +// Google Mock - a framework for writing C++ mock classes. +// +// This file implements some commonly used variadic actions. + +#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_ +#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_ + +#include "gmock/gmock-actions.h" +#include "gmock/internal/gmock-port.h" + +namespace testing { +namespace internal { + +// InvokeHelper knows how to unpack an N-tuple and invoke an N-ary +// function or method with the unpacked values, where F is a function +// type that takes N arguments. +template +class InvokeHelper; + +template +class InvokeHelper > { + public: + template + static R Invoke(Function function, const ::std::tr1::tuple<>&) { + return function(); + } + + template + static R InvokeMethod(Class* obj_ptr, + MethodPtr method_ptr, + const ::std::tr1::tuple<>&) { + return (obj_ptr->*method_ptr)(); + } +}; + +template +class InvokeHelper > { + public: + template + static R Invoke(Function function, const ::std::tr1::tuple& args) { + using ::std::tr1::get; + return function(get<0>(args)); + } + + template + static R InvokeMethod(Class* obj_ptr, + MethodPtr method_ptr, + const ::std::tr1::tuple& args) { + using ::std::tr1::get; + return (obj_ptr->*method_ptr)(get<0>(args)); + } +}; + +template +class InvokeHelper > { + public: + template + static R Invoke(Function function, const ::std::tr1::tuple& args) { + using ::std::tr1::get; + return function(get<0>(args), get<1>(args)); + } + + template + static R InvokeMethod(Class* obj_ptr, + MethodPtr method_ptr, + const ::std::tr1::tuple& args) { + using ::std::tr1::get; + return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args)); + } +}; + +template +class InvokeHelper > { + public: + template + static R Invoke(Function function, const ::std::tr1::tuple& args) { + using ::std::tr1::get; + return function(get<0>(args), get<1>(args), get<2>(args)); + } + + template + static R InvokeMethod(Class* obj_ptr, + MethodPtr method_ptr, + const ::std::tr1::tuple& args) { + using ::std::tr1::get; + return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args)); + } +}; + +template +class InvokeHelper > { + public: + template + static R Invoke(Function function, const ::std::tr1::tuple& args) { + using ::std::tr1::get; + return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args)); + } + + template + static R InvokeMethod(Class* obj_ptr, + MethodPtr method_ptr, + const ::std::tr1::tuple& args) { + using ::std::tr1::get; + return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args), + get<3>(args)); + } +}; + +template +class InvokeHelper > { + public: + template + static R Invoke(Function function, const ::std::tr1::tuple& args) { + using ::std::tr1::get; + return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args), + get<4>(args)); + } + + template + static R InvokeMethod(Class* obj_ptr, + MethodPtr method_ptr, + const ::std::tr1::tuple& args) { + using ::std::tr1::get; + return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args), + get<3>(args), get<4>(args)); + } +}; + +template +class InvokeHelper > { + public: + template + static R Invoke(Function function, const ::std::tr1::tuple& args) { + using ::std::tr1::get; + return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args), + get<4>(args), get<5>(args)); + } + + template + static R InvokeMethod(Class* obj_ptr, + MethodPtr method_ptr, + const ::std::tr1::tuple& args) { + using ::std::tr1::get; + return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args), + get<3>(args), get<4>(args), get<5>(args)); + } +}; + +template +class InvokeHelper > { + public: + template + static R Invoke(Function function, const ::std::tr1::tuple& args) { + using ::std::tr1::get; + return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args), + get<4>(args), get<5>(args), get<6>(args)); + } + + template + static R InvokeMethod(Class* obj_ptr, + MethodPtr method_ptr, + const ::std::tr1::tuple& args) { + using ::std::tr1::get; + return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args), + get<3>(args), get<4>(args), get<5>(args), get<6>(args)); + } +}; + +template +class InvokeHelper > { + public: + template + static R Invoke(Function function, const ::std::tr1::tuple& args) { + using ::std::tr1::get; + return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args), + get<4>(args), get<5>(args), get<6>(args), get<7>(args)); + } + + template + static R InvokeMethod(Class* obj_ptr, + MethodPtr method_ptr, + const ::std::tr1::tuple& args) { + using ::std::tr1::get; + return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args), + get<3>(args), get<4>(args), get<5>(args), get<6>(args), get<7>(args)); + } +}; + +template +class InvokeHelper > { + public: + template + static R Invoke(Function function, const ::std::tr1::tuple& args) { + using ::std::tr1::get; + return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args), + get<4>(args), get<5>(args), get<6>(args), get<7>(args), get<8>(args)); + } + + template + static R InvokeMethod(Class* obj_ptr, + MethodPtr method_ptr, + const ::std::tr1::tuple& args) { + using ::std::tr1::get; + return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args), + get<3>(args), get<4>(args), get<5>(args), get<6>(args), get<7>(args), + get<8>(args)); + } +}; + +template +class InvokeHelper > { + public: + template + static R Invoke(Function function, const ::std::tr1::tuple& args) { + using ::std::tr1::get; + return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args), + get<4>(args), get<5>(args), get<6>(args), get<7>(args), get<8>(args), + get<9>(args)); + } + + template + static R InvokeMethod(Class* obj_ptr, + MethodPtr method_ptr, + const ::std::tr1::tuple& args) { + using ::std::tr1::get; + return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args), + get<3>(args), get<4>(args), get<5>(args), get<6>(args), get<7>(args), + get<8>(args), get<9>(args)); + } +}; + +// CallableHelper has static methods for invoking "callables", +// i.e. function pointers and functors. It uses overloading to +// provide a uniform interface for invoking different kinds of +// callables. In particular, you can use: +// +// CallableHelper::Call(callable, a1, a2, ..., an) +// +// to invoke an n-ary callable, where R is its return type. If an +// argument, say a2, needs to be passed by reference, you should write +// ByRef(a2) instead of a2 in the above expression. +template +class CallableHelper { + public: + // Calls a nullary callable. + template + static R Call(Function function) { return function(); } + + // Calls a unary callable. + + // We deliberately pass a1 by value instead of const reference here + // in case it is a C-string literal. If we had declared the + // parameter as 'const A1& a1' and write Call(function, "Hi"), the + // compiler would've thought A1 is 'char[3]', which causes trouble + // when you need to copy a value of type A1. By declaring the + // parameter as 'A1 a1', the compiler will correctly infer that A1 + // is 'const char*' when it sees Call(function, "Hi"). + // + // Since this function is defined inline, the compiler can get rid + // of the copying of the arguments. Therefore the performance won't + // be hurt. + template + static R Call(Function function, A1 a1) { return function(a1); } + + // Calls a binary callable. + template + static R Call(Function function, A1 a1, A2 a2) { + return function(a1, a2); + } + + // Calls a ternary callable. + template + static R Call(Function function, A1 a1, A2 a2, A3 a3) { + return function(a1, a2, a3); + } + + // Calls a 4-ary callable. + template + static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4) { + return function(a1, a2, a3, a4); + } + + // Calls a 5-ary callable. + template + static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { + return function(a1, a2, a3, a4, a5); + } + + // Calls a 6-ary callable. + template + static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) { + return function(a1, a2, a3, a4, a5, a6); + } + + // Calls a 7-ary callable. + template + static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, + A7 a7) { + return function(a1, a2, a3, a4, a5, a6, a7); + } + + // Calls a 8-ary callable. + template + static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, + A7 a7, A8 a8) { + return function(a1, a2, a3, a4, a5, a6, a7, a8); + } + + // Calls a 9-ary callable. + template + static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, + A7 a7, A8 a8, A9 a9) { + return function(a1, a2, a3, a4, a5, a6, a7, a8, a9); + } + + // Calls a 10-ary callable. + template + static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, + A7 a7, A8 a8, A9 a9, A10 a10) { + return function(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10); + } +}; // class CallableHelper + +// An INTERNAL macro for extracting the type of a tuple field. It's +// subject to change without notice - DO NOT USE IN USER CODE! +#define GMOCK_FIELD_(Tuple, N) \ + typename ::std::tr1::tuple_element::type + +// SelectArgs::type is the +// type of an n-ary function whose i-th (1-based) argument type is the +// k{i}-th (0-based) field of ArgumentTuple, which must be a tuple +// type, and whose return type is Result. For example, +// SelectArgs, 0, 3>::type +// is int(bool, long). +// +// SelectArgs::Select(args) +// returns the selected fields (k1, k2, ..., k_n) of args as a tuple. +// For example, +// SelectArgs, 2, 0>::Select( +// ::std::tr1::make_tuple(true, 'a', 2.5)) +// returns ::std::tr1::tuple (2.5, true). +// +// The numbers in list k1, k2, ..., k_n must be >= 0, where n can be +// in the range [0, 10]. Duplicates are allowed and they don't have +// to be in an ascending or descending order. + +template +class SelectArgs { + public: + typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1), + GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3), + GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5), + GMOCK_FIELD_(ArgumentTuple, k6), GMOCK_FIELD_(ArgumentTuple, k7), + GMOCK_FIELD_(ArgumentTuple, k8), GMOCK_FIELD_(ArgumentTuple, k9), + GMOCK_FIELD_(ArgumentTuple, k10)); + typedef typename Function::ArgumentTuple SelectedArgs; + static SelectedArgs Select(const ArgumentTuple& args) { + using ::std::tr1::get; + return SelectedArgs(get(args), get(args), get(args), + get(args), get(args), get(args), get(args), + get(args), get(args), get(args)); + } +}; + +template +class SelectArgs { + public: + typedef Result type(); + typedef typename Function::ArgumentTuple SelectedArgs; + static SelectedArgs Select(const ArgumentTuple& /* args */) { + using ::std::tr1::get; + return SelectedArgs(); + } +}; + +template +class SelectArgs { + public: + typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1)); + typedef typename Function::ArgumentTuple SelectedArgs; + static SelectedArgs Select(const ArgumentTuple& args) { + using ::std::tr1::get; + return SelectedArgs(get(args)); + } +}; + +template +class SelectArgs { + public: + typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1), + GMOCK_FIELD_(ArgumentTuple, k2)); + typedef typename Function::ArgumentTuple SelectedArgs; + static SelectedArgs Select(const ArgumentTuple& args) { + using ::std::tr1::get; + return SelectedArgs(get(args), get(args)); + } +}; + +template +class SelectArgs { + public: + typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1), + GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3)); + typedef typename Function::ArgumentTuple SelectedArgs; + static SelectedArgs Select(const ArgumentTuple& args) { + using ::std::tr1::get; + return SelectedArgs(get(args), get(args), get(args)); + } +}; + +template +class SelectArgs { + public: + typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1), + GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3), + GMOCK_FIELD_(ArgumentTuple, k4)); + typedef typename Function::ArgumentTuple SelectedArgs; + static SelectedArgs Select(const ArgumentTuple& args) { + using ::std::tr1::get; + return SelectedArgs(get(args), get(args), get(args), + get(args)); + } +}; + +template +class SelectArgs { + public: + typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1), + GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3), + GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5)); + typedef typename Function::ArgumentTuple SelectedArgs; + static SelectedArgs Select(const ArgumentTuple& args) { + using ::std::tr1::get; + return SelectedArgs(get(args), get(args), get(args), + get(args), get(args)); + } +}; + +template +class SelectArgs { + public: + typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1), + GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3), + GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5), + GMOCK_FIELD_(ArgumentTuple, k6)); + typedef typename Function::ArgumentTuple SelectedArgs; + static SelectedArgs Select(const ArgumentTuple& args) { + using ::std::tr1::get; + return SelectedArgs(get(args), get(args), get(args), + get(args), get(args), get(args)); + } +}; + +template +class SelectArgs { + public: + typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1), + GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3), + GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5), + GMOCK_FIELD_(ArgumentTuple, k6), GMOCK_FIELD_(ArgumentTuple, k7)); + typedef typename Function::ArgumentTuple SelectedArgs; + static SelectedArgs Select(const ArgumentTuple& args) { + using ::std::tr1::get; + return SelectedArgs(get(args), get(args), get(args), + get(args), get(args), get(args), get(args)); + } +}; + +template +class SelectArgs { + public: + typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1), + GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3), + GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5), + GMOCK_FIELD_(ArgumentTuple, k6), GMOCK_FIELD_(ArgumentTuple, k7), + GMOCK_FIELD_(ArgumentTuple, k8)); + typedef typename Function::ArgumentTuple SelectedArgs; + static SelectedArgs Select(const ArgumentTuple& args) { + using ::std::tr1::get; + return SelectedArgs(get(args), get(args), get(args), + get(args), get(args), get(args), get(args), + get(args)); + } +}; + +template +class SelectArgs { + public: + typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1), + GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3), + GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5), + GMOCK_FIELD_(ArgumentTuple, k6), GMOCK_FIELD_(ArgumentTuple, k7), + GMOCK_FIELD_(ArgumentTuple, k8), GMOCK_FIELD_(ArgumentTuple, k9)); + typedef typename Function::ArgumentTuple SelectedArgs; + static SelectedArgs Select(const ArgumentTuple& args) { + using ::std::tr1::get; + return SelectedArgs(get(args), get(args), get(args), + get(args), get(args), get(args), get(args), + get(args), get(args)); + } +}; + +#undef GMOCK_FIELD_ + +// Implements the WithArgs action. +template +class WithArgsAction { + public: + explicit WithArgsAction(const InnerAction& action) : action_(action) {} + + template + operator Action() const { return MakeAction(new Impl(action_)); } + + private: + template + class Impl : public ActionInterface { + public: + typedef typename Function::Result Result; + typedef typename Function::ArgumentTuple ArgumentTuple; + + explicit Impl(const InnerAction& action) : action_(action) {} + + virtual Result Perform(const ArgumentTuple& args) { + return action_.Perform(SelectArgs::Select(args)); + } + + private: + typedef typename SelectArgs::type InnerFunctionType; + + Action action_; + }; + + const InnerAction action_; + + GTEST_DISALLOW_ASSIGN_(WithArgsAction); +}; + +// A macro from the ACTION* family (defined later in this file) +// defines an action that can be used in a mock function. Typically, +// these actions only care about a subset of the arguments of the mock +// function. For example, if such an action only uses the second +// argument, it can be used in any mock function that takes >= 2 +// arguments where the type of the second argument is compatible. +// +// Therefore, the action implementation must be prepared to take more +// arguments than it needs. The ExcessiveArg type is used to +// represent those excessive arguments. In order to keep the compiler +// error messages tractable, we define it in the testing namespace +// instead of testing::internal. However, this is an INTERNAL TYPE +// and subject to change without notice, so a user MUST NOT USE THIS +// TYPE DIRECTLY. +struct ExcessiveArg {}; + +// A helper class needed for implementing the ACTION* macros. +template +class ActionHelper { + public: + static Result Perform(Impl* impl, const ::std::tr1::tuple<>& args) { + using ::std::tr1::get; + return impl->template gmock_PerformImpl<>(args, ExcessiveArg(), + ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), + ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), + ExcessiveArg()); + } + + template + static Result Perform(Impl* impl, const ::std::tr1::tuple& args) { + using ::std::tr1::get; + return impl->template gmock_PerformImpl(args, get<0>(args), + ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), + ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), + ExcessiveArg()); + } + + template + static Result Perform(Impl* impl, const ::std::tr1::tuple& args) { + using ::std::tr1::get; + return impl->template gmock_PerformImpl(args, get<0>(args), + get<1>(args), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), + ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), + ExcessiveArg()); + } + + template + static Result Perform(Impl* impl, const ::std::tr1::tuple& args) { + using ::std::tr1::get; + return impl->template gmock_PerformImpl(args, get<0>(args), + get<1>(args), get<2>(args), ExcessiveArg(), ExcessiveArg(), + ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), + ExcessiveArg()); + } + + template + static Result Perform(Impl* impl, const ::std::tr1::tuple& args) { + using ::std::tr1::get; + return impl->template gmock_PerformImpl(args, get<0>(args), + get<1>(args), get<2>(args), get<3>(args), ExcessiveArg(), + ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), + ExcessiveArg()); + } + + template + static Result Perform(Impl* impl, const ::std::tr1::tuple& args) { + using ::std::tr1::get; + return impl->template gmock_PerformImpl(args, + get<0>(args), get<1>(args), get<2>(args), get<3>(args), get<4>(args), + ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), + ExcessiveArg()); + } + + template + static Result Perform(Impl* impl, const ::std::tr1::tuple& args) { + using ::std::tr1::get; + return impl->template gmock_PerformImpl(args, + get<0>(args), get<1>(args), get<2>(args), get<3>(args), get<4>(args), + get<5>(args), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), + ExcessiveArg()); + } + + template + static Result Perform(Impl* impl, const ::std::tr1::tuple& args) { + using ::std::tr1::get; + return impl->template gmock_PerformImpl(args, + get<0>(args), get<1>(args), get<2>(args), get<3>(args), get<4>(args), + get<5>(args), get<6>(args), ExcessiveArg(), ExcessiveArg(), + ExcessiveArg()); + } + + template + static Result Perform(Impl* impl, const ::std::tr1::tuple& args) { + using ::std::tr1::get; + return impl->template gmock_PerformImpl(args, get<0>(args), get<1>(args), get<2>(args), get<3>(args), + get<4>(args), get<5>(args), get<6>(args), get<7>(args), ExcessiveArg(), + ExcessiveArg()); + } + + template + static Result Perform(Impl* impl, const ::std::tr1::tuple& args) { + using ::std::tr1::get; + return impl->template gmock_PerformImpl(args, get<0>(args), get<1>(args), get<2>(args), get<3>(args), + get<4>(args), get<5>(args), get<6>(args), get<7>(args), get<8>(args), + ExcessiveArg()); + } + + template + static Result Perform(Impl* impl, const ::std::tr1::tuple& args) { + using ::std::tr1::get; + return impl->template gmock_PerformImpl(args, get<0>(args), get<1>(args), get<2>(args), get<3>(args), + get<4>(args), get<5>(args), get<6>(args), get<7>(args), get<8>(args), + get<9>(args)); + } +}; + +} // namespace internal + +// Various overloads for Invoke(). + +// WithArgs(an_action) creates an action that passes +// the selected arguments of the mock function to an_action and +// performs it. It serves as an adaptor between actions with +// different argument lists. C++ doesn't support default arguments for +// function templates, so we have to overload it. +template +inline internal::WithArgsAction +WithArgs(const InnerAction& action) { + return internal::WithArgsAction(action); +} + +template +inline internal::WithArgsAction +WithArgs(const InnerAction& action) { + return internal::WithArgsAction(action); +} + +template +inline internal::WithArgsAction +WithArgs(const InnerAction& action) { + return internal::WithArgsAction(action); +} + +template +inline internal::WithArgsAction +WithArgs(const InnerAction& action) { + return internal::WithArgsAction(action); +} + +template +inline internal::WithArgsAction +WithArgs(const InnerAction& action) { + return internal::WithArgsAction(action); +} + +template +inline internal::WithArgsAction +WithArgs(const InnerAction& action) { + return internal::WithArgsAction(action); +} + +template +inline internal::WithArgsAction +WithArgs(const InnerAction& action) { + return internal::WithArgsAction(action); +} + +template +inline internal::WithArgsAction +WithArgs(const InnerAction& action) { + return internal::WithArgsAction(action); +} + +template +inline internal::WithArgsAction +WithArgs(const InnerAction& action) { + return internal::WithArgsAction(action); +} + +template +inline internal::WithArgsAction +WithArgs(const InnerAction& action) { + return internal::WithArgsAction(action); +} + +// Creates an action that does actions a1, a2, ..., sequentially in +// each invocation. +template +inline internal::DoBothAction +DoAll(Action1 a1, Action2 a2) { + return internal::DoBothAction(a1, a2); +} + +template +inline internal::DoBothAction > +DoAll(Action1 a1, Action2 a2, Action3 a3) { + return DoAll(a1, DoAll(a2, a3)); +} + +template +inline internal::DoBothAction > > +DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4) { + return DoAll(a1, DoAll(a2, a3, a4)); +} + +template +inline internal::DoBothAction > > > +DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5) { + return DoAll(a1, DoAll(a2, a3, a4, a5)); +} + +template +inline internal::DoBothAction > > > > +DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6) { + return DoAll(a1, DoAll(a2, a3, a4, a5, a6)); +} + +template +inline internal::DoBothAction > > > > > +DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, + Action7 a7) { + return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7)); +} + +template +inline internal::DoBothAction > > > > > > +DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, + Action7 a7, Action8 a8) { + return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7, a8)); +} + +template +inline internal::DoBothAction > > > > > > > +DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, + Action7 a7, Action8 a8, Action9 a9) { + return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7, a8, a9)); +} + +template +inline internal::DoBothAction > > > > > > > > +DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, + Action7 a7, Action8 a8, Action9 a9, Action10 a10) { + return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7, a8, a9, a10)); +} + +} // namespace testing + +// The ACTION* family of macros can be used in a namespace scope to +// define custom actions easily. The syntax: +// +// ACTION(name) { statements; } +// +// will define an action with the given name that executes the +// statements. The value returned by the statements will be used as +// the return value of the action. Inside the statements, you can +// refer to the K-th (0-based) argument of the mock function by +// 'argK', and refer to its type by 'argK_type'. For example: +// +// ACTION(IncrementArg1) { +// arg1_type temp = arg1; +// return ++(*temp); +// } +// +// allows you to write +// +// ...WillOnce(IncrementArg1()); +// +// You can also refer to the entire argument tuple and its type by +// 'args' and 'args_type', and refer to the mock function type and its +// return type by 'function_type' and 'return_type'. +// +// Note that you don't need to specify the types of the mock function +// arguments. However rest assured that your code is still type-safe: +// you'll get a compiler error if *arg1 doesn't support the ++ +// operator, or if the type of ++(*arg1) isn't compatible with the +// mock function's return type, for example. +// +// Sometimes you'll want to parameterize the action. For that you can use +// another macro: +// +// ACTION_P(name, param_name) { statements; } +// +// For example: +// +// ACTION_P(Add, n) { return arg0 + n; } +// +// will allow you to write: +// +// ...WillOnce(Add(5)); +// +// Note that you don't need to provide the type of the parameter +// either. If you need to reference the type of a parameter named +// 'foo', you can write 'foo_type'. For example, in the body of +// ACTION_P(Add, n) above, you can write 'n_type' to refer to the type +// of 'n'. +// +// We also provide ACTION_P2, ACTION_P3, ..., up to ACTION_P10 to support +// multi-parameter actions. +// +// For the purpose of typing, you can view +// +// ACTION_Pk(Foo, p1, ..., pk) { ... } +// +// as shorthand for +// +// template +// FooActionPk Foo(p1_type p1, ..., pk_type pk) { ... } +// +// In particular, you can provide the template type arguments +// explicitly when invoking Foo(), as in Foo(5, false); +// although usually you can rely on the compiler to infer the types +// for you automatically. You can assign the result of expression +// Foo(p1, ..., pk) to a variable of type FooActionPk. This can be useful when composing actions. +// +// You can also overload actions with different numbers of parameters: +// +// ACTION_P(Plus, a) { ... } +// ACTION_P2(Plus, a, b) { ... } +// +// While it's tempting to always use the ACTION* macros when defining +// a new action, you should also consider implementing ActionInterface +// or using MakePolymorphicAction() instead, especially if you need to +// use the action a lot. While these approaches require more work, +// they give you more control on the types of the mock function +// arguments and the action parameters, which in general leads to +// better compiler error messages that pay off in the long run. They +// also allow overloading actions based on parameter types (as opposed +// to just based on the number of parameters). +// +// CAVEAT: +// +// ACTION*() can only be used in a namespace scope. The reason is +// that C++ doesn't yet allow function-local types to be used to +// instantiate templates. The up-coming C++0x standard will fix this. +// Once that's done, we'll consider supporting using ACTION*() inside +// a function. +// +// MORE INFORMATION: +// +// To learn more about using these macros, please search for 'ACTION' +// on http://code.google.com/p/googlemock/wiki/CookBook. + +// An internal macro needed for implementing ACTION*(). +#define GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_\ + const args_type& args GTEST_ATTRIBUTE_UNUSED_, \ + arg0_type arg0 GTEST_ATTRIBUTE_UNUSED_, \ + arg1_type arg1 GTEST_ATTRIBUTE_UNUSED_, \ + arg2_type arg2 GTEST_ATTRIBUTE_UNUSED_, \ + arg3_type arg3 GTEST_ATTRIBUTE_UNUSED_, \ + arg4_type arg4 GTEST_ATTRIBUTE_UNUSED_, \ + arg5_type arg5 GTEST_ATTRIBUTE_UNUSED_, \ + arg6_type arg6 GTEST_ATTRIBUTE_UNUSED_, \ + arg7_type arg7 GTEST_ATTRIBUTE_UNUSED_, \ + arg8_type arg8 GTEST_ATTRIBUTE_UNUSED_, \ + arg9_type arg9 GTEST_ATTRIBUTE_UNUSED_ + +// Sometimes you want to give an action explicit template parameters +// that cannot be inferred from its value parameters. ACTION() and +// ACTION_P*() don't support that. ACTION_TEMPLATE() remedies that +// and can be viewed as an extension to ACTION() and ACTION_P*(). +// +// The syntax: +// +// ACTION_TEMPLATE(ActionName, +// HAS_m_TEMPLATE_PARAMS(kind1, name1, ..., kind_m, name_m), +// AND_n_VALUE_PARAMS(p1, ..., p_n)) { statements; } +// +// defines an action template that takes m explicit template +// parameters and n value parameters. name_i is the name of the i-th +// template parameter, and kind_i specifies whether it's a typename, +// an integral constant, or a template. p_i is the name of the i-th +// value parameter. +// +// Example: +// +// // DuplicateArg(output) converts the k-th argument of the mock +// // function to type T and copies it to *output. +// ACTION_TEMPLATE(DuplicateArg, +// HAS_2_TEMPLATE_PARAMS(int, k, typename, T), +// AND_1_VALUE_PARAMS(output)) { +// *output = T(std::tr1::get(args)); +// } +// ... +// int n; +// EXPECT_CALL(mock, Foo(_, _)) +// .WillOnce(DuplicateArg<1, unsigned char>(&n)); +// +// To create an instance of an action template, write: +// +// ActionName(v1, ..., v_n) +// +// where the ts are the template arguments and the vs are the value +// arguments. The value argument types are inferred by the compiler. +// If you want to explicitly specify the value argument types, you can +// provide additional template arguments: +// +// ActionName(v1, ..., v_n) +// +// where u_i is the desired type of v_i. +// +// ACTION_TEMPLATE and ACTION/ACTION_P* can be overloaded on the +// number of value parameters, but not on the number of template +// parameters. Without the restriction, the meaning of the following +// is unclear: +// +// OverloadedAction(x); +// +// Are we using a single-template-parameter action where 'bool' refers +// to the type of x, or are we using a two-template-parameter action +// where the compiler is asked to infer the type of x? +// +// Implementation notes: +// +// GMOCK_INTERNAL_*_HAS_m_TEMPLATE_PARAMS and +// GMOCK_INTERNAL_*_AND_n_VALUE_PARAMS are internal macros for +// implementing ACTION_TEMPLATE. The main trick we use is to create +// new macro invocations when expanding a macro. For example, we have +// +// #define ACTION_TEMPLATE(name, template_params, value_params) +// ... GMOCK_INTERNAL_DECL_##template_params ... +// +// which causes ACTION_TEMPLATE(..., HAS_1_TEMPLATE_PARAMS(typename, T), ...) +// to expand to +// +// ... GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS(typename, T) ... +// +// Since GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS is a macro, the +// preprocessor will continue to expand it to +// +// ... typename T ... +// +// This technique conforms to the C++ standard and is portable. It +// allows us to implement action templates using O(N) code, where N is +// the maximum number of template/value parameters supported. Without +// using it, we'd have to devote O(N^2) amount of code to implement all +// combinations of m and n. + +// Declares the template parameters. +#define GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS(kind0, name0) kind0 name0 +#define GMOCK_INTERNAL_DECL_HAS_2_TEMPLATE_PARAMS(kind0, name0, kind1, \ + name1) kind0 name0, kind1 name1 +#define GMOCK_INTERNAL_DECL_HAS_3_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ + kind2, name2) kind0 name0, kind1 name1, kind2 name2 +#define GMOCK_INTERNAL_DECL_HAS_4_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ + kind2, name2, kind3, name3) kind0 name0, kind1 name1, kind2 name2, \ + kind3 name3 +#define GMOCK_INTERNAL_DECL_HAS_5_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ + kind2, name2, kind3, name3, kind4, name4) kind0 name0, kind1 name1, \ + kind2 name2, kind3 name3, kind4 name4 +#define GMOCK_INTERNAL_DECL_HAS_6_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ + kind2, name2, kind3, name3, kind4, name4, kind5, name5) kind0 name0, \ + kind1 name1, kind2 name2, kind3 name3, kind4 name4, kind5 name5 +#define GMOCK_INTERNAL_DECL_HAS_7_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ + kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \ + name6) kind0 name0, kind1 name1, kind2 name2, kind3 name3, kind4 name4, \ + kind5 name5, kind6 name6 +#define GMOCK_INTERNAL_DECL_HAS_8_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ + kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \ + kind7, name7) kind0 name0, kind1 name1, kind2 name2, kind3 name3, \ + kind4 name4, kind5 name5, kind6 name6, kind7 name7 +#define GMOCK_INTERNAL_DECL_HAS_9_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ + kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \ + kind7, name7, kind8, name8) kind0 name0, kind1 name1, kind2 name2, \ + kind3 name3, kind4 name4, kind5 name5, kind6 name6, kind7 name7, \ + kind8 name8 +#define GMOCK_INTERNAL_DECL_HAS_10_TEMPLATE_PARAMS(kind0, name0, kind1, \ + name1, kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \ + name6, kind7, name7, kind8, name8, kind9, name9) kind0 name0, \ + kind1 name1, kind2 name2, kind3 name3, kind4 name4, kind5 name5, \ + kind6 name6, kind7 name7, kind8 name8, kind9 name9 + +// Lists the template parameters. +#define GMOCK_INTERNAL_LIST_HAS_1_TEMPLATE_PARAMS(kind0, name0) name0 +#define GMOCK_INTERNAL_LIST_HAS_2_TEMPLATE_PARAMS(kind0, name0, kind1, \ + name1) name0, name1 +#define GMOCK_INTERNAL_LIST_HAS_3_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ + kind2, name2) name0, name1, name2 +#define GMOCK_INTERNAL_LIST_HAS_4_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ + kind2, name2, kind3, name3) name0, name1, name2, name3 +#define GMOCK_INTERNAL_LIST_HAS_5_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ + kind2, name2, kind3, name3, kind4, name4) name0, name1, name2, name3, \ + name4 +#define GMOCK_INTERNAL_LIST_HAS_6_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ + kind2, name2, kind3, name3, kind4, name4, kind5, name5) name0, name1, \ + name2, name3, name4, name5 +#define GMOCK_INTERNAL_LIST_HAS_7_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ + kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \ + name6) name0, name1, name2, name3, name4, name5, name6 +#define GMOCK_INTERNAL_LIST_HAS_8_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ + kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \ + kind7, name7) name0, name1, name2, name3, name4, name5, name6, name7 +#define GMOCK_INTERNAL_LIST_HAS_9_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ + kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \ + kind7, name7, kind8, name8) name0, name1, name2, name3, name4, name5, \ + name6, name7, name8 +#define GMOCK_INTERNAL_LIST_HAS_10_TEMPLATE_PARAMS(kind0, name0, kind1, \ + name1, kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \ + name6, kind7, name7, kind8, name8, kind9, name9) name0, name1, name2, \ + name3, name4, name5, name6, name7, name8, name9 + +// Declares the types of value parameters. +#define GMOCK_INTERNAL_DECL_TYPE_AND_0_VALUE_PARAMS() +#define GMOCK_INTERNAL_DECL_TYPE_AND_1_VALUE_PARAMS(p0) , typename p0##_type +#define GMOCK_INTERNAL_DECL_TYPE_AND_2_VALUE_PARAMS(p0, p1) , \ + typename p0##_type, typename p1##_type +#define GMOCK_INTERNAL_DECL_TYPE_AND_3_VALUE_PARAMS(p0, p1, p2) , \ + typename p0##_type, typename p1##_type, typename p2##_type +#define GMOCK_INTERNAL_DECL_TYPE_AND_4_VALUE_PARAMS(p0, p1, p2, p3) , \ + typename p0##_type, typename p1##_type, typename p2##_type, \ + typename p3##_type +#define GMOCK_INTERNAL_DECL_TYPE_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) , \ + typename p0##_type, typename p1##_type, typename p2##_type, \ + typename p3##_type, typename p4##_type +#define GMOCK_INTERNAL_DECL_TYPE_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) , \ + typename p0##_type, typename p1##_type, typename p2##_type, \ + typename p3##_type, typename p4##_type, typename p5##_type +#define GMOCK_INTERNAL_DECL_TYPE_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ + p6) , typename p0##_type, typename p1##_type, typename p2##_type, \ + typename p3##_type, typename p4##_type, typename p5##_type, \ + typename p6##_type +#define GMOCK_INTERNAL_DECL_TYPE_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ + p6, p7) , typename p0##_type, typename p1##_type, typename p2##_type, \ + typename p3##_type, typename p4##_type, typename p5##_type, \ + typename p6##_type, typename p7##_type +#define GMOCK_INTERNAL_DECL_TYPE_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ + p6, p7, p8) , typename p0##_type, typename p1##_type, typename p2##_type, \ + typename p3##_type, typename p4##_type, typename p5##_type, \ + typename p6##_type, typename p7##_type, typename p8##_type +#define GMOCK_INTERNAL_DECL_TYPE_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ + p6, p7, p8, p9) , typename p0##_type, typename p1##_type, \ + typename p2##_type, typename p3##_type, typename p4##_type, \ + typename p5##_type, typename p6##_type, typename p7##_type, \ + typename p8##_type, typename p9##_type + +// Initializes the value parameters. +#define GMOCK_INTERNAL_INIT_AND_0_VALUE_PARAMS()\ + () +#define GMOCK_INTERNAL_INIT_AND_1_VALUE_PARAMS(p0)\ + (p0##_type gmock_p0) : p0(gmock_p0) +#define GMOCK_INTERNAL_INIT_AND_2_VALUE_PARAMS(p0, p1)\ + (p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), p1(gmock_p1) +#define GMOCK_INTERNAL_INIT_AND_3_VALUE_PARAMS(p0, p1, p2)\ + (p0##_type gmock_p0, p1##_type gmock_p1, \ + p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) +#define GMOCK_INTERNAL_INIT_AND_4_VALUE_PARAMS(p0, p1, p2, p3)\ + (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ + p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ + p3(gmock_p3) +#define GMOCK_INTERNAL_INIT_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4)\ + (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ + p3##_type gmock_p3, p4##_type gmock_p4) : p0(gmock_p0), p1(gmock_p1), \ + p2(gmock_p2), p3(gmock_p3), p4(gmock_p4) +#define GMOCK_INTERNAL_INIT_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5)\ + (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ + p3##_type gmock_p3, p4##_type gmock_p4, \ + p5##_type gmock_p5) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ + p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) +#define GMOCK_INTERNAL_INIT_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6)\ + (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ + p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ + p6##_type gmock_p6) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ + p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6) +#define GMOCK_INTERNAL_INIT_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7)\ + (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ + p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ + p6##_type gmock_p6, p7##_type gmock_p7) : p0(gmock_p0), p1(gmock_p1), \ + p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \ + p7(gmock_p7) +#define GMOCK_INTERNAL_INIT_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ + p7, p8)\ + (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ + p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ + p6##_type gmock_p6, p7##_type gmock_p7, \ + p8##_type gmock_p8) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ + p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \ + p8(gmock_p8) +#define GMOCK_INTERNAL_INIT_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ + p7, p8, p9)\ + (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ + p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ + p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8, \ + p9##_type gmock_p9) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ + p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \ + p8(gmock_p8), p9(gmock_p9) + +// Declares the fields for storing the value parameters. +#define GMOCK_INTERNAL_DEFN_AND_0_VALUE_PARAMS() +#define GMOCK_INTERNAL_DEFN_AND_1_VALUE_PARAMS(p0) p0##_type p0; +#define GMOCK_INTERNAL_DEFN_AND_2_VALUE_PARAMS(p0, p1) p0##_type p0; \ + p1##_type p1; +#define GMOCK_INTERNAL_DEFN_AND_3_VALUE_PARAMS(p0, p1, p2) p0##_type p0; \ + p1##_type p1; p2##_type p2; +#define GMOCK_INTERNAL_DEFN_AND_4_VALUE_PARAMS(p0, p1, p2, p3) p0##_type p0; \ + p1##_type p1; p2##_type p2; p3##_type p3; +#define GMOCK_INTERNAL_DEFN_AND_5_VALUE_PARAMS(p0, p1, p2, p3, \ + p4) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; +#define GMOCK_INTERNAL_DEFN_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, \ + p5) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; \ + p5##_type p5; +#define GMOCK_INTERNAL_DEFN_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ + p6) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; \ + p5##_type p5; p6##_type p6; +#define GMOCK_INTERNAL_DEFN_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ + p7) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; \ + p5##_type p5; p6##_type p6; p7##_type p7; +#define GMOCK_INTERNAL_DEFN_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ + p7, p8) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; \ + p4##_type p4; p5##_type p5; p6##_type p6; p7##_type p7; p8##_type p8; +#define GMOCK_INTERNAL_DEFN_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ + p7, p8, p9) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; \ + p4##_type p4; p5##_type p5; p6##_type p6; p7##_type p7; p8##_type p8; \ + p9##_type p9; + +// Lists the value parameters. +#define GMOCK_INTERNAL_LIST_AND_0_VALUE_PARAMS() +#define GMOCK_INTERNAL_LIST_AND_1_VALUE_PARAMS(p0) p0 +#define GMOCK_INTERNAL_LIST_AND_2_VALUE_PARAMS(p0, p1) p0, p1 +#define GMOCK_INTERNAL_LIST_AND_3_VALUE_PARAMS(p0, p1, p2) p0, p1, p2 +#define GMOCK_INTERNAL_LIST_AND_4_VALUE_PARAMS(p0, p1, p2, p3) p0, p1, p2, p3 +#define GMOCK_INTERNAL_LIST_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) p0, p1, \ + p2, p3, p4 +#define GMOCK_INTERNAL_LIST_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) p0, \ + p1, p2, p3, p4, p5 +#define GMOCK_INTERNAL_LIST_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ + p6) p0, p1, p2, p3, p4, p5, p6 +#define GMOCK_INTERNAL_LIST_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ + p7) p0, p1, p2, p3, p4, p5, p6, p7 +#define GMOCK_INTERNAL_LIST_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ + p7, p8) p0, p1, p2, p3, p4, p5, p6, p7, p8 +#define GMOCK_INTERNAL_LIST_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ + p7, p8, p9) p0, p1, p2, p3, p4, p5, p6, p7, p8, p9 + +// Lists the value parameter types. +#define GMOCK_INTERNAL_LIST_TYPE_AND_0_VALUE_PARAMS() +#define GMOCK_INTERNAL_LIST_TYPE_AND_1_VALUE_PARAMS(p0) , p0##_type +#define GMOCK_INTERNAL_LIST_TYPE_AND_2_VALUE_PARAMS(p0, p1) , p0##_type, \ + p1##_type +#define GMOCK_INTERNAL_LIST_TYPE_AND_3_VALUE_PARAMS(p0, p1, p2) , p0##_type, \ + p1##_type, p2##_type +#define GMOCK_INTERNAL_LIST_TYPE_AND_4_VALUE_PARAMS(p0, p1, p2, p3) , \ + p0##_type, p1##_type, p2##_type, p3##_type +#define GMOCK_INTERNAL_LIST_TYPE_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) , \ + p0##_type, p1##_type, p2##_type, p3##_type, p4##_type +#define GMOCK_INTERNAL_LIST_TYPE_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) , \ + p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, p5##_type +#define GMOCK_INTERNAL_LIST_TYPE_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ + p6) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, p5##_type, \ + p6##_type +#define GMOCK_INTERNAL_LIST_TYPE_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ + p6, p7) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \ + p5##_type, p6##_type, p7##_type +#define GMOCK_INTERNAL_LIST_TYPE_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ + p6, p7, p8) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \ + p5##_type, p6##_type, p7##_type, p8##_type +#define GMOCK_INTERNAL_LIST_TYPE_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ + p6, p7, p8, p9) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \ + p5##_type, p6##_type, p7##_type, p8##_type, p9##_type + +// Declares the value parameters. +#define GMOCK_INTERNAL_DECL_AND_0_VALUE_PARAMS() +#define GMOCK_INTERNAL_DECL_AND_1_VALUE_PARAMS(p0) p0##_type p0 +#define GMOCK_INTERNAL_DECL_AND_2_VALUE_PARAMS(p0, p1) p0##_type p0, \ + p1##_type p1 +#define GMOCK_INTERNAL_DECL_AND_3_VALUE_PARAMS(p0, p1, p2) p0##_type p0, \ + p1##_type p1, p2##_type p2 +#define GMOCK_INTERNAL_DECL_AND_4_VALUE_PARAMS(p0, p1, p2, p3) p0##_type p0, \ + p1##_type p1, p2##_type p2, p3##_type p3 +#define GMOCK_INTERNAL_DECL_AND_5_VALUE_PARAMS(p0, p1, p2, p3, \ + p4) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4 +#define GMOCK_INTERNAL_DECL_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, \ + p5) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \ + p5##_type p5 +#define GMOCK_INTERNAL_DECL_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ + p6) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \ + p5##_type p5, p6##_type p6 +#define GMOCK_INTERNAL_DECL_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ + p7) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \ + p5##_type p5, p6##_type p6, p7##_type p7 +#define GMOCK_INTERNAL_DECL_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ + p7, p8) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \ + p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8 +#define GMOCK_INTERNAL_DECL_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ + p7, p8, p9) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \ + p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8, \ + p9##_type p9 + +// The suffix of the class template implementing the action template. +#define GMOCK_INTERNAL_COUNT_AND_0_VALUE_PARAMS() +#define GMOCK_INTERNAL_COUNT_AND_1_VALUE_PARAMS(p0) P +#define GMOCK_INTERNAL_COUNT_AND_2_VALUE_PARAMS(p0, p1) P2 +#define GMOCK_INTERNAL_COUNT_AND_3_VALUE_PARAMS(p0, p1, p2) P3 +#define GMOCK_INTERNAL_COUNT_AND_4_VALUE_PARAMS(p0, p1, p2, p3) P4 +#define GMOCK_INTERNAL_COUNT_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) P5 +#define GMOCK_INTERNAL_COUNT_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) P6 +#define GMOCK_INTERNAL_COUNT_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6) P7 +#define GMOCK_INTERNAL_COUNT_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ + p7) P8 +#define GMOCK_INTERNAL_COUNT_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ + p7, p8) P9 +#define GMOCK_INTERNAL_COUNT_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ + p7, p8, p9) P10 + +// The name of the class template implementing the action template. +#define GMOCK_ACTION_CLASS_(name, value_params)\ + GTEST_CONCAT_TOKEN_(name##Action, GMOCK_INTERNAL_COUNT_##value_params) + +#define ACTION_TEMPLATE(name, template_params, value_params)\ + template \ + class GMOCK_ACTION_CLASS_(name, value_params) {\ + public:\ + GMOCK_ACTION_CLASS_(name, value_params)\ + GMOCK_INTERNAL_INIT_##value_params {}\ + template \ + class gmock_Impl : public ::testing::ActionInterface {\ + public:\ + typedef F function_type;\ + typedef typename ::testing::internal::Function::Result return_type;\ + typedef typename ::testing::internal::Function::ArgumentTuple\ + args_type;\ + explicit gmock_Impl GMOCK_INTERNAL_INIT_##value_params {}\ + virtual return_type Perform(const args_type& args) {\ + return ::testing::internal::ActionHelper::\ + Perform(this, args);\ + }\ + template \ + return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ + arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ + arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ + arg9_type arg9) const;\ + GMOCK_INTERNAL_DEFN_##value_params\ + private:\ + GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ + };\ + template operator ::testing::Action() const {\ + return ::testing::Action(\ + new gmock_Impl(GMOCK_INTERNAL_LIST_##value_params));\ + }\ + GMOCK_INTERNAL_DEFN_##value_params\ + private:\ + GTEST_DISALLOW_ASSIGN_(GMOCK_ACTION_CLASS_(name, value_params));\ + };\ + template \ + inline GMOCK_ACTION_CLASS_(name, value_params)<\ + GMOCK_INTERNAL_LIST_##template_params\ + GMOCK_INTERNAL_LIST_TYPE_##value_params> name(\ + GMOCK_INTERNAL_DECL_##value_params) {\ + return GMOCK_ACTION_CLASS_(name, value_params)<\ + GMOCK_INTERNAL_LIST_##template_params\ + GMOCK_INTERNAL_LIST_TYPE_##value_params>(\ + GMOCK_INTERNAL_LIST_##value_params);\ + }\ + template \ + template \ + template \ + typename ::testing::internal::Function::Result\ + GMOCK_ACTION_CLASS_(name, value_params)<\ + GMOCK_INTERNAL_LIST_##template_params\ + GMOCK_INTERNAL_LIST_TYPE_##value_params>::gmock_Impl::\ + gmock_PerformImpl(\ + GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const + +#define ACTION(name)\ + class name##Action {\ + public:\ + name##Action() {}\ + template \ + class gmock_Impl : public ::testing::ActionInterface {\ + public:\ + typedef F function_type;\ + typedef typename ::testing::internal::Function::Result return_type;\ + typedef typename ::testing::internal::Function::ArgumentTuple\ + args_type;\ + gmock_Impl() {}\ + virtual return_type Perform(const args_type& args) {\ + return ::testing::internal::ActionHelper::\ + Perform(this, args);\ + }\ + template \ + return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ + arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ + arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ + arg9_type arg9) const;\ + private:\ + GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ + };\ + template operator ::testing::Action() const {\ + return ::testing::Action(new gmock_Impl());\ + }\ + private:\ + GTEST_DISALLOW_ASSIGN_(name##Action);\ + };\ + inline name##Action name() {\ + return name##Action();\ + }\ + template \ + template \ + typename ::testing::internal::Function::Result\ + name##Action::gmock_Impl::gmock_PerformImpl(\ + GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const + +#define ACTION_P(name, p0)\ + template \ + class name##ActionP {\ + public:\ + name##ActionP(p0##_type gmock_p0) : p0(gmock_p0) {}\ + template \ + class gmock_Impl : public ::testing::ActionInterface {\ + public:\ + typedef F function_type;\ + typedef typename ::testing::internal::Function::Result return_type;\ + typedef typename ::testing::internal::Function::ArgumentTuple\ + args_type;\ + explicit gmock_Impl(p0##_type gmock_p0) : p0(gmock_p0) {}\ + virtual return_type Perform(const args_type& args) {\ + return ::testing::internal::ActionHelper::\ + Perform(this, args);\ + }\ + template \ + return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ + arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ + arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ + arg9_type arg9) const;\ + p0##_type p0;\ + private:\ + GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ + };\ + template operator ::testing::Action() const {\ + return ::testing::Action(new gmock_Impl(p0));\ + }\ + p0##_type p0;\ + private:\ + GTEST_DISALLOW_ASSIGN_(name##ActionP);\ + };\ + template \ + inline name##ActionP name(p0##_type p0) {\ + return name##ActionP(p0);\ + }\ + template \ + template \ + template \ + typename ::testing::internal::Function::Result\ + name##ActionP::gmock_Impl::gmock_PerformImpl(\ + GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const + +#define ACTION_P2(name, p0, p1)\ + template \ + class name##ActionP2 {\ + public:\ + name##ActionP2(p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), \ + p1(gmock_p1) {}\ + template \ + class gmock_Impl : public ::testing::ActionInterface {\ + public:\ + typedef F function_type;\ + typedef typename ::testing::internal::Function::Result return_type;\ + typedef typename ::testing::internal::Function::ArgumentTuple\ + args_type;\ + gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), \ + p1(gmock_p1) {}\ + virtual return_type Perform(const args_type& args) {\ + return ::testing::internal::ActionHelper::\ + Perform(this, args);\ + }\ + template \ + return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ + arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ + arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ + arg9_type arg9) const;\ + p0##_type p0;\ + p1##_type p1;\ + private:\ + GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ + };\ + template operator ::testing::Action() const {\ + return ::testing::Action(new gmock_Impl(p0, p1));\ + }\ + p0##_type p0;\ + p1##_type p1;\ + private:\ + GTEST_DISALLOW_ASSIGN_(name##ActionP2);\ + };\ + template \ + inline name##ActionP2 name(p0##_type p0, \ + p1##_type p1) {\ + return name##ActionP2(p0, p1);\ + }\ + template \ + template \ + template \ + typename ::testing::internal::Function::Result\ + name##ActionP2::gmock_Impl::gmock_PerformImpl(\ + GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const + +#define ACTION_P3(name, p0, p1, p2)\ + template \ + class name##ActionP3 {\ + public:\ + name##ActionP3(p0##_type gmock_p0, p1##_type gmock_p1, \ + p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {}\ + template \ + class gmock_Impl : public ::testing::ActionInterface {\ + public:\ + typedef F function_type;\ + typedef typename ::testing::internal::Function::Result return_type;\ + typedef typename ::testing::internal::Function::ArgumentTuple\ + args_type;\ + gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, \ + p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {}\ + virtual return_type Perform(const args_type& args) {\ + return ::testing::internal::ActionHelper::\ + Perform(this, args);\ + }\ + template \ + return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ + arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ + arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ + arg9_type arg9) const;\ + p0##_type p0;\ + p1##_type p1;\ + p2##_type p2;\ + private:\ + GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ + };\ + template operator ::testing::Action() const {\ + return ::testing::Action(new gmock_Impl(p0, p1, p2));\ + }\ + p0##_type p0;\ + p1##_type p1;\ + p2##_type p2;\ + private:\ + GTEST_DISALLOW_ASSIGN_(name##ActionP3);\ + };\ + template \ + inline name##ActionP3 name(p0##_type p0, \ + p1##_type p1, p2##_type p2) {\ + return name##ActionP3(p0, p1, p2);\ + }\ + template \ + template \ + template \ + typename ::testing::internal::Function::Result\ + name##ActionP3::gmock_Impl::gmock_PerformImpl(\ + GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const + +#define ACTION_P4(name, p0, p1, p2, p3)\ + template \ + class name##ActionP4 {\ + public:\ + name##ActionP4(p0##_type gmock_p0, p1##_type gmock_p1, \ + p2##_type gmock_p2, p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), \ + p2(gmock_p2), p3(gmock_p3) {}\ + template \ + class gmock_Impl : public ::testing::ActionInterface {\ + public:\ + typedef F function_type;\ + typedef typename ::testing::internal::Function::Result return_type;\ + typedef typename ::testing::internal::Function::ArgumentTuple\ + args_type;\ + gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ + p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ + p3(gmock_p3) {}\ + virtual return_type Perform(const args_type& args) {\ + return ::testing::internal::ActionHelper::\ + Perform(this, args);\ + }\ + template \ + return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ + arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ + arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ + arg9_type arg9) const;\ + p0##_type p0;\ + p1##_type p1;\ + p2##_type p2;\ + p3##_type p3;\ + private:\ + GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ + };\ + template operator ::testing::Action() const {\ + return ::testing::Action(new gmock_Impl(p0, p1, p2, p3));\ + }\ + p0##_type p0;\ + p1##_type p1;\ + p2##_type p2;\ + p3##_type p3;\ + private:\ + GTEST_DISALLOW_ASSIGN_(name##ActionP4);\ + };\ + template \ + inline name##ActionP4 name(p0##_type p0, p1##_type p1, p2##_type p2, \ + p3##_type p3) {\ + return name##ActionP4(p0, p1, \ + p2, p3);\ + }\ + template \ + template \ + template \ + typename ::testing::internal::Function::Result\ + name##ActionP4::gmock_Impl::gmock_PerformImpl(\ + GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const + +#define ACTION_P5(name, p0, p1, p2, p3, p4)\ + template \ + class name##ActionP5 {\ + public:\ + name##ActionP5(p0##_type gmock_p0, p1##_type gmock_p1, \ + p2##_type gmock_p2, p3##_type gmock_p3, \ + p4##_type gmock_p4) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ + p3(gmock_p3), p4(gmock_p4) {}\ + template \ + class gmock_Impl : public ::testing::ActionInterface {\ + public:\ + typedef F function_type;\ + typedef typename ::testing::internal::Function::Result return_type;\ + typedef typename ::testing::internal::Function::ArgumentTuple\ + args_type;\ + gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ + p3##_type gmock_p3, p4##_type gmock_p4) : p0(gmock_p0), \ + p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), p4(gmock_p4) {}\ + virtual return_type Perform(const args_type& args) {\ + return ::testing::internal::ActionHelper::\ + Perform(this, args);\ + }\ + template \ + return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ + arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ + arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ + arg9_type arg9) const;\ + p0##_type p0;\ + p1##_type p1;\ + p2##_type p2;\ + p3##_type p3;\ + p4##_type p4;\ + private:\ + GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ + };\ + template operator ::testing::Action() const {\ + return ::testing::Action(new gmock_Impl(p0, p1, p2, p3, p4));\ + }\ + p0##_type p0;\ + p1##_type p1;\ + p2##_type p2;\ + p3##_type p3;\ + p4##_type p4;\ + private:\ + GTEST_DISALLOW_ASSIGN_(name##ActionP5);\ + };\ + template \ + inline name##ActionP5 name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \ + p4##_type p4) {\ + return name##ActionP5(p0, p1, p2, p3, p4);\ + }\ + template \ + template \ + template \ + typename ::testing::internal::Function::Result\ + name##ActionP5::gmock_Impl::gmock_PerformImpl(\ + GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const + +#define ACTION_P6(name, p0, p1, p2, p3, p4, p5)\ + template \ + class name##ActionP6 {\ + public:\ + name##ActionP6(p0##_type gmock_p0, p1##_type gmock_p1, \ + p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \ + p5##_type gmock_p5) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ + p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) {}\ + template \ + class gmock_Impl : public ::testing::ActionInterface {\ + public:\ + typedef F function_type;\ + typedef typename ::testing::internal::Function::Result return_type;\ + typedef typename ::testing::internal::Function::ArgumentTuple\ + args_type;\ + gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ + p3##_type gmock_p3, p4##_type gmock_p4, \ + p5##_type gmock_p5) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ + p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) {}\ + virtual return_type Perform(const args_type& args) {\ + return ::testing::internal::ActionHelper::\ + Perform(this, args);\ + }\ + template \ + return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ + arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ + arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ + arg9_type arg9) const;\ + p0##_type p0;\ + p1##_type p1;\ + p2##_type p2;\ + p3##_type p3;\ + p4##_type p4;\ + p5##_type p5;\ + private:\ + GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ + };\ + template operator ::testing::Action() const {\ + return ::testing::Action(new gmock_Impl(p0, p1, p2, p3, p4, p5));\ + }\ + p0##_type p0;\ + p1##_type p1;\ + p2##_type p2;\ + p3##_type p3;\ + p4##_type p4;\ + p5##_type p5;\ + private:\ + GTEST_DISALLOW_ASSIGN_(name##ActionP6);\ + };\ + template \ + inline name##ActionP6 name(p0##_type p0, p1##_type p1, p2##_type p2, \ + p3##_type p3, p4##_type p4, p5##_type p5) {\ + return name##ActionP6(p0, p1, p2, p3, p4, p5);\ + }\ + template \ + template \ + template \ + typename ::testing::internal::Function::Result\ + name##ActionP6::gmock_Impl::gmock_PerformImpl(\ + GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const + +#define ACTION_P7(name, p0, p1, p2, p3, p4, p5, p6)\ + template \ + class name##ActionP7 {\ + public:\ + name##ActionP7(p0##_type gmock_p0, p1##_type gmock_p1, \ + p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \ + p5##_type gmock_p5, p6##_type gmock_p6) : p0(gmock_p0), p1(gmock_p1), \ + p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), \ + p6(gmock_p6) {}\ + template \ + class gmock_Impl : public ::testing::ActionInterface {\ + public:\ + typedef F function_type;\ + typedef typename ::testing::internal::Function::Result return_type;\ + typedef typename ::testing::internal::Function::ArgumentTuple\ + args_type;\ + gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ + p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ + p6##_type gmock_p6) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ + p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6) {}\ + virtual return_type Perform(const args_type& args) {\ + return ::testing::internal::ActionHelper::\ + Perform(this, args);\ + }\ + template \ + return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ + arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ + arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ + arg9_type arg9) const;\ + p0##_type p0;\ + p1##_type p1;\ + p2##_type p2;\ + p3##_type p3;\ + p4##_type p4;\ + p5##_type p5;\ + p6##_type p6;\ + private:\ + GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ + };\ + template operator ::testing::Action() const {\ + return ::testing::Action(new gmock_Impl(p0, p1, p2, p3, p4, p5, \ + p6));\ + }\ + p0##_type p0;\ + p1##_type p1;\ + p2##_type p2;\ + p3##_type p3;\ + p4##_type p4;\ + p5##_type p5;\ + p6##_type p6;\ + private:\ + GTEST_DISALLOW_ASSIGN_(name##ActionP7);\ + };\ + template \ + inline name##ActionP7 name(p0##_type p0, p1##_type p1, \ + p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \ + p6##_type p6) {\ + return name##ActionP7(p0, p1, p2, p3, p4, p5, p6);\ + }\ + template \ + template \ + template \ + typename ::testing::internal::Function::Result\ + name##ActionP7::gmock_Impl::gmock_PerformImpl(\ + GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const + +#define ACTION_P8(name, p0, p1, p2, p3, p4, p5, p6, p7)\ + template \ + class name##ActionP8 {\ + public:\ + name##ActionP8(p0##_type gmock_p0, p1##_type gmock_p1, \ + p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \ + p5##_type gmock_p5, p6##_type gmock_p6, \ + p7##_type gmock_p7) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ + p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \ + p7(gmock_p7) {}\ + template \ + class gmock_Impl : public ::testing::ActionInterface {\ + public:\ + typedef F function_type;\ + typedef typename ::testing::internal::Function::Result return_type;\ + typedef typename ::testing::internal::Function::ArgumentTuple\ + args_type;\ + gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ + p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ + p6##_type gmock_p6, p7##_type gmock_p7) : p0(gmock_p0), \ + p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), \ + p5(gmock_p5), p6(gmock_p6), p7(gmock_p7) {}\ + virtual return_type Perform(const args_type& args) {\ + return ::testing::internal::ActionHelper::\ + Perform(this, args);\ + }\ + template \ + return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ + arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ + arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ + arg9_type arg9) const;\ + p0##_type p0;\ + p1##_type p1;\ + p2##_type p2;\ + p3##_type p3;\ + p4##_type p4;\ + p5##_type p5;\ + p6##_type p6;\ + p7##_type p7;\ + private:\ + GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ + };\ + template operator ::testing::Action() const {\ + return ::testing::Action(new gmock_Impl(p0, p1, p2, p3, p4, p5, \ + p6, p7));\ + }\ + p0##_type p0;\ + p1##_type p1;\ + p2##_type p2;\ + p3##_type p3;\ + p4##_type p4;\ + p5##_type p5;\ + p6##_type p6;\ + p7##_type p7;\ + private:\ + GTEST_DISALLOW_ASSIGN_(name##ActionP8);\ + };\ + template \ + inline name##ActionP8 name(p0##_type p0, \ + p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \ + p6##_type p6, p7##_type p7) {\ + return name##ActionP8(p0, p1, p2, p3, p4, p5, \ + p6, p7);\ + }\ + template \ + template \ + template \ + typename ::testing::internal::Function::Result\ + name##ActionP8::gmock_Impl::gmock_PerformImpl(\ + GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const + +#define ACTION_P9(name, p0, p1, p2, p3, p4, p5, p6, p7, p8)\ + template \ + class name##ActionP9 {\ + public:\ + name##ActionP9(p0##_type gmock_p0, p1##_type gmock_p1, \ + p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \ + p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \ + p8##_type gmock_p8) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ + p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \ + p8(gmock_p8) {}\ + template \ + class gmock_Impl : public ::testing::ActionInterface {\ + public:\ + typedef F function_type;\ + typedef typename ::testing::internal::Function::Result return_type;\ + typedef typename ::testing::internal::Function::ArgumentTuple\ + args_type;\ + gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ + p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ + p6##_type gmock_p6, p7##_type gmock_p7, \ + p8##_type gmock_p8) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ + p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \ + p7(gmock_p7), p8(gmock_p8) {}\ + virtual return_type Perform(const args_type& args) {\ + return ::testing::internal::ActionHelper::\ + Perform(this, args);\ + }\ + template \ + return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ + arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ + arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ + arg9_type arg9) const;\ + p0##_type p0;\ + p1##_type p1;\ + p2##_type p2;\ + p3##_type p3;\ + p4##_type p4;\ + p5##_type p5;\ + p6##_type p6;\ + p7##_type p7;\ + p8##_type p8;\ + private:\ + GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ + };\ + template operator ::testing::Action() const {\ + return ::testing::Action(new gmock_Impl(p0, p1, p2, p3, p4, p5, \ + p6, p7, p8));\ + }\ + p0##_type p0;\ + p1##_type p1;\ + p2##_type p2;\ + p3##_type p3;\ + p4##_type p4;\ + p5##_type p5;\ + p6##_type p6;\ + p7##_type p7;\ + p8##_type p8;\ + private:\ + GTEST_DISALLOW_ASSIGN_(name##ActionP9);\ + };\ + template \ + inline name##ActionP9 name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \ + p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, \ + p8##_type p8) {\ + return name##ActionP9(p0, p1, p2, \ + p3, p4, p5, p6, p7, p8);\ + }\ + template \ + template \ + template \ + typename ::testing::internal::Function::Result\ + name##ActionP9::gmock_Impl::gmock_PerformImpl(\ + GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const + +#define ACTION_P10(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)\ + template \ + class name##ActionP10 {\ + public:\ + name##ActionP10(p0##_type gmock_p0, p1##_type gmock_p1, \ + p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \ + p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \ + p8##_type gmock_p8, p9##_type gmock_p9) : p0(gmock_p0), p1(gmock_p1), \ + p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \ + p7(gmock_p7), p8(gmock_p8), p9(gmock_p9) {}\ + template \ + class gmock_Impl : public ::testing::ActionInterface {\ + public:\ + typedef F function_type;\ + typedef typename ::testing::internal::Function::Result return_type;\ + typedef typename ::testing::internal::Function::ArgumentTuple\ + args_type;\ + gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ + p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ + p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8, \ + p9##_type gmock_p9) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ + p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \ + p7(gmock_p7), p8(gmock_p8), p9(gmock_p9) {}\ + virtual return_type Perform(const args_type& args) {\ + return ::testing::internal::ActionHelper::\ + Perform(this, args);\ + }\ + template \ + return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ + arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ + arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ + arg9_type arg9) const;\ + p0##_type p0;\ + p1##_type p1;\ + p2##_type p2;\ + p3##_type p3;\ + p4##_type p4;\ + p5##_type p5;\ + p6##_type p6;\ + p7##_type p7;\ + p8##_type p8;\ + p9##_type p9;\ + private:\ + GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ + };\ + template operator ::testing::Action() const {\ + return ::testing::Action(new gmock_Impl(p0, p1, p2, p3, p4, p5, \ + p6, p7, p8, p9));\ + }\ + p0##_type p0;\ + p1##_type p1;\ + p2##_type p2;\ + p3##_type p3;\ + p4##_type p4;\ + p5##_type p5;\ + p6##_type p6;\ + p7##_type p7;\ + p8##_type p8;\ + p9##_type p9;\ + private:\ + GTEST_DISALLOW_ASSIGN_(name##ActionP10);\ + };\ + template \ + inline name##ActionP10 name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \ + p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8, \ + p9##_type p9) {\ + return name##ActionP10(p0, \ + p1, p2, p3, p4, p5, p6, p7, p8, p9);\ + }\ + template \ + template \ + template \ + typename ::testing::internal::Function::Result\ + name##ActionP10::gmock_Impl::gmock_PerformImpl(\ + GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const + +namespace testing { + +// The ACTION*() macros trigger warning C4100 (unreferenced formal +// parameter) in MSVC with -W4. Unfortunately they cannot be fixed in +// the macro definition, as the warnings are generated when the macro +// is expanded and macro expansion cannot contain #pragma. Therefore +// we suppress them here. +#ifdef _MSC_VER +# pragma warning(push) +# pragma warning(disable:4100) +#endif + +// Various overloads for InvokeArgument(). +// +// The InvokeArgument(a1, a2, ..., a_k) action invokes the N-th +// (0-based) argument, which must be a k-ary callable, of the mock +// function, with arguments a1, a2, ..., a_k. +// +// Notes: +// +// 1. The arguments are passed by value by default. If you need to +// pass an argument by reference, wrap it inside ByRef(). For +// example, +// +// InvokeArgument<1>(5, string("Hello"), ByRef(foo)) +// +// passes 5 and string("Hello") by value, and passes foo by +// reference. +// +// 2. If the callable takes an argument by reference but ByRef() is +// not used, it will receive the reference to a copy of the value, +// instead of the original value. For example, when the 0-th +// argument of the mock function takes a const string&, the action +// +// InvokeArgument<0>(string("Hello")) +// +// makes a copy of the temporary string("Hello") object and passes a +// reference of the copy, instead of the original temporary object, +// to the callable. This makes it easy for a user to define an +// InvokeArgument action from temporary values and have it performed +// later. + +ACTION_TEMPLATE(InvokeArgument, + HAS_1_TEMPLATE_PARAMS(int, k), + AND_0_VALUE_PARAMS()) { + return internal::CallableHelper::Call( + ::std::tr1::get(args)); +} + +ACTION_TEMPLATE(InvokeArgument, + HAS_1_TEMPLATE_PARAMS(int, k), + AND_1_VALUE_PARAMS(p0)) { + return internal::CallableHelper::Call( + ::std::tr1::get(args), p0); +} + +ACTION_TEMPLATE(InvokeArgument, + HAS_1_TEMPLATE_PARAMS(int, k), + AND_2_VALUE_PARAMS(p0, p1)) { + return internal::CallableHelper::Call( + ::std::tr1::get(args), p0, p1); +} + +ACTION_TEMPLATE(InvokeArgument, + HAS_1_TEMPLATE_PARAMS(int, k), + AND_3_VALUE_PARAMS(p0, p1, p2)) { + return internal::CallableHelper::Call( + ::std::tr1::get(args), p0, p1, p2); +} + +ACTION_TEMPLATE(InvokeArgument, + HAS_1_TEMPLATE_PARAMS(int, k), + AND_4_VALUE_PARAMS(p0, p1, p2, p3)) { + return internal::CallableHelper::Call( + ::std::tr1::get(args), p0, p1, p2, p3); +} + +ACTION_TEMPLATE(InvokeArgument, + HAS_1_TEMPLATE_PARAMS(int, k), + AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4)) { + return internal::CallableHelper::Call( + ::std::tr1::get(args), p0, p1, p2, p3, p4); +} + +ACTION_TEMPLATE(InvokeArgument, + HAS_1_TEMPLATE_PARAMS(int, k), + AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5)) { + return internal::CallableHelper::Call( + ::std::tr1::get(args), p0, p1, p2, p3, p4, p5); +} + +ACTION_TEMPLATE(InvokeArgument, + HAS_1_TEMPLATE_PARAMS(int, k), + AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6)) { + return internal::CallableHelper::Call( + ::std::tr1::get(args), p0, p1, p2, p3, p4, p5, p6); +} + +ACTION_TEMPLATE(InvokeArgument, + HAS_1_TEMPLATE_PARAMS(int, k), + AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7)) { + return internal::CallableHelper::Call( + ::std::tr1::get(args), p0, p1, p2, p3, p4, p5, p6, p7); +} + +ACTION_TEMPLATE(InvokeArgument, + HAS_1_TEMPLATE_PARAMS(int, k), + AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8)) { + return internal::CallableHelper::Call( + ::std::tr1::get(args), p0, p1, p2, p3, p4, p5, p6, p7, p8); +} + +ACTION_TEMPLATE(InvokeArgument, + HAS_1_TEMPLATE_PARAMS(int, k), + AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)) { + return internal::CallableHelper::Call( + ::std::tr1::get(args), p0, p1, p2, p3, p4, p5, p6, p7, p8, p9); +} + +// Various overloads for ReturnNew(). +// +// The ReturnNew(a1, a2, ..., a_k) action returns a pointer to a new +// instance of type T, constructed on the heap with constructor arguments +// a1, a2, ..., and a_k. The caller assumes ownership of the returned value. +ACTION_TEMPLATE(ReturnNew, + HAS_1_TEMPLATE_PARAMS(typename, T), + AND_0_VALUE_PARAMS()) { + return new T(); +} + +ACTION_TEMPLATE(ReturnNew, + HAS_1_TEMPLATE_PARAMS(typename, T), + AND_1_VALUE_PARAMS(p0)) { + return new T(p0); +} + +ACTION_TEMPLATE(ReturnNew, + HAS_1_TEMPLATE_PARAMS(typename, T), + AND_2_VALUE_PARAMS(p0, p1)) { + return new T(p0, p1); +} + +ACTION_TEMPLATE(ReturnNew, + HAS_1_TEMPLATE_PARAMS(typename, T), + AND_3_VALUE_PARAMS(p0, p1, p2)) { + return new T(p0, p1, p2); +} + +ACTION_TEMPLATE(ReturnNew, + HAS_1_TEMPLATE_PARAMS(typename, T), + AND_4_VALUE_PARAMS(p0, p1, p2, p3)) { + return new T(p0, p1, p2, p3); +} + +ACTION_TEMPLATE(ReturnNew, + HAS_1_TEMPLATE_PARAMS(typename, T), + AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4)) { + return new T(p0, p1, p2, p3, p4); +} + +ACTION_TEMPLATE(ReturnNew, + HAS_1_TEMPLATE_PARAMS(typename, T), + AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5)) { + return new T(p0, p1, p2, p3, p4, p5); +} + +ACTION_TEMPLATE(ReturnNew, + HAS_1_TEMPLATE_PARAMS(typename, T), + AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6)) { + return new T(p0, p1, p2, p3, p4, p5, p6); +} + +ACTION_TEMPLATE(ReturnNew, + HAS_1_TEMPLATE_PARAMS(typename, T), + AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7)) { + return new T(p0, p1, p2, p3, p4, p5, p6, p7); +} + +ACTION_TEMPLATE(ReturnNew, + HAS_1_TEMPLATE_PARAMS(typename, T), + AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8)) { + return new T(p0, p1, p2, p3, p4, p5, p6, p7, p8); +} + +ACTION_TEMPLATE(ReturnNew, + HAS_1_TEMPLATE_PARAMS(typename, T), + AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)) { + return new T(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9); +} + +#ifdef _MSC_VER +# pragma warning(pop) +#endif + +} // namespace testing + +#endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_ diff --git a/mbelib-wasm/mbelib/test/gmock/include/gmock/gmock-generated-actions.h.pump b/mbelib-wasm/mbelib/test/gmock/include/gmock/gmock-generated-actions.h.pump new file mode 100644 index 0000000..8e2b573 --- /dev/null +++ b/mbelib-wasm/mbelib/test/gmock/include/gmock/gmock-generated-actions.h.pump @@ -0,0 +1,821 @@ +$$ -*- mode: c++; -*- +$$ This is a Pump source file. Please use Pump to convert it to +$$ gmock-generated-actions.h. +$$ +$var n = 10 $$ The maximum arity we support. +$$}} This meta comment fixes auto-indentation in editors. +// Copyright 2007, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Author: wan@google.com (Zhanyong Wan) + +// Google Mock - a framework for writing C++ mock classes. +// +// This file implements some commonly used variadic actions. + +#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_ +#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_ + +#include "gmock/gmock-actions.h" +#include "gmock/internal/gmock-port.h" + +namespace testing { +namespace internal { + +// InvokeHelper knows how to unpack an N-tuple and invoke an N-ary +// function or method with the unpacked values, where F is a function +// type that takes N arguments. +template +class InvokeHelper; + + +$range i 0..n +$for i [[ +$range j 1..i +$var types = [[$for j [[, typename A$j]]]] +$var as = [[$for j, [[A$j]]]] +$var args = [[$if i==0 [[]] $else [[ args]]]] +$var import = [[$if i==0 [[]] $else [[ + using ::std::tr1::get; + +]]]] +$var gets = [[$for j, [[get<$(j - 1)>(args)]]]] +template +class InvokeHelper > { + public: + template + static R Invoke(Function function, const ::std::tr1::tuple<$as>&$args) { +$import return function($gets); + } + + template + static R InvokeMethod(Class* obj_ptr, + MethodPtr method_ptr, + const ::std::tr1::tuple<$as>&$args) { +$import return (obj_ptr->*method_ptr)($gets); + } +}; + + +]] +// CallableHelper has static methods for invoking "callables", +// i.e. function pointers and functors. It uses overloading to +// provide a uniform interface for invoking different kinds of +// callables. In particular, you can use: +// +// CallableHelper::Call(callable, a1, a2, ..., an) +// +// to invoke an n-ary callable, where R is its return type. If an +// argument, say a2, needs to be passed by reference, you should write +// ByRef(a2) instead of a2 in the above expression. +template +class CallableHelper { + public: + // Calls a nullary callable. + template + static R Call(Function function) { return function(); } + + // Calls a unary callable. + + // We deliberately pass a1 by value instead of const reference here + // in case it is a C-string literal. If we had declared the + // parameter as 'const A1& a1' and write Call(function, "Hi"), the + // compiler would've thought A1 is 'char[3]', which causes trouble + // when you need to copy a value of type A1. By declaring the + // parameter as 'A1 a1', the compiler will correctly infer that A1 + // is 'const char*' when it sees Call(function, "Hi"). + // + // Since this function is defined inline, the compiler can get rid + // of the copying of the arguments. Therefore the performance won't + // be hurt. + template + static R Call(Function function, A1 a1) { return function(a1); } + +$range i 2..n +$for i +[[ +$var arity = [[$if i==2 [[binary]] $elif i==3 [[ternary]] $else [[$i-ary]]]] + + // Calls a $arity callable. + +$range j 1..i +$var typename_As = [[$for j, [[typename A$j]]]] +$var Aas = [[$for j, [[A$j a$j]]]] +$var as = [[$for j, [[a$j]]]] +$var typename_Ts = [[$for j, [[typename T$j]]]] +$var Ts = [[$for j, [[T$j]]]] + template + static R Call(Function function, $Aas) { + return function($as); + } + +]] +}; // class CallableHelper + +// An INTERNAL macro for extracting the type of a tuple field. It's +// subject to change without notice - DO NOT USE IN USER CODE! +#define GMOCK_FIELD_(Tuple, N) \ + typename ::std::tr1::tuple_element::type + +$range i 1..n + +// SelectArgs::type is the +// type of an n-ary function whose i-th (1-based) argument type is the +// k{i}-th (0-based) field of ArgumentTuple, which must be a tuple +// type, and whose return type is Result. For example, +// SelectArgs, 0, 3>::type +// is int(bool, long). +// +// SelectArgs::Select(args) +// returns the selected fields (k1, k2, ..., k_n) of args as a tuple. +// For example, +// SelectArgs, 2, 0>::Select( +// ::std::tr1::make_tuple(true, 'a', 2.5)) +// returns ::std::tr1::tuple (2.5, true). +// +// The numbers in list k1, k2, ..., k_n must be >= 0, where n can be +// in the range [0, $n]. Duplicates are allowed and they don't have +// to be in an ascending or descending order. + +template +class SelectArgs { + public: + typedef Result type($for i, [[GMOCK_FIELD_(ArgumentTuple, k$i)]]); + typedef typename Function::ArgumentTuple SelectedArgs; + static SelectedArgs Select(const ArgumentTuple& args) { + using ::std::tr1::get; + return SelectedArgs($for i, [[get(args)]]); + } +}; + + +$for i [[ +$range j 1..n +$range j1 1..i-1 +template +class SelectArgs { + public: + typedef Result type($for j1, [[GMOCK_FIELD_(ArgumentTuple, k$j1)]]); + typedef typename Function::ArgumentTuple SelectedArgs; + static SelectedArgs Select(const ArgumentTuple& [[]] +$if i == 1 [[/* args */]] $else [[args]]) { + using ::std::tr1::get; + return SelectedArgs($for j1, [[get(args)]]); + } +}; + + +]] +#undef GMOCK_FIELD_ + +$var ks = [[$for i, [[k$i]]]] + +// Implements the WithArgs action. +template +class WithArgsAction { + public: + explicit WithArgsAction(const InnerAction& action) : action_(action) {} + + template + operator Action() const { return MakeAction(new Impl(action_)); } + + private: + template + class Impl : public ActionInterface { + public: + typedef typename Function::Result Result; + typedef typename Function::ArgumentTuple ArgumentTuple; + + explicit Impl(const InnerAction& action) : action_(action) {} + + virtual Result Perform(const ArgumentTuple& args) { + return action_.Perform(SelectArgs::Select(args)); + } + + private: + typedef typename SelectArgs::type InnerFunctionType; + + Action action_; + }; + + const InnerAction action_; + + GTEST_DISALLOW_ASSIGN_(WithArgsAction); +}; + +// A macro from the ACTION* family (defined later in this file) +// defines an action that can be used in a mock function. Typically, +// these actions only care about a subset of the arguments of the mock +// function. For example, if such an action only uses the second +// argument, it can be used in any mock function that takes >= 2 +// arguments where the type of the second argument is compatible. +// +// Therefore, the action implementation must be prepared to take more +// arguments than it needs. The ExcessiveArg type is used to +// represent those excessive arguments. In order to keep the compiler +// error messages tractable, we define it in the testing namespace +// instead of testing::internal. However, this is an INTERNAL TYPE +// and subject to change without notice, so a user MUST NOT USE THIS +// TYPE DIRECTLY. +struct ExcessiveArg {}; + +// A helper class needed for implementing the ACTION* macros. +template +class ActionHelper { + public: +$range i 0..n +$for i + +[[ +$var template = [[$if i==0 [[]] $else [[ +$range j 0..i-1 + template <$for j, [[typename A$j]]> +]]]] +$range j 0..i-1 +$var As = [[$for j, [[A$j]]]] +$var as = [[$for j, [[get<$j>(args)]]]] +$range k 1..n-i +$var eas = [[$for k, [[ExcessiveArg()]]]] +$var arg_list = [[$if (i==0) | (i==n) [[$as$eas]] $else [[$as, $eas]]]] +$template + static Result Perform(Impl* impl, const ::std::tr1::tuple<$As>& args) { + using ::std::tr1::get; + return impl->template gmock_PerformImpl<$As>(args, $arg_list); + } + +]] +}; + +} // namespace internal + +// Various overloads for Invoke(). + +// WithArgs(an_action) creates an action that passes +// the selected arguments of the mock function to an_action and +// performs it. It serves as an adaptor between actions with +// different argument lists. C++ doesn't support default arguments for +// function templates, so we have to overload it. + +$range i 1..n +$for i [[ +$range j 1..i +template <$for j [[int k$j, ]]typename InnerAction> +inline internal::WithArgsAction +WithArgs(const InnerAction& action) { + return internal::WithArgsAction(action); +} + + +]] +// Creates an action that does actions a1, a2, ..., sequentially in +// each invocation. +$range i 2..n +$for i [[ +$range j 2..i +$var types = [[$for j, [[typename Action$j]]]] +$var Aas = [[$for j [[, Action$j a$j]]]] + +template +$range k 1..i-1 + +inline $for k [[internal::DoBothAction]] + +DoAll(Action1 a1$Aas) { +$if i==2 [[ + + return internal::DoBothAction(a1, a2); +]] $else [[ +$range j2 2..i + + return DoAll(a1, DoAll($for j2, [[a$j2]])); +]] + +} + +]] + +} // namespace testing + +// The ACTION* family of macros can be used in a namespace scope to +// define custom actions easily. The syntax: +// +// ACTION(name) { statements; } +// +// will define an action with the given name that executes the +// statements. The value returned by the statements will be used as +// the return value of the action. Inside the statements, you can +// refer to the K-th (0-based) argument of the mock function by +// 'argK', and refer to its type by 'argK_type'. For example: +// +// ACTION(IncrementArg1) { +// arg1_type temp = arg1; +// return ++(*temp); +// } +// +// allows you to write +// +// ...WillOnce(IncrementArg1()); +// +// You can also refer to the entire argument tuple and its type by +// 'args' and 'args_type', and refer to the mock function type and its +// return type by 'function_type' and 'return_type'. +// +// Note that you don't need to specify the types of the mock function +// arguments. However rest assured that your code is still type-safe: +// you'll get a compiler error if *arg1 doesn't support the ++ +// operator, or if the type of ++(*arg1) isn't compatible with the +// mock function's return type, for example. +// +// Sometimes you'll want to parameterize the action. For that you can use +// another macro: +// +// ACTION_P(name, param_name) { statements; } +// +// For example: +// +// ACTION_P(Add, n) { return arg0 + n; } +// +// will allow you to write: +// +// ...WillOnce(Add(5)); +// +// Note that you don't need to provide the type of the parameter +// either. If you need to reference the type of a parameter named +// 'foo', you can write 'foo_type'. For example, in the body of +// ACTION_P(Add, n) above, you can write 'n_type' to refer to the type +// of 'n'. +// +// We also provide ACTION_P2, ACTION_P3, ..., up to ACTION_P$n to support +// multi-parameter actions. +// +// For the purpose of typing, you can view +// +// ACTION_Pk(Foo, p1, ..., pk) { ... } +// +// as shorthand for +// +// template +// FooActionPk Foo(p1_type p1, ..., pk_type pk) { ... } +// +// In particular, you can provide the template type arguments +// explicitly when invoking Foo(), as in Foo(5, false); +// although usually you can rely on the compiler to infer the types +// for you automatically. You can assign the result of expression +// Foo(p1, ..., pk) to a variable of type FooActionPk. This can be useful when composing actions. +// +// You can also overload actions with different numbers of parameters: +// +// ACTION_P(Plus, a) { ... } +// ACTION_P2(Plus, a, b) { ... } +// +// While it's tempting to always use the ACTION* macros when defining +// a new action, you should also consider implementing ActionInterface +// or using MakePolymorphicAction() instead, especially if you need to +// use the action a lot. While these approaches require more work, +// they give you more control on the types of the mock function +// arguments and the action parameters, which in general leads to +// better compiler error messages that pay off in the long run. They +// also allow overloading actions based on parameter types (as opposed +// to just based on the number of parameters). +// +// CAVEAT: +// +// ACTION*() can only be used in a namespace scope. The reason is +// that C++ doesn't yet allow function-local types to be used to +// instantiate templates. The up-coming C++0x standard will fix this. +// Once that's done, we'll consider supporting using ACTION*() inside +// a function. +// +// MORE INFORMATION: +// +// To learn more about using these macros, please search for 'ACTION' +// on http://code.google.com/p/googlemock/wiki/CookBook. + +$range i 0..n +$range k 0..n-1 + +// An internal macro needed for implementing ACTION*(). +#define GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_\ + const args_type& args GTEST_ATTRIBUTE_UNUSED_ +$for k [[, \ + arg$k[[]]_type arg$k GTEST_ATTRIBUTE_UNUSED_]] + + +// Sometimes you want to give an action explicit template parameters +// that cannot be inferred from its value parameters. ACTION() and +// ACTION_P*() don't support that. ACTION_TEMPLATE() remedies that +// and can be viewed as an extension to ACTION() and ACTION_P*(). +// +// The syntax: +// +// ACTION_TEMPLATE(ActionName, +// HAS_m_TEMPLATE_PARAMS(kind1, name1, ..., kind_m, name_m), +// AND_n_VALUE_PARAMS(p1, ..., p_n)) { statements; } +// +// defines an action template that takes m explicit template +// parameters and n value parameters. name_i is the name of the i-th +// template parameter, and kind_i specifies whether it's a typename, +// an integral constant, or a template. p_i is the name of the i-th +// value parameter. +// +// Example: +// +// // DuplicateArg(output) converts the k-th argument of the mock +// // function to type T and copies it to *output. +// ACTION_TEMPLATE(DuplicateArg, +// HAS_2_TEMPLATE_PARAMS(int, k, typename, T), +// AND_1_VALUE_PARAMS(output)) { +// *output = T(std::tr1::get(args)); +// } +// ... +// int n; +// EXPECT_CALL(mock, Foo(_, _)) +// .WillOnce(DuplicateArg<1, unsigned char>(&n)); +// +// To create an instance of an action template, write: +// +// ActionName(v1, ..., v_n) +// +// where the ts are the template arguments and the vs are the value +// arguments. The value argument types are inferred by the compiler. +// If you want to explicitly specify the value argument types, you can +// provide additional template arguments: +// +// ActionName(v1, ..., v_n) +// +// where u_i is the desired type of v_i. +// +// ACTION_TEMPLATE and ACTION/ACTION_P* can be overloaded on the +// number of value parameters, but not on the number of template +// parameters. Without the restriction, the meaning of the following +// is unclear: +// +// OverloadedAction(x); +// +// Are we using a single-template-parameter action where 'bool' refers +// to the type of x, or are we using a two-template-parameter action +// where the compiler is asked to infer the type of x? +// +// Implementation notes: +// +// GMOCK_INTERNAL_*_HAS_m_TEMPLATE_PARAMS and +// GMOCK_INTERNAL_*_AND_n_VALUE_PARAMS are internal macros for +// implementing ACTION_TEMPLATE. The main trick we use is to create +// new macro invocations when expanding a macro. For example, we have +// +// #define ACTION_TEMPLATE(name, template_params, value_params) +// ... GMOCK_INTERNAL_DECL_##template_params ... +// +// which causes ACTION_TEMPLATE(..., HAS_1_TEMPLATE_PARAMS(typename, T), ...) +// to expand to +// +// ... GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS(typename, T) ... +// +// Since GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS is a macro, the +// preprocessor will continue to expand it to +// +// ... typename T ... +// +// This technique conforms to the C++ standard and is portable. It +// allows us to implement action templates using O(N) code, where N is +// the maximum number of template/value parameters supported. Without +// using it, we'd have to devote O(N^2) amount of code to implement all +// combinations of m and n. + +// Declares the template parameters. + +$range j 1..n +$for j [[ +$range m 0..j-1 +#define GMOCK_INTERNAL_DECL_HAS_$j[[]] +_TEMPLATE_PARAMS($for m, [[kind$m, name$m]]) $for m, [[kind$m name$m]] + + +]] + +// Lists the template parameters. + +$for j [[ +$range m 0..j-1 +#define GMOCK_INTERNAL_LIST_HAS_$j[[]] +_TEMPLATE_PARAMS($for m, [[kind$m, name$m]]) $for m, [[name$m]] + + +]] + +// Declares the types of value parameters. + +$for i [[ +$range j 0..i-1 +#define GMOCK_INTERNAL_DECL_TYPE_AND_$i[[]] +_VALUE_PARAMS($for j, [[p$j]]) $for j [[, typename p$j##_type]] + + +]] + +// Initializes the value parameters. + +$for i [[ +$range j 0..i-1 +#define GMOCK_INTERNAL_INIT_AND_$i[[]]_VALUE_PARAMS($for j, [[p$j]])\ + ($for j, [[p$j##_type gmock_p$j]])$if i>0 [[ : ]]$for j, [[p$j(gmock_p$j)]] + + +]] + +// Declares the fields for storing the value parameters. + +$for i [[ +$range j 0..i-1 +#define GMOCK_INTERNAL_DEFN_AND_$i[[]] +_VALUE_PARAMS($for j, [[p$j]]) $for j [[p$j##_type p$j; ]] + + +]] + +// Lists the value parameters. + +$for i [[ +$range j 0..i-1 +#define GMOCK_INTERNAL_LIST_AND_$i[[]] +_VALUE_PARAMS($for j, [[p$j]]) $for j, [[p$j]] + + +]] + +// Lists the value parameter types. + +$for i [[ +$range j 0..i-1 +#define GMOCK_INTERNAL_LIST_TYPE_AND_$i[[]] +_VALUE_PARAMS($for j, [[p$j]]) $for j [[, p$j##_type]] + + +]] + +// Declares the value parameters. + +$for i [[ +$range j 0..i-1 +#define GMOCK_INTERNAL_DECL_AND_$i[[]]_VALUE_PARAMS($for j, [[p$j]]) [[]] +$for j, [[p$j##_type p$j]] + + +]] + +// The suffix of the class template implementing the action template. +$for i [[ + + +$range j 0..i-1 +#define GMOCK_INTERNAL_COUNT_AND_$i[[]]_VALUE_PARAMS($for j, [[p$j]]) [[]] +$if i==1 [[P]] $elif i>=2 [[P$i]] +]] + + +// The name of the class template implementing the action template. +#define GMOCK_ACTION_CLASS_(name, value_params)\ + GTEST_CONCAT_TOKEN_(name##Action, GMOCK_INTERNAL_COUNT_##value_params) + +$range k 0..n-1 + +#define ACTION_TEMPLATE(name, template_params, value_params)\ + template \ + class GMOCK_ACTION_CLASS_(name, value_params) {\ + public:\ + GMOCK_ACTION_CLASS_(name, value_params)\ + GMOCK_INTERNAL_INIT_##value_params {}\ + template \ + class gmock_Impl : public ::testing::ActionInterface {\ + public:\ + typedef F function_type;\ + typedef typename ::testing::internal::Function::Result return_type;\ + typedef typename ::testing::internal::Function::ArgumentTuple\ + args_type;\ + explicit gmock_Impl GMOCK_INTERNAL_INIT_##value_params {}\ + virtual return_type Perform(const args_type& args) {\ + return ::testing::internal::ActionHelper::\ + Perform(this, args);\ + }\ + template <$for k, [[typename arg$k[[]]_type]]>\ + return_type gmock_PerformImpl(const args_type& args[[]] +$for k [[, arg$k[[]]_type arg$k]]) const;\ + GMOCK_INTERNAL_DEFN_##value_params\ + private:\ + GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ + };\ + template operator ::testing::Action() const {\ + return ::testing::Action(\ + new gmock_Impl(GMOCK_INTERNAL_LIST_##value_params));\ + }\ + GMOCK_INTERNAL_DEFN_##value_params\ + private:\ + GTEST_DISALLOW_ASSIGN_(GMOCK_ACTION_CLASS_(name, value_params));\ + };\ + template \ + inline GMOCK_ACTION_CLASS_(name, value_params)<\ + GMOCK_INTERNAL_LIST_##template_params\ + GMOCK_INTERNAL_LIST_TYPE_##value_params> name(\ + GMOCK_INTERNAL_DECL_##value_params) {\ + return GMOCK_ACTION_CLASS_(name, value_params)<\ + GMOCK_INTERNAL_LIST_##template_params\ + GMOCK_INTERNAL_LIST_TYPE_##value_params>(\ + GMOCK_INTERNAL_LIST_##value_params);\ + }\ + template \ + template \ + template \ + typename ::testing::internal::Function::Result\ + GMOCK_ACTION_CLASS_(name, value_params)<\ + GMOCK_INTERNAL_LIST_##template_params\ + GMOCK_INTERNAL_LIST_TYPE_##value_params>::gmock_Impl::\ + gmock_PerformImpl(\ + GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const + +$for i + +[[ +$var template = [[$if i==0 [[]] $else [[ +$range j 0..i-1 + + template <$for j, [[typename p$j##_type]]>\ +]]]] +$var class_name = [[name##Action[[$if i==0 [[]] $elif i==1 [[P]] + $else [[P$i]]]]]] +$range j 0..i-1 +$var ctor_param_list = [[$for j, [[p$j##_type gmock_p$j]]]] +$var param_types_and_names = [[$for j, [[p$j##_type p$j]]]] +$var inits = [[$if i==0 [[]] $else [[ : $for j, [[p$j(gmock_p$j)]]]]]] +$var param_field_decls = [[$for j +[[ + + p$j##_type p$j;\ +]]]] +$var param_field_decls2 = [[$for j +[[ + + p$j##_type p$j;\ +]]]] +$var params = [[$for j, [[p$j]]]] +$var param_types = [[$if i==0 [[]] $else [[<$for j, [[p$j##_type]]>]]]] +$var typename_arg_types = [[$for k, [[typename arg$k[[]]_type]]]] +$var arg_types_and_names = [[$for k, [[arg$k[[]]_type arg$k]]]] +$var macro_name = [[$if i==0 [[ACTION]] $elif i==1 [[ACTION_P]] + $else [[ACTION_P$i]]]] + +#define $macro_name(name$for j [[, p$j]])\$template + class $class_name {\ + public:\ + $class_name($ctor_param_list)$inits {}\ + template \ + class gmock_Impl : public ::testing::ActionInterface {\ + public:\ + typedef F function_type;\ + typedef typename ::testing::internal::Function::Result return_type;\ + typedef typename ::testing::internal::Function::ArgumentTuple\ + args_type;\ + [[$if i==1 [[explicit ]]]]gmock_Impl($ctor_param_list)$inits {}\ + virtual return_type Perform(const args_type& args) {\ + return ::testing::internal::ActionHelper::\ + Perform(this, args);\ + }\ + template <$typename_arg_types>\ + return_type gmock_PerformImpl(const args_type& args, [[]] +$arg_types_and_names) const;\$param_field_decls + private:\ + GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ + };\ + template operator ::testing::Action() const {\ + return ::testing::Action(new gmock_Impl($params));\ + }\$param_field_decls2 + private:\ + GTEST_DISALLOW_ASSIGN_($class_name);\ + };\$template + inline $class_name$param_types name($param_types_and_names) {\ + return $class_name$param_types($params);\ + }\$template + template \ + template <$typename_arg_types>\ + typename ::testing::internal::Function::Result\ + $class_name$param_types::gmock_Impl::gmock_PerformImpl(\ + GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const +]] +$$ } // This meta comment fixes auto-indentation in Emacs. It won't +$$ // show up in the generated code. + + +namespace testing { + +// The ACTION*() macros trigger warning C4100 (unreferenced formal +// parameter) in MSVC with -W4. Unfortunately they cannot be fixed in +// the macro definition, as the warnings are generated when the macro +// is expanded and macro expansion cannot contain #pragma. Therefore +// we suppress them here. +#ifdef _MSC_VER +# pragma warning(push) +# pragma warning(disable:4100) +#endif + +// Various overloads for InvokeArgument(). +// +// The InvokeArgument(a1, a2, ..., a_k) action invokes the N-th +// (0-based) argument, which must be a k-ary callable, of the mock +// function, with arguments a1, a2, ..., a_k. +// +// Notes: +// +// 1. The arguments are passed by value by default. If you need to +// pass an argument by reference, wrap it inside ByRef(). For +// example, +// +// InvokeArgument<1>(5, string("Hello"), ByRef(foo)) +// +// passes 5 and string("Hello") by value, and passes foo by +// reference. +// +// 2. If the callable takes an argument by reference but ByRef() is +// not used, it will receive the reference to a copy of the value, +// instead of the original value. For example, when the 0-th +// argument of the mock function takes a const string&, the action +// +// InvokeArgument<0>(string("Hello")) +// +// makes a copy of the temporary string("Hello") object and passes a +// reference of the copy, instead of the original temporary object, +// to the callable. This makes it easy for a user to define an +// InvokeArgument action from temporary values and have it performed +// later. + +$range i 0..n +$for i [[ +$range j 0..i-1 + +ACTION_TEMPLATE(InvokeArgument, + HAS_1_TEMPLATE_PARAMS(int, k), + AND_$i[[]]_VALUE_PARAMS($for j, [[p$j]])) { + return internal::CallableHelper::Call( + ::std::tr1::get(args)$for j [[, p$j]]); +} + +]] + +// Various overloads for ReturnNew(). +// +// The ReturnNew(a1, a2, ..., a_k) action returns a pointer to a new +// instance of type T, constructed on the heap with constructor arguments +// a1, a2, ..., and a_k. The caller assumes ownership of the returned value. +$range i 0..n +$for i [[ +$range j 0..i-1 +$var ps = [[$for j, [[p$j]]]] + +ACTION_TEMPLATE(ReturnNew, + HAS_1_TEMPLATE_PARAMS(typename, T), + AND_$i[[]]_VALUE_PARAMS($ps)) { + return new T($ps); +} + +]] + +#ifdef _MSC_VER +# pragma warning(pop) +#endif + +} // namespace testing + +#endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_ diff --git a/mbelib-wasm/mbelib/test/gmock/include/gmock/gmock-generated-function-mockers.h b/mbelib-wasm/mbelib/test/gmock/include/gmock/gmock-generated-function-mockers.h new file mode 100644 index 0000000..577fd9e --- /dev/null +++ b/mbelib-wasm/mbelib/test/gmock/include/gmock/gmock-generated-function-mockers.h @@ -0,0 +1,991 @@ +// This file was GENERATED by command: +// pump.py gmock-generated-function-mockers.h.pump +// DO NOT EDIT BY HAND!!! + +// Copyright 2007, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Author: wan@google.com (Zhanyong Wan) + +// Google Mock - a framework for writing C++ mock classes. +// +// This file implements function mockers of various arities. + +#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_ +#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_ + +#include "gmock/gmock-spec-builders.h" +#include "gmock/internal/gmock-internal-utils.h" + +namespace testing { +namespace internal { + +template +class FunctionMockerBase; + +// Note: class FunctionMocker really belongs to the ::testing +// namespace. However if we define it in ::testing, MSVC will +// complain when classes in ::testing::internal declare it as a +// friend class template. To workaround this compiler bug, we define +// FunctionMocker in ::testing::internal and import it into ::testing. +template +class FunctionMocker; + +template +class FunctionMocker : public + internal::FunctionMockerBase { + public: + typedef R F(); + typedef typename internal::Function::ArgumentTuple ArgumentTuple; + + MockSpec& With() { + return this->current_spec(); + } + + R Invoke() { + // Even though gcc and MSVC don't enforce it, 'this->' is required + // by the C++ standard [14.6.4] here, as the base class type is + // dependent on the template argument (and thus shouldn't be + // looked into when resolving InvokeWith). + return this->InvokeWith(ArgumentTuple()); + } +}; + +template +class FunctionMocker : public + internal::FunctionMockerBase { + public: + typedef R F(A1); + typedef typename internal::Function::ArgumentTuple ArgumentTuple; + + MockSpec& With(const Matcher& m1) { + this->current_spec().SetMatchers(::std::tr1::make_tuple(m1)); + return this->current_spec(); + } + + R Invoke(A1 a1) { + // Even though gcc and MSVC don't enforce it, 'this->' is required + // by the C++ standard [14.6.4] here, as the base class type is + // dependent on the template argument (and thus shouldn't be + // looked into when resolving InvokeWith). + return this->InvokeWith(ArgumentTuple(a1)); + } +}; + +template +class FunctionMocker : public + internal::FunctionMockerBase { + public: + typedef R F(A1, A2); + typedef typename internal::Function::ArgumentTuple ArgumentTuple; + + MockSpec& With(const Matcher& m1, const Matcher& m2) { + this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2)); + return this->current_spec(); + } + + R Invoke(A1 a1, A2 a2) { + // Even though gcc and MSVC don't enforce it, 'this->' is required + // by the C++ standard [14.6.4] here, as the base class type is + // dependent on the template argument (and thus shouldn't be + // looked into when resolving InvokeWith). + return this->InvokeWith(ArgumentTuple(a1, a2)); + } +}; + +template +class FunctionMocker : public + internal::FunctionMockerBase { + public: + typedef R F(A1, A2, A3); + typedef typename internal::Function::ArgumentTuple ArgumentTuple; + + MockSpec& With(const Matcher& m1, const Matcher& m2, + const Matcher& m3) { + this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3)); + return this->current_spec(); + } + + R Invoke(A1 a1, A2 a2, A3 a3) { + // Even though gcc and MSVC don't enforce it, 'this->' is required + // by the C++ standard [14.6.4] here, as the base class type is + // dependent on the template argument (and thus shouldn't be + // looked into when resolving InvokeWith). + return this->InvokeWith(ArgumentTuple(a1, a2, a3)); + } +}; + +template +class FunctionMocker : public + internal::FunctionMockerBase { + public: + typedef R F(A1, A2, A3, A4); + typedef typename internal::Function::ArgumentTuple ArgumentTuple; + + MockSpec& With(const Matcher& m1, const Matcher& m2, + const Matcher& m3, const Matcher& m4) { + this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4)); + return this->current_spec(); + } + + R Invoke(A1 a1, A2 a2, A3 a3, A4 a4) { + // Even though gcc and MSVC don't enforce it, 'this->' is required + // by the C++ standard [14.6.4] here, as the base class type is + // dependent on the template argument (and thus shouldn't be + // looked into when resolving InvokeWith). + return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4)); + } +}; + +template +class FunctionMocker : public + internal::FunctionMockerBase { + public: + typedef R F(A1, A2, A3, A4, A5); + typedef typename internal::Function::ArgumentTuple ArgumentTuple; + + MockSpec& With(const Matcher& m1, const Matcher& m2, + const Matcher& m3, const Matcher& m4, const Matcher& m5) { + this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4, + m5)); + return this->current_spec(); + } + + R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { + // Even though gcc and MSVC don't enforce it, 'this->' is required + // by the C++ standard [14.6.4] here, as the base class type is + // dependent on the template argument (and thus shouldn't be + // looked into when resolving InvokeWith). + return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5)); + } +}; + +template +class FunctionMocker : public + internal::FunctionMockerBase { + public: + typedef R F(A1, A2, A3, A4, A5, A6); + typedef typename internal::Function::ArgumentTuple ArgumentTuple; + + MockSpec& With(const Matcher& m1, const Matcher& m2, + const Matcher& m3, const Matcher& m4, const Matcher& m5, + const Matcher& m6) { + this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4, m5, + m6)); + return this->current_spec(); + } + + R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) { + // Even though gcc and MSVC don't enforce it, 'this->' is required + // by the C++ standard [14.6.4] here, as the base class type is + // dependent on the template argument (and thus shouldn't be + // looked into when resolving InvokeWith). + return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6)); + } +}; + +template +class FunctionMocker : public + internal::FunctionMockerBase { + public: + typedef R F(A1, A2, A3, A4, A5, A6, A7); + typedef typename internal::Function::ArgumentTuple ArgumentTuple; + + MockSpec& With(const Matcher& m1, const Matcher& m2, + const Matcher& m3, const Matcher& m4, const Matcher& m5, + const Matcher& m6, const Matcher& m7) { + this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4, m5, + m6, m7)); + return this->current_spec(); + } + + R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) { + // Even though gcc and MSVC don't enforce it, 'this->' is required + // by the C++ standard [14.6.4] here, as the base class type is + // dependent on the template argument (and thus shouldn't be + // looked into when resolving InvokeWith). + return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6, a7)); + } +}; + +template +class FunctionMocker : public + internal::FunctionMockerBase { + public: + typedef R F(A1, A2, A3, A4, A5, A6, A7, A8); + typedef typename internal::Function::ArgumentTuple ArgumentTuple; + + MockSpec& With(const Matcher& m1, const Matcher& m2, + const Matcher& m3, const Matcher& m4, const Matcher& m5, + const Matcher& m6, const Matcher& m7, const Matcher& m8) { + this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4, m5, + m6, m7, m8)); + return this->current_spec(); + } + + R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) { + // Even though gcc and MSVC don't enforce it, 'this->' is required + // by the C++ standard [14.6.4] here, as the base class type is + // dependent on the template argument (and thus shouldn't be + // looked into when resolving InvokeWith). + return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6, a7, a8)); + } +}; + +template +class FunctionMocker : public + internal::FunctionMockerBase { + public: + typedef R F(A1, A2, A3, A4, A5, A6, A7, A8, A9); + typedef typename internal::Function::ArgumentTuple ArgumentTuple; + + MockSpec& With(const Matcher& m1, const Matcher& m2, + const Matcher& m3, const Matcher& m4, const Matcher& m5, + const Matcher& m6, const Matcher& m7, const Matcher& m8, + const Matcher& m9) { + this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4, m5, + m6, m7, m8, m9)); + return this->current_spec(); + } + + R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) { + // Even though gcc and MSVC don't enforce it, 'this->' is required + // by the C++ standard [14.6.4] here, as the base class type is + // dependent on the template argument (and thus shouldn't be + // looked into when resolving InvokeWith). + return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6, a7, a8, a9)); + } +}; + +template +class FunctionMocker : public + internal::FunctionMockerBase { + public: + typedef R F(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10); + typedef typename internal::Function::ArgumentTuple ArgumentTuple; + + MockSpec& With(const Matcher& m1, const Matcher& m2, + const Matcher& m3, const Matcher& m4, const Matcher& m5, + const Matcher& m6, const Matcher& m7, const Matcher& m8, + const Matcher& m9, const Matcher& m10) { + this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4, m5, + m6, m7, m8, m9, m10)); + return this->current_spec(); + } + + R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, + A10 a10) { + // Even though gcc and MSVC don't enforce it, 'this->' is required + // by the C++ standard [14.6.4] here, as the base class type is + // dependent on the template argument (and thus shouldn't be + // looked into when resolving InvokeWith). + return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6, a7, a8, a9, + a10)); + } +}; + +} // namespace internal + +// The style guide prohibits "using" statements in a namespace scope +// inside a header file. However, the FunctionMocker class template +// is meant to be defined in the ::testing namespace. The following +// line is just a trick for working around a bug in MSVC 8.0, which +// cannot handle it if we define FunctionMocker in ::testing. +using internal::FunctionMocker; + +// GMOCK_RESULT_(tn, F) expands to the result type of function type F. +// We define this as a variadic macro in case F contains unprotected +// commas (the same reason that we use variadic macros in other places +// in this file). +// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! +#define GMOCK_RESULT_(tn, ...) \ + tn ::testing::internal::Function<__VA_ARGS__>::Result + +// The type of argument N of the given function type. +// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! +#define GMOCK_ARG_(tn, N, ...) \ + tn ::testing::internal::Function<__VA_ARGS__>::Argument##N + +// The matcher type for argument N of the given function type. +// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! +#define GMOCK_MATCHER_(tn, N, ...) \ + const ::testing::Matcher& + +// The variable for mocking the given method. +// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! +#define GMOCK_MOCKER_(arity, constness, Method) \ + GTEST_CONCAT_TOKEN_(gmock##constness##arity##_##Method##_, __LINE__) + +// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! +#define GMOCK_METHOD0_(tn, constness, ct, Method, ...) \ + GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ + ) constness { \ + GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size< \ + tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ + == 0), \ + this_method_does_not_take_0_arguments); \ + GMOCK_MOCKER_(0, constness, Method).SetOwnerAndName(this, #Method); \ + return GMOCK_MOCKER_(0, constness, Method).Invoke(); \ + } \ + ::testing::MockSpec<__VA_ARGS__>& \ + gmock_##Method() constness { \ + GMOCK_MOCKER_(0, constness, Method).RegisterOwner(this); \ + return GMOCK_MOCKER_(0, constness, Method).With(); \ + } \ + mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(0, constness, \ + Method) + +// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! +#define GMOCK_METHOD1_(tn, constness, ct, Method, ...) \ + GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ + GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1) constness { \ + GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size< \ + tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ + == 1), \ + this_method_does_not_take_1_argument); \ + GMOCK_MOCKER_(1, constness, Method).SetOwnerAndName(this, #Method); \ + return GMOCK_MOCKER_(1, constness, Method).Invoke(gmock_a1); \ + } \ + ::testing::MockSpec<__VA_ARGS__>& \ + gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1) constness { \ + GMOCK_MOCKER_(1, constness, Method).RegisterOwner(this); \ + return GMOCK_MOCKER_(1, constness, Method).With(gmock_a1); \ + } \ + mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(1, constness, \ + Method) + +// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! +#define GMOCK_METHOD2_(tn, constness, ct, Method, ...) \ + GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ + GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ + GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2) constness { \ + GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size< \ + tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ + == 2), \ + this_method_does_not_take_2_arguments); \ + GMOCK_MOCKER_(2, constness, Method).SetOwnerAndName(this, #Method); \ + return GMOCK_MOCKER_(2, constness, Method).Invoke(gmock_a1, gmock_a2); \ + } \ + ::testing::MockSpec<__VA_ARGS__>& \ + gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ + GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2) constness { \ + GMOCK_MOCKER_(2, constness, Method).RegisterOwner(this); \ + return GMOCK_MOCKER_(2, constness, Method).With(gmock_a1, gmock_a2); \ + } \ + mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(2, constness, \ + Method) + +// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! +#define GMOCK_METHOD3_(tn, constness, ct, Method, ...) \ + GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ + GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ + GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \ + GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3) constness { \ + GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size< \ + tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ + == 3), \ + this_method_does_not_take_3_arguments); \ + GMOCK_MOCKER_(3, constness, Method).SetOwnerAndName(this, #Method); \ + return GMOCK_MOCKER_(3, constness, Method).Invoke(gmock_a1, gmock_a2, \ + gmock_a3); \ + } \ + ::testing::MockSpec<__VA_ARGS__>& \ + gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ + GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ + GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3) constness { \ + GMOCK_MOCKER_(3, constness, Method).RegisterOwner(this); \ + return GMOCK_MOCKER_(3, constness, Method).With(gmock_a1, gmock_a2, \ + gmock_a3); \ + } \ + mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(3, constness, \ + Method) + +// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! +#define GMOCK_METHOD4_(tn, constness, ct, Method, ...) \ + GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ + GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ + GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \ + GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ + GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4) constness { \ + GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size< \ + tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ + == 4), \ + this_method_does_not_take_4_arguments); \ + GMOCK_MOCKER_(4, constness, Method).SetOwnerAndName(this, #Method); \ + return GMOCK_MOCKER_(4, constness, Method).Invoke(gmock_a1, gmock_a2, \ + gmock_a3, gmock_a4); \ + } \ + ::testing::MockSpec<__VA_ARGS__>& \ + gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ + GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ + GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ + GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4) constness { \ + GMOCK_MOCKER_(4, constness, Method).RegisterOwner(this); \ + return GMOCK_MOCKER_(4, constness, Method).With(gmock_a1, gmock_a2, \ + gmock_a3, gmock_a4); \ + } \ + mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(4, constness, \ + Method) + +// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! +#define GMOCK_METHOD5_(tn, constness, ct, Method, ...) \ + GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ + GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ + GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \ + GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ + GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \ + GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5) constness { \ + GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size< \ + tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ + == 5), \ + this_method_does_not_take_5_arguments); \ + GMOCK_MOCKER_(5, constness, Method).SetOwnerAndName(this, #Method); \ + return GMOCK_MOCKER_(5, constness, Method).Invoke(gmock_a1, gmock_a2, \ + gmock_a3, gmock_a4, gmock_a5); \ + } \ + ::testing::MockSpec<__VA_ARGS__>& \ + gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ + GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ + GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ + GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \ + GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5) constness { \ + GMOCK_MOCKER_(5, constness, Method).RegisterOwner(this); \ + return GMOCK_MOCKER_(5, constness, Method).With(gmock_a1, gmock_a2, \ + gmock_a3, gmock_a4, gmock_a5); \ + } \ + mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(5, constness, \ + Method) + +// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! +#define GMOCK_METHOD6_(tn, constness, ct, Method, ...) \ + GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ + GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ + GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \ + GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ + GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \ + GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \ + GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6) constness { \ + GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size< \ + tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ + == 6), \ + this_method_does_not_take_6_arguments); \ + GMOCK_MOCKER_(6, constness, Method).SetOwnerAndName(this, #Method); \ + return GMOCK_MOCKER_(6, constness, Method).Invoke(gmock_a1, gmock_a2, \ + gmock_a3, gmock_a4, gmock_a5, gmock_a6); \ + } \ + ::testing::MockSpec<__VA_ARGS__>& \ + gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ + GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ + GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ + GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \ + GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \ + GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6) constness { \ + GMOCK_MOCKER_(6, constness, Method).RegisterOwner(this); \ + return GMOCK_MOCKER_(6, constness, Method).With(gmock_a1, gmock_a2, \ + gmock_a3, gmock_a4, gmock_a5, gmock_a6); \ + } \ + mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(6, constness, \ + Method) + +// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! +#define GMOCK_METHOD7_(tn, constness, ct, Method, ...) \ + GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ + GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ + GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \ + GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ + GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \ + GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \ + GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \ + GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7) constness { \ + GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size< \ + tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ + == 7), \ + this_method_does_not_take_7_arguments); \ + GMOCK_MOCKER_(7, constness, Method).SetOwnerAndName(this, #Method); \ + return GMOCK_MOCKER_(7, constness, Method).Invoke(gmock_a1, gmock_a2, \ + gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7); \ + } \ + ::testing::MockSpec<__VA_ARGS__>& \ + gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ + GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ + GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ + GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \ + GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \ + GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6, \ + GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7) constness { \ + GMOCK_MOCKER_(7, constness, Method).RegisterOwner(this); \ + return GMOCK_MOCKER_(7, constness, Method).With(gmock_a1, gmock_a2, \ + gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7); \ + } \ + mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(7, constness, \ + Method) + +// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! +#define GMOCK_METHOD8_(tn, constness, ct, Method, ...) \ + GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ + GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ + GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \ + GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ + GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \ + GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \ + GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \ + GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, \ + GMOCK_ARG_(tn, 8, __VA_ARGS__) gmock_a8) constness { \ + GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size< \ + tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ + == 8), \ + this_method_does_not_take_8_arguments); \ + GMOCK_MOCKER_(8, constness, Method).SetOwnerAndName(this, #Method); \ + return GMOCK_MOCKER_(8, constness, Method).Invoke(gmock_a1, gmock_a2, \ + gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8); \ + } \ + ::testing::MockSpec<__VA_ARGS__>& \ + gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ + GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ + GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ + GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \ + GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \ + GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6, \ + GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7, \ + GMOCK_MATCHER_(tn, 8, __VA_ARGS__) gmock_a8) constness { \ + GMOCK_MOCKER_(8, constness, Method).RegisterOwner(this); \ + return GMOCK_MOCKER_(8, constness, Method).With(gmock_a1, gmock_a2, \ + gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8); \ + } \ + mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(8, constness, \ + Method) + +// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! +#define GMOCK_METHOD9_(tn, constness, ct, Method, ...) \ + GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ + GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ + GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \ + GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ + GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \ + GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \ + GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \ + GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, \ + GMOCK_ARG_(tn, 8, __VA_ARGS__) gmock_a8, \ + GMOCK_ARG_(tn, 9, __VA_ARGS__) gmock_a9) constness { \ + GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size< \ + tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ + == 9), \ + this_method_does_not_take_9_arguments); \ + GMOCK_MOCKER_(9, constness, Method).SetOwnerAndName(this, #Method); \ + return GMOCK_MOCKER_(9, constness, Method).Invoke(gmock_a1, gmock_a2, \ + gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, \ + gmock_a9); \ + } \ + ::testing::MockSpec<__VA_ARGS__>& \ + gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ + GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ + GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ + GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \ + GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \ + GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6, \ + GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7, \ + GMOCK_MATCHER_(tn, 8, __VA_ARGS__) gmock_a8, \ + GMOCK_MATCHER_(tn, 9, __VA_ARGS__) gmock_a9) constness { \ + GMOCK_MOCKER_(9, constness, Method).RegisterOwner(this); \ + return GMOCK_MOCKER_(9, constness, Method).With(gmock_a1, gmock_a2, \ + gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, \ + gmock_a9); \ + } \ + mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(9, constness, \ + Method) + +// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! +#define GMOCK_METHOD10_(tn, constness, ct, Method, ...) \ + GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ + GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ + GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \ + GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ + GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \ + GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \ + GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \ + GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, \ + GMOCK_ARG_(tn, 8, __VA_ARGS__) gmock_a8, \ + GMOCK_ARG_(tn, 9, __VA_ARGS__) gmock_a9, \ + GMOCK_ARG_(tn, 10, __VA_ARGS__) gmock_a10) constness { \ + GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size< \ + tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ + == 10), \ + this_method_does_not_take_10_arguments); \ + GMOCK_MOCKER_(10, constness, Method).SetOwnerAndName(this, #Method); \ + return GMOCK_MOCKER_(10, constness, Method).Invoke(gmock_a1, gmock_a2, \ + gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, gmock_a9, \ + gmock_a10); \ + } \ + ::testing::MockSpec<__VA_ARGS__>& \ + gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ + GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ + GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ + GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \ + GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \ + GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6, \ + GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7, \ + GMOCK_MATCHER_(tn, 8, __VA_ARGS__) gmock_a8, \ + GMOCK_MATCHER_(tn, 9, __VA_ARGS__) gmock_a9, \ + GMOCK_MATCHER_(tn, 10, \ + __VA_ARGS__) gmock_a10) constness { \ + GMOCK_MOCKER_(10, constness, Method).RegisterOwner(this); \ + return GMOCK_MOCKER_(10, constness, Method).With(gmock_a1, gmock_a2, \ + gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, gmock_a9, \ + gmock_a10); \ + } \ + mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(10, constness, \ + Method) + +#define MOCK_METHOD0(m, ...) GMOCK_METHOD0_(, , , m, __VA_ARGS__) +#define MOCK_METHOD1(m, ...) GMOCK_METHOD1_(, , , m, __VA_ARGS__) +#define MOCK_METHOD2(m, ...) GMOCK_METHOD2_(, , , m, __VA_ARGS__) +#define MOCK_METHOD3(m, ...) GMOCK_METHOD3_(, , , m, __VA_ARGS__) +#define MOCK_METHOD4(m, ...) GMOCK_METHOD4_(, , , m, __VA_ARGS__) +#define MOCK_METHOD5(m, ...) GMOCK_METHOD5_(, , , m, __VA_ARGS__) +#define MOCK_METHOD6(m, ...) GMOCK_METHOD6_(, , , m, __VA_ARGS__) +#define MOCK_METHOD7(m, ...) GMOCK_METHOD7_(, , , m, __VA_ARGS__) +#define MOCK_METHOD8(m, ...) GMOCK_METHOD8_(, , , m, __VA_ARGS__) +#define MOCK_METHOD9(m, ...) GMOCK_METHOD9_(, , , m, __VA_ARGS__) +#define MOCK_METHOD10(m, ...) GMOCK_METHOD10_(, , , m, __VA_ARGS__) + +#define MOCK_CONST_METHOD0(m, ...) GMOCK_METHOD0_(, const, , m, __VA_ARGS__) +#define MOCK_CONST_METHOD1(m, ...) GMOCK_METHOD1_(, const, , m, __VA_ARGS__) +#define MOCK_CONST_METHOD2(m, ...) GMOCK_METHOD2_(, const, , m, __VA_ARGS__) +#define MOCK_CONST_METHOD3(m, ...) GMOCK_METHOD3_(, const, , m, __VA_ARGS__) +#define MOCK_CONST_METHOD4(m, ...) GMOCK_METHOD4_(, const, , m, __VA_ARGS__) +#define MOCK_CONST_METHOD5(m, ...) GMOCK_METHOD5_(, const, , m, __VA_ARGS__) +#define MOCK_CONST_METHOD6(m, ...) GMOCK_METHOD6_(, const, , m, __VA_ARGS__) +#define MOCK_CONST_METHOD7(m, ...) GMOCK_METHOD7_(, const, , m, __VA_ARGS__) +#define MOCK_CONST_METHOD8(m, ...) GMOCK_METHOD8_(, const, , m, __VA_ARGS__) +#define MOCK_CONST_METHOD9(m, ...) GMOCK_METHOD9_(, const, , m, __VA_ARGS__) +#define MOCK_CONST_METHOD10(m, ...) GMOCK_METHOD10_(, const, , m, __VA_ARGS__) + +#define MOCK_METHOD0_T(m, ...) GMOCK_METHOD0_(typename, , , m, __VA_ARGS__) +#define MOCK_METHOD1_T(m, ...) GMOCK_METHOD1_(typename, , , m, __VA_ARGS__) +#define MOCK_METHOD2_T(m, ...) GMOCK_METHOD2_(typename, , , m, __VA_ARGS__) +#define MOCK_METHOD3_T(m, ...) GMOCK_METHOD3_(typename, , , m, __VA_ARGS__) +#define MOCK_METHOD4_T(m, ...) GMOCK_METHOD4_(typename, , , m, __VA_ARGS__) +#define MOCK_METHOD5_T(m, ...) GMOCK_METHOD5_(typename, , , m, __VA_ARGS__) +#define MOCK_METHOD6_T(m, ...) GMOCK_METHOD6_(typename, , , m, __VA_ARGS__) +#define MOCK_METHOD7_T(m, ...) GMOCK_METHOD7_(typename, , , m, __VA_ARGS__) +#define MOCK_METHOD8_T(m, ...) GMOCK_METHOD8_(typename, , , m, __VA_ARGS__) +#define MOCK_METHOD9_T(m, ...) GMOCK_METHOD9_(typename, , , m, __VA_ARGS__) +#define MOCK_METHOD10_T(m, ...) GMOCK_METHOD10_(typename, , , m, __VA_ARGS__) + +#define MOCK_CONST_METHOD0_T(m, ...) \ + GMOCK_METHOD0_(typename, const, , m, __VA_ARGS__) +#define MOCK_CONST_METHOD1_T(m, ...) \ + GMOCK_METHOD1_(typename, const, , m, __VA_ARGS__) +#define MOCK_CONST_METHOD2_T(m, ...) \ + GMOCK_METHOD2_(typename, const, , m, __VA_ARGS__) +#define MOCK_CONST_METHOD3_T(m, ...) \ + GMOCK_METHOD3_(typename, const, , m, __VA_ARGS__) +#define MOCK_CONST_METHOD4_T(m, ...) \ + GMOCK_METHOD4_(typename, const, , m, __VA_ARGS__) +#define MOCK_CONST_METHOD5_T(m, ...) \ + GMOCK_METHOD5_(typename, const, , m, __VA_ARGS__) +#define MOCK_CONST_METHOD6_T(m, ...) \ + GMOCK_METHOD6_(typename, const, , m, __VA_ARGS__) +#define MOCK_CONST_METHOD7_T(m, ...) \ + GMOCK_METHOD7_(typename, const, , m, __VA_ARGS__) +#define MOCK_CONST_METHOD8_T(m, ...) \ + GMOCK_METHOD8_(typename, const, , m, __VA_ARGS__) +#define MOCK_CONST_METHOD9_T(m, ...) \ + GMOCK_METHOD9_(typename, const, , m, __VA_ARGS__) +#define MOCK_CONST_METHOD10_T(m, ...) \ + GMOCK_METHOD10_(typename, const, , m, __VA_ARGS__) + +#define MOCK_METHOD0_WITH_CALLTYPE(ct, m, ...) \ + GMOCK_METHOD0_(, , ct, m, __VA_ARGS__) +#define MOCK_METHOD1_WITH_CALLTYPE(ct, m, ...) \ + GMOCK_METHOD1_(, , ct, m, __VA_ARGS__) +#define MOCK_METHOD2_WITH_CALLTYPE(ct, m, ...) \ + GMOCK_METHOD2_(, , ct, m, __VA_ARGS__) +#define MOCK_METHOD3_WITH_CALLTYPE(ct, m, ...) \ + GMOCK_METHOD3_(, , ct, m, __VA_ARGS__) +#define MOCK_METHOD4_WITH_CALLTYPE(ct, m, ...) \ + GMOCK_METHOD4_(, , ct, m, __VA_ARGS__) +#define MOCK_METHOD5_WITH_CALLTYPE(ct, m, ...) \ + GMOCK_METHOD5_(, , ct, m, __VA_ARGS__) +#define MOCK_METHOD6_WITH_CALLTYPE(ct, m, ...) \ + GMOCK_METHOD6_(, , ct, m, __VA_ARGS__) +#define MOCK_METHOD7_WITH_CALLTYPE(ct, m, ...) \ + GMOCK_METHOD7_(, , ct, m, __VA_ARGS__) +#define MOCK_METHOD8_WITH_CALLTYPE(ct, m, ...) \ + GMOCK_METHOD8_(, , ct, m, __VA_ARGS__) +#define MOCK_METHOD9_WITH_CALLTYPE(ct, m, ...) \ + GMOCK_METHOD9_(, , ct, m, __VA_ARGS__) +#define MOCK_METHOD10_WITH_CALLTYPE(ct, m, ...) \ + GMOCK_METHOD10_(, , ct, m, __VA_ARGS__) + +#define MOCK_CONST_METHOD0_WITH_CALLTYPE(ct, m, ...) \ + GMOCK_METHOD0_(, const, ct, m, __VA_ARGS__) +#define MOCK_CONST_METHOD1_WITH_CALLTYPE(ct, m, ...) \ + GMOCK_METHOD1_(, const, ct, m, __VA_ARGS__) +#define MOCK_CONST_METHOD2_WITH_CALLTYPE(ct, m, ...) \ + GMOCK_METHOD2_(, const, ct, m, __VA_ARGS__) +#define MOCK_CONST_METHOD3_WITH_CALLTYPE(ct, m, ...) \ + GMOCK_METHOD3_(, const, ct, m, __VA_ARGS__) +#define MOCK_CONST_METHOD4_WITH_CALLTYPE(ct, m, ...) \ + GMOCK_METHOD4_(, const, ct, m, __VA_ARGS__) +#define MOCK_CONST_METHOD5_WITH_CALLTYPE(ct, m, ...) \ + GMOCK_METHOD5_(, const, ct, m, __VA_ARGS__) +#define MOCK_CONST_METHOD6_WITH_CALLTYPE(ct, m, ...) \ + GMOCK_METHOD6_(, const, ct, m, __VA_ARGS__) +#define MOCK_CONST_METHOD7_WITH_CALLTYPE(ct, m, ...) \ + GMOCK_METHOD7_(, const, ct, m, __VA_ARGS__) +#define MOCK_CONST_METHOD8_WITH_CALLTYPE(ct, m, ...) \ + GMOCK_METHOD8_(, const, ct, m, __VA_ARGS__) +#define MOCK_CONST_METHOD9_WITH_CALLTYPE(ct, m, ...) \ + GMOCK_METHOD9_(, const, ct, m, __VA_ARGS__) +#define MOCK_CONST_METHOD10_WITH_CALLTYPE(ct, m, ...) \ + GMOCK_METHOD10_(, const, ct, m, __VA_ARGS__) + +#define MOCK_METHOD0_T_WITH_CALLTYPE(ct, m, ...) \ + GMOCK_METHOD0_(typename, , ct, m, __VA_ARGS__) +#define MOCK_METHOD1_T_WITH_CALLTYPE(ct, m, ...) \ + GMOCK_METHOD1_(typename, , ct, m, __VA_ARGS__) +#define MOCK_METHOD2_T_WITH_CALLTYPE(ct, m, ...) \ + GMOCK_METHOD2_(typename, , ct, m, __VA_ARGS__) +#define MOCK_METHOD3_T_WITH_CALLTYPE(ct, m, ...) \ + GMOCK_METHOD3_(typename, , ct, m, __VA_ARGS__) +#define MOCK_METHOD4_T_WITH_CALLTYPE(ct, m, ...) \ + GMOCK_METHOD4_(typename, , ct, m, __VA_ARGS__) +#define MOCK_METHOD5_T_WITH_CALLTYPE(ct, m, ...) \ + GMOCK_METHOD5_(typename, , ct, m, __VA_ARGS__) +#define MOCK_METHOD6_T_WITH_CALLTYPE(ct, m, ...) \ + GMOCK_METHOD6_(typename, , ct, m, __VA_ARGS__) +#define MOCK_METHOD7_T_WITH_CALLTYPE(ct, m, ...) \ + GMOCK_METHOD7_(typename, , ct, m, __VA_ARGS__) +#define MOCK_METHOD8_T_WITH_CALLTYPE(ct, m, ...) \ + GMOCK_METHOD8_(typename, , ct, m, __VA_ARGS__) +#define MOCK_METHOD9_T_WITH_CALLTYPE(ct, m, ...) \ + GMOCK_METHOD9_(typename, , ct, m, __VA_ARGS__) +#define MOCK_METHOD10_T_WITH_CALLTYPE(ct, m, ...) \ + GMOCK_METHOD10_(typename, , ct, m, __VA_ARGS__) + +#define MOCK_CONST_METHOD0_T_WITH_CALLTYPE(ct, m, ...) \ + GMOCK_METHOD0_(typename, const, ct, m, __VA_ARGS__) +#define MOCK_CONST_METHOD1_T_WITH_CALLTYPE(ct, m, ...) \ + GMOCK_METHOD1_(typename, const, ct, m, __VA_ARGS__) +#define MOCK_CONST_METHOD2_T_WITH_CALLTYPE(ct, m, ...) \ + GMOCK_METHOD2_(typename, const, ct, m, __VA_ARGS__) +#define MOCK_CONST_METHOD3_T_WITH_CALLTYPE(ct, m, ...) \ + GMOCK_METHOD3_(typename, const, ct, m, __VA_ARGS__) +#define MOCK_CONST_METHOD4_T_WITH_CALLTYPE(ct, m, ...) \ + GMOCK_METHOD4_(typename, const, ct, m, __VA_ARGS__) +#define MOCK_CONST_METHOD5_T_WITH_CALLTYPE(ct, m, ...) \ + GMOCK_METHOD5_(typename, const, ct, m, __VA_ARGS__) +#define MOCK_CONST_METHOD6_T_WITH_CALLTYPE(ct, m, ...) \ + GMOCK_METHOD6_(typename, const, ct, m, __VA_ARGS__) +#define MOCK_CONST_METHOD7_T_WITH_CALLTYPE(ct, m, ...) \ + GMOCK_METHOD7_(typename, const, ct, m, __VA_ARGS__) +#define MOCK_CONST_METHOD8_T_WITH_CALLTYPE(ct, m, ...) \ + GMOCK_METHOD8_(typename, const, ct, m, __VA_ARGS__) +#define MOCK_CONST_METHOD9_T_WITH_CALLTYPE(ct, m, ...) \ + GMOCK_METHOD9_(typename, const, ct, m, __VA_ARGS__) +#define MOCK_CONST_METHOD10_T_WITH_CALLTYPE(ct, m, ...) \ + GMOCK_METHOD10_(typename, const, ct, m, __VA_ARGS__) + +// A MockFunction class has one mock method whose type is F. It is +// useful when you just want your test code to emit some messages and +// have Google Mock verify the right messages are sent (and perhaps at +// the right times). For example, if you are exercising code: +// +// Foo(1); +// Foo(2); +// Foo(3); +// +// and want to verify that Foo(1) and Foo(3) both invoke +// mock.Bar("a"), but Foo(2) doesn't invoke anything, you can write: +// +// TEST(FooTest, InvokesBarCorrectly) { +// MyMock mock; +// MockFunction check; +// { +// InSequence s; +// +// EXPECT_CALL(mock, Bar("a")); +// EXPECT_CALL(check, Call("1")); +// EXPECT_CALL(check, Call("2")); +// EXPECT_CALL(mock, Bar("a")); +// } +// Foo(1); +// check.Call("1"); +// Foo(2); +// check.Call("2"); +// Foo(3); +// } +// +// The expectation spec says that the first Bar("a") must happen +// before check point "1", the second Bar("a") must happen after check +// point "2", and nothing should happen between the two check +// points. The explicit check points make it easy to tell which +// Bar("a") is called by which call to Foo(). +template +class MockFunction; + +template +class MockFunction { + public: + MockFunction() {} + + MOCK_METHOD0_T(Call, R()); + + private: + GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); +}; + +template +class MockFunction { + public: + MockFunction() {} + + MOCK_METHOD1_T(Call, R(A0)); + + private: + GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); +}; + +template +class MockFunction { + public: + MockFunction() {} + + MOCK_METHOD2_T(Call, R(A0, A1)); + + private: + GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); +}; + +template +class MockFunction { + public: + MockFunction() {} + + MOCK_METHOD3_T(Call, R(A0, A1, A2)); + + private: + GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); +}; + +template +class MockFunction { + public: + MockFunction() {} + + MOCK_METHOD4_T(Call, R(A0, A1, A2, A3)); + + private: + GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); +}; + +template +class MockFunction { + public: + MockFunction() {} + + MOCK_METHOD5_T(Call, R(A0, A1, A2, A3, A4)); + + private: + GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); +}; + +template +class MockFunction { + public: + MockFunction() {} + + MOCK_METHOD6_T(Call, R(A0, A1, A2, A3, A4, A5)); + + private: + GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); +}; + +template +class MockFunction { + public: + MockFunction() {} + + MOCK_METHOD7_T(Call, R(A0, A1, A2, A3, A4, A5, A6)); + + private: + GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); +}; + +template +class MockFunction { + public: + MockFunction() {} + + MOCK_METHOD8_T(Call, R(A0, A1, A2, A3, A4, A5, A6, A7)); + + private: + GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); +}; + +template +class MockFunction { + public: + MockFunction() {} + + MOCK_METHOD9_T(Call, R(A0, A1, A2, A3, A4, A5, A6, A7, A8)); + + private: + GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); +}; + +template +class MockFunction { + public: + MockFunction() {} + + MOCK_METHOD10_T(Call, R(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9)); + + private: + GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); +}; + +} // namespace testing + +#endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_ diff --git a/mbelib-wasm/mbelib/test/gmock/include/gmock/gmock-generated-function-mockers.h.pump b/mbelib-wasm/mbelib/test/gmock/include/gmock/gmock-generated-function-mockers.h.pump new file mode 100644 index 0000000..f050caf --- /dev/null +++ b/mbelib-wasm/mbelib/test/gmock/include/gmock/gmock-generated-function-mockers.h.pump @@ -0,0 +1,265 @@ +$$ -*- mode: c++; -*- +$$ This is a Pump source file. Please use Pump to convert it to +$$ gmock-generated-function-mockers.h. +$$ +$var n = 10 $$ The maximum arity we support. +// Copyright 2007, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Author: wan@google.com (Zhanyong Wan) + +// Google Mock - a framework for writing C++ mock classes. +// +// This file implements function mockers of various arities. + +#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_ +#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_ + +#include "gmock/gmock-spec-builders.h" +#include "gmock/internal/gmock-internal-utils.h" + +namespace testing { +namespace internal { + +template +class FunctionMockerBase; + +// Note: class FunctionMocker really belongs to the ::testing +// namespace. However if we define it in ::testing, MSVC will +// complain when classes in ::testing::internal declare it as a +// friend class template. To workaround this compiler bug, we define +// FunctionMocker in ::testing::internal and import it into ::testing. +template +class FunctionMocker; + + +$range i 0..n +$for i [[ +$range j 1..i +$var typename_As = [[$for j [[, typename A$j]]]] +$var As = [[$for j, [[A$j]]]] +$var as = [[$for j, [[a$j]]]] +$var Aas = [[$for j, [[A$j a$j]]]] +$var ms = [[$for j, [[m$j]]]] +$var matchers = [[$for j, [[const Matcher& m$j]]]] +template +class FunctionMocker : public + internal::FunctionMockerBase { + public: + typedef R F($As); + typedef typename internal::Function::ArgumentTuple ArgumentTuple; + + MockSpec& With($matchers) { + +$if i >= 1 [[ + this->current_spec().SetMatchers(::std::tr1::make_tuple($ms)); + +]] + return this->current_spec(); + } + + R Invoke($Aas) { + // Even though gcc and MSVC don't enforce it, 'this->' is required + // by the C++ standard [14.6.4] here, as the base class type is + // dependent on the template argument (and thus shouldn't be + // looked into when resolving InvokeWith). + return this->InvokeWith(ArgumentTuple($as)); + } +}; + + +]] +} // namespace internal + +// The style guide prohibits "using" statements in a namespace scope +// inside a header file. However, the FunctionMocker class template +// is meant to be defined in the ::testing namespace. The following +// line is just a trick for working around a bug in MSVC 8.0, which +// cannot handle it if we define FunctionMocker in ::testing. +using internal::FunctionMocker; + +// GMOCK_RESULT_(tn, F) expands to the result type of function type F. +// We define this as a variadic macro in case F contains unprotected +// commas (the same reason that we use variadic macros in other places +// in this file). +// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! +#define GMOCK_RESULT_(tn, ...) \ + tn ::testing::internal::Function<__VA_ARGS__>::Result + +// The type of argument N of the given function type. +// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! +#define GMOCK_ARG_(tn, N, ...) \ + tn ::testing::internal::Function<__VA_ARGS__>::Argument##N + +// The matcher type for argument N of the given function type. +// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! +#define GMOCK_MATCHER_(tn, N, ...) \ + const ::testing::Matcher& + +// The variable for mocking the given method. +// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! +#define GMOCK_MOCKER_(arity, constness, Method) \ + GTEST_CONCAT_TOKEN_(gmock##constness##arity##_##Method##_, __LINE__) + + +$for i [[ +$range j 1..i +$var arg_as = [[$for j, \ + [[GMOCK_ARG_(tn, $j, __VA_ARGS__) gmock_a$j]]]] +$var as = [[$for j, [[gmock_a$j]]]] +$var matcher_as = [[$for j, \ + [[GMOCK_MATCHER_(tn, $j, __VA_ARGS__) gmock_a$j]]]] +// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! +#define GMOCK_METHOD$i[[]]_(tn, constness, ct, Method, ...) \ + GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ + $arg_as) constness { \ + GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size< \ + tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value == $i), \ + this_method_does_not_take_$i[[]]_argument[[$if i != 1 [[s]]]]); \ + GMOCK_MOCKER_($i, constness, Method).SetOwnerAndName(this, #Method); \ + return GMOCK_MOCKER_($i, constness, Method).Invoke($as); \ + } \ + ::testing::MockSpec<__VA_ARGS__>& \ + gmock_##Method($matcher_as) constness { \ + GMOCK_MOCKER_($i, constness, Method).RegisterOwner(this); \ + return GMOCK_MOCKER_($i, constness, Method).With($as); \ + } \ + mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_($i, constness, Method) + + +]] +$for i [[ +#define MOCK_METHOD$i(m, ...) GMOCK_METHOD$i[[]]_(, , , m, __VA_ARGS__) + +]] + + +$for i [[ +#define MOCK_CONST_METHOD$i(m, ...) GMOCK_METHOD$i[[]]_(, const, , m, __VA_ARGS__) + +]] + + +$for i [[ +#define MOCK_METHOD$i[[]]_T(m, ...) GMOCK_METHOD$i[[]]_(typename, , , m, __VA_ARGS__) + +]] + + +$for i [[ +#define MOCK_CONST_METHOD$i[[]]_T(m, ...) \ + GMOCK_METHOD$i[[]]_(typename, const, , m, __VA_ARGS__) + +]] + + +$for i [[ +#define MOCK_METHOD$i[[]]_WITH_CALLTYPE(ct, m, ...) \ + GMOCK_METHOD$i[[]]_(, , ct, m, __VA_ARGS__) + +]] + + +$for i [[ +#define MOCK_CONST_METHOD$i[[]]_WITH_CALLTYPE(ct, m, ...) \ + GMOCK_METHOD$i[[]]_(, const, ct, m, __VA_ARGS__) + +]] + + +$for i [[ +#define MOCK_METHOD$i[[]]_T_WITH_CALLTYPE(ct, m, ...) \ + GMOCK_METHOD$i[[]]_(typename, , ct, m, __VA_ARGS__) + +]] + + +$for i [[ +#define MOCK_CONST_METHOD$i[[]]_T_WITH_CALLTYPE(ct, m, ...) \ + GMOCK_METHOD$i[[]]_(typename, const, ct, m, __VA_ARGS__) + +]] + +// A MockFunction class has one mock method whose type is F. It is +// useful when you just want your test code to emit some messages and +// have Google Mock verify the right messages are sent (and perhaps at +// the right times). For example, if you are exercising code: +// +// Foo(1); +// Foo(2); +// Foo(3); +// +// and want to verify that Foo(1) and Foo(3) both invoke +// mock.Bar("a"), but Foo(2) doesn't invoke anything, you can write: +// +// TEST(FooTest, InvokesBarCorrectly) { +// MyMock mock; +// MockFunction check; +// { +// InSequence s; +// +// EXPECT_CALL(mock, Bar("a")); +// EXPECT_CALL(check, Call("1")); +// EXPECT_CALL(check, Call("2")); +// EXPECT_CALL(mock, Bar("a")); +// } +// Foo(1); +// check.Call("1"); +// Foo(2); +// check.Call("2"); +// Foo(3); +// } +// +// The expectation spec says that the first Bar("a") must happen +// before check point "1", the second Bar("a") must happen after check +// point "2", and nothing should happen between the two check +// points. The explicit check points make it easy to tell which +// Bar("a") is called by which call to Foo(). +template +class MockFunction; + + +$for i [[ +$range j 0..i-1 +template +class MockFunction { + public: + MockFunction() {} + + MOCK_METHOD$i[[]]_T(Call, R($for j, [[A$j]])); + + private: + GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); +}; + + +]] +} // namespace testing + +#endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_ diff --git a/mbelib-wasm/mbelib/test/gmock/include/gmock/gmock-generated-matchers.h b/mbelib-wasm/mbelib/test/gmock/include/gmock/gmock-generated-matchers.h new file mode 100644 index 0000000..b4c8571 --- /dev/null +++ b/mbelib-wasm/mbelib/test/gmock/include/gmock/gmock-generated-matchers.h @@ -0,0 +1,2190 @@ +// This file was GENERATED by command: +// pump.py gmock-generated-matchers.h.pump +// DO NOT EDIT BY HAND!!! + +// Copyright 2008, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Google Mock - a framework for writing C++ mock classes. +// +// This file implements some commonly used variadic matchers. + +#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_ +#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_ + +#include +#include +#include +#include +#include "gmock/gmock-matchers.h" + +namespace testing { +namespace internal { + +// The type of the i-th (0-based) field of Tuple. +#define GMOCK_FIELD_TYPE_(Tuple, i) \ + typename ::std::tr1::tuple_element::type + +// TupleFields is for selecting fields from a +// tuple of type Tuple. It has two members: +// +// type: a tuple type whose i-th field is the ki-th field of Tuple. +// GetSelectedFields(t): returns fields k0, ..., and kn of t as a tuple. +// +// For example, in class TupleFields, 2, 0>, we have: +// +// type is tuple, and +// GetSelectedFields(make_tuple(true, 'a', 42)) is (42, true). + +template +class TupleFields; + +// This generic version is used when there are 10 selectors. +template +class TupleFields { + public: + typedef ::std::tr1::tuple type; + static type GetSelectedFields(const Tuple& t) { + using ::std::tr1::get; + return type(get(t), get(t), get(t), get(t), get(t), + get(t), get(t), get(t), get(t), get(t)); + } +}; + +// The following specialization is used for 0 ~ 9 selectors. + +template +class TupleFields { + public: + typedef ::std::tr1::tuple<> type; + static type GetSelectedFields(const Tuple& /* t */) { + using ::std::tr1::get; + return type(); + } +}; + +template +class TupleFields { + public: + typedef ::std::tr1::tuple type; + static type GetSelectedFields(const Tuple& t) { + using ::std::tr1::get; + return type(get(t)); + } +}; + +template +class TupleFields { + public: + typedef ::std::tr1::tuple type; + static type GetSelectedFields(const Tuple& t) { + using ::std::tr1::get; + return type(get(t), get(t)); + } +}; + +template +class TupleFields { + public: + typedef ::std::tr1::tuple type; + static type GetSelectedFields(const Tuple& t) { + using ::std::tr1::get; + return type(get(t), get(t), get(t)); + } +}; + +template +class TupleFields { + public: + typedef ::std::tr1::tuple type; + static type GetSelectedFields(const Tuple& t) { + using ::std::tr1::get; + return type(get(t), get(t), get(t), get(t)); + } +}; + +template +class TupleFields { + public: + typedef ::std::tr1::tuple type; + static type GetSelectedFields(const Tuple& t) { + using ::std::tr1::get; + return type(get(t), get(t), get(t), get(t), get(t)); + } +}; + +template +class TupleFields { + public: + typedef ::std::tr1::tuple type; + static type GetSelectedFields(const Tuple& t) { + using ::std::tr1::get; + return type(get(t), get(t), get(t), get(t), get(t), + get(t)); + } +}; + +template +class TupleFields { + public: + typedef ::std::tr1::tuple type; + static type GetSelectedFields(const Tuple& t) { + using ::std::tr1::get; + return type(get(t), get(t), get(t), get(t), get(t), + get(t), get(t)); + } +}; + +template +class TupleFields { + public: + typedef ::std::tr1::tuple type; + static type GetSelectedFields(const Tuple& t) { + using ::std::tr1::get; + return type(get(t), get(t), get(t), get(t), get(t), + get(t), get(t), get(t)); + } +}; + +template +class TupleFields { + public: + typedef ::std::tr1::tuple type; + static type GetSelectedFields(const Tuple& t) { + using ::std::tr1::get; + return type(get(t), get(t), get(t), get(t), get(t), + get(t), get(t), get(t), get(t)); + } +}; + +#undef GMOCK_FIELD_TYPE_ + +// Implements the Args() matcher. +template +class ArgsMatcherImpl : public MatcherInterface { + public: + // ArgsTuple may have top-level const or reference modifiers. + typedef GTEST_REMOVE_REFERENCE_AND_CONST_(ArgsTuple) RawArgsTuple; + typedef typename internal::TupleFields::type SelectedArgs; + typedef Matcher MonomorphicInnerMatcher; + + template + explicit ArgsMatcherImpl(const InnerMatcher& inner_matcher) + : inner_matcher_(SafeMatcherCast(inner_matcher)) {} + + virtual bool MatchAndExplain(ArgsTuple args, + MatchResultListener* listener) const { + const SelectedArgs& selected_args = GetSelectedArgs(args); + if (!listener->IsInterested()) + return inner_matcher_.Matches(selected_args); + + PrintIndices(listener->stream()); + *listener << "are " << PrintToString(selected_args); + + StringMatchResultListener inner_listener; + const bool match = inner_matcher_.MatchAndExplain(selected_args, + &inner_listener); + PrintIfNotEmpty(inner_listener.str(), listener->stream()); + return match; + } + + virtual void DescribeTo(::std::ostream* os) const { + *os << "are a tuple "; + PrintIndices(os); + inner_matcher_.DescribeTo(os); + } + + virtual void DescribeNegationTo(::std::ostream* os) const { + *os << "are a tuple "; + PrintIndices(os); + inner_matcher_.DescribeNegationTo(os); + } + + private: + static SelectedArgs GetSelectedArgs(ArgsTuple args) { + return TupleFields::GetSelectedFields(args); + } + + // Prints the indices of the selected fields. + static void PrintIndices(::std::ostream* os) { + *os << "whose fields ("; + const int indices[10] = { k0, k1, k2, k3, k4, k5, k6, k7, k8, k9 }; + for (int i = 0; i < 10; i++) { + if (indices[i] < 0) + break; + + if (i >= 1) + *os << ", "; + + *os << "#" << indices[i]; + } + *os << ") "; + } + + const MonomorphicInnerMatcher inner_matcher_; + + GTEST_DISALLOW_ASSIGN_(ArgsMatcherImpl); +}; + +template +class ArgsMatcher { + public: + explicit ArgsMatcher(const InnerMatcher& inner_matcher) + : inner_matcher_(inner_matcher) {} + + template + operator Matcher() const { + return MakeMatcher(new ArgsMatcherImpl(inner_matcher_)); + } + + private: + const InnerMatcher inner_matcher_; + + GTEST_DISALLOW_ASSIGN_(ArgsMatcher); +}; + +// A set of metafunctions for computing the result type of AllOf. +// AllOf(m1, ..., mN) returns +// AllOfResultN::type. + +// Although AllOf isn't defined for one argument, AllOfResult1 is defined +// to simplify the implementation. +template +struct AllOfResult1 { + typedef M1 type; +}; + +template +struct AllOfResult2 { + typedef BothOfMatcher< + typename AllOfResult1::type, + typename AllOfResult1::type + > type; +}; + +template +struct AllOfResult3 { + typedef BothOfMatcher< + typename AllOfResult1::type, + typename AllOfResult2::type + > type; +}; + +template +struct AllOfResult4 { + typedef BothOfMatcher< + typename AllOfResult2::type, + typename AllOfResult2::type + > type; +}; + +template +struct AllOfResult5 { + typedef BothOfMatcher< + typename AllOfResult2::type, + typename AllOfResult3::type + > type; +}; + +template +struct AllOfResult6 { + typedef BothOfMatcher< + typename AllOfResult3::type, + typename AllOfResult3::type + > type; +}; + +template +struct AllOfResult7 { + typedef BothOfMatcher< + typename AllOfResult3::type, + typename AllOfResult4::type + > type; +}; + +template +struct AllOfResult8 { + typedef BothOfMatcher< + typename AllOfResult4::type, + typename AllOfResult4::type + > type; +}; + +template +struct AllOfResult9 { + typedef BothOfMatcher< + typename AllOfResult4::type, + typename AllOfResult5::type + > type; +}; + +template +struct AllOfResult10 { + typedef BothOfMatcher< + typename AllOfResult5::type, + typename AllOfResult5::type + > type; +}; + +// A set of metafunctions for computing the result type of AnyOf. +// AnyOf(m1, ..., mN) returns +// AnyOfResultN::type. + +// Although AnyOf isn't defined for one argument, AnyOfResult1 is defined +// to simplify the implementation. +template +struct AnyOfResult1 { + typedef M1 type; +}; + +template +struct AnyOfResult2 { + typedef EitherOfMatcher< + typename AnyOfResult1::type, + typename AnyOfResult1::type + > type; +}; + +template +struct AnyOfResult3 { + typedef EitherOfMatcher< + typename AnyOfResult1::type, + typename AnyOfResult2::type + > type; +}; + +template +struct AnyOfResult4 { + typedef EitherOfMatcher< + typename AnyOfResult2::type, + typename AnyOfResult2::type + > type; +}; + +template +struct AnyOfResult5 { + typedef EitherOfMatcher< + typename AnyOfResult2::type, + typename AnyOfResult3::type + > type; +}; + +template +struct AnyOfResult6 { + typedef EitherOfMatcher< + typename AnyOfResult3::type, + typename AnyOfResult3::type + > type; +}; + +template +struct AnyOfResult7 { + typedef EitherOfMatcher< + typename AnyOfResult3::type, + typename AnyOfResult4::type + > type; +}; + +template +struct AnyOfResult8 { + typedef EitherOfMatcher< + typename AnyOfResult4::type, + typename AnyOfResult4::type + > type; +}; + +template +struct AnyOfResult9 { + typedef EitherOfMatcher< + typename AnyOfResult4::type, + typename AnyOfResult5::type + > type; +}; + +template +struct AnyOfResult10 { + typedef EitherOfMatcher< + typename AnyOfResult5::type, + typename AnyOfResult5::type + > type; +}; + +} // namespace internal + +// Args(a_matcher) matches a tuple if the selected +// fields of it matches a_matcher. C++ doesn't support default +// arguments for function templates, so we have to overload it. +template +inline internal::ArgsMatcher +Args(const InnerMatcher& matcher) { + return internal::ArgsMatcher(matcher); +} + +template +inline internal::ArgsMatcher +Args(const InnerMatcher& matcher) { + return internal::ArgsMatcher(matcher); +} + +template +inline internal::ArgsMatcher +Args(const InnerMatcher& matcher) { + return internal::ArgsMatcher(matcher); +} + +template +inline internal::ArgsMatcher +Args(const InnerMatcher& matcher) { + return internal::ArgsMatcher(matcher); +} + +template +inline internal::ArgsMatcher +Args(const InnerMatcher& matcher) { + return internal::ArgsMatcher(matcher); +} + +template +inline internal::ArgsMatcher +Args(const InnerMatcher& matcher) { + return internal::ArgsMatcher(matcher); +} + +template +inline internal::ArgsMatcher +Args(const InnerMatcher& matcher) { + return internal::ArgsMatcher(matcher); +} + +template +inline internal::ArgsMatcher +Args(const InnerMatcher& matcher) { + return internal::ArgsMatcher(matcher); +} + +template +inline internal::ArgsMatcher +Args(const InnerMatcher& matcher) { + return internal::ArgsMatcher(matcher); +} + +template +inline internal::ArgsMatcher +Args(const InnerMatcher& matcher) { + return internal::ArgsMatcher(matcher); +} + +template +inline internal::ArgsMatcher +Args(const InnerMatcher& matcher) { + return internal::ArgsMatcher(matcher); +} + +// ElementsAre(e_1, e_2, ... e_n) matches an STL-style container with +// n elements, where the i-th element in the container must +// match the i-th argument in the list. Each argument of +// ElementsAre() can be either a value or a matcher. We support up to +// 10 arguments. +// +// The use of DecayArray in the implementation allows ElementsAre() +// to accept string literals, whose type is const char[N], but we +// want to treat them as const char*. +// +// NOTE: Since ElementsAre() cares about the order of the elements, it +// must not be used with containers whose elements's order is +// undefined (e.g. hash_map). + +inline internal::ElementsAreMatcher< + std::tr1::tuple<> > +ElementsAre() { + typedef std::tr1::tuple<> Args; + return internal::ElementsAreMatcher(Args()); +} + +template +inline internal::ElementsAreMatcher< + std::tr1::tuple< + typename internal::DecayArray::type> > +ElementsAre(const T1& e1) { + typedef std::tr1::tuple< + typename internal::DecayArray::type> Args; + return internal::ElementsAreMatcher(Args(e1)); +} + +template +inline internal::ElementsAreMatcher< + std::tr1::tuple< + typename internal::DecayArray::type, + typename internal::DecayArray::type> > +ElementsAre(const T1& e1, const T2& e2) { + typedef std::tr1::tuple< + typename internal::DecayArray::type, + typename internal::DecayArray::type> Args; + return internal::ElementsAreMatcher(Args(e1, e2)); +} + +template +inline internal::ElementsAreMatcher< + std::tr1::tuple< + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type> > +ElementsAre(const T1& e1, const T2& e2, const T3& e3) { + typedef std::tr1::tuple< + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type> Args; + return internal::ElementsAreMatcher(Args(e1, e2, e3)); +} + +template +inline internal::ElementsAreMatcher< + std::tr1::tuple< + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type> > +ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4) { + typedef std::tr1::tuple< + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type> Args; + return internal::ElementsAreMatcher(Args(e1, e2, e3, e4)); +} + +template +inline internal::ElementsAreMatcher< + std::tr1::tuple< + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type> > +ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4, + const T5& e5) { + typedef std::tr1::tuple< + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type> Args; + return internal::ElementsAreMatcher(Args(e1, e2, e3, e4, e5)); +} + +template +inline internal::ElementsAreMatcher< + std::tr1::tuple< + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type> > +ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4, + const T5& e5, const T6& e6) { + typedef std::tr1::tuple< + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type> Args; + return internal::ElementsAreMatcher(Args(e1, e2, e3, e4, e5, e6)); +} + +template +inline internal::ElementsAreMatcher< + std::tr1::tuple< + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type> > +ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4, + const T5& e5, const T6& e6, const T7& e7) { + typedef std::tr1::tuple< + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type> Args; + return internal::ElementsAreMatcher(Args(e1, e2, e3, e4, e5, e6, e7)); +} + +template +inline internal::ElementsAreMatcher< + std::tr1::tuple< + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type> > +ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4, + const T5& e5, const T6& e6, const T7& e7, const T8& e8) { + typedef std::tr1::tuple< + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type> Args; + return internal::ElementsAreMatcher(Args(e1, e2, e3, e4, e5, e6, e7, + e8)); +} + +template +inline internal::ElementsAreMatcher< + std::tr1::tuple< + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type> > +ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4, + const T5& e5, const T6& e6, const T7& e7, const T8& e8, const T9& e9) { + typedef std::tr1::tuple< + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type> Args; + return internal::ElementsAreMatcher(Args(e1, e2, e3, e4, e5, e6, e7, + e8, e9)); +} + +template +inline internal::ElementsAreMatcher< + std::tr1::tuple< + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type> > +ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4, + const T5& e5, const T6& e6, const T7& e7, const T8& e8, const T9& e9, + const T10& e10) { + typedef std::tr1::tuple< + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type> Args; + return internal::ElementsAreMatcher(Args(e1, e2, e3, e4, e5, e6, e7, + e8, e9, e10)); +} + +// UnorderedElementsAre(e_1, e_2, ..., e_n) is an ElementsAre extension +// that matches n elements in any order. We support up to n=10 arguments. + +inline internal::UnorderedElementsAreMatcher< + std::tr1::tuple<> > +UnorderedElementsAre() { + typedef std::tr1::tuple<> Args; + return internal::UnorderedElementsAreMatcher(Args()); +} + +template +inline internal::UnorderedElementsAreMatcher< + std::tr1::tuple< + typename internal::DecayArray::type> > +UnorderedElementsAre(const T1& e1) { + typedef std::tr1::tuple< + typename internal::DecayArray::type> Args; + return internal::UnorderedElementsAreMatcher(Args(e1)); +} + +template +inline internal::UnorderedElementsAreMatcher< + std::tr1::tuple< + typename internal::DecayArray::type, + typename internal::DecayArray::type> > +UnorderedElementsAre(const T1& e1, const T2& e2) { + typedef std::tr1::tuple< + typename internal::DecayArray::type, + typename internal::DecayArray::type> Args; + return internal::UnorderedElementsAreMatcher(Args(e1, e2)); +} + +template +inline internal::UnorderedElementsAreMatcher< + std::tr1::tuple< + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type> > +UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3) { + typedef std::tr1::tuple< + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type> Args; + return internal::UnorderedElementsAreMatcher(Args(e1, e2, e3)); +} + +template +inline internal::UnorderedElementsAreMatcher< + std::tr1::tuple< + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type> > +UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4) { + typedef std::tr1::tuple< + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type> Args; + return internal::UnorderedElementsAreMatcher(Args(e1, e2, e3, e4)); +} + +template +inline internal::UnorderedElementsAreMatcher< + std::tr1::tuple< + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type> > +UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4, + const T5& e5) { + typedef std::tr1::tuple< + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type> Args; + return internal::UnorderedElementsAreMatcher(Args(e1, e2, e3, e4, e5)); +} + +template +inline internal::UnorderedElementsAreMatcher< + std::tr1::tuple< + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type> > +UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4, + const T5& e5, const T6& e6) { + typedef std::tr1::tuple< + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type> Args; + return internal::UnorderedElementsAreMatcher(Args(e1, e2, e3, e4, e5, + e6)); +} + +template +inline internal::UnorderedElementsAreMatcher< + std::tr1::tuple< + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type> > +UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4, + const T5& e5, const T6& e6, const T7& e7) { + typedef std::tr1::tuple< + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type> Args; + return internal::UnorderedElementsAreMatcher(Args(e1, e2, e3, e4, e5, + e6, e7)); +} + +template +inline internal::UnorderedElementsAreMatcher< + std::tr1::tuple< + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type> > +UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4, + const T5& e5, const T6& e6, const T7& e7, const T8& e8) { + typedef std::tr1::tuple< + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type> Args; + return internal::UnorderedElementsAreMatcher(Args(e1, e2, e3, e4, e5, + e6, e7, e8)); +} + +template +inline internal::UnorderedElementsAreMatcher< + std::tr1::tuple< + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type> > +UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4, + const T5& e5, const T6& e6, const T7& e7, const T8& e8, const T9& e9) { + typedef std::tr1::tuple< + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type> Args; + return internal::UnorderedElementsAreMatcher(Args(e1, e2, e3, e4, e5, + e6, e7, e8, e9)); +} + +template +inline internal::UnorderedElementsAreMatcher< + std::tr1::tuple< + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type> > +UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4, + const T5& e5, const T6& e6, const T7& e7, const T8& e8, const T9& e9, + const T10& e10) { + typedef std::tr1::tuple< + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type> Args; + return internal::UnorderedElementsAreMatcher(Args(e1, e2, e3, e4, e5, + e6, e7, e8, e9, e10)); +} + +// AllOf(m1, m2, ..., mk) matches any value that matches all of the given +// sub-matchers. AllOf is called fully qualified to prevent ADL from firing. + +template +inline typename internal::AllOfResult2::type +AllOf(M1 m1, M2 m2) { + return typename internal::AllOfResult2::type( + m1, + m2); +} + +template +inline typename internal::AllOfResult3::type +AllOf(M1 m1, M2 m2, M3 m3) { + return typename internal::AllOfResult3::type( + m1, + ::testing::AllOf(m2, m3)); +} + +template +inline typename internal::AllOfResult4::type +AllOf(M1 m1, M2 m2, M3 m3, M4 m4) { + return typename internal::AllOfResult4::type( + ::testing::AllOf(m1, m2), + ::testing::AllOf(m3, m4)); +} + +template +inline typename internal::AllOfResult5::type +AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5) { + return typename internal::AllOfResult5::type( + ::testing::AllOf(m1, m2), + ::testing::AllOf(m3, m4, m5)); +} + +template +inline typename internal::AllOfResult6::type +AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6) { + return typename internal::AllOfResult6::type( + ::testing::AllOf(m1, m2, m3), + ::testing::AllOf(m4, m5, m6)); +} + +template +inline typename internal::AllOfResult7::type +AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7) { + return typename internal::AllOfResult7::type( + ::testing::AllOf(m1, m2, m3), + ::testing::AllOf(m4, m5, m6, m7)); +} + +template +inline typename internal::AllOfResult8::type +AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8) { + return typename internal::AllOfResult8::type( + ::testing::AllOf(m1, m2, m3, m4), + ::testing::AllOf(m5, m6, m7, m8)); +} + +template +inline typename internal::AllOfResult9::type +AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9) { + return typename internal::AllOfResult9::type( + ::testing::AllOf(m1, m2, m3, m4), + ::testing::AllOf(m5, m6, m7, m8, m9)); +} + +template +inline typename internal::AllOfResult10::type +AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { + return typename internal::AllOfResult10::type( + ::testing::AllOf(m1, m2, m3, m4, m5), + ::testing::AllOf(m6, m7, m8, m9, m10)); +} + +// AnyOf(m1, m2, ..., mk) matches any value that matches any of the given +// sub-matchers. AnyOf is called fully qualified to prevent ADL from firing. + +template +inline typename internal::AnyOfResult2::type +AnyOf(M1 m1, M2 m2) { + return typename internal::AnyOfResult2::type( + m1, + m2); +} + +template +inline typename internal::AnyOfResult3::type +AnyOf(M1 m1, M2 m2, M3 m3) { + return typename internal::AnyOfResult3::type( + m1, + ::testing::AnyOf(m2, m3)); +} + +template +inline typename internal::AnyOfResult4::type +AnyOf(M1 m1, M2 m2, M3 m3, M4 m4) { + return typename internal::AnyOfResult4::type( + ::testing::AnyOf(m1, m2), + ::testing::AnyOf(m3, m4)); +} + +template +inline typename internal::AnyOfResult5::type +AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5) { + return typename internal::AnyOfResult5::type( + ::testing::AnyOf(m1, m2), + ::testing::AnyOf(m3, m4, m5)); +} + +template +inline typename internal::AnyOfResult6::type +AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6) { + return typename internal::AnyOfResult6::type( + ::testing::AnyOf(m1, m2, m3), + ::testing::AnyOf(m4, m5, m6)); +} + +template +inline typename internal::AnyOfResult7::type +AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7) { + return typename internal::AnyOfResult7::type( + ::testing::AnyOf(m1, m2, m3), + ::testing::AnyOf(m4, m5, m6, m7)); +} + +template +inline typename internal::AnyOfResult8::type +AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8) { + return typename internal::AnyOfResult8::type( + ::testing::AnyOf(m1, m2, m3, m4), + ::testing::AnyOf(m5, m6, m7, m8)); +} + +template +inline typename internal::AnyOfResult9::type +AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9) { + return typename internal::AnyOfResult9::type( + ::testing::AnyOf(m1, m2, m3, m4), + ::testing::AnyOf(m5, m6, m7, m8, m9)); +} + +template +inline typename internal::AnyOfResult10::type +AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { + return typename internal::AnyOfResult10::type( + ::testing::AnyOf(m1, m2, m3, m4, m5), + ::testing::AnyOf(m6, m7, m8, m9, m10)); +} + +} // namespace testing + + +// The MATCHER* family of macros can be used in a namespace scope to +// define custom matchers easily. +// +// Basic Usage +// =========== +// +// The syntax +// +// MATCHER(name, description_string) { statements; } +// +// defines a matcher with the given name that executes the statements, +// which must return a bool to indicate if the match succeeds. Inside +// the statements, you can refer to the value being matched by 'arg', +// and refer to its type by 'arg_type'. +// +// The description string documents what the matcher does, and is used +// to generate the failure message when the match fails. Since a +// MATCHER() is usually defined in a header file shared by multiple +// C++ source files, we require the description to be a C-string +// literal to avoid possible side effects. It can be empty, in which +// case we'll use the sequence of words in the matcher name as the +// description. +// +// For example: +// +// MATCHER(IsEven, "") { return (arg % 2) == 0; } +// +// allows you to write +// +// // Expects mock_foo.Bar(n) to be called where n is even. +// EXPECT_CALL(mock_foo, Bar(IsEven())); +// +// or, +// +// // Verifies that the value of some_expression is even. +// EXPECT_THAT(some_expression, IsEven()); +// +// If the above assertion fails, it will print something like: +// +// Value of: some_expression +// Expected: is even +// Actual: 7 +// +// where the description "is even" is automatically calculated from the +// matcher name IsEven. +// +// Argument Type +// ============= +// +// Note that the type of the value being matched (arg_type) is +// determined by the context in which you use the matcher and is +// supplied to you by the compiler, so you don't need to worry about +// declaring it (nor can you). This allows the matcher to be +// polymorphic. For example, IsEven() can be used to match any type +// where the value of "(arg % 2) == 0" can be implicitly converted to +// a bool. In the "Bar(IsEven())" example above, if method Bar() +// takes an int, 'arg_type' will be int; if it takes an unsigned long, +// 'arg_type' will be unsigned long; and so on. +// +// Parameterizing Matchers +// ======================= +// +// Sometimes you'll want to parameterize the matcher. For that you +// can use another macro: +// +// MATCHER_P(name, param_name, description_string) { statements; } +// +// For example: +// +// MATCHER_P(HasAbsoluteValue, value, "") { return abs(arg) == value; } +// +// will allow you to write: +// +// EXPECT_THAT(Blah("a"), HasAbsoluteValue(n)); +// +// which may lead to this message (assuming n is 10): +// +// Value of: Blah("a") +// Expected: has absolute value 10 +// Actual: -9 +// +// Note that both the matcher description and its parameter are +// printed, making the message human-friendly. +// +// In the matcher definition body, you can write 'foo_type' to +// reference the type of a parameter named 'foo'. For example, in the +// body of MATCHER_P(HasAbsoluteValue, value) above, you can write +// 'value_type' to refer to the type of 'value'. +// +// We also provide MATCHER_P2, MATCHER_P3, ..., up to MATCHER_P10 to +// support multi-parameter matchers. +// +// Describing Parameterized Matchers +// ================================= +// +// The last argument to MATCHER*() is a string-typed expression. The +// expression can reference all of the matcher's parameters and a +// special bool-typed variable named 'negation'. When 'negation' is +// false, the expression should evaluate to the matcher's description; +// otherwise it should evaluate to the description of the negation of +// the matcher. For example, +// +// using testing::PrintToString; +// +// MATCHER_P2(InClosedRange, low, hi, +// string(negation ? "is not" : "is") + " in range [" + +// PrintToString(low) + ", " + PrintToString(hi) + "]") { +// return low <= arg && arg <= hi; +// } +// ... +// EXPECT_THAT(3, InClosedRange(4, 6)); +// EXPECT_THAT(3, Not(InClosedRange(2, 4))); +// +// would generate two failures that contain the text: +// +// Expected: is in range [4, 6] +// ... +// Expected: is not in range [2, 4] +// +// If you specify "" as the description, the failure message will +// contain the sequence of words in the matcher name followed by the +// parameter values printed as a tuple. For example, +// +// MATCHER_P2(InClosedRange, low, hi, "") { ... } +// ... +// EXPECT_THAT(3, InClosedRange(4, 6)); +// EXPECT_THAT(3, Not(InClosedRange(2, 4))); +// +// would generate two failures that contain the text: +// +// Expected: in closed range (4, 6) +// ... +// Expected: not (in closed range (2, 4)) +// +// Types of Matcher Parameters +// =========================== +// +// For the purpose of typing, you can view +// +// MATCHER_Pk(Foo, p1, ..., pk, description_string) { ... } +// +// as shorthand for +// +// template +// FooMatcherPk +// Foo(p1_type p1, ..., pk_type pk) { ... } +// +// When you write Foo(v1, ..., vk), the compiler infers the types of +// the parameters v1, ..., and vk for you. If you are not happy with +// the result of the type inference, you can specify the types by +// explicitly instantiating the template, as in Foo(5, +// false). As said earlier, you don't get to (or need to) specify +// 'arg_type' as that's determined by the context in which the matcher +// is used. You can assign the result of expression Foo(p1, ..., pk) +// to a variable of type FooMatcherPk. This +// can be useful when composing matchers. +// +// While you can instantiate a matcher template with reference types, +// passing the parameters by pointer usually makes your code more +// readable. If, however, you still want to pass a parameter by +// reference, be aware that in the failure message generated by the +// matcher you will see the value of the referenced object but not its +// address. +// +// Explaining Match Results +// ======================== +// +// Sometimes the matcher description alone isn't enough to explain why +// the match has failed or succeeded. For example, when expecting a +// long string, it can be very helpful to also print the diff between +// the expected string and the actual one. To achieve that, you can +// optionally stream additional information to a special variable +// named result_listener, whose type is a pointer to class +// MatchResultListener: +// +// MATCHER_P(EqualsLongString, str, "") { +// if (arg == str) return true; +// +// *result_listener << "the difference: " +/// << DiffStrings(str, arg); +// return false; +// } +// +// Overloading Matchers +// ==================== +// +// You can overload matchers with different numbers of parameters: +// +// MATCHER_P(Blah, a, description_string1) { ... } +// MATCHER_P2(Blah, a, b, description_string2) { ... } +// +// Caveats +// ======= +// +// When defining a new matcher, you should also consider implementing +// MatcherInterface or using MakePolymorphicMatcher(). These +// approaches require more work than the MATCHER* macros, but also +// give you more control on the types of the value being matched and +// the matcher parameters, which may leads to better compiler error +// messages when the matcher is used wrong. They also allow +// overloading matchers based on parameter types (as opposed to just +// based on the number of parameters). +// +// MATCHER*() can only be used in a namespace scope. The reason is +// that C++ doesn't yet allow function-local types to be used to +// instantiate templates. The up-coming C++0x standard will fix this. +// Once that's done, we'll consider supporting using MATCHER*() inside +// a function. +// +// More Information +// ================ +// +// To learn more about using these macros, please search for 'MATCHER' +// on http://code.google.com/p/googlemock/wiki/CookBook. + +#define MATCHER(name, description)\ + class name##Matcher {\ + public:\ + template \ + class gmock_Impl : public ::testing::MatcherInterface {\ + public:\ + gmock_Impl()\ + {}\ + virtual bool MatchAndExplain(\ + arg_type arg, ::testing::MatchResultListener* result_listener) const;\ + virtual void DescribeTo(::std::ostream* gmock_os) const {\ + *gmock_os << FormatDescription(false);\ + }\ + virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ + *gmock_os << FormatDescription(true);\ + }\ + private:\ + ::testing::internal::string FormatDescription(bool negation) const {\ + const ::testing::internal::string gmock_description = (description);\ + if (!gmock_description.empty())\ + return gmock_description;\ + return ::testing::internal::FormatMatcherDescription(\ + negation, #name, \ + ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ + ::std::tr1::tuple<>()));\ + }\ + GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ + };\ + template \ + operator ::testing::Matcher() const {\ + return ::testing::Matcher(\ + new gmock_Impl());\ + }\ + name##Matcher() {\ + }\ + private:\ + GTEST_DISALLOW_ASSIGN_(name##Matcher);\ + };\ + inline name##Matcher name() {\ + return name##Matcher();\ + }\ + template \ + bool name##Matcher::gmock_Impl::MatchAndExplain(\ + arg_type arg, \ + ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ + const + +#define MATCHER_P(name, p0, description)\ + template \ + class name##MatcherP {\ + public:\ + template \ + class gmock_Impl : public ::testing::MatcherInterface {\ + public:\ + explicit gmock_Impl(p0##_type gmock_p0)\ + : p0(gmock_p0) {}\ + virtual bool MatchAndExplain(\ + arg_type arg, ::testing::MatchResultListener* result_listener) const;\ + virtual void DescribeTo(::std::ostream* gmock_os) const {\ + *gmock_os << FormatDescription(false);\ + }\ + virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ + *gmock_os << FormatDescription(true);\ + }\ + p0##_type p0;\ + private:\ + ::testing::internal::string FormatDescription(bool negation) const {\ + const ::testing::internal::string gmock_description = (description);\ + if (!gmock_description.empty())\ + return gmock_description;\ + return ::testing::internal::FormatMatcherDescription(\ + negation, #name, \ + ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ + ::std::tr1::tuple(p0)));\ + }\ + GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ + };\ + template \ + operator ::testing::Matcher() const {\ + return ::testing::Matcher(\ + new gmock_Impl(p0));\ + }\ + name##MatcherP(p0##_type gmock_p0) : p0(gmock_p0) {\ + }\ + p0##_type p0;\ + private:\ + GTEST_DISALLOW_ASSIGN_(name##MatcherP);\ + };\ + template \ + inline name##MatcherP name(p0##_type p0) {\ + return name##MatcherP(p0);\ + }\ + template \ + template \ + bool name##MatcherP::gmock_Impl::MatchAndExplain(\ + arg_type arg, \ + ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ + const + +#define MATCHER_P2(name, p0, p1, description)\ + template \ + class name##MatcherP2 {\ + public:\ + template \ + class gmock_Impl : public ::testing::MatcherInterface {\ + public:\ + gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1)\ + : p0(gmock_p0), p1(gmock_p1) {}\ + virtual bool MatchAndExplain(\ + arg_type arg, ::testing::MatchResultListener* result_listener) const;\ + virtual void DescribeTo(::std::ostream* gmock_os) const {\ + *gmock_os << FormatDescription(false);\ + }\ + virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ + *gmock_os << FormatDescription(true);\ + }\ + p0##_type p0;\ + p1##_type p1;\ + private:\ + ::testing::internal::string FormatDescription(bool negation) const {\ + const ::testing::internal::string gmock_description = (description);\ + if (!gmock_description.empty())\ + return gmock_description;\ + return ::testing::internal::FormatMatcherDescription(\ + negation, #name, \ + ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ + ::std::tr1::tuple(p0, p1)));\ + }\ + GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ + };\ + template \ + operator ::testing::Matcher() const {\ + return ::testing::Matcher(\ + new gmock_Impl(p0, p1));\ + }\ + name##MatcherP2(p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), \ + p1(gmock_p1) {\ + }\ + p0##_type p0;\ + p1##_type p1;\ + private:\ + GTEST_DISALLOW_ASSIGN_(name##MatcherP2);\ + };\ + template \ + inline name##MatcherP2 name(p0##_type p0, \ + p1##_type p1) {\ + return name##MatcherP2(p0, p1);\ + }\ + template \ + template \ + bool name##MatcherP2::gmock_Impl::MatchAndExplain(\ + arg_type arg, \ + ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ + const + +#define MATCHER_P3(name, p0, p1, p2, description)\ + template \ + class name##MatcherP3 {\ + public:\ + template \ + class gmock_Impl : public ::testing::MatcherInterface {\ + public:\ + gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2)\ + : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {}\ + virtual bool MatchAndExplain(\ + arg_type arg, ::testing::MatchResultListener* result_listener) const;\ + virtual void DescribeTo(::std::ostream* gmock_os) const {\ + *gmock_os << FormatDescription(false);\ + }\ + virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ + *gmock_os << FormatDescription(true);\ + }\ + p0##_type p0;\ + p1##_type p1;\ + p2##_type p2;\ + private:\ + ::testing::internal::string FormatDescription(bool negation) const {\ + const ::testing::internal::string gmock_description = (description);\ + if (!gmock_description.empty())\ + return gmock_description;\ + return ::testing::internal::FormatMatcherDescription(\ + negation, #name, \ + ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ + ::std::tr1::tuple(p0, p1, \ + p2)));\ + }\ + GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ + };\ + template \ + operator ::testing::Matcher() const {\ + return ::testing::Matcher(\ + new gmock_Impl(p0, p1, p2));\ + }\ + name##MatcherP3(p0##_type gmock_p0, p1##_type gmock_p1, \ + p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {\ + }\ + p0##_type p0;\ + p1##_type p1;\ + p2##_type p2;\ + private:\ + GTEST_DISALLOW_ASSIGN_(name##MatcherP3);\ + };\ + template \ + inline name##MatcherP3 name(p0##_type p0, \ + p1##_type p1, p2##_type p2) {\ + return name##MatcherP3(p0, p1, p2);\ + }\ + template \ + template \ + bool name##MatcherP3::gmock_Impl::MatchAndExplain(\ + arg_type arg, \ + ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ + const + +#define MATCHER_P4(name, p0, p1, p2, p3, description)\ + template \ + class name##MatcherP4 {\ + public:\ + template \ + class gmock_Impl : public ::testing::MatcherInterface {\ + public:\ + gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ + p3##_type gmock_p3)\ + : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3) {}\ + virtual bool MatchAndExplain(\ + arg_type arg, ::testing::MatchResultListener* result_listener) const;\ + virtual void DescribeTo(::std::ostream* gmock_os) const {\ + *gmock_os << FormatDescription(false);\ + }\ + virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ + *gmock_os << FormatDescription(true);\ + }\ + p0##_type p0;\ + p1##_type p1;\ + p2##_type p2;\ + p3##_type p3;\ + private:\ + ::testing::internal::string FormatDescription(bool negation) const {\ + const ::testing::internal::string gmock_description = (description);\ + if (!gmock_description.empty())\ + return gmock_description;\ + return ::testing::internal::FormatMatcherDescription(\ + negation, #name, \ + ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ + ::std::tr1::tuple(p0, p1, p2, p3)));\ + }\ + GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ + };\ + template \ + operator ::testing::Matcher() const {\ + return ::testing::Matcher(\ + new gmock_Impl(p0, p1, p2, p3));\ + }\ + name##MatcherP4(p0##_type gmock_p0, p1##_type gmock_p1, \ + p2##_type gmock_p2, p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), \ + p2(gmock_p2), p3(gmock_p3) {\ + }\ + p0##_type p0;\ + p1##_type p1;\ + p2##_type p2;\ + p3##_type p3;\ + private:\ + GTEST_DISALLOW_ASSIGN_(name##MatcherP4);\ + };\ + template \ + inline name##MatcherP4 name(p0##_type p0, p1##_type p1, p2##_type p2, \ + p3##_type p3) {\ + return name##MatcherP4(p0, \ + p1, p2, p3);\ + }\ + template \ + template \ + bool name##MatcherP4::gmock_Impl::MatchAndExplain(\ + arg_type arg, \ + ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ + const + +#define MATCHER_P5(name, p0, p1, p2, p3, p4, description)\ + template \ + class name##MatcherP5 {\ + public:\ + template \ + class gmock_Impl : public ::testing::MatcherInterface {\ + public:\ + gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ + p3##_type gmock_p3, p4##_type gmock_p4)\ + : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \ + p4(gmock_p4) {}\ + virtual bool MatchAndExplain(\ + arg_type arg, ::testing::MatchResultListener* result_listener) const;\ + virtual void DescribeTo(::std::ostream* gmock_os) const {\ + *gmock_os << FormatDescription(false);\ + }\ + virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ + *gmock_os << FormatDescription(true);\ + }\ + p0##_type p0;\ + p1##_type p1;\ + p2##_type p2;\ + p3##_type p3;\ + p4##_type p4;\ + private:\ + ::testing::internal::string FormatDescription(bool negation) const {\ + const ::testing::internal::string gmock_description = (description);\ + if (!gmock_description.empty())\ + return gmock_description;\ + return ::testing::internal::FormatMatcherDescription(\ + negation, #name, \ + ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ + ::std::tr1::tuple(p0, p1, p2, p3, p4)));\ + }\ + GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ + };\ + template \ + operator ::testing::Matcher() const {\ + return ::testing::Matcher(\ + new gmock_Impl(p0, p1, p2, p3, p4));\ + }\ + name##MatcherP5(p0##_type gmock_p0, p1##_type gmock_p1, \ + p2##_type gmock_p2, p3##_type gmock_p3, \ + p4##_type gmock_p4) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ + p3(gmock_p3), p4(gmock_p4) {\ + }\ + p0##_type p0;\ + p1##_type p1;\ + p2##_type p2;\ + p3##_type p3;\ + p4##_type p4;\ + private:\ + GTEST_DISALLOW_ASSIGN_(name##MatcherP5);\ + };\ + template \ + inline name##MatcherP5 name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \ + p4##_type p4) {\ + return name##MatcherP5(p0, p1, p2, p3, p4);\ + }\ + template \ + template \ + bool name##MatcherP5::gmock_Impl::MatchAndExplain(\ + arg_type arg, \ + ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ + const + +#define MATCHER_P6(name, p0, p1, p2, p3, p4, p5, description)\ + template \ + class name##MatcherP6 {\ + public:\ + template \ + class gmock_Impl : public ::testing::MatcherInterface {\ + public:\ + gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ + p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5)\ + : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \ + p4(gmock_p4), p5(gmock_p5) {}\ + virtual bool MatchAndExplain(\ + arg_type arg, ::testing::MatchResultListener* result_listener) const;\ + virtual void DescribeTo(::std::ostream* gmock_os) const {\ + *gmock_os << FormatDescription(false);\ + }\ + virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ + *gmock_os << FormatDescription(true);\ + }\ + p0##_type p0;\ + p1##_type p1;\ + p2##_type p2;\ + p3##_type p3;\ + p4##_type p4;\ + p5##_type p5;\ + private:\ + ::testing::internal::string FormatDescription(bool negation) const {\ + const ::testing::internal::string gmock_description = (description);\ + if (!gmock_description.empty())\ + return gmock_description;\ + return ::testing::internal::FormatMatcherDescription(\ + negation, #name, \ + ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ + ::std::tr1::tuple(p0, p1, p2, p3, p4, p5)));\ + }\ + GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ + };\ + template \ + operator ::testing::Matcher() const {\ + return ::testing::Matcher(\ + new gmock_Impl(p0, p1, p2, p3, p4, p5));\ + }\ + name##MatcherP6(p0##_type gmock_p0, p1##_type gmock_p1, \ + p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \ + p5##_type gmock_p5) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ + p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) {\ + }\ + p0##_type p0;\ + p1##_type p1;\ + p2##_type p2;\ + p3##_type p3;\ + p4##_type p4;\ + p5##_type p5;\ + private:\ + GTEST_DISALLOW_ASSIGN_(name##MatcherP6);\ + };\ + template \ + inline name##MatcherP6 name(p0##_type p0, p1##_type p1, p2##_type p2, \ + p3##_type p3, p4##_type p4, p5##_type p5) {\ + return name##MatcherP6(p0, p1, p2, p3, p4, p5);\ + }\ + template \ + template \ + bool name##MatcherP6::gmock_Impl::MatchAndExplain(\ + arg_type arg, \ + ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ + const + +#define MATCHER_P7(name, p0, p1, p2, p3, p4, p5, p6, description)\ + template \ + class name##MatcherP7 {\ + public:\ + template \ + class gmock_Impl : public ::testing::MatcherInterface {\ + public:\ + gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ + p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ + p6##_type gmock_p6)\ + : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \ + p4(gmock_p4), p5(gmock_p5), p6(gmock_p6) {}\ + virtual bool MatchAndExplain(\ + arg_type arg, ::testing::MatchResultListener* result_listener) const;\ + virtual void DescribeTo(::std::ostream* gmock_os) const {\ + *gmock_os << FormatDescription(false);\ + }\ + virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ + *gmock_os << FormatDescription(true);\ + }\ + p0##_type p0;\ + p1##_type p1;\ + p2##_type p2;\ + p3##_type p3;\ + p4##_type p4;\ + p5##_type p5;\ + p6##_type p6;\ + private:\ + ::testing::internal::string FormatDescription(bool negation) const {\ + const ::testing::internal::string gmock_description = (description);\ + if (!gmock_description.empty())\ + return gmock_description;\ + return ::testing::internal::FormatMatcherDescription(\ + negation, #name, \ + ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ + ::std::tr1::tuple(p0, p1, p2, p3, p4, p5, \ + p6)));\ + }\ + GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ + };\ + template \ + operator ::testing::Matcher() const {\ + return ::testing::Matcher(\ + new gmock_Impl(p0, p1, p2, p3, p4, p5, p6));\ + }\ + name##MatcherP7(p0##_type gmock_p0, p1##_type gmock_p1, \ + p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \ + p5##_type gmock_p5, p6##_type gmock_p6) : p0(gmock_p0), p1(gmock_p1), \ + p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), \ + p6(gmock_p6) {\ + }\ + p0##_type p0;\ + p1##_type p1;\ + p2##_type p2;\ + p3##_type p3;\ + p4##_type p4;\ + p5##_type p5;\ + p6##_type p6;\ + private:\ + GTEST_DISALLOW_ASSIGN_(name##MatcherP7);\ + };\ + template \ + inline name##MatcherP7 name(p0##_type p0, p1##_type p1, \ + p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \ + p6##_type p6) {\ + return name##MatcherP7(p0, p1, p2, p3, p4, p5, p6);\ + }\ + template \ + template \ + bool name##MatcherP7::gmock_Impl::MatchAndExplain(\ + arg_type arg, \ + ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ + const + +#define MATCHER_P8(name, p0, p1, p2, p3, p4, p5, p6, p7, description)\ + template \ + class name##MatcherP8 {\ + public:\ + template \ + class gmock_Impl : public ::testing::MatcherInterface {\ + public:\ + gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ + p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ + p6##_type gmock_p6, p7##_type gmock_p7)\ + : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \ + p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7) {}\ + virtual bool MatchAndExplain(\ + arg_type arg, ::testing::MatchResultListener* result_listener) const;\ + virtual void DescribeTo(::std::ostream* gmock_os) const {\ + *gmock_os << FormatDescription(false);\ + }\ + virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ + *gmock_os << FormatDescription(true);\ + }\ + p0##_type p0;\ + p1##_type p1;\ + p2##_type p2;\ + p3##_type p3;\ + p4##_type p4;\ + p5##_type p5;\ + p6##_type p6;\ + p7##_type p7;\ + private:\ + ::testing::internal::string FormatDescription(bool negation) const {\ + const ::testing::internal::string gmock_description = (description);\ + if (!gmock_description.empty())\ + return gmock_description;\ + return ::testing::internal::FormatMatcherDescription(\ + negation, #name, \ + ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ + ::std::tr1::tuple(p0, p1, p2, \ + p3, p4, p5, p6, p7)));\ + }\ + GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ + };\ + template \ + operator ::testing::Matcher() const {\ + return ::testing::Matcher(\ + new gmock_Impl(p0, p1, p2, p3, p4, p5, p6, p7));\ + }\ + name##MatcherP8(p0##_type gmock_p0, p1##_type gmock_p1, \ + p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \ + p5##_type gmock_p5, p6##_type gmock_p6, \ + p7##_type gmock_p7) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ + p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \ + p7(gmock_p7) {\ + }\ + p0##_type p0;\ + p1##_type p1;\ + p2##_type p2;\ + p3##_type p3;\ + p4##_type p4;\ + p5##_type p5;\ + p6##_type p6;\ + p7##_type p7;\ + private:\ + GTEST_DISALLOW_ASSIGN_(name##MatcherP8);\ + };\ + template \ + inline name##MatcherP8 name(p0##_type p0, \ + p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \ + p6##_type p6, p7##_type p7) {\ + return name##MatcherP8(p0, p1, p2, p3, p4, p5, \ + p6, p7);\ + }\ + template \ + template \ + bool name##MatcherP8::gmock_Impl::MatchAndExplain(\ + arg_type arg, \ + ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ + const + +#define MATCHER_P9(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, description)\ + template \ + class name##MatcherP9 {\ + public:\ + template \ + class gmock_Impl : public ::testing::MatcherInterface {\ + public:\ + gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ + p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ + p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8)\ + : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \ + p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \ + p8(gmock_p8) {}\ + virtual bool MatchAndExplain(\ + arg_type arg, ::testing::MatchResultListener* result_listener) const;\ + virtual void DescribeTo(::std::ostream* gmock_os) const {\ + *gmock_os << FormatDescription(false);\ + }\ + virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ + *gmock_os << FormatDescription(true);\ + }\ + p0##_type p0;\ + p1##_type p1;\ + p2##_type p2;\ + p3##_type p3;\ + p4##_type p4;\ + p5##_type p5;\ + p6##_type p6;\ + p7##_type p7;\ + p8##_type p8;\ + private:\ + ::testing::internal::string FormatDescription(bool negation) const {\ + const ::testing::internal::string gmock_description = (description);\ + if (!gmock_description.empty())\ + return gmock_description;\ + return ::testing::internal::FormatMatcherDescription(\ + negation, #name, \ + ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ + ::std::tr1::tuple(p0, p1, p2, p3, p4, p5, p6, p7, p8)));\ + }\ + GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ + };\ + template \ + operator ::testing::Matcher() const {\ + return ::testing::Matcher(\ + new gmock_Impl(p0, p1, p2, p3, p4, p5, p6, p7, p8));\ + }\ + name##MatcherP9(p0##_type gmock_p0, p1##_type gmock_p1, \ + p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \ + p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \ + p8##_type gmock_p8) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ + p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \ + p8(gmock_p8) {\ + }\ + p0##_type p0;\ + p1##_type p1;\ + p2##_type p2;\ + p3##_type p3;\ + p4##_type p4;\ + p5##_type p5;\ + p6##_type p6;\ + p7##_type p7;\ + p8##_type p8;\ + private:\ + GTEST_DISALLOW_ASSIGN_(name##MatcherP9);\ + };\ + template \ + inline name##MatcherP9 name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \ + p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, \ + p8##_type p8) {\ + return name##MatcherP9(p0, p1, p2, \ + p3, p4, p5, p6, p7, p8);\ + }\ + template \ + template \ + bool name##MatcherP9::gmock_Impl::MatchAndExplain(\ + arg_type arg, \ + ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ + const + +#define MATCHER_P10(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, description)\ + template \ + class name##MatcherP10 {\ + public:\ + template \ + class gmock_Impl : public ::testing::MatcherInterface {\ + public:\ + gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ + p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ + p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8, \ + p9##_type gmock_p9)\ + : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \ + p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \ + p8(gmock_p8), p9(gmock_p9) {}\ + virtual bool MatchAndExplain(\ + arg_type arg, ::testing::MatchResultListener* result_listener) const;\ + virtual void DescribeTo(::std::ostream* gmock_os) const {\ + *gmock_os << FormatDescription(false);\ + }\ + virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ + *gmock_os << FormatDescription(true);\ + }\ + p0##_type p0;\ + p1##_type p1;\ + p2##_type p2;\ + p3##_type p3;\ + p4##_type p4;\ + p5##_type p5;\ + p6##_type p6;\ + p7##_type p7;\ + p8##_type p8;\ + p9##_type p9;\ + private:\ + ::testing::internal::string FormatDescription(bool negation) const {\ + const ::testing::internal::string gmock_description = (description);\ + if (!gmock_description.empty())\ + return gmock_description;\ + return ::testing::internal::FormatMatcherDescription(\ + negation, #name, \ + ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ + ::std::tr1::tuple(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)));\ + }\ + GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ + };\ + template \ + operator ::testing::Matcher() const {\ + return ::testing::Matcher(\ + new gmock_Impl(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9));\ + }\ + name##MatcherP10(p0##_type gmock_p0, p1##_type gmock_p1, \ + p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \ + p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \ + p8##_type gmock_p8, p9##_type gmock_p9) : p0(gmock_p0), p1(gmock_p1), \ + p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \ + p7(gmock_p7), p8(gmock_p8), p9(gmock_p9) {\ + }\ + p0##_type p0;\ + p1##_type p1;\ + p2##_type p2;\ + p3##_type p3;\ + p4##_type p4;\ + p5##_type p5;\ + p6##_type p6;\ + p7##_type p7;\ + p8##_type p8;\ + p9##_type p9;\ + private:\ + GTEST_DISALLOW_ASSIGN_(name##MatcherP10);\ + };\ + template \ + inline name##MatcherP10 name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \ + p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8, \ + p9##_type p9) {\ + return name##MatcherP10(p0, \ + p1, p2, p3, p4, p5, p6, p7, p8, p9);\ + }\ + template \ + template \ + bool name##MatcherP10::gmock_Impl::MatchAndExplain(\ + arg_type arg, \ + ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ + const + +#endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_ diff --git a/mbelib-wasm/mbelib/test/gmock/include/gmock/gmock-generated-matchers.h.pump b/mbelib-wasm/mbelib/test/gmock/include/gmock/gmock-generated-matchers.h.pump new file mode 100644 index 0000000..af02acb --- /dev/null +++ b/mbelib-wasm/mbelib/test/gmock/include/gmock/gmock-generated-matchers.h.pump @@ -0,0 +1,674 @@ +$$ -*- mode: c++; -*- +$$ This is a Pump source file. Please use Pump to convert it to +$$ gmock-generated-actions.h. +$$ +$var n = 10 $$ The maximum arity we support. +$$ }} This line fixes auto-indentation of the following code in Emacs. +// Copyright 2008, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// Google Mock - a framework for writing C++ mock classes. +// +// This file implements some commonly used variadic matchers. + +#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_ +#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_ + +#include +#include +#include +#include +#include "gmock/gmock-matchers.h" + +namespace testing { +namespace internal { + +$range i 0..n-1 + +// The type of the i-th (0-based) field of Tuple. +#define GMOCK_FIELD_TYPE_(Tuple, i) \ + typename ::std::tr1::tuple_element::type + +// TupleFields is for selecting fields from a +// tuple of type Tuple. It has two members: +// +// type: a tuple type whose i-th field is the ki-th field of Tuple. +// GetSelectedFields(t): returns fields k0, ..., and kn of t as a tuple. +// +// For example, in class TupleFields, 2, 0>, we have: +// +// type is tuple, and +// GetSelectedFields(make_tuple(true, 'a', 42)) is (42, true). + +template +class TupleFields; + +// This generic version is used when there are $n selectors. +template +class TupleFields { + public: + typedef ::std::tr1::tuple<$for i, [[GMOCK_FIELD_TYPE_(Tuple, k$i)]]> type; + static type GetSelectedFields(const Tuple& t) { + using ::std::tr1::get; + return type($for i, [[get(t)]]); + } +}; + +// The following specialization is used for 0 ~ $(n-1) selectors. + +$for i [[ +$$ }}} +$range j 0..i-1 +$range k 0..n-1 + +template +class TupleFields { + public: + typedef ::std::tr1::tuple<$for j, [[GMOCK_FIELD_TYPE_(Tuple, k$j)]]> type; + static type GetSelectedFields(const Tuple& $if i==0 [[/* t */]] $else [[t]]) { + using ::std::tr1::get; + return type($for j, [[get(t)]]); + } +}; + +]] + +#undef GMOCK_FIELD_TYPE_ + +// Implements the Args() matcher. + +$var ks = [[$for i, [[k$i]]]] +template +class ArgsMatcherImpl : public MatcherInterface { + public: + // ArgsTuple may have top-level const or reference modifiers. + typedef GTEST_REMOVE_REFERENCE_AND_CONST_(ArgsTuple) RawArgsTuple; + typedef typename internal::TupleFields::type SelectedArgs; + typedef Matcher MonomorphicInnerMatcher; + + template + explicit ArgsMatcherImpl(const InnerMatcher& inner_matcher) + : inner_matcher_(SafeMatcherCast(inner_matcher)) {} + + virtual bool MatchAndExplain(ArgsTuple args, + MatchResultListener* listener) const { + const SelectedArgs& selected_args = GetSelectedArgs(args); + if (!listener->IsInterested()) + return inner_matcher_.Matches(selected_args); + + PrintIndices(listener->stream()); + *listener << "are " << PrintToString(selected_args); + + StringMatchResultListener inner_listener; + const bool match = inner_matcher_.MatchAndExplain(selected_args, + &inner_listener); + PrintIfNotEmpty(inner_listener.str(), listener->stream()); + return match; + } + + virtual void DescribeTo(::std::ostream* os) const { + *os << "are a tuple "; + PrintIndices(os); + inner_matcher_.DescribeTo(os); + } + + virtual void DescribeNegationTo(::std::ostream* os) const { + *os << "are a tuple "; + PrintIndices(os); + inner_matcher_.DescribeNegationTo(os); + } + + private: + static SelectedArgs GetSelectedArgs(ArgsTuple args) { + return TupleFields::GetSelectedFields(args); + } + + // Prints the indices of the selected fields. + static void PrintIndices(::std::ostream* os) { + *os << "whose fields ("; + const int indices[$n] = { $ks }; + for (int i = 0; i < $n; i++) { + if (indices[i] < 0) + break; + + if (i >= 1) + *os << ", "; + + *os << "#" << indices[i]; + } + *os << ") "; + } + + const MonomorphicInnerMatcher inner_matcher_; + + GTEST_DISALLOW_ASSIGN_(ArgsMatcherImpl); +}; + +template +class ArgsMatcher { + public: + explicit ArgsMatcher(const InnerMatcher& inner_matcher) + : inner_matcher_(inner_matcher) {} + + template + operator Matcher() const { + return MakeMatcher(new ArgsMatcherImpl(inner_matcher_)); + } + + private: + const InnerMatcher inner_matcher_; + + GTEST_DISALLOW_ASSIGN_(ArgsMatcher); +}; + +// A set of metafunctions for computing the result type of AllOf. +// AllOf(m1, ..., mN) returns +// AllOfResultN::type. + +// Although AllOf isn't defined for one argument, AllOfResult1 is defined +// to simplify the implementation. +template +struct AllOfResult1 { + typedef M1 type; +}; + +$range i 1..n + +$range i 2..n +$for i [[ +$range j 2..i +$var m = i/2 +$range k 1..m +$range t m+1..i + +template +struct AllOfResult$i { + typedef BothOfMatcher< + typename AllOfResult$m<$for k, [[M$k]]>::type, + typename AllOfResult$(i-m)<$for t, [[M$t]]>::type + > type; +}; + +]] + +// A set of metafunctions for computing the result type of AnyOf. +// AnyOf(m1, ..., mN) returns +// AnyOfResultN::type. + +// Although AnyOf isn't defined for one argument, AnyOfResult1 is defined +// to simplify the implementation. +template +struct AnyOfResult1 { + typedef M1 type; +}; + +$range i 1..n + +$range i 2..n +$for i [[ +$range j 2..i +$var m = i/2 +$range k 1..m +$range t m+1..i + +template +struct AnyOfResult$i { + typedef EitherOfMatcher< + typename AnyOfResult$m<$for k, [[M$k]]>::type, + typename AnyOfResult$(i-m)<$for t, [[M$t]]>::type + > type; +}; + +]] + +} // namespace internal + +// Args(a_matcher) matches a tuple if the selected +// fields of it matches a_matcher. C++ doesn't support default +// arguments for function templates, so we have to overload it. + +$range i 0..n +$for i [[ +$range j 1..i +template <$for j [[int k$j, ]]typename InnerMatcher> +inline internal::ArgsMatcher +Args(const InnerMatcher& matcher) { + return internal::ArgsMatcher(matcher); +} + + +]] +// ElementsAre(e_1, e_2, ... e_n) matches an STL-style container with +// n elements, where the i-th element in the container must +// match the i-th argument in the list. Each argument of +// ElementsAre() can be either a value or a matcher. We support up to +// $n arguments. +// +// The use of DecayArray in the implementation allows ElementsAre() +// to accept string literals, whose type is const char[N], but we +// want to treat them as const char*. +// +// NOTE: Since ElementsAre() cares about the order of the elements, it +// must not be used with containers whose elements's order is +// undefined (e.g. hash_map). + +$range i 0..n +$for i [[ + +$range j 1..i + +$if i>0 [[ + +template <$for j, [[typename T$j]]> +]] + +inline internal::ElementsAreMatcher< + std::tr1::tuple< +$for j, [[ + + typename internal::DecayArray::type]]> > +ElementsAre($for j, [[const T$j& e$j]]) { + typedef std::tr1::tuple< +$for j, [[ + + typename internal::DecayArray::type]]> Args; + return internal::ElementsAreMatcher(Args($for j, [[e$j]])); +} + +]] + +// UnorderedElementsAre(e_1, e_2, ..., e_n) is an ElementsAre extension +// that matches n elements in any order. We support up to n=$n arguments. + +$range i 0..n +$for i [[ + +$range j 1..i + +$if i>0 [[ + +template <$for j, [[typename T$j]]> +]] + +inline internal::UnorderedElementsAreMatcher< + std::tr1::tuple< +$for j, [[ + + typename internal::DecayArray::type]]> > +UnorderedElementsAre($for j, [[const T$j& e$j]]) { + typedef std::tr1::tuple< +$for j, [[ + + typename internal::DecayArray::type]]> Args; + return internal::UnorderedElementsAreMatcher(Args($for j, [[e$j]])); +} + +]] + +// AllOf(m1, m2, ..., mk) matches any value that matches all of the given +// sub-matchers. AllOf is called fully qualified to prevent ADL from firing. + +$range i 2..n +$for i [[ +$range j 1..i +$var m = i/2 +$range k 1..m +$range t m+1..i + +template <$for j, [[typename M$j]]> +inline typename internal::AllOfResult$i<$for j, [[M$j]]>::type +AllOf($for j, [[M$j m$j]]) { + return typename internal::AllOfResult$i<$for j, [[M$j]]>::type( + $if m == 1 [[m1]] $else [[::testing::AllOf($for k, [[m$k]])]], + $if m+1 == i [[m$i]] $else [[::testing::AllOf($for t, [[m$t]])]]); +} + +]] + +// AnyOf(m1, m2, ..., mk) matches any value that matches any of the given +// sub-matchers. AnyOf is called fully qualified to prevent ADL from firing. + +$range i 2..n +$for i [[ +$range j 1..i +$var m = i/2 +$range k 1..m +$range t m+1..i + +template <$for j, [[typename M$j]]> +inline typename internal::AnyOfResult$i<$for j, [[M$j]]>::type +AnyOf($for j, [[M$j m$j]]) { + return typename internal::AnyOfResult$i<$for j, [[M$j]]>::type( + $if m == 1 [[m1]] $else [[::testing::AnyOf($for k, [[m$k]])]], + $if m+1 == i [[m$i]] $else [[::testing::AnyOf($for t, [[m$t]])]]); +} + +]] + +} // namespace testing +$$ } // This Pump meta comment fixes auto-indentation in Emacs. It will not +$$ // show up in the generated code. + + +// The MATCHER* family of macros can be used in a namespace scope to +// define custom matchers easily. +// +// Basic Usage +// =========== +// +// The syntax +// +// MATCHER(name, description_string) { statements; } +// +// defines a matcher with the given name that executes the statements, +// which must return a bool to indicate if the match succeeds. Inside +// the statements, you can refer to the value being matched by 'arg', +// and refer to its type by 'arg_type'. +// +// The description string documents what the matcher does, and is used +// to generate the failure message when the match fails. Since a +// MATCHER() is usually defined in a header file shared by multiple +// C++ source files, we require the description to be a C-string +// literal to avoid possible side effects. It can be empty, in which +// case we'll use the sequence of words in the matcher name as the +// description. +// +// For example: +// +// MATCHER(IsEven, "") { return (arg % 2) == 0; } +// +// allows you to write +// +// // Expects mock_foo.Bar(n) to be called where n is even. +// EXPECT_CALL(mock_foo, Bar(IsEven())); +// +// or, +// +// // Verifies that the value of some_expression is even. +// EXPECT_THAT(some_expression, IsEven()); +// +// If the above assertion fails, it will print something like: +// +// Value of: some_expression +// Expected: is even +// Actual: 7 +// +// where the description "is even" is automatically calculated from the +// matcher name IsEven. +// +// Argument Type +// ============= +// +// Note that the type of the value being matched (arg_type) is +// determined by the context in which you use the matcher and is +// supplied to you by the compiler, so you don't need to worry about +// declaring it (nor can you). This allows the matcher to be +// polymorphic. For example, IsEven() can be used to match any type +// where the value of "(arg % 2) == 0" can be implicitly converted to +// a bool. In the "Bar(IsEven())" example above, if method Bar() +// takes an int, 'arg_type' will be int; if it takes an unsigned long, +// 'arg_type' will be unsigned long; and so on. +// +// Parameterizing Matchers +// ======================= +// +// Sometimes you'll want to parameterize the matcher. For that you +// can use another macro: +// +// MATCHER_P(name, param_name, description_string) { statements; } +// +// For example: +// +// MATCHER_P(HasAbsoluteValue, value, "") { return abs(arg) == value; } +// +// will allow you to write: +// +// EXPECT_THAT(Blah("a"), HasAbsoluteValue(n)); +// +// which may lead to this message (assuming n is 10): +// +// Value of: Blah("a") +// Expected: has absolute value 10 +// Actual: -9 +// +// Note that both the matcher description and its parameter are +// printed, making the message human-friendly. +// +// In the matcher definition body, you can write 'foo_type' to +// reference the type of a parameter named 'foo'. For example, in the +// body of MATCHER_P(HasAbsoluteValue, value) above, you can write +// 'value_type' to refer to the type of 'value'. +// +// We also provide MATCHER_P2, MATCHER_P3, ..., up to MATCHER_P$n to +// support multi-parameter matchers. +// +// Describing Parameterized Matchers +// ================================= +// +// The last argument to MATCHER*() is a string-typed expression. The +// expression can reference all of the matcher's parameters and a +// special bool-typed variable named 'negation'. When 'negation' is +// false, the expression should evaluate to the matcher's description; +// otherwise it should evaluate to the description of the negation of +// the matcher. For example, +// +// using testing::PrintToString; +// +// MATCHER_P2(InClosedRange, low, hi, +// string(negation ? "is not" : "is") + " in range [" + +// PrintToString(low) + ", " + PrintToString(hi) + "]") { +// return low <= arg && arg <= hi; +// } +// ... +// EXPECT_THAT(3, InClosedRange(4, 6)); +// EXPECT_THAT(3, Not(InClosedRange(2, 4))); +// +// would generate two failures that contain the text: +// +// Expected: is in range [4, 6] +// ... +// Expected: is not in range [2, 4] +// +// If you specify "" as the description, the failure message will +// contain the sequence of words in the matcher name followed by the +// parameter values printed as a tuple. For example, +// +// MATCHER_P2(InClosedRange, low, hi, "") { ... } +// ... +// EXPECT_THAT(3, InClosedRange(4, 6)); +// EXPECT_THAT(3, Not(InClosedRange(2, 4))); +// +// would generate two failures that contain the text: +// +// Expected: in closed range (4, 6) +// ... +// Expected: not (in closed range (2, 4)) +// +// Types of Matcher Parameters +// =========================== +// +// For the purpose of typing, you can view +// +// MATCHER_Pk(Foo, p1, ..., pk, description_string) { ... } +// +// as shorthand for +// +// template +// FooMatcherPk +// Foo(p1_type p1, ..., pk_type pk) { ... } +// +// When you write Foo(v1, ..., vk), the compiler infers the types of +// the parameters v1, ..., and vk for you. If you are not happy with +// the result of the type inference, you can specify the types by +// explicitly instantiating the template, as in Foo(5, +// false). As said earlier, you don't get to (or need to) specify +// 'arg_type' as that's determined by the context in which the matcher +// is used. You can assign the result of expression Foo(p1, ..., pk) +// to a variable of type FooMatcherPk. This +// can be useful when composing matchers. +// +// While you can instantiate a matcher template with reference types, +// passing the parameters by pointer usually makes your code more +// readable. If, however, you still want to pass a parameter by +// reference, be aware that in the failure message generated by the +// matcher you will see the value of the referenced object but not its +// address. +// +// Explaining Match Results +// ======================== +// +// Sometimes the matcher description alone isn't enough to explain why +// the match has failed or succeeded. For example, when expecting a +// long string, it can be very helpful to also print the diff between +// the expected string and the actual one. To achieve that, you can +// optionally stream additional information to a special variable +// named result_listener, whose type is a pointer to class +// MatchResultListener: +// +// MATCHER_P(EqualsLongString, str, "") { +// if (arg == str) return true; +// +// *result_listener << "the difference: " +/// << DiffStrings(str, arg); +// return false; +// } +// +// Overloading Matchers +// ==================== +// +// You can overload matchers with different numbers of parameters: +// +// MATCHER_P(Blah, a, description_string1) { ... } +// MATCHER_P2(Blah, a, b, description_string2) { ... } +// +// Caveats +// ======= +// +// When defining a new matcher, you should also consider implementing +// MatcherInterface or using MakePolymorphicMatcher(). These +// approaches require more work than the MATCHER* macros, but also +// give you more control on the types of the value being matched and +// the matcher parameters, which may leads to better compiler error +// messages when the matcher is used wrong. They also allow +// overloading matchers based on parameter types (as opposed to just +// based on the number of parameters). +// +// MATCHER*() can only be used in a namespace scope. The reason is +// that C++ doesn't yet allow function-local types to be used to +// instantiate templates. The up-coming C++0x standard will fix this. +// Once that's done, we'll consider supporting using MATCHER*() inside +// a function. +// +// More Information +// ================ +// +// To learn more about using these macros, please search for 'MATCHER' +// on http://code.google.com/p/googlemock/wiki/CookBook. + +$range i 0..n +$for i + +[[ +$var macro_name = [[$if i==0 [[MATCHER]] $elif i==1 [[MATCHER_P]] + $else [[MATCHER_P$i]]]] +$var class_name = [[name##Matcher[[$if i==0 [[]] $elif i==1 [[P]] + $else [[P$i]]]]]] +$range j 0..i-1 +$var template = [[$if i==0 [[]] $else [[ + + template <$for j, [[typename p$j##_type]]>\ +]]]] +$var ctor_param_list = [[$for j, [[p$j##_type gmock_p$j]]]] +$var impl_ctor_param_list = [[$for j, [[p$j##_type gmock_p$j]]]] +$var impl_inits = [[$if i==0 [[]] $else [[ : $for j, [[p$j(gmock_p$j)]]]]]] +$var inits = [[$if i==0 [[]] $else [[ : $for j, [[p$j(gmock_p$j)]]]]]] +$var params = [[$for j, [[p$j]]]] +$var param_types = [[$if i==0 [[]] $else [[<$for j, [[p$j##_type]]>]]]] +$var param_types_and_names = [[$for j, [[p$j##_type p$j]]]] +$var param_field_decls = [[$for j +[[ + + p$j##_type p$j;\ +]]]] +$var param_field_decls2 = [[$for j +[[ + + p$j##_type p$j;\ +]]]] + +#define $macro_name(name$for j [[, p$j]], description)\$template + class $class_name {\ + public:\ + template \ + class gmock_Impl : public ::testing::MatcherInterface {\ + public:\ + [[$if i==1 [[explicit ]]]]gmock_Impl($impl_ctor_param_list)\ + $impl_inits {}\ + virtual bool MatchAndExplain(\ + arg_type arg, ::testing::MatchResultListener* result_listener) const;\ + virtual void DescribeTo(::std::ostream* gmock_os) const {\ + *gmock_os << FormatDescription(false);\ + }\ + virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ + *gmock_os << FormatDescription(true);\ + }\$param_field_decls + private:\ + ::testing::internal::string FormatDescription(bool negation) const {\ + const ::testing::internal::string gmock_description = (description);\ + if (!gmock_description.empty())\ + return gmock_description;\ + return ::testing::internal::FormatMatcherDescription(\ + negation, #name, \ + ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ + ::std::tr1::tuple<$for j, [[p$j##_type]]>($for j, [[p$j]])));\ + }\ + GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ + };\ + template \ + operator ::testing::Matcher() const {\ + return ::testing::Matcher(\ + new gmock_Impl($params));\ + }\ + $class_name($ctor_param_list)$inits {\ + }\$param_field_decls2 + private:\ + GTEST_DISALLOW_ASSIGN_($class_name);\ + };\$template + inline $class_name$param_types name($param_types_and_names) {\ + return $class_name$param_types($params);\ + }\$template + template \ + bool $class_name$param_types::gmock_Impl::MatchAndExplain(\ + arg_type arg, \ + ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ + const +]] + + +#endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_ diff --git a/mbelib-wasm/mbelib/test/gmock/include/gmock/gmock-generated-nice-strict.h b/mbelib-wasm/mbelib/test/gmock/include/gmock/gmock-generated-nice-strict.h new file mode 100644 index 0000000..4095f4d --- /dev/null +++ b/mbelib-wasm/mbelib/test/gmock/include/gmock/gmock-generated-nice-strict.h @@ -0,0 +1,397 @@ +// This file was GENERATED by command: +// pump.py gmock-generated-nice-strict.h.pump +// DO NOT EDIT BY HAND!!! + +// Copyright 2008, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Author: wan@google.com (Zhanyong Wan) + +// Implements class templates NiceMock, NaggyMock, and StrictMock. +// +// Given a mock class MockFoo that is created using Google Mock, +// NiceMock is a subclass of MockFoo that allows +// uninteresting calls (i.e. calls to mock methods that have no +// EXPECT_CALL specs), NaggyMock is a subclass of MockFoo +// that prints a warning when an uninteresting call occurs, and +// StrictMock is a subclass of MockFoo that treats all +// uninteresting calls as errors. +// +// Currently a mock is naggy by default, so MockFoo and +// NaggyMock behave like the same. However, we will soon +// switch the default behavior of mocks to be nice, as that in general +// leads to more maintainable tests. When that happens, MockFoo will +// stop behaving like NaggyMock and start behaving like +// NiceMock. +// +// NiceMock, NaggyMock, and StrictMock "inherit" the constructors of +// their respective base class, with up-to 10 arguments. Therefore +// you can write NiceMock(5, "a") to construct a nice mock +// where MockFoo has a constructor that accepts (int, const char*), +// for example. +// +// A known limitation is that NiceMock, NaggyMock, +// and StrictMock only works for mock methods defined using +// the MOCK_METHOD* family of macros DIRECTLY in the MockFoo class. +// If a mock method is defined in a base class of MockFoo, the "nice" +// or "strict" modifier may not affect it, depending on the compiler. +// In particular, nesting NiceMock, NaggyMock, and StrictMock is NOT +// supported. +// +// Another known limitation is that the constructors of the base mock +// cannot have arguments passed by non-const reference, which are +// banned by the Google C++ style guide anyway. + +#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_ +#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_ + +#include "gmock/gmock-spec-builders.h" +#include "gmock/internal/gmock-port.h" + +namespace testing { + +template +class NiceMock : public MockClass { + public: + // We don't factor out the constructor body to a common method, as + // we have to avoid a possible clash with members of MockClass. + NiceMock() { + ::testing::Mock::AllowUninterestingCalls( + internal::ImplicitCast_(this)); + } + + // C++ doesn't (yet) allow inheritance of constructors, so we have + // to define it for each arity. + template + explicit NiceMock(const A1& a1) : MockClass(a1) { + ::testing::Mock::AllowUninterestingCalls( + internal::ImplicitCast_(this)); + } + template + NiceMock(const A1& a1, const A2& a2) : MockClass(a1, a2) { + ::testing::Mock::AllowUninterestingCalls( + internal::ImplicitCast_(this)); + } + + template + NiceMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) { + ::testing::Mock::AllowUninterestingCalls( + internal::ImplicitCast_(this)); + } + + template + NiceMock(const A1& a1, const A2& a2, const A3& a3, + const A4& a4) : MockClass(a1, a2, a3, a4) { + ::testing::Mock::AllowUninterestingCalls( + internal::ImplicitCast_(this)); + } + + template + NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, + const A5& a5) : MockClass(a1, a2, a3, a4, a5) { + ::testing::Mock::AllowUninterestingCalls( + internal::ImplicitCast_(this)); + } + + template + NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, + const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) { + ::testing::Mock::AllowUninterestingCalls( + internal::ImplicitCast_(this)); + } + + template + NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, + const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5, + a6, a7) { + ::testing::Mock::AllowUninterestingCalls( + internal::ImplicitCast_(this)); + } + + template + NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, + const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1, + a2, a3, a4, a5, a6, a7, a8) { + ::testing::Mock::AllowUninterestingCalls( + internal::ImplicitCast_(this)); + } + + template + NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, + const A5& a5, const A6& a6, const A7& a7, const A8& a8, + const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) { + ::testing::Mock::AllowUninterestingCalls( + internal::ImplicitCast_(this)); + } + + template + NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, + const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, + const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) { + ::testing::Mock::AllowUninterestingCalls( + internal::ImplicitCast_(this)); + } + + virtual ~NiceMock() { + ::testing::Mock::UnregisterCallReaction( + internal::ImplicitCast_(this)); + } + + private: + GTEST_DISALLOW_COPY_AND_ASSIGN_(NiceMock); +}; + +template +class NaggyMock : public MockClass { + public: + // We don't factor out the constructor body to a common method, as + // we have to avoid a possible clash with members of MockClass. + NaggyMock() { + ::testing::Mock::WarnUninterestingCalls( + internal::ImplicitCast_(this)); + } + + // C++ doesn't (yet) allow inheritance of constructors, so we have + // to define it for each arity. + template + explicit NaggyMock(const A1& a1) : MockClass(a1) { + ::testing::Mock::WarnUninterestingCalls( + internal::ImplicitCast_(this)); + } + template + NaggyMock(const A1& a1, const A2& a2) : MockClass(a1, a2) { + ::testing::Mock::WarnUninterestingCalls( + internal::ImplicitCast_(this)); + } + + template + NaggyMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) { + ::testing::Mock::WarnUninterestingCalls( + internal::ImplicitCast_(this)); + } + + template + NaggyMock(const A1& a1, const A2& a2, const A3& a3, + const A4& a4) : MockClass(a1, a2, a3, a4) { + ::testing::Mock::WarnUninterestingCalls( + internal::ImplicitCast_(this)); + } + + template + NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, + const A5& a5) : MockClass(a1, a2, a3, a4, a5) { + ::testing::Mock::WarnUninterestingCalls( + internal::ImplicitCast_(this)); + } + + template + NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, + const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) { + ::testing::Mock::WarnUninterestingCalls( + internal::ImplicitCast_(this)); + } + + template + NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, + const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5, + a6, a7) { + ::testing::Mock::WarnUninterestingCalls( + internal::ImplicitCast_(this)); + } + + template + NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, + const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1, + a2, a3, a4, a5, a6, a7, a8) { + ::testing::Mock::WarnUninterestingCalls( + internal::ImplicitCast_(this)); + } + + template + NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, + const A5& a5, const A6& a6, const A7& a7, const A8& a8, + const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) { + ::testing::Mock::WarnUninterestingCalls( + internal::ImplicitCast_(this)); + } + + template + NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, + const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, + const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) { + ::testing::Mock::WarnUninterestingCalls( + internal::ImplicitCast_(this)); + } + + virtual ~NaggyMock() { + ::testing::Mock::UnregisterCallReaction( + internal::ImplicitCast_(this)); + } + + private: + GTEST_DISALLOW_COPY_AND_ASSIGN_(NaggyMock); +}; + +template +class StrictMock : public MockClass { + public: + // We don't factor out the constructor body to a common method, as + // we have to avoid a possible clash with members of MockClass. + StrictMock() { + ::testing::Mock::FailUninterestingCalls( + internal::ImplicitCast_(this)); + } + + // C++ doesn't (yet) allow inheritance of constructors, so we have + // to define it for each arity. + template + explicit StrictMock(const A1& a1) : MockClass(a1) { + ::testing::Mock::FailUninterestingCalls( + internal::ImplicitCast_(this)); + } + template + StrictMock(const A1& a1, const A2& a2) : MockClass(a1, a2) { + ::testing::Mock::FailUninterestingCalls( + internal::ImplicitCast_(this)); + } + + template + StrictMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) { + ::testing::Mock::FailUninterestingCalls( + internal::ImplicitCast_(this)); + } + + template + StrictMock(const A1& a1, const A2& a2, const A3& a3, + const A4& a4) : MockClass(a1, a2, a3, a4) { + ::testing::Mock::FailUninterestingCalls( + internal::ImplicitCast_(this)); + } + + template + StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, + const A5& a5) : MockClass(a1, a2, a3, a4, a5) { + ::testing::Mock::FailUninterestingCalls( + internal::ImplicitCast_(this)); + } + + template + StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, + const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) { + ::testing::Mock::FailUninterestingCalls( + internal::ImplicitCast_(this)); + } + + template + StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, + const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5, + a6, a7) { + ::testing::Mock::FailUninterestingCalls( + internal::ImplicitCast_(this)); + } + + template + StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, + const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1, + a2, a3, a4, a5, a6, a7, a8) { + ::testing::Mock::FailUninterestingCalls( + internal::ImplicitCast_(this)); + } + + template + StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, + const A5& a5, const A6& a6, const A7& a7, const A8& a8, + const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) { + ::testing::Mock::FailUninterestingCalls( + internal::ImplicitCast_(this)); + } + + template + StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, + const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, + const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) { + ::testing::Mock::FailUninterestingCalls( + internal::ImplicitCast_(this)); + } + + virtual ~StrictMock() { + ::testing::Mock::UnregisterCallReaction( + internal::ImplicitCast_(this)); + } + + private: + GTEST_DISALLOW_COPY_AND_ASSIGN_(StrictMock); +}; + +// The following specializations catch some (relatively more common) +// user errors of nesting nice and strict mocks. They do NOT catch +// all possible errors. + +// These specializations are declared but not defined, as NiceMock, +// NaggyMock, and StrictMock cannot be nested. + +template +class NiceMock >; +template +class NiceMock >; +template +class NiceMock >; + +template +class NaggyMock >; +template +class NaggyMock >; +template +class NaggyMock >; + +template +class StrictMock >; +template +class StrictMock >; +template +class StrictMock >; + +} // namespace testing + +#endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_ diff --git a/mbelib-wasm/mbelib/test/gmock/include/gmock/gmock-generated-nice-strict.h.pump b/mbelib-wasm/mbelib/test/gmock/include/gmock/gmock-generated-nice-strict.h.pump new file mode 100644 index 0000000..3ee1ce7 --- /dev/null +++ b/mbelib-wasm/mbelib/test/gmock/include/gmock/gmock-generated-nice-strict.h.pump @@ -0,0 +1,161 @@ +$$ -*- mode: c++; -*- +$$ This is a Pump source file. Please use Pump to convert it to +$$ gmock-generated-nice-strict.h. +$$ +$var n = 10 $$ The maximum arity we support. +// Copyright 2008, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Author: wan@google.com (Zhanyong Wan) + +// Implements class templates NiceMock, NaggyMock, and StrictMock. +// +// Given a mock class MockFoo that is created using Google Mock, +// NiceMock is a subclass of MockFoo that allows +// uninteresting calls (i.e. calls to mock methods that have no +// EXPECT_CALL specs), NaggyMock is a subclass of MockFoo +// that prints a warning when an uninteresting call occurs, and +// StrictMock is a subclass of MockFoo that treats all +// uninteresting calls as errors. +// +// Currently a mock is naggy by default, so MockFoo and +// NaggyMock behave like the same. However, we will soon +// switch the default behavior of mocks to be nice, as that in general +// leads to more maintainable tests. When that happens, MockFoo will +// stop behaving like NaggyMock and start behaving like +// NiceMock. +// +// NiceMock, NaggyMock, and StrictMock "inherit" the constructors of +// their respective base class, with up-to $n arguments. Therefore +// you can write NiceMock(5, "a") to construct a nice mock +// where MockFoo has a constructor that accepts (int, const char*), +// for example. +// +// A known limitation is that NiceMock, NaggyMock, +// and StrictMock only works for mock methods defined using +// the MOCK_METHOD* family of macros DIRECTLY in the MockFoo class. +// If a mock method is defined in a base class of MockFoo, the "nice" +// or "strict" modifier may not affect it, depending on the compiler. +// In particular, nesting NiceMock, NaggyMock, and StrictMock is NOT +// supported. +// +// Another known limitation is that the constructors of the base mock +// cannot have arguments passed by non-const reference, which are +// banned by the Google C++ style guide anyway. + +#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_ +#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_ + +#include "gmock/gmock-spec-builders.h" +#include "gmock/internal/gmock-port.h" + +namespace testing { + +$range kind 0..2 +$for kind [[ + +$var clazz=[[$if kind==0 [[NiceMock]] + $elif kind==1 [[NaggyMock]] + $else [[StrictMock]]]] + +$var method=[[$if kind==0 [[AllowUninterestingCalls]] + $elif kind==1 [[WarnUninterestingCalls]] + $else [[FailUninterestingCalls]]]] + +template +class $clazz : public MockClass { + public: + // We don't factor out the constructor body to a common method, as + // we have to avoid a possible clash with members of MockClass. + $clazz() { + ::testing::Mock::$method( + internal::ImplicitCast_(this)); + } + + // C++ doesn't (yet) allow inheritance of constructors, so we have + // to define it for each arity. + template + explicit $clazz(const A1& a1) : MockClass(a1) { + ::testing::Mock::$method( + internal::ImplicitCast_(this)); + } + +$range i 2..n +$for i [[ +$range j 1..i + template <$for j, [[typename A$j]]> + $clazz($for j, [[const A$j& a$j]]) : MockClass($for j, [[a$j]]) { + ::testing::Mock::$method( + internal::ImplicitCast_(this)); + } + + +]] + virtual ~$clazz() { + ::testing::Mock::UnregisterCallReaction( + internal::ImplicitCast_(this)); + } + + private: + GTEST_DISALLOW_COPY_AND_ASSIGN_($clazz); +}; + +]] + +// The following specializations catch some (relatively more common) +// user errors of nesting nice and strict mocks. They do NOT catch +// all possible errors. + +// These specializations are declared but not defined, as NiceMock, +// NaggyMock, and StrictMock cannot be nested. + +template +class NiceMock >; +template +class NiceMock >; +template +class NiceMock >; + +template +class NaggyMock >; +template +class NaggyMock >; +template +class NaggyMock >; + +template +class StrictMock >; +template +class StrictMock >; +template +class StrictMock >; + +} // namespace testing + +#endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_ diff --git a/mbelib-wasm/mbelib/test/gmock/include/gmock/gmock-matchers.h b/mbelib-wasm/mbelib/test/gmock/include/gmock/gmock-matchers.h new file mode 100644 index 0000000..44055c9 --- /dev/null +++ b/mbelib-wasm/mbelib/test/gmock/include/gmock/gmock-matchers.h @@ -0,0 +1,3986 @@ +// Copyright 2007, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Author: wan@google.com (Zhanyong Wan) + +// Google Mock - a framework for writing C++ mock classes. +// +// This file implements some commonly used argument matchers. More +// matchers can be defined by the user implementing the +// MatcherInterface interface if necessary. + +#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_ +#define GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_ + +#include +#include +#include +#include +#include // NOLINT +#include +#include +#include +#include + +#include "gmock/internal/gmock-internal-utils.h" +#include "gmock/internal/gmock-port.h" +#include "gtest/gtest.h" + +#if GTEST_LANG_CXX11 +#include // NOLINT -- must be after gtest.h +#endif + +namespace testing { + +// To implement a matcher Foo for type T, define: +// 1. a class FooMatcherImpl that implements the +// MatcherInterface interface, and +// 2. a factory function that creates a Matcher object from a +// FooMatcherImpl*. +// +// The two-level delegation design makes it possible to allow a user +// to write "v" instead of "Eq(v)" where a Matcher is expected, which +// is impossible if we pass matchers by pointers. It also eases +// ownership management as Matcher objects can now be copied like +// plain values. + +// MatchResultListener is an abstract class. Its << operator can be +// used by a matcher to explain why a value matches or doesn't match. +// +// TODO(wan@google.com): add method +// bool InterestedInWhy(bool result) const; +// to indicate whether the listener is interested in why the match +// result is 'result'. +class MatchResultListener { + public: + // Creates a listener object with the given underlying ostream. The + // listener does not own the ostream, and does not dereference it + // in the constructor or destructor. + explicit MatchResultListener(::std::ostream* os) : stream_(os) {} + virtual ~MatchResultListener() = 0; // Makes this class abstract. + + // Streams x to the underlying ostream; does nothing if the ostream + // is NULL. + template + MatchResultListener& operator<<(const T& x) { + if (stream_ != NULL) + *stream_ << x; + return *this; + } + + // Returns the underlying ostream. + ::std::ostream* stream() { return stream_; } + + // Returns true iff the listener is interested in an explanation of + // the match result. A matcher's MatchAndExplain() method can use + // this information to avoid generating the explanation when no one + // intends to hear it. + bool IsInterested() const { return stream_ != NULL; } + + private: + ::std::ostream* const stream_; + + GTEST_DISALLOW_COPY_AND_ASSIGN_(MatchResultListener); +}; + +inline MatchResultListener::~MatchResultListener() { +} + +// An instance of a subclass of this knows how to describe itself as a +// matcher. +class MatcherDescriberInterface { + public: + virtual ~MatcherDescriberInterface() {} + + // Describes this matcher to an ostream. The function should print + // a verb phrase that describes the property a value matching this + // matcher should have. The subject of the verb phrase is the value + // being matched. For example, the DescribeTo() method of the Gt(7) + // matcher prints "is greater than 7". + virtual void DescribeTo(::std::ostream* os) const = 0; + + // Describes the negation of this matcher to an ostream. For + // example, if the description of this matcher is "is greater than + // 7", the negated description could be "is not greater than 7". + // You are not required to override this when implementing + // MatcherInterface, but it is highly advised so that your matcher + // can produce good error messages. + virtual void DescribeNegationTo(::std::ostream* os) const { + *os << "not ("; + DescribeTo(os); + *os << ")"; + } +}; + +// The implementation of a matcher. +template +class MatcherInterface : public MatcherDescriberInterface { + public: + // Returns true iff the matcher matches x; also explains the match + // result to 'listener' if necessary (see the next paragraph), in + // the form of a non-restrictive relative clause ("which ...", + // "whose ...", etc) that describes x. For example, the + // MatchAndExplain() method of the Pointee(...) matcher should + // generate an explanation like "which points to ...". + // + // Implementations of MatchAndExplain() should add an explanation of + // the match result *if and only if* they can provide additional + // information that's not already present (or not obvious) in the + // print-out of x and the matcher's description. Whether the match + // succeeds is not a factor in deciding whether an explanation is + // needed, as sometimes the caller needs to print a failure message + // when the match succeeds (e.g. when the matcher is used inside + // Not()). + // + // For example, a "has at least 10 elements" matcher should explain + // what the actual element count is, regardless of the match result, + // as it is useful information to the reader; on the other hand, an + // "is empty" matcher probably only needs to explain what the actual + // size is when the match fails, as it's redundant to say that the + // size is 0 when the value is already known to be empty. + // + // You should override this method when defining a new matcher. + // + // It's the responsibility of the caller (Google Mock) to guarantee + // that 'listener' is not NULL. This helps to simplify a matcher's + // implementation when it doesn't care about the performance, as it + // can talk to 'listener' without checking its validity first. + // However, in order to implement dummy listeners efficiently, + // listener->stream() may be NULL. + virtual bool MatchAndExplain(T x, MatchResultListener* listener) const = 0; + + // Inherits these methods from MatcherDescriberInterface: + // virtual void DescribeTo(::std::ostream* os) const = 0; + // virtual void DescribeNegationTo(::std::ostream* os) const; +}; + +// A match result listener that stores the explanation in a string. +class StringMatchResultListener : public MatchResultListener { + public: + StringMatchResultListener() : MatchResultListener(&ss_) {} + + // Returns the explanation accumulated so far. + internal::string str() const { return ss_.str(); } + + // Clears the explanation accumulated so far. + void Clear() { ss_.str(""); } + + private: + ::std::stringstream ss_; + + GTEST_DISALLOW_COPY_AND_ASSIGN_(StringMatchResultListener); +}; + +namespace internal { + +// A match result listener that ignores the explanation. +class DummyMatchResultListener : public MatchResultListener { + public: + DummyMatchResultListener() : MatchResultListener(NULL) {} + + private: + GTEST_DISALLOW_COPY_AND_ASSIGN_(DummyMatchResultListener); +}; + +// A match result listener that forwards the explanation to a given +// ostream. The difference between this and MatchResultListener is +// that the former is concrete. +class StreamMatchResultListener : public MatchResultListener { + public: + explicit StreamMatchResultListener(::std::ostream* os) + : MatchResultListener(os) {} + + private: + GTEST_DISALLOW_COPY_AND_ASSIGN_(StreamMatchResultListener); +}; + +// An internal class for implementing Matcher, which will derive +// from it. We put functionalities common to all Matcher +// specializations here to avoid code duplication. +template +class MatcherBase { + public: + // Returns true iff the matcher matches x; also explains the match + // result to 'listener'. + bool MatchAndExplain(T x, MatchResultListener* listener) const { + return impl_->MatchAndExplain(x, listener); + } + + // Returns true iff this matcher matches x. + bool Matches(T x) const { + DummyMatchResultListener dummy; + return MatchAndExplain(x, &dummy); + } + + // Describes this matcher to an ostream. + void DescribeTo(::std::ostream* os) const { impl_->DescribeTo(os); } + + // Describes the negation of this matcher to an ostream. + void DescribeNegationTo(::std::ostream* os) const { + impl_->DescribeNegationTo(os); + } + + // Explains why x matches, or doesn't match, the matcher. + void ExplainMatchResultTo(T x, ::std::ostream* os) const { + StreamMatchResultListener listener(os); + MatchAndExplain(x, &listener); + } + + // Returns the describer for this matcher object; retains ownership + // of the describer, which is only guaranteed to be alive when + // this matcher object is alive. + const MatcherDescriberInterface* GetDescriber() const { + return impl_.get(); + } + + protected: + MatcherBase() {} + + // Constructs a matcher from its implementation. + explicit MatcherBase(const MatcherInterface* impl) + : impl_(impl) {} + + virtual ~MatcherBase() {} + + private: + // shared_ptr (util/gtl/shared_ptr.h) and linked_ptr have similar + // interfaces. The former dynamically allocates a chunk of memory + // to hold the reference count, while the latter tracks all + // references using a circular linked list without allocating + // memory. It has been observed that linked_ptr performs better in + // typical scenarios. However, shared_ptr can out-perform + // linked_ptr when there are many more uses of the copy constructor + // than the default constructor. + // + // If performance becomes a problem, we should see if using + // shared_ptr helps. + ::testing::internal::linked_ptr > impl_; +}; + +} // namespace internal + +// A Matcher is a copyable and IMMUTABLE (except by assignment) +// object that can check whether a value of type T matches. The +// implementation of Matcher is just a linked_ptr to const +// MatcherInterface, so copying is fairly cheap. Don't inherit +// from Matcher! +template +class Matcher : public internal::MatcherBase { + public: + // Constructs a null matcher. Needed for storing Matcher objects in STL + // containers. A default-constructed matcher is not yet initialized. You + // cannot use it until a valid value has been assigned to it. + Matcher() {} + + // Constructs a matcher from its implementation. + explicit Matcher(const MatcherInterface* impl) + : internal::MatcherBase(impl) {} + + // Implicit constructor here allows people to write + // EXPECT_CALL(foo, Bar(5)) instead of EXPECT_CALL(foo, Bar(Eq(5))) sometimes + Matcher(T value); // NOLINT +}; + +// The following two specializations allow the user to write str +// instead of Eq(str) and "foo" instead of Eq("foo") when a string +// matcher is expected. +template <> +class GTEST_API_ Matcher + : public internal::MatcherBase { + public: + Matcher() {} + + explicit Matcher(const MatcherInterface* impl) + : internal::MatcherBase(impl) {} + + // Allows the user to write str instead of Eq(str) sometimes, where + // str is a string object. + Matcher(const internal::string& s); // NOLINT + + // Allows the user to write "foo" instead of Eq("foo") sometimes. + Matcher(const char* s); // NOLINT +}; + +template <> +class GTEST_API_ Matcher + : public internal::MatcherBase { + public: + Matcher() {} + + explicit Matcher(const MatcherInterface* impl) + : internal::MatcherBase(impl) {} + + // Allows the user to write str instead of Eq(str) sometimes, where + // str is a string object. + Matcher(const internal::string& s); // NOLINT + + // Allows the user to write "foo" instead of Eq("foo") sometimes. + Matcher(const char* s); // NOLINT +}; + +#if GTEST_HAS_STRING_PIECE_ +// The following two specializations allow the user to write str +// instead of Eq(str) and "foo" instead of Eq("foo") when a StringPiece +// matcher is expected. +template <> +class GTEST_API_ Matcher + : public internal::MatcherBase { + public: + Matcher() {} + + explicit Matcher(const MatcherInterface* impl) + : internal::MatcherBase(impl) {} + + // Allows the user to write str instead of Eq(str) sometimes, where + // str is a string object. + Matcher(const internal::string& s); // NOLINT + + // Allows the user to write "foo" instead of Eq("foo") sometimes. + Matcher(const char* s); // NOLINT + + // Allows the user to pass StringPieces directly. + Matcher(StringPiece s); // NOLINT +}; + +template <> +class GTEST_API_ Matcher + : public internal::MatcherBase { + public: + Matcher() {} + + explicit Matcher(const MatcherInterface* impl) + : internal::MatcherBase(impl) {} + + // Allows the user to write str instead of Eq(str) sometimes, where + // str is a string object. + Matcher(const internal::string& s); // NOLINT + + // Allows the user to write "foo" instead of Eq("foo") sometimes. + Matcher(const char* s); // NOLINT + + // Allows the user to pass StringPieces directly. + Matcher(StringPiece s); // NOLINT +}; +#endif // GTEST_HAS_STRING_PIECE_ + +// The PolymorphicMatcher class template makes it easy to implement a +// polymorphic matcher (i.e. a matcher that can match values of more +// than one type, e.g. Eq(n) and NotNull()). +// +// To define a polymorphic matcher, a user should provide an Impl +// class that has a DescribeTo() method and a DescribeNegationTo() +// method, and define a member function (or member function template) +// +// bool MatchAndExplain(const Value& value, +// MatchResultListener* listener) const; +// +// See the definition of NotNull() for a complete example. +template +class PolymorphicMatcher { + public: + explicit PolymorphicMatcher(const Impl& an_impl) : impl_(an_impl) {} + + // Returns a mutable reference to the underlying matcher + // implementation object. + Impl& mutable_impl() { return impl_; } + + // Returns an immutable reference to the underlying matcher + // implementation object. + const Impl& impl() const { return impl_; } + + template + operator Matcher() const { + return Matcher(new MonomorphicImpl(impl_)); + } + + private: + template + class MonomorphicImpl : public MatcherInterface { + public: + explicit MonomorphicImpl(const Impl& impl) : impl_(impl) {} + + virtual void DescribeTo(::std::ostream* os) const { + impl_.DescribeTo(os); + } + + virtual void DescribeNegationTo(::std::ostream* os) const { + impl_.DescribeNegationTo(os); + } + + virtual bool MatchAndExplain(T x, MatchResultListener* listener) const { + return impl_.MatchAndExplain(x, listener); + } + + private: + const Impl impl_; + + GTEST_DISALLOW_ASSIGN_(MonomorphicImpl); + }; + + Impl impl_; + + GTEST_DISALLOW_ASSIGN_(PolymorphicMatcher); +}; + +// Creates a matcher from its implementation. This is easier to use +// than the Matcher constructor as it doesn't require you to +// explicitly write the template argument, e.g. +// +// MakeMatcher(foo); +// vs +// Matcher(foo); +template +inline Matcher MakeMatcher(const MatcherInterface* impl) { + return Matcher(impl); +} + +// Creates a polymorphic matcher from its implementation. This is +// easier to use than the PolymorphicMatcher constructor as it +// doesn't require you to explicitly write the template argument, e.g. +// +// MakePolymorphicMatcher(foo); +// vs +// PolymorphicMatcher(foo); +template +inline PolymorphicMatcher MakePolymorphicMatcher(const Impl& impl) { + return PolymorphicMatcher(impl); +} + +// Anything inside the 'internal' namespace IS INTERNAL IMPLEMENTATION +// and MUST NOT BE USED IN USER CODE!!! +namespace internal { + +// The MatcherCastImpl class template is a helper for implementing +// MatcherCast(). We need this helper in order to partially +// specialize the implementation of MatcherCast() (C++ allows +// class/struct templates to be partially specialized, but not +// function templates.). + +// This general version is used when MatcherCast()'s argument is a +// polymorphic matcher (i.e. something that can be converted to a +// Matcher but is not one yet; for example, Eq(value)) or a value (for +// example, "hello"). +template +class MatcherCastImpl { + public: + static Matcher Cast(M polymorphic_matcher_or_value) { + // M can be a polymorhic matcher, in which case we want to use + // its conversion operator to create Matcher. Or it can be a value + // that should be passed to the Matcher's constructor. + // + // We can't call Matcher(polymorphic_matcher_or_value) when M is a + // polymorphic matcher because it'll be ambiguous if T has an implicit + // constructor from M (this usually happens when T has an implicit + // constructor from any type). + // + // It won't work to unconditionally implict_cast + // polymorphic_matcher_or_value to Matcher because it won't trigger + // a user-defined conversion from M to T if one exists (assuming M is + // a value). + return CastImpl( + polymorphic_matcher_or_value, + BooleanConstant< + internal::ImplicitlyConvertible >::value>()); + } + + private: + static Matcher CastImpl(M value, BooleanConstant) { + // M can't be implicitly converted to Matcher, so M isn't a polymorphic + // matcher. It must be a value then. Use direct initialization to create + // a matcher. + return Matcher(ImplicitCast_(value)); + } + + static Matcher CastImpl(M polymorphic_matcher_or_value, + BooleanConstant) { + // M is implicitly convertible to Matcher, which means that either + // M is a polymorhpic matcher or Matcher has an implicit constructor + // from M. In both cases using the implicit conversion will produce a + // matcher. + // + // Even if T has an implicit constructor from M, it won't be called because + // creating Matcher would require a chain of two user-defined conversions + // (first to create T from M and then to create Matcher from T). + return polymorphic_matcher_or_value; + } +}; + +// This more specialized version is used when MatcherCast()'s argument +// is already a Matcher. This only compiles when type T can be +// statically converted to type U. +template +class MatcherCastImpl > { + public: + static Matcher Cast(const Matcher& source_matcher) { + return Matcher(new Impl(source_matcher)); + } + + private: + class Impl : public MatcherInterface { + public: + explicit Impl(const Matcher& source_matcher) + : source_matcher_(source_matcher) {} + + // We delegate the matching logic to the source matcher. + virtual bool MatchAndExplain(T x, MatchResultListener* listener) const { + return source_matcher_.MatchAndExplain(static_cast(x), listener); + } + + virtual void DescribeTo(::std::ostream* os) const { + source_matcher_.DescribeTo(os); + } + + virtual void DescribeNegationTo(::std::ostream* os) const { + source_matcher_.DescribeNegationTo(os); + } + + private: + const Matcher source_matcher_; + + GTEST_DISALLOW_ASSIGN_(Impl); + }; +}; + +// This even more specialized version is used for efficiently casting +// a matcher to its own type. +template +class MatcherCastImpl > { + public: + static Matcher Cast(const Matcher& matcher) { return matcher; } +}; + +} // namespace internal + +// In order to be safe and clear, casting between different matcher +// types is done explicitly via MatcherCast(m), which takes a +// matcher m and returns a Matcher. It compiles only when T can be +// statically converted to the argument type of m. +template +inline Matcher MatcherCast(M matcher) { + return internal::MatcherCastImpl::Cast(matcher); +} + +// Implements SafeMatcherCast(). +// +// We use an intermediate class to do the actual safe casting as Nokia's +// Symbian compiler cannot decide between +// template ... (M) and +// template ... (const Matcher&) +// for function templates but can for member function templates. +template +class SafeMatcherCastImpl { + public: + // This overload handles polymorphic matchers and values only since + // monomorphic matchers are handled by the next one. + template + static inline Matcher Cast(M polymorphic_matcher_or_value) { + return internal::MatcherCastImpl::Cast(polymorphic_matcher_or_value); + } + + // This overload handles monomorphic matchers. + // + // In general, if type T can be implicitly converted to type U, we can + // safely convert a Matcher to a Matcher (i.e. Matcher is + // contravariant): just keep a copy of the original Matcher, convert the + // argument from type T to U, and then pass it to the underlying Matcher. + // The only exception is when U is a reference and T is not, as the + // underlying Matcher may be interested in the argument's address, which + // is not preserved in the conversion from T to U. + template + static inline Matcher Cast(const Matcher& matcher) { + // Enforce that T can be implicitly converted to U. + GTEST_COMPILE_ASSERT_((internal::ImplicitlyConvertible::value), + T_must_be_implicitly_convertible_to_U); + // Enforce that we are not converting a non-reference type T to a reference + // type U. + GTEST_COMPILE_ASSERT_( + internal::is_reference::value || !internal::is_reference::value, + cannot_convert_non_referentce_arg_to_reference); + // In case both T and U are arithmetic types, enforce that the + // conversion is not lossy. + typedef GTEST_REMOVE_REFERENCE_AND_CONST_(T) RawT; + typedef GTEST_REMOVE_REFERENCE_AND_CONST_(U) RawU; + const bool kTIsOther = GMOCK_KIND_OF_(RawT) == internal::kOther; + const bool kUIsOther = GMOCK_KIND_OF_(RawU) == internal::kOther; + GTEST_COMPILE_ASSERT_( + kTIsOther || kUIsOther || + (internal::LosslessArithmeticConvertible::value), + conversion_of_arithmetic_types_must_be_lossless); + return MatcherCast(matcher); + } +}; + +template +inline Matcher SafeMatcherCast(const M& polymorphic_matcher) { + return SafeMatcherCastImpl::Cast(polymorphic_matcher); +} + +// A() returns a matcher that matches any value of type T. +template +Matcher A(); + +// Anything inside the 'internal' namespace IS INTERNAL IMPLEMENTATION +// and MUST NOT BE USED IN USER CODE!!! +namespace internal { + +// If the explanation is not empty, prints it to the ostream. +inline void PrintIfNotEmpty(const internal::string& explanation, + ::std::ostream* os) { + if (explanation != "" && os != NULL) { + *os << ", " << explanation; + } +} + +// Returns true if the given type name is easy to read by a human. +// This is used to decide whether printing the type of a value might +// be helpful. +inline bool IsReadableTypeName(const string& type_name) { + // We consider a type name readable if it's short or doesn't contain + // a template or function type. + return (type_name.length() <= 20 || + type_name.find_first_of("<(") == string::npos); +} + +// Matches the value against the given matcher, prints the value and explains +// the match result to the listener. Returns the match result. +// 'listener' must not be NULL. +// Value cannot be passed by const reference, because some matchers take a +// non-const argument. +template +bool MatchPrintAndExplain(Value& value, const Matcher& matcher, + MatchResultListener* listener) { + if (!listener->IsInterested()) { + // If the listener is not interested, we do not need to construct the + // inner explanation. + return matcher.Matches(value); + } + + StringMatchResultListener inner_listener; + const bool match = matcher.MatchAndExplain(value, &inner_listener); + + UniversalPrint(value, listener->stream()); +#if GTEST_HAS_RTTI + const string& type_name = GetTypeName(); + if (IsReadableTypeName(type_name)) + *listener->stream() << " (of type " << type_name << ")"; +#endif + PrintIfNotEmpty(inner_listener.str(), listener->stream()); + + return match; +} + +// An internal helper class for doing compile-time loop on a tuple's +// fields. +template +class TuplePrefix { + public: + // TuplePrefix::Matches(matcher_tuple, value_tuple) returns true + // iff the first N fields of matcher_tuple matches the first N + // fields of value_tuple, respectively. + template + static bool Matches(const MatcherTuple& matcher_tuple, + const ValueTuple& value_tuple) { + using ::std::tr1::get; + return TuplePrefix::Matches(matcher_tuple, value_tuple) + && get(matcher_tuple).Matches(get(value_tuple)); + } + + // TuplePrefix::ExplainMatchFailuresTo(matchers, values, os) + // describes failures in matching the first N fields of matchers + // against the first N fields of values. If there is no failure, + // nothing will be streamed to os. + template + static void ExplainMatchFailuresTo(const MatcherTuple& matchers, + const ValueTuple& values, + ::std::ostream* os) { + using ::std::tr1::tuple_element; + using ::std::tr1::get; + + // First, describes failures in the first N - 1 fields. + TuplePrefix::ExplainMatchFailuresTo(matchers, values, os); + + // Then describes the failure (if any) in the (N - 1)-th (0-based) + // field. + typename tuple_element::type matcher = + get(matchers); + typedef typename tuple_element::type Value; + Value value = get(values); + StringMatchResultListener listener; + if (!matcher.MatchAndExplain(value, &listener)) { + // TODO(wan): include in the message the name of the parameter + // as used in MOCK_METHOD*() when possible. + *os << " Expected arg #" << N - 1 << ": "; + get(matchers).DescribeTo(os); + *os << "\n Actual: "; + // We remove the reference in type Value to prevent the + // universal printer from printing the address of value, which + // isn't interesting to the user most of the time. The + // matcher's MatchAndExplain() method handles the case when + // the address is interesting. + internal::UniversalPrint(value, os); + PrintIfNotEmpty(listener.str(), os); + *os << "\n"; + } + } +}; + +// The base case. +template <> +class TuplePrefix<0> { + public: + template + static bool Matches(const MatcherTuple& /* matcher_tuple */, + const ValueTuple& /* value_tuple */) { + return true; + } + + template + static void ExplainMatchFailuresTo(const MatcherTuple& /* matchers */, + const ValueTuple& /* values */, + ::std::ostream* /* os */) {} +}; + +// TupleMatches(matcher_tuple, value_tuple) returns true iff all +// matchers in matcher_tuple match the corresponding fields in +// value_tuple. It is a compiler error if matcher_tuple and +// value_tuple have different number of fields or incompatible field +// types. +template +bool TupleMatches(const MatcherTuple& matcher_tuple, + const ValueTuple& value_tuple) { + using ::std::tr1::tuple_size; + // Makes sure that matcher_tuple and value_tuple have the same + // number of fields. + GTEST_COMPILE_ASSERT_(tuple_size::value == + tuple_size::value, + matcher_and_value_have_different_numbers_of_fields); + return TuplePrefix::value>:: + Matches(matcher_tuple, value_tuple); +} + +// Describes failures in matching matchers against values. If there +// is no failure, nothing will be streamed to os. +template +void ExplainMatchFailureTupleTo(const MatcherTuple& matchers, + const ValueTuple& values, + ::std::ostream* os) { + using ::std::tr1::tuple_size; + TuplePrefix::value>::ExplainMatchFailuresTo( + matchers, values, os); +} + +// TransformTupleValues and its helper. +// +// TransformTupleValuesHelper hides the internal machinery that +// TransformTupleValues uses to implement a tuple traversal. +template +class TransformTupleValuesHelper { + private: + typedef typename ::std::tr1::tuple_size TupleSize; + + public: + // For each member of tuple 't', taken in order, evaluates '*out++ = f(t)'. + // Returns the final value of 'out' in case the caller needs it. + static OutIter Run(Func f, const Tuple& t, OutIter out) { + return IterateOverTuple()(f, t, out); + } + + private: + template + struct IterateOverTuple { + OutIter operator() (Func f, const Tup& t, OutIter out) const { + *out++ = f(::std::tr1::get(t)); + return IterateOverTuple()(f, t, out); + } + }; + template + struct IterateOverTuple { + OutIter operator() (Func /* f */, const Tup& /* t */, OutIter out) const { + return out; + } + }; +}; + +// Successively invokes 'f(element)' on each element of the tuple 't', +// appending each result to the 'out' iterator. Returns the final value +// of 'out'. +template +OutIter TransformTupleValues(Func f, const Tuple& t, OutIter out) { + return TransformTupleValuesHelper::Run(f, t, out); +} + +// Implements A(). +template +class AnyMatcherImpl : public MatcherInterface { + public: + virtual bool MatchAndExplain( + T /* x */, MatchResultListener* /* listener */) const { return true; } + virtual void DescribeTo(::std::ostream* os) const { *os << "is anything"; } + virtual void DescribeNegationTo(::std::ostream* os) const { + // This is mostly for completeness' safe, as it's not very useful + // to write Not(A()). However we cannot completely rule out + // such a possibility, and it doesn't hurt to be prepared. + *os << "never matches"; + } +}; + +// Implements _, a matcher that matches any value of any +// type. This is a polymorphic matcher, so we need a template type +// conversion operator to make it appearing as a Matcher for any +// type T. +class AnythingMatcher { + public: + template + operator Matcher() const { return A(); } +}; + +// Implements a matcher that compares a given value with a +// pre-supplied value using one of the ==, <=, <, etc, operators. The +// two values being compared don't have to have the same type. +// +// The matcher defined here is polymorphic (for example, Eq(5) can be +// used to match an int, a short, a double, etc). Therefore we use +// a template type conversion operator in the implementation. +// +// We define this as a macro in order to eliminate duplicated source +// code. +// +// The following template definition assumes that the Rhs parameter is +// a "bare" type (i.e. neither 'const T' nor 'T&'). +#define GMOCK_IMPLEMENT_COMPARISON_MATCHER_( \ + name, op, relation, negated_relation) \ + template class name##Matcher { \ + public: \ + explicit name##Matcher(const Rhs& rhs) : rhs_(rhs) {} \ + template \ + operator Matcher() const { \ + return MakeMatcher(new Impl(rhs_)); \ + } \ + private: \ + template \ + class Impl : public MatcherInterface { \ + public: \ + explicit Impl(const Rhs& rhs) : rhs_(rhs) {} \ + virtual bool MatchAndExplain(\ + Lhs lhs, MatchResultListener* /* listener */) const { \ + return lhs op rhs_; \ + } \ + virtual void DescribeTo(::std::ostream* os) const { \ + *os << relation " "; \ + UniversalPrint(rhs_, os); \ + } \ + virtual void DescribeNegationTo(::std::ostream* os) const { \ + *os << negated_relation " "; \ + UniversalPrint(rhs_, os); \ + } \ + private: \ + Rhs rhs_; \ + GTEST_DISALLOW_ASSIGN_(Impl); \ + }; \ + Rhs rhs_; \ + GTEST_DISALLOW_ASSIGN_(name##Matcher); \ + } + +// Implements Eq(v), Ge(v), Gt(v), Le(v), Lt(v), and Ne(v) +// respectively. +GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Eq, ==, "is equal to", "isn't equal to"); +GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Ge, >=, "is >=", "isn't >="); +GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Gt, >, "is >", "isn't >"); +GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Le, <=, "is <=", "isn't <="); +GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Lt, <, "is <", "isn't <"); +GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Ne, !=, "isn't equal to", "is equal to"); + +#undef GMOCK_IMPLEMENT_COMPARISON_MATCHER_ + +// Implements the polymorphic IsNull() matcher, which matches any raw or smart +// pointer that is NULL. +class IsNullMatcher { + public: + template + bool MatchAndExplain(const Pointer& p, + MatchResultListener* /* listener */) const { + return GetRawPointer(p) == NULL; + } + + void DescribeTo(::std::ostream* os) const { *os << "is NULL"; } + void DescribeNegationTo(::std::ostream* os) const { + *os << "isn't NULL"; + } +}; + +// Implements the polymorphic NotNull() matcher, which matches any raw or smart +// pointer that is not NULL. +class NotNullMatcher { + public: + template + bool MatchAndExplain(const Pointer& p, + MatchResultListener* /* listener */) const { + return GetRawPointer(p) != NULL; + } + + void DescribeTo(::std::ostream* os) const { *os << "isn't NULL"; } + void DescribeNegationTo(::std::ostream* os) const { + *os << "is NULL"; + } +}; + +// Ref(variable) matches any argument that is a reference to +// 'variable'. This matcher is polymorphic as it can match any +// super type of the type of 'variable'. +// +// The RefMatcher template class implements Ref(variable). It can +// only be instantiated with a reference type. This prevents a user +// from mistakenly using Ref(x) to match a non-reference function +// argument. For example, the following will righteously cause a +// compiler error: +// +// int n; +// Matcher m1 = Ref(n); // This won't compile. +// Matcher m2 = Ref(n); // This will compile. +template +class RefMatcher; + +template +class RefMatcher { + // Google Mock is a generic framework and thus needs to support + // mocking any function types, including those that take non-const + // reference arguments. Therefore the template parameter T (and + // Super below) can be instantiated to either a const type or a + // non-const type. + public: + // RefMatcher() takes a T& instead of const T&, as we want the + // compiler to catch using Ref(const_value) as a matcher for a + // non-const reference. + explicit RefMatcher(T& x) : object_(x) {} // NOLINT + + template + operator Matcher() const { + // By passing object_ (type T&) to Impl(), which expects a Super&, + // we make sure that Super is a super type of T. In particular, + // this catches using Ref(const_value) as a matcher for a + // non-const reference, as you cannot implicitly convert a const + // reference to a non-const reference. + return MakeMatcher(new Impl(object_)); + } + + private: + template + class Impl : public MatcherInterface { + public: + explicit Impl(Super& x) : object_(x) {} // NOLINT + + // MatchAndExplain() takes a Super& (as opposed to const Super&) + // in order to match the interface MatcherInterface. + virtual bool MatchAndExplain( + Super& x, MatchResultListener* listener) const { + *listener << "which is located @" << static_cast(&x); + return &x == &object_; + } + + virtual void DescribeTo(::std::ostream* os) const { + *os << "references the variable "; + UniversalPrinter::Print(object_, os); + } + + virtual void DescribeNegationTo(::std::ostream* os) const { + *os << "does not reference the variable "; + UniversalPrinter::Print(object_, os); + } + + private: + const Super& object_; + + GTEST_DISALLOW_ASSIGN_(Impl); + }; + + T& object_; + + GTEST_DISALLOW_ASSIGN_(RefMatcher); +}; + +// Polymorphic helper functions for narrow and wide string matchers. +inline bool CaseInsensitiveCStringEquals(const char* lhs, const char* rhs) { + return String::CaseInsensitiveCStringEquals(lhs, rhs); +} + +inline bool CaseInsensitiveCStringEquals(const wchar_t* lhs, + const wchar_t* rhs) { + return String::CaseInsensitiveWideCStringEquals(lhs, rhs); +} + +// String comparison for narrow or wide strings that can have embedded NUL +// characters. +template +bool CaseInsensitiveStringEquals(const StringType& s1, + const StringType& s2) { + // Are the heads equal? + if (!CaseInsensitiveCStringEquals(s1.c_str(), s2.c_str())) { + return false; + } + + // Skip the equal heads. + const typename StringType::value_type nul = 0; + const size_t i1 = s1.find(nul), i2 = s2.find(nul); + + // Are we at the end of either s1 or s2? + if (i1 == StringType::npos || i2 == StringType::npos) { + return i1 == i2; + } + + // Are the tails equal? + return CaseInsensitiveStringEquals(s1.substr(i1 + 1), s2.substr(i2 + 1)); +} + +// String matchers. + +// Implements equality-based string matchers like StrEq, StrCaseNe, and etc. +template +class StrEqualityMatcher { + public: + StrEqualityMatcher(const StringType& str, bool expect_eq, + bool case_sensitive) + : string_(str), expect_eq_(expect_eq), case_sensitive_(case_sensitive) {} + + // Accepts pointer types, particularly: + // const char* + // char* + // const wchar_t* + // wchar_t* + template + bool MatchAndExplain(CharType* s, MatchResultListener* listener) const { + if (s == NULL) { + return !expect_eq_; + } + return MatchAndExplain(StringType(s), listener); + } + + // Matches anything that can convert to StringType. + // + // This is a template, not just a plain function with const StringType&, + // because StringPiece has some interfering non-explicit constructors. + template + bool MatchAndExplain(const MatcheeStringType& s, + MatchResultListener* /* listener */) const { + const StringType& s2(s); + const bool eq = case_sensitive_ ? s2 == string_ : + CaseInsensitiveStringEquals(s2, string_); + return expect_eq_ == eq; + } + + void DescribeTo(::std::ostream* os) const { + DescribeToHelper(expect_eq_, os); + } + + void DescribeNegationTo(::std::ostream* os) const { + DescribeToHelper(!expect_eq_, os); + } + + private: + void DescribeToHelper(bool expect_eq, ::std::ostream* os) const { + *os << (expect_eq ? "is " : "isn't "); + *os << "equal to "; + if (!case_sensitive_) { + *os << "(ignoring case) "; + } + UniversalPrint(string_, os); + } + + const StringType string_; + const bool expect_eq_; + const bool case_sensitive_; + + GTEST_DISALLOW_ASSIGN_(StrEqualityMatcher); +}; + +// Implements the polymorphic HasSubstr(substring) matcher, which +// can be used as a Matcher as long as T can be converted to a +// string. +template +class HasSubstrMatcher { + public: + explicit HasSubstrMatcher(const StringType& substring) + : substring_(substring) {} + + // Accepts pointer types, particularly: + // const char* + // char* + // const wchar_t* + // wchar_t* + template + bool MatchAndExplain(CharType* s, MatchResultListener* listener) const { + return s != NULL && MatchAndExplain(StringType(s), listener); + } + + // Matches anything that can convert to StringType. + // + // This is a template, not just a plain function with const StringType&, + // because StringPiece has some interfering non-explicit constructors. + template + bool MatchAndExplain(const MatcheeStringType& s, + MatchResultListener* /* listener */) const { + const StringType& s2(s); + return s2.find(substring_) != StringType::npos; + } + + // Describes what this matcher matches. + void DescribeTo(::std::ostream* os) const { + *os << "has substring "; + UniversalPrint(substring_, os); + } + + void DescribeNegationTo(::std::ostream* os) const { + *os << "has no substring "; + UniversalPrint(substring_, os); + } + + private: + const StringType substring_; + + GTEST_DISALLOW_ASSIGN_(HasSubstrMatcher); +}; + +// Implements the polymorphic StartsWith(substring) matcher, which +// can be used as a Matcher as long as T can be converted to a +// string. +template +class StartsWithMatcher { + public: + explicit StartsWithMatcher(const StringType& prefix) : prefix_(prefix) { + } + + // Accepts pointer types, particularly: + // const char* + // char* + // const wchar_t* + // wchar_t* + template + bool MatchAndExplain(CharType* s, MatchResultListener* listener) const { + return s != NULL && MatchAndExplain(StringType(s), listener); + } + + // Matches anything that can convert to StringType. + // + // This is a template, not just a plain function with const StringType&, + // because StringPiece has some interfering non-explicit constructors. + template + bool MatchAndExplain(const MatcheeStringType& s, + MatchResultListener* /* listener */) const { + const StringType& s2(s); + return s2.length() >= prefix_.length() && + s2.substr(0, prefix_.length()) == prefix_; + } + + void DescribeTo(::std::ostream* os) const { + *os << "starts with "; + UniversalPrint(prefix_, os); + } + + void DescribeNegationTo(::std::ostream* os) const { + *os << "doesn't start with "; + UniversalPrint(prefix_, os); + } + + private: + const StringType prefix_; + + GTEST_DISALLOW_ASSIGN_(StartsWithMatcher); +}; + +// Implements the polymorphic EndsWith(substring) matcher, which +// can be used as a Matcher as long as T can be converted to a +// string. +template +class EndsWithMatcher { + public: + explicit EndsWithMatcher(const StringType& suffix) : suffix_(suffix) {} + + // Accepts pointer types, particularly: + // const char* + // char* + // const wchar_t* + // wchar_t* + template + bool MatchAndExplain(CharType* s, MatchResultListener* listener) const { + return s != NULL && MatchAndExplain(StringType(s), listener); + } + + // Matches anything that can convert to StringType. + // + // This is a template, not just a plain function with const StringType&, + // because StringPiece has some interfering non-explicit constructors. + template + bool MatchAndExplain(const MatcheeStringType& s, + MatchResultListener* /* listener */) const { + const StringType& s2(s); + return s2.length() >= suffix_.length() && + s2.substr(s2.length() - suffix_.length()) == suffix_; + } + + void DescribeTo(::std::ostream* os) const { + *os << "ends with "; + UniversalPrint(suffix_, os); + } + + void DescribeNegationTo(::std::ostream* os) const { + *os << "doesn't end with "; + UniversalPrint(suffix_, os); + } + + private: + const StringType suffix_; + + GTEST_DISALLOW_ASSIGN_(EndsWithMatcher); +}; + +// Implements polymorphic matchers MatchesRegex(regex) and +// ContainsRegex(regex), which can be used as a Matcher as long as +// T can be converted to a string. +class MatchesRegexMatcher { + public: + MatchesRegexMatcher(const RE* regex, bool full_match) + : regex_(regex), full_match_(full_match) {} + + // Accepts pointer types, particularly: + // const char* + // char* + // const wchar_t* + // wchar_t* + template + bool MatchAndExplain(CharType* s, MatchResultListener* listener) const { + return s != NULL && MatchAndExplain(internal::string(s), listener); + } + + // Matches anything that can convert to internal::string. + // + // This is a template, not just a plain function with const internal::string&, + // because StringPiece has some interfering non-explicit constructors. + template + bool MatchAndExplain(const MatcheeStringType& s, + MatchResultListener* /* listener */) const { + const internal::string& s2(s); + return full_match_ ? RE::FullMatch(s2, *regex_) : + RE::PartialMatch(s2, *regex_); + } + + void DescribeTo(::std::ostream* os) const { + *os << (full_match_ ? "matches" : "contains") + << " regular expression "; + UniversalPrinter::Print(regex_->pattern(), os); + } + + void DescribeNegationTo(::std::ostream* os) const { + *os << "doesn't " << (full_match_ ? "match" : "contain") + << " regular expression "; + UniversalPrinter::Print(regex_->pattern(), os); + } + + private: + const internal::linked_ptr regex_; + const bool full_match_; + + GTEST_DISALLOW_ASSIGN_(MatchesRegexMatcher); +}; + +// Implements a matcher that compares the two fields of a 2-tuple +// using one of the ==, <=, <, etc, operators. The two fields being +// compared don't have to have the same type. +// +// The matcher defined here is polymorphic (for example, Eq() can be +// used to match a tuple, a tuple, +// etc). Therefore we use a template type conversion operator in the +// implementation. +// +// We define this as a macro in order to eliminate duplicated source +// code. +#define GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(name, op, relation) \ + class name##2Matcher { \ + public: \ + template \ + operator Matcher< ::std::tr1::tuple >() const { \ + return MakeMatcher(new Impl< ::std::tr1::tuple >); \ + } \ + template \ + operator Matcher&>() const { \ + return MakeMatcher(new Impl&>); \ + } \ + private: \ + template \ + class Impl : public MatcherInterface { \ + public: \ + virtual bool MatchAndExplain( \ + Tuple args, \ + MatchResultListener* /* listener */) const { \ + return ::std::tr1::get<0>(args) op ::std::tr1::get<1>(args); \ + } \ + virtual void DescribeTo(::std::ostream* os) const { \ + *os << "are " relation; \ + } \ + virtual void DescribeNegationTo(::std::ostream* os) const { \ + *os << "aren't " relation; \ + } \ + }; \ + } + +// Implements Eq(), Ge(), Gt(), Le(), Lt(), and Ne() respectively. +GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(Eq, ==, "an equal pair"); +GMOCK_IMPLEMENT_COMPARISON2_MATCHER_( + Ge, >=, "a pair where the first >= the second"); +GMOCK_IMPLEMENT_COMPARISON2_MATCHER_( + Gt, >, "a pair where the first > the second"); +GMOCK_IMPLEMENT_COMPARISON2_MATCHER_( + Le, <=, "a pair where the first <= the second"); +GMOCK_IMPLEMENT_COMPARISON2_MATCHER_( + Lt, <, "a pair where the first < the second"); +GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(Ne, !=, "an unequal pair"); + +#undef GMOCK_IMPLEMENT_COMPARISON2_MATCHER_ + +// Implements the Not(...) matcher for a particular argument type T. +// We do not nest it inside the NotMatcher class template, as that +// will prevent different instantiations of NotMatcher from sharing +// the same NotMatcherImpl class. +template +class NotMatcherImpl : public MatcherInterface { + public: + explicit NotMatcherImpl(const Matcher& matcher) + : matcher_(matcher) {} + + virtual bool MatchAndExplain(T x, MatchResultListener* listener) const { + return !matcher_.MatchAndExplain(x, listener); + } + + virtual void DescribeTo(::std::ostream* os) const { + matcher_.DescribeNegationTo(os); + } + + virtual void DescribeNegationTo(::std::ostream* os) const { + matcher_.DescribeTo(os); + } + + private: + const Matcher matcher_; + + GTEST_DISALLOW_ASSIGN_(NotMatcherImpl); +}; + +// Implements the Not(m) matcher, which matches a value that doesn't +// match matcher m. +template +class NotMatcher { + public: + explicit NotMatcher(InnerMatcher matcher) : matcher_(matcher) {} + + // This template type conversion operator allows Not(m) to be used + // to match any type m can match. + template + operator Matcher() const { + return Matcher(new NotMatcherImpl(SafeMatcherCast(matcher_))); + } + + private: + InnerMatcher matcher_; + + GTEST_DISALLOW_ASSIGN_(NotMatcher); +}; + +// Implements the AllOf(m1, m2) matcher for a particular argument type +// T. We do not nest it inside the BothOfMatcher class template, as +// that will prevent different instantiations of BothOfMatcher from +// sharing the same BothOfMatcherImpl class. +template +class BothOfMatcherImpl : public MatcherInterface { + public: + BothOfMatcherImpl(const Matcher& matcher1, const Matcher& matcher2) + : matcher1_(matcher1), matcher2_(matcher2) {} + + virtual void DescribeTo(::std::ostream* os) const { + *os << "("; + matcher1_.DescribeTo(os); + *os << ") and ("; + matcher2_.DescribeTo(os); + *os << ")"; + } + + virtual void DescribeNegationTo(::std::ostream* os) const { + *os << "("; + matcher1_.DescribeNegationTo(os); + *os << ") or ("; + matcher2_.DescribeNegationTo(os); + *os << ")"; + } + + virtual bool MatchAndExplain(T x, MatchResultListener* listener) const { + // If either matcher1_ or matcher2_ doesn't match x, we only need + // to explain why one of them fails. + StringMatchResultListener listener1; + if (!matcher1_.MatchAndExplain(x, &listener1)) { + *listener << listener1.str(); + return false; + } + + StringMatchResultListener listener2; + if (!matcher2_.MatchAndExplain(x, &listener2)) { + *listener << listener2.str(); + return false; + } + + // Otherwise we need to explain why *both* of them match. + const internal::string s1 = listener1.str(); + const internal::string s2 = listener2.str(); + + if (s1 == "") { + *listener << s2; + } else { + *listener << s1; + if (s2 != "") { + *listener << ", and " << s2; + } + } + return true; + } + + private: + const Matcher matcher1_; + const Matcher matcher2_; + + GTEST_DISALLOW_ASSIGN_(BothOfMatcherImpl); +}; + +#if GTEST_LANG_CXX11 +// MatcherList provides mechanisms for storing a variable number of matchers in +// a list structure (ListType) and creating a combining matcher from such a +// list. +// The template is defined recursively using the following template paramters: +// * kSize is the length of the MatcherList. +// * Head is the type of the first matcher of the list. +// * Tail denotes the types of the remaining matchers of the list. +template +struct MatcherList { + typedef MatcherList MatcherListTail; + typedef ::std::pair ListType; + + // BuildList stores variadic type values in a nested pair structure. + // Example: + // MatcherList<3, int, string, float>::BuildList(5, "foo", 2.0) will return + // the corresponding result of type pair>. + static ListType BuildList(const Head& matcher, const Tail&... tail) { + return ListType(matcher, MatcherListTail::BuildList(tail...)); + } + + // CreateMatcher creates a Matcher from a given list of matchers (built + // by BuildList()). CombiningMatcher is used to combine the matchers of the + // list. CombiningMatcher must implement MatcherInterface and have a + // constructor taking two Matchers as input. + template class CombiningMatcher> + static Matcher CreateMatcher(const ListType& matchers) { + return Matcher(new CombiningMatcher( + SafeMatcherCast(matchers.first), + MatcherListTail::template CreateMatcher( + matchers.second))); + } +}; + +// The following defines the base case for the recursive definition of +// MatcherList. +template +struct MatcherList<2, Matcher1, Matcher2> { + typedef ::std::pair ListType; + + static ListType BuildList(const Matcher1& matcher1, + const Matcher2& matcher2) { + return ::std::pair(matcher1, matcher2); + } + + template class CombiningMatcher> + static Matcher CreateMatcher(const ListType& matchers) { + return Matcher(new CombiningMatcher( + SafeMatcherCast(matchers.first), + SafeMatcherCast(matchers.second))); + } +}; + +// VariadicMatcher is used for the variadic implementation of +// AllOf(m_1, m_2, ...) and AnyOf(m_1, m_2, ...). +// CombiningMatcher is used to recursively combine the provided matchers +// (of type Args...). +template