├── .clang-format ├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── README.md ├── clean.sh ├── reports ├── MiniSQLReport.pdf ├── lab1 │ ├── bitmap_test.png │ ├── buffer_pool_test.png │ ├── clock_test.png │ ├── disk_manager_test.png │ ├── lab1_report.md │ ├── lab1_report.pdf │ └── lru_test.png ├── lab2 │ ├── lab2_report.md │ ├── lab2_report.pdf │ ├── perf.png │ ├── table_heap_test.png │ └── tuple_test.png ├── lab3 │ ├── B+树正确性.png │ ├── B+树索引正确性.png │ ├── 增大数据量.png │ ├── 增大正确.png │ ├── 迭代器正确性.png │ ├── 黄政-3200100836-实验6(3).md │ └── 黄政-3200100836-实验6(3).pdf ├── lab4 │ └── lab4.pdf └── lab5 │ ├── 全选.png │ ├── 全部删除.png │ ├── 删除操作.png │ ├── 删除索引前后.png │ ├── 前四个1.png │ ├── 前四个2.png │ ├── 建立索引前后.png │ ├── 建立索引前选择时间.png │ ├── 执行建库和建表.png │ ├── 执行插入.png │ ├── 执行插入结果.png │ ├── 插入时间.png │ ├── 语法树.png │ ├── 选择结果.png │ ├── 重启后数据保留.png │ ├── 重启后数据都在.png │ ├── 黄政-3200100836-实验6(5).md │ └── 黄政-3200100836-实验6(5).pdf ├── src ├── CMakeLists.txt ├── buffer │ ├── buffer_pool_manager.cpp │ ├── clock_replacer.cpp │ └── lru_replacer.cpp ├── catalog │ ├── catalog.cpp │ ├── indexes.cpp │ └── table.cpp ├── executor │ └── execute_engine.cpp ├── include │ ├── buffer │ │ ├── buffer_pool_manager.h │ │ ├── clock_replacer.h │ │ ├── lru_replacer.h │ │ └── replacer.h │ ├── catalog │ │ ├── catalog.h │ │ ├── indexes.h │ │ └── table.h │ ├── common │ │ ├── config.h │ │ ├── dberr.h │ │ ├── instance.h │ │ ├── macros.h │ │ ├── rowid.h │ │ └── rwlatch.h │ ├── executor │ │ └── execute_engine.h │ ├── index │ │ ├── b_plus_tree.h │ │ ├── b_plus_tree_index.h │ │ ├── basic_comparator.h │ │ ├── generic_key.h │ │ ├── index.h │ │ └── index_iterator.h │ ├── page │ │ ├── b_plus_tree_internal_page.h │ │ ├── b_plus_tree_leaf_page.h │ │ ├── b_plus_tree_page.h │ │ ├── bitmap_page.h │ │ ├── disk_file_meta_page.h │ │ ├── index_roots_page.h │ │ ├── page.h │ │ └── table_page.h │ ├── parser │ │ ├── compile.sh │ │ ├── minisql.l │ │ ├── minisql.y │ │ ├── minisql_lex.h │ │ ├── minisql_yacc.h │ │ ├── parser.h │ │ ├── syntax_tree.h │ │ └── syntax_tree_printer.h │ ├── record │ │ ├── column.h │ │ ├── field.h │ │ ├── row.h │ │ ├── schema.h │ │ ├── type_id.h │ │ └── types.h │ ├── storage │ │ ├── disk_manager.h │ │ ├── table_heap.h │ │ └── table_iterator.h │ ├── transaction │ │ ├── lock_manager.h │ │ ├── log_manager.h │ │ └── transaction.h │ └── utils │ │ ├── mem_heap.h │ │ └── tree_file_mgr.h ├── index │ ├── b_plus_tree.cpp │ ├── b_plus_tree_index.cpp │ └── index_iterator.cpp ├── main.cpp ├── page │ ├── b_plus_tree_internal_page.cpp │ ├── b_plus_tree_leaf_page.cpp │ ├── b_plus_tree_page.cpp │ ├── bitmap_page.cpp │ ├── index_roots_page.cpp │ └── table_page.cpp ├── parser │ ├── minisql_lex.c │ ├── minisql_yacc.c │ ├── parser.c │ ├── syntax_tree.c │ └── syntax_tree_printer.cpp ├── record │ ├── column.cpp │ ├── row.cpp │ ├── schema.cpp │ └── types.cpp └── storage │ ├── disk_manager.cpp │ ├── table_heap.cpp │ └── table_iterator.cpp ├── test ├── CMakeLists.txt ├── buffer │ ├── buffer_pool_manager_test.cpp │ ├── clock_replacer_test.cpp │ └── lru_replacer_test.cpp ├── catalog │ └── catalog_test.cpp ├── include │ └── utils │ │ └── utils.h ├── index │ ├── b_plus_tree_index_test.cpp │ ├── b_plus_tree_test.cpp │ └── index_iterator_test.cpp ├── main_test.cpp ├── page │ └── index_roots_page_test.cpp ├── record │ └── tuple_test.cpp └── storage │ ├── disk_manager_test.cpp │ └── table_heap_test.cpp ├── testfiles ├── accounts.txt ├── basic.txt ├── cselect.txt └── dreopen.txt └── thirdparty ├── glog ├── .bazelci │ └── presubmit.yml ├── .clang-format ├── .clang-tidy ├── .gitattributes ├── .github │ └── workflows │ │ ├── android.yml │ │ ├── linux.yml │ │ ├── macos.yml │ │ └── windows.yml ├── .gitignore ├── AUTHORS ├── BUILD.bazel ├── CMakeLists.txt ├── CONTRIBUTORS ├── COPYING ├── ChangeLog ├── README.rst ├── WORKSPACE ├── bazel │ ├── example │ │ ├── BUILD.bazel │ │ └── main.cc │ └── glog.bzl ├── cmake │ ├── DetermineGflagsNamespace.cmake │ ├── FindUnwind.cmake │ ├── GetCacheVariables.cmake │ ├── RunCleanerTest1.cmake │ ├── RunCleanerTest2.cmake │ ├── RunCleanerTest3.cmake │ ├── TestInitPackageConfig.cmake │ └── TestPackageConfig.cmake ├── glog-config.cmake.in ├── glog-modules.cmake.in ├── libglog.pc.in └── src │ ├── base │ ├── commandlineflags.h │ ├── googleinit.h │ └── mutex.h │ ├── cleanup_immediately_unittest.cc │ ├── cleanup_with_absolute_prefix_unittest.cc │ ├── cleanup_with_relative_prefix_unittest.cc │ ├── config.h.cmake.in │ ├── demangle.cc │ ├── demangle.h │ ├── demangle_unittest.cc │ ├── demangle_unittest.sh │ ├── demangle_unittest.txt │ ├── glog │ ├── log_severity.h │ ├── logging.h.in │ ├── platform.h │ ├── raw_logging.h.in │ ├── stl_logging.h.in │ └── vlog_is_on.h.in │ ├── googletest.h │ ├── logging.cc │ ├── logging_custom_prefix_unittest.cc │ ├── logging_custom_prefix_unittest.err │ ├── logging_striplog_test.sh │ ├── logging_striptest10.cc │ ├── logging_striptest2.cc │ ├── logging_striptest_main.cc │ ├── logging_unittest.cc │ ├── logging_unittest.err │ ├── mock-log.h │ ├── mock-log_unittest.cc │ ├── package_config_unittest │ └── working_config │ │ ├── CMakeLists.txt │ │ └── glog_package_config.cc │ ├── raw_logging.cc │ ├── signalhandler.cc │ ├── signalhandler_unittest.cc │ ├── signalhandler_unittest.sh │ ├── stacktrace.h │ ├── stacktrace_generic-inl.h │ ├── stacktrace_libunwind-inl.h │ ├── stacktrace_powerpc-inl.h │ ├── stacktrace_unittest.cc │ ├── stacktrace_unwind-inl.h │ ├── stacktrace_windows-inl.h │ ├── stacktrace_x86-inl.h │ ├── stl_logging_unittest.cc │ ├── symbolize.cc │ ├── symbolize.h │ ├── symbolize_unittest.cc │ ├── utilities.cc │ ├── utilities.h │ ├── utilities_unittest.cc │ ├── vlog_is_on.cc │ └── windows │ ├── dirent.h │ ├── port.cc │ ├── port.h │ └── preprocess.sh └── googletest ├── CMakeLists.txt ├── README.md ├── cmake ├── Config.cmake.in ├── gtest.pc.in ├── gtest_main.pc.in ├── internal_utils.cmake └── libgtest.la.in ├── docs └── README.md ├── include └── gtest │ ├── gtest-death-test.h │ ├── gtest-matchers.h │ ├── gtest-message.h │ ├── gtest-param-test.h │ ├── gtest-printers.h │ ├── gtest-spi.h │ ├── gtest-test-part.h │ ├── gtest-typed-test.h │ ├── gtest.h │ ├── gtest_pred_impl.h │ ├── gtest_prod.h │ └── internal │ ├── custom │ ├── README.md │ ├── gtest-port.h │ ├── gtest-printers.h │ └── gtest.h │ ├── gtest-death-test-internal.h │ ├── gtest-filepath.h │ ├── gtest-internal.h │ ├── gtest-param-util.h │ ├── gtest-port-arch.h │ ├── gtest-port.h │ ├── gtest-string.h │ └── gtest-type-util.h ├── samples ├── prime_tables.h ├── sample1.cc ├── sample1.h ├── sample10_unittest.cc ├── sample1_unittest.cc ├── sample2.cc ├── sample2.h ├── sample2_unittest.cc ├── sample3-inl.h ├── sample3_unittest.cc ├── sample4.cc ├── sample4.h ├── sample4_unittest.cc ├── sample5_unittest.cc ├── sample6_unittest.cc ├── sample7_unittest.cc ├── sample8_unittest.cc └── sample9_unittest.cc ├── scripts ├── README.md ├── common.py ├── fuse_gtest_files.py ├── gen_gtest_pred_impl.py ├── gtest-config.in ├── release_docs.py ├── run_with_path.py ├── test │ └── Makefile ├── upload.py └── upload_gtest.py ├── src ├── gtest-all.cc ├── gtest-death-test.cc ├── gtest-filepath.cc ├── gtest-internal-inl.h ├── gtest-matchers.cc ├── gtest-port.cc ├── gtest-printers.cc ├── gtest-test-part.cc ├── gtest-typed-test.cc ├── gtest.cc └── gtest_main.cc └── test ├── BUILD.bazel ├── googletest-break-on-failure-unittest.py ├── googletest-break-on-failure-unittest_.cc ├── googletest-catch-exceptions-test.py ├── googletest-catch-exceptions-test_.cc ├── googletest-color-test.py ├── googletest-color-test_.cc ├── googletest-death-test-test.cc ├── googletest-death-test_ex_test.cc ├── googletest-env-var-test.py ├── googletest-env-var-test_.cc ├── googletest-failfast-unittest.py ├── googletest-failfast-unittest_.cc ├── googletest-filepath-test.cc ├── googletest-filter-unittest.py ├── googletest-filter-unittest_.cc ├── googletest-global-environment-unittest.py ├── googletest-global-environment-unittest_.cc ├── googletest-json-outfiles-test.py ├── googletest-json-output-unittest.py ├── googletest-list-tests-unittest.py ├── googletest-list-tests-unittest_.cc ├── googletest-listener-test.cc ├── googletest-message-test.cc ├── googletest-options-test.cc ├── googletest-output-test-golden-lin.txt ├── googletest-output-test.py ├── googletest-output-test_.cc ├── googletest-param-test-invalid-name1-test.py ├── googletest-param-test-invalid-name1-test_.cc ├── googletest-param-test-invalid-name2-test.py ├── googletest-param-test-invalid-name2-test_.cc ├── googletest-param-test-test.cc ├── googletest-param-test-test.h ├── googletest-param-test2-test.cc ├── googletest-port-test.cc ├── googletest-printers-test.cc ├── googletest-setuptestsuite-test.py ├── googletest-setuptestsuite-test_.cc ├── googletest-shuffle-test.py ├── googletest-shuffle-test_.cc ├── googletest-test-part-test.cc ├── googletest-throw-on-failure-test.py ├── googletest-throw-on-failure-test_.cc ├── googletest-uninitialized-test.py ├── googletest-uninitialized-test_.cc ├── gtest-typed-test2_test.cc ├── gtest-typed-test_test.cc ├── gtest-typed-test_test.h ├── gtest-unittest-api_test.cc ├── gtest_all_test.cc ├── gtest_assert_by_exception_test.cc ├── gtest_environment_test.cc ├── gtest_help_test.py ├── gtest_help_test_.cc ├── gtest_json_test_utils.py ├── gtest_list_output_unittest.py ├── gtest_list_output_unittest_.cc ├── gtest_main_unittest.cc ├── gtest_no_test_unittest.cc ├── gtest_pred_impl_unittest.cc ├── gtest_premature_exit_test.cc ├── gtest_prod_test.cc ├── gtest_repeat_test.cc ├── gtest_skip_check_output_test.py ├── gtest_skip_environment_check_output_test.py ├── gtest_skip_in_environment_setup_test.cc ├── gtest_skip_test.cc ├── gtest_sole_header_test.cc ├── gtest_stress_test.cc ├── gtest_test_macro_stack_footprint_test.cc ├── gtest_test_utils.py ├── gtest_testbridge_test.py ├── gtest_testbridge_test_.cc ├── gtest_throw_on_failure_ex_test.cc ├── gtest_unittest.cc ├── gtest_xml_outfile1_test_.cc ├── gtest_xml_outfile2_test_.cc ├── gtest_xml_outfiles_test.py ├── gtest_xml_output_unittest.py ├── gtest_xml_output_unittest_.cc ├── gtest_xml_test_utils.py ├── production.cc └── production.h /.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: Google 2 | DerivePointerAlignment: false 3 | PointerAlignment: Right 4 | ColumnLimit: 120 5 | 6 | # Default for clang-8, changed in later clangs. Set explicitly for forwards 7 | # compatibility for students with modern clangs 8 | IncludeBlocks: Preserve 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | bin/ 2 | build/ 3 | dbfiles/ 4 | datas/ 5 | .vscode/ 6 | .idea/ 7 | cmake-build-debug/ 8 | cmake-build-release/ -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | CMAKE_MINIMUM_REQUIRED(VERSION 3.10) 2 | if(POLICY CMP0042) 3 | cmake_policy(SET CMP0042 NEW) 4 | endif() 5 | 6 | MESSAGE(STATUS "Cmake output binray directory: ${CMAKE_BINARY_DIR}") 7 | 8 | # Project Info 9 | SET(CMAKE_CXX_STANDARD 17) 10 | PROJECT(MiniSQL 11 | VERSION 2022.1 12 | DESCRIPTION "ZheJiang University 2021~2022 Spring-Summer Database System Project" 13 | LANGUAGES C CXX) 14 | 15 | # CTest 16 | enable_testing() 17 | 18 | # Options 19 | ADD_DEFINITIONS(-DENABLE_DEBUG) 20 | # ADD_DEFINITIONS(-DENABLE_EXECUTE_DEBUG) 21 | # ADD_DEFINITIONS(-DENABLE_PARSER_DEBUG) 22 | # ADD_DEFINITIONS(-DENABLE_BPM_DEBUG) 23 | # ADD_DEFINITIONS(-DSHOW_PAGE_SPLIT) 24 | 25 | # Set Include Directory 26 | SET(THIRD_PARTY_DIR ${PROJECT_SOURCE_DIR}/thirdparty) 27 | SET(MINISQL_SRC_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/src/include) 28 | SET(MINISQL_TEST_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/test/include) 29 | SET(MINISQL_GTEST_INCLUDE_DIR ${THIRD_PARTY_DIR}/googletest/include) 30 | SET(MINISQL_GLOG_INCLUDE_DIR ${THIRD_PARTY_DIR}/glog/src) 31 | INCLUDE_DIRECTORIES(${MINISQL_SRC_INCLUDE_DIR} ${MINISQL_TEST_INCLUDE_DIR} ${MINISQL_GTEST_INCLUDE_DIR} ${MINISQL_GLOG_INCLUDE_DIR}) 32 | 33 | # Add gtest 34 | ADD_SUBDIRECTORY(${THIRD_PARTY_DIR}/googletest ${CMAKE_BINARY_DIR}/googletest-build) 35 | # Add glog 36 | ADD_SUBDIRECTORY(${THIRD_PARTY_DIR}/glog ${CMAKE_BINARY_DIR}/glog-build) 37 | target_compile_options(gtest PRIVATE "-fPIC") 38 | target_compile_options(gtest_main PRIVATE "-fPIC") 39 | 40 | # Compiler flags. 41 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall -Wextra -Werror -march=native") 42 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter -Wno-attributes") 43 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") 44 | set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -ggdb") 45 | # set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -ggdb -fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls") 46 | # set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fPIC") 47 | # set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fPIC") 48 | # set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} -fPIC") 49 | 50 | # set(GCC_COVERAGE_LINK_FLAGS "-fPIC") 51 | # message(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}") 52 | # message(STATUS "CMAKE_CXX_FLAGS_DEBUG: ${CMAKE_CXX_FLAGS_DEBUG}") 53 | # message(STATUS "CMAKE_EXE_LINKER_FLAGS: ${CMAKE_EXE_LINKER_FLAGS}") 54 | # message(STATUS "CMAKE_SHARED_LINKER_FLAGS: ${CMAKE_SHARED_LINKER_FLAGS}") 55 | 56 | # Add Subdirectory 57 | ADD_SUBDIRECTORY(src ${CMAKE_BINARY_DIR}/bin) 58 | ADD_SUBDIRECTORY(test ${CMAKE_BINARY_DIR}/test) 59 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 CMU Database Group 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MiniSQL 2 | 3 | 4 | 本框架参考CMU-15445 BusTub框架进行改写,在保留了缓冲池、索引、记录模块的一些核心设计理念的基础上,做了一些修改和扩展,使之兼容于原MiniSQL实验指导的要求。 5 | 以下列出了改动/扩展较大的几个地方: 6 | - 对Disk Manager模块进行改动,扩展了位图页、磁盘文件元数据页用于支持持久化数据页分配回收状态; 7 | - 在Record Manager, Index Manager, Catalog Manager等模块中,通过对内存对象的序列化和反序列化来持久化数据; 8 | - 对Record Manager层的一些数据结构(`Row`、`Field`、`Schema`、`Column`等)和实现进行重构; 9 | - 对Catalog Manager层进行重构,支持持久化并为Executor层提供接口调用; 10 | - 扩展了Parser层,Parser层支持输出语法树供Executor层调用; 11 | 12 | 此外还涉及到很多零碎的改动,包括源代码中部分模块代码的调整,测试代码的修改,性能上的优化等,在此不做赘述。 13 | 14 | 15 | 注意:为了避免代码抄袭,请不要将自己的代码发布到任何公共平台中。 16 | 17 | ### 编译&开发环境 18 | - Apple clang version: 11.0+ (MacOS),使用`gcc --version`和`g++ --version`查看 19 | - gcc & g++ : 8.0+ (Linux),使用`gcc --version`和`g++ --version`查看 20 | - cmake: 3.20+ (Both),使用`cmake --version`查看 21 | - gdb: 7.0+ (Optional),使用`gdb --version`查看 22 | - flex & bison (暂时不需要安装,但如果需要对SQL编译器的语法进行修改,需要安装) 23 | - llvm-symbolizer (暂时不需要安装) 24 | - in mac os `brew install llvm`, then set path and env variables. 25 | - in centos `yum install devtoolset-8-libasan-devel libasan` 26 | - https://www.jetbrains.com/help/clion/google-sanitizers.html#AsanChapter 27 | - https://www.jianshu.com/p/e4cbcd764783 28 | 29 | ### 构建 30 | #### Windows 31 | 目前该代码暂不支持在Windows平台上的编译。但在Win10及以上的系统中,可以通过安装WSL(Windows的Linux子系统)来进行 32 | 开发和构建。WSL请选择Ubuntu子系统(推荐Ubuntu20及以上)。如果你使用Clion作为IDE,可以在Clion中配置WSL从而进行调试,具体请参考 33 | [Clion with WSL](https://blog.jetbrains.com/clion/2018/01/clion-and-linux-toolchain-on-windows-are-now-friends/) 34 | 35 | #### MacOS & Linux & WSL 36 | 基本构建命令 37 | ```bash 38 | mkdir build 39 | cd build 40 | cmake .. 41 | make -j 42 | ``` 43 | 若不涉及到`CMakeLists`相关文件的变动且没有新增或删除`.cpp`代码(通俗来说,就是只是对现有代码做了修改) 44 | 则无需重新执行`cmake..`命令,直接执行`make -j`编译即可。 45 | 46 | 默认以`debug`模式进行编译,如果你需要使用`release`模式进行编译: 47 | ```bash 48 | cmake -DCMAKE_BUILD_TYPE=Release .. 49 | ``` 50 | 51 | ### 测试 52 | 在构建后,默认会在`build/test`目录下生成`minisql_test`的可执行文件,通过`./minisql_test`即可运行所有测试。 53 | 54 | 如果需要运行单个测试,例如,想要运行`lru_replacer_test.cpp`对应的测试文件,可以通过`make lru_replacer_test` 55 | 命令进行构建。 56 | -------------------------------------------------------------------------------- /clean.sh: -------------------------------------------------------------------------------- 1 | rm -rf build 2 | mkdir build 3 | -------------------------------------------------------------------------------- /reports/MiniSQLReport.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QAQdev/mini-sql-engine/5bb8cbe07d1c1b9a27279d77136d092011672489/reports/MiniSQLReport.pdf -------------------------------------------------------------------------------- /reports/lab1/bitmap_test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QAQdev/mini-sql-engine/5bb8cbe07d1c1b9a27279d77136d092011672489/reports/lab1/bitmap_test.png -------------------------------------------------------------------------------- /reports/lab1/buffer_pool_test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QAQdev/mini-sql-engine/5bb8cbe07d1c1b9a27279d77136d092011672489/reports/lab1/buffer_pool_test.png -------------------------------------------------------------------------------- /reports/lab1/clock_test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QAQdev/mini-sql-engine/5bb8cbe07d1c1b9a27279d77136d092011672489/reports/lab1/clock_test.png -------------------------------------------------------------------------------- /reports/lab1/disk_manager_test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QAQdev/mini-sql-engine/5bb8cbe07d1c1b9a27279d77136d092011672489/reports/lab1/disk_manager_test.png -------------------------------------------------------------------------------- /reports/lab1/lab1_report.md: -------------------------------------------------------------------------------- 1 | # Report on MiniSQL Lab1 2 | 3 | Author: 程政淋 4 | 5 | Student ID: 3200105708 6 | 7 | ## Lab1 Overview 8 | 9 | 实验1主要包括了四个部分,分别是: 10 | - 位图的实现 11 | - 磁盘管理的实现 12 | - 缓冲池替换策略的实现 13 | - LRU 替换策略 14 | - Clock 替换策略 15 | - 缓冲池的实现 16 | 17 | ## Bitmap 的实现 18 | 每一个位图页由两部分组成,第一部分是元信息,包含已分配的页 `page_allocated` 和下一个空闲页 `next_free_page_`,第二部分是一串 bit 来标记页的分配与否,1代表分配,0代表不分配。实现上采用 `std::bitset<>` 来管理数据页。测试样例结果如下: 19 | 20 | ![](bitmap_test.png) 21 | 22 | ### 📌 Notice 23 | 24 | 此处本来打算更新元信息 `next_free_page_` ,这样在后续磁盘管理从位图中分配数据页时不用逐个查找空闲页( $O(n)$ ),而是可以直接返回空闲页。我计划找到一串 bit 中的第一个0,算法如下: 25 | 26 | 把一串 bit 记作 data,这里以1110 1011为例: 27 | 28 | 1. ~data: 0001 0100,取反后问题转化为找到第一个1 29 | 2. data - 1: 0001 0011 30 | 3. ~(data - 1): 1110 1100 31 | 4. (data - 1)&(~(data - 1)): 0001 0000 32 | 33 | 然后可以将其以整数形式取对数得到是第五个位置上出现 0 ,但我们的问题中的 bit 流有4032位,不可能直接转化为整数,并且 `std::bitset` 并没有相应的无符号加法和减法,因此这个方法也就作罢。 34 | 35 | ## 磁盘数据页管理 36 | 37 | 这一部分首先要明白我们的做法是对于整个磁盘,我们有一个 `PAGE_SIZE` 大小的元信息页来管理磁盘数据信息,包含了已分配的位图页和已分配的页的数量,大小为两个 `uint_32t` ,剩下的空间用来记录每一个位图页已分配的页的数量,其次是前面的位图页用于管理一段连续的数据页,依次类推。 38 | 39 | 从测试代码中我发现了 `DiskFileMetaPage` 这个专门用于管理磁盘元信息的类,于是在从磁盘中分配一页时,我的做法是: 40 | 41 | 1. 首先从 `extent_nums` 中获得第一个没有分配满的位图页。 42 | - 如果没有找到而且当前位图页数量已经达到最大可分配数量,返回 `INVALID_PAGE_ID`。 43 | - 如果没有找到但位图页小于最大数量,分配新的一页,更新分区数量和已分配页数量等元信息,然后调用 `WritePhysicalPage` 写回磁盘并返回分配的页号。 44 | 2. 找到没有分配满的位图页,找到该位图页中第一个空闲页并分配,更新元信息,调用 `WritePhysicalPage` 写回磁盘并返回分配的页号(这里就是线性查找可以优化的地方,但是失败了)。 45 | 46 | 在释放一页时,做法则基本相反: 47 | 48 | 找到 `logical_page_id` 所在的分区,调用 `ReadPhysicalPage` 读取当前分区的数据,更新元数据,释放对应数据页,再调用 `WritePhysicalPage` 写回磁盘。 49 | 50 | 测试结果如下: 51 | 52 | ![](disk_manager_test.png) 53 | 54 | ## 缓冲区替换策略 55 | 56 | ### LRU 替换策略 57 | 58 | LRU 替换策略是最近最少访问者被替换,我的实现方式是用一个链表记录 `frame_id` ,用哈希表记录 `frame_id` 在链表中的位置。效果类似于一个队列,每次 `Unpin` 时,从链表末尾加入,每次寻找 Victim 时,则从链表头取出。 59 | 60 | 测试结果如下: 61 | 62 | ![](lru_test.png) 63 | 64 | ### **Bonus: Clock 替换策略** 65 | 66 | Clock 替换策略是一种较为开销较低的替换策略,通过给予每个数据页“第二次机会”来实现页面的替换。对每个数据页来说,一共设置两种状态,`ACCESSED` 和 `UNUSED` ,对于初次加入 Clock Replacer 的页面,设置为 `ACCESSED` ,在寻找待替换页面时,先遍历一遍 Replacer ,将 `ACCESSED` 设置为 `UNUSED` ,同时将待替换的页面设置为第一个遇到的 `UNUSED` 页面。 67 | 68 | 测试结果如下: 69 | 70 | ![](clock_test.png) 71 | 72 | ## 缓冲池管理 73 | 74 | 这个部分集成了前面全部模块,基于代码中注释的提示,以 `FetchPage` 为例,我的做法是: 75 | 76 | 1. 在 `page_table_` 中搜寻页号。 77 | 2. 若存在则直接返回。 78 | 3. 若不存在则先从 `free_list_` 中查找,在 `free_list_` 中仍不存在的(缓冲池已满)再使用 LRU 策略进行替换,若没有找到可替换对象,返回空值。 79 | 4. 从 `page_table_` 中删除待替换帧(步骤3中找到的),插入新的帧,调用 `ReadPage` 返回该帧的数据信息。 80 | 81 | 注意该模块的 `FlushPage` 函数的作用是将数据进行磁盘中的回写来删除其 `IsDirty` 标志。 82 | 83 | 总的来说,该模块的主要工作是实现缓冲池的I/O操作。 84 | 85 | 测试结果如下: 86 | 87 | ![](buffer_pool_test.png) -------------------------------------------------------------------------------- /reports/lab1/lab1_report.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QAQdev/mini-sql-engine/5bb8cbe07d1c1b9a27279d77136d092011672489/reports/lab1/lab1_report.pdf -------------------------------------------------------------------------------- /reports/lab1/lru_test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QAQdev/mini-sql-engine/5bb8cbe07d1c1b9a27279d77136d092011672489/reports/lab1/lru_test.png -------------------------------------------------------------------------------- /reports/lab2/lab2_report.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QAQdev/mini-sql-engine/5bb8cbe07d1c1b9a27279d77136d092011672489/reports/lab2/lab2_report.pdf -------------------------------------------------------------------------------- /reports/lab2/perf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QAQdev/mini-sql-engine/5bb8cbe07d1c1b9a27279d77136d092011672489/reports/lab2/perf.png -------------------------------------------------------------------------------- /reports/lab2/table_heap_test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QAQdev/mini-sql-engine/5bb8cbe07d1c1b9a27279d77136d092011672489/reports/lab2/table_heap_test.png -------------------------------------------------------------------------------- /reports/lab2/tuple_test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QAQdev/mini-sql-engine/5bb8cbe07d1c1b9a27279d77136d092011672489/reports/lab2/tuple_test.png -------------------------------------------------------------------------------- /reports/lab3/B+树正确性.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QAQdev/mini-sql-engine/5bb8cbe07d1c1b9a27279d77136d092011672489/reports/lab3/B+树正确性.png -------------------------------------------------------------------------------- /reports/lab3/B+树索引正确性.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QAQdev/mini-sql-engine/5bb8cbe07d1c1b9a27279d77136d092011672489/reports/lab3/B+树索引正确性.png -------------------------------------------------------------------------------- /reports/lab3/增大数据量.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QAQdev/mini-sql-engine/5bb8cbe07d1c1b9a27279d77136d092011672489/reports/lab3/增大数据量.png -------------------------------------------------------------------------------- /reports/lab3/增大正确.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QAQdev/mini-sql-engine/5bb8cbe07d1c1b9a27279d77136d092011672489/reports/lab3/增大正确.png -------------------------------------------------------------------------------- /reports/lab3/迭代器正确性.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QAQdev/mini-sql-engine/5bb8cbe07d1c1b9a27279d77136d092011672489/reports/lab3/迭代器正确性.png -------------------------------------------------------------------------------- /reports/lab3/黄政-3200100836-实验6(3).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QAQdev/mini-sql-engine/5bb8cbe07d1c1b9a27279d77136d092011672489/reports/lab3/黄政-3200100836-实验6(3).pdf -------------------------------------------------------------------------------- /reports/lab4/lab4.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QAQdev/mini-sql-engine/5bb8cbe07d1c1b9a27279d77136d092011672489/reports/lab4/lab4.pdf -------------------------------------------------------------------------------- /reports/lab5/全选.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QAQdev/mini-sql-engine/5bb8cbe07d1c1b9a27279d77136d092011672489/reports/lab5/全选.png -------------------------------------------------------------------------------- /reports/lab5/全部删除.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QAQdev/mini-sql-engine/5bb8cbe07d1c1b9a27279d77136d092011672489/reports/lab5/全部删除.png -------------------------------------------------------------------------------- /reports/lab5/删除操作.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QAQdev/mini-sql-engine/5bb8cbe07d1c1b9a27279d77136d092011672489/reports/lab5/删除操作.png -------------------------------------------------------------------------------- /reports/lab5/删除索引前后.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QAQdev/mini-sql-engine/5bb8cbe07d1c1b9a27279d77136d092011672489/reports/lab5/删除索引前后.png -------------------------------------------------------------------------------- /reports/lab5/前四个1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QAQdev/mini-sql-engine/5bb8cbe07d1c1b9a27279d77136d092011672489/reports/lab5/前四个1.png -------------------------------------------------------------------------------- /reports/lab5/前四个2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QAQdev/mini-sql-engine/5bb8cbe07d1c1b9a27279d77136d092011672489/reports/lab5/前四个2.png -------------------------------------------------------------------------------- /reports/lab5/建立索引前后.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QAQdev/mini-sql-engine/5bb8cbe07d1c1b9a27279d77136d092011672489/reports/lab5/建立索引前后.png -------------------------------------------------------------------------------- /reports/lab5/建立索引前选择时间.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QAQdev/mini-sql-engine/5bb8cbe07d1c1b9a27279d77136d092011672489/reports/lab5/建立索引前选择时间.png -------------------------------------------------------------------------------- /reports/lab5/执行建库和建表.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QAQdev/mini-sql-engine/5bb8cbe07d1c1b9a27279d77136d092011672489/reports/lab5/执行建库和建表.png -------------------------------------------------------------------------------- /reports/lab5/执行插入.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QAQdev/mini-sql-engine/5bb8cbe07d1c1b9a27279d77136d092011672489/reports/lab5/执行插入.png -------------------------------------------------------------------------------- /reports/lab5/执行插入结果.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QAQdev/mini-sql-engine/5bb8cbe07d1c1b9a27279d77136d092011672489/reports/lab5/执行插入结果.png -------------------------------------------------------------------------------- /reports/lab5/插入时间.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QAQdev/mini-sql-engine/5bb8cbe07d1c1b9a27279d77136d092011672489/reports/lab5/插入时间.png -------------------------------------------------------------------------------- /reports/lab5/语法树.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QAQdev/mini-sql-engine/5bb8cbe07d1c1b9a27279d77136d092011672489/reports/lab5/语法树.png -------------------------------------------------------------------------------- /reports/lab5/选择结果.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QAQdev/mini-sql-engine/5bb8cbe07d1c1b9a27279d77136d092011672489/reports/lab5/选择结果.png -------------------------------------------------------------------------------- /reports/lab5/重启后数据保留.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QAQdev/mini-sql-engine/5bb8cbe07d1c1b9a27279d77136d092011672489/reports/lab5/重启后数据保留.png -------------------------------------------------------------------------------- /reports/lab5/重启后数据都在.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QAQdev/mini-sql-engine/5bb8cbe07d1c1b9a27279d77136d092011672489/reports/lab5/重启后数据都在.png -------------------------------------------------------------------------------- /reports/lab5/黄政-3200100836-实验6(5).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QAQdev/mini-sql-engine/5bb8cbe07d1c1b9a27279d77136d092011672489/reports/lab5/黄政-3200100836-实验6(5).pdf -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # recursive files 2 | FILE(GLOB_RECURSE MINISQL_SOURCE ${PROJECT_SOURCE_DIR}/src/*/*.cpp 3 | ${PROJECT_SOURCE_DIR}/src/*/*/*.cpp 4 | ${PROJECT_SOURCE_DIR}/src/*/*.c 5 | ${PROJECT_SOURCE_DIR}/src/*/*/*.c 6 | ) 7 | ADD_LIBRARY(minisql_shared SHARED ${MINISQL_SOURCE}) 8 | TARGET_LINK_LIBRARIES(minisql_shared glog) 9 | 10 | ADD_EXECUTABLE(main main.cpp) 11 | TARGET_LINK_LIBRARIES(main glog minisql_shared) -------------------------------------------------------------------------------- /src/buffer/clock_replacer.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by kenshin on 5/2/22. 3 | // 4 | 5 | #include "buffer/clock_replacer.h" 6 | 7 | ClockReplacer::ClockReplacer(size_t num_pages) 8 | :second_chance(num_pages,State::EMPTY), 9 | pointer(0), 10 | capacity(num_pages) {} 11 | 12 | ClockReplacer::~ClockReplacer() { 13 | //do nothing 14 | } 15 | 16 | bool ClockReplacer::Victim(frame_id_t *frame_id) { 17 | size_t nonempty_count = 0, i; 18 | frame_id_t victim_frame_id = 0; 19 | 20 | for (i = 0; i < capacity; i++) { 21 | auto id = (pointer + i) % capacity; 22 | if (second_chance[id] == State::EMPTY) 23 | continue; 24 | else if (second_chance[id] == State::ACCESSED) { 25 | nonempty_count++; 26 | second_chance[id] = State::UNUSED; // second chance reset 27 | } else if (second_chance[id] == State::UNUSED) { 28 | nonempty_count++; 29 | // get the first victim 30 | victim_frame_id = (victim_frame_id != 0) ? victim_frame_id : id; 31 | } 32 | } 33 | 34 | // all empty, return false 35 | if (nonempty_count == 0) { 36 | frame_id = nullptr; 37 | return false; 38 | } 39 | 40 | if (victim_frame_id == 0) { 41 | for (i = 0; i < capacity; i++) { 42 | auto id = (pointer + i) % capacity; 43 | if (second_chance[id] == State::UNUSED) { 44 | victim_frame_id = id; 45 | break; 46 | } 47 | } 48 | } 49 | 50 | second_chance[victim_frame_id] = State::EMPTY; 51 | pointer = victim_frame_id; 52 | *frame_id = victim_frame_id; 53 | 54 | return true; 55 | } 56 | 57 | void ClockReplacer::Pin(frame_id_t frame_id) { 58 | //remove from replacer 59 | second_chance[frame_id % capacity] = State::EMPTY; 60 | } 61 | 62 | void ClockReplacer::Unpin(frame_id_t frame_id) { 63 | //add into replacer 64 | second_chance[frame_id % capacity] = State::ACCESSED; 65 | } 66 | 67 | /** 68 | * @breif count those State != EMPTY 69 | * @return the current size of replacer 70 | */ 71 | 72 | size_t ClockReplacer::Size() { 73 | return count_if(second_chance.begin(), second_chance.end(), IsEmpty); 74 | } 75 | 76 | /** 77 | * @param itr 78 | * @return if *itr != State::EMPTY, return true, otherwise false 79 | */ 80 | 81 | bool ClockReplacer::IsEmpty(ClockReplacer::State& item) { 82 | return item != State::EMPTY; 83 | } -------------------------------------------------------------------------------- /src/buffer/lru_replacer.cpp: -------------------------------------------------------------------------------- 1 | #include "buffer/lru_replacer.h" 2 | 3 | LRUReplacer::LRUReplacer(size_t num_pages) 4 | :capacity(num_pages) { 5 | 6 | } 7 | 8 | LRUReplacer::~LRUReplacer() = default; 9 | 10 | bool LRUReplacer::Victim(frame_id_t *frame_id) { 11 | // return false; 12 | if (visit_lst.empty()) return false; 13 | 14 | auto least = visit_lst.front(); // get header 15 | visit_lst.pop_front(); 16 | 17 | auto least_itr = mapping.find(least); 18 | if (least_itr != mapping.end()) { // found 19 | mapping.erase(least_itr); // out of list 20 | *frame_id = least; 21 | return true; 22 | } 23 | 24 | return false; 25 | } 26 | 27 | void LRUReplacer::Pin(frame_id_t frame_id) { 28 | auto least_itr = mapping.find(frame_id); 29 | if (least_itr != mapping.end()) { 30 | visit_lst.erase(least_itr->second); //remove from lru list 31 | mapping.erase(least_itr); //remove from mapping 32 | } 33 | } 34 | 35 | void LRUReplacer::Unpin(frame_id_t frame_id) { 36 | // do the opposite of Pin() 37 | if (mapping.size() >= capacity) return; 38 | 39 | auto itr = mapping.find(frame_id); 40 | if (itr != mapping.end()) return; 41 | 42 | visit_lst.push_back(frame_id); 43 | mapping.insert(pair::iterator>(frame_id, prev(visit_lst.end(), 1))); 44 | } 45 | 46 | size_t LRUReplacer::Size() { return mapping.size(); } -------------------------------------------------------------------------------- /src/include/buffer/buffer_pool_manager.h: -------------------------------------------------------------------------------- 1 | #ifndef MINISQL_BUFFER_POOL_MANAGER_H 2 | #define MINISQL_BUFFER_POOL_MANAGER_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "buffer/lru_replacer.h" 9 | #include "buffer/clock_replacer.h" 10 | #include "page/page.h" 11 | #include "page/disk_file_meta_page.h" 12 | #include "storage/disk_manager.h" 13 | 14 | using namespace std; 15 | 16 | class BufferPoolManager { 17 | public: 18 | explicit BufferPoolManager(size_t pool_size, DiskManager *disk_manager); 19 | 20 | ~BufferPoolManager(); 21 | 22 | Page *FetchPage(page_id_t page_id); 23 | 24 | bool UnpinPage(page_id_t page_id, bool is_dirty); 25 | 26 | bool FlushPage(page_id_t page_id); 27 | 28 | Page *NewPage(page_id_t &page_id); 29 | 30 | bool DeletePage(page_id_t page_id); 31 | 32 | bool IsPageFree(page_id_t page_id); 33 | 34 | bool CheckAllUnpinned(); 35 | 36 | private: 37 | /** 38 | * Allocate new page (operations like create index/table) For now just keep an increasing counter 39 | */ 40 | page_id_t AllocatePage(); 41 | 42 | /** 43 | * Deallocate page (operations like drop index/table) Need bitmap in header page for tracking pages 44 | */ 45 | void DeallocatePage(page_id_t page_id); 46 | 47 | 48 | private: 49 | size_t pool_size_; // number of pages in buffer pool 50 | Page *pages_; // array of pages 51 | DiskManager *disk_manager_; // pointer to the disk manager. 52 | std::unordered_map page_table_; // to keep track of pages 53 | Replacer *replacer_; // to find an unpinned page for replacement 54 | std::list free_list_; // to find a free page for replacement 55 | recursive_mutex latch_; // to protect shared data structure 56 | }; 57 | 58 | #endif // MINISQL_BUFFER_POOL_MANAGER_H 59 | -------------------------------------------------------------------------------- /src/include/buffer/clock_replacer.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by kenshin on 5/2/22. 3 | // 4 | 5 | #ifndef MINISQL_CLOCK_REPLACER_H 6 | #define MINISQL_CLOCK_REPLACER_H 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include "buffer/replacer.h" 13 | #include "common/config.h" 14 | 15 | using namespace std; 16 | 17 | class ClockReplacer: public Replacer { 18 | private: 19 | /** 20 | * @brief state of the frame 21 | * if pin -> EMPTY 22 | * if unpin -> ACCESSED 23 | * after ACCESSED -> UNUSED 24 | */ 25 | enum class State { EMPTY, ACCESSED, UNUSED }; 26 | 27 | public: 28 | /** 29 | * Create a new ClockReplacer. 30 | * @param num_pages the maximum number of pages the ClockReplacer will be required to store 31 | */ 32 | explicit ClockReplacer(size_t num_pages); 33 | 34 | /** 35 | * Destroys the ClockReplacer. 36 | */ 37 | ~ClockReplacer() override; 38 | 39 | bool Victim(frame_id_t *frame_id) override; 40 | 41 | void Pin(frame_id_t frame_id) override; 42 | 43 | void Unpin(frame_id_t frame_id) override; 44 | 45 | size_t Size() override; 46 | 47 | private: 48 | static bool IsEmpty(ClockReplacer::State &); 49 | 50 | private: 51 | std::vector second_chance; 52 | frame_id_t pointer{0}; 53 | size_t capacity; 54 | }; 55 | 56 | #endif // MINISQL_CLOCK_REPLACER_H 57 | -------------------------------------------------------------------------------- /src/include/buffer/lru_replacer.h: -------------------------------------------------------------------------------- 1 | #ifndef MINISQL_LRU_REPLACER_H 2 | #define MINISQL_LRU_REPLACER_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "buffer/replacer.h" 11 | #include "common/config.h" 12 | 13 | using namespace std; 14 | 15 | /** 16 | * LRUReplacer implements the Least Recently Used replacement policy. 17 | */ 18 | class LRUReplacer : public Replacer { 19 | public: 20 | /** 21 | * Create a new LRUReplacer. 22 | * @param num_pages the maximum number of pages the LRUReplacer will be required to store 23 | */ 24 | explicit LRUReplacer(size_t num_pages); 25 | 26 | /** 27 | * Destroys the LRUReplacer. 28 | */ 29 | ~LRUReplacer() override; 30 | 31 | bool Victim(frame_id_t *frame_id) override; 32 | 33 | void Pin(frame_id_t frame_id) override; 34 | 35 | void Unpin(frame_id_t frame_id) override; 36 | 37 | size_t Size() override; 38 | 39 | private: 40 | // add your own private member variables here 41 | size_t capacity; 42 | list visit_lst; 43 | unordered_map::iterator> mapping; 44 | }; 45 | 46 | #endif // MINISQL_LRU_REPLACER_H 47 | -------------------------------------------------------------------------------- /src/include/buffer/replacer.h: -------------------------------------------------------------------------------- 1 | #ifndef MINISQL_REPLACER_H 2 | #define MINISQL_REPLACER_H 3 | 4 | #include 5 | #include "common/config.h" 6 | 7 | /** 8 | * Replacer is an abstract class that tracks page usage. 9 | */ 10 | class Replacer { 11 | public: 12 | Replacer() = default; 13 | 14 | virtual ~Replacer() = default; 15 | 16 | /** 17 | * Remove the victim frame as defined by the replacement policy. 18 | * @param[out] frame_id id of frame that was removed, nullptr if no victim was found 19 | * @return true if a victim frame was found, false otherwise 20 | */ 21 | virtual bool Victim(frame_id_t *frame_id) = 0; 22 | 23 | /** 24 | * Pins a frame, indicating that it should not be victimized until it is unpinned. 25 | * @param frame_id the id of the frame to pin 26 | */ 27 | virtual void Pin(frame_id_t frame_id) = 0; 28 | 29 | /** 30 | * Unpins a frame, indicating that it can now be victimized. 31 | * @param frame_id the id of the frame to unpin 32 | */ 33 | virtual void Unpin(frame_id_t frame_id) = 0; 34 | 35 | /** @return the number of elements in the replacer that can be victimized */ 36 | virtual size_t Size() = 0; 37 | }; 38 | 39 | #endif // MINISQL_REPLACER_H 40 | -------------------------------------------------------------------------------- /src/include/common/config.h: -------------------------------------------------------------------------------- 1 | #ifndef MINISQL_CONFIG_H 2 | #define MINISQL_CONFIG_H 3 | 4 | #include 5 | #include 6 | 7 | static constexpr int INVALID_PAGE_ID = -1; // invalid page id 8 | static constexpr int INVALID_FRAME_ID = -1; // invalid transaction id 9 | static constexpr int INVALID_TXN_ID = -1; // invalid transaction id 10 | static constexpr int INVALID_LSN = -1; // invalid log sequence number 11 | 12 | static constexpr int META_PAGE_ID = 0; // physical page id of the disk file meta info 13 | static constexpr int CATALOG_META_PAGE_ID = 0; // logical page id of the catalog meta data 14 | static constexpr int INDEX_ROOTS_PAGE_ID = 1; // logical page id of the index roots 15 | 16 | static constexpr int PAGE_SIZE = 4096; // size of a data page in byte 17 | static constexpr int DEFAULT_BUFFER_POOL_SIZE = 4096;// default size of buffer pool 18 | 19 | static constexpr uint32_t FIELD_NULL_LEN = UINT32_MAX; 20 | static constexpr uint32_t VARCHAR_MAX_LEN = PAGE_SIZE / 2; // max length of varchar 21 | 22 | // static std::string DB_META_FILE = "minisql.meta.db"; 23 | 24 | using page_id_t = int32_t; 25 | using frame_id_t = int32_t; 26 | using txn_id_t = int32_t; 27 | using lsn_t = int32_t; 28 | using column_id_t = uint32_t; 29 | using index_id_t = uint32_t; 30 | using table_id_t = uint32_t; 31 | 32 | #endif // MINISQL_CONFIG_H 33 | -------------------------------------------------------------------------------- /src/include/common/dberr.h: -------------------------------------------------------------------------------- 1 | #ifndef MINISQL_DBERR_H 2 | #define MINISQL_DBERR_H 3 | 4 | enum dberr_t { 5 | DB_SUCCESS = 0, 6 | DB_FAILED, 7 | DB_TABLE_ALREADY_EXIST, 8 | DB_TABLE_NOT_EXIST, 9 | DB_INDEX_ALREADY_EXIST, 10 | DB_INDEX_NOT_FOUND, 11 | DB_COLUMN_NAME_NOT_EXIST, 12 | DB_KEY_NOT_FOUND, 13 | }; 14 | 15 | #endif //MINISQL_DBERR_H 16 | -------------------------------------------------------------------------------- /src/include/common/instance.h: -------------------------------------------------------------------------------- 1 | #ifndef MINISQL_INSTANCE_H 2 | #define MINISQL_INSTANCE_H 3 | 4 | #include 5 | #include 6 | 7 | #include "buffer/buffer_pool_manager.h" 8 | #include "catalog/catalog.h" 9 | #include "common/config.h" 10 | #include "common/dberr.h" 11 | #include "storage/disk_manager.h" 12 | 13 | class DBStorageEngine { 14 | public: 15 | explicit DBStorageEngine(std::string db_name, bool init = true, uint32_t buffer_pool_size = DEFAULT_BUFFER_POOL_SIZE) 16 | : db_file_name_(std::move(db_name)), init_(init) { 17 | // Init database file if needed 18 | if (init_) { 19 | remove(db_file_name_.c_str()); 20 | } 21 | // Initialize components 22 | disk_mgr_ = new DiskManager(db_file_name_); 23 | bpm_ = new BufferPoolManager(buffer_pool_size, disk_mgr_); 24 | catalog_mgr_ = new CatalogManager(bpm_, nullptr, nullptr, init); 25 | // Allocate static page for db storage engine 26 | if (init) { 27 | page_id_t id; 28 | ASSERT(bpm_->IsPageFree(CATALOG_META_PAGE_ID), "Catalog meta page not free."); 29 | ASSERT(bpm_->IsPageFree(INDEX_ROOTS_PAGE_ID), "Header page not free."); 30 | ASSERT(bpm_->NewPage(id) != nullptr && id == CATALOG_META_PAGE_ID, "Failed to allocate catalog meta page."); 31 | ASSERT(bpm_->NewPage(id) != nullptr && id == INDEX_ROOTS_PAGE_ID, "Failed to allocate header page."); 32 | 33 | bpm_->UnpinPage(CATALOG_META_PAGE_ID, false); 34 | bpm_->UnpinPage(INDEX_ROOTS_PAGE_ID, false); 35 | } else { 36 | ASSERT(!bpm_->IsPageFree(CATALOG_META_PAGE_ID), "Invalid catalog meta page."); 37 | ASSERT(!bpm_->IsPageFree(INDEX_ROOTS_PAGE_ID), "Invalid header page."); 38 | } 39 | } 40 | 41 | ~DBStorageEngine() { 42 | delete catalog_mgr_; 43 | delete bpm_; 44 | delete disk_mgr_; 45 | } 46 | 47 | public: 48 | DiskManager *disk_mgr_; 49 | BufferPoolManager *bpm_; 50 | CatalogManager *catalog_mgr_; 51 | std::string db_file_name_; 52 | bool init_; 53 | }; 54 | 55 | #endif //MINISQL_INSTANCE_H 56 | -------------------------------------------------------------------------------- /src/include/common/macros.h: -------------------------------------------------------------------------------- 1 | #ifndef MINISQL_MACROS_H 2 | #define MINISQL_MACROS_H 3 | 4 | #include 5 | 6 | #define ASSERT(expr, message) assert((expr) && (message)) 7 | 8 | // Macros to disable copying and moving 9 | #define DISALLOW_COPY(cname) \ 10 | cname(const cname &) = delete; /* NOLINT */ \ 11 | cname &operator=(const cname &) = delete; /* NOLINT */ 12 | 13 | #define DISALLOW_MOVE(cname) \ 14 | cname(cname &&) = delete; /* NOLINT */ \ 15 | cname &operator=(cname &&) = delete; /* NOLINT */ 16 | 17 | #define DISALLOW_COPY_AND_MOVE(cname) \ 18 | DISALLOW_COPY(cname); \ 19 | DISALLOW_MOVE(cname); 20 | 21 | #define MACH_WRITE_TO(Type, Buf, Data) \ 22 | do { \ 23 | *reinterpret_cast(Buf) = (Data); \ 24 | } while (0) 25 | #define MACH_WRITE_UINT32(Buf, Data) MACH_WRITE_TO(uint32_t, (Buf), (Data)) 26 | #define MACH_WRITE_INT32(Buf, Data) MACH_WRITE_TO(int32_t, (Buf), (Data)) 27 | #define MACH_WRITE_STRING(Buf, Str) \ 28 | do { \ 29 | memcpy(Buf, Str.c_str(), Str.length()); \ 30 | } while (0) 31 | 32 | #define MACH_READ_FROM(Type, Buf) (*reinterpret_cast(Buf)) 33 | #define MACH_READ_UINT32(Buf) MACH_READ_FROM(uint32_t, (Buf)) 34 | #define MACH_READ_INT32(Buf) MACH_READ_FROM(int32_t, (Buf)) 35 | 36 | #define MACH_STR_SERIALIZED_SIZE(Str) (4 + Str.length()) 37 | 38 | #define ALLOC(Heap, Type) new(Heap.Allocate(sizeof(Type)))Type 39 | #define ALLOC_P(Heap, Type) new(Heap->Allocate(sizeof(Type)))Type 40 | #define ALLOC_COLUMN(Heap) ALLOC(Heap, Column) 41 | 42 | 43 | #endif // MINISQL_MACROS_H 44 | -------------------------------------------------------------------------------- /src/include/common/rowid.h: -------------------------------------------------------------------------------- 1 | #ifndef MINISQL_RID_H 2 | #define MINISQL_RID_H 3 | 4 | #include 5 | #include "common/config.h" 6 | 7 | /** 8 | * | page_id(32bit) | slot_num(32bit) | 9 | */ 10 | class RowId { 11 | public: 12 | RowId() = default; 13 | 14 | RowId(page_id_t page_id, uint32_t slot_num) : page_id_(page_id), slot_num_(slot_num) {} 15 | 16 | explicit RowId(int64_t rid) 17 | : page_id_(static_cast(rid >> 32)), 18 | slot_num_(static_cast(rid)) {} 19 | 20 | inline int64_t Get() const { 21 | return (static_cast(page_id_)) << 32 | slot_num_; 22 | } 23 | 24 | inline page_id_t GetPageId() const { return page_id_; } 25 | 26 | inline uint32_t GetSlotNum() const { return slot_num_; } 27 | 28 | inline void Set(page_id_t page_id, uint32_t slot_num) { 29 | page_id_ = page_id; 30 | slot_num_ = slot_num; 31 | } 32 | 33 | bool operator==(const RowId &other) const { 34 | return page_id_ == other.page_id_ && slot_num_ == other.slot_num_; 35 | } 36 | 37 | private: 38 | page_id_t page_id_{INVALID_PAGE_ID}; 39 | uint32_t slot_num_{0}; // logical offset of the record in page, starts from 0. eg:0, 1, 2... 40 | }; 41 | 42 | static const RowId INVALID_ROWID = RowId(INVALID_PAGE_ID, 0); 43 | 44 | #endif //MINISQL_RID_H 45 | -------------------------------------------------------------------------------- /src/include/common/rwlatch.h: -------------------------------------------------------------------------------- 1 | #ifndef MINISQL_RWLATCH_H 2 | #define MINISQL_RWLATCH_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include "macros.h" 8 | 9 | 10 | /** 11 | * Reader-Writer latch backed by std::mutex. 12 | */ 13 | class ReaderWriterLatch { 14 | using mutex_t = std::mutex; 15 | using cond_t = std::condition_variable; 16 | static const uint32_t MAX_READERS = UINT_MAX; 17 | 18 | public: 19 | ReaderWriterLatch() = default; 20 | 21 | ~ReaderWriterLatch() { std::lock_guard guard(mutex_); } 22 | 23 | DISALLOW_COPY(ReaderWriterLatch); 24 | 25 | /** 26 | * Acquire a write latch. 27 | */ 28 | void WLock() { 29 | std::unique_lock latch(mutex_); 30 | while (writer_entered_) { 31 | reader_.wait(latch); 32 | } 33 | writer_entered_ = true; 34 | while (reader_count_ > 0) { 35 | writer_.wait(latch); 36 | } 37 | } 38 | 39 | /** 40 | * Release a write latch. 41 | */ 42 | void WUnlock() { 43 | std::lock_guard guard(mutex_); 44 | writer_entered_ = false; 45 | reader_.notify_all(); 46 | } 47 | 48 | /** 49 | * Acquire a read latch. 50 | */ 51 | void RLock() { 52 | std::unique_lock latch(mutex_); 53 | while (writer_entered_ || reader_count_ == MAX_READERS) { 54 | reader_.wait(latch); 55 | } 56 | reader_count_++; 57 | } 58 | 59 | /** 60 | * Release a read latch. 61 | */ 62 | void RUnlock() { 63 | std::lock_guard guard(mutex_); 64 | reader_count_--; 65 | if (reader_count_ == MAX_READERS) { 66 | ASSERT(false, "RUnlock failed."); 67 | reader_count_ = 0; 68 | } 69 | if (writer_entered_) { 70 | if (reader_count_ == 0) { 71 | writer_.notify_one(); 72 | } 73 | } else { 74 | if (reader_count_ == MAX_READERS - 1) { 75 | reader_.notify_one(); 76 | } 77 | } 78 | } 79 | 80 | private: 81 | mutex_t mutex_; 82 | cond_t writer_; 83 | cond_t reader_; 84 | uint32_t reader_count_{0}; 85 | bool writer_entered_{false}; 86 | }; 87 | 88 | #endif // MINISQL_RWLATCH_H 89 | -------------------------------------------------------------------------------- /src/include/index/b_plus_tree_index.h: -------------------------------------------------------------------------------- 1 | #ifndef MINISQL_B_PLUS_TREE_INDEX_H 2 | #define MINISQL_B_PLUS_TREE_INDEX_H 3 | 4 | #include "index/b_plus_tree.h" 5 | #include "index/index.h" 6 | 7 | #define BPLUSTREE_INDEX_TYPE BPlusTreeIndex 8 | 9 | INDEX_TEMPLATE_ARGUMENTS 10 | class BPlusTreeIndex : public Index { 11 | public: 12 | BPlusTreeIndex(index_id_t index_id, IndexSchema *key_schema, 13 | BufferPoolManager *buffer_pool_manager); 14 | 15 | dberr_t InsertEntry(const Row &key, RowId row_id, Transaction *txn) override; 16 | 17 | dberr_t RemoveEntry(const Row &key, RowId row_id, Transaction *txn) override; 18 | 19 | dberr_t ScanKey(const Row &key, std::vector &result, Transaction *txn) override; 20 | 21 | dberr_t Destroy() override; 22 | 23 | INDEXITERATOR_TYPE GetBeginIterator(); 24 | 25 | INDEXITERATOR_TYPE GetBeginIterator(const KeyType &key); 26 | 27 | INDEXITERATOR_TYPE GetEndIterator(); 28 | 29 | protected: 30 | // comparator for key 31 | KeyComparator comparator_; 32 | // container 33 | BPLUSTREE_TYPE container_; 34 | }; 35 | 36 | #endif //MINISQL_B_PLUS_TREE_INDEX_H 37 | -------------------------------------------------------------------------------- /src/include/index/basic_comparator.h: -------------------------------------------------------------------------------- 1 | #ifndef MINISQL_BASIC_COMPARATOR_H 2 | #define MINISQL_BASIC_COMPARATOR_H 3 | 4 | template 5 | class BasicComparator { 6 | public: 7 | inline int operator()(const T &l, const T &r) const { 8 | if (l < r) { 9 | return -1; 10 | } else if (l > r) { 11 | return 1; 12 | } 13 | return 0; 14 | } 15 | }; 16 | 17 | #endif // MINISQL_BASIC_COMPARATOR_H 18 | -------------------------------------------------------------------------------- /src/include/index/index.h: -------------------------------------------------------------------------------- 1 | #ifndef MINISQL_INDEX_H 2 | #define MINISQL_INDEX_H 3 | 4 | #include 5 | 6 | #include "common/dberr.h" 7 | #include "record/row.h" 8 | #include "transaction/transaction.h" 9 | 10 | class Index { 11 | public: 12 | explicit Index(index_id_t index_id, IndexSchema *key_schema) 13 | : index_id_(index_id), key_schema_(key_schema) {} 14 | 15 | virtual ~Index() {} 16 | 17 | virtual dberr_t InsertEntry(const Row &key, RowId row_id, Transaction *txn) = 0; 18 | 19 | virtual dberr_t RemoveEntry(const Row &key, RowId row_id, Transaction *txn) = 0; 20 | 21 | virtual dberr_t ScanKey(const Row &key, std::vector &result, Transaction *txn) = 0; 22 | 23 | virtual dberr_t Destroy() = 0; 24 | 25 | protected: 26 | index_id_t index_id_; 27 | IndexSchema *key_schema_; 28 | }; 29 | 30 | #endif //MINISQL_INDEX_H 31 | -------------------------------------------------------------------------------- /src/include/index/index_iterator.h: -------------------------------------------------------------------------------- 1 | #ifndef MINISQL_INDEX_ITERATOR_H 2 | #define MINISQL_INDEX_ITERATOR_H 3 | 4 | #include "page/b_plus_tree_leaf_page.h" 5 | 6 | #define INDEXITERATOR_TYPE IndexIterator 7 | 8 | INDEX_TEMPLATE_ARGUMENTS 9 | class IndexIterator 10 | { 11 | using LeafPage = BPlusTreeLeafPage; 12 | public: 13 | // you may define your own constructor based on your member variables 14 | // explicit IndexIterator(); 15 | IndexIterator(BufferPoolManager *buffer_pool_manager, 16 | Page *page, int index); 17 | 18 | ~IndexIterator(); 19 | 20 | /** Return the key/value pair this iterator is currently pointing at. */ 21 | const MappingType &operator*(); 22 | 23 | /** Move to the next key/value pair.*/ 24 | IndexIterator &operator++(); 25 | 26 | /** Return whether two iterators are equal */ 27 | bool operator==(const IndexIterator &itr) const; 28 | 29 | /** Return whether two iterators are not equal. */ 30 | bool operator!=(const IndexIterator &itr) const; 31 | 32 | private: 33 | // add your own private member variables here 34 | BufferPoolManager* buffer_pool_manager_; 35 | Page* page_; 36 | LeafPage* leaf_page_; 37 | int index_ = 0; 38 | }; 39 | 40 | 41 | #endif //MINISQL_INDEX_ITERATOR_H 42 | -------------------------------------------------------------------------------- /src/include/page/b_plus_tree_page.h: -------------------------------------------------------------------------------- 1 | #ifndef MINISQL_B_PLUS_TREE_PAGE_H 2 | #define MINISQL_B_PLUS_TREE_PAGE_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "buffer/buffer_pool_manager.h" 9 | 10 | #define MappingType std::pair 11 | 12 | #define INDEX_TEMPLATE_ARGUMENTS template 13 | 14 | // define page type enum 15 | enum class IndexPageType { 16 | INVALID_INDEX_PAGE = 0, LEAF_PAGE, INTERNAL_PAGE 17 | }; 18 | 19 | /** 20 | * Both internal and leaf page are inherited from this page. 21 | * 22 | * It actually serves as a header part for each B+ tree page and 23 | * contains information shared by both leaf page and internal page. 24 | * 25 | * Header format (size in byte, 24 bytes in total): 26 | * ---------------------------------------------------------------------------- 27 | * | PageType (4) | LSN (4) | CurrentSize (4) | MaxSize (4) | 28 | * ---------------------------------------------------------------------------- 29 | * | ParentPageId (4) | PageId(4) | 30 | * ---------------------------------------------------------------------------- 31 | */ 32 | class BPlusTreePage { 33 | public: 34 | bool IsLeafPage() const; 35 | 36 | bool IsRootPage() const; 37 | 38 | void SetPageType(IndexPageType page_type); 39 | 40 | int GetSize() const; 41 | 42 | void SetSize(int size); 43 | 44 | void IncreaseSize(int amount); 45 | 46 | int GetMaxSize() const; 47 | 48 | void SetMaxSize(int max_size); 49 | 50 | int GetMinSize() const; 51 | 52 | page_id_t GetParentPageId() const; 53 | 54 | void SetParentPageId(page_id_t parent_page_id); 55 | 56 | page_id_t GetPageId() const; 57 | 58 | void SetPageId(page_id_t page_id); 59 | 60 | void SetLSN(lsn_t lsn = INVALID_LSN); 61 | 62 | private: 63 | // member variable, attributes that both internal and leaf page share 64 | [[maybe_unused]] IndexPageType page_type_; 65 | [[maybe_unused]] lsn_t lsn_; 66 | [[maybe_unused]] int size_; 67 | [[maybe_unused]] int max_size_; 68 | [[maybe_unused]] page_id_t parent_page_id_; 69 | [[maybe_unused]] page_id_t page_id_; 70 | }; 71 | 72 | #endif // MINISQL_B_PLUS_TREE_PAGE_H 73 | -------------------------------------------------------------------------------- /src/include/page/bitmap_page.h: -------------------------------------------------------------------------------- 1 | #ifndef MINISQL_BITMAP_PAGE_H 2 | #define MINISQL_BITMAP_PAGE_H 3 | 4 | #include 5 | 6 | #include "common/macros.h" 7 | #include "common/config.h" 8 | 9 | template 10 | class BitmapPage { 11 | public: 12 | /** 13 | * @return The number of pages that the bitmap page can record, i.e. the capacity of an extent. 14 | */ 15 | static constexpr size_t GetMaxSupportedSize() { return 8 * MAX_CHARS; } 16 | 17 | /** 18 | * @param page_offset Index in extent of the page allocated. 19 | * @return true if successfully allocate a page. 20 | */ 21 | bool AllocatePage(uint32_t &page_offset); 22 | 23 | /** 24 | * @return true if successfully de-allocate a page. 25 | */ 26 | bool DeAllocatePage(uint32_t page_offset); 27 | 28 | /** 29 | * @return whether a page in the extent is free 30 | */ 31 | bool IsPageFree(uint32_t page_offset) const; 32 | 33 | /** 34 | * @return whether a bitmap is full 35 | */ 36 | bool IsBitmapFull(); 37 | 38 | private: 39 | /** 40 | * @brief check a bit(byte_index, bit_index) in bytes is free(value 0). 41 | * 42 | * @param byte_index value of page_offset / 8 43 | * @param bit_index value of page_offset % 8 44 | * @return true if a bit is 0, false if 1. 45 | */ 46 | bool IsPageFreeLow(uint32_t byte_index, uint8_t bit_index) const; 47 | 48 | /** Note: need to update if modify page structure. */ 49 | static constexpr size_t MAX_CHARS = PageSize - 2 * sizeof(uint32_t); 50 | 51 | private: 52 | /** The space occupied by all members of the class should be equal to the PageSize */ 53 | [[maybe_unused]] uint32_t page_allocated_{0}; 54 | 55 | public: 56 | [[maybe_unused]] uint32_t next_free_page_{0}; 57 | 58 | private: 59 | std::bitset<8 * MAX_CHARS> allocate_pages; 60 | //[[maybe_unused]] unsigned char bytes[MAX_CHARS]{}; 61 | }; 62 | 63 | #endif //MINISQL_BITMAP_PAGE_H 64 | -------------------------------------------------------------------------------- /src/include/page/disk_file_meta_page.h: -------------------------------------------------------------------------------- 1 | #ifndef MINISQL_DISK_FILE_META_PAGE_H 2 | #define MINISQL_DISK_FILE_META_PAGE_H 3 | 4 | #include 5 | 6 | #include "page/bitmap_page.h" 7 | 8 | static constexpr page_id_t MAX_VALID_PAGE_ID = (PAGE_SIZE - 8) / 4 * BitmapPage::GetMaxSupportedSize(); 9 | 10 | class DiskFileMetaPage { 11 | public: 12 | uint32_t GetExtentNums() { 13 | return num_extents_; 14 | } 15 | 16 | uint32_t GetAllocatedPages() { 17 | return num_allocated_pages_; 18 | } 19 | 20 | uint32_t GetExtentUsedPage(uint32_t extent_id) { 21 | if (extent_id >= num_extents_) { 22 | return 0; 23 | } 24 | return extent_used_page_[extent_id]; 25 | } 26 | 27 | public: 28 | uint32_t num_allocated_pages_{0}; 29 | uint32_t num_extents_{0}; // each extent consists with a bit map and BIT_MAP_SIZE pages 30 | uint32_t extent_used_page_[0]; 31 | }; 32 | 33 | #endif //MINISQL_DISK_FILE_META_PAGE_H 34 | -------------------------------------------------------------------------------- /src/include/page/index_roots_page.h: -------------------------------------------------------------------------------- 1 | #ifndef MINISQL_INDEX_ROOTS_PAGE_H 2 | #define MINISQL_INDEX_ROOTS_PAGE_H 3 | 4 | #include 5 | 6 | #include "common/config.h" 7 | 8 | /** 9 | * Database use the one as index roots page page to store all 10 | * index's root page id 11 | * 12 | * Format (size in byte): 13 | * ----------------------------------------------------------------- 14 | * | RecordCount (4) | Index_1 id (4) | Index_1 root_id (4) | ... | 15 | * ----------------------------------------------------------------- 16 | */ 17 | class IndexRootsPage { 18 | public: 19 | void Init() { count_ = 0; } 20 | 21 | bool Insert(const index_id_t index_id, const page_id_t root_id); 22 | 23 | bool Delete(const index_id_t index_id); 24 | 25 | bool Update(const index_id_t index_id, const page_id_t root_id); 26 | 27 | // return root_id if success 28 | bool GetRootId(const index_id_t index_id, page_id_t *root_id); 29 | 30 | int GetIndexCount() { return count_; } 31 | 32 | private: 33 | static constexpr int MAX_INDEX_COUNT = (PAGE_SIZE - 4) / 8; 34 | 35 | int FindIndex(const index_id_t index_id); 36 | 37 | public: 38 | int count_ = 0; 39 | std::pair roots_[0]; 40 | }; 41 | 42 | #endif //MINISQL_INDEX_ROOTS_PAGE_H 43 | -------------------------------------------------------------------------------- /src/include/parser/compile.sh: -------------------------------------------------------------------------------- 1 | lex --header-file=./minisql_lex.h --outfile=../../parser/minisql_lex.c minisql.l \ 2 | && yacc -d -o ./minisql_yacc.c minisql.y \ 3 | && mv minisql_yacc.c ../../parser/minisql_yacc.c -------------------------------------------------------------------------------- /src/include/parser/parser.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by Chengjun Ying on 2022/3/10. 3 | */ 4 | #ifndef MINISQL_PARSER_H 5 | #define MINISQL_PARSER_H 6 | 7 | #include "parser/syntax_tree.h" 8 | 9 | void MinisqlParserMovePos(int line, char *text); 10 | 11 | void MinisqlParserSetRoot(pSyntaxNode node); 12 | 13 | void MinisqlParserSetError(char *msg); 14 | 15 | pSyntaxNode MinisqlGetParserRootNode(); 16 | 17 | void MinisqlParserInit(); 18 | 19 | void MinisqlParserFinish(); 20 | 21 | int MinisqlParserGetError(); 22 | 23 | char *MinisqlParserGetErrorMessage(); 24 | 25 | #endif //MINISQL_PARSER_H 26 | -------------------------------------------------------------------------------- /src/include/parser/syntax_tree_printer.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Chengjun Ying on 2022/4/5. 3 | // 4 | #ifndef MINISQL_SYNTAX_TREE_PRINTER_H 5 | #define MINISQL_SYNTAX_TREE_PRINTER_H 6 | 7 | #include 8 | #include 9 | 10 | extern "C" { 11 | #include "parser/syntax_tree.h" 12 | }; 13 | 14 | class SyntaxTreePrinter { 15 | public: 16 | explicit SyntaxTreePrinter(pSyntaxNode root) : root_(root) {}; 17 | 18 | void PrintTree(std::ofstream &out); 19 | 20 | private: 21 | void PrintTreeLow(pSyntaxNode node, std::ofstream &out); 22 | 23 | private: 24 | pSyntaxNode root_; 25 | }; 26 | 27 | #endif //MINISQL_SYNTAX_TREE_PRINTER_H 28 | -------------------------------------------------------------------------------- /src/include/record/column.h: -------------------------------------------------------------------------------- 1 | #ifndef MINISQL_COLUMN_H 2 | #define MINISQL_COLUMN_H 3 | 4 | #include 5 | 6 | #include "common/macros.h" 7 | #include "record/types.h" 8 | 9 | class Column { 10 | friend class Schema; 11 | 12 | public: 13 | Column(std::string column_name, TypeId type, uint32_t index, bool nullable, bool unique); 14 | 15 | Column(std::string column_name, TypeId type, uint32_t length, uint32_t index, bool nullable, bool unique); 16 | 17 | Column(const Column *other); 18 | 19 | std::string GetName() const { return name_; } 20 | 21 | uint32_t GetLength() const { return len_; } 22 | 23 | void SetTableInd(uint32_t ind) { table_ind_ = ind; } 24 | 25 | uint32_t GetTableInd() const { return table_ind_; } 26 | 27 | bool IsNullable() const { return nullable_; } 28 | 29 | bool IsUnique() const { return unique_; } 30 | 31 | TypeId GetType() const { return type_; } 32 | 33 | uint32_t SerializeTo(char *buf) const; 34 | 35 | uint32_t GetSerializedSize() const; 36 | 37 | static uint32_t DeserializeFrom(char *buf, Column *&column, MemHeap *heap); 38 | 39 | private: 40 | static constexpr uint32_t COLUMN_MAGIC_NUM = 210928; 41 | std::string name_; 42 | TypeId type_; 43 | uint32_t len_{0}; // for char type this is the maximum byte length of the string data, 44 | // otherwise is the fixed size 45 | uint32_t table_ind_{0}; // column position in table 46 | bool nullable_{false}; // whether the column can be null 47 | bool unique_{false}; // whether the column is unique 48 | 49 | }; 50 | 51 | #endif //MINISQL_COLUMN_H 52 | -------------------------------------------------------------------------------- /src/include/record/type_id.h: -------------------------------------------------------------------------------- 1 | #ifndef MINISQL_TYPE_ID_H 2 | #define MINISQL_TYPE_ID_H 3 | 4 | enum TypeId { 5 | kTypeInvalid = 0, 6 | kTypeInt, 7 | kTypeFloat, 8 | kTypeChar, 9 | KMaxTypeId = kTypeChar 10 | }; 11 | 12 | #endif //MINISQL_TYPE_ID_H 13 | -------------------------------------------------------------------------------- /src/include/storage/table_iterator.h: -------------------------------------------------------------------------------- 1 | #ifndef MINISQL_TABLE_ITERATOR_H 2 | #define MINISQL_TABLE_ITERATOR_H 3 | 4 | #include "common/rowid.h" 5 | #include "record/row.h" 6 | #include "transaction/transaction.h" 7 | 8 | 9 | class TableHeap; 10 | 11 | class TableIterator { 12 | private: 13 | explicit TableIterator() = default; 14 | 15 | public: 16 | // you may define your own constructor based on your member variables 17 | 18 | explicit TableIterator(TableHeap *table_heap, RowId rid, Transaction *txn); 19 | 20 | TableIterator(const TableIterator &other); 21 | 22 | virtual ~TableIterator(); 23 | 24 | bool operator==(const TableIterator &itr) const; 25 | 26 | bool operator!=(const TableIterator &itr) const; 27 | 28 | const Row &operator*(); 29 | 30 | Row *operator->(); 31 | 32 | TableIterator &operator++(); 33 | 34 | TableIterator operator++(int); 35 | 36 | private: 37 | // add your own private member variables here 38 | TableHeap *table_heap; 39 | Row *row; 40 | Transaction *txn; // not implemented, but need one 41 | }; 42 | 43 | #endif //MINISQL_TABLE_ITERATOR_H 44 | -------------------------------------------------------------------------------- /src/include/transaction/lock_manager.h: -------------------------------------------------------------------------------- 1 | #ifndef MINISQL_LOCK_MANAGER_H 2 | #define MINISQL_LOCK_MANAGER_H 3 | 4 | /** 5 | * LockManager handles transactions asking for locks on records. 6 | * 7 | * Implemented by student self. 8 | */ 9 | class LockManager { 10 | 11 | }; 12 | 13 | #endif //MINISQL_LOCK_MANAGER_H 14 | -------------------------------------------------------------------------------- /src/include/transaction/log_manager.h: -------------------------------------------------------------------------------- 1 | #ifndef MINISQL_LOG_MANAGER_H 2 | #define MINISQL_LOG_MANAGER_H 3 | 4 | /** 5 | * LogManager maintains a separate thread that is awakened whenever the 6 | * log buffer is full or whenever a timeout happens. 7 | * When the thread is awakened, the log buffer's content is written into the disk log file. 8 | * 9 | * Implemented by student self 10 | */ 11 | class LogManager { 12 | 13 | }; 14 | 15 | #endif //MINISQL_LOG_MANAGER_H 16 | -------------------------------------------------------------------------------- /src/include/transaction/transaction.h: -------------------------------------------------------------------------------- 1 | #ifndef MINISQL_TRANSACTION_H 2 | #define MINISQL_TRANSACTION_H 3 | 4 | /** 5 | * Transaction tracks information related to a transaction. 6 | * 7 | * Implemented by student self 8 | */ 9 | class Transaction 10 | { 11 | 12 | }; 13 | 14 | #endif // MINISQL_TRANSACTION_H 15 | -------------------------------------------------------------------------------- /src/include/utils/mem_heap.h: -------------------------------------------------------------------------------- 1 | #ifndef MINISQL_MEM_HEAP_H 2 | #define MINISQL_MEM_HEAP_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include "common/macros.h" 8 | 9 | class MemHeap { 10 | public: 11 | virtual ~MemHeap() = default; 12 | 13 | /** 14 | * @brief Allocate a contiguous block of memory of the given size 15 | * @param size The size (in bytes) of memory to allocate 16 | * @return A non-null pointer if allocation is successful. A null pointer if 17 | * allocation fails. 18 | */ 19 | virtual void *Allocate(size_t size) = 0; 20 | 21 | /** 22 | * @brief Returns the provided chunk of memory back into the pool 23 | */ 24 | virtual void Free(void *ptr) = 0; 25 | 26 | }; 27 | 28 | class SimpleMemHeap : public MemHeap { 29 | public: 30 | ~SimpleMemHeap() { 31 | for (auto it: allocated_) { 32 | free(it); 33 | } 34 | } 35 | 36 | void *Allocate(size_t size) { 37 | void *buf = malloc(size); 38 | ASSERT(buf != nullptr, "Out of memory exception"); 39 | allocated_.insert(buf); 40 | return buf; 41 | } 42 | 43 | void Free(void *ptr) { 44 | if (ptr == nullptr) { 45 | return; 46 | } 47 | auto iter = allocated_.find(ptr); 48 | if (iter != allocated_.end()) { 49 | allocated_.erase(iter); 50 | } 51 | } 52 | 53 | private: 54 | std::unordered_set allocated_; 55 | }; 56 | 57 | #endif //MINISQL_MEM_HEAP_H 58 | -------------------------------------------------------------------------------- /src/include/utils/tree_file_mgr.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Chengjun Ying on 2022/4/5. 3 | // 4 | #ifndef MINISQL_TREE_FILE_MGR_H 5 | #define MINISQL_TREE_FILE_MGR_H 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | class TreeFileManagers { 13 | public: 14 | explicit TreeFileManagers(std::string file_prefix) : file_prefix_(file_prefix) {}; 15 | 16 | ~TreeFileManagers() { 17 | for (auto e : outs_) { 18 | close_file(e.first); 19 | delete e.second; 20 | } 21 | } 22 | 23 | std::ofstream &operator[](int id) { 24 | if (outs_.find(id) == outs_.end()) { 25 | new_out_stream(id); 26 | } 27 | return *(outs_[id]); 28 | } 29 | 30 | private: 31 | void open_file(std::string file_name, std::ofstream &out) { 32 | remove(file_name.c_str()); 33 | out.open(file_name, std::ios::in | std::ios::out); 34 | if (!out.is_open()) { 35 | out.clear(); 36 | // create a new file 37 | out.open(file_name, std::ios::in | std::ios::trunc | std::ios::out); 38 | out.close(); 39 | // reopen with original mode 40 | out.open(file_name, std::ios::in | std::ios::out); 41 | if (!out.is_open()) { 42 | throw std::exception(); 43 | } 44 | } 45 | } 46 | 47 | void close_file(int id) { 48 | if (outs_.find(id) != outs_.end()) { 49 | outs_[id]->flush(); 50 | outs_[id]->close(); 51 | } 52 | } 53 | 54 | void new_out_stream(int id) { 55 | if (outs_.find(id) == outs_.end()) { 56 | std::stringstream ss; 57 | std::string filename; 58 | ss << file_prefix_ << std::to_string(id) << ".txt"; 59 | ss >> filename; 60 | std::ofstream *out = new std::ofstream; 61 | open_file(filename, *out); 62 | outs_[id] = out; 63 | } 64 | } 65 | 66 | private: 67 | std::map outs_; 68 | std::string file_prefix_; 69 | }; 70 | 71 | #endif //MINISQL_TREE_FILE_MGR_H 72 | -------------------------------------------------------------------------------- /src/index/b_plus_tree_index.cpp: -------------------------------------------------------------------------------- 1 | #include "index/b_plus_tree_index.h" 2 | #include "index/generic_key.h" 3 | 4 | INDEX_TEMPLATE_ARGUMENTS 5 | BPLUSTREE_INDEX_TYPE::BPlusTreeIndex(index_id_t index_id, IndexSchema *key_schema, 6 | BufferPoolManager *buffer_pool_manager) 7 | : Index(index_id, key_schema), 8 | comparator_(key_schema_), 9 | container_(index_id, buffer_pool_manager, comparator_) { 10 | 11 | } 12 | 13 | INDEX_TEMPLATE_ARGUMENTS 14 | dberr_t BPLUSTREE_INDEX_TYPE::InsertEntry(const Row &key, RowId row_id, Transaction *txn) { 15 | ASSERT(row_id.Get() != INVALID_ROWID.Get(), "Invalid row id for index insert."); 16 | KeyType index_key; 17 | index_key.SerializeFromKey(key, key_schema_); 18 | 19 | bool status = container_.Insert(index_key, row_id, txn); 20 | 21 | if (!status) { 22 | return DB_FAILED; 23 | } 24 | return DB_SUCCESS; 25 | } 26 | 27 | INDEX_TEMPLATE_ARGUMENTS 28 | dberr_t BPLUSTREE_INDEX_TYPE::RemoveEntry(const Row &key, RowId row_id, Transaction *txn) { 29 | KeyType index_key; 30 | index_key.SerializeFromKey(key, key_schema_); 31 | 32 | container_.Remove(index_key, txn); 33 | return DB_SUCCESS; 34 | } 35 | 36 | INDEX_TEMPLATE_ARGUMENTS 37 | dberr_t BPLUSTREE_INDEX_TYPE::ScanKey(const Row &key, vector &result, Transaction *txn) { 38 | KeyType index_key; 39 | index_key.SerializeFromKey(key, key_schema_); 40 | if (container_.GetValue(index_key, result, txn)) { 41 | return DB_SUCCESS; 42 | } 43 | return DB_KEY_NOT_FOUND; 44 | } 45 | 46 | INDEX_TEMPLATE_ARGUMENTS 47 | dberr_t BPLUSTREE_INDEX_TYPE::Destroy() { 48 | container_.Destroy(); 49 | return DB_SUCCESS; 50 | } 51 | 52 | INDEX_TEMPLATE_ARGUMENTS 53 | INDEXITERATOR_TYPE BPLUSTREE_INDEX_TYPE::GetBeginIterator() { 54 | return container_.Begin(); 55 | } 56 | 57 | INDEX_TEMPLATE_ARGUMENTS 58 | INDEXITERATOR_TYPE 59 | BPLUSTREE_INDEX_TYPE::GetBeginIterator(const KeyType &key) { 60 | return container_.Begin(key); 61 | } 62 | 63 | INDEX_TEMPLATE_ARGUMENTS 64 | INDEXITERATOR_TYPE BPLUSTREE_INDEX_TYPE::GetEndIterator() { 65 | return container_.End(); 66 | } 67 | 68 | template 69 | class BPlusTreeIndex, RowId, GenericComparator<4>>; 70 | 71 | template 72 | class BPlusTreeIndex, RowId, GenericComparator<8>>; 73 | 74 | template 75 | class BPlusTreeIndex, RowId, GenericComparator<16>>; 76 | 77 | template 78 | class BPlusTreeIndex, RowId, GenericComparator<32>>; 79 | 80 | template 81 | class BPlusTreeIndex, RowId, GenericComparator<64>>; -------------------------------------------------------------------------------- /src/index/index_iterator.cpp: -------------------------------------------------------------------------------- 1 | #include "index/basic_comparator.h" 2 | #include "index/generic_key.h" 3 | #include "index/index_iterator.h" 4 | 5 | INDEX_TEMPLATE_ARGUMENTS INDEXITERATOR_TYPE::IndexIterator(BufferPoolManager *buffer_pool_manager, 6 | Page *page, int index) : 7 | buffer_pool_manager_(buffer_pool_manager), 8 | page_(page), 9 | index_(index) 10 | { 11 | leaf_page_ = reinterpret_cast(page->GetData()); 12 | } 13 | 14 | INDEX_TEMPLATE_ARGUMENTS INDEXITERATOR_TYPE::~IndexIterator() 15 | { 16 | page_->RUnlatch(); 17 | buffer_pool_manager_->UnpinPage(page_->GetPageId(), false); 18 | } 19 | 20 | INDEX_TEMPLATE_ARGUMENTS const MappingType &INDEXITERATOR_TYPE::operator*() 21 | { 22 | // ASSERT(false, "Not implemented yet."); 23 | return leaf_page_->GetItem(index_); 24 | } 25 | 26 | INDEX_TEMPLATE_ARGUMENTS INDEXITERATOR_TYPE &INDEXITERATOR_TYPE::operator++() 27 | { 28 | if (index_ == leaf_page_->GetSize() - 1 29 | && leaf_page_->GetNextPageId() != INVALID_PAGE_ID) 30 | { 31 | Page* next_page = buffer_pool_manager_->FetchPage(leaf_page_->GetNextPageId()); 32 | next_page->RLatch(); 33 | page_->RUnlatch(); 34 | buffer_pool_manager_->UnpinPage(page_->GetPageId(), false); 35 | page_ = next_page; 36 | leaf_page_ = reinterpret_cast(page_->GetData()); 37 | index_ = 0; 38 | } 39 | else 40 | { 41 | index_++; 42 | } 43 | 44 | return *this; 45 | } 46 | 47 | INDEX_TEMPLATE_ARGUMENTS 48 | bool INDEXITERATOR_TYPE::operator==(const IndexIterator &itr) const 49 | { 50 | if(itr.index_ == this->index_ 51 | && itr.leaf_page_->GetPageId() == this->leaf_page_->GetPageId()) 52 | { 53 | return true; 54 | } 55 | return false; 56 | } 57 | 58 | INDEX_TEMPLATE_ARGUMENTS 59 | bool INDEXITERATOR_TYPE::operator!=(const IndexIterator &itr) const 60 | { 61 | if(itr.index_ == this->index_ 62 | && itr.leaf_page_->GetPageId() == this->leaf_page_->GetPageId()) 63 | { 64 | return false; 65 | } 66 | return true; 67 | // return false; 68 | } 69 | 70 | template 71 | class IndexIterator>; 72 | 73 | template 74 | class IndexIterator, RowId, GenericComparator<4>>; 75 | 76 | template 77 | class IndexIterator, RowId, GenericComparator<8>>; 78 | 79 | template 80 | class IndexIterator, RowId, GenericComparator<16>>; 81 | 82 | template 83 | class IndexIterator, RowId, GenericComparator<32>>; 84 | 85 | template 86 | class IndexIterator, RowId, GenericComparator<64>>; 87 | -------------------------------------------------------------------------------- /src/page/b_plus_tree_page.cpp: -------------------------------------------------------------------------------- 1 | #include "page/b_plus_tree_page.h" 2 | 3 | // huangzheng 22.5.10 22:00 v1 4 | // all 5 | 6 | /* 7 | * Helper methods to get/set page type 8 | * Page type enum class is defined in b_plus_tree_page.h 9 | */ 10 | bool BPlusTreePage::IsLeafPage() const 11 | { 12 | // return false; 13 | if(this->page_type_ == IndexPageType::LEAF_PAGE) 14 | { 15 | return true; 16 | } 17 | return false; 18 | } 19 | 20 | bool BPlusTreePage::IsRootPage() const 21 | { 22 | if(this->parent_page_id_ == INVALID_PAGE_ID) 23 | { 24 | return true; 25 | } 26 | return false; 27 | } 28 | 29 | void BPlusTreePage::SetPageType(IndexPageType page_type) 30 | { 31 | this->page_type_ = page_type; 32 | } 33 | 34 | /* 35 | * Helper methods to get/set size (number of key/value pairs stored in that 36 | * page) 37 | */ 38 | int BPlusTreePage::GetSize() const 39 | { 40 | // return 0; 41 | return this->size_; 42 | } 43 | 44 | void BPlusTreePage::SetSize(int size) 45 | { 46 | this->size_ = size; 47 | } 48 | 49 | void BPlusTreePage::IncreaseSize(int amount) 50 | { 51 | this->size_ += amount; 52 | } 53 | 54 | /* 55 | * Helper methods to get/set max size (capacity) of the page 56 | */ 57 | int BPlusTreePage::GetMaxSize() const 58 | { 59 | // return 0; 60 | return this->max_size_; 61 | } 62 | 63 | void BPlusTreePage::SetMaxSize(int size) 64 | { 65 | this->max_size_ = size; 66 | } 67 | 68 | /* 69 | * Helper method to get min page size 70 | * Generally, min page size == max page size / 2 71 | */ 72 | int BPlusTreePage::GetMinSize() const 73 | { 74 | // return 0; 75 | return this->max_size_ / 2; 76 | } 77 | 78 | /* 79 | * Helper methods to get/set parent page id 80 | */ 81 | page_id_t BPlusTreePage::GetParentPageId() const 82 | { 83 | return this->parent_page_id_; 84 | } 85 | 86 | void BPlusTreePage::SetParentPageId(page_id_t parent_page_id) 87 | { 88 | this->parent_page_id_ = parent_page_id; 89 | } 90 | 91 | /* 92 | * Helper methods to get/set self page id 93 | */ 94 | page_id_t BPlusTreePage::GetPageId() const 95 | { 96 | // return INVALID_PAGE_ID; 97 | return this->page_id_; 98 | } 99 | 100 | void BPlusTreePage::SetPageId(page_id_t page_id) 101 | { 102 | this->page_id_ = page_id; 103 | } 104 | 105 | /* 106 | * Helper methods to set lsn 107 | */ 108 | void BPlusTreePage::SetLSN(lsn_t lsn) 109 | { 110 | lsn_ = lsn; 111 | } -------------------------------------------------------------------------------- /src/page/bitmap_page.cpp: -------------------------------------------------------------------------------- 1 | #include "page/bitmap_page.h" 2 | #include 3 | 4 | template 5 | bool BitmapPage::AllocatePage(uint32_t &page_offset) { 6 | if (allocate_pages.test(page_offset) || page_offset >= 8 * MAX_CHARS) { 7 | return false; 8 | } else { 9 | allocate_pages.set(page_offset, 1); 10 | return true; 11 | } 12 | } 13 | 14 | template 15 | bool BitmapPage::DeAllocatePage(uint32_t page_offset) { 16 | if (allocate_pages.test(page_offset)) { 17 | allocate_pages.set(page_offset, 0); 18 | next_free_page_ = page_offset; 19 | page_allocated_--; 20 | return true; 21 | } else { 22 | return false; 23 | } 24 | } 25 | 26 | template 27 | bool BitmapPage::IsPageFree(uint32_t page_offset) const { 28 | return !allocate_pages.test(page_offset); 29 | } 30 | 31 | template 32 | bool BitmapPage::IsPageFreeLow(uint32_t byte_index, uint8_t bit_index) const { 33 | return false; 34 | } 35 | template 36 | bool BitmapPage::IsBitmapFull() { 37 | return page_allocated_ == 8 * MAX_CHARS; 38 | } 39 | 40 | template 41 | class BitmapPage<64>; 42 | 43 | template 44 | class BitmapPage<128>; 45 | 46 | template 47 | class BitmapPage<256>; 48 | 49 | template 50 | class BitmapPage<512>; 51 | 52 | template 53 | class BitmapPage<1024>; 54 | 55 | template 56 | class BitmapPage<2048>; 57 | 58 | template 59 | class BitmapPage<4096>; -------------------------------------------------------------------------------- /src/page/index_roots_page.cpp: -------------------------------------------------------------------------------- 1 | #include "page/index_roots_page.h" 2 | 3 | bool IndexRootsPage::Insert(const index_id_t index_id, const page_id_t root_id) { 4 | auto index = FindIndex(index_id); 5 | // check for duplicate index id 6 | if (index != -1) { 7 | return false; 8 | } 9 | roots_[count_].first = index_id; 10 | roots_[count_].second = root_id; 11 | count_++; 12 | return true; 13 | } 14 | 15 | bool IndexRootsPage::Delete(const index_id_t index_id) { 16 | auto index = FindIndex(index_id); 17 | if (index == -1) { 18 | return false; 19 | } 20 | for (auto i = index; i < count_ - 1; i++) { 21 | roots_[i] = roots_[i + 1]; 22 | } 23 | count_--; 24 | return true; 25 | } 26 | 27 | bool IndexRootsPage::Update(const index_id_t index_id, const page_id_t root_id) { 28 | auto index = FindIndex(index_id); 29 | if (index == -1) { 30 | return false; 31 | } 32 | roots_[index].second = root_id; 33 | return true; 34 | } 35 | 36 | bool IndexRootsPage::GetRootId(const index_id_t index_id, page_id_t *root_id) { 37 | auto index = FindIndex(index_id); 38 | if (index == -1) { 39 | return false; 40 | } 41 | *root_id = roots_[index].second; 42 | return true; 43 | } 44 | 45 | int IndexRootsPage::FindIndex(const index_id_t index_id) { 46 | for (auto i = 0; i < count_; i++) { 47 | if (roots_[i].first == index_id) { 48 | return i; 49 | } 50 | } 51 | return -1; 52 | } 53 | -------------------------------------------------------------------------------- /src/parser/parser.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "parser/parser.h" 3 | #include "parser/syntax_tree.h" 4 | 5 | pSyntaxNode minisql_parser_root_node_ = NULL; 6 | pSyntaxNodeList minisql_parser_syntax_node_list_ = NULL; 7 | int minisql_parser_line_no_ = 0; 8 | int minisql_parser_column_no_ = 0; 9 | int minisql_parser_error_ = 0; 10 | char *minisql_parser_error_message_ = NULL; 11 | int minisql_parser_debug_node_count_ = 0; 12 | 13 | void MinisqlParserMovePos(int line, char *text) { 14 | size_t i = 0; 15 | while (i < strlen(text)) { 16 | char ch = text[i]; 17 | switch (ch) { 18 | case '\n': 19 | minisql_parser_column_no_ = 0; 20 | minisql_parser_line_no_++; 21 | break; 22 | case '\t': 23 | minisql_parser_column_no_ += 4 - (minisql_parser_column_no_ % 4); 24 | break; 25 | default: 26 | minisql_parser_column_no_++; 27 | } 28 | i++; 29 | } 30 | } 31 | 32 | void MinisqlParserSetRoot(pSyntaxNode node) { 33 | minisql_parser_root_node_ = node; 34 | } 35 | 36 | void MinisqlParserSetError(char *msg) { 37 | if (minisql_parser_error_) { 38 | return; 39 | } 40 | minisql_parser_error_ = 1; 41 | if (minisql_parser_error_message_ != NULL) { 42 | printf("minisql parse error message not null in MinisqlParserSetError.\n"); 43 | } 44 | printf("Minisql parse error at line %d, col %d, message: %s\n", minisql_parser_line_no_, minisql_parser_column_no_, 45 | msg); 46 | minisql_parser_error_message_ = msg; 47 | } 48 | 49 | pSyntaxNode MinisqlGetParserRootNode() { 50 | return minisql_parser_root_node_; 51 | } 52 | 53 | void MinisqlParserInit() { 54 | minisql_parser_root_node_ = NULL; 55 | minisql_parser_line_no_ = 1; 56 | minisql_parser_column_no_ = 0; 57 | minisql_parser_error_ = 0; 58 | minisql_parser_error_message_ = NULL; 59 | minisql_parser_debug_node_count_ = 0; 60 | } 61 | 62 | void MinisqlParserFinish() { 63 | DestroySyntaxTree(); 64 | } 65 | 66 | int MinisqlParserGetError() { 67 | return minisql_parser_error_; 68 | } 69 | 70 | char *MinisqlParserGetErrorMessage() { 71 | return minisql_parser_error_message_; 72 | } -------------------------------------------------------------------------------- /src/parser/syntax_tree_printer.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Chengjun Ying on 2022/4/5. 3 | // 4 | #include 5 | #include 6 | #include 7 | 8 | #include "parser/syntax_tree_printer.h" 9 | 10 | void SyntaxTreePrinter::PrintTree(std::ofstream &out) { 11 | if (root_ == nullptr) { 12 | out << "digraph G{ }" << std::endl; 13 | return; 14 | } 15 | out << "digraph G{ " << std::endl; 16 | PrintTreeLow(root_, out); 17 | out << "}" << std::endl; 18 | } 19 | 20 | void SyntaxTreePrinter::PrintTreeLow(pSyntaxNode node, std::ofstream &out) { 21 | out << "SYNTAX_NODE_" << node->id_ << "[label=\""; 22 | out << GetSyntaxNodeTypeStr(node->type_) << "(" << node->line_no_ << "," << node->col_no_ << ")"; 23 | out << "\\n"; 24 | out << "id(" << node->id_ << ")"; 25 | if (node->val_ != nullptr) { 26 | out << ",val(" << node->val_ << ")"; 27 | } 28 | out << "\"];" << std::endl; 29 | 30 | if (node->child_ != nullptr) { 31 | PrintTreeLow(node->child_, out); 32 | out << "SYNTAX_NODE_" << node->id_ << " -> " << "SYNTAX_NODE_" << node->child_->id_ << ";" << std::endl; 33 | } 34 | 35 | if (node->next_ != nullptr) { 36 | PrintTreeLow(node->next_, out); 37 | out << "SYNTAX_NODE_" << node->id_ << " -> " << "SYNTAX_NODE_" << node->next_->id_ << ";" << std::endl; 38 | out << "{rank=same; " << "SYNTAX_NODE_" << node->id_ << "," << "SYNTAX_NODE_" << node->next_->id_ << "};" 39 | << std::endl; 40 | } 41 | 42 | } -------------------------------------------------------------------------------- /src/record/row.cpp: -------------------------------------------------------------------------------- 1 | #include "record/row.h" 2 | 3 | uint32_t Row::SerializeTo(char *buf, Schema *schema) const { 4 | uint32_t ofs = 0; 5 | 6 | MACH_WRITE_TO(uint32_t, buf, fields_nums); 7 | ofs += sizeof(uint32_t); 8 | MACH_WRITE_TO(uint32_t, buf + ofs, null_nums); 9 | ofs += sizeof(uint32_t); 10 | 11 | for (uint32_t i = 0; i < fields_.size(); i++) { 12 | if (fields_[i]->IsNull()) { 13 | MACH_WRITE_INT32(buf + ofs, i); 14 | ofs += sizeof(uint32_t); 15 | } 16 | } 17 | 18 | for (auto &itr : fields_) { 19 | if (!itr->IsNull()) ofs += itr->SerializeTo(buf + ofs); 20 | } 21 | 22 | return ofs; 23 | } 24 | 25 | uint32_t Row::DeserializeFrom(char *buf, Schema *schema) { 26 | uint32_t ofs = 0, i = 0; 27 | 28 | fields_nums = MACH_READ_UINT32(buf); 29 | ofs += sizeof(uint32_t); 30 | null_nums = MACH_READ_UINT32(buf + ofs); 31 | ofs += sizeof(uint32_t); 32 | 33 | std::vector null_bitmap(fields_nums, 0); 34 | for (i = 0; i < null_nums; i++) { 35 | null_bitmap[MACH_READ_UINT32(buf + ofs)] = 1; 36 | ofs += sizeof(uint32_t); 37 | } 38 | 39 | for (i = 0; i < fields_nums; i++) { 40 | fields_.push_back(ALLOC_P(heap_, Field)(schema->GetColumn(i)->GetType())); 41 | if (!null_bitmap[i]) { 42 | ofs += Field::DeserializeFrom(buf + ofs, schema->GetColumn(i)->GetType(), &fields_[i], false, heap_); 43 | } 44 | } 45 | return ofs; 46 | } 47 | 48 | uint32_t Row::GetSerializedSize(Schema *schema) const { 49 | if (fields_.empty()) 50 | return 0; 51 | else if (fields_nums == null_nums) 52 | return sizeof(uint32_t) * (2 + null_nums); 53 | else { 54 | uint32_t ofs = 0; 55 | for (auto &itr : fields_) { 56 | if (!itr->IsNull()) ofs += itr->GetSerializedSize(); 57 | } 58 | 59 | return ofs + sizeof(uint32_t) * (2 + null_nums); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/record/schema.cpp: -------------------------------------------------------------------------------- 1 | #include "record/schema.h" 2 | 3 | uint32_t Schema::SerializeTo(char *buf) const { 4 | uint32_t ofs = 0; 5 | 6 | MACH_WRITE_TO(uint32_t, buf, SCHEMA_MAGIC_NUM); 7 | ofs += sizeof(uint32_t); 8 | 9 | MACH_WRITE_UINT32(buf + ofs, columns_.size()); 10 | ofs += sizeof(uint32_t); 11 | 12 | for (auto &itr : columns_) { 13 | ofs += itr->SerializeTo(buf + ofs); 14 | } 15 | 16 | return ofs; 17 | } 18 | 19 | uint32_t Schema::GetSerializedSize() const { 20 | uint32_t size = 0; 21 | for (auto &itr : columns_) { 22 | size += itr->GetSerializedSize(); 23 | } 24 | return size + 2 * sizeof(uint32_t); 25 | } 26 | 27 | uint32_t Schema::DeserializeFrom(char *buf, Schema *&schema, MemHeap *heap) { 28 | auto num = MACH_READ_FROM(uint32_t, buf); 29 | ASSERT(num == Schema::SCHEMA_MAGIC_NUM, "Schema magic num error."); 30 | 31 | uint32_t ofs = sizeof(uint32_t); 32 | 33 | auto col_size = MACH_READ_UINT32(buf + ofs); 34 | ofs += sizeof(uint32_t); 35 | 36 | std::vector columns; 37 | for (auto i = 0u; i < col_size; i++) { 38 | Column *col; 39 | ofs += Column::DeserializeFrom(buf + ofs, col, heap); 40 | columns.push_back(col); 41 | } 42 | 43 | schema = ALLOC_P(heap, Schema)(columns); 44 | 45 | return ofs; 46 | } -------------------------------------------------------------------------------- /test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | FILE(GLOB_RECURSE MINISQL_TEST_SOURCES ${PROJECT_SOURCE_DIR}/test/*/*test.cpp) 2 | 3 | SET(TEST_MAIN_PATH ${PROJECT_SOURCE_DIR}/test/main_test.cpp) 4 | ADD_EXECUTABLE(minisql_test ${MINISQL_TEST_SOURCES} ${TEST_MAIN_PATH}) 5 | ADD_LIBRARY(minisql_test_main ${TEST_MAIN_PATH}) 6 | TARGET_LINK_LIBRARIES(minisql_test_main glog gtest) 7 | TARGET_LINK_LIBRARIES(minisql_test minisql_shared glog gtest) 8 | 9 | foreach (test_source ${MINISQL_TEST_SOURCES}) 10 | # Create test suit 11 | get_filename_component(test_filename ${test_source} NAME) 12 | string(REPLACE ".cpp" "" test_name ${test_filename}) 13 | MESSAGE(STATUS "Create test suit: ${test_name}") 14 | 15 | # Add the test target separately and as part of "make check-tests". 16 | add_executable(${test_name} EXCLUDE_FROM_ALL ${test_source} buffer/clock_replacer_test.cpp) 17 | target_link_libraries(${test_name} minisql_shared glog gtest minisql_test_main) 18 | # target_link_libraries(${test_name} minisql_shared glog gtest gtest_main) 19 | 20 | # Set test target properties and dependencies. 21 | set_target_properties(${test_name} 22 | PROPERTIES 23 | RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/test" 24 | COMMAND ${test_name} 25 | ) 26 | 27 | # Add the test under CTest. 28 | add_test(${test_name} ${CMAKE_BINARY_DIR}/test/${test_name} --gtest_color=yes 29 | --gtest_output=xml:${CMAKE_BINARY_DIR}/test/${test_name}.xml) 30 | endforeach (test_source ${MINISQL_TEST_SOURCES}) -------------------------------------------------------------------------------- /test/buffer/clock_replacer_test.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by kenshin on 5/7/22. 3 | // 4 | 5 | 6 | // 7 | // Created by kenshin on 5/7/22. 8 | // 9 | #include "buffer/clock_replacer.h" 10 | #include "gtest/gtest.h" 11 | 12 | TEST(ClockReplacerTest, SampleTest) { 13 | ClockReplacer clock_replacer(7); 14 | 15 | // Scenario: unpin six elements, i.e. add them to the replacer. 16 | clock_replacer.Unpin(1); 17 | clock_replacer.Unpin(2); 18 | clock_replacer.Unpin(3); 19 | clock_replacer.Unpin(4); 20 | clock_replacer.Unpin(5); 21 | clock_replacer.Unpin(6); 22 | clock_replacer.Unpin(1); 23 | EXPECT_EQ(6, clock_replacer.Size()); 24 | 25 | // Scenario: get three victims from the clock. 26 | int value; 27 | clock_replacer.Victim(&value); 28 | EXPECT_EQ(1, value); 29 | clock_replacer.Victim(&value); 30 | EXPECT_EQ(2, value); 31 | clock_replacer.Victim(&value); 32 | EXPECT_EQ(3, value); 33 | 34 | // Scenario: pin elements in the replacer. 35 | // Note that 3 has already been victimized, so pinning 3 should have no effect. 36 | clock_replacer.Pin(3); 37 | clock_replacer.Pin(4); 38 | EXPECT_EQ(2, clock_replacer.Size()); 39 | 40 | // Scenario: unpin 4. We expect that the reference bit of 4 will be set to 1. 41 | clock_replacer.Unpin(4); 42 | 43 | // Scenario: continue looking for victims. We expect these victims. 44 | clock_replacer.Victim(&value); 45 | EXPECT_EQ(5, value); 46 | clock_replacer.Victim(&value); 47 | EXPECT_EQ(6, value); 48 | clock_replacer.Victim(&value); 49 | EXPECT_EQ(4, value); 50 | } 51 | 52 | TEST(ClockReplacerTest, CornerCaseTest) { 53 | ClockReplacer clock_replacer(4); 54 | int value; 55 | bool result = clock_replacer.Victim(&value); 56 | EXPECT_FALSE(result); 57 | 58 | clock_replacer.Unpin(3); 59 | clock_replacer.Unpin(2); 60 | EXPECT_EQ(2, clock_replacer.Size()); 61 | clock_replacer.Victim(&value); 62 | EXPECT_EQ(2, value); 63 | clock_replacer.Unpin(1); 64 | EXPECT_EQ(2, clock_replacer.Size()); 65 | clock_replacer.Victim(&value); 66 | EXPECT_EQ(3, value); 67 | clock_replacer.Victim(&value); 68 | EXPECT_EQ(1, value); 69 | EXPECT_FALSE(clock_replacer.Victim(&value)); 70 | EXPECT_EQ(0, clock_replacer.Size()); 71 | } -------------------------------------------------------------------------------- /test/buffer/lru_replacer_test.cpp: -------------------------------------------------------------------------------- 1 | #include "buffer/lru_replacer.h" 2 | #include "gtest/gtest.h" 3 | 4 | TEST(LRUReplacerTest, SampleTest) { 5 | LRUReplacer lru_replacer(7); 6 | 7 | // Scenario: unpin six elements, i.e. add them to the replacer. 8 | lru_replacer.Unpin(1); 9 | lru_replacer.Unpin(2); 10 | lru_replacer.Unpin(3); 11 | lru_replacer.Unpin(4); 12 | lru_replacer.Unpin(5); 13 | lru_replacer.Unpin(6); 14 | lru_replacer.Unpin(1); 15 | EXPECT_EQ(6, lru_replacer.Size()); 16 | 17 | // Scenario: get three victims from the lru. 18 | int value; 19 | lru_replacer.Victim(&value); 20 | EXPECT_EQ(1, value); 21 | lru_replacer.Victim(&value); 22 | EXPECT_EQ(2, value); 23 | lru_replacer.Victim(&value); 24 | EXPECT_EQ(3, value); 25 | 26 | // Scenario: pin elements in the replacer. 27 | // Note that 3 has already been victimized, so pinning 3 should have no effect. 28 | lru_replacer.Pin(3); 29 | lru_replacer.Pin(4); 30 | EXPECT_EQ(2, lru_replacer.Size()); 31 | 32 | // Scenario: unpin 4. We expect that the reference bit of 4 will be set to 1. 33 | lru_replacer.Unpin(4); 34 | 35 | // Scenario: continue looking for victims. We expect these victims. 36 | lru_replacer.Victim(&value); 37 | EXPECT_EQ(5, value); 38 | lru_replacer.Victim(&value); 39 | EXPECT_EQ(6, value); 40 | lru_replacer.Victim(&value); 41 | EXPECT_EQ(4, value); 42 | } -------------------------------------------------------------------------------- /test/include/utils/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef MINISQL_UTILS_H 2 | #define MINISQL_UTILS_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "buffer/buffer_pool_manager.h" 10 | #include "storage/disk_manager.h" 11 | 12 | template 13 | void ShuffleArray(std::vector &array) 14 | { 15 | std::random_device rd; 16 | std::mt19937 rng(rd()); 17 | std::shuffle(array.begin(), array.end(), rng); 18 | } 19 | 20 | class RandomUtils { 21 | public: 22 | static void RandomString(char *buf, size_t len) { 23 | std::random_device r; 24 | std::default_random_engine rng(r()); 25 | std::uniform_int_distribution uniform_dist(0); 26 | for (size_t i = 0; i < len; i++) { 27 | buf[i] = uniform_dist(rng); 28 | } 29 | } 30 | 31 | static int32_t RandomInt(int32_t low, int32_t high) { 32 | std::random_device r; 33 | std::default_random_engine rng(r()); 34 | std::uniform_int_distribution uniform_dist(low, high); 35 | return uniform_dist(rng); 36 | } 37 | 38 | static float_t RandomFloat(float_t low, float_t high) { 39 | std::random_device r; 40 | std::default_random_engine rng(r()); 41 | std::uniform_real_distribution uniform_dist(low, high); 42 | return uniform_dist(rng); 43 | } 44 | 45 | }; 46 | 47 | #endif //MINISQL_UTILS_H 48 | -------------------------------------------------------------------------------- /test/index/index_iterator_test.cpp: -------------------------------------------------------------------------------- 1 | #include "common/instance.h" 2 | #include "gtest/gtest.h" 3 | #include "index/b_plus_tree.h" 4 | #include "index/basic_comparator.h" 5 | 6 | static const std::string db_name = "bp_tree_insert_test.db"; 7 | 8 | TEST(BPlusTreeTests, IndexIteratorTest) { 9 | // Init engine 10 | DBStorageEngine engine(db_name); 11 | BasicComparator comparator; 12 | BPlusTree> tree(0, engine.bpm_, comparator, 4, 4); 13 | // Insert and delete record 14 | for (int i = 1; i <= 50; i++) { 15 | tree.Insert(i, i * 100, nullptr); 16 | } 17 | for (int i = 2; i <= 50; i += 2) { 18 | tree.Remove(i); 19 | } 20 | // Search keys 21 | vector v; 22 | for (int i = 2; i <= 50; i += 2) { 23 | ASSERT_FALSE(tree.GetValue(i, v)); 24 | } 25 | for (int i = 1; i <= 49; i += 2) { 26 | ASSERT_TRUE(tree.GetValue(i, v)); 27 | ASSERT_EQ(i * 100, v[v.size() - 1]); 28 | } 29 | // Iterator 30 | int ans = 1; 31 | for (auto iter = tree.Begin(); iter != tree.End(); ++iter, ans += 2) { 32 | EXPECT_EQ(ans, (*iter).first); 33 | EXPECT_EQ(ans * 100, (*iter).second); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /test/main_test.cpp: -------------------------------------------------------------------------------- 1 | #include "gtest/gtest.h" 2 | #include "glog/logging.h" 3 | 4 | int main(int argc, char **argv) { 5 | testing::InitGoogleTest(&argc, argv); 6 | // testing::GTEST_FLAG(filter) = "BPlusTreeTests*"; 7 | FLAGS_logtostderr = true; 8 | FLAGS_colorlogtostderr = true; 9 | google::InitGoogleLogging(argv[0]); 10 | return RUN_ALL_TESTS(); 11 | } -------------------------------------------------------------------------------- /test/page/index_roots_page_test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "gtest/gtest.h" 4 | #include "page/index_roots_page.h" 5 | 6 | TEST(PageTests, IndexRootsPageTest) { 7 | char *buf = new char[PAGE_SIZE]; 8 | memset(buf, 0, PAGE_SIZE); 9 | auto *page = reinterpret_cast(buf); 10 | page->Init(); 11 | for (int i = 0; i < 25; i++) { 12 | ASSERT_FALSE(page->Delete(i)); 13 | ASSERT_TRUE(page->Insert(i, i * 100)); 14 | } 15 | for (int i = 0; i < 25; i++) { 16 | ASSERT_FALSE(page->Insert(i, 0)); 17 | page_id_t id; 18 | ASSERT_TRUE(page->GetRootId(i, &id)); 19 | ASSERT_EQ(i * 100, id); 20 | } 21 | for (int i = 0; i < 25; i++) { 22 | ASSERT_TRUE(page->Update(i, i + 100)); 23 | page_id_t id; 24 | ASSERT_TRUE(page->GetRootId(i, &id)); 25 | ASSERT_EQ(i + 100, id); 26 | } 27 | std::unordered_set set{0, 4, 5, 13, 12, 7, 22, 24}; 28 | for (auto v : set) { 29 | ASSERT_TRUE(page->Delete(v)); 30 | } 31 | for (int i = 0; i < 25; i++) { 32 | page_id_t id; 33 | if (set.find(i) != set.end()) { 34 | ASSERT_FALSE(page->GetRootId(i, &id)); 35 | } else { 36 | ASSERT_TRUE(page->GetRootId(i, &id)); 37 | ASSERT_EQ(i + 100, id); 38 | } 39 | } 40 | delete[] buf; 41 | } 42 | -------------------------------------------------------------------------------- /test/storage/table_heap_test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "common/instance.h" 5 | #include "gtest/gtest.h" 6 | #include "record/field.h" 7 | #include "record/schema.h" 8 | #include "storage/table_heap.h" 9 | #include "utils/utils.h" 10 | 11 | static string db_file_name = "table_heap_test.db"; 12 | using Fields = std::vector; 13 | 14 | TEST(TableHeapTest, TableHeapSampleTest) { 15 | // init testing instance 16 | DBStorageEngine engine(db_file_name); 17 | SimpleMemHeap heap; 18 | const int row_nums = 200000; 19 | // create schema 20 | std::vector columns = {ALLOC_COLUMN(heap)("id", TypeId::kTypeInt, 0, false, false), 21 | ALLOC_COLUMN(heap)("name", TypeId::kTypeChar, 64, 1, true, false), 22 | ALLOC_COLUMN(heap)("account", TypeId::kTypeFloat, 2, true, false)}; 23 | auto schema = std::make_shared(columns); 24 | // create rows 25 | std::unordered_map row_values; 26 | TableHeap *table_heap = TableHeap::Create(engine.bpm_, schema.get(), nullptr, nullptr, nullptr, &heap); 27 | for (int i = 0; i < row_nums; i++) { 28 | int32_t len = RandomUtils::RandomInt(0, 64); 29 | char *characters = new char[len]; 30 | RandomUtils::RandomString(characters, len); 31 | Fields *fields = 32 | new Fields{Field(TypeId::kTypeInt, i), Field(TypeId::kTypeChar, const_cast(characters), len, true), 33 | Field(TypeId::kTypeFloat, RandomUtils::RandomFloat(-999.f, 999.f))}; 34 | Row row(*fields); 35 | if (!table_heap->InsertTuple(row, nullptr)) { 36 | int a = 1; 37 | a++; 38 | } 39 | row_values[row.GetRowId().Get()] = fields; 40 | delete[] characters; 41 | } 42 | 43 | ASSERT_EQ(row_nums, row_values.size()); 44 | for (auto row_kv : row_values) { 45 | Row row(RowId(row_kv.first)); 46 | table_heap->GetTuple(&row, nullptr); 47 | ASSERT_EQ(schema.get()->GetColumnCount(), row.GetFields().size()); 48 | for (size_t j = 0; j < schema.get()->GetColumnCount(); j++) { 49 | ASSERT_EQ(CmpBool::kTrue, row.GetField(j)->CompareEquals(row_kv.second->at(j))); 50 | } 51 | // free spaces 52 | delete row_kv.second; 53 | } 54 | } 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /testfiles/basic.txt: -------------------------------------------------------------------------------- 1 | create database db0; 2 | create database db1; 3 | create database db2; 4 | create database db3; 5 | create database db4; 6 | show databases; 7 | use db0; 8 | create table account( 9 | id int, 10 | name char(16) unique, 11 | balance float, 12 | primary key(id) 13 | ); -------------------------------------------------------------------------------- /testfiles/cselect.txt: -------------------------------------------------------------------------------- 1 | select * from account where id = 12500011; 2 | select * from account where balance = 462.55; 3 | select * from account where name = "name56789"; 0.09375 4 | select * from account where id <> 12500013; 5 | select * from account where balance <> 66.66; 6 | select * from account where name <> "123"; 7 | select id, name from account where balance = 666.64 and id = 12500008; 8 | 9 | create index idx01 on account(name); 10 | select * from account where name = "name56789"; 0.0625 11 | select * from account where name = "name45678"; 0.0625 12 | delete from account where name = "name45678"; 13 | insert into account values(32001, "name45678", 666.66); 14 | drop index idx01; 15 | select * from account where name = "name56789"; 0.1009375 16 | select * from account where name = "name45678"; 0.09375 17 | 18 | delete from account where balance = 666.66; 0.109375 19 | select * from account where balance = 666.66; 20 | delete from account; 21 | select * from account; 22 | drop table account; 23 | show tables; 24 | show indexes; -------------------------------------------------------------------------------- /testfiles/dreopen.txt: -------------------------------------------------------------------------------- 1 | show databases; 2 | use db0; 3 | select * from table; -------------------------------------------------------------------------------- /thirdparty/glog/.bazelci/presubmit.yml: -------------------------------------------------------------------------------- 1 | --- 2 | platforms: 3 | ubuntu1804: 4 | build_flags: 5 | - "--features=layering_check" 6 | - "--copt=-Werror" 7 | build_targets: 8 | - "//..." 9 | test_flags: 10 | - "--features=layering_check" 11 | - "--copt=-Werror" 12 | test_targets: 13 | - "//..." 14 | macos: 15 | build_flags: 16 | - "--features=layering_check" 17 | - "--copt=-Werror" 18 | build_targets: 19 | - "//..." 20 | test_flags: 21 | - "--features=layering_check" 22 | - "--copt=-Werror" 23 | test_targets: 24 | - "//..." 25 | windows: 26 | # Optional: use VS 2017 instead of 2015. 27 | environment: 28 | BAZEL_VC: "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools\\VC" 29 | build_flags: 30 | - "--features=layering_check" 31 | - "--copt=/WX" 32 | build_targets: 33 | - "//..." 34 | test_flags: 35 | - "--features=layering_check" 36 | - "--copt=/WX" 37 | test_targets: 38 | - "//..." 39 | -------------------------------------------------------------------------------- /thirdparty/glog/.gitattributes: -------------------------------------------------------------------------------- 1 | *.h linguist-language=C++ 2 | -------------------------------------------------------------------------------- /thirdparty/glog/.github/workflows/android.yml: -------------------------------------------------------------------------------- 1 | name: Android 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | build-android: 7 | name: NDK-C++${{matrix.std}}-${{matrix.abi}}-${{matrix.build_type}} 8 | runs-on: ubuntu-latest 9 | defaults: 10 | run: 11 | shell: bash 12 | strategy: 13 | fail-fast: true 14 | matrix: 15 | std: [98, 11, 14, 17, 20] 16 | abi: [arm64-v8a, armeabi-v7a, x86_64, x86] 17 | build_type: [Debug, Release] 18 | 19 | steps: 20 | - uses: actions/checkout@v2 21 | 22 | - name: Setup Ninja 23 | uses: ashutoshvarma/setup-ninja@master 24 | with: 25 | version: 1.10.0 26 | 27 | - name: Setup C++98 Environment 28 | if: matrix.std == '98' 29 | run: | 30 | echo 'CXXFLAGS=-Wno-error=variadic-macros -Wno-error=long-long ${{env.CXXFLAGS}}' >> $GITHUB_ENV 31 | 32 | - name: Configure 33 | env: 34 | CXXFLAGS: -Wall -Wextra -Wpedantic -Wsign-conversion -Wtautological-compare -Wformat-nonliteral -Wundef -Werror ${{env.CXXFLAGS}} 35 | run: | 36 | cmake -S . -B build_${{matrix.abi}} \ 37 | -DANDROID_ABI=${{matrix.abi}} \ 38 | -DANDROID_NATIVE_API_LEVEL=28 \ 39 | -DANDROID_STL=c++_shared \ 40 | -DCMAKE_BUILD_TYPE=${{matrix.build_type}} \ 41 | -DCMAKE_CXX_EXTENSIONS=OFF \ 42 | -DCMAKE_CXX_STANDARD=${{matrix.std}} \ 43 | -DCMAKE_CXX_STANDARD_REQUIRED=ON \ 44 | -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake \ 45 | -G Ninja \ 46 | -Werror 47 | 48 | - name: Build 49 | run: | 50 | cmake --build build_${{matrix.abi}} \ 51 | --config ${{matrix.build_type}} 52 | -------------------------------------------------------------------------------- /thirdparty/glog/.gitignore: -------------------------------------------------------------------------------- 1 | *.orig 2 | /build*/ 3 | bazel-* 4 | -------------------------------------------------------------------------------- /thirdparty/glog/AUTHORS: -------------------------------------------------------------------------------- 1 | # This is the official list of glog authors for copyright purposes. 2 | # This file is distinct from the CONTRIBUTORS files. 3 | # See the latter for an explanation. 4 | # 5 | # Names should be added to this file as: 6 | # Name or Organization 7 | # The email address is not required for organizations. 8 | # 9 | # Please keep the list sorted. 10 | 11 | Abhishek Dasgupta 12 | Abhishek Parmar 13 | Andrew Schwartzmeyer 14 | Andy Ying 15 | Brian Silverman 16 | Dmitriy Arbitman 17 | Google Inc. 18 | Guillaume Dumont 19 | Marco Wang 20 | Michael Tanner 21 | MiniLight 22 | romange 23 | Roman Perepelitsa 24 | Sergiu Deitsch 25 | tbennun 26 | Teddy Reed 27 | Vijaymahantesh Sattigeri 28 | Zhongming Qu 29 | Zhuoran Shen 30 | -------------------------------------------------------------------------------- /thirdparty/glog/BUILD.bazel: -------------------------------------------------------------------------------- 1 | licenses(['notice']) 2 | 3 | exports_files(["COPYING"]) 4 | 5 | load(':bazel/glog.bzl', 'glog_library') 6 | 7 | glog_library() 8 | -------------------------------------------------------------------------------- /thirdparty/glog/CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | # People who have agreed to one of the CLAs and can contribute patches. 2 | # The AUTHORS file lists the copyright holders; this file 3 | # lists people. For example, Google employees are listed here 4 | # but not in AUTHORS, because Google holds the copyright. 5 | # 6 | # Names should be added to this file only after verifying that 7 | # the individual or the individual's organization has agreed to 8 | # the appropriate Contributor License Agreement, found here: 9 | # 10 | # https://developers.google.com/open-source/cla/individual 11 | # https://developers.google.com/open-source/cla/corporate 12 | # 13 | # The agreement for individuals can be filled out on the web. 14 | # 15 | # When adding J Random Contributor's name to this file, 16 | # either J's name or J's organization's name should be 17 | # added to the AUTHORS file, depending on whether the 18 | # individual or corporate CLA was used. 19 | # 20 | # Names should be added to this file as: 21 | # Name 22 | # 23 | # Please keep the list sorted. 24 | 25 | Abhishek Dasgupta 26 | Abhishek Parmar 27 | Andrew Schwartzmeyer 28 | Andy Ying 29 | Bret McKee 30 | Brian Silverman 31 | Dmitriy Arbitman 32 | Fumitoshi Ukai 33 | Guillaume Dumont 34 | Håkan L. S. Younes 35 | Ivan Penkov 36 | Jacob Trimble 37 | Jim Ray 38 | Marco Wang 39 | Michael Darr 40 | Michael Tanner 41 | MiniLight 42 | Peter Collingbourne 43 | Rodrigo Queiro 44 | romange 45 | Roman Perepelitsa 46 | Sergiu Deitsch 47 | Shinichiro Hamaji 48 | tbennun 49 | Teddy Reed 50 | Vijaymahantesh Sattigeri 51 | Zhongming Qu 52 | Zhuoran Shen 53 | -------------------------------------------------------------------------------- /thirdparty/glog/WORKSPACE: -------------------------------------------------------------------------------- 1 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 2 | 3 | http_archive( 4 | name = "com_github_gflags_gflags", 5 | sha256 = "34af2f15cf7367513b352bdcd2493ab14ce43692d2dcd9dfc499492966c64dcf", 6 | strip_prefix = "gflags-2.2.2", 7 | urls = [ 8 | "https://mirror.bazel.build/github.com/gflags/gflags/archive/v2.2.2.tar.gz", 9 | "https://github.com/gflags/gflags/archive/v2.2.2.tar.gz", 10 | ], 11 | ) 12 | -------------------------------------------------------------------------------- /thirdparty/glog/bazel/example/BUILD.bazel: -------------------------------------------------------------------------------- 1 | cc_test( 2 | name = "main", 3 | size = "small", 4 | srcs = ["main.cc"], 5 | deps = [ 6 | "//:glog", 7 | "@com_github_gflags_gflags//:gflags", 8 | ], 9 | ) 10 | -------------------------------------------------------------------------------- /thirdparty/glog/bazel/example/main.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(int argc, char* argv[]) { 6 | // Initialize Google's logging library. 7 | google::InitGoogleLogging(argv[0]); 8 | 9 | // Optional: parse command line flags 10 | gflags::ParseCommandLineFlags(&argc, &argv, true); 11 | 12 | LOG(INFO) << "Hello, world!"; 13 | 14 | // glog/stl_logging.h allows logging STL containers. 15 | std::vector x; 16 | x.push_back(1); 17 | x.push_back(2); 18 | x.push_back(3); 19 | LOG(INFO) << "ABC, it's easy as " << x; 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /thirdparty/glog/cmake/DetermineGflagsNamespace.cmake: -------------------------------------------------------------------------------- 1 | macro(determine_gflags_namespace VARIABLE) 2 | if (NOT DEFINED "${VARIABLE}") 3 | if (CMAKE_REQUIRED_INCLUDES) 4 | set (CHECK_INCLUDE_FILE_CXX_INCLUDE_DIRS "-DINCLUDE_DIRECTORIES=${CMAKE_REQUIRED_INCLUDES}") 5 | else () 6 | set (CHECK_INCLUDE_FILE_CXX_INCLUDE_DIRS) 7 | endif () 8 | 9 | set(MACRO_CHECK_INCLUDE_FILE_FLAGS ${CMAKE_REQUIRED_FLAGS}) 10 | 11 | set(_NAMESPACES gflags google) 12 | set(_check_code 13 | " 14 | #include 15 | 16 | int main(int argc, char**argv) 17 | { 18 | GLOG_GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true); 19 | } 20 | ") 21 | if (NOT CMAKE_REQUIRED_QUIET) 22 | message (STATUS "Looking for gflags namespace") 23 | endif () 24 | if (${ARGC} EQUAL 3) 25 | set (CMAKE_CXX_FLAGS_SAVE ${CMAKE_CXX_FLAGS}) 26 | set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ARGV2}") 27 | endif () 28 | 29 | set (_check_file 30 | ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/DetermineGflagsNamespace.cxx) 31 | 32 | foreach (_namespace ${_NAMESPACES}) 33 | file (WRITE "${_check_file}" "${_check_code}") 34 | try_compile (${VARIABLE} 35 | "${CMAKE_BINARY_DIR}" "${_check_file}" 36 | COMPILE_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS}" -DGLOG_GFLAGS_NAMESPACE=${_namespace} 37 | LINK_LIBRARIES gflags 38 | CMAKE_FLAGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} 39 | OUTPUT_VARIABLE OUTPUT) 40 | 41 | if (${VARIABLE}) 42 | set (${VARIABLE} ${_namespace} CACHE INTERNAL "gflags namespace" FORCE) 43 | break () 44 | else () 45 | file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log 46 | "Determining the gflags namespace ${_namespace} failed with the following output:\n" 47 | "${OUTPUT}\n\n") 48 | endif () 49 | endforeach (_namespace) 50 | 51 | if (${ARGC} EQUAL 3) 52 | set (CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS_SAVE}) 53 | endif () 54 | 55 | if (${VARIABLE}) 56 | if (NOT CMAKE_REQUIRED_QUIET) 57 | message (STATUS "Looking for gflags namespace - ${${VARIABLE}}") 58 | endif () 59 | file (APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log 60 | "Determining the gflags namespace passed with the following output:\n" 61 | "${OUTPUT}\n\n") 62 | else () 63 | if (NOT CMAKE_REQUIRED_QUIET) 64 | message (STATUS "Looking for gflags namespace - failed") 65 | endif () 66 | set (${VARIABLE} ${_namespace} CACHE INTERNAL "gflags namespace") 67 | endif () 68 | endif () 69 | endmacro () 70 | -------------------------------------------------------------------------------- /thirdparty/glog/cmake/FindUnwind.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find libunwind 2 | # Once done this will define 3 | # 4 | # Unwind_FOUND - system has libunwind 5 | # unwind::unwind - cmake target for libunwind 6 | 7 | include (FindPackageHandleStandardArgs) 8 | 9 | find_path (Unwind_INCLUDE_DIR NAMES unwind.h libunwind.h DOC "unwind include directory") 10 | find_library (Unwind_LIBRARY NAMES unwind DOC "unwind library") 11 | 12 | mark_as_advanced (Unwind_INCLUDE_DIR Unwind_LIBRARY) 13 | 14 | # Extract version information 15 | if (Unwind_LIBRARY) 16 | set (_Unwind_VERSION_HEADER ${Unwind_INCLUDE_DIR}/libunwind-common.h) 17 | 18 | if (EXISTS ${_Unwind_VERSION_HEADER}) 19 | file (READ ${_Unwind_VERSION_HEADER} _Unwind_VERSION_CONTENTS) 20 | 21 | string (REGEX REPLACE ".*#define UNW_VERSION_MAJOR[ \t]+([0-9]+).*" "\\1" 22 | Unwind_VERSION_MAJOR "${_Unwind_VERSION_CONTENTS}") 23 | string (REGEX REPLACE ".*#define UNW_VERSION_MINOR[ \t]+([0-9]+).*" "\\1" 24 | Unwind_VERSION_MINOR "${_Unwind_VERSION_CONTENTS}") 25 | string (REGEX REPLACE ".*#define UNW_VERSION_EXTRA[ \t]+([0-9]+).*" "\\1" 26 | Unwind_VERSION_PATCH "${_Unwind_VERSION_CONTENTS}") 27 | 28 | set (Unwind_VERSION ${Unwind_VERSION_MAJOR}.${Unwind_VERSION_MINOR}) 29 | 30 | if (CMAKE_MATCH_0) 31 | # Third version component may be empty 32 | set (Unwind_VERSION ${Unwind_VERSION}.${Unwind_VERSION_PATCH}) 33 | set (Unwind_VERSION_COMPONENTS 3) 34 | else (CMAKE_MATCH_0) 35 | set (Unwind_VERSION_COMPONENTS 2) 36 | endif (CMAKE_MATCH_0) 37 | endif (EXISTS ${_Unwind_VERSION_HEADER}) 38 | endif (Unwind_LIBRARY) 39 | 40 | # handle the QUIETLY and REQUIRED arguments and set Unwind_FOUND to TRUE 41 | # if all listed variables are TRUE 42 | find_package_handle_standard_args (Unwind 43 | REQUIRED_VARS Unwind_INCLUDE_DIR Unwind_LIBRARY 44 | VERSION_VAR Unwind_VERSION 45 | ) 46 | 47 | if (Unwind_FOUND) 48 | if (NOT TARGET unwind::unwind) 49 | add_library (unwind::unwind INTERFACE IMPORTED) 50 | 51 | set_property (TARGET unwind::unwind PROPERTY 52 | INTERFACE_INCLUDE_DIRECTORIES ${Unwind_INCLUDE_DIR} 53 | ) 54 | set_property (TARGET unwind::unwind PROPERTY 55 | INTERFACE_LINK_LIBRARIES ${Unwind_LIBRARY} 56 | ) 57 | set_property (TARGET unwind::unwind PROPERTY 58 | IMPORTED_CONFIGURATIONS RELEASE 59 | ) 60 | endif (NOT TARGET unwind::unwind) 61 | endif (Unwind_FOUND) 62 | -------------------------------------------------------------------------------- /thirdparty/glog/cmake/RunCleanerTest1.cmake: -------------------------------------------------------------------------------- 1 | set (RUNS 3) 2 | 3 | foreach (iter RANGE 1 ${RUNS}) 4 | set (ENV{GOOGLE_LOG_DIR} ${TEST_DIR}) 5 | execute_process (COMMAND ${LOGCLEANUP} RESULT_VARIABLE _RESULT) 6 | 7 | if (NOT _RESULT EQUAL 0) 8 | message (FATAL_ERROR "Failed to run logcleanup_unittest (error: ${_RESULT})") 9 | endif (NOT _RESULT EQUAL 0) 10 | 11 | # Ensure the log files to have different modification timestamps such that 12 | # exactly one log file remains at the end. Otherwise all log files will be 13 | # retained. 14 | execute_process (COMMAND ${CMAKE_COMMAND} -E sleep 1) 15 | endforeach (iter) 16 | 17 | file (GLOB LOG_FILES ${TEST_DIR}/*.foobar) 18 | list (LENGTH LOG_FILES NUM_FILES) 19 | 20 | if (NOT NUM_FILES EQUAL 1) 21 | message (SEND_ERROR "Expected 1 log file in log directory but found ${NUM_FILES}") 22 | endif (NOT NUM_FILES EQUAL 1) 23 | -------------------------------------------------------------------------------- /thirdparty/glog/cmake/RunCleanerTest2.cmake: -------------------------------------------------------------------------------- 1 | set (RUNS 3) 2 | 3 | foreach (iter RANGE 1 ${RUNS}) 4 | execute_process (COMMAND ${LOGCLEANUP} -log_dir=${TEST_DIR} 5 | RESULT_VARIABLE _RESULT) 6 | 7 | if (NOT _RESULT EQUAL 0) 8 | message (FATAL_ERROR "Failed to run logcleanup_unittest (error: ${_RESULT})") 9 | endif (NOT _RESULT EQUAL 0) 10 | 11 | # Ensure the log files to have different modification timestamps such that 12 | # exactly one log file remains at the end. Otherwise all log files will be 13 | # retained. 14 | execute_process (COMMAND ${CMAKE_COMMAND} -E sleep 1) 15 | endforeach (iter) 16 | 17 | file (GLOB LOG_FILES ${TEST_DIR}/test_cleanup_*.barfoo) 18 | list (LENGTH LOG_FILES NUM_FILES) 19 | 20 | if (NOT NUM_FILES EQUAL 1) 21 | message (SEND_ERROR "Expected 1 log file in build directory ${TEST_DIR} but found ${NUM_FILES}") 22 | endif (NOT NUM_FILES EQUAL 1) 23 | -------------------------------------------------------------------------------- /thirdparty/glog/cmake/RunCleanerTest3.cmake: -------------------------------------------------------------------------------- 1 | set (RUNS 3) 2 | 3 | # Create the subdirectory required by this unit test. 4 | file (MAKE_DIRECTORY ${TEST_DIR}/${TEST_SUBDIR}) 5 | 6 | foreach (iter RANGE 1 ${RUNS}) 7 | execute_process (COMMAND ${LOGCLEANUP} -log_dir=${TEST_DIR} 8 | RESULT_VARIABLE _RESULT) 9 | 10 | if (NOT _RESULT EQUAL 0) 11 | message (FATAL_ERROR "Failed to run logcleanup_unittest (error: ${_RESULT})") 12 | endif (NOT _RESULT EQUAL 0) 13 | 14 | # Ensure the log files to have different modification timestamps such that 15 | # exactly one log file remains at the end. Otherwise all log files will be 16 | # retained. 17 | execute_process (COMMAND ${CMAKE_COMMAND} -E sleep 2) 18 | endforeach (iter) 19 | 20 | file (GLOB LOG_FILES ${TEST_DIR}/${TEST_SUBDIR}/test_cleanup_*.relativefoo) 21 | list (LENGTH LOG_FILES NUM_FILES) 22 | 23 | if (NOT NUM_FILES EQUAL 1) 24 | message (SEND_ERROR "Expected 1 log file in build directory ${TEST_DIR}${TEST_SUBDIR} but found ${NUM_FILES}") 25 | endif (NOT NUM_FILES EQUAL 1) 26 | 27 | # Remove the subdirectory required by this unit test. 28 | file (REMOVE_RECURSE ${TEST_DIR}/${TEST_SUBDIR}) 29 | -------------------------------------------------------------------------------- /thirdparty/glog/cmake/TestInitPackageConfig.cmake: -------------------------------------------------------------------------------- 1 | # Create the build directory 2 | execute_process ( 3 | COMMAND ${CMAKE_COMMAND} -E make_directory ${TEST_BINARY_DIR} 4 | RESULT_VARIABLE _DIRECTORY_CREATED_SUCCEEDED 5 | ) 6 | 7 | if (NOT _DIRECTORY_CREATED_SUCCEEDED EQUAL 0) 8 | message (FATAL_ERROR "Failed to create build directory") 9 | endif (NOT _DIRECTORY_CREATED_SUCCEEDED EQUAL 0) 10 | 11 | file (WRITE ${INITIAL_CACHE} "${CACHEVARS}") 12 | -------------------------------------------------------------------------------- /thirdparty/glog/cmake/TestPackageConfig.cmake: -------------------------------------------------------------------------------- 1 | # Create the build directory 2 | execute_process ( 3 | COMMAND ${CMAKE_COMMAND} -E make_directory ${TEST_BINARY_DIR} 4 | RESULT_VARIABLE _DIRECTORY_CREATED_SUCCEEDED 5 | ) 6 | 7 | if (NOT _DIRECTORY_CREATED_SUCCEEDED EQUAL 0) 8 | message (FATAL_ERROR "Failed to create build directory") 9 | endif (NOT _DIRECTORY_CREATED_SUCCEEDED EQUAL 0) 10 | 11 | if (GENERATOR_TOOLSET) 12 | list (APPEND _ADDITIONAL_ARGS -T ${GENERATOR_TOOLSET}) 13 | endif (GENERATOR_TOOLSET) 14 | 15 | if (GENERATOR_PLATFORM) 16 | list (APPEND _ADDITIONAL_ARGS -A ${GENERATOR_PLATFORM}) 17 | endif (GENERATOR_PLATFORM) 18 | 19 | # Run CMake 20 | execute_process ( 21 | # Capture the PATH environment variable content set during project generation 22 | # stage. This is required because later during the build stage the PATH is 23 | # modified again (e.g., for MinGW AppVeyor CI builds) by adding back the 24 | # directory containing git.exe. Incidently, the Git installation directory 25 | # also contains sh.exe which causes MinGW Makefile generation to fail. 26 | COMMAND ${CMAKE_COMMAND} env PATH=${PATH} 27 | ${CMAKE_COMMAND} -C ${INITIAL_CACHE} 28 | -G ${GENERATOR} 29 | ${_ADDITIONAL_ARGS} 30 | -DCMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY=ON 31 | -DCMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY=ON 32 | -DCMAKE_PREFIX_PATH=${PACKAGE_DIR} 33 | ${SOURCE_DIR} 34 | WORKING_DIRECTORY ${TEST_BINARY_DIR} 35 | RESULT_VARIABLE _GENERATE_SUCCEEDED 36 | ) 37 | 38 | if (NOT _GENERATE_SUCCEEDED EQUAL 0) 39 | message (FATAL_ERROR "Failed to generate project files using CMake") 40 | endif (NOT _GENERATE_SUCCEEDED EQUAL 0) 41 | -------------------------------------------------------------------------------- /thirdparty/glog/glog-config.cmake.in: -------------------------------------------------------------------------------- 1 | if (CMAKE_VERSION VERSION_LESS @glog_CMake_VERSION@) 2 | message (FATAL_ERROR "CMake >= @glog_CMake_VERSION@ required") 3 | endif (CMAKE_VERSION VERSION_LESS @glog_CMake_VERSION@) 4 | 5 | @PACKAGE_INIT@ 6 | 7 | include (CMakeFindDependencyMacro) 8 | include (${CMAKE_CURRENT_LIST_DIR}/glog-modules.cmake) 9 | 10 | @gflags_DEPENDENCY@ 11 | @Unwind_DEPENDENCY@ 12 | 13 | include (${CMAKE_CURRENT_LIST_DIR}/glog-targets.cmake) 14 | -------------------------------------------------------------------------------- /thirdparty/glog/glog-modules.cmake.in: -------------------------------------------------------------------------------- 1 | cmake_policy (PUSH) 2 | cmake_policy (SET CMP0057 NEW) 3 | 4 | if (CMAKE_VERSION VERSION_LESS 3.3) 5 | message (FATAL_ERROR "glog-modules.cmake requires the consumer " 6 | "to use CMake 3.3 (or newer)") 7 | endif (CMAKE_VERSION VERSION_LESS 3.3) 8 | 9 | set (glog_MODULE_PATH "@glog_FULL_CMake_DATADIR@") 10 | list (APPEND CMAKE_MODULE_PATH ${glog_MODULE_PATH}) 11 | 12 | if (NOT glog_MODULE_PATH IN_LIST CMAKE_MODULE_PATH) 13 | message (FATAL_ERROR "Cannot add '${glog_MODULE_PATH}' to " 14 | "CMAKE_MODULE_PATH. This will cause glog-config.cmake to fail at " 15 | "locating required find modules. Make sure CMAKE_MODULE_PATH is not a cache variable.") 16 | endif (NOT glog_MODULE_PATH IN_LIST CMAKE_MODULE_PATH) 17 | 18 | cmake_policy (POP) 19 | -------------------------------------------------------------------------------- /thirdparty/glog/libglog.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: libglog 7 | Description: Google Log (glog) C++ logging framework 8 | Version: @VERSION@ 9 | Libs: -L${libdir} -lglog 10 | Libs.private: @glog_libraries_options_for_static_linking@ 11 | Cflags: -I${includedir} 12 | -------------------------------------------------------------------------------- /thirdparty/glog/src/base/googleinit.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 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 | // --- 31 | // Author: Jacob Hoffman-Andrews 32 | 33 | #ifndef _GOOGLEINIT_H 34 | #define _GOOGLEINIT_H 35 | 36 | class GoogleInitializer { 37 | public: 38 | typedef void (*void_function)(void); 39 | GoogleInitializer(const char*, void_function f) { 40 | f(); 41 | } 42 | }; 43 | 44 | #define REGISTER_MODULE_INITIALIZER(name, body) \ 45 | namespace { \ 46 | static void google_init_module_##name () { body; } \ 47 | GoogleInitializer google_initializer_module_##name(#name, \ 48 | google_init_module_##name); \ 49 | } 50 | 51 | #endif /* _GOOGLEINIT_H */ 52 | -------------------------------------------------------------------------------- /thirdparty/glog/src/glog/platform.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 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: Shinichiro Hamaji 31 | // 32 | // Detect supported platforms. 33 | 34 | #ifndef GLOG_PLATFORM_H 35 | #define GLOG_PLATFORM_H 36 | 37 | #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) 38 | #define GLOG_OS_WINDOWS 39 | #elif defined(__CYGWIN__) || defined(__CYGWIN32__) 40 | #define GLOG_OS_CYGWIN 41 | #elif defined(linux) || defined(__linux) || defined(__linux__) 42 | #ifndef GLOG_OS_LINUX 43 | #define GLOG_OS_LINUX 44 | #endif 45 | #elif defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__) 46 | #define GLOG_OS_MACOSX 47 | #elif defined(__FreeBSD__) 48 | #define GLOG_OS_FREEBSD 49 | #elif defined(__NetBSD__) 50 | #define GLOG_OS_NETBSD 51 | #elif defined(__OpenBSD__) 52 | #define GLOG_OS_OPENBSD 53 | #else 54 | // TODO(hamaji): Add other platforms. 55 | #error Platform not supported by glog. Please consider to contribute platform information by submitting a pull request on Github. 56 | #endif 57 | 58 | #endif // GLOG_PLATFORM_H 59 | -------------------------------------------------------------------------------- /thirdparty/glog/src/logging_striptest10.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 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: Sergey Ioffe 31 | 32 | #define GOOGLE_STRIP_LOG 10 33 | 34 | // Include the actual test. 35 | #include "logging_striptest_main.cc" 36 | -------------------------------------------------------------------------------- /thirdparty/glog/src/logging_striptest2.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 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: Sergey Ioffe 31 | 32 | #define GOOGLE_STRIP_LOG 2 33 | 34 | // Include the actual test. 35 | #include "logging_striptest_main.cc" 36 | -------------------------------------------------------------------------------- /thirdparty/glog/src/package_config_unittest/working_config/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.16) 2 | project (glog_package_config LANGUAGES CXX) 3 | 4 | find_package (glog REQUIRED NO_MODULE) 5 | 6 | add_executable (glog_package_config glog_package_config.cc) 7 | 8 | target_link_libraries (glog_package_config PRIVATE glog::glog) 9 | -------------------------------------------------------------------------------- /thirdparty/glog/src/package_config_unittest/working_config/glog_package_config.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int /*argc*/, char** argv) 4 | { 5 | google::InitGoogleLogging(argv[0]); 6 | } 7 | -------------------------------------------------------------------------------- /thirdparty/glog/src/stacktrace.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2000 - 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 | // Routines to extract the current stack trace. These functions are 31 | // thread-safe. 32 | 33 | #ifndef BASE_STACKTRACE_H_ 34 | #define BASE_STACKTRACE_H_ 35 | 36 | #include "config.h" 37 | #include 38 | 39 | _START_GOOGLE_NAMESPACE_ 40 | 41 | // This is similar to the GetStackFrames routine, except that it returns 42 | // the stack trace only, and not the stack frame sizes as well. 43 | // Example: 44 | // main() { foo(); } 45 | // foo() { bar(); } 46 | // bar() { 47 | // void* result[10]; 48 | // int depth = GetStackFrames(result, 10, 1); 49 | // } 50 | // 51 | // This produces: 52 | // result[0] foo 53 | // result[1] main 54 | // .... ... 55 | // 56 | // "result" must not be NULL. 57 | GOOGLE_GLOG_DLL_DECL int GetStackTrace(void** result, int max_depth, int skip_count); 58 | 59 | _END_GOOGLE_NAMESPACE_ 60 | 61 | #endif // BASE_STACKTRACE_H_ 62 | -------------------------------------------------------------------------------- /thirdparty/glog/src/stacktrace_windows-inl.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2000 - 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: Andrew Schwartzmeyer 31 | // 32 | // Windows implementation - just use CaptureStackBackTrace 33 | 34 | #include "config.h" 35 | #include "port.h" 36 | #include "stacktrace.h" 37 | #include 38 | 39 | _START_GOOGLE_NAMESPACE_ 40 | 41 | int GetStackTrace(void** result, int max_depth, int skip_count) { 42 | if (max_depth > 64) { 43 | max_depth = 64; 44 | } 45 | skip_count++; // we want to skip the current frame as well 46 | // This API is thread-safe (moreover it walks only the current thread). 47 | return CaptureStackBackTrace(static_cast(skip_count), static_cast(max_depth), result, NULL); 48 | } 49 | 50 | _END_GOOGLE_NAMESPACE_ 51 | -------------------------------------------------------------------------------- /thirdparty/glog/src/utilities_unittest.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 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: Shinichiro Hamaji 31 | #include "utilities.h" 32 | #include "googletest.h" 33 | #include 34 | 35 | #ifdef HAVE_LIB_GFLAGS 36 | #include 37 | using namespace GFLAGS_NAMESPACE; 38 | #endif 39 | 40 | using namespace GOOGLE_NAMESPACE; 41 | 42 | TEST(utilities, sync_val_compare_and_swap) { 43 | bool now_entering = false; 44 | EXPECT_FALSE(sync_val_compare_and_swap(&now_entering, false, true)); 45 | EXPECT_TRUE(sync_val_compare_and_swap(&now_entering, false, true)); 46 | EXPECT_TRUE(sync_val_compare_and_swap(&now_entering, false, true)); 47 | } 48 | 49 | TEST(utilities, InitGoogleLoggingDeathTest) { 50 | ASSERT_DEATH(InitGoogleLogging("foobar"), ""); 51 | } 52 | 53 | int main(int argc, char **argv) { 54 | InitGoogleLogging(argv[0]); 55 | InitGoogleTest(&argc, argv); 56 | 57 | CHECK_EQ(RUN_ALL_TESTS(), 0); 58 | } 59 | -------------------------------------------------------------------------------- /thirdparty/googletest/cmake/Config.cmake.in: -------------------------------------------------------------------------------- 1 | @PACKAGE_INIT@ 2 | include(CMakeFindDependencyMacro) 3 | if (@GTEST_HAS_PTHREAD@) 4 | set(THREADS_PREFER_PTHREAD_FLAG @THREADS_PREFER_PTHREAD_FLAG@) 5 | find_dependency(Threads) 6 | endif() 7 | 8 | include("${CMAKE_CURRENT_LIST_DIR}/@targets_export_name@.cmake") 9 | check_required_components("@project_name@") 10 | -------------------------------------------------------------------------------- /thirdparty/googletest/cmake/gtest.pc.in: -------------------------------------------------------------------------------- 1 | libdir=@CMAKE_INSTALL_FULL_LIBDIR@ 2 | includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ 3 | 4 | Name: gtest 5 | Description: GoogleTest (without main() function) 6 | Version: @PROJECT_VERSION@ 7 | URL: https://github.com/google/googletest 8 | Libs: -L${libdir} -lgtest @CMAKE_THREAD_LIBS_INIT@ 9 | Cflags: -I${includedir} @GTEST_HAS_PTHREAD_MACRO@ 10 | -------------------------------------------------------------------------------- /thirdparty/googletest/cmake/gtest_main.pc.in: -------------------------------------------------------------------------------- 1 | libdir=@CMAKE_INSTALL_FULL_LIBDIR@ 2 | includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ 3 | 4 | Name: gtest_main 5 | Description: GoogleTest (with main() function) 6 | Version: @PROJECT_VERSION@ 7 | URL: https://github.com/google/googletest 8 | Requires: gtest = @PROJECT_VERSION@ 9 | Libs: -L${libdir} -lgtest_main @CMAKE_THREAD_LIBS_INIT@ 10 | Cflags: -I${includedir} @GTEST_HAS_PTHREAD_MACRO@ 11 | -------------------------------------------------------------------------------- /thirdparty/googletest/cmake/libgtest.la.in: -------------------------------------------------------------------------------- 1 | # libgtest.la - a libtool library file 2 | # Generated by libtool (GNU libtool) 2.4.6 3 | 4 | # Please DO NOT delete this file! 5 | # It is necessary for linking the library. 6 | 7 | # Names of this library. 8 | library_names='libgtest.so' 9 | 10 | # Is this an already installed library? 11 | installed=yes 12 | 13 | # Should we warn about portability when linking against -modules? 14 | shouldnotlink=no 15 | 16 | # Files to dlopen/dlpreopen 17 | dlopen='' 18 | dlpreopen='' 19 | 20 | # Directory that this library needs to be installed in: 21 | libdir='@CMAKE_INSTALL_FULL_LIBDIR@' 22 | -------------------------------------------------------------------------------- /thirdparty/googletest/docs/README.md: -------------------------------------------------------------------------------- 1 | # Content Moved 2 | 3 | We are working on updates to the GoogleTest documentation, which has moved to 4 | the top-level [docs](../../../tp/googletest/docs) directory. 5 | -------------------------------------------------------------------------------- /thirdparty/googletest/include/gtest/internal/custom/README.md: -------------------------------------------------------------------------------- 1 | # Customization Points 2 | 3 | The custom directory is an injection point for custom user configurations. 4 | 5 | ## Header `gtest.h` 6 | 7 | ### The following macros can be defined: 8 | 9 | * `GTEST_OS_STACK_TRACE_GETTER_` - The name of an implementation of 10 | `OsStackTraceGetterInterface`. 11 | * `GTEST_CUSTOM_TEMPDIR_FUNCTION_` - An override for `testing::TempDir()`. See 12 | `testing::TempDir` for semantics and signature. 13 | 14 | ## Header `gtest-port.h` 15 | 16 | The following macros can be defined: 17 | 18 | ### Flag related macros: 19 | 20 | * `GTEST_FLAG(flag_name)` 21 | * `GTEST_USE_OWN_FLAGFILE_FLAG_` - Define to 0 when the system provides its 22 | own flagfile flag parsing. 23 | * `GTEST_DECLARE_bool_(name)` 24 | * `GTEST_DECLARE_int32_(name)` 25 | * `GTEST_DECLARE_string_(name)` 26 | * `GTEST_DEFINE_bool_(name, default_val, doc)` 27 | * `GTEST_DEFINE_int32_(name, default_val, doc)` 28 | * `GTEST_DEFINE_string_(name, default_val, doc)` 29 | 30 | ### Logging: 31 | 32 | * `GTEST_LOG_(severity)` 33 | * `GTEST_CHECK_(condition)` 34 | * Functions `LogToStderr()` and `FlushInfoLog()` have to be provided too. 35 | 36 | ### Threading: 37 | 38 | * `GTEST_HAS_NOTIFICATION_` - Enabled if Notification is already provided. 39 | * `GTEST_HAS_MUTEX_AND_THREAD_LOCAL_` - Enabled if `Mutex` and `ThreadLocal` 40 | are already provided. Must also provide `GTEST_DECLARE_STATIC_MUTEX_(mutex)` 41 | and `GTEST_DEFINE_STATIC_MUTEX_(mutex)` 42 | * `GTEST_EXCLUSIVE_LOCK_REQUIRED_(locks)` 43 | * `GTEST_LOCK_EXCLUDED_(locks)` 44 | 45 | ### Underlying library support features 46 | 47 | * `GTEST_HAS_CXXABI_H_` 48 | 49 | ### Exporting API symbols: 50 | 51 | * `GTEST_API_` - Specifier for exported symbols. 52 | 53 | ## Header `gtest-printers.h` 54 | 55 | * See documentation at `gtest/gtest-printers.h` for details on how to define a 56 | custom printer. 57 | -------------------------------------------------------------------------------- /thirdparty/googletest/include/gtest/internal/custom/gtest-port.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015, 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 | // Injection point for custom user configurations. See README for details 31 | // 32 | // ** Custom implementation starts here ** 33 | 34 | #ifndef GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PORT_H_ 35 | #define GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PORT_H_ 36 | 37 | #endif // GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PORT_H_ 38 | -------------------------------------------------------------------------------- /thirdparty/googletest/include/gtest/internal/custom/gtest-printers.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015, 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 | // This file provides an injection point for custom printers in a local 31 | // installation of gTest. 32 | // It will be included from gtest-printers.h and the overrides in this file 33 | // will be visible to everyone. 34 | // 35 | // Injection point for custom user configurations. See README for details 36 | // 37 | // ** Custom implementation starts here ** 38 | 39 | #ifndef GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_ 40 | #define GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_ 41 | 42 | #endif // GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_ 43 | -------------------------------------------------------------------------------- /thirdparty/googletest/include/gtest/internal/custom/gtest.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015, 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 | // Injection point for custom user configurations. See README for details 31 | // 32 | // ** Custom implementation starts here ** 33 | 34 | #ifndef GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_ 35 | #define GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_ 36 | 37 | #endif // GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_ 38 | -------------------------------------------------------------------------------- /thirdparty/googletest/samples/sample1.h: -------------------------------------------------------------------------------- 1 | // Copyright 2005, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | // A sample program demonstrating using Google C++ testing framework. 31 | 32 | #ifndef GOOGLETEST_SAMPLES_SAMPLE1_H_ 33 | #define GOOGLETEST_SAMPLES_SAMPLE1_H_ 34 | 35 | // Returns n! (the factorial of n). For negative n, n! is defined to be 1. 36 | int Factorial(int n); 37 | 38 | // Returns true if and only if n is a prime number. 39 | bool IsPrime(int n); 40 | 41 | #endif // GOOGLETEST_SAMPLES_SAMPLE1_H_ 42 | -------------------------------------------------------------------------------- /thirdparty/googletest/samples/sample2.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2005, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | // A sample program demonstrating using Google C++ testing framework. 31 | 32 | #include "sample2.h" 33 | 34 | #include 35 | 36 | // Clones a 0-terminated C string, allocating memory using new. 37 | const char* MyString::CloneCString(const char* a_c_string) { 38 | if (a_c_string == nullptr) return nullptr; 39 | 40 | const size_t len = strlen(a_c_string); 41 | char* const clone = new char[ len + 1 ]; 42 | memcpy(clone, a_c_string, len + 1); 43 | 44 | return clone; 45 | } 46 | 47 | // Sets the 0-terminated C string this MyString object 48 | // represents. 49 | void MyString::Set(const char* a_c_string) { 50 | // Makes sure this works when c_string == c_string_ 51 | const char* const temp = MyString::CloneCString(a_c_string); 52 | delete[] c_string_; 53 | c_string_ = temp; 54 | } 55 | -------------------------------------------------------------------------------- /thirdparty/googletest/samples/sample4.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2005, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | // A sample program demonstrating using Google C++ testing framework. 31 | 32 | #include 33 | 34 | #include "sample4.h" 35 | 36 | // Returns the current counter value, and increments it. 37 | int Counter::Increment() { 38 | return counter_++; 39 | } 40 | 41 | // Returns the current counter value, and decrements it. 42 | // counter can not be less than 0, return 0 in this case 43 | int Counter::Decrement() { 44 | if (counter_ == 0) { 45 | return counter_; 46 | } else { 47 | return counter_--; 48 | } 49 | } 50 | 51 | // Prints the current counter value to STDOUT. 52 | void Counter::Print() const { 53 | printf("%d", counter_); 54 | } 55 | -------------------------------------------------------------------------------- /thirdparty/googletest/samples/sample4.h: -------------------------------------------------------------------------------- 1 | // Copyright 2005, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | // A sample program demonstrating using Google C++ testing framework. 31 | #ifndef GOOGLETEST_SAMPLES_SAMPLE4_H_ 32 | #define GOOGLETEST_SAMPLES_SAMPLE4_H_ 33 | 34 | // A simple monotonic counter. 35 | class Counter { 36 | private: 37 | int counter_; 38 | 39 | public: 40 | // Creates a counter that starts at 0. 41 | Counter() : counter_(0) {} 42 | 43 | // Returns the current counter value, and increments it. 44 | int Increment(); 45 | 46 | // Returns the current counter value, and decrements it. 47 | int Decrement(); 48 | 49 | // Prints the current counter value to STDOUT. 50 | void Print() const; 51 | }; 52 | 53 | #endif // GOOGLETEST_SAMPLES_SAMPLE4_H_ 54 | -------------------------------------------------------------------------------- /thirdparty/googletest/samples/sample4_unittest.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2005, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | 31 | #include "sample4.h" 32 | #include "gtest/gtest.h" 33 | 34 | namespace { 35 | // Tests the Increment() method. 36 | 37 | TEST(Counter, Increment) { 38 | Counter c; 39 | 40 | // Test that counter 0 returns 0 41 | EXPECT_EQ(0, c.Decrement()); 42 | 43 | // EXPECT_EQ() evaluates its arguments exactly once, so they 44 | // can have side effects. 45 | 46 | EXPECT_EQ(0, c.Increment()); 47 | EXPECT_EQ(1, c.Increment()); 48 | EXPECT_EQ(2, c.Increment()); 49 | 50 | EXPECT_EQ(3, c.Decrement()); 51 | } 52 | 53 | } // namespace 54 | -------------------------------------------------------------------------------- /thirdparty/googletest/scripts/README.md: -------------------------------------------------------------------------------- 1 | # Please Note: 2 | 3 | Files in this directory are no longer supported by the maintainers. They 4 | represent mosty historical artifacts and supported by the community only. There 5 | is no guarantee whatsoever that these scripts still work. 6 | -------------------------------------------------------------------------------- /thirdparty/googletest/scripts/run_with_path.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright 2010 Google Inc. All Rights Reserved. 4 | 5 | """Runs program specified in the command line with the substituted PATH. 6 | 7 | This script is needed for to support building under Pulse which is unable 8 | to override the existing PATH variable. 9 | """ 10 | 11 | import os 12 | import subprocess 13 | import sys 14 | 15 | SUBST_PATH_ENV_VAR_NAME = "SUBST_PATH" 16 | 17 | def main(): 18 | if SUBST_PATH_ENV_VAR_NAME in os.environ: 19 | os.environ["PATH"] = os.environ[SUBST_PATH_ENV_VAR_NAME] 20 | 21 | exit_code = subprocess.Popen(sys.argv[1:]).wait() 22 | 23 | # exit_code is negative (-signal) if the process has been terminated by 24 | # a signal. Returning negative exit code is not portable and so we return 25 | # 100 instead. 26 | if exit_code < 0: 27 | exit_code = 100 28 | 29 | sys.exit(exit_code) 30 | 31 | if __name__ == "__main__": 32 | main() 33 | -------------------------------------------------------------------------------- /thirdparty/googletest/scripts/test/Makefile: -------------------------------------------------------------------------------- 1 | # A Makefile for fusing Google Test and building a sample test against it. 2 | # 3 | # SYNOPSIS: 4 | # 5 | # make [all] - makes everything. 6 | # make TARGET - makes the given target. 7 | # make check - makes everything and runs the built sample test. 8 | # make clean - removes all files generated by make. 9 | 10 | # Points to the root of fused Google Test, relative to where this file is. 11 | FUSED_GTEST_DIR = output 12 | 13 | # Paths to the fused gtest files. 14 | FUSED_GTEST_H = $(FUSED_GTEST_DIR)/gtest/gtest.h 15 | FUSED_GTEST_ALL_CC = $(FUSED_GTEST_DIR)/gtest/gtest-all.cc 16 | 17 | # Where to find the sample test. 18 | SAMPLE_DIR = ../../samples 19 | 20 | # Where to find gtest_main.cc. 21 | GTEST_MAIN_CC = ../../src/gtest_main.cc 22 | 23 | # Flags passed to the preprocessor. 24 | # We have no idea here whether pthreads is available in the system, so 25 | # disable its use. 26 | CPPFLAGS += -I$(FUSED_GTEST_DIR) -DGTEST_HAS_PTHREAD=0 27 | 28 | # Flags passed to the C++ compiler. 29 | CXXFLAGS += -g 30 | 31 | all : sample1_unittest 32 | 33 | check : all 34 | ./sample1_unittest 35 | 36 | clean : 37 | rm -rf $(FUSED_GTEST_DIR) sample1_unittest *.o 38 | 39 | $(FUSED_GTEST_H) : 40 | ../fuse_gtest_files.py $(FUSED_GTEST_DIR) 41 | 42 | $(FUSED_GTEST_ALL_CC) : 43 | ../fuse_gtest_files.py $(FUSED_GTEST_DIR) 44 | 45 | gtest-all.o : $(FUSED_GTEST_H) $(FUSED_GTEST_ALL_CC) 46 | $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(FUSED_GTEST_DIR)/gtest/gtest-all.cc 47 | 48 | gtest_main.o : $(FUSED_GTEST_H) $(GTEST_MAIN_CC) 49 | $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(GTEST_MAIN_CC) 50 | 51 | sample1.o : $(SAMPLE_DIR)/sample1.cc $(SAMPLE_DIR)/sample1.h 52 | $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(SAMPLE_DIR)/sample1.cc 53 | 54 | sample1_unittest.o : $(SAMPLE_DIR)/sample1_unittest.cc \ 55 | $(SAMPLE_DIR)/sample1.h $(FUSED_GTEST_H) 56 | $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(SAMPLE_DIR)/sample1_unittest.cc 57 | 58 | sample1_unittest : sample1.o sample1_unittest.o gtest-all.o gtest_main.o 59 | $(CXX) $(CPPFLAGS) $(CXXFLAGS) $^ -o $@ 60 | -------------------------------------------------------------------------------- /thirdparty/googletest/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 | // 31 | // Google C++ Testing and Mocking Framework (Google Test) 32 | // 33 | // Sometimes it's desirable to build Google Test by compiling a single file. 34 | // This file serves this purpose. 35 | 36 | // This line ensures that gtest.h can be compiled on its own, even 37 | // when it's fused. 38 | #include "gtest/gtest.h" 39 | 40 | // The following lines pull in the real gtest *.cc files. 41 | #include "src/gtest.cc" 42 | #include "src/gtest-death-test.cc" 43 | #include "src/gtest-filepath.cc" 44 | #include "src/gtest-matchers.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 | -------------------------------------------------------------------------------- /thirdparty/googletest/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 | #include "gtest/gtest.h" 32 | 33 | #if GTEST_OS_ESP8266 || GTEST_OS_ESP32 34 | #if GTEST_OS_ESP8266 35 | extern "C" { 36 | #endif 37 | void setup() { 38 | testing::InitGoogleTest(); 39 | } 40 | 41 | void loop() { RUN_ALL_TESTS(); } 42 | 43 | #if GTEST_OS_ESP8266 44 | } 45 | #endif 46 | 47 | #else 48 | 49 | GTEST_API_ int main(int argc, char **argv) { 50 | printf("Running main() from %s\n", __FILE__); 51 | testing::InitGoogleTest(&argc, argv); 52 | return RUN_ALL_TESTS(); 53 | } 54 | #endif 55 | -------------------------------------------------------------------------------- /thirdparty/googletest/test/googletest-global-environment-unittest_.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2005, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | // Unit test for Google Test global test environments. 31 | // 32 | // The program will be invoked from a Python unit test. Don't run it 33 | // directly. 34 | 35 | #include "gtest/gtest.h" 36 | 37 | namespace { 38 | 39 | // An environment that always fails in its SetUp method. 40 | class FailingEnvironment final : public ::testing::Environment { 41 | public: 42 | void SetUp() override { FAIL() << "Canned environment setup error"; } 43 | }; 44 | 45 | // Register the environment. 46 | auto* const g_environment_ = 47 | ::testing::AddGlobalTestEnvironment(new FailingEnvironment); 48 | 49 | // A test that doesn't actually run. 50 | TEST(SomeTest, DoesFoo) { FAIL() << "Unexpected call"; } 51 | 52 | } // namespace 53 | 54 | int main(int argc, char** argv) { 55 | ::testing::InitGoogleTest(&argc, argv); 56 | 57 | return RUN_ALL_TESTS(); 58 | } 59 | -------------------------------------------------------------------------------- /thirdparty/googletest/test/googletest-param-test-invalid-name1-test_.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | 31 | #include "gtest/gtest.h" 32 | 33 | namespace { 34 | class DummyTest : public ::testing::TestWithParam {}; 35 | 36 | TEST_P(DummyTest, Dummy) { 37 | } 38 | 39 | INSTANTIATE_TEST_SUITE_P(InvalidTestName, 40 | DummyTest, 41 | ::testing::Values("InvalidWithQuotes"), 42 | ::testing::PrintToStringParamName()); 43 | 44 | } // namespace 45 | 46 | int main(int argc, char *argv[]) { 47 | testing::InitGoogleTest(&argc, argv); 48 | return RUN_ALL_TESTS(); 49 | } 50 | 51 | -------------------------------------------------------------------------------- /thirdparty/googletest/test/googletest-param-test-invalid-name2-test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright 2015 Google Inc. All rights reserved. 4 | # 5 | # Redistribution and use in source and binary forms, with or without 6 | # modification, are permitted provided that the following conditions are 7 | # met: 8 | # 9 | # * Redistributions of source code must retain the above copyright 10 | # notice, this list of conditions and the following disclaimer. 11 | # * Redistributions in binary form must reproduce the above 12 | # copyright notice, this list of conditions and the following disclaimer 13 | # in the documentation and/or other materials provided with the 14 | # distribution. 15 | # * Neither the name of Google Inc. nor the names of its 16 | # contributors may be used to endorse or promote products derived from 17 | # this software without specific prior written permission. 18 | # 19 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | """Verifies that Google Test warns the user when not initialized properly.""" 32 | 33 | import gtest_test_utils 34 | 35 | binary_name = 'googletest-param-test-invalid-name2-test_' 36 | COMMAND = gtest_test_utils.GetTestExecutablePath(binary_name) 37 | 38 | 39 | def Assert(condition): 40 | if not condition: 41 | raise AssertionError 42 | 43 | 44 | def TestExitCodeAndOutput(command): 45 | """Runs the given command and verifies its exit code and output.""" 46 | 47 | err = ('Duplicate parameterized test name \'a\'') 48 | 49 | p = gtest_test_utils.Subprocess(command) 50 | Assert(p.terminated_by_signal) 51 | 52 | # Check for appropriate output 53 | Assert(err in p.output) 54 | 55 | 56 | class GTestParamTestInvalidName2Test(gtest_test_utils.TestCase): 57 | 58 | def testExitCodeAndOutput(self): 59 | TestExitCodeAndOutput(COMMAND) 60 | 61 | if __name__ == '__main__': 62 | gtest_test_utils.Main() 63 | -------------------------------------------------------------------------------- /thirdparty/googletest/test/googletest-param-test-invalid-name2-test_.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | 31 | #include "gtest/gtest.h" 32 | 33 | namespace { 34 | class DummyTest : public ::testing::TestWithParam {}; 35 | 36 | std::string StringParamTestSuffix( 37 | const testing::TestParamInfo& info) { 38 | return std::string(info.param); 39 | } 40 | 41 | TEST_P(DummyTest, Dummy) { 42 | } 43 | 44 | INSTANTIATE_TEST_SUITE_P(DuplicateTestNames, 45 | DummyTest, 46 | ::testing::Values("a", "b", "a", "c"), 47 | StringParamTestSuffix); 48 | } // namespace 49 | 50 | int main(int argc, char *argv[]) { 51 | testing::InitGoogleTest(&argc, argv); 52 | return RUN_ALL_TESTS(); 53 | } 54 | 55 | 56 | -------------------------------------------------------------------------------- /thirdparty/googletest/test/googletest-param-test-test.h: -------------------------------------------------------------------------------- 1 | // Copyright 2008, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // The Google C++ Testing and Mocking Framework (Google Test) 31 | // 32 | // This header file provides classes and functions used internally 33 | // for testing Google Test itself. 34 | 35 | #ifndef GOOGLETEST_TEST_GOOGLETEST_PARAM_TEST_TEST_H_ 36 | #define GOOGLETEST_TEST_GOOGLETEST_PARAM_TEST_TEST_H_ 37 | 38 | #include "gtest/gtest.h" 39 | 40 | // Test fixture for testing definition and instantiation of a test 41 | // in separate translation units. 42 | class ExternalInstantiationTest : public ::testing::TestWithParam { 43 | }; 44 | 45 | // Test fixture for testing instantiation of a test in multiple 46 | // translation units. 47 | class InstantiationInMultipleTranslationUnitsTest 48 | : public ::testing::TestWithParam { 49 | }; 50 | 51 | #endif // GOOGLETEST_TEST_GOOGLETEST_PARAM_TEST_TEST_H_ 52 | -------------------------------------------------------------------------------- /thirdparty/googletest/test/googletest-setuptestsuite-test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright 2019, Google Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are 8 | # met: 9 | # 10 | # * Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # * Redistributions in binary form must reproduce the above 13 | # copyright notice, this list of conditions and the following disclaimer 14 | # in the documentation and/or other materials provided with the 15 | # distribution. 16 | # * Neither the name of Google Inc. nor the names of its 17 | # contributors may be used to endorse or promote products derived from 18 | # this software without specific prior written permission. 19 | # 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | """Verifies that SetUpTestSuite and TearDownTestSuite errors are noticed.""" 33 | 34 | import gtest_test_utils 35 | 36 | COMMAND = gtest_test_utils.GetTestExecutablePath( 37 | 'googletest-setuptestsuite-test_') 38 | 39 | 40 | class GTestSetUpTestSuiteTest(gtest_test_utils.TestCase): 41 | 42 | def testSetupErrorAndTearDownError(self): 43 | p = gtest_test_utils.Subprocess(COMMAND) 44 | self.assertNotEqual(p.exit_code, 0, msg=p.output) 45 | 46 | self.assertIn( 47 | '[ FAILED ] SetupFailTest: SetUpTestSuite or TearDownTestSuite\n' 48 | '[ FAILED ] TearDownFailTest: SetUpTestSuite or TearDownTestSuite\n' 49 | '\n' 50 | ' 2 FAILED TEST SUITES\n', 51 | p.output) 52 | 53 | if __name__ == '__main__': 54 | gtest_test_utils.Main() 55 | -------------------------------------------------------------------------------- /thirdparty/googletest/test/googletest-setuptestsuite-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 | 31 | #include "gtest/gtest.h" 32 | 33 | class SetupFailTest : public ::testing::Test { 34 | protected: 35 | static void SetUpTestSuite() { 36 | ASSERT_EQ("", "SET_UP_FAIL"); 37 | } 38 | }; 39 | 40 | TEST_F(SetupFailTest, NoopPassingTest) {} 41 | 42 | class TearDownFailTest : public ::testing::Test { 43 | protected: 44 | static void TearDownTestSuite() { 45 | ASSERT_EQ("", "TEAR_DOWN_FAIL"); 46 | } 47 | }; 48 | 49 | TEST_F(TearDownFailTest, NoopPassingTest) {} 50 | -------------------------------------------------------------------------------- /thirdparty/googletest/test/googletest-uninitialized-test_.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2008, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | 31 | #include "gtest/gtest.h" 32 | 33 | TEST(DummyTest, Dummy) { 34 | // This test doesn't verify anything. We just need it to create a 35 | // realistic stage for testing the behavior of Google Test when 36 | // RUN_ALL_TESTS() is called without 37 | // testing::InitGoogleTest() being called first. 38 | } 39 | 40 | int main() { 41 | return RUN_ALL_TESTS(); 42 | } 43 | -------------------------------------------------------------------------------- /thirdparty/googletest/test/gtest-typed-test2_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2008 Google Inc. 2 | // All Rights Reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | 31 | #include 32 | 33 | #include "test/gtest-typed-test_test.h" 34 | #include "gtest/gtest.h" 35 | 36 | // Tests that the same type-parameterized test case can be 37 | // instantiated in different translation units linked together. 38 | // (ContainerTest is also instantiated in gtest-typed-test_test.cc.) 39 | INSTANTIATE_TYPED_TEST_SUITE_P(Vector, ContainerTest, 40 | testing::Types >); 41 | -------------------------------------------------------------------------------- /thirdparty/googletest/test/gtest-typed-test_test.h: -------------------------------------------------------------------------------- 1 | // Copyright 2008 Google Inc. 2 | // All Rights Reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | #ifndef GOOGLETEST_TEST_GTEST_TYPED_TEST_TEST_H_ 31 | #define GOOGLETEST_TEST_GTEST_TYPED_TEST_TEST_H_ 32 | 33 | #include "gtest/gtest.h" 34 | 35 | using testing::Test; 36 | 37 | // For testing that the same type-parameterized test case can be 38 | // instantiated in different translation units linked together. 39 | // ContainerTest will be instantiated in both gtest-typed-test_test.cc 40 | // and gtest-typed-test2_test.cc. 41 | 42 | template 43 | class ContainerTest : public Test { 44 | }; 45 | 46 | TYPED_TEST_SUITE_P(ContainerTest); 47 | 48 | TYPED_TEST_P(ContainerTest, CanBeDefaultConstructed) { 49 | TypeParam container; 50 | } 51 | 52 | TYPED_TEST_P(ContainerTest, InitialSizeIsZero) { 53 | TypeParam container; 54 | EXPECT_EQ(0U, container.size()); 55 | } 56 | 57 | REGISTER_TYPED_TEST_SUITE_P(ContainerTest, 58 | CanBeDefaultConstructed, InitialSizeIsZero); 59 | 60 | #endif // GOOGLETEST_TEST_GTEST_TYPED_TEST_TEST_H_ 61 | -------------------------------------------------------------------------------- /thirdparty/googletest/test/gtest_all_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2009, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | // 31 | // Tests for Google C++ Testing and Mocking Framework (Google Test) 32 | // 33 | // Sometimes it's desirable to build most of Google Test's own tests 34 | // by compiling a single file. This file serves this purpose. 35 | #include "test/googletest-filepath-test.cc" 36 | #include "test/googletest-message-test.cc" 37 | #include "test/googletest-options-test.cc" 38 | #include "test/googletest-port-test.cc" 39 | #include "test/googletest-test-part-test.cc" 40 | #include "test/gtest-typed-test2_test.cc" 41 | #include "test/gtest-typed-test_test.cc" 42 | #include "test/gtest_pred_impl_unittest.cc" 43 | #include "test/gtest_prod_test.cc" 44 | #include "test/gtest_skip_test.cc" 45 | #include "test/gtest_unittest.cc" 46 | #include "test/production.cc" 47 | -------------------------------------------------------------------------------- /thirdparty/googletest/test/gtest_help_test_.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2009, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | 31 | // This program is meant to be run by gtest_help_test.py. Do not run 32 | // it directly. 33 | 34 | #include "gtest/gtest.h" 35 | 36 | // When a help flag is specified, this program should skip the tests 37 | // and exit with 0; otherwise the following test will be executed, 38 | // causing this program to exit with a non-zero code. 39 | TEST(HelpFlagTest, ShouldNotBeRun) { 40 | ASSERT_TRUE(false) << "Tests shouldn't be run when --help is specified."; 41 | } 42 | 43 | #if GTEST_HAS_DEATH_TEST 44 | TEST(DeathTest, UsedByPythonScriptToDetectSupportForDeathTestsInThisBinary) {} 45 | #endif 46 | -------------------------------------------------------------------------------- /thirdparty/googletest/test/gtest_json_test_utils.py: -------------------------------------------------------------------------------- 1 | # Copyright 2018, 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 | """Unit test utilities for gtest_json_output.""" 31 | 32 | import re 33 | 34 | 35 | def normalize(obj): 36 | """Normalize output object. 37 | 38 | Args: 39 | obj: Google Test's JSON output object to normalize. 40 | 41 | Returns: 42 | Normalized output without any references to transient information that may 43 | change from run to run. 44 | """ 45 | def _normalize(key, value): 46 | if key == 'time': 47 | return re.sub(r'^\d+(\.\d+)?s$', '*', value) 48 | elif key == 'timestamp': 49 | return re.sub(r'^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\dZ$', '*', value) 50 | elif key == 'failure': 51 | value = re.sub(r'^.*[/\\](.*:)\d+\n', '\\1*\n', value) 52 | return re.sub(r'Stack trace:\n(.|\n)*', 'Stack trace:\n*', value) 53 | else: 54 | return normalize(value) 55 | if isinstance(obj, dict): 56 | return {k: _normalize(k, v) for k, v in obj.items()} 57 | if isinstance(obj, list): 58 | return [normalize(x) for x in obj] 59 | else: 60 | return obj 61 | -------------------------------------------------------------------------------- /thirdparty/googletest/test/gtest_main_unittest.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2006, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | 31 | #include "gtest/gtest.h" 32 | 33 | // Tests that we don't have to define main() when we link to 34 | // gtest_main instead of gtest. 35 | 36 | namespace { 37 | 38 | TEST(GTestMainTest, ShouldSucceed) { 39 | } 40 | 41 | } // namespace 42 | 43 | // We are using the main() function defined in gtest_main.cc, so we 44 | // don't define it here. 45 | -------------------------------------------------------------------------------- /thirdparty/googletest/test/gtest_no_test_unittest.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2006, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | // Tests that a Google Test program that has no test defined can run 31 | // successfully. 32 | 33 | #include "gtest/gtest.h" 34 | 35 | int main(int argc, char **argv) { 36 | testing::InitGoogleTest(&argc, argv); 37 | 38 | // An ad-hoc assertion outside of all tests. 39 | // 40 | // This serves three purposes: 41 | // 42 | // 1. It verifies that an ad-hoc assertion can be executed even if 43 | // no test is defined. 44 | // 2. It verifies that a failed ad-hoc assertion causes the test 45 | // program to fail. 46 | // 3. We had a bug where the XML output won't be generated if an 47 | // assertion is executed before RUN_ALL_TESTS() is called, even 48 | // though --gtest_output=xml is specified. This makes sure the 49 | // bug is fixed and doesn't regress. 50 | EXPECT_EQ(1, 2); 51 | 52 | // The above EXPECT_EQ() should cause RUN_ALL_TESTS() to return non-zero. 53 | return RUN_ALL_TESTS() ? 0 : 1; 54 | } 55 | -------------------------------------------------------------------------------- /thirdparty/googletest/test/gtest_prod_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2006, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | // 31 | // Unit test for gtest_prod.h. 32 | 33 | #include "production.h" 34 | #include "gtest/gtest.h" 35 | 36 | // Tests that private members can be accessed from a TEST declared as 37 | // a friend of the class. 38 | TEST(PrivateCodeTest, CanAccessPrivateMembers) { 39 | PrivateCode a; 40 | EXPECT_EQ(0, a.x_); 41 | 42 | a.set_x(1); 43 | EXPECT_EQ(1, a.x_); 44 | } 45 | 46 | typedef testing::Test PrivateCodeFixtureTest; 47 | 48 | // Tests that private members can be accessed from a TEST_F declared 49 | // as a friend of the class. 50 | TEST_F(PrivateCodeFixtureTest, CanAccessPrivateMembers) { 51 | PrivateCode a; 52 | EXPECT_EQ(0, a.x_); 53 | 54 | a.set_x(2); 55 | EXPECT_EQ(2, a.x_); 56 | } 57 | -------------------------------------------------------------------------------- /thirdparty/googletest/test/gtest_skip_check_output_test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright 2019 Google LLC. All Rights Reserved. 4 | # 5 | # Redistribution and use in source and binary forms, with or without 6 | # modification, are permitted provided that the following conditions are 7 | # met: 8 | # 9 | # * Redistributions of source code must retain the above copyright 10 | # notice, this list of conditions and the following disclaimer. 11 | # * Redistributions in binary form must reproduce the above 12 | # copyright notice, this list of conditions and the following disclaimer 13 | # in the documentation and/or other materials provided with the 14 | # distribution. 15 | # * Neither the name of Google Inc. nor the names of its 16 | # contributors may be used to endorse or promote products derived from 17 | # this software without specific prior written permission. 18 | # 19 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | """Tests Google Test's gtest skip in environment setup behavior. 31 | 32 | This script invokes gtest_skip_in_environment_setup_test_ and verifies its 33 | output. 34 | """ 35 | 36 | import gtest_test_utils 37 | import re 38 | 39 | # Path to the gtest_skip_in_environment_setup_test binary 40 | EXE_PATH = gtest_test_utils.GetTestExecutablePath('gtest_skip_test') 41 | 42 | OUTPUT = gtest_test_utils.Subprocess([EXE_PATH]).output 43 | 44 | 45 | # Test. 46 | class SkipEntireEnvironmentTest(gtest_test_utils.TestCase): 47 | 48 | def testSkipEntireEnvironmentTest(self): 49 | self.assertIn('Skipped\nskipping single test\n', OUTPUT) 50 | skip_fixture = 'Skipped\nskipping all tests for this fixture\n' 51 | self.assertIsNotNone( 52 | re.search(skip_fixture + '.*' + skip_fixture, OUTPUT, flags=re.DOTALL), 53 | repr(OUTPUT)) 54 | self.assertNotIn('FAILED', OUTPUT) 55 | 56 | 57 | if __name__ == '__main__': 58 | gtest_test_utils.Main() 59 | -------------------------------------------------------------------------------- /thirdparty/googletest/test/gtest_skip_environment_check_output_test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright 2019 Google LLC. All Rights Reserved. 4 | # 5 | # Redistribution and use in source and binary forms, with or without 6 | # modification, are permitted provided that the following conditions are 7 | # met: 8 | # 9 | # * Redistributions of source code must retain the above copyright 10 | # notice, this list of conditions and the following disclaimer. 11 | # * Redistributions in binary form must reproduce the above 12 | # copyright notice, this list of conditions and the following disclaimer 13 | # in the documentation and/or other materials provided with the 14 | # distribution. 15 | # * Neither the name of Google Inc. nor the names of its 16 | # contributors may be used to endorse or promote products derived from 17 | # this software without specific prior written permission. 18 | # 19 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | """Tests Google Test's gtest skip in environment setup behavior. 31 | 32 | This script invokes gtest_skip_in_environment_setup_test_ and verifies its 33 | output. 34 | """ 35 | 36 | import gtest_test_utils 37 | 38 | # Path to the gtest_skip_in_environment_setup_test binary 39 | EXE_PATH = gtest_test_utils.GetTestExecutablePath( 40 | 'gtest_skip_in_environment_setup_test') 41 | 42 | OUTPUT = gtest_test_utils.Subprocess([EXE_PATH]).output 43 | 44 | 45 | # Test. 46 | class SkipEntireEnvironmentTest(gtest_test_utils.TestCase): 47 | 48 | def testSkipEntireEnvironmentTest(self): 49 | self.assertIn('Skipping the entire environment', OUTPUT) 50 | self.assertNotIn('FAILED', OUTPUT) 51 | 52 | 53 | if __name__ == '__main__': 54 | gtest_test_utils.Main() 55 | -------------------------------------------------------------------------------- /thirdparty/googletest/test/gtest_skip_in_environment_setup_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2019, Google LLC. 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 LLC. 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 | // This test verifies that skipping in the environment results in the 31 | // testcases being skipped. 32 | 33 | #include 34 | #include "gtest/gtest.h" 35 | 36 | class SetupEnvironment : public testing::Environment { 37 | public: 38 | void SetUp() override { GTEST_SKIP() << "Skipping the entire environment"; } 39 | }; 40 | 41 | TEST(Test, AlwaysFails) { EXPECT_EQ(true, false); } 42 | 43 | int main(int argc, char **argv) { 44 | testing::InitGoogleTest(&argc, argv); 45 | 46 | testing::AddGlobalTestEnvironment(new SetupEnvironment()); 47 | 48 | return RUN_ALL_TESTS(); 49 | } 50 | -------------------------------------------------------------------------------- /thirdparty/googletest/test/gtest_skip_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: arseny.aprelev@gmail.com (Arseny Aprelev) 31 | // 32 | 33 | #include "gtest/gtest.h" 34 | 35 | using ::testing::Test; 36 | 37 | TEST(SkipTest, DoesSkip) { 38 | GTEST_SKIP() << "skipping single test"; 39 | EXPECT_EQ(0, 1); 40 | } 41 | 42 | class Fixture : public Test { 43 | protected: 44 | void SetUp() override { 45 | GTEST_SKIP() << "skipping all tests for this fixture"; 46 | } 47 | }; 48 | 49 | TEST_F(Fixture, SkipsOneTest) { 50 | EXPECT_EQ(5, 7); 51 | } 52 | 53 | TEST_F(Fixture, SkipsAnotherTest) { 54 | EXPECT_EQ(99, 100); 55 | } 56 | -------------------------------------------------------------------------------- /thirdparty/googletest/test/gtest_sole_header_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2008, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | // 31 | // This test verifies that it's possible to use Google Test by including 32 | // the gtest.h header file alone. 33 | 34 | #include "gtest/gtest.h" 35 | 36 | namespace { 37 | 38 | void Subroutine() { 39 | EXPECT_EQ(42, 42); 40 | } 41 | 42 | TEST(NoFatalFailureTest, ExpectNoFatalFailure) { 43 | EXPECT_NO_FATAL_FAILURE(;); 44 | EXPECT_NO_FATAL_FAILURE(SUCCEED()); 45 | EXPECT_NO_FATAL_FAILURE(Subroutine()); 46 | EXPECT_NO_FATAL_FAILURE({ SUCCEED(); }); 47 | } 48 | 49 | TEST(NoFatalFailureTest, AssertNoFatalFailure) { 50 | ASSERT_NO_FATAL_FAILURE(;); 51 | ASSERT_NO_FATAL_FAILURE(SUCCEED()); 52 | ASSERT_NO_FATAL_FAILURE(Subroutine()); 53 | ASSERT_NO_FATAL_FAILURE({ SUCCEED(); }); 54 | } 55 | 56 | } // namespace 57 | -------------------------------------------------------------------------------- /thirdparty/googletest/test/gtest_testbridge_test_.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2018, Google LLC. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | 31 | // This program is meant to be run by gtest_test_filter_test.py. Do not run 32 | // it directly. 33 | 34 | #include "gtest/gtest.h" 35 | 36 | // These tests are used to detect if filtering is working. Only 37 | // 'TestThatSucceeds' should ever run. 38 | 39 | TEST(TestFilterTest, TestThatSucceeds) {} 40 | 41 | TEST(TestFilterTest, TestThatFails) { 42 | ASSERT_TRUE(false) << "This test should never be run."; 43 | } 44 | -------------------------------------------------------------------------------- /thirdparty/googletest/test/gtest_xml_outfile1_test_.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2008, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // gtest_xml_outfile1_test_ writes some xml via TestProperty used by 31 | // gtest_xml_outfiles_test.py 32 | 33 | #include "gtest/gtest.h" 34 | 35 | class PropertyOne : public testing::Test { 36 | protected: 37 | void SetUp() override { RecordProperty("SetUpProp", 1); } 38 | void TearDown() override { RecordProperty("TearDownProp", 1); } 39 | }; 40 | 41 | TEST_F(PropertyOne, TestSomeProperties) { 42 | RecordProperty("TestSomeProperty", 1); 43 | } 44 | -------------------------------------------------------------------------------- /thirdparty/googletest/test/gtest_xml_outfile2_test_.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2008, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // gtest_xml_outfile2_test_ writes some xml via TestProperty used by 31 | // gtest_xml_outfiles_test.py 32 | 33 | #include "gtest/gtest.h" 34 | 35 | class PropertyTwo : public testing::Test { 36 | protected: 37 | void SetUp() override { RecordProperty("SetUpProp", 2); } 38 | void TearDown() override { RecordProperty("TearDownProp", 2); } 39 | }; 40 | 41 | TEST_F(PropertyTwo, TestSomeProperties) { 42 | RecordProperty("TestSomeProperty", 2); 43 | } 44 | -------------------------------------------------------------------------------- /thirdparty/googletest/test/production.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2006, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | // 31 | // This is part of the unit test for gtest_prod.h. 32 | 33 | #include "production.h" 34 | 35 | PrivateCode::PrivateCode() : x_(0) {} 36 | -------------------------------------------------------------------------------- /thirdparty/googletest/test/production.h: -------------------------------------------------------------------------------- 1 | // Copyright 2006, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | // 31 | // This is part of the unit test for gtest_prod.h. 32 | 33 | #ifndef GOOGLETEST_TEST_PRODUCTION_H_ 34 | #define GOOGLETEST_TEST_PRODUCTION_H_ 35 | 36 | #include "gtest/gtest_prod.h" 37 | 38 | class PrivateCode { 39 | public: 40 | // Declares a friend test that does not use a fixture. 41 | FRIEND_TEST(PrivateCodeTest, CanAccessPrivateMembers); 42 | 43 | // Declares a friend test that uses a fixture. 44 | FRIEND_TEST(PrivateCodeFixtureTest, CanAccessPrivateMembers); 45 | 46 | PrivateCode(); 47 | 48 | int x() const { return x_; } 49 | private: 50 | void set_x(int an_x) { x_ = an_x; } 51 | int x_; 52 | }; 53 | 54 | #endif // GOOGLETEST_TEST_PRODUCTION_H_ 55 | --------------------------------------------------------------------------------