├── .gitignore ├── .travis.yml ├── CHANGELOG ├── CMakeLists.txt ├── COPYRIGHT ├── README.md ├── ambe3600x2400.c ├── ambe3600x2400_const.h ├── ambe3600x2450.c ├── ambe3600x2450_const.h ├── cmake_uninstall.cmake.in ├── config.h ├── debian ├── changelog ├── compat ├── control ├── copyright ├── libmbe-dev.install ├── libmbe1.install ├── rules └── source │ └── format ├── ecc.c ├── ecc_const.h ├── imbe7100x4400.c ├── imbe7200x4400.c ├── imbe7200x4400_const.h ├── libmbe.pc.in ├── mbelib.c ├── mbelib.h ├── mbelib_Author.pgp ├── mbelib_const.h └── test ├── CMakeLists.txt ├── gmock ├── CMakeLists.txt ├── include │ └── gmock │ │ ├── gmock-actions.h │ │ ├── gmock-cardinalities.h │ │ ├── gmock-generated-actions.h │ │ ├── gmock-generated-actions.h.pump │ │ ├── gmock-generated-function-mockers.h │ │ ├── gmock-generated-function-mockers.h.pump │ │ ├── gmock-generated-matchers.h │ │ ├── gmock-generated-matchers.h.pump │ │ ├── gmock-generated-nice-strict.h │ │ ├── gmock-generated-nice-strict.h.pump │ │ ├── gmock-matchers.h │ │ ├── gmock-more-actions.h │ │ ├── gmock-more-matchers.h │ │ ├── gmock-spec-builders.h │ │ ├── gmock.h │ │ └── internal │ │ ├── gmock-generated-internal-utils.h │ │ ├── gmock-generated-internal-utils.h.pump │ │ ├── gmock-internal-utils.h │ │ └── gmock-port.h └── src │ ├── gmock-all.cc │ ├── gmock-cardinalities.cc │ ├── gmock-internal-utils.cc │ ├── gmock-matchers.cc │ ├── gmock-spec-builders.cc │ ├── gmock.cc │ └── gmock_main.cc ├── gtest ├── CMakeLists.txt ├── cmake │ └── internal_utils.cmake ├── include │ └── gtest │ │ ├── gtest-death-test.h │ │ ├── gtest-message.h │ │ ├── gtest-param-test.h │ │ ├── gtest-param-test.h.pump │ │ ├── gtest-printers.h │ │ ├── gtest-spi.h │ │ ├── gtest-test-part.h │ │ ├── gtest-typed-test.h │ │ ├── gtest.h │ │ ├── gtest_pred_impl.h │ │ ├── gtest_prod.h │ │ └── internal │ │ ├── gtest-death-test-internal.h │ │ ├── gtest-filepath.h │ │ ├── gtest-internal.h │ │ ├── gtest-linked_ptr.h │ │ ├── gtest-param-util-generated.h │ │ ├── gtest-param-util-generated.h.pump │ │ ├── gtest-param-util.h │ │ ├── gtest-port.h │ │ ├── gtest-string.h │ │ ├── gtest-tuple.h │ │ ├── gtest-tuple.h.pump │ │ ├── gtest-type-util.h │ │ └── gtest-type-util.h.pump └── src │ ├── gtest-all.cc │ ├── gtest-death-test.cc │ ├── gtest-filepath.cc │ ├── gtest-internal-inl.h │ ├── gtest-port.cc │ ├── gtest-printers.cc │ ├── gtest-test-part.cc │ ├── gtest-typed-test.cc │ ├── gtest.cc │ └── gtest_main.cc ├── mbe-test.cpp └── test.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | *.[ao] 2 | *.so* 3 | *.dylib 4 | build 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | 3 | compiler: 4 | - gcc 5 | 6 | before_script: 7 | - mkdir build 8 | - cd build 9 | - cmake .. 10 | 11 | script: 12 | - make 13 | - make test 14 | -------------------------------------------------------------------------------- /CHANGELOG: -------------------------------------------------------------------------------- 1 | 1.3.0: 2 | Initial DSTAR AMBE support 3 | Fixed random number generator 4 | Several bug fixes and optimizations 5 | 6 | 1.2.5 Use CMake: 7 | The cross platform building was getting hard to maintain, 8 | removed Makefile in favor of CMake. 9 | 10 | 1.2.4 Fixed bugs: 11 | Makefile cleanup 12 | Readme file improvements 13 | fix golayMatrix 14 | bug in imbe7100x4400 15 | 16 | 1.2.3 Fixed bugs: 17 | Cik array in mbe_decodeAmbe2250Parms was too small 18 | 19 | 1.2.2 Fixed bugs: 20 | uninitialized variable in SpectralAmpEnhance() 21 | 22 | 1.2.1 New Features: 23 | 24 | Improved unvoiced speech synthesis 25 | 26 | Fixed bugs: 27 | bug in spectralAmpEnhance() 28 | 29 | 1.2 New features: 30 | Support for imbe7100x4400 vocoder 31 | Improved audio quality 32 | 33 | Fixed bugs: 34 | error in hamming ecc 35 | 36 | 1.1 New features: 37 | new synthesizer functions with floating point output buffer. 38 | original short output buffer function stubs for compatibility. 39 | audio gain and clipping is no longer done during synthesis 40 | except within the compatibility functions. 41 | 42 | 1.0.2 Fixed bugs: 43 | fixed several problems in synthesizer causing clicks 44 | reduced error -> repeat thresholds for reduced noise bursts 45 | ambe3600x2250 now correctly handles "Silence" frames 46 | ambe Tone and Erasure frames are now indicated with T and E in errorbars 47 | 48 | 1.0.1 Fixed bugs: 49 | cur_mp->repeat was not being copied to prev_mp 50 | logic to check for bad mbe frames was incorrect 51 | 52 | 1.0 First release 53 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(mbe) 2 | cmake_minimum_required(VERSION 2.6) 3 | 4 | if(MSVC) 5 | # needed for M_PI macro 6 | add_definitions(-D_USE_MATH_DEFINES) 7 | endif() 8 | 9 | FILE(GLOB SRCS *.c) 10 | 11 | include_directories("${PROJECT_SOURCE_DIR}") 12 | 13 | ADD_LIBRARY(mbe-static STATIC ${SRCS}) 14 | ADD_LIBRARY(mbe-shared SHARED ${SRCS}) 15 | if(NOT WIN32) 16 | TARGET_LINK_LIBRARIES(mbe-static m) 17 | TARGET_LINK_LIBRARIES(mbe-shared m) 18 | endif() 19 | 20 | include(GNUInstallDirs) 21 | 22 | set_target_properties(mbe-static mbe-shared 23 | PROPERTIES 24 | OUTPUT_NAME mbe 25 | VERSION 1.3 26 | SOVERSION 1 27 | INSTALL_NAME_DIR ${CMAKE_INSTALL_FULL_LIBDIR} 28 | PUBLIC_HEADER "mbelib.h") 29 | 30 | configure_file("${CMAKE_CURRENT_SOURCE_DIR}/libmbe.pc.in" 31 | "${CMAKE_CURRENT_BINARY_DIR}/libmbe.pc" 32 | @ONLY) 33 | 34 | install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libmbe.pc" 35 | DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") 36 | 37 | install(TARGETS mbe-static mbe-shared 38 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} 39 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} 40 | PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) 41 | 42 | # uninstall target 43 | configure_file( 44 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in" 45 | "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" 46 | IMMEDIATE @ONLY) 47 | 48 | add_custom_target(uninstall 49 | COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) 50 | 51 | option(DISABLE_TEST "Disable building of test framework." OFF) 52 | 53 | if (NOT DISABLE_TEST) 54 | enable_testing() 55 | add_subdirectory(test) 56 | endif() 57 | -------------------------------------------------------------------------------- /COPYRIGHT: -------------------------------------------------------------------------------- 1 | Copyright (C) 2010 mbelib Author 2 | GPG Key ID: 0xEA5EFE2C (9E7A 5527 9CDC EBF7 BF1B D772 4F98 E863 EA5E FE2C) 3 | 4 | Permission to use, copy, modify, and/or distribute this software for any 5 | purpose with or without fee is hereby granted, provided that the above 6 | copyright notice and this permission notice appear in all copies. 7 | 8 | THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 9 | REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 10 | AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 11 | INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 12 | LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 13 | OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 14 | PERFORMANCE OF THIS SOFTWARE. 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.org/szechyjs/mbelib.png?branch=master)](https://travis-ci.org/szechyjs/mbelib) 2 | 3 | PATENT NOTICE 4 | 5 | This source code is provided for educational purposes only. It is 6 | a written description of how certain voice encoding/decoding 7 | algorythims could be implemented. Executable objects compiled or 8 | derived from this package may be covered by one or more patents. 9 | Readers are strongly advised to check for any patent restrictions or 10 | licencing requirements before compiling or using this source code. 11 | 12 | mbelib 1.3.0 13 | 14 | mbelib supports the 7200x4400 bit/s codec used in P25 Phase 1, 15 | the 7100x4400 bit/s codec used in ProVoice and the "Half Rate" 16 | 3600x2250 bit/s vocoder used in various radio systems. 17 | 18 | Example building instructions on Ubuntu: 19 | 20 | sudo apt-get update 21 | sudo apt-get install git make cmake # Update packages 22 | git clone # Something like: git@github.com:USERNAME/mbelib.git 23 | cd mbelib # Move into source folder 24 | mkdir build # Create build directory 25 | cd build # Move to build directory 26 | cmake .. # Create Makefile for current system 27 | make # Compiles the library 28 | sudo make install # Library is installed into computer 29 | -------------------------------------------------------------------------------- /cmake_uninstall.cmake.in: -------------------------------------------------------------------------------- 1 | if (NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") 2 | message(FATAL_ERROR "Cannot find install manifest: \"@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt\"") 3 | endif(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") 4 | 5 | file(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files) 6 | string(REGEX REPLACE "\n" ";" files "${files}") 7 | cmake_policy(SET CMP0007 OLD) 8 | list(REVERSE files) 9 | foreach (file ${files}) 10 | message(STATUS "Uninstalling \"$ENV{DESTDIR}${file}\"") 11 | if (EXISTS "$ENV{DESTDIR}${file}") 12 | execute_process( 13 | COMMAND @CMAKE_COMMAND@ -E remove "$ENV{DESTDIR}${file}" 14 | OUTPUT_VARIABLE rm_out 15 | RESULT_VARIABLE rm_retval 16 | ) 17 | if(NOT ${rm_retval} EQUAL 0) 18 | message(FATAL_ERROR "Problem when removing \"$ENV{DESTDIR}${file}\"") 19 | endif (NOT ${rm_retval} EQUAL 0) 20 | else (EXISTS "$ENV{DESTDIR}${file}") 21 | message(STATUS "File \"$ENV{DESTDIR}${file}\" does not exist.") 22 | endif (EXISTS "$ENV{DESTDIR}${file}") 23 | endforeach(file) -------------------------------------------------------------------------------- /config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 mbelib Author 3 | * GPG Key ID: 0xEA5EFE2C (9E7A 5527 9CDC EBF7 BF1B D772 4F98 E863 EA5E FE2C) 4 | * 5 | * Permission to use, copy, modify, and/or distribute this software for any 6 | * purpose with or without fee is hereby granted, provided that the above 7 | * copyright notice and this permission notice appear in all copies. 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 10 | * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11 | * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 12 | * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13 | * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 14 | * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15 | * PERFORMANCE OF THIS SOFTWARE. 16 | */ 17 | 18 | /* 19 | * very noisy debug/developer options 20 | */ 21 | 22 | //#define MBE_DEBUG 23 | //#define IMBE_DEBUG 24 | //#define AMBE_DEBUG 25 | -------------------------------------------------------------------------------- /debian/changelog: -------------------------------------------------------------------------------- 1 | libmbe (1.3.0) bionic; urgency=low 2 | 3 | * Initial upload! 4 | 5 | -- Jared Szechy Wed, 27 Jun 2018 23:00:00 -0400 6 | -------------------------------------------------------------------------------- /debian/compat: -------------------------------------------------------------------------------- 1 | 9 -------------------------------------------------------------------------------- /debian/control: -------------------------------------------------------------------------------- 1 | Source: libmbe 2 | Section: libs 3 | Priority: optional 4 | Maintainer: Jared Szechy 5 | Build-Depends: debhelper (>= 9), cmake 6 | Standards-Version: 4.1.4 7 | Homepage: https://github.com/szechyjs/mbelib 8 | Vcs-Git: https://github.com/szechyjs/mbelib.git 9 | Vcs-Browser: https://github.com/szechyjs/mbelib 10 | 11 | Package: libmbe-dev 12 | Section: libdevel 13 | Architecture: any 14 | Multi-Arch: same 15 | Depends: libmbe1 (= ${binary:Version}), ${misc:Depends} 16 | Description: P25 Phase 1 and ProVoice vocoder - development kit 17 | libMBE supports the 7200x4400 bit/s codec used in P25 Phase 1, 18 | the 7100x4400 bit/s codec used in ProVoice and the "Half Rate" 19 | 3600x2250 bit/s vocoder used in various radio systems. 20 | . 21 | This package contains the development files for libmbe. 22 | 23 | Package: libmbe1 24 | Section: libs 25 | Architecture: any 26 | Multi-Arch: same 27 | Pre-Depends: ${misc:Pre-Depends} 28 | Depends: ${shlibs:Depends}, ${misc:Depends} 29 | Description: P25 Phase 1 and ProVoice vocoder - runtime library 30 | libMBE supports the 7200x4400 bit/s codec used in P25 Phase 1, 31 | the 7100x4400 bit/s codec used in ProVoice and the "Half Rate" 32 | 3600x2250 bit/s vocoder used in various radio systems. 33 | . 34 | This package contains the libmbe library used by applications. -------------------------------------------------------------------------------- /debian/copyright: -------------------------------------------------------------------------------- 1 | Copyright (C) 2010 mbelib Author 2 | GPG Key ID: 0xEA5EFE2C (9E7A 5527 9CDC EBF7 BF1B D772 4F98 E863 EA5E FE2C) 3 | 4 | Permission to use, copy, modify, and/or distribute this software for any 5 | purpose with or without fee is hereby granted, provided that the above 6 | copyright notice and this permission notice appear in all copies. 7 | 8 | THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 9 | REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 10 | AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 11 | INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 12 | LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 13 | OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 14 | PERFORMANCE OF THIS SOFTWARE. 15 | -------------------------------------------------------------------------------- /debian/libmbe-dev.install: -------------------------------------------------------------------------------- 1 | usr/include 2 | usr/lib/*/*.so 3 | usr/lib/*/*.a 4 | usr/lib/*/pkgconfig -------------------------------------------------------------------------------- /debian/libmbe1.install: -------------------------------------------------------------------------------- 1 | /usr/lib/*/*.so.* 2 | -------------------------------------------------------------------------------- /debian/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | 3 | %: 4 | dh $@ -------------------------------------------------------------------------------- /debian/source/format: -------------------------------------------------------------------------------- 1 | 3.0 (native) -------------------------------------------------------------------------------- /ecc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 mbelib Author 3 | * GPG Key ID: 0xEA5EFE2C (9E7A 5527 9CDC EBF7 BF1B D772 4F98 E863 EA5E FE2C) 4 | * 5 | * Permission to use, copy, modify, and/or distribute this software for any 6 | * purpose with or without fee is hereby granted, provided that the above 7 | * copyright notice and this permission notice appear in all copies. 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 10 | * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11 | * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 12 | * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13 | * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 14 | * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15 | * PERFORMANCE OF THIS SOFTWARE. 16 | */ 17 | 18 | #include 19 | #include "ecc_const.h" 20 | 21 | void 22 | mbe_checkGolayBlock (long int *block) 23 | { 24 | 25 | static int i, syndrome, eccexpected, eccbits, databits; 26 | long int mask, block_l; 27 | 28 | block_l = *block; 29 | 30 | mask = 0x400000l; 31 | eccexpected = 0; 32 | for (i = 0; i < 12; i++) 33 | { 34 | if ((block_l & mask) != 0l) 35 | { 36 | eccexpected ^= golayGenerator[i]; 37 | } 38 | mask = mask >> 1; 39 | } 40 | eccbits = (int) (block_l & 0x7ffl); 41 | syndrome = eccexpected ^ eccbits; 42 | 43 | databits = (int) (block_l >> 11); 44 | databits = databits ^ golayMatrix[syndrome]; 45 | 46 | *block = (long) databits; 47 | } 48 | 49 | int 50 | mbe_golay2312 (char *in, char *out) 51 | { 52 | 53 | int i, errs; 54 | long block; 55 | 56 | block = 0; 57 | for (i = 22; i >= 0; i--) 58 | { 59 | block = block << 1; 60 | block = block + in[i]; 61 | } 62 | 63 | mbe_checkGolayBlock (&block); 64 | 65 | for (i = 22; i >= 11; i--) 66 | { 67 | out[i] = (block & 2048) >> 11; 68 | block = block << 1; 69 | } 70 | for (i = 10; i >= 0; i--) 71 | { 72 | out[i] = in[i]; 73 | } 74 | 75 | errs = 0; 76 | for (i = 22; i >= 11; i--) 77 | { 78 | if (out[i] != in[i]) 79 | { 80 | errs++; 81 | } 82 | } 83 | return (errs); 84 | } 85 | 86 | int 87 | mbe_hamming1511 (char *in, char *out) 88 | { 89 | int i, j, errs, block, syndrome, stmp, stmp2; 90 | 91 | errs = 0; 92 | 93 | block = 0; 94 | for (i = 14; i >= 0; i--) 95 | { 96 | block <<= 1; 97 | block |= in[i]; 98 | } 99 | 100 | syndrome = 0; 101 | for (i = 0; i < 4; i++) 102 | { 103 | syndrome <<= 1; 104 | stmp = block; 105 | stmp &= hammingGenerator[i]; 106 | 107 | stmp2 = (stmp % 2); 108 | for (j = 0; j < 14; j++) 109 | { 110 | stmp >>= 1; 111 | stmp2 ^= (stmp % 2); 112 | } 113 | 114 | syndrome |= stmp2; 115 | } 116 | if (syndrome > 0) 117 | { 118 | errs++; 119 | block ^= hammingMatrix[syndrome]; 120 | } 121 | 122 | for (i = 14; i >= 0; i--) 123 | { 124 | out[i] = (block & 0x4000) >> 14; 125 | block = block << 1; 126 | } 127 | return (errs); 128 | } 129 | 130 | int 131 | mbe_7100x4400hamming1511 (char *in, char *out) 132 | { 133 | int i, j, errs, block, syndrome, stmp, stmp2; 134 | 135 | errs = 0; 136 | 137 | block = 0; 138 | for (i = 14; i >= 0; i--) 139 | { 140 | block <<= 1; 141 | block |= in[i]; 142 | } 143 | 144 | syndrome = 0; 145 | for (i = 0; i < 4; i++) 146 | { 147 | syndrome <<= 1; 148 | stmp = block; 149 | stmp &= imbe7100x4400hammingGenerator[i]; 150 | 151 | stmp2 = (stmp % 2); 152 | for (j = 0; j < 14; j++) 153 | { 154 | stmp >>= 1; 155 | stmp2 ^= (stmp % 2); 156 | } 157 | 158 | syndrome |= stmp2; 159 | } 160 | if (syndrome > 0) 161 | { 162 | errs++; 163 | block ^= hammingMatrix[syndrome]; 164 | } 165 | 166 | for (i = 14; i >= 0; i--) 167 | { 168 | out[i] = (block & 0x4000) >> 14; 169 | block = block << 1; 170 | } 171 | return (errs); 172 | } 173 | -------------------------------------------------------------------------------- /ecc_const.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 mbelib Author 3 | * GPG Key ID: 0xEA5EFE2C (9E7A 5527 9CDC EBF7 BF1B D772 4F98 E863 EA5E FE2C) 4 | * 5 | * Permission to use, copy, modify, and/or distribute this software for any 6 | * purpose with or without fee is hereby granted, provided that the above 7 | * copyright notice and this permission notice appear in all copies. 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 10 | * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11 | * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 12 | * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13 | * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 14 | * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15 | * PERFORMANCE OF THIS SOFTWARE. 16 | */ 17 | 18 | /* 19 | * constants for ecc.c 20 | */ 21 | #ifndef _ECC_H 22 | #define _ECC_H 23 | 24 | const int hammingGenerator[4] = { 25 | 0x7f08, 0x78e4, 0x66d2, 0x55b1 26 | }; 27 | 28 | const int imbe7100x4400hammingGenerator[4] = { 29 | 0x7ac8, 0x3d64, 0x1eb2, 0x7591 30 | }; 31 | 32 | const int hammingMatrix[16] = { 33 | 0x0, 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80, 0x100, 0x200, 0x400, 0x800, 0x1000, 0x2000, 0x4000 34 | }; 35 | 36 | const int golayGenerator[12] = { 37 | 0x63a, 0x31d, 0x7b4, 0x3da, 0x1ed, 0x6cc, 0x366, 0x1b3, 0x6e3, 0x54b, 0x49f, 0x475 38 | }; 39 | 40 | const int golayMatrix[2048] = { 41 | 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, 42 | 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, 43 | 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, 44 | 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, 45 | 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, 46 | 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, 47 | 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, 48 | 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, 49 | 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, 50 | 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, 51 | 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, 52 | 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, 53 | 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, 54 | 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, 55 | 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, 56 | 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, 57 | 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, 58 | 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, 59 | 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, 60 | 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, 61 | 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, 62 | 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, 63 | 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, 64 | 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, 65 | 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, 66 | 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, 67 | 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, 68 | 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, 69 | 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, 70 | 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, 71 | 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, 72 | 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, 73 | 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, 74 | 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, 75 | 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, 76 | 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, 77 | 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, 78 | 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, 79 | 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, 80 | 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, 81 | 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, 82 | 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, 83 | 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, 84 | 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, 85 | 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, 86 | 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, 87 | 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, 88 | 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, 89 | 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, 90 | 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, 91 | 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, 92 | 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, 93 | 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, 94 | 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, 95 | 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, 96 | 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, 97 | 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, 98 | 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, 99 | 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, 100 | 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, 101 | 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, 102 | 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, 103 | 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, 104 | 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, 105 | 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, 106 | 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, 107 | 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, 108 | 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, 109 | 34, 256, 34, 512, 34, 1032, 80 110 | }; 111 | 112 | #endif 113 | -------------------------------------------------------------------------------- /imbe7100x4400.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 mbelib Author 3 | * GPG Key ID: 0xEA5EFE2C (9E7A 5527 9CDC EBF7 BF1B D772 4F98 E863 EA5E FE2C) 4 | * 5 | * Permission to use, copy, modify, and/or distribute this software for any 6 | * purpose with or without fee is hereby granted, provided that the above 7 | * copyright notice and this permission notice appear in all copies. 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 10 | * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11 | * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 12 | * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13 | * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 14 | * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15 | * PERFORMANCE OF THIS SOFTWARE. 16 | */ 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #include "mbelib.h" 23 | 24 | void 25 | mbe_dumpImbe7100x4400Data (char *imbe_d) 26 | { 27 | 28 | int i; 29 | char *imbe; 30 | 31 | imbe = imbe_d; 32 | for (i = 0; i < 88; i++) 33 | { 34 | if ((i == 7) || (i == 19) || (i == 31) || (i == 43) || (i == 54) || (i == 65)) 35 | { 36 | printf (" "); 37 | } 38 | printf ("%i", *imbe); 39 | imbe++; 40 | } 41 | } 42 | 43 | 44 | void 45 | mbe_dumpImbe7100x4400Frame (char imbe_fr[7][24]) 46 | { 47 | 48 | int i, j; 49 | 50 | for (j = 18; j >= 0; j--) 51 | { 52 | if (j == 11) 53 | { 54 | printf (" "); 55 | } 56 | printf ("%i", imbe_fr[0][j]); 57 | } 58 | printf (" "); 59 | 60 | for (j = 23; j >= 0; j--) 61 | { 62 | if (j == 11) 63 | { 64 | printf (" "); 65 | } 66 | printf ("%i", imbe_fr[1][j]); 67 | } 68 | printf (" "); 69 | 70 | for (i = 2; i < 4; i++) 71 | { 72 | for (j = 22; j >= 0; j--) 73 | { 74 | if (j == 10) 75 | { 76 | printf (" "); 77 | } 78 | printf ("%i", imbe_fr[i][j]); 79 | } 80 | printf (" "); 81 | } 82 | for (i = 4; i < 6; i++) 83 | { 84 | for (j = 14; j >= 0; j--) 85 | { 86 | if (j == 3) 87 | { 88 | printf (" "); 89 | } 90 | printf ("%i", imbe_fr[i][j]); 91 | } 92 | printf (" "); 93 | } 94 | for (j = 22; j >= 0; j--) 95 | { 96 | printf ("%i", imbe_fr[6][j]); 97 | } 98 | } 99 | 100 | int 101 | mbe_eccImbe7100x4400C0 (char imbe_fr[7][24]) 102 | { 103 | 104 | int j, errs; 105 | char in[23], out[23]; 106 | 107 | for (j = 0; j < 18; j++) 108 | { 109 | in[j] = imbe_fr[0][j + 1]; 110 | } 111 | for (j = 18; j < 23; j++) 112 | { 113 | in[j] = 0; 114 | } 115 | 116 | errs = mbe_golay2312 (in, out); 117 | for (j = 0; j < 18; j++) 118 | { 119 | imbe_fr[0][j + 1] = out[j]; 120 | } 121 | 122 | return (errs); 123 | 124 | } 125 | 126 | int 127 | mbe_eccImbe7100x4400Data (char imbe_fr[7][24], char *imbe_d) 128 | { 129 | 130 | int i, j, errs; 131 | char *imbe, gin[23], gout[23], hin[15], hout[15]; 132 | 133 | errs = 0; 134 | imbe = imbe_d; 135 | 136 | // just copy C0 137 | for (j = 18; j > 11; j--) 138 | { 139 | *imbe = imbe_fr[0][j]; 140 | imbe++; 141 | } 142 | 143 | // ecc and copy C1 144 | for (j = 0; j < 23; j++) 145 | { 146 | gin[j] = imbe_fr[1][j + 1]; 147 | } 148 | errs = mbe_golay2312 (gin, gout); 149 | for (j = 22; j > 10; j--) 150 | { 151 | *imbe = gout[j]; 152 | imbe++; 153 | } 154 | 155 | // ecc and copy C2, C3 156 | for (i = 2; i < 4; i++) 157 | { 158 | for (j = 0; j < 23; j++) 159 | { 160 | gin[j] = imbe_fr[i][j]; 161 | } 162 | errs += mbe_golay2312 (gin, gout); 163 | for (j = 22; j > 10; j--) 164 | { 165 | *imbe = gout[j]; 166 | imbe++; 167 | } 168 | } 169 | // ecc and copy C4, C5 170 | for (i = 4; i < 6; i++) 171 | { 172 | for (j = 0; j < 15; j++) 173 | { 174 | hin[j] = imbe_fr[i][j]; 175 | } 176 | errs += mbe_7100x4400hamming1511 (hin, hout); 177 | for (j = 14; j >= 4; j--) 178 | { 179 | *imbe = hout[j]; 180 | imbe++; 181 | } 182 | } 183 | 184 | // just copy C6 185 | for (j = 22; j >= 0; j--) 186 | { 187 | *imbe = imbe_fr[6][j]; 188 | imbe++; 189 | } 190 | 191 | return (errs); 192 | } 193 | 194 | void 195 | mbe_demodulateImbe7100x4400Data (char imbe[7][24]) 196 | { 197 | 198 | int i, j, k; 199 | unsigned short pr[115]; 200 | unsigned short seed; 201 | char tmpstr[24]; 202 | 203 | // create pseudo-random modulator 204 | j = 0; 205 | tmpstr[7] = 0; 206 | for (i = 18; i > 11; i--) 207 | { 208 | tmpstr[j] = (imbe[0][i] + 48); 209 | j++; 210 | } 211 | seed = strtol (tmpstr, NULL, 2); 212 | pr[0] = (16 * seed); 213 | for (i = 1; i < 101; i++) 214 | { 215 | pr[i] = (173 * pr[i - 1]) + 13849 - (65536 * (((173 * pr[i - 1]) + 13849) / 65536)); 216 | } 217 | seed = pr[100]; 218 | for (i = 1; i < 101; i++) 219 | { 220 | pr[i] = pr[i] / 32768; 221 | } 222 | 223 | // demodulate imbe with pr 224 | k = 1; 225 | for (j = 23; j >= 0; j--) 226 | { 227 | imbe[1][j] = ((imbe[1][j]) ^ pr[k]); 228 | k++; 229 | } 230 | 231 | for (i = 2; i < 4; i++) 232 | { 233 | for (j = 22; j >= 0; j--) 234 | { 235 | imbe[i][j] = ((imbe[i][j]) ^ pr[k]); 236 | k++; 237 | } 238 | } 239 | 240 | for (i = 4; i < 6; i++) 241 | { 242 | for (j = 14; j >= 0; j--) 243 | { 244 | imbe[i][j] = ((imbe[i][j]) ^ pr[k]); 245 | k++; 246 | } 247 | } 248 | } 249 | 250 | void 251 | mbe_convertImbe7100to7200 (char *imbe_d) 252 | { 253 | 254 | int i, j, k, K, L, b0; 255 | char tmpstr[9]; 256 | char tmp_imbe[88]; 257 | float w0; 258 | 259 | // decode fundamental frequency w0 from b0 260 | tmpstr[8] = 0; 261 | tmpstr[0] = imbe_d[1] + 48; 262 | tmpstr[1] = imbe_d[2] + 48; 263 | tmpstr[2] = imbe_d[3] + 48; 264 | tmpstr[3] = imbe_d[4] + 48; 265 | tmpstr[4] = imbe_d[5] + 48; 266 | tmpstr[5] = imbe_d[6] + 48; 267 | tmpstr[6] = imbe_d[86] + 48; 268 | tmpstr[7] = imbe_d[87] + 48; 269 | b0 = strtol (tmpstr, NULL, 2); 270 | w0 = ((float) (4 * M_PI) / (float) ((float) b0 + 39.5)); 271 | 272 | // decode L from w0 273 | L = (int) (0.9254 * (int) ((M_PI / w0) + 0.25)); 274 | 275 | // decode K from L 276 | if (L < 37) 277 | { 278 | K = (int) ((float) (L + 2) / (float) 3); 279 | } 280 | else 281 | { 282 | K = 12; 283 | } 284 | 285 | // rearrange bits from imbe7100x4400 format to imbe7200x4400 format 286 | tmp_imbe[87] = imbe_d[0]; // "status"/zero bit 287 | tmp_imbe[48 + K] = imbe_d[42]; // b2.2 288 | tmp_imbe[49 + K] = imbe_d[43]; // b2.1 289 | 290 | k = 44; 291 | j = 48; 292 | for (i = 0; i < K; i++) 293 | { 294 | tmp_imbe[j] = imbe_d[k]; // b1 295 | j++; 296 | k++; 297 | } 298 | 299 | j = 0; 300 | k = 1; 301 | while (j < 87) 302 | { 303 | tmp_imbe[j] = imbe_d[k]; 304 | if (++j == 48) 305 | { 306 | j += (K + 2); // skip over b1, b2.2, b2.1 on dest 307 | } 308 | if (++k == 42) 309 | { 310 | k += (K + 2); // skip over b2.2, b2.1, b1 on src 311 | } 312 | } 313 | 314 | //copy new format back to imbe_d 315 | 316 | for (i = 0; i < 88; i++) 317 | { 318 | imbe_d[i] = tmp_imbe[i]; 319 | } 320 | 321 | } 322 | 323 | void 324 | 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) 325 | { 326 | 327 | *errs = 0; 328 | *errs2 = 0; 329 | *errs = mbe_eccImbe7100x4400C0 (imbe_fr); 330 | mbe_demodulateImbe7100x4400Data (imbe_fr); 331 | *errs2 = *errs; 332 | *errs2 += mbe_eccImbe7100x4400Data (imbe_fr, imbe_d); 333 | mbe_convertImbe7100to7200 (imbe_d); 334 | 335 | mbe_processImbe4400Dataf (aout_buf, errs, errs2, err_str, imbe_d, cur_mp, prev_mp, prev_mp_enhanced, uvquality); 336 | } 337 | 338 | void 339 | 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) 340 | { 341 | 342 | float float_buf[160]; 343 | mbe_processImbe7100x4400Framef (float_buf, errs, errs2, err_str, imbe_fr, imbe_d, cur_mp, prev_mp, prev_mp_enhanced, uvquality); 344 | mbe_floattoshort (float_buf, aout_buf); 345 | } 346 | -------------------------------------------------------------------------------- /libmbe.pc.in: -------------------------------------------------------------------------------- 1 | libdir=@CMAKE_INSTALL_FULL_LIBDIR@ 2 | includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ 3 | 4 | Name: libMBE 5 | Description: P25 Phase 1 and ProVoice vocoder 6 | Version: 1.3.0 7 | 8 | Libs: -L${libdir} -lmbe 9 | Libs.private: -lm 10 | Cflags: -I${includedir} -------------------------------------------------------------------------------- /mbelib.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 mbelib Author 3 | * GPG Key ID: 0xEA5EFE2C (9E7A 5527 9CDC EBF7 BF1B D772 4F98 E863 EA5E FE2C) 4 | * 5 | * Permission to use, copy, modify, and/or distribute this software for any 6 | * purpose with or without fee is hereby granted, provided that the above 7 | * copyright notice and this permission notice appear in all copies. 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 10 | * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11 | * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 12 | * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13 | * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 14 | * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15 | * PERFORMANCE OF THIS SOFTWARE. 16 | */ 17 | 18 | #ifndef _MBELIB_H 19 | #define _MBELIB_H 20 | 21 | #define MBELIB_VERSION "1.3.0" 22 | 23 | struct mbe_parameters 24 | { 25 | float w0; 26 | int L; 27 | int K; 28 | int Vl[57]; 29 | float Ml[57]; 30 | float log2Ml[57]; 31 | float PHIl[57]; 32 | float PSIl[57]; 33 | float gamma; 34 | int un; 35 | int repeat; 36 | }; 37 | 38 | typedef struct mbe_parameters mbe_parms; 39 | 40 | /* 41 | * Prototypes from ecc.c 42 | */ 43 | void mbe_checkGolayBlock (long int *block); 44 | int mbe_golay2312 (char *in, char *out); 45 | int mbe_hamming1511 (char *in, char *out); 46 | int mbe_7100x4400hamming1511 (char *in, char *out); 47 | 48 | /* 49 | * Prototypes from ambe3600x2400.c 50 | */ 51 | int mbe_eccAmbe3600x2400C0 (char ambe_fr[4][24]); 52 | int mbe_eccAmbe3600x2400Data (char ambe_fr[4][24], char *ambe_d); 53 | int mbe_decodeAmbe2400Parms (char *ambe_d, mbe_parms * cur_mp, mbe_parms * prev_mp); 54 | void mbe_demodulateAmbe3600x2400Data (char ambe_fr[4][24]); 55 | 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); 56 | 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); 57 | 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); 58 | 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); 59 | 60 | /* 61 | * Prototypes from ambe3600x2450.c 62 | */ 63 | int mbe_eccAmbe3600x2450C0 (char ambe_fr[4][24]); 64 | int mbe_eccAmbe3600x2450Data (char ambe_fr[4][24], char *ambe_d); 65 | int mbe_decodeAmbe2450Parms (char *ambe_d, mbe_parms * cur_mp, mbe_parms * prev_mp); 66 | void mbe_demodulateAmbe3600x2450Data (char ambe_fr[4][24]); 67 | 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); 68 | 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); 69 | 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); 70 | 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); 71 | 72 | /* 73 | * Prototypes from imbe7200x4400.c 74 | */ 75 | void mbe_dumpImbe4400Data (char *imbe_d); 76 | void mbe_dumpImbe7200x4400Data (char *imbe_d); 77 | void mbe_dumpImbe7200x4400Frame (char imbe_fr[8][23]); 78 | int mbe_eccImbe7200x4400C0 (char imbe_fr[8][23]); 79 | int mbe_eccImbe7200x4400Data (char imbe_fr[8][23], char *imbe_d); 80 | int mbe_decodeImbe4400Parms (char *imbe_d, mbe_parms * cur_mp, mbe_parms * prev_mp); 81 | void mbe_demodulateImbe7200x4400Data (char imbe[8][23]); 82 | 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); 83 | 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); 84 | 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); 85 | 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); 86 | 87 | /* 88 | * Prototypes from imbe7100x4400.c 89 | */ 90 | void mbe_dumpImbe7100x4400Data (char *imbe_d); 91 | void mbe_dumpImbe7100x4400Frame (char imbe_fr[7][24]); 92 | int mbe_eccImbe7100x4400C0 (char imbe_fr[7][24]); 93 | int mbe_eccImbe7100x4400Data (char imbe_fr[7][24], char *imbe_d); 94 | void mbe_demodulateImbe7100x4400Data (char imbe[7][24]); 95 | void mbe_convertImbe7100to7200 (char *imbe_d); 96 | 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); 97 | 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); 98 | 99 | /* 100 | * Prototypes from mbelib.c 101 | */ 102 | void mbe_printVersion (char *str); 103 | void mbe_moveMbeParms (mbe_parms * cur_mp, mbe_parms * prev_mp); 104 | void mbe_useLastMbeParms (mbe_parms * cur_mp, mbe_parms * prev_mp); 105 | void mbe_initMbeParms (mbe_parms * cur_mp, mbe_parms * prev_mp, mbe_parms * prev_mp_enhanced); 106 | void mbe_spectralAmpEnhance (mbe_parms * cur_mp); 107 | void mbe_synthesizeSilencef (float *aout_buf); 108 | void mbe_synthesizeSilence (short *aout_buf); 109 | void mbe_synthesizeSpeechf (float *aout_buf, mbe_parms * cur_mp, mbe_parms * prev_mp, int uvquality); 110 | void mbe_synthesizeSpeech (short *aout_buf, mbe_parms * cur_mp, mbe_parms * prev_mp, int uvquality); 111 | void mbe_floattoshort (float *float_buf, short *aout_buf); 112 | 113 | #endif 114 | -------------------------------------------------------------------------------- /mbelib_Author.pgp: -------------------------------------------------------------------------------- 1 | -----BEGIN PGP PUBLIC KEY BLOCK----- 2 | Version: GnuPG v1.4.10 3 | 4 | mQENBEufusYBCADN1SNkRkQzdLM02MCjen8KQmfuA38MrQIV0dZLpPJcn1+hsvZZ 5 | KWvpUiWCNw1ClGRsJAT5cjonndi1PV7tpzQz+CyMqSP5OwR40eTJBoZhl74hdmU8 6 | QvcKkJ32khSsOXMo60NHk5iIMDELzOGqq57NHhbunj6NtYog2mR5+WT37JLCvF/q 7 | dvYl2KkRwEHD76/b/O1CyheiiqNMGBb13zPN0qO/PRlENSgViLcDh9qVj4ETNNS6 8 | zMlP4D4pa07iED4Ua31wiXI04ReznnmvMqzQb8uFbg7d98F3bZpsbNURbmsFHMhj 9 | c9qw65nzaMa3OHfZ3Qwl4XRlNqEzZrclIZADABEBAAG0DW1iZWxpYiBBdXRob3KJ 10 | ATgEEwECACIFAkufusYCGwMGCwkIBwMCBhUIAgkKCwQWAgMBAh4BAheAAAoJEE+Y 11 | 6GPqXv4sI/4H/RsumInT5GtDdBTgxt3lERqc5GF8tI5CAQX9DUMMkKxQ306Fgb4M 12 | ISYdepgL6BlbtSyMdKpKsDLScNA6YXER4gMU1nhhyBulqj41kAfsVbG8hiTBy5Ri 13 | FTo36HrC//Zj1MlaTCB8Rl6B6IftAHIb1U+Gda3WnLDe+R5Pym/76TqeYx23PnJl 14 | V+qfrkjbNyOb2bttyko2iccm9DSq/I1OF0Ufz3P60ssUwHW/b2S6WOXRxiZIq0sz 15 | 8pAweUFCxIMWo+XYlSpRtwpebfx+JoHJKdW1cSCgY9jwVsOZO1zxc8P+jr3ByiIR 16 | ZPd0PfBt/AHuC6Hmw9nC12e49+4qsHkj50S5AQ0ES5+6xgEIALf60WjqHm552FIX 17 | KqmG0TIrXpCsYoTWzDdO5j0Ro6fmg9U48BqDH5aS4YRvuyPE7q6DGYEnXF5EIPtU 18 | FhUk4FMmez5eMg91UW4Qjqx8M3reoBROYocM5Nfbc9w7St8+3oRS6rUBIh/B6o4O 19 | kEjkoW3R7O3uFpC53Oi9IVhx/joWxhi430RrUTig5CQzuPFTAHd3xJVE6Pv44nsY 20 | /PsOhBLu2Z3kRkvjcGbsGDlAl2bDEobzQdsqXDD8gJkF5W4IeBKvRC54SE0FSm57 21 | G1gadhZ7vT4DWQZvYYKXR+AE7FTcopoAFHdapYokOGLHCguabyeZ5q7+s7J4nddL 22 | p5yq8ikAEQEAAYkBHwQYAQIACQUCS5+6xgIbDAAKCRBPmOhj6l7+LPi6B/sEkDkm 23 | Qs/aTz9HDANBAbTuDZTY4WBbkPdFos3xxC2Z/TH5m4bfHEkvNk5WD+j+vYB3exAc 24 | uBi7ZiqibRpap4kiAiKKCRXOyvmEmrjKB5wOWbRpkdTeEdPcpsQ4dDDw1ZUKwzjN 25 | 1jI/9GOgq49nAGdlU59f3IdPut6oQNq9vrtanTq2xHVN/rOhV9GLE6gLX1YWkpIH 26 | zYSUheGPsnv4sWRsQDTB7xmF+6RZzjmauKNwsGFscX1TenOWtUbYb9qFCwvNMOSk 27 | 51sEaD6PK6wWTXMqQlgjaoGqh1ZaePgT0QTh1W/bvOD0fL5NEToJl2h/lBSvO+ez 28 | R9B++dt5JX9BMxAH 29 | =puA7 30 | -----END PGP PUBLIC KEY BLOCK----- 31 | -------------------------------------------------------------------------------- /test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(mbetest) 2 | 3 | add_subdirectory(gtest) 4 | add_subdirectory(gmock) 5 | 6 | FILE(GLOB SRCS *.cpp) 7 | 8 | include_directories( 9 | ${PROJECT_SOURCE_DIR}/gtest/include 10 | ${PROJECT_SOURCE_DIR}/gmock/include 11 | ${mbe_SOURCE_DIR} 12 | ) 13 | 14 | link_directories( ${mbe_BINARY_DIR} ) 15 | 16 | ADD_EXECUTABLE(mbetest ${SRCS}) 17 | TARGET_LINK_LIBRARIES(mbetest mbe gmock gtest) 18 | 19 | add_test(gtest mbetest) 20 | -------------------------------------------------------------------------------- /test/gmock/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ######################################################################## 2 | # CMake build script for Google Mock. 3 | # 4 | # To run the tests for Google Mock itself on Linux, use 'make test' or 5 | # ctest. You can select which tests to run using 'ctest -R regex'. 6 | # For more options, run 'ctest --help'. 7 | 8 | # BUILD_SHARED_LIBS is a standard CMake variable, but we declare it here to 9 | # make it prominent in the GUI. 10 | option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)." OFF) 11 | 12 | ######################################################################## 13 | # 14 | # Project-wide settings 15 | 16 | # Name of the project. 17 | # 18 | # CMake files in this project can refer to the root source directory 19 | # as ${gmock_SOURCE_DIR} and to the root binary directory as 20 | # ${gmock_BINARY_DIR}. 21 | # Language "C" is required for find_package(Threads). 22 | project(gmock CXX C) 23 | cmake_minimum_required(VERSION 2.6.2) 24 | 25 | # Adds Google Mock's and Google Test's header directories to the search path. 26 | include_directories("${gmock_SOURCE_DIR}/include" 27 | "${gmock_SOURCE_DIR}" 28 | "${gtest_SOURCE_DIR}/include") 29 | 30 | ######################################################################## 31 | # 32 | # Defines the gmock & gmock_main libraries. User tests should link 33 | # with one of them. 34 | 35 | # Google Mock libraries. We build them using more strict warnings than what 36 | # are used for other targets, to ensure that Google Mock can be compiled by 37 | # a user aggressive about warnings. 38 | cxx_library(gmock 39 | "${cxx_strict}" 40 | src/gmock-all.cc) 41 | 42 | cxx_library(gmock_main 43 | "${cxx_strict}" 44 | src/gmock-all.cc 45 | src/gmock_main.cc) 46 | -------------------------------------------------------------------------------- /test/gmock/include/gmock/gmock-cardinalities.h: -------------------------------------------------------------------------------- 1 | // Copyright 2007, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: wan@google.com (Zhanyong Wan) 31 | 32 | // Google Mock - a framework for writing C++ mock classes. 33 | // 34 | // This file implements some commonly used cardinalities. More 35 | // cardinalities can be defined by the user implementing the 36 | // CardinalityInterface interface if necessary. 37 | 38 | #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_ 39 | #define GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_ 40 | 41 | #include 42 | #include // NOLINT 43 | #include "gmock/internal/gmock-port.h" 44 | #include "gtest/gtest.h" 45 | 46 | namespace testing { 47 | 48 | // To implement a cardinality Foo, define: 49 | // 1. a class FooCardinality that implements the 50 | // CardinalityInterface interface, and 51 | // 2. a factory function that creates a Cardinality object from a 52 | // const FooCardinality*. 53 | // 54 | // The two-level delegation design follows that of Matcher, providing 55 | // consistency for extension developers. It also eases ownership 56 | // management as Cardinality objects can now be copied like plain values. 57 | 58 | // The implementation of a cardinality. 59 | class CardinalityInterface { 60 | public: 61 | virtual ~CardinalityInterface() {} 62 | 63 | // Conservative estimate on the lower/upper bound of the number of 64 | // calls allowed. 65 | virtual int ConservativeLowerBound() const { return 0; } 66 | virtual int ConservativeUpperBound() const { return INT_MAX; } 67 | 68 | // Returns true iff call_count calls will satisfy this cardinality. 69 | virtual bool IsSatisfiedByCallCount(int call_count) const = 0; 70 | 71 | // Returns true iff call_count calls will saturate this cardinality. 72 | virtual bool IsSaturatedByCallCount(int call_count) const = 0; 73 | 74 | // Describes self to an ostream. 75 | virtual void DescribeTo(::std::ostream* os) const = 0; 76 | }; 77 | 78 | // A Cardinality is a copyable and IMMUTABLE (except by assignment) 79 | // object that specifies how many times a mock function is expected to 80 | // be called. The implementation of Cardinality is just a linked_ptr 81 | // to const CardinalityInterface, so copying is fairly cheap. 82 | // Don't inherit from Cardinality! 83 | class GTEST_API_ Cardinality { 84 | public: 85 | // Constructs a null cardinality. Needed for storing Cardinality 86 | // objects in STL containers. 87 | Cardinality() {} 88 | 89 | // Constructs a Cardinality from its implementation. 90 | explicit Cardinality(const CardinalityInterface* impl) : impl_(impl) {} 91 | 92 | // Conservative estimate on the lower/upper bound of the number of 93 | // calls allowed. 94 | int ConservativeLowerBound() const { return impl_->ConservativeLowerBound(); } 95 | int ConservativeUpperBound() const { return impl_->ConservativeUpperBound(); } 96 | 97 | // Returns true iff call_count calls will satisfy this cardinality. 98 | bool IsSatisfiedByCallCount(int call_count) const { 99 | return impl_->IsSatisfiedByCallCount(call_count); 100 | } 101 | 102 | // Returns true iff call_count calls will saturate this cardinality. 103 | bool IsSaturatedByCallCount(int call_count) const { 104 | return impl_->IsSaturatedByCallCount(call_count); 105 | } 106 | 107 | // Returns true iff call_count calls will over-saturate this 108 | // cardinality, i.e. exceed the maximum number of allowed calls. 109 | bool IsOverSaturatedByCallCount(int call_count) const { 110 | return impl_->IsSaturatedByCallCount(call_count) && 111 | !impl_->IsSatisfiedByCallCount(call_count); 112 | } 113 | 114 | // Describes self to an ostream 115 | void DescribeTo(::std::ostream* os) const { impl_->DescribeTo(os); } 116 | 117 | // Describes the given actual call count to an ostream. 118 | static void DescribeActualCallCountTo(int actual_call_count, 119 | ::std::ostream* os); 120 | 121 | private: 122 | internal::linked_ptr impl_; 123 | }; 124 | 125 | // Creates a cardinality that allows at least n calls. 126 | GTEST_API_ Cardinality AtLeast(int n); 127 | 128 | // Creates a cardinality that allows at most n calls. 129 | GTEST_API_ Cardinality AtMost(int n); 130 | 131 | // Creates a cardinality that allows any number of calls. 132 | GTEST_API_ Cardinality AnyNumber(); 133 | 134 | // Creates a cardinality that allows between min and max calls. 135 | GTEST_API_ Cardinality Between(int min, int max); 136 | 137 | // Creates a cardinality that allows exactly n calls. 138 | GTEST_API_ Cardinality Exactly(int n); 139 | 140 | // Creates a cardinality from its implementation. 141 | inline Cardinality MakeCardinality(const CardinalityInterface* c) { 142 | return Cardinality(c); 143 | } 144 | 145 | } // namespace testing 146 | 147 | #endif // GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_ 148 | -------------------------------------------------------------------------------- /test/gmock/include/gmock/gmock-generated-function-mockers.h.pump: -------------------------------------------------------------------------------- 1 | $$ -*- mode: c++; -*- 2 | $$ This is a Pump source file. Please use Pump to convert it to 3 | $$ gmock-generated-function-mockers.h. 4 | $$ 5 | $var n = 10 $$ The maximum arity we support. 6 | // Copyright 2007, Google Inc. 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are 11 | // met: 12 | // 13 | // * Redistributions of source code must retain the above copyright 14 | // notice, this list of conditions and the following disclaimer. 15 | // * Redistributions in binary form must reproduce the above 16 | // copyright notice, this list of conditions and the following disclaimer 17 | // in the documentation and/or other materials provided with the 18 | // distribution. 19 | // * Neither the name of Google Inc. nor the names of its 20 | // contributors may be used to endorse or promote products derived from 21 | // this software without specific prior written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 29 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | // 35 | // Author: wan@google.com (Zhanyong Wan) 36 | 37 | // Google Mock - a framework for writing C++ mock classes. 38 | // 39 | // This file implements function mockers of various arities. 40 | 41 | #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_ 42 | #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_ 43 | 44 | #include "gmock/gmock-spec-builders.h" 45 | #include "gmock/internal/gmock-internal-utils.h" 46 | 47 | namespace testing { 48 | namespace internal { 49 | 50 | template 51 | class FunctionMockerBase; 52 | 53 | // Note: class FunctionMocker really belongs to the ::testing 54 | // namespace. However if we define it in ::testing, MSVC will 55 | // complain when classes in ::testing::internal declare it as a 56 | // friend class template. To workaround this compiler bug, we define 57 | // FunctionMocker in ::testing::internal and import it into ::testing. 58 | template 59 | class FunctionMocker; 60 | 61 | 62 | $range i 0..n 63 | $for i [[ 64 | $range j 1..i 65 | $var typename_As = [[$for j [[, typename A$j]]]] 66 | $var As = [[$for j, [[A$j]]]] 67 | $var as = [[$for j, [[a$j]]]] 68 | $var Aas = [[$for j, [[A$j a$j]]]] 69 | $var ms = [[$for j, [[m$j]]]] 70 | $var matchers = [[$for j, [[const Matcher& m$j]]]] 71 | template 72 | class FunctionMocker : public 73 | internal::FunctionMockerBase { 74 | public: 75 | typedef R F($As); 76 | typedef typename internal::Function::ArgumentTuple ArgumentTuple; 77 | 78 | MockSpec& With($matchers) { 79 | 80 | $if i >= 1 [[ 81 | this->current_spec().SetMatchers(::std::tr1::make_tuple($ms)); 82 | 83 | ]] 84 | return this->current_spec(); 85 | } 86 | 87 | R Invoke($Aas) { 88 | // Even though gcc and MSVC don't enforce it, 'this->' is required 89 | // by the C++ standard [14.6.4] here, as the base class type is 90 | // dependent on the template argument (and thus shouldn't be 91 | // looked into when resolving InvokeWith). 92 | return this->InvokeWith(ArgumentTuple($as)); 93 | } 94 | }; 95 | 96 | 97 | ]] 98 | } // namespace internal 99 | 100 | // The style guide prohibits "using" statements in a namespace scope 101 | // inside a header file. However, the FunctionMocker class template 102 | // is meant to be defined in the ::testing namespace. The following 103 | // line is just a trick for working around a bug in MSVC 8.0, which 104 | // cannot handle it if we define FunctionMocker in ::testing. 105 | using internal::FunctionMocker; 106 | 107 | // GMOCK_RESULT_(tn, F) expands to the result type of function type F. 108 | // We define this as a variadic macro in case F contains unprotected 109 | // commas (the same reason that we use variadic macros in other places 110 | // in this file). 111 | // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! 112 | #define GMOCK_RESULT_(tn, ...) \ 113 | tn ::testing::internal::Function<__VA_ARGS__>::Result 114 | 115 | // The type of argument N of the given function type. 116 | // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! 117 | #define GMOCK_ARG_(tn, N, ...) \ 118 | tn ::testing::internal::Function<__VA_ARGS__>::Argument##N 119 | 120 | // The matcher type for argument N of the given function type. 121 | // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! 122 | #define GMOCK_MATCHER_(tn, N, ...) \ 123 | const ::testing::Matcher& 124 | 125 | // The variable for mocking the given method. 126 | // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! 127 | #define GMOCK_MOCKER_(arity, constness, Method) \ 128 | GTEST_CONCAT_TOKEN_(gmock##constness##arity##_##Method##_, __LINE__) 129 | 130 | 131 | $for i [[ 132 | $range j 1..i 133 | $var arg_as = [[$for j, \ 134 | [[GMOCK_ARG_(tn, $j, __VA_ARGS__) gmock_a$j]]]] 135 | $var as = [[$for j, [[gmock_a$j]]]] 136 | $var matcher_as = [[$for j, \ 137 | [[GMOCK_MATCHER_(tn, $j, __VA_ARGS__) gmock_a$j]]]] 138 | // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! 139 | #define GMOCK_METHOD$i[[]]_(tn, constness, ct, Method, ...) \ 140 | GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ 141 | $arg_as) constness { \ 142 | GTEST_COMPILE_ASSERT_((::std::tr1::tuple_size< \ 143 | tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value == $i), \ 144 | this_method_does_not_take_$i[[]]_argument[[$if i != 1 [[s]]]]); \ 145 | GMOCK_MOCKER_($i, constness, Method).SetOwnerAndName(this, #Method); \ 146 | return GMOCK_MOCKER_($i, constness, Method).Invoke($as); \ 147 | } \ 148 | ::testing::MockSpec<__VA_ARGS__>& \ 149 | gmock_##Method($matcher_as) constness { \ 150 | GMOCK_MOCKER_($i, constness, Method).RegisterOwner(this); \ 151 | return GMOCK_MOCKER_($i, constness, Method).With($as); \ 152 | } \ 153 | mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_($i, constness, Method) 154 | 155 | 156 | ]] 157 | $for i [[ 158 | #define MOCK_METHOD$i(m, ...) GMOCK_METHOD$i[[]]_(, , , m, __VA_ARGS__) 159 | 160 | ]] 161 | 162 | 163 | $for i [[ 164 | #define MOCK_CONST_METHOD$i(m, ...) GMOCK_METHOD$i[[]]_(, const, , m, __VA_ARGS__) 165 | 166 | ]] 167 | 168 | 169 | $for i [[ 170 | #define MOCK_METHOD$i[[]]_T(m, ...) GMOCK_METHOD$i[[]]_(typename, , , m, __VA_ARGS__) 171 | 172 | ]] 173 | 174 | 175 | $for i [[ 176 | #define MOCK_CONST_METHOD$i[[]]_T(m, ...) \ 177 | GMOCK_METHOD$i[[]]_(typename, const, , m, __VA_ARGS__) 178 | 179 | ]] 180 | 181 | 182 | $for i [[ 183 | #define MOCK_METHOD$i[[]]_WITH_CALLTYPE(ct, m, ...) \ 184 | GMOCK_METHOD$i[[]]_(, , ct, m, __VA_ARGS__) 185 | 186 | ]] 187 | 188 | 189 | $for i [[ 190 | #define MOCK_CONST_METHOD$i[[]]_WITH_CALLTYPE(ct, m, ...) \ 191 | GMOCK_METHOD$i[[]]_(, const, ct, m, __VA_ARGS__) 192 | 193 | ]] 194 | 195 | 196 | $for i [[ 197 | #define MOCK_METHOD$i[[]]_T_WITH_CALLTYPE(ct, m, ...) \ 198 | GMOCK_METHOD$i[[]]_(typename, , ct, m, __VA_ARGS__) 199 | 200 | ]] 201 | 202 | 203 | $for i [[ 204 | #define MOCK_CONST_METHOD$i[[]]_T_WITH_CALLTYPE(ct, m, ...) \ 205 | GMOCK_METHOD$i[[]]_(typename, const, ct, m, __VA_ARGS__) 206 | 207 | ]] 208 | 209 | // A MockFunction class has one mock method whose type is F. It is 210 | // useful when you just want your test code to emit some messages and 211 | // have Google Mock verify the right messages are sent (and perhaps at 212 | // the right times). For example, if you are exercising code: 213 | // 214 | // Foo(1); 215 | // Foo(2); 216 | // Foo(3); 217 | // 218 | // and want to verify that Foo(1) and Foo(3) both invoke 219 | // mock.Bar("a"), but Foo(2) doesn't invoke anything, you can write: 220 | // 221 | // TEST(FooTest, InvokesBarCorrectly) { 222 | // MyMock mock; 223 | // MockFunction check; 224 | // { 225 | // InSequence s; 226 | // 227 | // EXPECT_CALL(mock, Bar("a")); 228 | // EXPECT_CALL(check, Call("1")); 229 | // EXPECT_CALL(check, Call("2")); 230 | // EXPECT_CALL(mock, Bar("a")); 231 | // } 232 | // Foo(1); 233 | // check.Call("1"); 234 | // Foo(2); 235 | // check.Call("2"); 236 | // Foo(3); 237 | // } 238 | // 239 | // The expectation spec says that the first Bar("a") must happen 240 | // before check point "1", the second Bar("a") must happen after check 241 | // point "2", and nothing should happen between the two check 242 | // points. The explicit check points make it easy to tell which 243 | // Bar("a") is called by which call to Foo(). 244 | template 245 | class MockFunction; 246 | 247 | 248 | $for i [[ 249 | $range j 0..i-1 250 | template 251 | class MockFunction { 252 | public: 253 | MockFunction() {} 254 | 255 | MOCK_METHOD$i[[]]_T(Call, R($for j, [[A$j]])); 256 | 257 | private: 258 | GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); 259 | }; 260 | 261 | 262 | ]] 263 | } // namespace testing 264 | 265 | #endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_ 266 | -------------------------------------------------------------------------------- /test/gmock/include/gmock/gmock-generated-nice-strict.h.pump: -------------------------------------------------------------------------------- 1 | $$ -*- mode: c++; -*- 2 | $$ This is a Pump source file. Please use Pump to convert it to 3 | $$ gmock-generated-nice-strict.h. 4 | $$ 5 | $var n = 10 $$ The maximum arity we support. 6 | // Copyright 2008, Google Inc. 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are 11 | // met: 12 | // 13 | // * Redistributions of source code must retain the above copyright 14 | // notice, this list of conditions and the following disclaimer. 15 | // * Redistributions in binary form must reproduce the above 16 | // copyright notice, this list of conditions and the following disclaimer 17 | // in the documentation and/or other materials provided with the 18 | // distribution. 19 | // * Neither the name of Google Inc. nor the names of its 20 | // contributors may be used to endorse or promote products derived from 21 | // this software without specific prior written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 29 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | // 35 | // Author: wan@google.com (Zhanyong Wan) 36 | 37 | // Implements class templates NiceMock, NaggyMock, and StrictMock. 38 | // 39 | // Given a mock class MockFoo that is created using Google Mock, 40 | // NiceMock is a subclass of MockFoo that allows 41 | // uninteresting calls (i.e. calls to mock methods that have no 42 | // EXPECT_CALL specs), NaggyMock is a subclass of MockFoo 43 | // that prints a warning when an uninteresting call occurs, and 44 | // StrictMock is a subclass of MockFoo that treats all 45 | // uninteresting calls as errors. 46 | // 47 | // Currently a mock is naggy by default, so MockFoo and 48 | // NaggyMock behave like the same. However, we will soon 49 | // switch the default behavior of mocks to be nice, as that in general 50 | // leads to more maintainable tests. When that happens, MockFoo will 51 | // stop behaving like NaggyMock and start behaving like 52 | // NiceMock. 53 | // 54 | // NiceMock, NaggyMock, and StrictMock "inherit" the constructors of 55 | // their respective base class, with up-to $n arguments. Therefore 56 | // you can write NiceMock(5, "a") to construct a nice mock 57 | // where MockFoo has a constructor that accepts (int, const char*), 58 | // for example. 59 | // 60 | // A known limitation is that NiceMock, NaggyMock, 61 | // and StrictMock only works for mock methods defined using 62 | // the MOCK_METHOD* family of macros DIRECTLY in the MockFoo class. 63 | // If a mock method is defined in a base class of MockFoo, the "nice" 64 | // or "strict" modifier may not affect it, depending on the compiler. 65 | // In particular, nesting NiceMock, NaggyMock, and StrictMock is NOT 66 | // supported. 67 | // 68 | // Another known limitation is that the constructors of the base mock 69 | // cannot have arguments passed by non-const reference, which are 70 | // banned by the Google C++ style guide anyway. 71 | 72 | #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_ 73 | #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_ 74 | 75 | #include "gmock/gmock-spec-builders.h" 76 | #include "gmock/internal/gmock-port.h" 77 | 78 | namespace testing { 79 | 80 | $range kind 0..2 81 | $for kind [[ 82 | 83 | $var clazz=[[$if kind==0 [[NiceMock]] 84 | $elif kind==1 [[NaggyMock]] 85 | $else [[StrictMock]]]] 86 | 87 | $var method=[[$if kind==0 [[AllowUninterestingCalls]] 88 | $elif kind==1 [[WarnUninterestingCalls]] 89 | $else [[FailUninterestingCalls]]]] 90 | 91 | template 92 | class $clazz : public MockClass { 93 | public: 94 | // We don't factor out the constructor body to a common method, as 95 | // we have to avoid a possible clash with members of MockClass. 96 | $clazz() { 97 | ::testing::Mock::$method( 98 | internal::ImplicitCast_(this)); 99 | } 100 | 101 | // C++ doesn't (yet) allow inheritance of constructors, so we have 102 | // to define it for each arity. 103 | template 104 | explicit $clazz(const A1& a1) : MockClass(a1) { 105 | ::testing::Mock::$method( 106 | internal::ImplicitCast_(this)); 107 | } 108 | 109 | $range i 2..n 110 | $for i [[ 111 | $range j 1..i 112 | template <$for j, [[typename A$j]]> 113 | $clazz($for j, [[const A$j& a$j]]) : MockClass($for j, [[a$j]]) { 114 | ::testing::Mock::$method( 115 | internal::ImplicitCast_(this)); 116 | } 117 | 118 | 119 | ]] 120 | virtual ~$clazz() { 121 | ::testing::Mock::UnregisterCallReaction( 122 | internal::ImplicitCast_(this)); 123 | } 124 | 125 | private: 126 | GTEST_DISALLOW_COPY_AND_ASSIGN_($clazz); 127 | }; 128 | 129 | ]] 130 | 131 | // The following specializations catch some (relatively more common) 132 | // user errors of nesting nice and strict mocks. They do NOT catch 133 | // all possible errors. 134 | 135 | // These specializations are declared but not defined, as NiceMock, 136 | // NaggyMock, and StrictMock cannot be nested. 137 | 138 | template 139 | class NiceMock >; 140 | template 141 | class NiceMock >; 142 | template 143 | class NiceMock >; 144 | 145 | template 146 | class NaggyMock >; 147 | template 148 | class NaggyMock >; 149 | template 150 | class NaggyMock >; 151 | 152 | template 153 | class StrictMock >; 154 | template 155 | class StrictMock >; 156 | template 157 | class StrictMock >; 158 | 159 | } // namespace testing 160 | 161 | #endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_ 162 | -------------------------------------------------------------------------------- /test/gmock/include/gmock/gmock-more-actions.h: -------------------------------------------------------------------------------- 1 | // Copyright 2007, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: wan@google.com (Zhanyong Wan) 31 | 32 | // Google Mock - a framework for writing C++ mock classes. 33 | // 34 | // This file implements some actions that depend on gmock-generated-actions.h. 35 | 36 | #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_ 37 | #define GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_ 38 | 39 | #include 40 | 41 | #include "gmock/gmock-generated-actions.h" 42 | 43 | namespace testing { 44 | namespace internal { 45 | 46 | // Implements the Invoke(f) action. The template argument 47 | // FunctionImpl is the implementation type of f, which can be either a 48 | // function pointer or a functor. Invoke(f) can be used as an 49 | // Action as long as f's type is compatible with F (i.e. f can be 50 | // assigned to a tr1::function). 51 | template 52 | class InvokeAction { 53 | public: 54 | // The c'tor makes a copy of function_impl (either a function 55 | // pointer or a functor). 56 | explicit InvokeAction(FunctionImpl function_impl) 57 | : function_impl_(function_impl) {} 58 | 59 | template 60 | Result Perform(const ArgumentTuple& args) { 61 | return InvokeHelper::Invoke(function_impl_, args); 62 | } 63 | 64 | private: 65 | FunctionImpl function_impl_; 66 | 67 | GTEST_DISALLOW_ASSIGN_(InvokeAction); 68 | }; 69 | 70 | // Implements the Invoke(object_ptr, &Class::Method) action. 71 | template 72 | class InvokeMethodAction { 73 | public: 74 | InvokeMethodAction(Class* obj_ptr, MethodPtr method_ptr) 75 | : obj_ptr_(obj_ptr), method_ptr_(method_ptr) {} 76 | 77 | template 78 | Result Perform(const ArgumentTuple& args) const { 79 | return InvokeHelper::InvokeMethod( 80 | obj_ptr_, method_ptr_, args); 81 | } 82 | 83 | private: 84 | Class* const obj_ptr_; 85 | const MethodPtr method_ptr_; 86 | 87 | GTEST_DISALLOW_ASSIGN_(InvokeMethodAction); 88 | }; 89 | 90 | } // namespace internal 91 | 92 | // Various overloads for Invoke(). 93 | 94 | // Creates an action that invokes 'function_impl' with the mock 95 | // function's arguments. 96 | template 97 | PolymorphicAction > Invoke( 98 | FunctionImpl function_impl) { 99 | return MakePolymorphicAction( 100 | internal::InvokeAction(function_impl)); 101 | } 102 | 103 | // Creates an action that invokes the given method on the given object 104 | // with the mock function's arguments. 105 | template 106 | PolymorphicAction > Invoke( 107 | Class* obj_ptr, MethodPtr method_ptr) { 108 | return MakePolymorphicAction( 109 | internal::InvokeMethodAction(obj_ptr, method_ptr)); 110 | } 111 | 112 | // WithoutArgs(inner_action) can be used in a mock function with a 113 | // non-empty argument list to perform inner_action, which takes no 114 | // argument. In other words, it adapts an action accepting no 115 | // argument to one that accepts (and ignores) arguments. 116 | template 117 | inline internal::WithArgsAction 118 | WithoutArgs(const InnerAction& action) { 119 | return internal::WithArgsAction(action); 120 | } 121 | 122 | // WithArg(an_action) creates an action that passes the k-th 123 | // (0-based) argument of the mock function to an_action and performs 124 | // it. It adapts an action accepting one argument to one that accepts 125 | // multiple arguments. For convenience, we also provide 126 | // WithArgs(an_action) (defined below) as a synonym. 127 | template 128 | inline internal::WithArgsAction 129 | WithArg(const InnerAction& action) { 130 | return internal::WithArgsAction(action); 131 | } 132 | 133 | // The ACTION*() macros trigger warning C4100 (unreferenced formal 134 | // parameter) in MSVC with -W4. Unfortunately they cannot be fixed in 135 | // the macro definition, as the warnings are generated when the macro 136 | // is expanded and macro expansion cannot contain #pragma. Therefore 137 | // we suppress them here. 138 | #ifdef _MSC_VER 139 | # pragma warning(push) 140 | # pragma warning(disable:4100) 141 | #endif 142 | 143 | // Action ReturnArg() returns the k-th argument of the mock function. 144 | ACTION_TEMPLATE(ReturnArg, 145 | HAS_1_TEMPLATE_PARAMS(int, k), 146 | AND_0_VALUE_PARAMS()) { 147 | return std::tr1::get(args); 148 | } 149 | 150 | // Action SaveArg(pointer) saves the k-th (0-based) argument of the 151 | // mock function to *pointer. 152 | ACTION_TEMPLATE(SaveArg, 153 | HAS_1_TEMPLATE_PARAMS(int, k), 154 | AND_1_VALUE_PARAMS(pointer)) { 155 | *pointer = ::std::tr1::get(args); 156 | } 157 | 158 | // Action SaveArgPointee(pointer) saves the value pointed to 159 | // by the k-th (0-based) argument of the mock function to *pointer. 160 | ACTION_TEMPLATE(SaveArgPointee, 161 | HAS_1_TEMPLATE_PARAMS(int, k), 162 | AND_1_VALUE_PARAMS(pointer)) { 163 | *pointer = *::std::tr1::get(args); 164 | } 165 | 166 | // Action SetArgReferee(value) assigns 'value' to the variable 167 | // referenced by the k-th (0-based) argument of the mock function. 168 | ACTION_TEMPLATE(SetArgReferee, 169 | HAS_1_TEMPLATE_PARAMS(int, k), 170 | AND_1_VALUE_PARAMS(value)) { 171 | typedef typename ::std::tr1::tuple_element::type argk_type; 172 | // Ensures that argument #k is a reference. If you get a compiler 173 | // error on the next line, you are using SetArgReferee(value) in 174 | // a mock function whose k-th (0-based) argument is not a reference. 175 | GTEST_COMPILE_ASSERT_(internal::is_reference::value, 176 | SetArgReferee_must_be_used_with_a_reference_argument); 177 | ::std::tr1::get(args) = value; 178 | } 179 | 180 | // Action SetArrayArgument(first, last) copies the elements in 181 | // source range [first, last) to the array pointed to by the k-th 182 | // (0-based) argument, which can be either a pointer or an 183 | // iterator. The action does not take ownership of the elements in the 184 | // source range. 185 | ACTION_TEMPLATE(SetArrayArgument, 186 | HAS_1_TEMPLATE_PARAMS(int, k), 187 | AND_2_VALUE_PARAMS(first, last)) { 188 | // Microsoft compiler deprecates ::std::copy, so we want to suppress warning 189 | // 4996 (Function call with parameters that may be unsafe) there. 190 | #ifdef _MSC_VER 191 | # pragma warning(push) // Saves the current warning state. 192 | # pragma warning(disable:4996) // Temporarily disables warning 4996. 193 | #endif 194 | ::std::copy(first, last, ::std::tr1::get(args)); 195 | #ifdef _MSC_VER 196 | # pragma warning(pop) // Restores the warning state. 197 | #endif 198 | } 199 | 200 | // Action DeleteArg() deletes the k-th (0-based) argument of the mock 201 | // function. 202 | ACTION_TEMPLATE(DeleteArg, 203 | HAS_1_TEMPLATE_PARAMS(int, k), 204 | AND_0_VALUE_PARAMS()) { 205 | delete ::std::tr1::get(args); 206 | } 207 | 208 | // This action returns the value pointed to by 'pointer'. 209 | ACTION_P(ReturnPointee, pointer) { return *pointer; } 210 | 211 | // Action Throw(exception) can be used in a mock function of any type 212 | // to throw the given exception. Any copyable value can be thrown. 213 | #if GTEST_HAS_EXCEPTIONS 214 | 215 | // Suppresses the 'unreachable code' warning that VC generates in opt modes. 216 | # ifdef _MSC_VER 217 | # pragma warning(push) // Saves the current warning state. 218 | # pragma warning(disable:4702) // Temporarily disables warning 4702. 219 | # endif 220 | ACTION_P(Throw, exception) { throw exception; } 221 | # ifdef _MSC_VER 222 | # pragma warning(pop) // Restores the warning state. 223 | # endif 224 | 225 | #endif // GTEST_HAS_EXCEPTIONS 226 | 227 | #ifdef _MSC_VER 228 | # pragma warning(pop) 229 | #endif 230 | 231 | } // namespace testing 232 | 233 | #endif // GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_ 234 | -------------------------------------------------------------------------------- /test/gmock/include/gmock/gmock-more-matchers.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: marcus.boerger@google.com (Marcus Boerger) 31 | 32 | // Google Mock - a framework for writing C++ mock classes. 33 | // 34 | // This file implements some matchers that depend on gmock-generated-matchers.h. 35 | // 36 | // Note that tests are implemented in gmock-matchers_test.cc rather than 37 | // gmock-more-matchers-test.cc. 38 | 39 | #ifndef GMOCK_GMOCK_MORE_MATCHERS_H_ 40 | #define GMOCK_GMOCK_MORE_MATCHERS_H_ 41 | 42 | #include "gmock/gmock-generated-matchers.h" 43 | 44 | namespace testing { 45 | 46 | // Defines a matcher that matches an empty container. The container must 47 | // support both size() and empty(), which all STL-like containers provide. 48 | MATCHER(IsEmpty, negation ? "isn't empty" : "is empty") { 49 | if (arg.empty()) { 50 | return true; 51 | } 52 | *result_listener << "whose size is " << arg.size(); 53 | return false; 54 | } 55 | 56 | } // namespace testing 57 | 58 | #endif // GMOCK_GMOCK_MORE_MATCHERS_H_ 59 | -------------------------------------------------------------------------------- /test/gmock/include/gmock/gmock.h: -------------------------------------------------------------------------------- 1 | // Copyright 2007, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: wan@google.com (Zhanyong Wan) 31 | 32 | // Google Mock - a framework for writing C++ mock classes. 33 | // 34 | // This is the main header file a user should include. 35 | 36 | #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_H_ 37 | #define GMOCK_INCLUDE_GMOCK_GMOCK_H_ 38 | 39 | // This file implements the following syntax: 40 | // 41 | // ON_CALL(mock_object.Method(...)) 42 | // .With(...) ? 43 | // .WillByDefault(...); 44 | // 45 | // where With() is optional and WillByDefault() must appear exactly 46 | // once. 47 | // 48 | // EXPECT_CALL(mock_object.Method(...)) 49 | // .With(...) ? 50 | // .Times(...) ? 51 | // .InSequence(...) * 52 | // .WillOnce(...) * 53 | // .WillRepeatedly(...) ? 54 | // .RetiresOnSaturation() ? ; 55 | // 56 | // where all clauses are optional and WillOnce() can be repeated. 57 | 58 | #include "gmock/gmock-actions.h" 59 | #include "gmock/gmock-cardinalities.h" 60 | #include "gmock/gmock-generated-actions.h" 61 | #include "gmock/gmock-generated-function-mockers.h" 62 | #include "gmock/gmock-generated-nice-strict.h" 63 | #include "gmock/gmock-generated-matchers.h" 64 | #include "gmock/gmock-matchers.h" 65 | #include "gmock/gmock-more-actions.h" 66 | #include "gmock/gmock-more-matchers.h" 67 | #include "gmock/internal/gmock-internal-utils.h" 68 | 69 | namespace testing { 70 | 71 | // Declares Google Mock flags that we want a user to use programmatically. 72 | GMOCK_DECLARE_bool_(catch_leaked_mocks); 73 | GMOCK_DECLARE_string_(verbose); 74 | 75 | // Initializes Google Mock. This must be called before running the 76 | // tests. In particular, it parses the command line for the flags 77 | // that Google Mock recognizes. Whenever a Google Mock flag is seen, 78 | // it is removed from argv, and *argc is decremented. 79 | // 80 | // No value is returned. Instead, the Google Mock flag variables are 81 | // updated. 82 | // 83 | // Since Google Test is needed for Google Mock to work, this function 84 | // also initializes Google Test and parses its flags, if that hasn't 85 | // been done. 86 | GTEST_API_ void InitGoogleMock(int* argc, char** argv); 87 | 88 | // This overloaded version can be used in Windows programs compiled in 89 | // UNICODE mode. 90 | GTEST_API_ void InitGoogleMock(int* argc, wchar_t** argv); 91 | 92 | } // namespace testing 93 | 94 | #endif // GMOCK_INCLUDE_GMOCK_GMOCK_H_ 95 | -------------------------------------------------------------------------------- /test/gmock/include/gmock/internal/gmock-generated-internal-utils.h.pump: -------------------------------------------------------------------------------- 1 | $$ -*- mode: c++; -*- 2 | $$ This is a Pump source file. Please use Pump to convert it to 3 | $$ gmock-generated-function-mockers.h. 4 | $$ 5 | $var n = 10 $$ The maximum arity we support. 6 | // Copyright 2007, Google Inc. 7 | // All rights reserved. 8 | // 9 | // Redistribution and use in source and binary forms, with or without 10 | // modification, are permitted provided that the following conditions are 11 | // met: 12 | // 13 | // * Redistributions of source code must retain the above copyright 14 | // notice, this list of conditions and the following disclaimer. 15 | // * Redistributions in binary form must reproduce the above 16 | // copyright notice, this list of conditions and the following disclaimer 17 | // in the documentation and/or other materials provided with the 18 | // distribution. 19 | // * Neither the name of Google Inc. nor the names of its 20 | // contributors may be used to endorse or promote products derived from 21 | // this software without specific prior written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 29 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | // 35 | // Author: wan@google.com (Zhanyong Wan) 36 | 37 | // Google Mock - a framework for writing C++ mock classes. 38 | // 39 | // This file contains template meta-programming utility classes needed 40 | // for implementing Google Mock. 41 | 42 | #ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_GENERATED_INTERNAL_UTILS_H_ 43 | #define GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_GENERATED_INTERNAL_UTILS_H_ 44 | 45 | #include "gmock/internal/gmock-port.h" 46 | 47 | namespace testing { 48 | 49 | template 50 | class Matcher; 51 | 52 | namespace internal { 53 | 54 | // An IgnoredValue object can be implicitly constructed from ANY value. 55 | // This is used in implementing the IgnoreResult(a) action. 56 | class IgnoredValue { 57 | public: 58 | // This constructor template allows any value to be implicitly 59 | // converted to IgnoredValue. The object has no data member and 60 | // doesn't try to remember anything about the argument. We 61 | // deliberately omit the 'explicit' keyword in order to allow the 62 | // conversion to be implicit. 63 | template 64 | IgnoredValue(const T& /* ignored */) {} // NOLINT(runtime/explicit) 65 | }; 66 | 67 | // MatcherTuple::type is a tuple type where each field is a Matcher 68 | // for the corresponding field in tuple type T. 69 | template 70 | struct MatcherTuple; 71 | 72 | 73 | $range i 0..n 74 | $for i [[ 75 | $range j 1..i 76 | $var typename_As = [[$for j, [[typename A$j]]]] 77 | $var As = [[$for j, [[A$j]]]] 78 | $var matcher_As = [[$for j, [[Matcher]]]] 79 | template <$typename_As> 80 | struct MatcherTuple< ::std::tr1::tuple<$As> > { 81 | typedef ::std::tr1::tuple<$matcher_As > type; 82 | }; 83 | 84 | 85 | ]] 86 | // Template struct Function, where F must be a function type, contains 87 | // the following typedefs: 88 | // 89 | // Result: the function's return type. 90 | // ArgumentN: the type of the N-th argument, where N starts with 1. 91 | // ArgumentTuple: the tuple type consisting of all parameters of F. 92 | // ArgumentMatcherTuple: the tuple type consisting of Matchers for all 93 | // parameters of F. 94 | // MakeResultVoid: the function type obtained by substituting void 95 | // for the return type of F. 96 | // MakeResultIgnoredValue: 97 | // the function type obtained by substituting Something 98 | // for the return type of F. 99 | template 100 | struct Function; 101 | 102 | template 103 | struct Function { 104 | typedef R Result; 105 | typedef ::std::tr1::tuple<> ArgumentTuple; 106 | typedef typename MatcherTuple::type ArgumentMatcherTuple; 107 | typedef void MakeResultVoid(); 108 | typedef IgnoredValue MakeResultIgnoredValue(); 109 | }; 110 | 111 | 112 | $range i 1..n 113 | $for i [[ 114 | $range j 1..i 115 | $var typename_As = [[$for j [[, typename A$j]]]] 116 | $var As = [[$for j, [[A$j]]]] 117 | $var matcher_As = [[$for j, [[Matcher]]]] 118 | $range k 1..i-1 119 | $var prev_As = [[$for k, [[A$k]]]] 120 | template 121 | struct Function 122 | : Function { 123 | typedef A$i Argument$i; 124 | typedef ::std::tr1::tuple<$As> ArgumentTuple; 125 | typedef typename MatcherTuple::type ArgumentMatcherTuple; 126 | typedef void MakeResultVoid($As); 127 | typedef IgnoredValue MakeResultIgnoredValue($As); 128 | }; 129 | 130 | 131 | ]] 132 | } // namespace internal 133 | 134 | } // namespace testing 135 | 136 | #endif // GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_GENERATED_INTERNAL_UTILS_H_ 137 | -------------------------------------------------------------------------------- /test/gmock/include/gmock/internal/gmock-port.h: -------------------------------------------------------------------------------- 1 | // Copyright 2008, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: vadimb@google.com (Vadim Berman) 31 | // 32 | // Low-level types and utilities for porting Google Mock to various 33 | // platforms. They are subject to change without notice. DO NOT USE 34 | // THEM IN USER CODE. 35 | 36 | #ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_ 37 | #define GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_ 38 | 39 | #include 40 | #include 41 | #include 42 | 43 | // Most of the types needed for porting Google Mock are also required 44 | // for Google Test and are defined in gtest-port.h. 45 | #include "gtest/internal/gtest-linked_ptr.h" 46 | #include "gtest/internal/gtest-port.h" 47 | 48 | // To avoid conditional compilation everywhere, we make it 49 | // gmock-port.h's responsibility to #include the header implementing 50 | // tr1/tuple. gmock-port.h does this via gtest-port.h, which is 51 | // guaranteed to pull in the tuple header. 52 | 53 | // For MS Visual C++, check the compiler version. At least VS 2003 is 54 | // required to compile Google Mock. 55 | #if defined(_MSC_VER) && _MSC_VER < 1310 56 | # error "At least Visual C++ 2003 (7.1) is required to compile Google Mock." 57 | #endif 58 | 59 | // Macro for referencing flags. This is public as we want the user to 60 | // use this syntax to reference Google Mock flags. 61 | #define GMOCK_FLAG(name) FLAGS_gmock_##name 62 | 63 | // Macros for declaring flags. 64 | #define GMOCK_DECLARE_bool_(name) extern GTEST_API_ bool GMOCK_FLAG(name) 65 | #define GMOCK_DECLARE_int32_(name) \ 66 | extern GTEST_API_ ::testing::internal::Int32 GMOCK_FLAG(name) 67 | #define GMOCK_DECLARE_string_(name) \ 68 | extern GTEST_API_ ::std::string GMOCK_FLAG(name) 69 | 70 | // Macros for defining flags. 71 | #define GMOCK_DEFINE_bool_(name, default_val, doc) \ 72 | GTEST_API_ bool GMOCK_FLAG(name) = (default_val) 73 | #define GMOCK_DEFINE_int32_(name, default_val, doc) \ 74 | GTEST_API_ ::testing::internal::Int32 GMOCK_FLAG(name) = (default_val) 75 | #define GMOCK_DEFINE_string_(name, default_val, doc) \ 76 | GTEST_API_ ::std::string GMOCK_FLAG(name) = (default_val) 77 | 78 | #endif // GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_ 79 | -------------------------------------------------------------------------------- /test/gmock/src/gmock-all.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2008, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: wan@google.com (Zhanyong Wan) 31 | // 32 | // Google C++ Mocking Framework (Google Mock) 33 | // 34 | // This file #includes all Google Mock implementation .cc files. The 35 | // purpose is to allow a user to build Google Mock by compiling this 36 | // file alone. 37 | 38 | // This line ensures that gmock.h can be compiled on its own, even 39 | // when it's fused. 40 | #include "gmock/gmock.h" 41 | 42 | // The following lines pull in the real gmock *.cc files. 43 | #include "src/gmock-cardinalities.cc" 44 | #include "src/gmock-internal-utils.cc" 45 | #include "src/gmock-matchers.cc" 46 | #include "src/gmock-spec-builders.cc" 47 | #include "src/gmock.cc" 48 | -------------------------------------------------------------------------------- /test/gmock/src/gmock-cardinalities.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2007, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: wan@google.com (Zhanyong Wan) 31 | 32 | // Google Mock - a framework for writing C++ mock classes. 33 | // 34 | // This file implements cardinalities. 35 | 36 | #include "gmock/gmock-cardinalities.h" 37 | 38 | #include 39 | #include // NOLINT 40 | #include 41 | #include 42 | #include "gmock/internal/gmock-internal-utils.h" 43 | #include "gtest/gtest.h" 44 | 45 | namespace testing { 46 | 47 | namespace { 48 | 49 | // Implements the Between(m, n) cardinality. 50 | class BetweenCardinalityImpl : public CardinalityInterface { 51 | public: 52 | BetweenCardinalityImpl(int min, int max) 53 | : min_(min >= 0 ? min : 0), 54 | max_(max >= min_ ? max : min_) { 55 | std::stringstream ss; 56 | if (min < 0) { 57 | ss << "The invocation lower bound must be >= 0, " 58 | << "but is actually " << min << "."; 59 | internal::Expect(false, __FILE__, __LINE__, ss.str()); 60 | } else if (max < 0) { 61 | ss << "The invocation upper bound must be >= 0, " 62 | << "but is actually " << max << "."; 63 | internal::Expect(false, __FILE__, __LINE__, ss.str()); 64 | } else if (min > max) { 65 | ss << "The invocation upper bound (" << max 66 | << ") must be >= the invocation lower bound (" << min 67 | << ")."; 68 | internal::Expect(false, __FILE__, __LINE__, ss.str()); 69 | } 70 | } 71 | 72 | // Conservative estimate on the lower/upper bound of the number of 73 | // calls allowed. 74 | virtual int ConservativeLowerBound() const { return min_; } 75 | virtual int ConservativeUpperBound() const { return max_; } 76 | 77 | virtual bool IsSatisfiedByCallCount(int call_count) const { 78 | return min_ <= call_count && call_count <= max_; 79 | } 80 | 81 | virtual bool IsSaturatedByCallCount(int call_count) const { 82 | return call_count >= max_; 83 | } 84 | 85 | virtual void DescribeTo(::std::ostream* os) const; 86 | 87 | private: 88 | const int min_; 89 | const int max_; 90 | 91 | GTEST_DISALLOW_COPY_AND_ASSIGN_(BetweenCardinalityImpl); 92 | }; 93 | 94 | // Formats "n times" in a human-friendly way. 95 | inline internal::string FormatTimes(int n) { 96 | if (n == 1) { 97 | return "once"; 98 | } else if (n == 2) { 99 | return "twice"; 100 | } else { 101 | std::stringstream ss; 102 | ss << n << " times"; 103 | return ss.str(); 104 | } 105 | } 106 | 107 | // Describes the Between(m, n) cardinality in human-friendly text. 108 | void BetweenCardinalityImpl::DescribeTo(::std::ostream* os) const { 109 | if (min_ == 0) { 110 | if (max_ == 0) { 111 | *os << "never called"; 112 | } else if (max_ == INT_MAX) { 113 | *os << "called any number of times"; 114 | } else { 115 | *os << "called at most " << FormatTimes(max_); 116 | } 117 | } else if (min_ == max_) { 118 | *os << "called " << FormatTimes(min_); 119 | } else if (max_ == INT_MAX) { 120 | *os << "called at least " << FormatTimes(min_); 121 | } else { 122 | // 0 < min_ < max_ < INT_MAX 123 | *os << "called between " << min_ << " and " << max_ << " times"; 124 | } 125 | } 126 | 127 | } // Unnamed namespace 128 | 129 | // Describes the given call count to an ostream. 130 | void Cardinality::DescribeActualCallCountTo(int actual_call_count, 131 | ::std::ostream* os) { 132 | if (actual_call_count > 0) { 133 | *os << "called " << FormatTimes(actual_call_count); 134 | } else { 135 | *os << "never called"; 136 | } 137 | } 138 | 139 | // Creates a cardinality that allows at least n calls. 140 | GTEST_API_ Cardinality AtLeast(int n) { return Between(n, INT_MAX); } 141 | 142 | // Creates a cardinality that allows at most n calls. 143 | GTEST_API_ Cardinality AtMost(int n) { return Between(0, n); } 144 | 145 | // Creates a cardinality that allows any number of calls. 146 | GTEST_API_ Cardinality AnyNumber() { return AtLeast(0); } 147 | 148 | // Creates a cardinality that allows between min and max calls. 149 | GTEST_API_ Cardinality Between(int min, int max) { 150 | return Cardinality(new BetweenCardinalityImpl(min, max)); 151 | } 152 | 153 | // Creates a cardinality that allows exactly n calls. 154 | GTEST_API_ Cardinality Exactly(int n) { return Between(n, n); } 155 | 156 | } // namespace testing 157 | -------------------------------------------------------------------------------- /test/gmock/src/gmock-internal-utils.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2007, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: wan@google.com (Zhanyong Wan) 31 | 32 | // Google Mock - a framework for writing C++ mock classes. 33 | // 34 | // This file defines some utilities useful for implementing Google 35 | // Mock. They are subject to change without notice, so please DO NOT 36 | // USE THEM IN USER CODE. 37 | 38 | #include "gmock/internal/gmock-internal-utils.h" 39 | 40 | #include 41 | #include // NOLINT 42 | #include 43 | #include "gmock/gmock.h" 44 | #include "gmock/internal/gmock-port.h" 45 | #include "gtest/gtest.h" 46 | 47 | namespace testing { 48 | namespace internal { 49 | 50 | // Converts an identifier name to a space-separated list of lower-case 51 | // words. Each maximum substring of the form [A-Za-z][a-z]*|\d+ is 52 | // treated as one word. For example, both "FooBar123" and 53 | // "foo_bar_123" are converted to "foo bar 123". 54 | GTEST_API_ string ConvertIdentifierNameToWords(const char* id_name) { 55 | string result; 56 | char prev_char = '\0'; 57 | for (const char* p = id_name; *p != '\0'; prev_char = *(p++)) { 58 | // We don't care about the current locale as the input is 59 | // guaranteed to be a valid C++ identifier name. 60 | const bool starts_new_word = IsUpper(*p) || 61 | (!IsAlpha(prev_char) && IsLower(*p)) || 62 | (!IsDigit(prev_char) && IsDigit(*p)); 63 | 64 | if (IsAlNum(*p)) { 65 | if (starts_new_word && result != "") 66 | result += ' '; 67 | result += ToLower(*p); 68 | } 69 | } 70 | return result; 71 | } 72 | 73 | // This class reports Google Mock failures as Google Test failures. A 74 | // user can define another class in a similar fashion if he intends to 75 | // use Google Mock with a testing framework other than Google Test. 76 | class GoogleTestFailureReporter : public FailureReporterInterface { 77 | public: 78 | virtual void ReportFailure(FailureType type, const char* file, int line, 79 | const string& message) { 80 | AssertHelper(type == kFatal ? 81 | TestPartResult::kFatalFailure : 82 | TestPartResult::kNonFatalFailure, 83 | file, 84 | line, 85 | message.c_str()) = Message(); 86 | if (type == kFatal) { 87 | posix::Abort(); 88 | } 89 | } 90 | }; 91 | 92 | // Returns the global failure reporter. Will create a 93 | // GoogleTestFailureReporter and return it the first time called. 94 | GTEST_API_ FailureReporterInterface* GetFailureReporter() { 95 | // Points to the global failure reporter used by Google Mock. gcc 96 | // guarantees that the following use of failure_reporter is 97 | // thread-safe. We may need to add additional synchronization to 98 | // protect failure_reporter if we port Google Mock to other 99 | // compilers. 100 | static FailureReporterInterface* const failure_reporter = 101 | new GoogleTestFailureReporter(); 102 | return failure_reporter; 103 | } 104 | 105 | // Protects global resources (stdout in particular) used by Log(). 106 | static GTEST_DEFINE_STATIC_MUTEX_(g_log_mutex); 107 | 108 | // Returns true iff a log with the given severity is visible according 109 | // to the --gmock_verbose flag. 110 | GTEST_API_ bool LogIsVisible(LogSeverity severity) { 111 | if (GMOCK_FLAG(verbose) == kInfoVerbosity) { 112 | // Always show the log if --gmock_verbose=info. 113 | return true; 114 | } else if (GMOCK_FLAG(verbose) == kErrorVerbosity) { 115 | // Always hide it if --gmock_verbose=error. 116 | return false; 117 | } else { 118 | // If --gmock_verbose is neither "info" nor "error", we treat it 119 | // as "warning" (its default value). 120 | return severity == kWarning; 121 | } 122 | } 123 | 124 | // Prints the given message to stdout iff 'severity' >= the level 125 | // specified by the --gmock_verbose flag. If stack_frames_to_skip >= 126 | // 0, also prints the stack trace excluding the top 127 | // stack_frames_to_skip frames. In opt mode, any positive 128 | // stack_frames_to_skip is treated as 0, since we don't know which 129 | // function calls will be inlined by the compiler and need to be 130 | // conservative. 131 | GTEST_API_ void Log(LogSeverity severity, 132 | const string& message, 133 | int stack_frames_to_skip) { 134 | if (!LogIsVisible(severity)) 135 | return; 136 | 137 | // Ensures that logs from different threads don't interleave. 138 | MutexLock l(&g_log_mutex); 139 | 140 | // "using ::std::cout;" doesn't work with Symbian's STLport, where cout is a 141 | // macro. 142 | 143 | if (severity == kWarning) { 144 | // Prints a GMOCK WARNING marker to make the warnings easily searchable. 145 | std::cout << "\nGMOCK WARNING:"; 146 | } 147 | // Pre-pends a new-line to message if it doesn't start with one. 148 | if (message.empty() || message[0] != '\n') { 149 | std::cout << "\n"; 150 | } 151 | std::cout << message; 152 | if (stack_frames_to_skip >= 0) { 153 | #ifdef NDEBUG 154 | // In opt mode, we have to be conservative and skip no stack frame. 155 | const int actual_to_skip = 0; 156 | #else 157 | // In dbg mode, we can do what the caller tell us to do (plus one 158 | // for skipping this function's stack frame). 159 | const int actual_to_skip = stack_frames_to_skip + 1; 160 | #endif // NDEBUG 161 | 162 | // Appends a new-line to message if it doesn't end with one. 163 | if (!message.empty() && *message.rbegin() != '\n') { 164 | std::cout << "\n"; 165 | } 166 | std::cout << "Stack trace:\n" 167 | << ::testing::internal::GetCurrentOsStackTraceExceptTop( 168 | ::testing::UnitTest::GetInstance(), actual_to_skip); 169 | } 170 | std::cout << ::std::flush; 171 | } 172 | 173 | } // namespace internal 174 | } // namespace testing 175 | -------------------------------------------------------------------------------- /test/gmock/src/gmock.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2008, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: wan@google.com (Zhanyong Wan) 31 | 32 | #include "gmock/gmock.h" 33 | #include "gmock/internal/gmock-port.h" 34 | 35 | namespace testing { 36 | 37 | // TODO(wan@google.com): support using environment variables to 38 | // control the flag values, like what Google Test does. 39 | 40 | GMOCK_DEFINE_bool_(catch_leaked_mocks, true, 41 | "true iff Google Mock should report leaked mock objects " 42 | "as failures."); 43 | 44 | GMOCK_DEFINE_string_(verbose, internal::kWarningVerbosity, 45 | "Controls how verbose Google Mock's output is." 46 | " Valid values:\n" 47 | " info - prints all messages.\n" 48 | " warning - prints warnings and errors.\n" 49 | " error - prints errors only."); 50 | 51 | namespace internal { 52 | 53 | // Parses a string as a command line flag. The string should have the 54 | // format "--gmock_flag=value". When def_optional is true, the 55 | // "=value" part can be omitted. 56 | // 57 | // Returns the value of the flag, or NULL if the parsing failed. 58 | static const char* ParseGoogleMockFlagValue(const char* str, 59 | const char* flag, 60 | bool def_optional) { 61 | // str and flag must not be NULL. 62 | if (str == NULL || flag == NULL) return NULL; 63 | 64 | // The flag must start with "--gmock_". 65 | const std::string flag_str = std::string("--gmock_") + flag; 66 | const size_t flag_len = flag_str.length(); 67 | if (strncmp(str, flag_str.c_str(), flag_len) != 0) return NULL; 68 | 69 | // Skips the flag name. 70 | const char* flag_end = str + flag_len; 71 | 72 | // When def_optional is true, it's OK to not have a "=value" part. 73 | if (def_optional && (flag_end[0] == '\0')) { 74 | return flag_end; 75 | } 76 | 77 | // If def_optional is true and there are more characters after the 78 | // flag name, or if def_optional is false, there must be a '=' after 79 | // the flag name. 80 | if (flag_end[0] != '=') return NULL; 81 | 82 | // Returns the string after "=". 83 | return flag_end + 1; 84 | } 85 | 86 | // Parses a string for a Google Mock bool flag, in the form of 87 | // "--gmock_flag=value". 88 | // 89 | // On success, stores the value of the flag in *value, and returns 90 | // true. On failure, returns false without changing *value. 91 | static bool ParseGoogleMockBoolFlag(const char* str, const char* flag, 92 | bool* value) { 93 | // Gets the value of the flag as a string. 94 | const char* const value_str = ParseGoogleMockFlagValue(str, flag, true); 95 | 96 | // Aborts if the parsing failed. 97 | if (value_str == NULL) return false; 98 | 99 | // Converts the string value to a bool. 100 | *value = !(*value_str == '0' || *value_str == 'f' || *value_str == 'F'); 101 | return true; 102 | } 103 | 104 | // Parses a string for a Google Mock string flag, in the form of 105 | // "--gmock_flag=value". 106 | // 107 | // On success, stores the value of the flag in *value, and returns 108 | // true. On failure, returns false without changing *value. 109 | static bool ParseGoogleMockStringFlag(const char* str, const char* flag, 110 | std::string* value) { 111 | // Gets the value of the flag as a string. 112 | const char* const value_str = ParseGoogleMockFlagValue(str, flag, false); 113 | 114 | // Aborts if the parsing failed. 115 | if (value_str == NULL) return false; 116 | 117 | // Sets *value to the value of the flag. 118 | *value = value_str; 119 | return true; 120 | } 121 | 122 | // The internal implementation of InitGoogleMock(). 123 | // 124 | // The type parameter CharType can be instantiated to either char or 125 | // wchar_t. 126 | template 127 | void InitGoogleMockImpl(int* argc, CharType** argv) { 128 | // Makes sure Google Test is initialized. InitGoogleTest() is 129 | // idempotent, so it's fine if the user has already called it. 130 | InitGoogleTest(argc, argv); 131 | if (*argc <= 0) return; 132 | 133 | for (int i = 1; i != *argc; i++) { 134 | const std::string arg_string = StreamableToString(argv[i]); 135 | const char* const arg = arg_string.c_str(); 136 | 137 | // Do we see a Google Mock flag? 138 | if (ParseGoogleMockBoolFlag(arg, "catch_leaked_mocks", 139 | &GMOCK_FLAG(catch_leaked_mocks)) || 140 | ParseGoogleMockStringFlag(arg, "verbose", &GMOCK_FLAG(verbose))) { 141 | // Yes. Shift the remainder of the argv list left by one. Note 142 | // that argv has (*argc + 1) elements, the last one always being 143 | // NULL. The following loop moves the trailing NULL element as 144 | // well. 145 | for (int j = i; j != *argc; j++) { 146 | argv[j] = argv[j + 1]; 147 | } 148 | 149 | // Decrements the argument count. 150 | (*argc)--; 151 | 152 | // We also need to decrement the iterator as we just removed 153 | // an element. 154 | i--; 155 | } 156 | } 157 | } 158 | 159 | } // namespace internal 160 | 161 | // Initializes Google Mock. This must be called before running the 162 | // tests. In particular, it parses a command line for the flags that 163 | // Google Mock recognizes. Whenever a Google Mock flag is seen, it is 164 | // removed from argv, and *argc is decremented. 165 | // 166 | // No value is returned. Instead, the Google Mock flag variables are 167 | // updated. 168 | // 169 | // Since Google Test is needed for Google Mock to work, this function 170 | // also initializes Google Test and parses its flags, if that hasn't 171 | // been done. 172 | GTEST_API_ void InitGoogleMock(int* argc, char** argv) { 173 | internal::InitGoogleMockImpl(argc, argv); 174 | } 175 | 176 | // This overloaded version can be used in Windows programs compiled in 177 | // UNICODE mode. 178 | GTEST_API_ void InitGoogleMock(int* argc, wchar_t** argv) { 179 | internal::InitGoogleMockImpl(argc, argv); 180 | } 181 | 182 | } // namespace testing 183 | -------------------------------------------------------------------------------- /test/gmock/src/gmock_main.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2008, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: wan@google.com (Zhanyong Wan) 31 | 32 | #include 33 | #include "gmock/gmock.h" 34 | #include "gtest/gtest.h" 35 | 36 | // MS C++ compiler/linker has a bug on Windows (not on Windows CE), which 37 | // causes a link error when _tmain is defined in a static library and UNICODE 38 | // is enabled. For this reason instead of _tmain, main function is used on 39 | // Windows. See the following link to track the current status of this bug: 40 | // http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=394464 // NOLINT 41 | #if GTEST_OS_WINDOWS_MOBILE 42 | # include // NOLINT 43 | 44 | GTEST_API_ int _tmain(int argc, TCHAR** argv) { 45 | #else 46 | GTEST_API_ int main(int argc, char** argv) { 47 | #endif // GTEST_OS_WINDOWS_MOBILE 48 | std::cout << "Running main() from gmock_main.cc\n"; 49 | // Since Google Mock depends on Google Test, InitGoogleMock() is 50 | // also responsible for initializing Google Test. Therefore there's 51 | // no need for calling testing::InitGoogleTest() separately. 52 | testing::InitGoogleMock(&argc, argv); 53 | return RUN_ALL_TESTS(); 54 | } 55 | -------------------------------------------------------------------------------- /test/gtest/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ######################################################################## 2 | # CMake build script for Google Test. 3 | # 4 | # To run the tests for Google Test itself on Linux, use 'make test' or 5 | # ctest. You can select which tests to run using 'ctest -R regex'. 6 | # For more options, run 'ctest --help'. 7 | 8 | # BUILD_SHARED_LIBS is a standard CMake variable, but we declare it here to 9 | # make it prominent in the GUI. 10 | option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)." OFF) 11 | 12 | # When other libraries are using a shared version of runtime libraries, 13 | # Google Test also has to use one. 14 | option( 15 | gtest_force_shared_crt 16 | "Use shared (DLL) run-time lib even when Google Test is built as static lib." 17 | OFF) 18 | 19 | option(gtest_disable_pthreads "Disable uses of pthreads in gtest." OFF) 20 | 21 | # Defines pre_project_set_up_hermetic_build() and set_up_hermetic_build(). 22 | include(cmake/hermetic_build.cmake OPTIONAL) 23 | 24 | if (COMMAND pre_project_set_up_hermetic_build) 25 | pre_project_set_up_hermetic_build() 26 | endif() 27 | 28 | ######################################################################## 29 | # 30 | # Project-wide settings 31 | 32 | # Name of the project. 33 | # 34 | # CMake files in this project can refer to the root source directory 35 | # as ${gtest_SOURCE_DIR} and to the root binary directory as 36 | # ${gtest_BINARY_DIR}. 37 | # Language "C" is required for find_package(Threads). 38 | project(gtest CXX C) 39 | cmake_minimum_required(VERSION 2.6.2) 40 | 41 | if (COMMAND set_up_hermetic_build) 42 | set_up_hermetic_build() 43 | endif() 44 | 45 | # Define helper functions and macros used by Google Test. 46 | include(cmake/internal_utils.cmake) 47 | 48 | config_compiler_and_linker() # Defined in internal_utils.cmake. 49 | 50 | # Where Google Test's .h files can be found. 51 | include_directories( 52 | ${gtest_SOURCE_DIR}/include 53 | ${gtest_SOURCE_DIR}) 54 | 55 | # Where Google Test's libraries can be found. 56 | link_directories(${gtest_BINARY_DIR}/src) 57 | 58 | ######################################################################## 59 | # 60 | # Defines the gtest & gtest_main libraries. User tests should link 61 | # with one of them. 62 | 63 | # Google Test libraries. We build them using more strict warnings than what 64 | # are used for other targets, to ensure that gtest can be compiled by a user 65 | # aggressive about warnings. 66 | cxx_library(gtest "${cxx_strict}" src/gtest-all.cc) 67 | cxx_library(gtest_main "${cxx_strict}" src/gtest_main.cc) 68 | target_link_libraries(gtest_main gtest) 69 | 70 | -------------------------------------------------------------------------------- /test/gtest/cmake/internal_utils.cmake: -------------------------------------------------------------------------------- 1 | # Defines functions and macros useful for building Google Test and 2 | # Google Mock. 3 | # 4 | # Note: 5 | # 6 | # - This file will be run twice when building Google Mock (once via 7 | # Google Test's CMakeLists.txt, and once via Google Mock's). 8 | # Therefore it shouldn't have any side effects other than defining 9 | # the functions and macros. 10 | # 11 | # - The functions/macros defined in this file may depend on Google 12 | # Test and Google Mock's option() definitions, and thus must be 13 | # called *after* the options have been defined. 14 | 15 | # Tweaks CMake's default compiler/linker settings to suit Google Test's needs. 16 | # 17 | # This must be a macro(), as inside a function string() can only 18 | # update variables in the function scope. 19 | macro(fix_default_compiler_settings_) 20 | if (MSVC) 21 | # For MSVC, CMake sets certain flags to defaults we want to override. 22 | # This replacement code is taken from sample in the CMake Wiki at 23 | # http://www.cmake.org/Wiki/CMake_FAQ#Dynamic_Replace. 24 | foreach (flag_var 25 | CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE 26 | CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO) 27 | if (NOT BUILD_SHARED_LIBS AND NOT gtest_force_shared_crt) 28 | # When Google Test is built as a shared library, it should also use 29 | # shared runtime libraries. Otherwise, it may end up with multiple 30 | # copies of runtime library data in different modules, resulting in 31 | # hard-to-find crashes. When it is built as a static library, it is 32 | # preferable to use CRT as static libraries, as we don't have to rely 33 | # on CRT DLLs being available. CMake always defaults to using shared 34 | # CRT libraries, so we override that default here. 35 | string(REPLACE "/MD" "-MT" ${flag_var} "${${flag_var}}") 36 | endif() 37 | 38 | # We prefer more strict warning checking for building Google Test. 39 | # Replaces /W3 with /W4 in defaults. 40 | string(REPLACE "/W3" "-W4" ${flag_var} "${${flag_var}}") 41 | endforeach() 42 | endif() 43 | endmacro() 44 | 45 | # Defines the compiler/linker flags used to build Google Test and 46 | # Google Mock. You can tweak these definitions to suit your need. A 47 | # variable's value is empty before it's explicitly assigned to. 48 | macro(config_compiler_and_linker) 49 | if (NOT gtest_disable_pthreads) 50 | # Defines CMAKE_USE_PTHREADS_INIT and CMAKE_THREAD_LIBS_INIT. 51 | find_package(Threads) 52 | endif() 53 | 54 | fix_default_compiler_settings_() 55 | if (MSVC) 56 | # Newlines inside flags variables break CMake's NMake generator. 57 | # TODO(vladl@google.com): Add -RTCs and -RTCu to debug builds. 58 | set(cxx_base_flags "-GS -W4 -WX -wd4127 -wd4251 -wd4275 -nologo -J -Zi") 59 | if (MSVC_VERSION LESS 1400) 60 | # Suppress spurious warnings MSVC 7.1 sometimes issues. 61 | # Forcing value to bool. 62 | set(cxx_base_flags "${cxx_base_flags} -wd4800") 63 | # Copy constructor and assignment operator could not be generated. 64 | set(cxx_base_flags "${cxx_base_flags} -wd4511 -wd4512") 65 | # Compatibility warnings not applicable to Google Test. 66 | # Resolved overload was found by argument-dependent lookup. 67 | set(cxx_base_flags "${cxx_base_flags} -wd4675") 68 | endif() 69 | set(cxx_base_flags "${cxx_base_flags} -D_UNICODE -DUNICODE -DWIN32 -D_WIN32") 70 | set(cxx_base_flags "${cxx_base_flags} -DSTRICT -DWIN32_LEAN_AND_MEAN") 71 | set(cxx_exception_flags "-EHsc -D_HAS_EXCEPTIONS=1") 72 | set(cxx_no_exception_flags "-D_HAS_EXCEPTIONS=0") 73 | set(cxx_no_rtti_flags "-GR-") 74 | elseif (CMAKE_COMPILER_IS_GNUCXX) 75 | set(cxx_base_flags "-Wall -Wshadow") 76 | set(cxx_exception_flags "-fexceptions") 77 | set(cxx_no_exception_flags "-fno-exceptions") 78 | # Until version 4.3.2, GCC doesn't define a macro to indicate 79 | # whether RTTI is enabled. Therefore we define GTEST_HAS_RTTI 80 | # explicitly. 81 | set(cxx_no_rtti_flags "-fno-rtti -DGTEST_HAS_RTTI=0") 82 | set(cxx_strict_flags 83 | "-Wextra -Wno-unused-parameter -Wno-missing-field-initializers") 84 | elseif (CMAKE_CXX_COMPILER_ID STREQUAL "SunPro") 85 | set(cxx_exception_flags "-features=except") 86 | # Sun Pro doesn't provide macros to indicate whether exceptions and 87 | # RTTI are enabled, so we define GTEST_HAS_* explicitly. 88 | set(cxx_no_exception_flags "-features=no%except -DGTEST_HAS_EXCEPTIONS=0") 89 | set(cxx_no_rtti_flags "-features=no%rtti -DGTEST_HAS_RTTI=0") 90 | elseif (CMAKE_CXX_COMPILER_ID STREQUAL "VisualAge" OR 91 | CMAKE_CXX_COMPILER_ID STREQUAL "XL") 92 | # CMake 2.8 changes Visual Age's compiler ID to "XL". 93 | set(cxx_exception_flags "-qeh") 94 | set(cxx_no_exception_flags "-qnoeh") 95 | # Until version 9.0, Visual Age doesn't define a macro to indicate 96 | # whether RTTI is enabled. Therefore we define GTEST_HAS_RTTI 97 | # explicitly. 98 | set(cxx_no_rtti_flags "-qnortti -DGTEST_HAS_RTTI=0") 99 | elseif (CMAKE_CXX_COMPILER_ID STREQUAL "HP") 100 | set(cxx_base_flags "-AA -mt") 101 | set(cxx_exception_flags "-DGTEST_HAS_EXCEPTIONS=1") 102 | set(cxx_no_exception_flags "+noeh -DGTEST_HAS_EXCEPTIONS=0") 103 | # RTTI can not be disabled in HP aCC compiler. 104 | set(cxx_no_rtti_flags "") 105 | endif() 106 | 107 | if (CMAKE_USE_PTHREADS_INIT) # The pthreads library is available and allowed. 108 | set(cxx_base_flags "${cxx_base_flags} -DGTEST_HAS_PTHREAD=1") 109 | else() 110 | set(cxx_base_flags "${cxx_base_flags} -DGTEST_HAS_PTHREAD=0") 111 | endif() 112 | 113 | # For building gtest's own tests and samples. 114 | set(cxx_exception "${CMAKE_CXX_FLAGS} ${cxx_base_flags} ${cxx_exception_flags}") 115 | set(cxx_no_exception 116 | "${CMAKE_CXX_FLAGS} ${cxx_base_flags} ${cxx_no_exception_flags}") 117 | set(cxx_default "${cxx_exception}") 118 | set(cxx_no_rtti "${cxx_default} ${cxx_no_rtti_flags}") 119 | set(cxx_use_own_tuple "${cxx_default} -DGTEST_USE_OWN_TR1_TUPLE=1") 120 | 121 | # For building the gtest libraries. 122 | set(cxx_strict "${cxx_default} ${cxx_strict_flags}") 123 | endmacro() 124 | 125 | # Defines the gtest & gtest_main libraries. User tests should link 126 | # with one of them. 127 | function(cxx_library_with_type name type cxx_flags) 128 | # type can be either STATIC or SHARED to denote a static or shared library. 129 | # ARGN refers to additional arguments after 'cxx_flags'. 130 | add_library(${name} ${type} ${ARGN}) 131 | set_target_properties(${name} 132 | PROPERTIES 133 | COMPILE_FLAGS "${cxx_flags}") 134 | if (BUILD_SHARED_LIBS OR type STREQUAL "SHARED") 135 | set_target_properties(${name} 136 | PROPERTIES 137 | COMPILE_DEFINITIONS "GTEST_CREATE_SHARED_LIBRARY=1") 138 | endif() 139 | if (CMAKE_USE_PTHREADS_INIT) 140 | target_link_libraries(${name} ${CMAKE_THREAD_LIBS_INIT}) 141 | endif() 142 | endfunction() 143 | 144 | ######################################################################## 145 | # 146 | # Helper functions for creating build targets. 147 | 148 | function(cxx_shared_library name cxx_flags) 149 | cxx_library_with_type(${name} SHARED "${cxx_flags}" ${ARGN}) 150 | endfunction() 151 | 152 | function(cxx_library name cxx_flags) 153 | cxx_library_with_type(${name} "" "${cxx_flags}" ${ARGN}) 154 | endfunction() 155 | 156 | # cxx_executable_with_flags(name cxx_flags libs srcs...) 157 | # 158 | # creates a named C++ executable that depends on the given libraries and 159 | # is built from the given source files with the given compiler flags. 160 | function(cxx_executable_with_flags name cxx_flags libs) 161 | add_executable(${name} ${ARGN}) 162 | if (cxx_flags) 163 | set_target_properties(${name} 164 | PROPERTIES 165 | COMPILE_FLAGS "${cxx_flags}") 166 | endif() 167 | if (BUILD_SHARED_LIBS) 168 | set_target_properties(${name} 169 | PROPERTIES 170 | COMPILE_DEFINITIONS "GTEST_LINKED_AS_SHARED_LIBRARY=1") 171 | endif() 172 | # To support mixing linking in static and dynamic libraries, link each 173 | # library in with an extra call to target_link_libraries. 174 | foreach (lib "${libs}") 175 | target_link_libraries(${name} ${lib}) 176 | endforeach() 177 | endfunction() 178 | 179 | # cxx_executable(name dir lib srcs...) 180 | # 181 | # creates a named target that depends on the given libs and is built 182 | # from the given source files. dir/name.cc is implicitly included in 183 | # the source file list. 184 | function(cxx_executable name dir libs) 185 | cxx_executable_with_flags( 186 | ${name} "${cxx_default}" "${libs}" "${dir}/${name}.cc" ${ARGN}) 187 | endfunction() 188 | 189 | # Sets PYTHONINTERP_FOUND and PYTHON_EXECUTABLE. 190 | find_package(PythonInterp) 191 | 192 | # cxx_test_with_flags(name cxx_flags libs srcs...) 193 | # 194 | # creates a named C++ test that depends on the given libs and is built 195 | # from the given source files with the given compiler flags. 196 | function(cxx_test_with_flags name cxx_flags libs) 197 | cxx_executable_with_flags(${name} "${cxx_flags}" "${libs}" ${ARGN}) 198 | add_test(${name} ${name}) 199 | endfunction() 200 | 201 | # cxx_test(name libs srcs...) 202 | # 203 | # creates a named test target that depends on the given libs and is 204 | # built from the given source files. Unlike cxx_test_with_flags, 205 | # test/name.cc is already implicitly included in the source file list. 206 | function(cxx_test name libs) 207 | cxx_test_with_flags("${name}" "${cxx_default}" "${libs}" 208 | "test/${name}.cc" ${ARGN}) 209 | endfunction() 210 | 211 | # py_test(name) 212 | # 213 | # creates a Python test with the given name whose main module is in 214 | # test/name.py. It does nothing if Python is not installed. 215 | function(py_test name) 216 | # We are not supporting Python tests on Linux yet as they consider 217 | # all Linux environments to be google3 and try to use google3 features. 218 | if (PYTHONINTERP_FOUND) 219 | # ${CMAKE_BINARY_DIR} is known at configuration time, so we can 220 | # directly bind it from cmake. ${CTEST_CONFIGURATION_TYPE} is known 221 | # only at ctest runtime (by calling ctest -c ), so 222 | # we have to escape $ to delay variable substitution here. 223 | add_test(${name} 224 | ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test/${name}.py 225 | --build_dir=${CMAKE_CURRENT_BINARY_DIR}/\${CTEST_CONFIGURATION_TYPE}) 226 | endif() 227 | endfunction() 228 | -------------------------------------------------------------------------------- /test/gtest/include/gtest/gtest-message.h: -------------------------------------------------------------------------------- 1 | // Copyright 2005, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: wan@google.com (Zhanyong Wan) 31 | // 32 | // The Google C++ Testing Framework (Google Test) 33 | // 34 | // This header file defines the Message class. 35 | // 36 | // IMPORTANT NOTE: Due to limitation of the C++ language, we have to 37 | // leave some internal implementation details in this header file. 38 | // They are clearly marked by comments like this: 39 | // 40 | // // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. 41 | // 42 | // Such code is NOT meant to be used by a user directly, and is subject 43 | // to CHANGE WITHOUT NOTICE. Therefore DO NOT DEPEND ON IT in a user 44 | // program! 45 | 46 | #ifndef GTEST_INCLUDE_GTEST_GTEST_MESSAGE_H_ 47 | #define GTEST_INCLUDE_GTEST_GTEST_MESSAGE_H_ 48 | 49 | #include 50 | 51 | #include "gtest/internal/gtest-port.h" 52 | 53 | // Ensures that there is at least one operator<< in the global namespace. 54 | // See Message& operator<<(...) below for why. 55 | void operator<<(const testing::internal::Secret&, int); 56 | 57 | namespace testing { 58 | 59 | // The Message class works like an ostream repeater. 60 | // 61 | // Typical usage: 62 | // 63 | // 1. You stream a bunch of values to a Message object. 64 | // It will remember the text in a stringstream. 65 | // 2. Then you stream the Message object to an ostream. 66 | // This causes the text in the Message to be streamed 67 | // to the ostream. 68 | // 69 | // For example; 70 | // 71 | // testing::Message foo; 72 | // foo << 1 << " != " << 2; 73 | // std::cout << foo; 74 | // 75 | // will print "1 != 2". 76 | // 77 | // Message is not intended to be inherited from. In particular, its 78 | // destructor is not virtual. 79 | // 80 | // Note that stringstream behaves differently in gcc and in MSVC. You 81 | // can stream a NULL char pointer to it in the former, but not in the 82 | // latter (it causes an access violation if you do). The Message 83 | // class hides this difference by treating a NULL char pointer as 84 | // "(null)". 85 | class GTEST_API_ Message { 86 | private: 87 | // The type of basic IO manipulators (endl, ends, and flush) for 88 | // narrow streams. 89 | typedef std::ostream& (*BasicNarrowIoManip)(std::ostream&); 90 | 91 | public: 92 | // Constructs an empty Message. 93 | Message(); 94 | 95 | // Copy constructor. 96 | Message(const Message& msg) : ss_(new ::std::stringstream) { // NOLINT 97 | *ss_ << msg.GetString(); 98 | } 99 | 100 | // Constructs a Message from a C-string. 101 | explicit Message(const char* str) : ss_(new ::std::stringstream) { 102 | *ss_ << str; 103 | } 104 | 105 | #if GTEST_OS_SYMBIAN 106 | // Streams a value (either a pointer or not) to this object. 107 | template 108 | inline Message& operator <<(const T& value) { 109 | StreamHelper(typename internal::is_pointer::type(), value); 110 | return *this; 111 | } 112 | #else 113 | // Streams a non-pointer value to this object. 114 | template 115 | inline Message& operator <<(const T& val) { 116 | // Some libraries overload << for STL containers. These 117 | // overloads are defined in the global namespace instead of ::std. 118 | // 119 | // C++'s symbol lookup rule (i.e. Koenig lookup) says that these 120 | // overloads are visible in either the std namespace or the global 121 | // namespace, but not other namespaces, including the testing 122 | // namespace which Google Test's Message class is in. 123 | // 124 | // To allow STL containers (and other types that has a << operator 125 | // defined in the global namespace) to be used in Google Test 126 | // assertions, testing::Message must access the custom << operator 127 | // from the global namespace. With this using declaration, 128 | // overloads of << defined in the global namespace and those 129 | // visible via Koenig lookup are both exposed in this function. 130 | using ::operator <<; 131 | *ss_ << val; 132 | return *this; 133 | } 134 | 135 | // Streams a pointer value to this object. 136 | // 137 | // This function is an overload of the previous one. When you 138 | // stream a pointer to a Message, this definition will be used as it 139 | // is more specialized. (The C++ Standard, section 140 | // [temp.func.order].) If you stream a non-pointer, then the 141 | // previous definition will be used. 142 | // 143 | // The reason for this overload is that streaming a NULL pointer to 144 | // ostream is undefined behavior. Depending on the compiler, you 145 | // may get "0", "(nil)", "(null)", or an access violation. To 146 | // ensure consistent result across compilers, we always treat NULL 147 | // as "(null)". 148 | template 149 | inline Message& operator <<(T* const& pointer) { // NOLINT 150 | if (pointer == NULL) { 151 | *ss_ << "(null)"; 152 | } else { 153 | *ss_ << pointer; 154 | } 155 | return *this; 156 | } 157 | #endif // GTEST_OS_SYMBIAN 158 | 159 | // Since the basic IO manipulators are overloaded for both narrow 160 | // and wide streams, we have to provide this specialized definition 161 | // of operator <<, even though its body is the same as the 162 | // templatized version above. Without this definition, streaming 163 | // endl or other basic IO manipulators to Message will confuse the 164 | // compiler. 165 | Message& operator <<(BasicNarrowIoManip val) { 166 | *ss_ << val; 167 | return *this; 168 | } 169 | 170 | // Instead of 1/0, we want to see true/false for bool values. 171 | Message& operator <<(bool b) { 172 | return *this << (b ? "true" : "false"); 173 | } 174 | 175 | // These two overloads allow streaming a wide C string to a Message 176 | // using the UTF-8 encoding. 177 | Message& operator <<(const wchar_t* wide_c_str); 178 | Message& operator <<(wchar_t* wide_c_str); 179 | 180 | #if GTEST_HAS_STD_WSTRING 181 | // Converts the given wide string to a narrow string using the UTF-8 182 | // encoding, and streams the result to this Message object. 183 | Message& operator <<(const ::std::wstring& wstr); 184 | #endif // GTEST_HAS_STD_WSTRING 185 | 186 | #if GTEST_HAS_GLOBAL_WSTRING 187 | // Converts the given wide string to a narrow string using the UTF-8 188 | // encoding, and streams the result to this Message object. 189 | Message& operator <<(const ::wstring& wstr); 190 | #endif // GTEST_HAS_GLOBAL_WSTRING 191 | 192 | // Gets the text streamed to this object so far as an std::string. 193 | // Each '\0' character in the buffer is replaced with "\\0". 194 | // 195 | // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. 196 | std::string GetString() const; 197 | 198 | private: 199 | 200 | #if GTEST_OS_SYMBIAN 201 | // These are needed as the Nokia Symbian Compiler cannot decide between 202 | // const T& and const T* in a function template. The Nokia compiler _can_ 203 | // decide between class template specializations for T and T*, so a 204 | // tr1::type_traits-like is_pointer works, and we can overload on that. 205 | template 206 | inline void StreamHelper(internal::true_type /*is_pointer*/, T* pointer) { 207 | if (pointer == NULL) { 208 | *ss_ << "(null)"; 209 | } else { 210 | *ss_ << pointer; 211 | } 212 | } 213 | template 214 | inline void StreamHelper(internal::false_type /*is_pointer*/, 215 | const T& value) { 216 | // See the comments in Message& operator <<(const T&) above for why 217 | // we need this using statement. 218 | using ::operator <<; 219 | *ss_ << value; 220 | } 221 | #endif // GTEST_OS_SYMBIAN 222 | 223 | // We'll hold the text streamed to this object here. 224 | const internal::scoped_ptr< ::std::stringstream> ss_; 225 | 226 | // We declare (but don't implement) this to prevent the compiler 227 | // from implementing the assignment operator. 228 | void operator=(const Message&); 229 | }; 230 | 231 | // Streams a Message to an ostream. 232 | inline std::ostream& operator <<(std::ostream& os, const Message& sb) { 233 | return os << sb.GetString(); 234 | } 235 | 236 | namespace internal { 237 | 238 | // Converts a streamable value to an std::string. A NULL pointer is 239 | // converted to "(null)". When the input value is a ::string, 240 | // ::std::string, ::wstring, or ::std::wstring object, each NUL 241 | // character in it is replaced with "\\0". 242 | template 243 | std::string StreamableToString(const T& streamable) { 244 | return (Message() << streamable).GetString(); 245 | } 246 | 247 | } // namespace internal 248 | } // namespace testing 249 | 250 | #endif // GTEST_INCLUDE_GTEST_GTEST_MESSAGE_H_ 251 | -------------------------------------------------------------------------------- /test/gtest/include/gtest/gtest-test-part.h: -------------------------------------------------------------------------------- 1 | // Copyright 2008, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: mheule@google.com (Markus Heule) 31 | // 32 | 33 | #ifndef GTEST_INCLUDE_GTEST_GTEST_TEST_PART_H_ 34 | #define GTEST_INCLUDE_GTEST_GTEST_TEST_PART_H_ 35 | 36 | #include 37 | #include 38 | #include "gtest/internal/gtest-internal.h" 39 | #include "gtest/internal/gtest-string.h" 40 | 41 | namespace testing { 42 | 43 | // A copyable object representing the result of a test part (i.e. an 44 | // assertion or an explicit FAIL(), ADD_FAILURE(), or SUCCESS()). 45 | // 46 | // Don't inherit from TestPartResult as its destructor is not virtual. 47 | class GTEST_API_ TestPartResult { 48 | public: 49 | // The possible outcomes of a test part (i.e. an assertion or an 50 | // explicit SUCCEED(), FAIL(), or ADD_FAILURE()). 51 | enum Type { 52 | kSuccess, // Succeeded. 53 | kNonFatalFailure, // Failed but the test can continue. 54 | kFatalFailure // Failed and the test should be terminated. 55 | }; 56 | 57 | // C'tor. TestPartResult does NOT have a default constructor. 58 | // Always use this constructor (with parameters) to create a 59 | // TestPartResult object. 60 | TestPartResult(Type a_type, 61 | const char* a_file_name, 62 | int a_line_number, 63 | const char* a_message) 64 | : type_(a_type), 65 | file_name_(a_file_name == NULL ? "" : a_file_name), 66 | line_number_(a_line_number), 67 | summary_(ExtractSummary(a_message)), 68 | message_(a_message) { 69 | } 70 | 71 | // Gets the outcome of the test part. 72 | Type type() const { return type_; } 73 | 74 | // Gets the name of the source file where the test part took place, or 75 | // NULL if it's unknown. 76 | const char* file_name() const { 77 | return file_name_.empty() ? NULL : file_name_.c_str(); 78 | } 79 | 80 | // Gets the line in the source file where the test part took place, 81 | // or -1 if it's unknown. 82 | int line_number() const { return line_number_; } 83 | 84 | // Gets the summary of the failure message. 85 | const char* summary() const { return summary_.c_str(); } 86 | 87 | // Gets the message associated with the test part. 88 | const char* message() const { return message_.c_str(); } 89 | 90 | // Returns true iff the test part passed. 91 | bool passed() const { return type_ == kSuccess; } 92 | 93 | // Returns true iff the test part failed. 94 | bool failed() const { return type_ != kSuccess; } 95 | 96 | // Returns true iff the test part non-fatally failed. 97 | bool nonfatally_failed() const { return type_ == kNonFatalFailure; } 98 | 99 | // Returns true iff the test part fatally failed. 100 | bool fatally_failed() const { return type_ == kFatalFailure; } 101 | 102 | private: 103 | Type type_; 104 | 105 | // Gets the summary of the failure message by omitting the stack 106 | // trace in it. 107 | static std::string ExtractSummary(const char* message); 108 | 109 | // The name of the source file where the test part took place, or 110 | // "" if the source file is unknown. 111 | std::string file_name_; 112 | // The line in the source file where the test part took place, or -1 113 | // if the line number is unknown. 114 | int line_number_; 115 | std::string summary_; // The test failure summary. 116 | std::string message_; // The test failure message. 117 | }; 118 | 119 | // Prints a TestPartResult object. 120 | std::ostream& operator<<(std::ostream& os, const TestPartResult& result); 121 | 122 | // An array of TestPartResult objects. 123 | // 124 | // Don't inherit from TestPartResultArray as its destructor is not 125 | // virtual. 126 | class GTEST_API_ TestPartResultArray { 127 | public: 128 | TestPartResultArray() {} 129 | 130 | // Appends the given TestPartResult to the array. 131 | void Append(const TestPartResult& result); 132 | 133 | // Returns the TestPartResult at the given index (0-based). 134 | const TestPartResult& GetTestPartResult(int index) const; 135 | 136 | // Returns the number of TestPartResult objects in the array. 137 | int size() const; 138 | 139 | private: 140 | std::vector array_; 141 | 142 | GTEST_DISALLOW_COPY_AND_ASSIGN_(TestPartResultArray); 143 | }; 144 | 145 | // This interface knows how to report a test part result. 146 | class TestPartResultReporterInterface { 147 | public: 148 | virtual ~TestPartResultReporterInterface() {} 149 | 150 | virtual void ReportTestPartResult(const TestPartResult& result) = 0; 151 | }; 152 | 153 | namespace internal { 154 | 155 | // This helper class is used by {ASSERT|EXPECT}_NO_FATAL_FAILURE to check if a 156 | // statement generates new fatal failures. To do so it registers itself as the 157 | // current test part result reporter. Besides checking if fatal failures were 158 | // reported, it only delegates the reporting to the former result reporter. 159 | // The original result reporter is restored in the destructor. 160 | // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. 161 | class GTEST_API_ HasNewFatalFailureHelper 162 | : public TestPartResultReporterInterface { 163 | public: 164 | HasNewFatalFailureHelper(); 165 | virtual ~HasNewFatalFailureHelper(); 166 | virtual void ReportTestPartResult(const TestPartResult& result); 167 | bool has_new_fatal_failure() const { return has_new_fatal_failure_; } 168 | private: 169 | bool has_new_fatal_failure_; 170 | TestPartResultReporterInterface* original_reporter_; 171 | 172 | GTEST_DISALLOW_COPY_AND_ASSIGN_(HasNewFatalFailureHelper); 173 | }; 174 | 175 | } // namespace internal 176 | 177 | } // namespace testing 178 | 179 | #endif // GTEST_INCLUDE_GTEST_GTEST_TEST_PART_H_ 180 | -------------------------------------------------------------------------------- /test/gtest/include/gtest/gtest_prod.h: -------------------------------------------------------------------------------- 1 | // Copyright 2006, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: wan@google.com (Zhanyong Wan) 31 | // 32 | // Google C++ Testing Framework definitions useful in production code. 33 | 34 | #ifndef GTEST_INCLUDE_GTEST_GTEST_PROD_H_ 35 | #define GTEST_INCLUDE_GTEST_GTEST_PROD_H_ 36 | 37 | // When you need to test the private or protected members of a class, 38 | // use the FRIEND_TEST macro to declare your tests as friends of the 39 | // class. For example: 40 | // 41 | // class MyClass { 42 | // private: 43 | // void MyMethod(); 44 | // FRIEND_TEST(MyClassTest, MyMethod); 45 | // }; 46 | // 47 | // class MyClassTest : public testing::Test { 48 | // // ... 49 | // }; 50 | // 51 | // TEST_F(MyClassTest, MyMethod) { 52 | // // Can call MyClass::MyMethod() here. 53 | // } 54 | 55 | #define FRIEND_TEST(test_case_name, test_name)\ 56 | friend class test_case_name##_##test_name##_Test 57 | 58 | #endif // GTEST_INCLUDE_GTEST_GTEST_PROD_H_ 59 | -------------------------------------------------------------------------------- /test/gtest/include/gtest/internal/gtest-filepath.h: -------------------------------------------------------------------------------- 1 | // Copyright 2008, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: keith.ray@gmail.com (Keith Ray) 31 | // 32 | // Google Test filepath utilities 33 | // 34 | // This header file declares classes and functions used internally by 35 | // Google Test. They are subject to change without notice. 36 | // 37 | // This file is #included in . 38 | // Do not include this header file separately! 39 | 40 | #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_ 41 | #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_ 42 | 43 | #include "gtest/internal/gtest-string.h" 44 | 45 | namespace testing { 46 | namespace internal { 47 | 48 | // FilePath - a class for file and directory pathname manipulation which 49 | // handles platform-specific conventions (like the pathname separator). 50 | // Used for helper functions for naming files in a directory for xml output. 51 | // Except for Set methods, all methods are const or static, which provides an 52 | // "immutable value object" -- useful for peace of mind. 53 | // A FilePath with a value ending in a path separator ("like/this/") represents 54 | // a directory, otherwise it is assumed to represent a file. In either case, 55 | // it may or may not represent an actual file or directory in the file system. 56 | // Names are NOT checked for syntax correctness -- no checking for illegal 57 | // characters, malformed paths, etc. 58 | 59 | class GTEST_API_ FilePath { 60 | public: 61 | FilePath() : pathname_("") { } 62 | FilePath(const FilePath& rhs) : pathname_(rhs.pathname_) { } 63 | 64 | explicit FilePath(const std::string& pathname) : pathname_(pathname) { 65 | Normalize(); 66 | } 67 | 68 | FilePath& operator=(const FilePath& rhs) { 69 | Set(rhs); 70 | return *this; 71 | } 72 | 73 | void Set(const FilePath& rhs) { 74 | pathname_ = rhs.pathname_; 75 | } 76 | 77 | const std::string& string() const { return pathname_; } 78 | const char* c_str() const { return pathname_.c_str(); } 79 | 80 | // Returns the current working directory, or "" if unsuccessful. 81 | static FilePath GetCurrentDir(); 82 | 83 | // Given directory = "dir", base_name = "test", number = 0, 84 | // extension = "xml", returns "dir/test.xml". If number is greater 85 | // than zero (e.g., 12), returns "dir/test_12.xml". 86 | // On Windows platform, uses \ as the separator rather than /. 87 | static FilePath MakeFileName(const FilePath& directory, 88 | const FilePath& base_name, 89 | int number, 90 | const char* extension); 91 | 92 | // Given directory = "dir", relative_path = "test.xml", 93 | // returns "dir/test.xml". 94 | // On Windows, uses \ as the separator rather than /. 95 | static FilePath ConcatPaths(const FilePath& directory, 96 | const FilePath& relative_path); 97 | 98 | // Returns a pathname for a file that does not currently exist. The pathname 99 | // will be directory/base_name.extension or 100 | // directory/base_name_.extension if directory/base_name.extension 101 | // already exists. The number will be incremented until a pathname is found 102 | // that does not already exist. 103 | // Examples: 'dir/foo_test.xml' or 'dir/foo_test_1.xml'. 104 | // There could be a race condition if two or more processes are calling this 105 | // function at the same time -- they could both pick the same filename. 106 | static FilePath GenerateUniqueFileName(const FilePath& directory, 107 | const FilePath& base_name, 108 | const char* extension); 109 | 110 | // Returns true iff the path is "". 111 | bool IsEmpty() const { return pathname_.empty(); } 112 | 113 | // If input name has a trailing separator character, removes it and returns 114 | // the name, otherwise return the name string unmodified. 115 | // On Windows platform, uses \ as the separator, other platforms use /. 116 | FilePath RemoveTrailingPathSeparator() const; 117 | 118 | // Returns a copy of the FilePath with the directory part removed. 119 | // Example: FilePath("path/to/file").RemoveDirectoryName() returns 120 | // FilePath("file"). If there is no directory part ("just_a_file"), it returns 121 | // the FilePath unmodified. If there is no file part ("just_a_dir/") it 122 | // returns an empty FilePath (""). 123 | // On Windows platform, '\' is the path separator, otherwise it is '/'. 124 | FilePath RemoveDirectoryName() const; 125 | 126 | // RemoveFileName returns the directory path with the filename removed. 127 | // Example: FilePath("path/to/file").RemoveFileName() returns "path/to/". 128 | // If the FilePath is "a_file" or "/a_file", RemoveFileName returns 129 | // FilePath("./") or, on Windows, FilePath(".\\"). If the filepath does 130 | // not have a file, like "just/a/dir/", it returns the FilePath unmodified. 131 | // On Windows platform, '\' is the path separator, otherwise it is '/'. 132 | FilePath RemoveFileName() const; 133 | 134 | // Returns a copy of the FilePath with the case-insensitive extension removed. 135 | // Example: FilePath("dir/file.exe").RemoveExtension("EXE") returns 136 | // FilePath("dir/file"). If a case-insensitive extension is not 137 | // found, returns a copy of the original FilePath. 138 | FilePath RemoveExtension(const char* extension) const; 139 | 140 | // Creates directories so that path exists. Returns true if successful or if 141 | // the directories already exist; returns false if unable to create 142 | // directories for any reason. Will also return false if the FilePath does 143 | // not represent a directory (that is, it doesn't end with a path separator). 144 | bool CreateDirectoriesRecursively() const; 145 | 146 | // Create the directory so that path exists. Returns true if successful or 147 | // if the directory already exists; returns false if unable to create the 148 | // directory for any reason, including if the parent directory does not 149 | // exist. Not named "CreateDirectory" because that's a macro on Windows. 150 | bool CreateFolder() const; 151 | 152 | // Returns true if FilePath describes something in the file-system, 153 | // either a file, directory, or whatever, and that something exists. 154 | bool FileOrDirectoryExists() const; 155 | 156 | // Returns true if pathname describes a directory in the file-system 157 | // that exists. 158 | bool DirectoryExists() const; 159 | 160 | // Returns true if FilePath ends with a path separator, which indicates that 161 | // it is intended to represent a directory. Returns false otherwise. 162 | // This does NOT check that a directory (or file) actually exists. 163 | bool IsDirectory() const; 164 | 165 | // Returns true if pathname describes a root directory. (Windows has one 166 | // root directory per disk drive.) 167 | bool IsRootDirectory() const; 168 | 169 | // Returns true if pathname describes an absolute path. 170 | bool IsAbsolutePath() const; 171 | 172 | private: 173 | // Replaces multiple consecutive separators with a single separator. 174 | // For example, "bar///foo" becomes "bar/foo". Does not eliminate other 175 | // redundancies that might be in a pathname involving "." or "..". 176 | // 177 | // A pathname with multiple consecutive separators may occur either through 178 | // user error or as a result of some scripts or APIs that generate a pathname 179 | // with a trailing separator. On other platforms the same API or script 180 | // may NOT generate a pathname with a trailing "/". Then elsewhere that 181 | // pathname may have another "/" and pathname components added to it, 182 | // without checking for the separator already being there. 183 | // The script language and operating system may allow paths like "foo//bar" 184 | // but some of the functions in FilePath will not handle that correctly. In 185 | // particular, RemoveTrailingPathSeparator() only removes one separator, and 186 | // it is called in CreateDirectoriesRecursively() assuming that it will change 187 | // a pathname from directory syntax (trailing separator) to filename syntax. 188 | // 189 | // On Windows this method also replaces the alternate path separator '/' with 190 | // the primary path separator '\\', so that for example "bar\\/\\foo" becomes 191 | // "bar\\foo". 192 | 193 | void Normalize(); 194 | 195 | // Returns a pointer to the last occurence of a valid path separator in 196 | // the FilePath. On Windows, for example, both '/' and '\' are valid path 197 | // separators. Returns NULL if no path separator was found. 198 | const char* FindLastPathSeparator() const; 199 | 200 | std::string pathname_; 201 | }; // class FilePath 202 | 203 | } // namespace internal 204 | } // namespace testing 205 | 206 | #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_ 207 | -------------------------------------------------------------------------------- /test/gtest/include/gtest/internal/gtest-linked_ptr.h: -------------------------------------------------------------------------------- 1 | // Copyright 2003 Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Authors: Dan Egnor (egnor@google.com) 31 | // 32 | // A "smart" pointer type with reference tracking. Every pointer to a 33 | // particular object is kept on a circular linked list. When the last pointer 34 | // to an object is destroyed or reassigned, the object is deleted. 35 | // 36 | // Used properly, this deletes the object when the last reference goes away. 37 | // There are several caveats: 38 | // - Like all reference counting schemes, cycles lead to leaks. 39 | // - Each smart pointer is actually two pointers (8 bytes instead of 4). 40 | // - Every time a pointer is assigned, the entire list of pointers to that 41 | // object is traversed. This class is therefore NOT SUITABLE when there 42 | // will often be more than two or three pointers to a particular object. 43 | // - References are only tracked as long as linked_ptr<> objects are copied. 44 | // If a linked_ptr<> is converted to a raw pointer and back, BAD THINGS 45 | // will happen (double deletion). 46 | // 47 | // A good use of this class is storing object references in STL containers. 48 | // You can safely put linked_ptr<> in a vector<>. 49 | // Other uses may not be as good. 50 | // 51 | // Note: If you use an incomplete type with linked_ptr<>, the class 52 | // *containing* linked_ptr<> must have a constructor and destructor (even 53 | // if they do nothing!). 54 | // 55 | // Bill Gibbons suggested we use something like this. 56 | // 57 | // Thread Safety: 58 | // Unlike other linked_ptr implementations, in this implementation 59 | // a linked_ptr object is thread-safe in the sense that: 60 | // - it's safe to copy linked_ptr objects concurrently, 61 | // - it's safe to copy *from* a linked_ptr and read its underlying 62 | // raw pointer (e.g. via get()) concurrently, and 63 | // - it's safe to write to two linked_ptrs that point to the same 64 | // shared object concurrently. 65 | // TODO(wan@google.com): rename this to safe_linked_ptr to avoid 66 | // confusion with normal linked_ptr. 67 | 68 | #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_LINKED_PTR_H_ 69 | #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_LINKED_PTR_H_ 70 | 71 | #include 72 | #include 73 | 74 | #include "gtest/internal/gtest-port.h" 75 | 76 | namespace testing { 77 | namespace internal { 78 | 79 | // Protects copying of all linked_ptr objects. 80 | GTEST_API_ GTEST_DECLARE_STATIC_MUTEX_(g_linked_ptr_mutex); 81 | 82 | // This is used internally by all instances of linked_ptr<>. It needs to be 83 | // a non-template class because different types of linked_ptr<> can refer to 84 | // the same object (linked_ptr(obj) vs linked_ptr(obj)). 85 | // So, it needs to be possible for different types of linked_ptr to participate 86 | // in the same circular linked list, so we need a single class type here. 87 | // 88 | // DO NOT USE THIS CLASS DIRECTLY YOURSELF. Use linked_ptr. 89 | class linked_ptr_internal { 90 | public: 91 | // Create a new circle that includes only this instance. 92 | void join_new() { 93 | next_ = this; 94 | } 95 | 96 | // Many linked_ptr operations may change p.link_ for some linked_ptr 97 | // variable p in the same circle as this object. Therefore we need 98 | // to prevent two such operations from occurring concurrently. 99 | // 100 | // Note that different types of linked_ptr objects can coexist in a 101 | // circle (e.g. linked_ptr, linked_ptr, and 102 | // linked_ptr). Therefore we must use a single mutex to 103 | // protect all linked_ptr objects. This can create serious 104 | // contention in production code, but is acceptable in a testing 105 | // framework. 106 | 107 | // Join an existing circle. 108 | void join(linked_ptr_internal const* ptr) 109 | GTEST_LOCK_EXCLUDED_(g_linked_ptr_mutex) { 110 | MutexLock lock(&g_linked_ptr_mutex); 111 | 112 | linked_ptr_internal const* p = ptr; 113 | while (p->next_ != ptr) p = p->next_; 114 | p->next_ = this; 115 | next_ = ptr; 116 | } 117 | 118 | // Leave whatever circle we're part of. Returns true if we were the 119 | // last member of the circle. Once this is done, you can join() another. 120 | bool depart() 121 | GTEST_LOCK_EXCLUDED_(g_linked_ptr_mutex) { 122 | MutexLock lock(&g_linked_ptr_mutex); 123 | 124 | if (next_ == this) return true; 125 | linked_ptr_internal const* p = next_; 126 | while (p->next_ != this) p = p->next_; 127 | p->next_ = next_; 128 | return false; 129 | } 130 | 131 | private: 132 | mutable linked_ptr_internal const* next_; 133 | }; 134 | 135 | template 136 | class linked_ptr { 137 | public: 138 | typedef T element_type; 139 | 140 | // Take over ownership of a raw pointer. This should happen as soon as 141 | // possible after the object is created. 142 | explicit linked_ptr(T* ptr = NULL) { capture(ptr); } 143 | ~linked_ptr() { depart(); } 144 | 145 | // Copy an existing linked_ptr<>, adding ourselves to the list of references. 146 | template linked_ptr(linked_ptr const& ptr) { copy(&ptr); } 147 | linked_ptr(linked_ptr const& ptr) { // NOLINT 148 | assert(&ptr != this); 149 | copy(&ptr); 150 | } 151 | 152 | // Assignment releases the old value and acquires the new. 153 | template linked_ptr& operator=(linked_ptr const& ptr) { 154 | depart(); 155 | copy(&ptr); 156 | return *this; 157 | } 158 | 159 | linked_ptr& operator=(linked_ptr const& ptr) { 160 | if (&ptr != this) { 161 | depart(); 162 | copy(&ptr); 163 | } 164 | return *this; 165 | } 166 | 167 | // Smart pointer members. 168 | void reset(T* ptr = NULL) { 169 | depart(); 170 | capture(ptr); 171 | } 172 | T* get() const { return value_; } 173 | T* operator->() const { return value_; } 174 | T& operator*() const { return *value_; } 175 | 176 | bool operator==(T* p) const { return value_ == p; } 177 | bool operator!=(T* p) const { return value_ != p; } 178 | template 179 | bool operator==(linked_ptr const& ptr) const { 180 | return value_ == ptr.get(); 181 | } 182 | template 183 | bool operator!=(linked_ptr const& ptr) const { 184 | return value_ != ptr.get(); 185 | } 186 | 187 | private: 188 | template 189 | friend class linked_ptr; 190 | 191 | T* value_; 192 | linked_ptr_internal link_; 193 | 194 | void depart() { 195 | if (link_.depart()) delete value_; 196 | } 197 | 198 | void capture(T* ptr) { 199 | value_ = ptr; 200 | link_.join_new(); 201 | } 202 | 203 | template void copy(linked_ptr const* ptr) { 204 | value_ = ptr->get(); 205 | if (value_) 206 | link_.join(&ptr->link_); 207 | else 208 | link_.join_new(); 209 | } 210 | }; 211 | 212 | template inline 213 | bool operator==(T* ptr, const linked_ptr& x) { 214 | return ptr == x.get(); 215 | } 216 | 217 | template inline 218 | bool operator!=(T* ptr, const linked_ptr& x) { 219 | return ptr != x.get(); 220 | } 221 | 222 | // A function to convert T* into linked_ptr 223 | // Doing e.g. make_linked_ptr(new FooBarBaz(arg)) is a shorter notation 224 | // for linked_ptr >(new FooBarBaz(arg)) 225 | template 226 | linked_ptr make_linked_ptr(T* ptr) { 227 | return linked_ptr(ptr); 228 | } 229 | 230 | } // namespace internal 231 | } // namespace testing 232 | 233 | #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_LINKED_PTR_H_ 234 | -------------------------------------------------------------------------------- /test/gtest/include/gtest/internal/gtest-param-util-generated.h.pump: -------------------------------------------------------------------------------- 1 | $$ -*- mode: c++; -*- 2 | $var n = 50 $$ Maximum length of Values arguments we want to support. 3 | $var maxtuple = 10 $$ Maximum number of Combine arguments we want to support. 4 | // Copyright 2008 Google Inc. 5 | // All Rights Reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are 9 | // met: 10 | // 11 | // * Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // * Redistributions in binary form must reproduce the above 14 | // copyright notice, this list of conditions and the following disclaimer 15 | // in the documentation and/or other materials provided with the 16 | // distribution. 17 | // * Neither the name of Google Inc. nor the names of its 18 | // contributors may be used to endorse or promote products derived from 19 | // this software without specific prior written permission. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | // 33 | // Author: vladl@google.com (Vlad Losev) 34 | 35 | // Type and function utilities for implementing parameterized tests. 36 | // This file is generated by a SCRIPT. DO NOT EDIT BY HAND! 37 | // 38 | // Currently Google Test supports at most $n arguments in Values, 39 | // and at most $maxtuple arguments in Combine. Please contact 40 | // googletestframework@googlegroups.com if you need more. 41 | // Please note that the number of arguments to Combine is limited 42 | // by the maximum arity of the implementation of tr1::tuple which is 43 | // currently set at $maxtuple. 44 | 45 | #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_GENERATED_H_ 46 | #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_GENERATED_H_ 47 | 48 | // scripts/fuse_gtest.py depends on gtest's own header being #included 49 | // *unconditionally*. Therefore these #includes cannot be moved 50 | // inside #if GTEST_HAS_PARAM_TEST. 51 | #include "gtest/internal/gtest-param-util.h" 52 | #include "gtest/internal/gtest-port.h" 53 | 54 | #if GTEST_HAS_PARAM_TEST 55 | 56 | namespace testing { 57 | 58 | // Forward declarations of ValuesIn(), which is implemented in 59 | // include/gtest/gtest-param-test.h. 60 | template 61 | internal::ParamGenerator< 62 | typename ::testing::internal::IteratorTraits::value_type> 63 | ValuesIn(ForwardIterator begin, ForwardIterator end); 64 | 65 | template 66 | internal::ParamGenerator ValuesIn(const T (&array)[N]); 67 | 68 | template 69 | internal::ParamGenerator ValuesIn( 70 | const Container& container); 71 | 72 | namespace internal { 73 | 74 | // Used in the Values() function to provide polymorphic capabilities. 75 | template 76 | class ValueArray1 { 77 | public: 78 | explicit ValueArray1(T1 v1) : v1_(v1) {} 79 | 80 | template 81 | operator ParamGenerator() const { return ValuesIn(&v1_, &v1_ + 1); } 82 | 83 | private: 84 | // No implementation - assignment is unsupported. 85 | void operator=(const ValueArray1& other); 86 | 87 | const T1 v1_; 88 | }; 89 | 90 | $range i 2..n 91 | $for i [[ 92 | $range j 1..i 93 | 94 | template <$for j, [[typename T$j]]> 95 | class ValueArray$i { 96 | public: 97 | ValueArray$i($for j, [[T$j v$j]]) : $for j, [[v$(j)_(v$j)]] {} 98 | 99 | template 100 | operator ParamGenerator() const { 101 | const T array[] = {$for j, [[static_cast(v$(j)_)]]}; 102 | return ValuesIn(array); 103 | } 104 | 105 | private: 106 | // No implementation - assignment is unsupported. 107 | void operator=(const ValueArray$i& other); 108 | 109 | $for j [[ 110 | 111 | const T$j v$(j)_; 112 | ]] 113 | 114 | }; 115 | 116 | ]] 117 | 118 | # if GTEST_HAS_COMBINE 119 | // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. 120 | // 121 | // Generates values from the Cartesian product of values produced 122 | // by the argument generators. 123 | // 124 | $range i 2..maxtuple 125 | $for i [[ 126 | $range j 1..i 127 | $range k 2..i 128 | 129 | template <$for j, [[typename T$j]]> 130 | class CartesianProductGenerator$i 131 | : public ParamGeneratorInterface< ::std::tr1::tuple<$for j, [[T$j]]> > { 132 | public: 133 | typedef ::std::tr1::tuple<$for j, [[T$j]]> ParamType; 134 | 135 | CartesianProductGenerator$i($for j, [[const ParamGenerator& g$j]]) 136 | : $for j, [[g$(j)_(g$j)]] {} 137 | virtual ~CartesianProductGenerator$i() {} 138 | 139 | virtual ParamIteratorInterface* Begin() const { 140 | return new Iterator(this, $for j, [[g$(j)_, g$(j)_.begin()]]); 141 | } 142 | virtual ParamIteratorInterface* End() const { 143 | return new Iterator(this, $for j, [[g$(j)_, g$(j)_.end()]]); 144 | } 145 | 146 | private: 147 | class Iterator : public ParamIteratorInterface { 148 | public: 149 | Iterator(const ParamGeneratorInterface* base, $for j, [[ 150 | 151 | const ParamGenerator& g$j, 152 | const typename ParamGenerator::iterator& current$(j)]]) 153 | : base_(base), 154 | $for j, [[ 155 | 156 | begin$(j)_(g$j.begin()), end$(j)_(g$j.end()), current$(j)_(current$j) 157 | ]] { 158 | ComputeCurrentValue(); 159 | } 160 | virtual ~Iterator() {} 161 | 162 | virtual const ParamGeneratorInterface* BaseGenerator() const { 163 | return base_; 164 | } 165 | // Advance should not be called on beyond-of-range iterators 166 | // so no component iterators must be beyond end of range, either. 167 | virtual void Advance() { 168 | assert(!AtEnd()); 169 | ++current$(i)_; 170 | 171 | $for k [[ 172 | if (current$(i+2-k)_ == end$(i+2-k)_) { 173 | current$(i+2-k)_ = begin$(i+2-k)_; 174 | ++current$(i+2-k-1)_; 175 | } 176 | 177 | ]] 178 | ComputeCurrentValue(); 179 | } 180 | virtual ParamIteratorInterface* Clone() const { 181 | return new Iterator(*this); 182 | } 183 | virtual const ParamType* Current() const { return ¤t_value_; } 184 | virtual bool Equals(const ParamIteratorInterface& other) const { 185 | // Having the same base generator guarantees that the other 186 | // iterator is of the same type and we can downcast. 187 | GTEST_CHECK_(BaseGenerator() == other.BaseGenerator()) 188 | << "The program attempted to compare iterators " 189 | << "from different generators." << std::endl; 190 | const Iterator* typed_other = 191 | CheckedDowncastToActualType(&other); 192 | // We must report iterators equal if they both point beyond their 193 | // respective ranges. That can happen in a variety of fashions, 194 | // so we have to consult AtEnd(). 195 | return (AtEnd() && typed_other->AtEnd()) || 196 | ($for j && [[ 197 | 198 | current$(j)_ == typed_other->current$(j)_ 199 | ]]); 200 | } 201 | 202 | private: 203 | Iterator(const Iterator& other) 204 | : base_(other.base_), $for j, [[ 205 | 206 | begin$(j)_(other.begin$(j)_), 207 | end$(j)_(other.end$(j)_), 208 | current$(j)_(other.current$(j)_) 209 | ]] { 210 | ComputeCurrentValue(); 211 | } 212 | 213 | void ComputeCurrentValue() { 214 | if (!AtEnd()) 215 | current_value_ = ParamType($for j, [[*current$(j)_]]); 216 | } 217 | bool AtEnd() const { 218 | // We must report iterator past the end of the range when either of the 219 | // component iterators has reached the end of its range. 220 | return 221 | $for j || [[ 222 | 223 | current$(j)_ == end$(j)_ 224 | ]]; 225 | } 226 | 227 | // No implementation - assignment is unsupported. 228 | void operator=(const Iterator& other); 229 | 230 | const ParamGeneratorInterface* const base_; 231 | // begin[i]_ and end[i]_ define the i-th range that Iterator traverses. 232 | // current[i]_ is the actual traversing iterator. 233 | $for j [[ 234 | 235 | const typename ParamGenerator::iterator begin$(j)_; 236 | const typename ParamGenerator::iterator end$(j)_; 237 | typename ParamGenerator::iterator current$(j)_; 238 | ]] 239 | 240 | ParamType current_value_; 241 | }; // class CartesianProductGenerator$i::Iterator 242 | 243 | // No implementation - assignment is unsupported. 244 | void operator=(const CartesianProductGenerator$i& other); 245 | 246 | 247 | $for j [[ 248 | const ParamGenerator g$(j)_; 249 | 250 | ]] 251 | }; // class CartesianProductGenerator$i 252 | 253 | 254 | ]] 255 | 256 | // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. 257 | // 258 | // Helper classes providing Combine() with polymorphic features. They allow 259 | // casting CartesianProductGeneratorN to ParamGenerator if T is 260 | // convertible to U. 261 | // 262 | $range i 2..maxtuple 263 | $for i [[ 264 | $range j 1..i 265 | 266 | template <$for j, [[class Generator$j]]> 267 | class CartesianProductHolder$i { 268 | public: 269 | CartesianProductHolder$i($for j, [[const Generator$j& g$j]]) 270 | : $for j, [[g$(j)_(g$j)]] {} 271 | template <$for j, [[typename T$j]]> 272 | operator ParamGenerator< ::std::tr1::tuple<$for j, [[T$j]]> >() const { 273 | return ParamGenerator< ::std::tr1::tuple<$for j, [[T$j]]> >( 274 | new CartesianProductGenerator$i<$for j, [[T$j]]>( 275 | $for j,[[ 276 | 277 | static_cast >(g$(j)_) 278 | ]])); 279 | } 280 | 281 | private: 282 | // No implementation - assignment is unsupported. 283 | void operator=(const CartesianProductHolder$i& other); 284 | 285 | 286 | $for j [[ 287 | const Generator$j g$(j)_; 288 | 289 | ]] 290 | }; // class CartesianProductHolder$i 291 | 292 | ]] 293 | 294 | # endif // GTEST_HAS_COMBINE 295 | 296 | } // namespace internal 297 | } // namespace testing 298 | 299 | #endif // GTEST_HAS_PARAM_TEST 300 | 301 | #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_GENERATED_H_ 302 | -------------------------------------------------------------------------------- /test/gtest/include/gtest/internal/gtest-string.h: -------------------------------------------------------------------------------- 1 | // Copyright 2005, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Authors: wan@google.com (Zhanyong Wan), eefacm@gmail.com (Sean Mcafee) 31 | // 32 | // The Google C++ Testing Framework (Google Test) 33 | // 34 | // This header file declares the String class and functions used internally by 35 | // Google Test. They are subject to change without notice. They should not used 36 | // by code external to Google Test. 37 | // 38 | // This header file is #included by . 39 | // It should not be #included by other files. 40 | 41 | #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_STRING_H_ 42 | #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_STRING_H_ 43 | 44 | #ifdef __BORLANDC__ 45 | // string.h is not guaranteed to provide strcpy on C++ Builder. 46 | # include 47 | #endif 48 | 49 | #include 50 | #include 51 | 52 | #include "gtest/internal/gtest-port.h" 53 | 54 | namespace testing { 55 | namespace internal { 56 | 57 | // String - an abstract class holding static string utilities. 58 | class GTEST_API_ String { 59 | public: 60 | // Static utility methods 61 | 62 | // Clones a 0-terminated C string, allocating memory using new. The 63 | // caller is responsible for deleting the return value using 64 | // delete[]. Returns the cloned string, or NULL if the input is 65 | // NULL. 66 | // 67 | // This is different from strdup() in string.h, which allocates 68 | // memory using malloc(). 69 | static const char* CloneCString(const char* c_str); 70 | 71 | #if GTEST_OS_WINDOWS_MOBILE 72 | // Windows CE does not have the 'ANSI' versions of Win32 APIs. To be 73 | // able to pass strings to Win32 APIs on CE we need to convert them 74 | // to 'Unicode', UTF-16. 75 | 76 | // Creates a UTF-16 wide string from the given ANSI string, allocating 77 | // memory using new. The caller is responsible for deleting the return 78 | // value using delete[]. Returns the wide string, or NULL if the 79 | // input is NULL. 80 | // 81 | // The wide string is created using the ANSI codepage (CP_ACP) to 82 | // match the behaviour of the ANSI versions of Win32 calls and the 83 | // C runtime. 84 | static LPCWSTR AnsiToUtf16(const char* c_str); 85 | 86 | // Creates an ANSI string from the given wide string, allocating 87 | // memory using new. The caller is responsible for deleting the return 88 | // value using delete[]. Returns the ANSI string, or NULL if the 89 | // input is NULL. 90 | // 91 | // The returned string is created using the ANSI codepage (CP_ACP) to 92 | // match the behaviour of the ANSI versions of Win32 calls and the 93 | // C runtime. 94 | static const char* Utf16ToAnsi(LPCWSTR utf16_str); 95 | #endif 96 | 97 | // Compares two C strings. Returns true iff they have the same content. 98 | // 99 | // Unlike strcmp(), this function can handle NULL argument(s). A 100 | // NULL C string is considered different to any non-NULL C string, 101 | // including the empty string. 102 | static bool CStringEquals(const char* lhs, const char* rhs); 103 | 104 | // Converts a wide C string to a String using the UTF-8 encoding. 105 | // NULL will be converted to "(null)". If an error occurred during 106 | // the conversion, "(failed to convert from wide string)" is 107 | // returned. 108 | static std::string ShowWideCString(const wchar_t* wide_c_str); 109 | 110 | // Compares two wide C strings. Returns true iff they have the same 111 | // content. 112 | // 113 | // Unlike wcscmp(), this function can handle NULL argument(s). A 114 | // NULL C string is considered different to any non-NULL C string, 115 | // including the empty string. 116 | static bool WideCStringEquals(const wchar_t* lhs, const wchar_t* rhs); 117 | 118 | // Compares two C strings, ignoring case. Returns true iff they 119 | // have the same content. 120 | // 121 | // Unlike strcasecmp(), this function can handle NULL argument(s). 122 | // A NULL C string is considered different to any non-NULL C string, 123 | // including the empty string. 124 | static bool CaseInsensitiveCStringEquals(const char* lhs, 125 | const char* rhs); 126 | 127 | // Compares two wide C strings, ignoring case. Returns true iff they 128 | // have the same content. 129 | // 130 | // Unlike wcscasecmp(), this function can handle NULL argument(s). 131 | // A NULL C string is considered different to any non-NULL wide C string, 132 | // including the empty string. 133 | // NB: The implementations on different platforms slightly differ. 134 | // On windows, this method uses _wcsicmp which compares according to LC_CTYPE 135 | // environment variable. On GNU platform this method uses wcscasecmp 136 | // which compares according to LC_CTYPE category of the current locale. 137 | // On MacOS X, it uses towlower, which also uses LC_CTYPE category of the 138 | // current locale. 139 | static bool CaseInsensitiveWideCStringEquals(const wchar_t* lhs, 140 | const wchar_t* rhs); 141 | 142 | // Returns true iff the given string ends with the given suffix, ignoring 143 | // case. Any string is considered to end with an empty suffix. 144 | static bool EndsWithCaseInsensitive( 145 | const std::string& str, const std::string& suffix); 146 | 147 | // Formats an int value as "%02d". 148 | static std::string FormatIntWidth2(int value); // "%02d" for width == 2 149 | 150 | // Formats an int value as "%X". 151 | static std::string FormatHexInt(int value); 152 | 153 | // Formats a byte as "%02X". 154 | static std::string FormatByte(unsigned char value); 155 | 156 | private: 157 | String(); // Not meant to be instantiated. 158 | }; // class String 159 | 160 | // Gets the content of the stringstream's buffer as an std::string. Each '\0' 161 | // character in the buffer is replaced with "\\0". 162 | GTEST_API_ std::string StringStreamToString(::std::stringstream* stream); 163 | 164 | } // namespace internal 165 | } // namespace testing 166 | 167 | #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_STRING_H_ 168 | -------------------------------------------------------------------------------- /test/gtest/include/gtest/internal/gtest-tuple.h.pump: -------------------------------------------------------------------------------- 1 | $$ -*- mode: c++; -*- 2 | $var n = 10 $$ Maximum number of tuple fields we want to support. 3 | $$ This meta comment fixes auto-indentation in Emacs. }} 4 | // Copyright 2009 Google Inc. 5 | // All Rights Reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are 9 | // met: 10 | // 11 | // * Redistributions of source code must retain the above copyright 12 | // notice, this list of conditions and the following disclaimer. 13 | // * Redistributions in binary form must reproduce the above 14 | // copyright notice, this list of conditions and the following disclaimer 15 | // in the documentation and/or other materials provided with the 16 | // distribution. 17 | // * Neither the name of Google Inc. nor the names of its 18 | // contributors may be used to endorse or promote products derived from 19 | // this software without specific prior written permission. 20 | // 21 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | // 33 | // Author: wan@google.com (Zhanyong Wan) 34 | 35 | // Implements a subset of TR1 tuple needed by Google Test and Google Mock. 36 | 37 | #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TUPLE_H_ 38 | #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TUPLE_H_ 39 | 40 | #include // For ::std::pair. 41 | 42 | // The compiler used in Symbian has a bug that prevents us from declaring the 43 | // tuple template as a friend (it complains that tuple is redefined). This 44 | // hack bypasses the bug by declaring the members that should otherwise be 45 | // private as public. 46 | // Sun Studio versions < 12 also have the above bug. 47 | #if defined(__SYMBIAN32__) || (defined(__SUNPRO_CC) && __SUNPRO_CC < 0x590) 48 | # define GTEST_DECLARE_TUPLE_AS_FRIEND_ public: 49 | #else 50 | # define GTEST_DECLARE_TUPLE_AS_FRIEND_ \ 51 | template friend class tuple; \ 52 | private: 53 | #endif 54 | 55 | 56 | $range i 0..n-1 57 | $range j 0..n 58 | $range k 1..n 59 | // GTEST_n_TUPLE_(T) is the type of an n-tuple. 60 | #define GTEST_0_TUPLE_(T) tuple<> 61 | 62 | $for k [[ 63 | $range m 0..k-1 64 | $range m2 k..n-1 65 | #define GTEST_$(k)_TUPLE_(T) tuple<$for m, [[T##$m]]$for m2 [[, void]]> 66 | 67 | ]] 68 | 69 | // GTEST_n_TYPENAMES_(T) declares a list of n typenames. 70 | 71 | $for j [[ 72 | $range m 0..j-1 73 | #define GTEST_$(j)_TYPENAMES_(T) $for m, [[typename T##$m]] 74 | 75 | 76 | ]] 77 | 78 | // In theory, defining stuff in the ::std namespace is undefined 79 | // behavior. We can do this as we are playing the role of a standard 80 | // library vendor. 81 | namespace std { 82 | namespace tr1 { 83 | 84 | template <$for i, [[typename T$i = void]]> 85 | class tuple; 86 | 87 | // Anything in namespace gtest_internal is Google Test's INTERNAL 88 | // IMPLEMENTATION DETAIL and MUST NOT BE USED DIRECTLY in user code. 89 | namespace gtest_internal { 90 | 91 | // ByRef::type is T if T is a reference; otherwise it's const T&. 92 | template 93 | struct ByRef { typedef const T& type; }; // NOLINT 94 | template 95 | struct ByRef { typedef T& type; }; // NOLINT 96 | 97 | // A handy wrapper for ByRef. 98 | #define GTEST_BY_REF_(T) typename ::std::tr1::gtest_internal::ByRef::type 99 | 100 | // AddRef::type is T if T is a reference; otherwise it's T&. This 101 | // is the same as tr1::add_reference::type. 102 | template 103 | struct AddRef { typedef T& type; }; // NOLINT 104 | template 105 | struct AddRef { typedef T& type; }; // NOLINT 106 | 107 | // A handy wrapper for AddRef. 108 | #define GTEST_ADD_REF_(T) typename ::std::tr1::gtest_internal::AddRef::type 109 | 110 | // A helper for implementing get(). 111 | template class Get; 112 | 113 | // A helper for implementing tuple_element. kIndexValid is true 114 | // iff k < the number of fields in tuple type T. 115 | template 116 | struct TupleElement; 117 | 118 | 119 | $for i [[ 120 | template 121 | struct TupleElement { 122 | typedef T$i type; 123 | }; 124 | 125 | 126 | ]] 127 | } // namespace gtest_internal 128 | 129 | template <> 130 | class tuple<> { 131 | public: 132 | tuple() {} 133 | tuple(const tuple& /* t */) {} 134 | tuple& operator=(const tuple& /* t */) { return *this; } 135 | }; 136 | 137 | 138 | $for k [[ 139 | $range m 0..k-1 140 | template 141 | class $if k < n [[GTEST_$(k)_TUPLE_(T)]] $else [[tuple]] { 142 | public: 143 | template friend class gtest_internal::Get; 144 | 145 | tuple() : $for m, [[f$(m)_()]] {} 146 | 147 | explicit tuple($for m, [[GTEST_BY_REF_(T$m) f$m]]) : [[]] 148 | $for m, [[f$(m)_(f$m)]] {} 149 | 150 | tuple(const tuple& t) : $for m, [[f$(m)_(t.f$(m)_)]] {} 151 | 152 | template 153 | tuple(const GTEST_$(k)_TUPLE_(U)& t) : $for m, [[f$(m)_(t.f$(m)_)]] {} 154 | 155 | $if k == 2 [[ 156 | template 157 | tuple(const ::std::pair& p) : f0_(p.first), f1_(p.second) {} 158 | 159 | ]] 160 | 161 | tuple& operator=(const tuple& t) { return CopyFrom(t); } 162 | 163 | template 164 | tuple& operator=(const GTEST_$(k)_TUPLE_(U)& t) { 165 | return CopyFrom(t); 166 | } 167 | 168 | $if k == 2 [[ 169 | template 170 | tuple& operator=(const ::std::pair& p) { 171 | f0_ = p.first; 172 | f1_ = p.second; 173 | return *this; 174 | } 175 | 176 | ]] 177 | 178 | GTEST_DECLARE_TUPLE_AS_FRIEND_ 179 | 180 | template 181 | tuple& CopyFrom(const GTEST_$(k)_TUPLE_(U)& t) { 182 | 183 | $for m [[ 184 | f$(m)_ = t.f$(m)_; 185 | 186 | ]] 187 | return *this; 188 | } 189 | 190 | 191 | $for m [[ 192 | T$m f$(m)_; 193 | 194 | ]] 195 | }; 196 | 197 | 198 | ]] 199 | // 6.1.3.2 Tuple creation functions. 200 | 201 | // Known limitations: we don't support passing an 202 | // std::tr1::reference_wrapper to make_tuple(). And we don't 203 | // implement tie(). 204 | 205 | inline tuple<> make_tuple() { return tuple<>(); } 206 | 207 | $for k [[ 208 | $range m 0..k-1 209 | 210 | template 211 | inline GTEST_$(k)_TUPLE_(T) make_tuple($for m, [[const T$m& f$m]]) { 212 | return GTEST_$(k)_TUPLE_(T)($for m, [[f$m]]); 213 | } 214 | 215 | ]] 216 | 217 | // 6.1.3.3 Tuple helper classes. 218 | 219 | template struct tuple_size; 220 | 221 | 222 | $for j [[ 223 | template 224 | struct tuple_size { 225 | static const int value = $j; 226 | }; 227 | 228 | 229 | ]] 230 | template 231 | struct tuple_element { 232 | typedef typename gtest_internal::TupleElement< 233 | k < (tuple_size::value), k, Tuple>::type type; 234 | }; 235 | 236 | #define GTEST_TUPLE_ELEMENT_(k, Tuple) typename tuple_element::type 237 | 238 | // 6.1.3.4 Element access. 239 | 240 | namespace gtest_internal { 241 | 242 | 243 | $for i [[ 244 | template <> 245 | class Get<$i> { 246 | public: 247 | template 248 | static GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_($i, Tuple)) 249 | Field(Tuple& t) { return t.f$(i)_; } // NOLINT 250 | 251 | template 252 | static GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_($i, Tuple)) 253 | ConstField(const Tuple& t) { return t.f$(i)_; } 254 | }; 255 | 256 | 257 | ]] 258 | } // namespace gtest_internal 259 | 260 | template 261 | GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(k, GTEST_$(n)_TUPLE_(T))) 262 | get(GTEST_$(n)_TUPLE_(T)& t) { 263 | return gtest_internal::Get::Field(t); 264 | } 265 | 266 | template 267 | GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(k, GTEST_$(n)_TUPLE_(T))) 268 | get(const GTEST_$(n)_TUPLE_(T)& t) { 269 | return gtest_internal::Get::ConstField(t); 270 | } 271 | 272 | // 6.1.3.5 Relational operators 273 | 274 | // We only implement == and !=, as we don't have a need for the rest yet. 275 | 276 | namespace gtest_internal { 277 | 278 | // SameSizeTuplePrefixComparator::Eq(t1, t2) returns true if the 279 | // first k fields of t1 equals the first k fields of t2. 280 | // SameSizeTuplePrefixComparator(k1, k2) would be a compiler error if 281 | // k1 != k2. 282 | template 283 | struct SameSizeTuplePrefixComparator; 284 | 285 | template <> 286 | struct SameSizeTuplePrefixComparator<0, 0> { 287 | template 288 | static bool Eq(const Tuple1& /* t1 */, const Tuple2& /* t2 */) { 289 | return true; 290 | } 291 | }; 292 | 293 | template 294 | struct SameSizeTuplePrefixComparator { 295 | template 296 | static bool Eq(const Tuple1& t1, const Tuple2& t2) { 297 | return SameSizeTuplePrefixComparator::Eq(t1, t2) && 298 | ::std::tr1::get(t1) == ::std::tr1::get(t2); 299 | } 300 | }; 301 | 302 | } // namespace gtest_internal 303 | 304 | template 305 | inline bool operator==(const GTEST_$(n)_TUPLE_(T)& t, 306 | const GTEST_$(n)_TUPLE_(U)& u) { 307 | return gtest_internal::SameSizeTuplePrefixComparator< 308 | tuple_size::value, 309 | tuple_size::value>::Eq(t, u); 310 | } 311 | 312 | template 313 | inline bool operator!=(const GTEST_$(n)_TUPLE_(T)& t, 314 | const GTEST_$(n)_TUPLE_(U)& u) { return !(t == u); } 315 | 316 | // 6.1.4 Pairs. 317 | // Unimplemented. 318 | 319 | } // namespace tr1 320 | } // namespace std 321 | 322 | 323 | $for j [[ 324 | #undef GTEST_$(j)_TUPLE_ 325 | 326 | ]] 327 | 328 | 329 | $for j [[ 330 | #undef GTEST_$(j)_TYPENAMES_ 331 | 332 | ]] 333 | 334 | #undef GTEST_DECLARE_TUPLE_AS_FRIEND_ 335 | #undef GTEST_BY_REF_ 336 | #undef GTEST_ADD_REF_ 337 | #undef GTEST_TUPLE_ELEMENT_ 338 | 339 | #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TUPLE_H_ 340 | -------------------------------------------------------------------------------- /test/gtest/include/gtest/internal/gtest-type-util.h.pump: -------------------------------------------------------------------------------- 1 | $$ -*- mode: c++; -*- 2 | $var n = 50 $$ Maximum length of type lists we want to support. 3 | // Copyright 2008 Google Inc. 4 | // All Rights Reserved. 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are 8 | // met: 9 | // 10 | // * Redistributions of source code must retain the above copyright 11 | // notice, this list of conditions and the following disclaimer. 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following disclaimer 14 | // in the documentation and/or other materials provided with the 15 | // distribution. 16 | // * Neither the name of Google Inc. nor the names of its 17 | // contributors may be used to endorse or promote products derived from 18 | // this software without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | // 32 | // Author: wan@google.com (Zhanyong Wan) 33 | 34 | // Type utilities needed for implementing typed and type-parameterized 35 | // tests. This file is generated by a SCRIPT. DO NOT EDIT BY HAND! 36 | // 37 | // Currently we support at most $n types in a list, and at most $n 38 | // type-parameterized tests in one type-parameterized test case. 39 | // Please contact googletestframework@googlegroups.com if you need 40 | // more. 41 | 42 | #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_ 43 | #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_ 44 | 45 | #include "gtest/internal/gtest-port.h" 46 | 47 | // #ifdef __GNUC__ is too general here. It is possible to use gcc without using 48 | // libstdc++ (which is where cxxabi.h comes from). 49 | # if GTEST_HAS_CXXABI_H_ 50 | # include 51 | # elif defined(__HP_aCC) 52 | # include 53 | # endif // GTEST_HASH_CXXABI_H_ 54 | 55 | namespace testing { 56 | namespace internal { 57 | 58 | // GetTypeName() returns a human-readable name of type T. 59 | // NB: This function is also used in Google Mock, so don't move it inside of 60 | // the typed-test-only section below. 61 | template 62 | std::string GetTypeName() { 63 | # if GTEST_HAS_RTTI 64 | 65 | const char* const name = typeid(T).name(); 66 | # if GTEST_HAS_CXXABI_H_ || defined(__HP_aCC) 67 | int status = 0; 68 | // gcc's implementation of typeid(T).name() mangles the type name, 69 | // so we have to demangle it. 70 | # if GTEST_HAS_CXXABI_H_ 71 | using abi::__cxa_demangle; 72 | # endif // GTEST_HAS_CXXABI_H_ 73 | char* const readable_name = __cxa_demangle(name, 0, 0, &status); 74 | const std::string name_str(status == 0 ? readable_name : name); 75 | free(readable_name); 76 | return name_str; 77 | # else 78 | return name; 79 | # endif // GTEST_HAS_CXXABI_H_ || __HP_aCC 80 | 81 | # else 82 | 83 | return ""; 84 | 85 | # endif // GTEST_HAS_RTTI 86 | } 87 | 88 | #if GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P 89 | 90 | // AssertyTypeEq::type is defined iff T1 and T2 are the same 91 | // type. This can be used as a compile-time assertion to ensure that 92 | // two types are equal. 93 | 94 | template 95 | struct AssertTypeEq; 96 | 97 | template 98 | struct AssertTypeEq { 99 | typedef bool type; 100 | }; 101 | 102 | // A unique type used as the default value for the arguments of class 103 | // template Types. This allows us to simulate variadic templates 104 | // (e.g. Types, Type, and etc), which C++ doesn't 105 | // support directly. 106 | struct None {}; 107 | 108 | // The following family of struct and struct templates are used to 109 | // represent type lists. In particular, TypesN 110 | // represents a type list with N types (T1, T2, ..., and TN) in it. 111 | // Except for Types0, every struct in the family has two member types: 112 | // Head for the first type in the list, and Tail for the rest of the 113 | // list. 114 | 115 | // The empty type list. 116 | struct Types0 {}; 117 | 118 | // Type lists of length 1, 2, 3, and so on. 119 | 120 | template 121 | struct Types1 { 122 | typedef T1 Head; 123 | typedef Types0 Tail; 124 | }; 125 | 126 | $range i 2..n 127 | 128 | $for i [[ 129 | $range j 1..i 130 | $range k 2..i 131 | template <$for j, [[typename T$j]]> 132 | struct Types$i { 133 | typedef T1 Head; 134 | typedef Types$(i-1)<$for k, [[T$k]]> Tail; 135 | }; 136 | 137 | 138 | ]] 139 | 140 | } // namespace internal 141 | 142 | // We don't want to require the users to write TypesN<...> directly, 143 | // as that would require them to count the length. Types<...> is much 144 | // easier to write, but generates horrible messages when there is a 145 | // compiler error, as gcc insists on printing out each template 146 | // argument, even if it has the default value (this means Types 147 | // will appear as Types in the compiler 148 | // errors). 149 | // 150 | // Our solution is to combine the best part of the two approaches: a 151 | // user would write Types, and Google Test will translate 152 | // that to TypesN internally to make error messages 153 | // readable. The translation is done by the 'type' member of the 154 | // Types template. 155 | 156 | $range i 1..n 157 | template <$for i, [[typename T$i = internal::None]]> 158 | struct Types { 159 | typedef internal::Types$n<$for i, [[T$i]]> type; 160 | }; 161 | 162 | template <> 163 | struct Types<$for i, [[internal::None]]> { 164 | typedef internal::Types0 type; 165 | }; 166 | 167 | $range i 1..n-1 168 | $for i [[ 169 | $range j 1..i 170 | $range k i+1..n 171 | template <$for j, [[typename T$j]]> 172 | struct Types<$for j, [[T$j]]$for k[[, internal::None]]> { 173 | typedef internal::Types$i<$for j, [[T$j]]> type; 174 | }; 175 | 176 | ]] 177 | 178 | namespace internal { 179 | 180 | # define GTEST_TEMPLATE_ template class 181 | 182 | // The template "selector" struct TemplateSel is used to 183 | // represent Tmpl, which must be a class template with one type 184 | // parameter, as a type. TemplateSel::Bind::type is defined 185 | // as the type Tmpl. This allows us to actually instantiate the 186 | // template "selected" by TemplateSel. 187 | // 188 | // This trick is necessary for simulating typedef for class templates, 189 | // which C++ doesn't support directly. 190 | template 191 | struct TemplateSel { 192 | template 193 | struct Bind { 194 | typedef Tmpl type; 195 | }; 196 | }; 197 | 198 | # define GTEST_BIND_(TmplSel, T) \ 199 | TmplSel::template Bind::type 200 | 201 | // A unique struct template used as the default value for the 202 | // arguments of class template Templates. This allows us to simulate 203 | // variadic templates (e.g. Templates, Templates, 204 | // and etc), which C++ doesn't support directly. 205 | template 206 | struct NoneT {}; 207 | 208 | // The following family of struct and struct templates are used to 209 | // represent template lists. In particular, TemplatesN represents a list of N templates (T1, T2, ..., and TN). Except 211 | // for Templates0, every struct in the family has two member types: 212 | // Head for the selector of the first template in the list, and Tail 213 | // for the rest of the list. 214 | 215 | // The empty template list. 216 | struct Templates0 {}; 217 | 218 | // Template lists of length 1, 2, 3, and so on. 219 | 220 | template 221 | struct Templates1 { 222 | typedef TemplateSel Head; 223 | typedef Templates0 Tail; 224 | }; 225 | 226 | $range i 2..n 227 | 228 | $for i [[ 229 | $range j 1..i 230 | $range k 2..i 231 | template <$for j, [[GTEST_TEMPLATE_ T$j]]> 232 | struct Templates$i { 233 | typedef TemplateSel Head; 234 | typedef Templates$(i-1)<$for k, [[T$k]]> Tail; 235 | }; 236 | 237 | 238 | ]] 239 | 240 | // We don't want to require the users to write TemplatesN<...> directly, 241 | // as that would require them to count the length. Templates<...> is much 242 | // easier to write, but generates horrible messages when there is a 243 | // compiler error, as gcc insists on printing out each template 244 | // argument, even if it has the default value (this means Templates 245 | // will appear as Templates in the compiler 246 | // errors). 247 | // 248 | // Our solution is to combine the best part of the two approaches: a 249 | // user would write Templates, and Google Test will translate 250 | // that to TemplatesN internally to make error messages 251 | // readable. The translation is done by the 'type' member of the 252 | // Templates template. 253 | 254 | $range i 1..n 255 | template <$for i, [[GTEST_TEMPLATE_ T$i = NoneT]]> 256 | struct Templates { 257 | typedef Templates$n<$for i, [[T$i]]> type; 258 | }; 259 | 260 | template <> 261 | struct Templates<$for i, [[NoneT]]> { 262 | typedef Templates0 type; 263 | }; 264 | 265 | $range i 1..n-1 266 | $for i [[ 267 | $range j 1..i 268 | $range k i+1..n 269 | template <$for j, [[GTEST_TEMPLATE_ T$j]]> 270 | struct Templates<$for j, [[T$j]]$for k[[, NoneT]]> { 271 | typedef Templates$i<$for j, [[T$j]]> type; 272 | }; 273 | 274 | ]] 275 | 276 | // The TypeList template makes it possible to use either a single type 277 | // or a Types<...> list in TYPED_TEST_CASE() and 278 | // INSTANTIATE_TYPED_TEST_CASE_P(). 279 | 280 | template 281 | struct TypeList { 282 | typedef Types1 type; 283 | }; 284 | 285 | 286 | $range i 1..n 287 | template <$for i, [[typename T$i]]> 288 | struct TypeList > { 289 | typedef typename Types<$for i, [[T$i]]>::type type; 290 | }; 291 | 292 | #endif // GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P 293 | 294 | } // namespace internal 295 | } // namespace testing 296 | 297 | #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_ 298 | -------------------------------------------------------------------------------- /test/gtest/src/gtest-all.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2008, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: mheule@google.com (Markus Heule) 31 | // 32 | // Google C++ Testing Framework (Google Test) 33 | // 34 | // Sometimes it's desirable to build Google Test by compiling a single file. 35 | // This file serves this purpose. 36 | 37 | // This line ensures that gtest.h can be compiled on its own, even 38 | // when it's fused. 39 | #include "gtest/gtest.h" 40 | 41 | // The following lines pull in the real gtest *.cc files. 42 | #include "src/gtest.cc" 43 | #include "src/gtest-death-test.cc" 44 | #include "src/gtest-filepath.cc" 45 | #include "src/gtest-port.cc" 46 | #include "src/gtest-printers.cc" 47 | #include "src/gtest-test-part.cc" 48 | #include "src/gtest-typed-test.cc" 49 | -------------------------------------------------------------------------------- /test/gtest/src/gtest-test-part.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2008, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: mheule@google.com (Markus Heule) 31 | // 32 | // The Google C++ Testing Framework (Google Test) 33 | 34 | #include "gtest/gtest-test-part.h" 35 | 36 | // Indicates that this translation unit is part of Google Test's 37 | // implementation. It must come before gtest-internal-inl.h is 38 | // included, or there will be a compiler error. This trick is to 39 | // prevent a user from accidentally including gtest-internal-inl.h in 40 | // his code. 41 | #define GTEST_IMPLEMENTATION_ 1 42 | #include "src/gtest-internal-inl.h" 43 | #undef GTEST_IMPLEMENTATION_ 44 | 45 | namespace testing { 46 | 47 | using internal::GetUnitTestImpl; 48 | 49 | // Gets the summary of the failure message by omitting the stack trace 50 | // in it. 51 | std::string TestPartResult::ExtractSummary(const char* message) { 52 | const char* const stack_trace = strstr(message, internal::kStackTraceMarker); 53 | return stack_trace == NULL ? message : 54 | std::string(message, stack_trace); 55 | } 56 | 57 | // Prints a TestPartResult object. 58 | std::ostream& operator<<(std::ostream& os, const TestPartResult& result) { 59 | return os 60 | << result.file_name() << ":" << result.line_number() << ": " 61 | << (result.type() == TestPartResult::kSuccess ? "Success" : 62 | result.type() == TestPartResult::kFatalFailure ? "Fatal failure" : 63 | "Non-fatal failure") << ":\n" 64 | << result.message() << std::endl; 65 | } 66 | 67 | // Appends a TestPartResult to the array. 68 | void TestPartResultArray::Append(const TestPartResult& result) { 69 | array_.push_back(result); 70 | } 71 | 72 | // Returns the TestPartResult at the given index (0-based). 73 | const TestPartResult& TestPartResultArray::GetTestPartResult(int index) const { 74 | if (index < 0 || index >= size()) { 75 | printf("\nInvalid index (%d) into TestPartResultArray.\n", index); 76 | internal::posix::Abort(); 77 | } 78 | 79 | return array_[index]; 80 | } 81 | 82 | // Returns the number of TestPartResult objects in the array. 83 | int TestPartResultArray::size() const { 84 | return static_cast(array_.size()); 85 | } 86 | 87 | namespace internal { 88 | 89 | HasNewFatalFailureHelper::HasNewFatalFailureHelper() 90 | : has_new_fatal_failure_(false), 91 | original_reporter_(GetUnitTestImpl()-> 92 | GetTestPartResultReporterForCurrentThread()) { 93 | GetUnitTestImpl()->SetTestPartResultReporterForCurrentThread(this); 94 | } 95 | 96 | HasNewFatalFailureHelper::~HasNewFatalFailureHelper() { 97 | GetUnitTestImpl()->SetTestPartResultReporterForCurrentThread( 98 | original_reporter_); 99 | } 100 | 101 | void HasNewFatalFailureHelper::ReportTestPartResult( 102 | const TestPartResult& result) { 103 | if (result.fatally_failed()) 104 | has_new_fatal_failure_ = true; 105 | original_reporter_->ReportTestPartResult(result); 106 | } 107 | 108 | } // namespace internal 109 | 110 | } // namespace testing 111 | -------------------------------------------------------------------------------- /test/gtest/src/gtest-typed-test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2008 Google Inc. 2 | // All Rights Reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: wan@google.com (Zhanyong Wan) 31 | 32 | #include "gtest/gtest-typed-test.h" 33 | #include "gtest/gtest.h" 34 | 35 | namespace testing { 36 | namespace internal { 37 | 38 | #if GTEST_HAS_TYPED_TEST_P 39 | 40 | // Skips to the first non-space char in str. Returns an empty string if str 41 | // contains only whitespace characters. 42 | static const char* SkipSpaces(const char* str) { 43 | while (IsSpace(*str)) 44 | str++; 45 | return str; 46 | } 47 | 48 | // Verifies that registered_tests match the test names in 49 | // defined_test_names_; returns registered_tests if successful, or 50 | // aborts the program otherwise. 51 | const char* TypedTestCasePState::VerifyRegisteredTestNames( 52 | const char* file, int line, const char* registered_tests) { 53 | typedef ::std::set::const_iterator DefinedTestIter; 54 | registered_ = true; 55 | 56 | // Skip initial whitespace in registered_tests since some 57 | // preprocessors prefix stringizied literals with whitespace. 58 | registered_tests = SkipSpaces(registered_tests); 59 | 60 | Message errors; 61 | ::std::set tests; 62 | for (const char* names = registered_tests; names != NULL; 63 | names = SkipComma(names)) { 64 | const std::string name = GetPrefixUntilComma(names); 65 | if (tests.count(name) != 0) { 66 | errors << "Test " << name << " is listed more than once.\n"; 67 | continue; 68 | } 69 | 70 | bool found = false; 71 | for (DefinedTestIter it = defined_test_names_.begin(); 72 | it != defined_test_names_.end(); 73 | ++it) { 74 | if (name == *it) { 75 | found = true; 76 | break; 77 | } 78 | } 79 | 80 | if (found) { 81 | tests.insert(name); 82 | } else { 83 | errors << "No test named " << name 84 | << " can be found in this test case.\n"; 85 | } 86 | } 87 | 88 | for (DefinedTestIter it = defined_test_names_.begin(); 89 | it != defined_test_names_.end(); 90 | ++it) { 91 | if (tests.count(*it) == 0) { 92 | errors << "You forgot to list test " << *it << ".\n"; 93 | } 94 | } 95 | 96 | const std::string& errors_str = errors.GetString(); 97 | if (errors_str != "") { 98 | fprintf(stderr, "%s %s", FormatFileLocation(file, line).c_str(), 99 | errors_str.c_str()); 100 | fflush(stderr); 101 | posix::Abort(); 102 | } 103 | 104 | return registered_tests; 105 | } 106 | 107 | #endif // GTEST_HAS_TYPED_TEST_P 108 | 109 | } // namespace internal 110 | } // namespace testing 111 | -------------------------------------------------------------------------------- /test/gtest/src/gtest_main.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2006, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | #include 31 | 32 | #include "gtest/gtest.h" 33 | 34 | GTEST_API_ int main(int argc, char **argv) { 35 | printf("Running main() from gtest_main.cc\n"); 36 | testing::InitGoogleTest(&argc, argv); 37 | return RUN_ALL_TESTS(); 38 | } 39 | -------------------------------------------------------------------------------- /test/mbe-test.cpp: -------------------------------------------------------------------------------- 1 | #include "gtest/gtest.h" 2 | #include "gmock/gmock.h" 3 | 4 | extern "C" { 5 | #include "mbelib.h" 6 | } 7 | 8 | TEST(mbelib, synthesize_silence_f) 9 | { 10 | float float_buf[160] = {1.23f, -1.12f, 4680.412f, 4800.12f, -4700.74f}; 11 | 12 | mbe_synthesizeSilencef(float_buf); 13 | 14 | EXPECT_THAT(float_buf, testing::Each(0)); 15 | } 16 | 17 | TEST(mbelib, synthesize_silence) 18 | { 19 | short short_buf[160] = {3, -1, 1}; 20 | 21 | mbe_synthesizeSilence(short_buf); 22 | 23 | EXPECT_THAT(short_buf, testing::Each(0)); 24 | } 25 | 26 | TEST(mbelib, float_to_short) 27 | { 28 | float float_buf[160] = {1.23f, -1.12f, 4680.412f, 4800.12f, -4700.74f}; 29 | short short_buf[160]; 30 | 31 | // There is a gain of 7, and clipping at +/- 32760 32 | short expected[160] = {8, -7, 32760, 32760, -32760}; 33 | 34 | mbe_floattoshort(float_buf, short_buf); 35 | 36 | EXPECT_THAT(short_buf, testing::ElementsAreArray(expected, 160)); 37 | } 38 | -------------------------------------------------------------------------------- /test/test.cpp: -------------------------------------------------------------------------------- 1 | #include "gtest/gtest.h" 2 | 3 | int main(int argc, char* argv[]) 4 | { 5 | ::testing::InitGoogleTest(&argc, argv); 6 | return RUN_ALL_TESTS(); 7 | } 8 | --------------------------------------------------------------------------------