diff --git a/.gitignore b/.gitignore index 78f9a6b..8151de2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,14 +1,2 @@ -# 项目的构建文件夹 -build/ - -# VSCode的配置文件夹 -.vscode/ - -# CLion的配置文件夹 .idea/ - -# draw.io的缓存文件 -*.bkp - -# 合成的全部代码文件 -all.c \ No newline at end of file +cmake-build-debug-visual-studio/ \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index a293953..e786e01 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,21 +1,57 @@ -cmake_minimum_required(VERSION 3.10) # 设置cmake项目需要的cmake最小版本 +cmake_minimum_required(VERSION 3.10) +project(auto_bus_gui) -add_subdirectory(test) -add_subdirectory(all_test) +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) +set(CMAKE_AUTOUIC ON) -project(auto_pilot_bus) # 设置项目的名称 +set(CMAKE_PREFIX_PATH "C:/Users/ricardo.DESKTOP-N6OVBK5/Programs/Qt/6.1.3/msvc2019_64") -set(CMAKE_C_STANDARD 11) # 设置项目的C语言标准版本 -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall") +find_package(Qt6 COMPONENTS + Core + Gui + Widgets + REQUIRED) -set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/build) # 设置项目的产生的库的路径,这里直接设为二进制文件处 - -# 设置项目的头文件目录 include_directories( - ${PROJECT_SOURCE_DIR}/include/ + ${PROJECT_SOURCE_DIR}/include + ${PROJECT_SOURCE_DIR}/src/header ) +aux_source_directory(${PROJECT_SOURCE_DIR}/src SRCS) -aux_source_directory(./src SRC) +add_executable(auto_bus_gui main.cpp ${SRCS}) +target_link_libraries(auto_bus_gui + Qt::Core + Qt::Gui + Qt::Widgets + ) -# 产生可执行文件 -add_executable(bus main.c ${SRC}) \ No newline at end of file +if (WIN32) + set(DEBUG_SUFFIX) + if (MSVC AND CMAKE_BUILD_TYPE MATCHES "Debug") + set(DEBUG_SUFFIX "d") + endif () + set(QT_INSTALL_PATH "${CMAKE_PREFIX_PATH}") + if (NOT EXISTS "${QT_INSTALL_PATH}/bin") + set(QT_INSTALL_PATH "${QT_INSTALL_PATH}/..") + if (NOT EXISTS "${QT_INSTALL_PATH}/bin") + set(QT_INSTALL_PATH "${QT_INSTALL_PATH}/..") + endif () + endif () + if (EXISTS "${QT_INSTALL_PATH}/plugins/platforms/qwindows${DEBUG_SUFFIX}.dll") + add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E make_directory + "$/plugins/platforms/") + add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + "${QT_INSTALL_PATH}/plugins/platforms/qwindows${DEBUG_SUFFIX}.dll" + "$/plugins/platforms/") + endif () + foreach (QT_LIB Core) + add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + "${QT_INSTALL_PATH}/bin/Qt6${QT_LIB}${DEBUG_SUFFIX}.dll" + "$") + endforeach (QT_LIB) +endif () diff --git a/README.md b/README.md deleted file mode 100644 index 6a69c61..0000000 --- a/README.md +++ /dev/null @@ -1,79 +0,0 @@ -# Auto Pilot Bus - -## 项目简介 - -北京邮电大学计算机学院2021级《计算导论与程序设计》实践大作业项目仓库。 - -在指定的公交车行驶模型下,实现指定的算法以实现对于公交车的自动调度。 - -## 项目使用 - -### 项目结构 - -``` -auto_pilot_bus -| -+-all_test //本地测试文件夹 -| -+-docs // 文档文件夹 -| -+-include // 头文件文件夹 -| -+-src // 源代码文件夹 -| -+-test //单元测试文件夹 -| -+-main.c // 程序入口 -+-convert.py //产生测试集的Python脚本 -+-main.py //将C代码合并到同一个文件的Python脚本 -+-CMakeLists.txt // CMake文件 -+-.gitignore //git的忽略文件名录 -+-README.md // 项目介绍文件 -``` - -### 编译环境 - -- 编译器 `MinGW-W64 gcc 8.1.0` -- 编译工具 `cmake 3.23.1` - -### 项目使用 - -处在校园网环境在 - -> 参考信息化中心的这篇[文章](https://nic.bupt.edu.cn/info/1016/1301.htm)安装VPN客户端 - -使用 - -```bash -git clone http://10.3.255.244:8801/2021211180/2021211180.git -``` - -下载仓库,在下载过程中可能提示输入账号和密码认证,账号即为你的学号,密码就是你登录`GitLab`时输入的密码。 - -下载完成后文件夹`2021211180`即为项目的文件夹。 - -使用 - -```bash -cd 20212111180 -mkdir build # 创建编译的文件夹 -cd build -cmake .. -G "MinGW Makefiles" # 在第一次生成之后就不必再使用"-G"参数指定编译类型 -cmake --build . -``` - -在编译执行完成之后,`build`文件下的`bus.exe`即为编译产生的程序。 - -## 项目测试 - -### 单元测试 - -在编译之后,`build/test`文件夹内即为`google test`框架生成的单元测试。 - -### 本地测试 - -在编译之后,`build/all_test`内的`bus_all_test.exe`就是全局本地测试程序。 - -运行这个程序,根据程序的提示选择适当的测试集,程序会自动读取选定的测试集中的配置文件和输入文件,并且将程序的输出和测试集中的输出文件进行对比,输出比对的结果。 - -程序现有的测试集存储在`all_test/test_cases`下面,目前已有18个测试集,对应测试集采用的调度策略可以查看测试集中的配置文件。 diff --git a/all_test/CMakeLists.txt b/all_test/CMakeLists.txt deleted file mode 100644 index df43eb9..0000000 --- a/all_test/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -cmake_minimum_required(VERSION 3.0) -project(bus_all_test) - -include_directories(../include) -include_directories(include) - -aux_source_directory("../src/" SRCS) -aux_source_directory("${CMAKE_CURRENT_SOURCE_DIR}/src" ALL_TEST_SRCS) - -add_executable(bus_all_test ${SRCS} ${ALL_TEST_SRCS} main.c) - -add_custom_command(TARGET bus_all_test POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_directory - "${CMAKE_CURRENT_SOURCE_DIR}/test_cases" - "$/test_cases") \ No newline at end of file diff --git a/all_test/include/tools.h b/all_test/include/tools.h deleted file mode 100644 index f32f73a..0000000 --- a/all_test/include/tools.h +++ /dev/null @@ -1,24 +0,0 @@ -// -// Created by ricardo on 2022/5/20. -// - -#ifndef AUTO_PILOT_BUS_TOOLS_H -#define AUTO_PILOT_BUS_TOOLS_H -#include "stdio.h" -#include "string.h" -#include "define.h" -#include "rail.h" -#include "controller.h" - -void ChooseTestCaseInput(char *path, int index); - -void ChooseTestCaseOutput(char *path, int index); - -rail_node_t *ChooseConfigFile(int index); - -void ReadOutputFile(char *result, FILE *f); - -int CheckOutput(char *program_output, char *read_output); - -rail_node_t *ReadChosenConfigFile(char *config_file_path); -#endif //AUTO_PILOT_BUS_TOOLS_H diff --git a/all_test/main.c b/all_test/main.c deleted file mode 100644 index f7c8917..0000000 --- a/all_test/main.c +++ /dev/null @@ -1,258 +0,0 @@ -// -// Created by ricardo on 2022/5/20. -// -#include "bus_io.h" -#include "tools.h" - -int main() -{ - /** - * 输入的字符串 - */ - char input[30]; - /** - * 输出的字符串 - */ - char output[150]; - /** - * the_bus指针的本体 - */ - bus_t main_bus; - /** - * 公交车前进的方向 - */ - int direction; - /** - * 完成的请求 - */ - bus_query_t *finished_query; - int index; - char path[50]; - char read_output[150]; - FILE *input_file = NULL; - FILE *output_file = NULL; - - printf("Please choose which test case to use:"); - scanf("%d", &index); - - ChooseTestCaseInput(path, index); - input_file = fopen(path, "r"); - ChooseTestCaseOutput(path, index); - output_file = fopen(path, "r"); - - // 读取配置文件 - rails = ChooseConfigFile(index); - - // 制造公交车 - the_bus = &main_bus; - the_bus->distance = 0; - the_bus->rail_node_pos = FindNode(rails, 1); - - // 开始时公交车应该是停下的 - direction = BUS_STOP; - - PrintStateInner(output); - ReadOutputFile(read_output, output_file); - if(CheckOutput(output, read_output) == BUS_FAlSE) - { - printf("Right:\n"); - printf("%s", read_output); - printf("Wrong:\n"); - printf("%s", output); - printf("\n"); // 打印一个空白作为分界线 - } - else - { - printf("%d Ok\n", bus_time); - } - - for(;;) - { - fgets(input, sizeof input, input_file); - - int result = ReadInput(input); - if(result == IO_CLOCK) - { - // 时间流动 - AddTime(); - - switch (chosen_strategy) - { - case BUS_FCFS: - // 如果到站,处理请求和 - if(JudgeOnStation() == BUS_TRUE) - { - direction = FCFSDirection(); //在开始得判断一次方向 - finished_query = FCFSQuery(); - - if(finished_query != NULL) // 有请求就处理请求 - { - // 循环处理所有可以处理的请求,总共消耗一秒 - while (finished_query != NULL) - { - DeleteQuery(finished_query); - finished_query = FCFSQuery(); - } - - // 请求处理完再进行方向的判断 - direction = FCFSDirection(); - } - else //如果没有请求就继续前进 - { - RunBus(direction); - } - } - else - { - RunBus(direction); - } - break; - case BUS_SSTF: - if(JudgeOnStation() == BUS_TRUE) - { - // 在没有目标请求的时候,获取一个目标站点 - if(target_query == NULL) - { - target_query = SSTFGetQuery(); - direction = SSTFDirection(target_query); - - // 处理下一个需要处理的请求就在脚底下的情况 - if(target_query != NULL && direction == BUS_STOP && target_query->node == the_bus->rail_node_pos) - { - while (target_query != NULL && direction == BUS_STOP && target_query->node == the_bus->rail_node_pos) - { - DeleteQuery(target_query); - target_query = SSTFGetQuery(); - direction = SSTFDirection(target_query); - } - } - RunBus(direction); - } - else - { - bus_query_t *btw_query = SSTFBTWQuery(direction); - // 如果到站了 - if(target_query->node == the_bus->rail_node_pos) - { - // 如果刚好在站点上就有不少请求,处理一波 - // 这里利用了&&运算符的短路特性,如果第一个判断为假,则不进行下一个判断,也就避免了段错误 - while (target_query != NULL && target_query->node == the_bus->rail_node_pos) - { - DeleteQuery(target_query); - target_query = SSTFGetQuery(); - direction = SSTFDirection(target_query); - } - } - else if(btw_query != NULL) - { - // 如果没有到站就看看能不能顺便服务 - while (btw_query != NULL) - { - DeleteQuery(btw_query); - btw_query = SSTFBTWQuery(direction); - } - } - else - { - // 如果啥也不能做就走吧 - RunBus(direction); - } - } - } - else - { - // 没到站的话那就走吧 - RunBus(direction); - } - break; - case BUS_SCAN: - // 如果没有指定的请求就获得指定的请求 - if(JudgeOnStation() == BUS_TRUE) - { - // 在没有目标请求的时候,获取一个目标站点 - if(target_query == NULL) - { - target_query = SCANGetQuery(direction); - direction = SCANDirection(target_query, direction); - - // 处理下一个需要处理的请求就在脚底下的情况 - if(target_query != NULL && target_query->node == the_bus->rail_node_pos) - { - while (target_query != NULL && target_query->node == the_bus->rail_node_pos) - { - DeleteQuery(target_query); - target_query = SSTFGetQuery(); - direction = SSTFDirection(target_query); - } - } - RunBus(direction); - } - else - { - bus_query_t *btw_query = SCANBTWQuery(); - // 如果到站了 - if(target_query->node == the_bus->rail_node_pos) - { - // 如果刚好在站点上就有不少请求,处理一波 - // 这里利用了&&运算符的短路特性,如果第一个判断为假,则不进行下一个判断,也就避免了段错误 - while (target_query != NULL && target_query->node == the_bus->rail_node_pos) - { - DeleteQuery(target_query); - target_query = SCANGetQuery(direction); - direction = SCANDirection(target_query, direction); - } - } - else if(btw_query != NULL) - { - // 如果没有到站就看看能不能顺便服务 - while (btw_query != NULL) - { - DeleteQuery(btw_query); - btw_query = SCANBTWQuery(); - } - } - else - { - // 如果啥也不能做就走吧 - RunBus(direction); - } - } - } - else - { - // 没到站的话那就走吧 - RunBus(direction); - } - break; - default: - // 这个分支只是为了符合代码规范而存在,理论上不会用到这个分支 - break; - } - - PrintStateInner(output); - ReadOutputFile(read_output, output_file); - if(CheckOutput(output, read_output) == BUS_FAlSE) - { - printf("Right:\n"); - printf("%s", read_output); - printf("Wrong:\n"); - printf("%s", output); - printf("\n"); // 打印一个空白行作为分界线 - } - else - { - printf("%d Ok\n", bus_time); - } - - } - else if(result == IO_END) - { - printf("end\n"); - break; - } - else - { - //在读取到创建请求的情况下,不做任何事 - } - } -} diff --git a/all_test/src/tools.c b/all_test/src/tools.c deleted file mode 100644 index 6a66938..0000000 --- a/all_test/src/tools.c +++ /dev/null @@ -1,194 +0,0 @@ -// -// Created by ricardo on 2022/5/20. -// -#include "tools.h" - -void ChooseTestCaseInput(char *path, int index) -{ - memset(path, 0, 50); - - char root_path[] = "./test_cases/"; - char input_file[] = "/input.txt"; - char case_path[3]; - - sprintf(case_path, "%d", index); - - strcat(path, root_path); - strcat(path, case_path); - strcat(path, input_file); -} - -void ChooseTestCaseOutput(char *path, int index) -{ - memset(path, 0, 50); - - char root_path[] = "./test_cases/"; - char output_file[] = "/output.txt"; - char case_path[3]; - - sprintf(case_path, "%d", index); - - strcat(path, root_path); - strcat(path, case_path); - strcat(path, output_file); -} - -void ReadOutputFile(char *result, FILE *f) -{ - memset(result, 0, 150); - - for(size_t i = 0; i < 7; i++) - { - char temp[50]; - fgets(temp, 50, f); - strcat(result, temp); - } -} - -int CheckOutput(char *program_output, char *read_output) -{ - int result = strcmp(program_output, read_output); - - if(result == 0) - { - return BUS_TRUE; - } - else - { - return BUS_FAlSE; - } -} - -rail_node_t *ChooseConfigFile(int index) -{ - char root_path[] = "./test_cases/"; - char config_path[] = "/dict.dic"; - char case_path[3]; - - sprintf(case_path, "%d", index); - - char file_path[30] = {0}; - - strcat(file_path, root_path); - strcat(file_path, case_path); - strcat(file_path, config_path); - - return ReadChosenConfigFile(file_path); -} - -rail_node_t *ReadChosenConfigFile(char *config_file_path) -{ - FILE *config_file = NULL; - char buffer[30]; - int total_station = 0; - int distance = 0; - - config_file = fopen(config_file_path, "r"); - - // 循环读取文件的每一行 - while (fgets(buffer, sizeof buffer, config_file) != NULL) - { - char first_char = buffer[0]; - char *p; - - switch (first_char) - { - case '#': - // 如果读取到#什么都不做 - break; - case 'T': - // TOTAL_STATION - p = buffer; - - // 把数字前面的所有字符全部干掉 - while (*p < '0' || *p > '9') - { - p++; - } - - // 讲道理,应该只有两位数,所以就这样处理了 - if (*(p + 1) == '\n' || *(p + 1) == '\0') - { - total_station = *p - 48; - } - else - { - total_station = (*p - 48) * 10 + *(p + 1) - 48; - } - - break; - case 'S': - // STRATEGY - p = buffer; - // 将=前的字符全部略去 - while (*p != '=') - { - p++; - } - // =也去掉 - p++; - // =和策略之间的空格也去掉 - while (*p == ' ') - { - p++; - } - - if (*p == 'F' && *(p + 1) == 'C') //FCFS - { - chosen_strategy = BUS_FCFS; - } - else if (*p == 'S' && *(p + 1) == 'S') //SSTF - { - chosen_strategy = BUS_SSTF; - } - else if (*p == 'S' && *(p + 1) == 'C') //SCAN - { - chosen_strategy = BUS_SCAN; - } - else - { - // 读取失败 - chosen_strategy = -1; - } - - break; - case 'D': - // DISTANCE - p = buffer; - - // 把数字前面的所有字符全部干掉 - while (*p < '0' || *p > '9') - { - p++; - } - - if (*(p + 1) == '\n' || *(p + 1) == '\0') - { - distance = *p - 48; - } - - break; - default: - continue; - } - - } - - // 处理参数去缺省值的情况 - if (distance == 0) - { - distance = 2; - } - if (total_station == 0) - { - total_station = 5; - } - if(chosen_strategy == -1) - { - chosen_strategy = BUS_FCFS; - } - - all_distance = distance * total_station; - rail_node_t *head = CreateRails(distance, total_station); - return head; -} \ No newline at end of file diff --git a/all_test/test_cases/1/dict.dic b/all_test/test_cases/1/dict.dic deleted file mode 100644 index ba4ce4d..0000000 --- a/all_test/test_cases/1/dict.dic +++ /dev/null @@ -1,3 +0,0 @@ -TOTAL_STATION = 10 -STRATEGY = FCFS -DISTANCE = 3 \ No newline at end of file diff --git a/all_test/test_cases/1/input.txt b/all_test/test_cases/1/input.txt deleted file mode 100644 index cc018ca..0000000 --- a/all_test/test_cases/1/input.txt +++ /dev/null @@ -1,21 +0,0 @@ -clock -counterclockwise 3 -clock -clock -clock -clock -clock -clock -target 10 -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -end diff --git a/all_test/test_cases/1/output.txt b/all_test/test_cases/1/output.txt deleted file mode 100644 index 0a94ab4..0000000 --- a/all_test/test_cases/1/output.txt +++ /dev/null @@ -1,134 +0,0 @@ -TIME:0 -BUS: -position:0 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:1 -BUS: -position:0 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:2 -BUS: -position:1 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0010000000 -TIME:3 -BUS: -position:2 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0010000000 -TIME:4 -BUS: -position:3 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0010000000 -TIME:5 -BUS: -position:4 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0010000000 -TIME:6 -BUS: -position:5 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0010000000 -TIME:7 -BUS: -position:6 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0010000000 -TIME:8 -BUS: -position:6 -target:0000000001 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:9 -BUS: -position:5 -target:0000000001 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:10 -BUS: -position:4 -target:0000000001 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:11 -BUS: -position:3 -target:0000000001 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:12 -BUS: -position:2 -target:0000000001 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:13 -BUS: -position:1 -target:0000000001 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:14 -BUS: -position:0 -target:0000000001 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:15 -BUS: -position:29 -target:0000000001 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:16 -BUS: -position:28 -target:0000000001 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:17 -BUS: -position:27 -target:0000000001 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:18 -BUS: -position:27 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -end diff --git a/all_test/test_cases/10/dict.dic b/all_test/test_cases/10/dict.dic deleted file mode 100644 index 5accfe3..0000000 --- a/all_test/test_cases/10/dict.dic +++ /dev/null @@ -1,3 +0,0 @@ -TOTAL_STATION = 10 -STRATEGY = SSTF -#end diff --git a/all_test/test_cases/10/input.txt b/all_test/test_cases/10/input.txt deleted file mode 100644 index 9107e4a..0000000 --- a/all_test/test_cases/10/input.txt +++ /dev/null @@ -1,11 +0,0 @@ -clock -clockwise 8 -clock -clockwise 8 -clock -clock -clock -clock -clock -clock -end diff --git a/all_test/test_cases/10/output.txt b/all_test/test_cases/10/output.txt deleted file mode 100644 index 94cbfe9..0000000 --- a/all_test/test_cases/10/output.txt +++ /dev/null @@ -1,64 +0,0 @@ -TIME:0 -BUS: -position:0 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:1 -BUS: -position:0 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:2 -BUS: -position:19 -target:0000000000 -STATION: -clockwise:0000000100 -counterclockwise:0000000000 -TIME:3 -BUS: -position:18 -target:0000000000 -STATION: -clockwise:0000000100 -counterclockwise:0000000000 -TIME:4 -BUS: -position:17 -target:0000000000 -STATION: -clockwise:0000000100 -counterclockwise:0000000000 -TIME:5 -BUS: -position:16 -target:0000000000 -STATION: -clockwise:0000000100 -counterclockwise:0000000000 -TIME:6 -BUS: -position:15 -target:0000000000 -STATION: -clockwise:0000000100 -counterclockwise:0000000000 -TIME:7 -BUS: -position:14 -target:0000000000 -STATION: -clockwise:0000000100 -counterclockwise:0000000000 -TIME:8 -BUS: -position:14 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -end diff --git a/all_test/test_cases/11/dict.dic b/all_test/test_cases/11/dict.dic deleted file mode 100644 index 5accfe3..0000000 --- a/all_test/test_cases/11/dict.dic +++ /dev/null @@ -1,3 +0,0 @@ -TOTAL_STATION = 10 -STRATEGY = SSTF -#end diff --git a/all_test/test_cases/11/input.txt b/all_test/test_cases/11/input.txt deleted file mode 100644 index bcf3841..0000000 --- a/all_test/test_cases/11/input.txt +++ /dev/null @@ -1,14 +0,0 @@ -clock -clockwise 8 -clock -clockwise 9 -clock -clock -clock -clock -clock -clock -clock -clock -clock -end diff --git a/all_test/test_cases/11/output.txt b/all_test/test_cases/11/output.txt deleted file mode 100644 index 082b7d1..0000000 --- a/all_test/test_cases/11/output.txt +++ /dev/null @@ -1,85 +0,0 @@ -TIME:0 -BUS: -position:0 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:1 -BUS: -position:0 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:2 -BUS: -position:19 -target:0000000000 -STATION: -clockwise:0000000100 -counterclockwise:0000000000 -TIME:3 -BUS: -position:18 -target:0000000000 -STATION: -clockwise:0000000110 -counterclockwise:0000000000 -TIME:4 -BUS: -position:17 -target:0000000000 -STATION: -clockwise:0000000110 -counterclockwise:0000000000 -TIME:5 -BUS: -position:16 -target:0000000000 -STATION: -clockwise:0000000110 -counterclockwise:0000000000 -TIME:6 -BUS: -position:15 -target:0000000000 -STATION: -clockwise:0000000110 -counterclockwise:0000000000 -TIME:7 -BUS: -position:14 -target:0000000000 -STATION: -clockwise:0000000110 -counterclockwise:0000000000 -TIME:8 -BUS: -position:14 -target:0000000000 -STATION: -clockwise:0000000010 -counterclockwise:0000000000 -TIME:9 -BUS: -position:15 -target:0000000000 -STATION: -clockwise:0000000010 -counterclockwise:0000000000 -TIME:10 -BUS: -position:16 -target:0000000000 -STATION: -clockwise:0000000010 -counterclockwise:0000000000 -TIME:11 -BUS: -position:16 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -end diff --git a/all_test/test_cases/12/dict.dic b/all_test/test_cases/12/dict.dic deleted file mode 100644 index 5accfe3..0000000 --- a/all_test/test_cases/12/dict.dic +++ /dev/null @@ -1,3 +0,0 @@ -TOTAL_STATION = 10 -STRATEGY = SSTF -#end diff --git a/all_test/test_cases/12/input.txt b/all_test/test_cases/12/input.txt deleted file mode 100644 index e0e8165..0000000 --- a/all_test/test_cases/12/input.txt +++ /dev/null @@ -1,14 +0,0 @@ -clock -clockwise 4 -clock -clock -clock -target 3 -clock -clock -clock -clock -clock -clock -clock -end diff --git a/all_test/test_cases/12/output.txt b/all_test/test_cases/12/output.txt deleted file mode 100644 index a9174f4..0000000 --- a/all_test/test_cases/12/output.txt +++ /dev/null @@ -1,85 +0,0 @@ -TIME:0 -BUS: -position:0 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:1 -BUS: -position:0 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:2 -BUS: -position:1 -target:0000000000 -STATION: -clockwise:0001000000 -counterclockwise:0000000000 -TIME:3 -BUS: -position:2 -target:0000000000 -STATION: -clockwise:0001000000 -counterclockwise:0000000000 -TIME:4 -BUS: -position:3 -target:0000000000 -STATION: -clockwise:0001000000 -counterclockwise:0000000000 -TIME:5 -BUS: -position:4 -target:0010000000 -STATION: -clockwise:0001000000 -counterclockwise:0000000000 -TIME:6 -BUS: -position:4 -target:0000000000 -STATION: -clockwise:0001000000 -counterclockwise:0000000000 -TIME:7 -BUS: -position:5 -target:0000000000 -STATION: -clockwise:0001000000 -counterclockwise:0000000000 -TIME:8 -BUS: -position:6 -target:0000000000 -STATION: -clockwise:0001000000 -counterclockwise:0000000000 -TIME:9 -BUS: -position:6 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:10 -BUS: -position:6 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:11 -BUS: -position:6 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -end diff --git a/all_test/test_cases/13/dict.dic b/all_test/test_cases/13/dict.dic deleted file mode 100644 index 5accfe3..0000000 --- a/all_test/test_cases/13/dict.dic +++ /dev/null @@ -1,3 +0,0 @@ -TOTAL_STATION = 10 -STRATEGY = SSTF -#end diff --git a/all_test/test_cases/13/input.txt b/all_test/test_cases/13/input.txt deleted file mode 100644 index 4096cad..0000000 --- a/all_test/test_cases/13/input.txt +++ /dev/null @@ -1,16 +0,0 @@ -clock -clockwise 4 -clock -clockwise 5 -clock -counterclockwise 4 -clock -target 4 -clock -clock -clock -clock -clock -clock -clock -end diff --git a/all_test/test_cases/13/output.txt b/all_test/test_cases/13/output.txt deleted file mode 100644 index fe10352..0000000 --- a/all_test/test_cases/13/output.txt +++ /dev/null @@ -1,85 +0,0 @@ -TIME:0 -BUS: -position:0 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:1 -BUS: -position:0 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:2 -BUS: -position:1 -target:0000000000 -STATION: -clockwise:0001000000 -counterclockwise:0000000000 -TIME:3 -BUS: -position:2 -target:0000000000 -STATION: -clockwise:0001100000 -counterclockwise:0000000000 -TIME:4 -BUS: -position:3 -target:0000000000 -STATION: -clockwise:0001100000 -counterclockwise:0001000000 -TIME:5 -BUS: -position:4 -target:0001000000 -STATION: -clockwise:0001100000 -counterclockwise:0001000000 -TIME:6 -BUS: -position:5 -target:0001000000 -STATION: -clockwise:0001100000 -counterclockwise:0001000000 -TIME:7 -BUS: -position:6 -target:0001000000 -STATION: -clockwise:0001100000 -counterclockwise:0001000000 -TIME:8 -BUS: -position:6 -target:0000000000 -STATION: -clockwise:0000100000 -counterclockwise:0000000000 -TIME:9 -BUS: -position:7 -target:0000000000 -STATION: -clockwise:0000100000 -counterclockwise:0000000000 -TIME:10 -BUS: -position:8 -target:0000000000 -STATION: -clockwise:0000100000 -counterclockwise:0000000000 -TIME:11 -BUS: -position:8 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -end diff --git a/all_test/test_cases/14/dict.dic b/all_test/test_cases/14/dict.dic deleted file mode 100644 index 5accfe3..0000000 --- a/all_test/test_cases/14/dict.dic +++ /dev/null @@ -1,3 +0,0 @@ -TOTAL_STATION = 10 -STRATEGY = SSTF -#end diff --git a/all_test/test_cases/14/input.txt b/all_test/test_cases/14/input.txt deleted file mode 100644 index 5c2326a..0000000 --- a/all_test/test_cases/14/input.txt +++ /dev/null @@ -1,12 +0,0 @@ -clock -clockwise 2 -counterclockwise 10 -clock -clock -clock -clock -clock -clock -clock -clock -end diff --git a/all_test/test_cases/14/output.txt b/all_test/test_cases/14/output.txt deleted file mode 100644 index 720f50f..0000000 --- a/all_test/test_cases/14/output.txt +++ /dev/null @@ -1,71 +0,0 @@ -TIME:0 -BUS: -position:0 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:1 -BUS: -position:0 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:2 -BUS: -position:1 -target:0000000000 -STATION: -clockwise:0100000000 -counterclockwise:0000000001 -TIME:3 -BUS: -position:2 -target:0000000000 -STATION: -clockwise:0100000000 -counterclockwise:0000000001 -TIME:4 -BUS: -position:2 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000001 -TIME:5 -BUS: -position:1 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000001 -TIME:6 -BUS: -position:0 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000001 -TIME:7 -BUS: -position:19 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000001 -TIME:8 -BUS: -position:18 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000001 -TIME:9 -BUS: -position:18 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -end diff --git a/all_test/test_cases/15/dict.dic b/all_test/test_cases/15/dict.dic deleted file mode 100644 index 5accfe3..0000000 --- a/all_test/test_cases/15/dict.dic +++ /dev/null @@ -1,3 +0,0 @@ -TOTAL_STATION = 10 -STRATEGY = SSTF -#end diff --git a/all_test/test_cases/15/input.txt b/all_test/test_cases/15/input.txt deleted file mode 100644 index 650d08a..0000000 --- a/all_test/test_cases/15/input.txt +++ /dev/null @@ -1,48 +0,0 @@ -clock -clockwise 6 -clock -clockwise 5 -clock -counterclockwise 9 -clock -target 3 -clock -clock -target 10 -clockwise 7 -clock -target 1 -clock -counterclockwise 2 -clock -target 4 -clock -target 8 -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -end diff --git a/all_test/test_cases/15/output.txt b/all_test/test_cases/15/output.txt deleted file mode 100644 index 22589c1..0000000 --- a/all_test/test_cases/15/output.txt +++ /dev/null @@ -1,267 +0,0 @@ -TIME:0 -BUS: -position:0 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:1 -BUS: -position:0 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:2 -BUS: -position:1 -target:0000000000 -STATION: -clockwise:0000010000 -counterclockwise:0000000000 -TIME:3 -BUS: -position:2 -target:0000000000 -STATION: -clockwise:0000110000 -counterclockwise:0000000000 -TIME:4 -BUS: -position:3 -target:0000000000 -STATION: -clockwise:0000110000 -counterclockwise:0000000010 -TIME:5 -BUS: -position:4 -target:0010000000 -STATION: -clockwise:0000110000 -counterclockwise:0000000010 -TIME:6 -BUS: -position:4 -target:0000000000 -STATION: -clockwise:0000110000 -counterclockwise:0000000010 -TIME:7 -BUS: -position:5 -target:0000000001 -STATION: -clockwise:0000111000 -counterclockwise:0000000010 -TIME:8 -BUS: -position:6 -target:1000000001 -STATION: -clockwise:0000111000 -counterclockwise:0000000010 -TIME:9 -BUS: -position:7 -target:1000000001 -STATION: -clockwise:0000111000 -counterclockwise:0100000010 -TIME:10 -BUS: -position:8 -target:1001000001 -STATION: -clockwise:0000111000 -counterclockwise:0100000010 -TIME:11 -BUS: -position:8 -target:1001000101 -STATION: -clockwise:0000011000 -counterclockwise:0100000010 -TIME:12 -BUS: -position:9 -target:1001000101 -STATION: -clockwise:0000011000 -counterclockwise:0100000010 -TIME:13 -BUS: -position:10 -target:1001000101 -STATION: -clockwise:0000011000 -counterclockwise:0100000010 -TIME:14 -BUS: -position:10 -target:1001000101 -STATION: -clockwise:0000001000 -counterclockwise:0100000010 -TIME:15 -BUS: -position:11 -target:1001000101 -STATION: -clockwise:0000001000 -counterclockwise:0100000010 -TIME:16 -BUS: -position:12 -target:1001000101 -STATION: -clockwise:0000001000 -counterclockwise:0100000010 -TIME:17 -BUS: -position:12 -target:1001000101 -STATION: -clockwise:0000000000 -counterclockwise:0100000010 -TIME:18 -BUS: -position:13 -target:1001000101 -STATION: -clockwise:0000000000 -counterclockwise:0100000010 -TIME:19 -BUS: -position:14 -target:1001000101 -STATION: -clockwise:0000000000 -counterclockwise:0100000010 -TIME:20 -BUS: -position:14 -target:1001000001 -STATION: -clockwise:0000000000 -counterclockwise:0100000010 -TIME:21 -BUS: -position:15 -target:1001000001 -STATION: -clockwise:0000000000 -counterclockwise:0100000010 -TIME:22 -BUS: -position:16 -target:1001000001 -STATION: -clockwise:0000000000 -counterclockwise:0100000010 -TIME:23 -BUS: -position:16 -target:1001000001 -STATION: -clockwise:0000000000 -counterclockwise:0100000000 -TIME:24 -BUS: -position:17 -target:1001000001 -STATION: -clockwise:0000000000 -counterclockwise:0100000000 -TIME:25 -BUS: -position:18 -target:1001000001 -STATION: -clockwise:0000000000 -counterclockwise:0100000000 -TIME:26 -BUS: -position:18 -target:1001000000 -STATION: -clockwise:0000000000 -counterclockwise:0100000000 -TIME:27 -BUS: -position:19 -target:1001000000 -STATION: -clockwise:0000000000 -counterclockwise:0100000000 -TIME:28 -BUS: -position:0 -target:1001000000 -STATION: -clockwise:0000000000 -counterclockwise:0100000000 -TIME:29 -BUS: -position:0 -target:0001000000 -STATION: -clockwise:0000000000 -counterclockwise:0100000000 -TIME:30 -BUS: -position:1 -target:0001000000 -STATION: -clockwise:0000000000 -counterclockwise:0100000000 -TIME:31 -BUS: -position:2 -target:0001000000 -STATION: -clockwise:0000000000 -counterclockwise:0100000000 -TIME:32 -BUS: -position:2 -target:0001000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:33 -BUS: -position:3 -target:0001000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:34 -BUS: -position:4 -target:0001000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:35 -BUS: -position:5 -target:0001000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:36 -BUS: -position:6 -target:0001000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:37 -BUS: -position:6 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -end diff --git a/all_test/test_cases/16/dict.dic b/all_test/test_cases/16/dict.dic deleted file mode 100644 index 5accfe3..0000000 --- a/all_test/test_cases/16/dict.dic +++ /dev/null @@ -1,3 +0,0 @@ -TOTAL_STATION = 10 -STRATEGY = SSTF -#end diff --git a/all_test/test_cases/16/input.txt b/all_test/test_cases/16/input.txt deleted file mode 100644 index a1fce3e..0000000 --- a/all_test/test_cases/16/input.txt +++ /dev/null @@ -1,24 +0,0 @@ -clock -clockwise 8 -clock -counterclockwise 9 -clock -clock -clock -clock -clock -clock -clock -clock -clock -clockwise 6 -clock -counterclockwise 7 -clock -clock -clock -clock -clock -clock -clock -end diff --git a/all_test/test_cases/16/output.txt b/all_test/test_cases/16/output.txt deleted file mode 100644 index dc9d595..0000000 --- a/all_test/test_cases/16/output.txt +++ /dev/null @@ -1,141 +0,0 @@ -TIME:0 -BUS: -position:0 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:1 -BUS: -position:0 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:2 -BUS: -position:19 -target:0000000000 -STATION: -clockwise:0000000100 -counterclockwise:0000000000 -TIME:3 -BUS: -position:18 -target:0000000000 -STATION: -clockwise:0000000100 -counterclockwise:0000000010 -TIME:4 -BUS: -position:17 -target:0000000000 -STATION: -clockwise:0000000100 -counterclockwise:0000000010 -TIME:5 -BUS: -position:16 -target:0000000000 -STATION: -clockwise:0000000100 -counterclockwise:0000000010 -TIME:6 -BUS: -position:16 -target:0000000000 -STATION: -clockwise:0000000100 -counterclockwise:0000000000 -TIME:7 -BUS: -position:15 -target:0000000000 -STATION: -clockwise:0000000100 -counterclockwise:0000000000 -TIME:8 -BUS: -position:14 -target:0000000000 -STATION: -clockwise:0000000100 -counterclockwise:0000000000 -TIME:9 -BUS: -position:14 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:10 -BUS: -position:14 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:11 -BUS: -position:14 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:12 -BUS: -position:13 -target:0000000000 -STATION: -clockwise:0000010000 -counterclockwise:0000000000 -TIME:13 -BUS: -position:12 -target:0000000000 -STATION: -clockwise:0000010000 -counterclockwise:0000001000 -TIME:14 -BUS: -position:12 -target:0000000000 -STATION: -clockwise:0000010000 -counterclockwise:0000000000 -TIME:15 -BUS: -position:11 -target:0000000000 -STATION: -clockwise:0000010000 -counterclockwise:0000000000 -TIME:16 -BUS: -position:10 -target:0000000000 -STATION: -clockwise:0000010000 -counterclockwise:0000000000 -TIME:17 -BUS: -position:10 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:18 -BUS: -position:10 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:19 -BUS: -position:10 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -end diff --git a/all_test/test_cases/17/dict.dic b/all_test/test_cases/17/dict.dic deleted file mode 100644 index 5accfe3..0000000 --- a/all_test/test_cases/17/dict.dic +++ /dev/null @@ -1,3 +0,0 @@ -TOTAL_STATION = 10 -STRATEGY = SSTF -#end diff --git a/all_test/test_cases/17/input.txt b/all_test/test_cases/17/input.txt deleted file mode 100644 index 9f9f7a7..0000000 --- a/all_test/test_cases/17/input.txt +++ /dev/null @@ -1,15 +0,0 @@ -clock -counterclockwise 6 -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -end diff --git a/all_test/test_cases/17/output.txt b/all_test/test_cases/17/output.txt deleted file mode 100644 index 3e2643f..0000000 --- a/all_test/test_cases/17/output.txt +++ /dev/null @@ -1,99 +0,0 @@ -TIME:0 -BUS: -position:0 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:1 -BUS: -position:0 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:2 -BUS: -position:1 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000010000 -TIME:3 -BUS: -position:2 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000010000 -TIME:4 -BUS: -position:3 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000010000 -TIME:5 -BUS: -position:4 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000010000 -TIME:6 -BUS: -position:5 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000010000 -TIME:7 -BUS: -position:6 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000010000 -TIME:8 -BUS: -position:7 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000010000 -TIME:9 -BUS: -position:8 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000010000 -TIME:10 -BUS: -position:9 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000010000 -TIME:11 -BUS: -position:10 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000010000 -TIME:12 -BUS: -position:10 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:13 -BUS: -position:10 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -end diff --git a/all_test/test_cases/18/dict.dic b/all_test/test_cases/18/dict.dic deleted file mode 100644 index 3d1105a..0000000 --- a/all_test/test_cases/18/dict.dic +++ /dev/null @@ -1,3 +0,0 @@ -TOTAL_STATION = 10 -DISTANCE = 3 -STRATEGY = SCAN \ No newline at end of file diff --git a/all_test/test_cases/18/input.txt b/all_test/test_cases/18/input.txt deleted file mode 100644 index a21d17c..0000000 --- a/all_test/test_cases/18/input.txt +++ /dev/null @@ -1,57 +0,0 @@ -clock -clockwise 7 -clockwise 2 -clock -clock -clock -target 7 -clock -clock -counterclockwise 7 -clockwise 2 -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -target 2 -target 3 -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -target 1 -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -end diff --git a/all_test/test_cases/18/output.txt b/all_test/test_cases/18/output.txt deleted file mode 100644 index daab3f4..0000000 --- a/all_test/test_cases/18/output.txt +++ /dev/null @@ -1,344 +0,0 @@ -TIME:0 -BUS: -position:0 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:1 -BUS: -position:0 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:2 -BUS: -position:1 -target:0000000000 -STATION: -clockwise:0100001000 -counterclockwise:0000000000 -TIME:3 -BUS: -position:2 -target:0000000000 -STATION: -clockwise:0100001000 -counterclockwise:0000000000 -TIME:4 -BUS: -position:3 -target:0000000000 -STATION: -clockwise:0100001000 -counterclockwise:0000000000 -TIME:5 -BUS: -position:3 -target:0000001000 -STATION: -clockwise:0000001000 -counterclockwise:0000000000 -TIME:6 -BUS: -position:4 -target:0000001000 -STATION: -clockwise:0000001000 -counterclockwise:0000000000 -TIME:7 -BUS: -position:5 -target:0000001000 -STATION: -clockwise:0100001000 -counterclockwise:0000001000 -TIME:8 -BUS: -position:6 -target:0000001000 -STATION: -clockwise:0100001000 -counterclockwise:0000001000 -TIME:9 -BUS: -position:7 -target:0000001000 -STATION: -clockwise:0100001000 -counterclockwise:0000001000 -TIME:10 -BUS: -position:8 -target:0000001000 -STATION: -clockwise:0100001000 -counterclockwise:0000001000 -TIME:11 -BUS: -position:9 -target:0000001000 -STATION: -clockwise:0100001000 -counterclockwise:0000001000 -TIME:12 -BUS: -position:10 -target:0000001000 -STATION: -clockwise:0100001000 -counterclockwise:0000001000 -TIME:13 -BUS: -position:11 -target:0000001000 -STATION: -clockwise:0100001000 -counterclockwise:0000001000 -TIME:14 -BUS: -position:12 -target:0000001000 -STATION: -clockwise:0100001000 -counterclockwise:0000001000 -TIME:15 -BUS: -position:13 -target:0000001000 -STATION: -clockwise:0100001000 -counterclockwise:0000001000 -TIME:16 -BUS: -position:14 -target:0000001000 -STATION: -clockwise:0100001000 -counterclockwise:0000001000 -TIME:17 -BUS: -position:15 -target:0000001000 -STATION: -clockwise:0100001000 -counterclockwise:0000001000 -TIME:18 -BUS: -position:16 -target:0000001000 -STATION: -clockwise:0100001000 -counterclockwise:0000001000 -TIME:19 -BUS: -position:17 -target:0000001000 -STATION: -clockwise:0100001000 -counterclockwise:0000001000 -TIME:20 -BUS: -position:18 -target:0000001000 -STATION: -clockwise:0100001000 -counterclockwise:0000001000 -TIME:21 -BUS: -position:18 -target:0110000000 -STATION: -clockwise:0100000000 -counterclockwise:0000000000 -TIME:22 -BUS: -position:19 -target:0110000000 -STATION: -clockwise:0100000000 -counterclockwise:0000000000 -TIME:23 -BUS: -position:20 -target:0110000000 -STATION: -clockwise:0100000000 -counterclockwise:0000000000 -TIME:24 -BUS: -position:21 -target:0110000000 -STATION: -clockwise:0100000000 -counterclockwise:0000000000 -TIME:25 -BUS: -position:22 -target:0110000000 -STATION: -clockwise:0100000000 -counterclockwise:0000000000 -TIME:26 -BUS: -position:23 -target:0110000000 -STATION: -clockwise:0100000000 -counterclockwise:0000000000 -TIME:27 -BUS: -position:24 -target:0110000000 -STATION: -clockwise:0100000000 -counterclockwise:0000000000 -TIME:28 -BUS: -position:25 -target:0110000000 -STATION: -clockwise:0100000000 -counterclockwise:0000000000 -TIME:29 -BUS: -position:26 -target:0110000000 -STATION: -clockwise:0100000000 -counterclockwise:0000000000 -TIME:30 -BUS: -position:27 -target:0110000000 -STATION: -clockwise:0100000000 -counterclockwise:0000000000 -TIME:31 -BUS: -position:28 -target:0110000000 -STATION: -clockwise:0100000000 -counterclockwise:0000000000 -TIME:32 -BUS: -position:29 -target:0110000000 -STATION: -clockwise:0100000000 -counterclockwise:0000000000 -TIME:33 -BUS: -position:0 -target:0110000000 -STATION: -clockwise:0100000000 -counterclockwise:0000000000 -TIME:34 -BUS: -position:1 -target:0110000000 -STATION: -clockwise:0100000000 -counterclockwise:0000000000 -TIME:35 -BUS: -position:2 -target:0110000000 -STATION: -clockwise:0100000000 -counterclockwise:0000000000 -TIME:36 -BUS: -position:3 -target:0110000000 -STATION: -clockwise:0100000000 -counterclockwise:0000000000 -TIME:37 -BUS: -position:3 -target:1010000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:38 -BUS: -position:4 -target:1010000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:39 -BUS: -position:5 -target:1010000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:40 -BUS: -position:6 -target:1010000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:41 -BUS: -position:6 -target:1000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:42 -BUS: -position:5 -target:1000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:43 -BUS: -position:4 -target:1000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:44 -BUS: -position:3 -target:1000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:45 -BUS: -position:2 -target:1000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:46 -BUS: -position:1 -target:1000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:47 -BUS: -position:0 -target:1000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:48 -BUS: -position:0 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -end diff --git a/all_test/test_cases/2/dict.dic b/all_test/test_cases/2/dict.dic deleted file mode 100644 index d9bf0c8..0000000 --- a/all_test/test_cases/2/dict.dic +++ /dev/null @@ -1,4 +0,0 @@ -# first come first serve -STRATEGY = FCFS -TOTAL_STATION = 10 -DISTANCE = 2 \ No newline at end of file diff --git a/all_test/test_cases/2/input.txt b/all_test/test_cases/2/input.txt deleted file mode 100644 index f2450ea..0000000 --- a/all_test/test_cases/2/input.txt +++ /dev/null @@ -1,30 +0,0 @@ -clock -clockwise 2 -clock -clockwise 4 -clock -clock -clockwise 6 -clock -target 8 -clock -clock -clock -target 10 -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -end diff --git a/all_test/test_cases/2/output.txt b/all_test/test_cases/2/output.txt deleted file mode 100644 index acc5063..0000000 --- a/all_test/test_cases/2/output.txt +++ /dev/null @@ -1,176 +0,0 @@ -TIME:0 -BUS: -position:0 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:1 -BUS: -position:0 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:2 -BUS: -position:1 -target:0000000000 -STATION: -clockwise:0100000000 -counterclockwise:0000000000 -TIME:3 -BUS: -position:2 -target:0000000000 -STATION: -clockwise:0101000000 -counterclockwise:0000000000 -TIME:4 -BUS: -position:2 -target:0000000000 -STATION: -clockwise:0001000000 -counterclockwise:0000000000 -TIME:5 -BUS: -position:3 -target:0000000000 -STATION: -clockwise:0001010000 -counterclockwise:0000000000 -TIME:6 -BUS: -position:4 -target:0000000100 -STATION: -clockwise:0001010000 -counterclockwise:0000000000 -TIME:7 -BUS: -position:5 -target:0000000100 -STATION: -clockwise:0001010000 -counterclockwise:0000000000 -TIME:8 -BUS: -position:6 -target:0000000100 -STATION: -clockwise:0001010000 -counterclockwise:0000000000 -TIME:9 -BUS: -position:6 -target:0000000101 -STATION: -clockwise:0000010000 -counterclockwise:0000000000 -TIME:10 -BUS: -position:7 -target:0000000101 -STATION: -clockwise:0000010000 -counterclockwise:0000000000 -TIME:11 -BUS: -position:8 -target:0000000101 -STATION: -clockwise:0000010000 -counterclockwise:0000000000 -TIME:12 -BUS: -position:9 -target:0000000101 -STATION: -clockwise:0000010000 -counterclockwise:0000000000 -TIME:13 -BUS: -position:10 -target:0000000101 -STATION: -clockwise:0000010000 -counterclockwise:0000000000 -TIME:14 -BUS: -position:10 -target:0000000101 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:15 -BUS: -position:11 -target:0000000101 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:16 -BUS: -position:12 -target:0000000101 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:17 -BUS: -position:13 -target:0000000101 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:18 -BUS: -position:14 -target:0000000101 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:19 -BUS: -position:14 -target:0000000001 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:20 -BUS: -position:15 -target:0000000001 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:21 -BUS: -position:16 -target:0000000001 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:22 -BUS: -position:17 -target:0000000001 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:23 -BUS: -position:18 -target:0000000001 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:24 -BUS: -position:18 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -end diff --git a/all_test/test_cases/3/dict.dic b/all_test/test_cases/3/dict.dic deleted file mode 100644 index d9bf0c8..0000000 --- a/all_test/test_cases/3/dict.dic +++ /dev/null @@ -1,4 +0,0 @@ -# first come first serve -STRATEGY = FCFS -TOTAL_STATION = 10 -DISTANCE = 2 \ No newline at end of file diff --git a/all_test/test_cases/3/input.txt b/all_test/test_cases/3/input.txt deleted file mode 100644 index 57ac345..0000000 --- a/all_test/test_cases/3/input.txt +++ /dev/null @@ -1,30 +0,0 @@ -clock -clockwise 2 -clock -target 10 -clock -clock -clock -clockwise 3 -clock -clock -target 9 -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -end diff --git a/all_test/test_cases/3/output.txt b/all_test/test_cases/3/output.txt deleted file mode 100644 index de95351..0000000 --- a/all_test/test_cases/3/output.txt +++ /dev/null @@ -1,183 +0,0 @@ -TIME:0 -BUS: -position:0 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:1 -BUS: -position:0 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:2 -BUS: -position:1 -target:0000000000 -STATION: -clockwise:0100000000 -counterclockwise:0000000000 -TIME:3 -BUS: -position:2 -target:0000000001 -STATION: -clockwise:0100000000 -counterclockwise:0000000000 -TIME:4 -BUS: -position:2 -target:0000000001 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:5 -BUS: -position:1 -target:0000000001 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:6 -BUS: -position:0 -target:0000000001 -STATION: -clockwise:0010000000 -counterclockwise:0000000000 -TIME:7 -BUS: -position:19 -target:0000000001 -STATION: -clockwise:0010000000 -counterclockwise:0000000000 -TIME:8 -BUS: -position:18 -target:0000000011 -STATION: -clockwise:0010000000 -counterclockwise:0000000000 -TIME:9 -BUS: -position:18 -target:0000000010 -STATION: -clockwise:0010000000 -counterclockwise:0000000000 -TIME:10 -BUS: -position:19 -target:0000000010 -STATION: -clockwise:0010000000 -counterclockwise:0000000000 -TIME:11 -BUS: -position:0 -target:0000000010 -STATION: -clockwise:0010000000 -counterclockwise:0000000000 -TIME:12 -BUS: -position:1 -target:0000000010 -STATION: -clockwise:0010000000 -counterclockwise:0000000000 -TIME:13 -BUS: -position:2 -target:0000000010 -STATION: -clockwise:0010000000 -counterclockwise:0000000000 -TIME:14 -BUS: -position:3 -target:0000000010 -STATION: -clockwise:0010000000 -counterclockwise:0000000000 -TIME:15 -BUS: -position:4 -target:0000000010 -STATION: -clockwise:0010000000 -counterclockwise:0000000000 -TIME:16 -BUS: -position:4 -target:0000000010 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:17 -BUS: -position:3 -target:0000000010 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:18 -BUS: -position:2 -target:0000000010 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:19 -BUS: -position:1 -target:0000000010 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:20 -BUS: -position:0 -target:0000000010 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:21 -BUS: -position:19 -target:0000000010 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:22 -BUS: -position:18 -target:0000000010 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:23 -BUS: -position:17 -target:0000000010 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:24 -BUS: -position:16 -target:0000000010 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:25 -BUS: -position:16 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -end diff --git a/all_test/test_cases/4/dict.dic b/all_test/test_cases/4/dict.dic deleted file mode 100644 index f8e2ddb..0000000 --- a/all_test/test_cases/4/dict.dic +++ /dev/null @@ -1,4 +0,0 @@ -DISTANCE = 4 -STRATEGY = SCAN -TOTAL_STATION = 6 -# scan serve diff --git a/all_test/test_cases/4/input.txt b/all_test/test_cases/4/input.txt deleted file mode 100644 index 5581d55..0000000 --- a/all_test/test_cases/4/input.txt +++ /dev/null @@ -1,34 +0,0 @@ -clock -clockwise 2 -clock -clock -counterclockwise 6 -clock -clock -clock -clock -clock -clock -clock -clock -target 1 -clock -clock -clock -clock -clock -clock -counterclockwise 5 -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -end diff --git a/all_test/test_cases/4/output.txt b/all_test/test_cases/4/output.txt deleted file mode 100644 index f53acef..0000000 --- a/all_test/test_cases/4/output.txt +++ /dev/null @@ -1,211 +0,0 @@ -TIME:0 -BUS: -position:0 -target:000000 -STATION: -clockwise:000000 -counterclockwise:000000 -TIME:1 -BUS: -position:0 -target:000000 -STATION: -clockwise:000000 -counterclockwise:000000 -TIME:2 -BUS: -position:1 -target:000000 -STATION: -clockwise:010000 -counterclockwise:000000 -TIME:3 -BUS: -position:2 -target:000000 -STATION: -clockwise:010000 -counterclockwise:000000 -TIME:4 -BUS: -position:3 -target:000000 -STATION: -clockwise:010000 -counterclockwise:000001 -TIME:5 -BUS: -position:4 -target:000000 -STATION: -clockwise:010000 -counterclockwise:000001 -TIME:6 -BUS: -position:4 -target:000000 -STATION: -clockwise:000000 -counterclockwise:000001 -TIME:7 -BUS: -position:3 -target:000000 -STATION: -clockwise:000000 -counterclockwise:000001 -TIME:8 -BUS: -position:2 -target:000000 -STATION: -clockwise:000000 -counterclockwise:000001 -TIME:9 -BUS: -position:1 -target:000000 -STATION: -clockwise:000000 -counterclockwise:000001 -TIME:10 -BUS: -position:0 -target:000000 -STATION: -clockwise:000000 -counterclockwise:000001 -TIME:11 -BUS: -position:23 -target:000000 -STATION: -clockwise:000000 -counterclockwise:000001 -TIME:12 -BUS: -position:22 -target:100000 -STATION: -clockwise:000000 -counterclockwise:000001 -TIME:13 -BUS: -position:21 -target:100000 -STATION: -clockwise:000000 -counterclockwise:000001 -TIME:14 -BUS: -position:20 -target:100000 -STATION: -clockwise:000000 -counterclockwise:000001 -TIME:15 -BUS: -position:20 -target:100000 -STATION: -clockwise:000000 -counterclockwise:000000 -TIME:16 -BUS: -position:21 -target:100000 -STATION: -clockwise:000000 -counterclockwise:000000 -TIME:17 -BUS: -position:22 -target:100000 -STATION: -clockwise:000000 -counterclockwise:000000 -TIME:18 -BUS: -position:23 -target:100000 -STATION: -clockwise:000000 -counterclockwise:000010 -TIME:19 -BUS: -position:0 -target:100000 -STATION: -clockwise:000000 -counterclockwise:000010 -TIME:20 -BUS: -position:0 -target:000000 -STATION: -clockwise:000000 -counterclockwise:000010 -TIME:21 -BUS: -position:23 -target:000000 -STATION: -clockwise:000000 -counterclockwise:000010 -TIME:22 -BUS: -position:22 -target:000000 -STATION: -clockwise:000000 -counterclockwise:000010 -TIME:23 -BUS: -position:21 -target:000000 -STATION: -clockwise:000000 -counterclockwise:000010 -TIME:24 -BUS: -position:20 -target:000000 -STATION: -clockwise:000000 -counterclockwise:000010 -TIME:25 -BUS: -position:19 -target:000000 -STATION: -clockwise:000000 -counterclockwise:000010 -TIME:26 -BUS: -position:18 -target:000000 -STATION: -clockwise:000000 -counterclockwise:000010 -TIME:27 -BUS: -position:17 -target:000000 -STATION: -clockwise:000000 -counterclockwise:000010 -TIME:28 -BUS: -position:16 -target:000000 -STATION: -clockwise:000000 -counterclockwise:000010 -TIME:29 -BUS: -position:16 -target:000000 -STATION: -clockwise:000000 -counterclockwise:000000 -end diff --git a/all_test/test_cases/5/dict.dic b/all_test/test_cases/5/dict.dic deleted file mode 100644 index f8e2ddb..0000000 --- a/all_test/test_cases/5/dict.dic +++ /dev/null @@ -1,4 +0,0 @@ -DISTANCE = 4 -STRATEGY = SCAN -TOTAL_STATION = 6 -# scan serve diff --git a/all_test/test_cases/5/input.txt b/all_test/test_cases/5/input.txt deleted file mode 100644 index 1adebd8..0000000 --- a/all_test/test_cases/5/input.txt +++ /dev/null @@ -1,26 +0,0 @@ -clock -clockwise 2 -counterclockwise 3 -clock -clock -clock -clock -clock -clock -target 4 -clock -clock -clock -clock -clock -clock -clockwise 5 -clock -clock -clock -clock -clock -clock -clock -clock -end diff --git a/all_test/test_cases/5/output.txt b/all_test/test_cases/5/output.txt deleted file mode 100644 index d1ee609..0000000 --- a/all_test/test_cases/5/output.txt +++ /dev/null @@ -1,155 +0,0 @@ -TIME:0 -BUS: -position:0 -target:000000 -STATION: -clockwise:000000 -counterclockwise:000000 -TIME:1 -BUS: -position:0 -target:000000 -STATION: -clockwise:000000 -counterclockwise:000000 -TIME:2 -BUS: -position:1 -target:000000 -STATION: -clockwise:010000 -counterclockwise:001000 -TIME:3 -BUS: -position:2 -target:000000 -STATION: -clockwise:010000 -counterclockwise:001000 -TIME:4 -BUS: -position:3 -target:000000 -STATION: -clockwise:010000 -counterclockwise:001000 -TIME:5 -BUS: -position:4 -target:000000 -STATION: -clockwise:010000 -counterclockwise:001000 -TIME:6 -BUS: -position:4 -target:000000 -STATION: -clockwise:000000 -counterclockwise:001000 -TIME:7 -BUS: -position:5 -target:000000 -STATION: -clockwise:000000 -counterclockwise:001000 -TIME:8 -BUS: -position:6 -target:000100 -STATION: -clockwise:000000 -counterclockwise:001000 -TIME:9 -BUS: -position:7 -target:000100 -STATION: -clockwise:000000 -counterclockwise:001000 -TIME:10 -BUS: -position:8 -target:000100 -STATION: -clockwise:000000 -counterclockwise:001000 -TIME:11 -BUS: -position:8 -target:000100 -STATION: -clockwise:000000 -counterclockwise:000000 -TIME:12 -BUS: -position:9 -target:000100 -STATION: -clockwise:000000 -counterclockwise:000000 -TIME:13 -BUS: -position:10 -target:000100 -STATION: -clockwise:000000 -counterclockwise:000000 -TIME:14 -BUS: -position:11 -target:000100 -STATION: -clockwise:000010 -counterclockwise:000000 -TIME:15 -BUS: -position:12 -target:000100 -STATION: -clockwise:000010 -counterclockwise:000000 -TIME:16 -BUS: -position:12 -target:000000 -STATION: -clockwise:000010 -counterclockwise:000000 -TIME:17 -BUS: -position:13 -target:000000 -STATION: -clockwise:000010 -counterclockwise:000000 -TIME:18 -BUS: -position:14 -target:000000 -STATION: -clockwise:000010 -counterclockwise:000000 -TIME:19 -BUS: -position:15 -target:000000 -STATION: -clockwise:000010 -counterclockwise:000000 -TIME:20 -BUS: -position:16 -target:000000 -STATION: -clockwise:000010 -counterclockwise:000000 -TIME:21 -BUS: -position:16 -target:000000 -STATION: -clockwise:000000 -counterclockwise:000000 -end diff --git a/all_test/test_cases/6/dict.dic b/all_test/test_cases/6/dict.dic deleted file mode 100644 index 9edb3be..0000000 --- a/all_test/test_cases/6/dict.dic +++ /dev/null @@ -1,4 +0,0 @@ -TOTAL_STATION = 5 -DISTANCE = 3 -# shortest seek time first -STRATEGY = SSTF diff --git a/all_test/test_cases/6/input.txt b/all_test/test_cases/6/input.txt deleted file mode 100644 index b2940ee..0000000 --- a/all_test/test_cases/6/input.txt +++ /dev/null @@ -1,47 +0,0 @@ -clock -clockwise 4 -clockwise 2 -counterclockwise 4 -clock -clockwise 2 -clock -clock -counterclockwise 1 -clock -clock -clockwise 3 -clock -clock -clock -clock -clock -clock -clock -target 5 -clock -target 3 -clock -clock -clock -clock -clock -clock -clock -clock -target 4 -target 1 -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -clock -end diff --git a/all_test/test_cases/6/output.txt b/all_test/test_cases/6/output.txt deleted file mode 100644 index d0b431f..0000000 --- a/all_test/test_cases/6/output.txt +++ /dev/null @@ -1,260 +0,0 @@ -TIME:0 -BUS: -position:0 -target:00000 -STATION: -clockwise:00000 -counterclockwise:00000 -TIME:1 -BUS: -position:0 -target:00000 -STATION: -clockwise:00000 -counterclockwise:00000 -TIME:2 -BUS: -position:1 -target:00000 -STATION: -clockwise:01010 -counterclockwise:00010 -TIME:3 -BUS: -position:2 -target:00000 -STATION: -clockwise:01010 -counterclockwise:00010 -TIME:4 -BUS: -position:3 -target:00000 -STATION: -clockwise:01010 -counterclockwise:00010 -TIME:5 -BUS: -position:3 -target:00000 -STATION: -clockwise:00010 -counterclockwise:10010 -TIME:6 -BUS: -position:2 -target:00000 -STATION: -clockwise:00010 -counterclockwise:10010 -TIME:7 -BUS: -position:1 -target:00000 -STATION: -clockwise:00110 -counterclockwise:10010 -TIME:8 -BUS: -position:0 -target:00000 -STATION: -clockwise:00110 -counterclockwise:10010 -TIME:9 -BUS: -position:0 -target:00000 -STATION: -clockwise:00110 -counterclockwise:00010 -TIME:10 -BUS: -position:1 -target:00000 -STATION: -clockwise:00110 -counterclockwise:00010 -TIME:11 -BUS: -position:2 -target:00000 -STATION: -clockwise:00110 -counterclockwise:00010 -TIME:12 -BUS: -position:3 -target:00000 -STATION: -clockwise:00110 -counterclockwise:00010 -TIME:13 -BUS: -position:4 -target:00000 -STATION: -clockwise:00110 -counterclockwise:00010 -TIME:14 -BUS: -position:5 -target:00001 -STATION: -clockwise:00110 -counterclockwise:00010 -TIME:15 -BUS: -position:6 -target:00101 -STATION: -clockwise:00110 -counterclockwise:00010 -TIME:16 -BUS: -position:6 -target:00001 -STATION: -clockwise:00010 -counterclockwise:00010 -TIME:17 -BUS: -position:7 -target:00001 -STATION: -clockwise:00010 -counterclockwise:00010 -TIME:18 -BUS: -position:8 -target:00001 -STATION: -clockwise:00010 -counterclockwise:00010 -TIME:19 -BUS: -position:9 -target:00001 -STATION: -clockwise:00010 -counterclockwise:00010 -TIME:20 -BUS: -position:9 -target:00001 -STATION: -clockwise:00000 -counterclockwise:00000 -TIME:21 -BUS: -position:10 -target:00001 -STATION: -clockwise:00000 -counterclockwise:00000 -TIME:22 -BUS: -position:11 -target:00001 -STATION: -clockwise:00000 -counterclockwise:00000 -TIME:23 -BUS: -position:12 -target:10011 -STATION: -clockwise:00000 -counterclockwise:00000 -TIME:24 -BUS: -position:12 -target:10010 -STATION: -clockwise:00000 -counterclockwise:00000 -TIME:25 -BUS: -position:13 -target:10010 -STATION: -clockwise:00000 -counterclockwise:00000 -TIME:26 -BUS: -position:14 -target:10010 -STATION: -clockwise:00000 -counterclockwise:00000 -TIME:27 -BUS: -position:0 -target:10010 -STATION: -clockwise:00000 -counterclockwise:00000 -TIME:28 -BUS: -position:0 -target:00010 -STATION: -clockwise:00000 -counterclockwise:00000 -TIME:29 -BUS: -position:14 -target:00010 -STATION: -clockwise:00000 -counterclockwise:00000 -TIME:30 -BUS: -position:13 -target:00010 -STATION: -clockwise:00000 -counterclockwise:00000 -TIME:31 -BUS: -position:12 -target:00010 -STATION: -clockwise:00000 -counterclockwise:00000 -TIME:32 -BUS: -position:11 -target:00010 -STATION: -clockwise:00000 -counterclockwise:00000 -TIME:33 -BUS: -position:10 -target:00010 -STATION: -clockwise:00000 -counterclockwise:00000 -TIME:34 -BUS: -position:9 -target:00010 -STATION: -clockwise:00000 -counterclockwise:00000 -TIME:35 -BUS: -position:9 -target:00000 -STATION: -clockwise:00000 -counterclockwise:00000 -TIME:36 -BUS: -position:9 -target:00000 -STATION: -clockwise:00000 -counterclockwise:00000 -end diff --git a/all_test/test_cases/7/dict.dic b/all_test/test_cases/7/dict.dic deleted file mode 100644 index 9edb3be..0000000 --- a/all_test/test_cases/7/dict.dic +++ /dev/null @@ -1,4 +0,0 @@ -TOTAL_STATION = 5 -DISTANCE = 3 -# shortest seek time first -STRATEGY = SSTF diff --git a/all_test/test_cases/7/input.txt b/all_test/test_cases/7/input.txt deleted file mode 100644 index 8ba05f6..0000000 --- a/all_test/test_cases/7/input.txt +++ /dev/null @@ -1,42 +0,0 @@ -clock -clockwise 2 -counterclockwise 4 -clock -clock -clock -clock -clock -counterclockwise 3 -clock -clock -clock -clock -target 5 -clock -clock -clock -clock -clock -clock -counterclockwise 4 -clock -clock -clock -clock -clock -target 1 -clockwise 3 -clock -clock -clock -clock -target 2 -clock -clock -clock -clock -clock -clock -clock -clock -end diff --git a/all_test/test_cases/7/output.txt b/all_test/test_cases/7/output.txt deleted file mode 100644 index 3509551..0000000 --- a/all_test/test_cases/7/output.txt +++ /dev/null @@ -1,239 +0,0 @@ -TIME:0 -BUS: -position:0 -target:00000 -STATION: -clockwise:00000 -counterclockwise:00000 -TIME:1 -BUS: -position:0 -target:00000 -STATION: -clockwise:00000 -counterclockwise:00000 -TIME:2 -BUS: -position:1 -target:00000 -STATION: -clockwise:01000 -counterclockwise:00010 -TIME:3 -BUS: -position:2 -target:00000 -STATION: -clockwise:01000 -counterclockwise:00010 -TIME:4 -BUS: -position:3 -target:00000 -STATION: -clockwise:01000 -counterclockwise:00010 -TIME:5 -BUS: -position:3 -target:00000 -STATION: -clockwise:00000 -counterclockwise:00010 -TIME:6 -BUS: -position:4 -target:00000 -STATION: -clockwise:00000 -counterclockwise:00010 -TIME:7 -BUS: -position:5 -target:00000 -STATION: -clockwise:00000 -counterclockwise:00110 -TIME:8 -BUS: -position:6 -target:00000 -STATION: -clockwise:00000 -counterclockwise:00110 -TIME:9 -BUS: -position:7 -target:00000 -STATION: -clockwise:00000 -counterclockwise:00110 -TIME:10 -BUS: -position:8 -target:00000 -STATION: -clockwise:00000 -counterclockwise:00110 -TIME:11 -BUS: -position:9 -target:00001 -STATION: -clockwise:00000 -counterclockwise:00110 -TIME:12 -BUS: -position:9 -target:00001 -STATION: -clockwise:00000 -counterclockwise:00100 -TIME:13 -BUS: -position:10 -target:00001 -STATION: -clockwise:00000 -counterclockwise:00100 -TIME:14 -BUS: -position:11 -target:00001 -STATION: -clockwise:00000 -counterclockwise:00100 -TIME:15 -BUS: -position:12 -target:00001 -STATION: -clockwise:00000 -counterclockwise:00100 -TIME:16 -BUS: -position:12 -target:00000 -STATION: -clockwise:00000 -counterclockwise:00100 -TIME:17 -BUS: -position:11 -target:00000 -STATION: -clockwise:00000 -counterclockwise:00110 -TIME:18 -BUS: -position:10 -target:00000 -STATION: -clockwise:00000 -counterclockwise:00110 -TIME:19 -BUS: -position:9 -target:00000 -STATION: -clockwise:00000 -counterclockwise:00110 -TIME:20 -BUS: -position:9 -target:00000 -STATION: -clockwise:00000 -counterclockwise:00100 -TIME:21 -BUS: -position:8 -target:00000 -STATION: -clockwise:00000 -counterclockwise:00100 -TIME:22 -BUS: -position:7 -target:10000 -STATION: -clockwise:00100 -counterclockwise:00100 -TIME:23 -BUS: -position:6 -target:10000 -STATION: -clockwise:00100 -counterclockwise:00100 -TIME:24 -BUS: -position:6 -target:10000 -STATION: -clockwise:00000 -counterclockwise:00000 -TIME:25 -BUS: -position:5 -target:10000 -STATION: -clockwise:00000 -counterclockwise:00000 -TIME:26 -BUS: -position:4 -target:11000 -STATION: -clockwise:00000 -counterclockwise:00000 -TIME:27 -BUS: -position:3 -target:11000 -STATION: -clockwise:00000 -counterclockwise:00000 -TIME:28 -BUS: -position:3 -target:10000 -STATION: -clockwise:00000 -counterclockwise:00000 -TIME:29 -BUS: -position:2 -target:10000 -STATION: -clockwise:00000 -counterclockwise:00000 -TIME:30 -BUS: -position:1 -target:10000 -STATION: -clockwise:00000 -counterclockwise:00000 -TIME:31 -BUS: -position:0 -target:10000 -STATION: -clockwise:00000 -counterclockwise:00000 -TIME:32 -BUS: -position:0 -target:00000 -STATION: -clockwise:00000 -counterclockwise:00000 -TIME:33 -BUS: -position:0 -target:00000 -STATION: -clockwise:00000 -counterclockwise:00000 -end diff --git a/all_test/test_cases/8/dict.dic b/all_test/test_cases/8/dict.dic deleted file mode 100644 index 5accfe3..0000000 --- a/all_test/test_cases/8/dict.dic +++ /dev/null @@ -1,3 +0,0 @@ -TOTAL_STATION = 10 -STRATEGY = SSTF -#end diff --git a/all_test/test_cases/8/input.txt b/all_test/test_cases/8/input.txt deleted file mode 100644 index c745f1b..0000000 --- a/all_test/test_cases/8/input.txt +++ /dev/null @@ -1,16 +0,0 @@ -clock -clockwise 3 -clockwise 10 -clock -clock -clock -clock -clock -clockwise 2 -clock -clock -clock -clock -clock -clock -end diff --git a/all_test/test_cases/8/output.txt b/all_test/test_cases/8/output.txt deleted file mode 100644 index f77e2b6..0000000 --- a/all_test/test_cases/8/output.txt +++ /dev/null @@ -1,92 +0,0 @@ -TIME:0 -BUS: -position:0 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:1 -BUS: -position:0 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:2 -BUS: -position:19 -target:0000000000 -STATION: -clockwise:0010000001 -counterclockwise:0000000000 -TIME:3 -BUS: -position:18 -target:0000000000 -STATION: -clockwise:0010000001 -counterclockwise:0000000000 -TIME:4 -BUS: -position:18 -target:0000000000 -STATION: -clockwise:0010000000 -counterclockwise:0000000000 -TIME:5 -BUS: -position:19 -target:0000000000 -STATION: -clockwise:0010000000 -counterclockwise:0000000000 -TIME:6 -BUS: -position:0 -target:0000000000 -STATION: -clockwise:0010000000 -counterclockwise:0000000000 -TIME:7 -BUS: -position:1 -target:0000000000 -STATION: -clockwise:0110000000 -counterclockwise:0000000000 -TIME:8 -BUS: -position:2 -target:0000000000 -STATION: -clockwise:0110000000 -counterclockwise:0000000000 -TIME:9 -BUS: -position:2 -target:0000000000 -STATION: -clockwise:0010000000 -counterclockwise:0000000000 -TIME:10 -BUS: -position:3 -target:0000000000 -STATION: -clockwise:0010000000 -counterclockwise:0000000000 -TIME:11 -BUS: -position:4 -target:0000000000 -STATION: -clockwise:0010000000 -counterclockwise:0000000000 -TIME:12 -BUS: -position:4 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -end diff --git a/all_test/test_cases/9/dict.dic b/all_test/test_cases/9/dict.dic deleted file mode 100644 index 5accfe3..0000000 --- a/all_test/test_cases/9/dict.dic +++ /dev/null @@ -1,3 +0,0 @@ -TOTAL_STATION = 10 -STRATEGY = SSTF -#end diff --git a/all_test/test_cases/9/input.txt b/all_test/test_cases/9/input.txt deleted file mode 100644 index e0a2cb4..0000000 --- a/all_test/test_cases/9/input.txt +++ /dev/null @@ -1,12 +0,0 @@ -clock -clockwise 3 -clock -clock -clockwise 2 -clock -clock -clock -clock -clock -clock -end diff --git a/all_test/test_cases/9/output.txt b/all_test/test_cases/9/output.txt deleted file mode 100644 index b00df4f..0000000 --- a/all_test/test_cases/9/output.txt +++ /dev/null @@ -1,71 +0,0 @@ -TIME:0 -BUS: -position:0 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:1 -BUS: -position:0 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -TIME:2 -BUS: -position:1 -target:0000000000 -STATION: -clockwise:0010000000 -counterclockwise:0000000000 -TIME:3 -BUS: -position:2 -target:0000000000 -STATION: -clockwise:0010000000 -counterclockwise:0000000000 -TIME:4 -BUS: -position:3 -target:0000000000 -STATION: -clockwise:0110000000 -counterclockwise:0000000000 -TIME:5 -BUS: -position:4 -target:0000000000 -STATION: -clockwise:0110000000 -counterclockwise:0000000000 -TIME:6 -BUS: -position:4 -target:0000000000 -STATION: -clockwise:0100000000 -counterclockwise:0000000000 -TIME:7 -BUS: -position:3 -target:0000000000 -STATION: -clockwise:0100000000 -counterclockwise:0000000000 -TIME:8 -BUS: -position:2 -target:0000000000 -STATION: -clockwise:0100000000 -counterclockwise:0000000000 -TIME:9 -BUS: -position:2 -target:0000000000 -STATION: -clockwise:0000000000 -counterclockwise:0000000000 -end diff --git a/convert.py b/convert.py deleted file mode 100644 index 00ae222..0000000 --- a/convert.py +++ /dev/null @@ -1,37 +0,0 @@ -import os - -path = "SSTF/" -dict_path = path + "dict.dic" - -in_path = path + "{}.in" -out_path = path + "{}.out" - -dict_file = open(dict_path, "r", encoding="utf8") -dict_str = dict_file.read() -dict_file.close() - -for i in range(1, 11): - dir_path = "{}/".format(i + 7) - - input_path = dir_path + "input.txt" - output_path = dir_path + "output.txt" - dict_path = dir_path + "dict.dic" - - os.mkdir("{}".format(i + 7)) - - in_file = open(in_path.format(i), "r", encoding="utf8") - out_file = open(out_path.format(i), "r", encoding="utf8") - input_file = open(input_path, "w", encoding="utf8") - output_file = open(output_path, "w", encoding="utf8") - dict_file = open(dict_path, "w", encoding="utf8") - - input_file.write(in_file.read()) - output_file.write(out_file.read()) - dict_file.write(dict_str) - - in_file.close() - out_file.close() - input_file.close() - output_file.close() - dict_file.close() - diff --git a/docs/代码规范/1.png b/docs/代码规范/1.png deleted file mode 100644 index b16d610..0000000 Binary files a/docs/代码规范/1.png and /dev/null differ diff --git a/docs/代码规范/2.png b/docs/代码规范/2.png deleted file mode 100644 index ee6093e..0000000 Binary files a/docs/代码规范/2.png and /dev/null differ diff --git a/docs/代码规范/3.png b/docs/代码规范/3.png deleted file mode 100644 index 430fe49..0000000 Binary files a/docs/代码规范/3.png and /dev/null differ diff --git a/docs/代码规范/4.png b/docs/代码规范/4.png deleted file mode 100644 index 45f2611..0000000 Binary files a/docs/代码规范/4.png and /dev/null differ diff --git a/docs/代码规范/代码规范.md b/docs/代码规范/代码规范.md deleted file mode 100644 index b35f1fe..0000000 --- a/docs/代码规范/代码规范.md +++ /dev/null @@ -1,159 +0,0 @@ -# 代码规范 - -### 命名规则 - -#### 变量命名规则 - -**所有**的局部变量都使用小写的下划线命名法。 - -```C -int bus_position; -char* output_string -``` - -在变量命名时应注意尽可能简洁清晰,但在不能为了简洁而导致变量意义的不明。 - -错误示范: - -```C -// DO NOT DO THIS: -lv_indev_drv_t indev_drv; -``` - -正确示范: - -```C -lv_input_device_driver_t mouse_input; -``` - -> 本例子来自LVGL库。 -> -> lv表示这个类型来自LVGL库,input_device表示这个一个输入设备,driver表示这是一个驱动,后缀t表示这是一个类型。 - -#### 常量命名规则 - -采用`#define`定义的常量采用全大写下划线命名法 - -```C -#define MAX_STR_LENGTH 1000 -``` - -#### 函数命名规则 - -**所有**函数采用驼峰命名法。 - -```C -int StrLength(char* str); -``` - -### 代码风格 - -#### 缩进 - -统一使用`tab`,四个空格的缩进。 - -```C -#include - -int main() -{ - printf("缩进是四格。\n"); - return 0; -} -``` - -> 这点一般不需要注意,现在流行的IDE都是四格缩进。 - -#### 大括号 - -所有的大括号都需要提行书写。 - -```C -if() -{ - -} -for() -{ - -} -int main() -{ - -} -``` - -同时注意在代码中所有的代码块都需要用大括号包裹,即使是一行的情形。 - -```c -// DO NOT DO THIS -if(1) - printf("..."); -// DO THIS -if(1) -{ - printf("..."); -} -``` - -### 注释 - -采用`Doxygen`风格的注释 - -> 在`VSCode`中安装`Doxygen Documentation Generator`这个扩展。 -> -> ![](1.png) -> -> 方便使用下列的功能。 - -在函数,变量的**上一行**输入`/**`后回车来创建模板。 - -```C -/** - * @brief 在stdin打印一个字符串 - * - * @param str 指向需要打印的字符串指针 - */ -void print(char* str) -{ - printf("%s", str); -} -``` - -```C -#include "example.h" - -int main() -{ - /** - * @brief 需要输出的字符串 - * - */ - char* string = "Good morning!\n"; - print(string); - return 0; -} -``` - -在`@brief`的后面输入函数的作用简述,在`@param`的输入每个参数的意义, 在`@return`的后面输入返回值的意义。 - -在`VSCode`中将指针悬停在函数上时就可以查看这个注释。 - -![](2.png) - -其他的注释都应该放在需要注释行的上一行。 - -> 在`Doxygen`规范中,所有的注释都是注释下一行的代码。 - -在文件开头的注释**不做要求**,我感觉应该没有什么用。 - -> 这里推荐一个`VSCode`插件`GitLens`,可以方便的查看提交信息,~~便于在发现问题时锤人~~。 -> -> ![](4.png) - -### 杂项 - -- 函数中的局部变量不必在函数的头部统一命名,但是建议比较重要的变量在头部先声明,并且使用注释注明变量的作用 -- 循环的变量一般情况下都在`for`语句中声明,不在循环以外的地方使用。但如果较为特殊的地方使用到,请使用注释表明。并且循环变量使用`i`,`j`,`k`。 -- `switch`语句中必须要有`default`的部分。 -- 每行代码不超过80个字符。 \ No newline at end of file diff --git a/docs/开发指北/开发指北.md b/docs/开发指北/开发指北.md deleted file mode 100644 index 5f6cf58..0000000 --- a/docs/开发指北/开发指北.md +++ /dev/null @@ -1,54 +0,0 @@ -# 开发指北 - -> 遇到任何问题都可以问。 - -## 任务一 - -> 布置时间:2022-4-29 - -### 终端(命令行)界面入门 - -#### 背景 - -我们在开发过程中需要用到的大部分工具都是以命令行交互为主,比如`cmake`, `gcc`,`git`;而且我们编译出来的应用也是在命令行界面中运行,所以掌握一些基本的命令是必要的。 - -#### 目标 - -掌握命令行界面的基础知识。 - -### Git入门 - -#### 背景 - -`git`是版本管理和团队合作的利器,掌握`git`的基本使用也是必要的。 - -#### 目标 - -克隆本次的大作业的项目仓库,并且进行**至少一次**提交。 - -> 可以在`main.c`文件中调用`printf`函数输出一些内容作为提交的内容。 - -### 模块入门 - -#### 背景 - -多模块编译是一个比较困难的部分,但是也是我们开发中十分有用的技能。 - -#### 目标 - -在项目中新建一个模块,包括头文件和源文件,在模块中设计实现一个简单的函数,并在`main.c`中调用。 - -### 概要设计 - -#### 背景 - -大作业有点难,不能只让我一个人抠脑壳,你们也得一起想。 - -#### 目标 - -设计完成函数原型,数据结构,全局常量。 - - - - - diff --git a/docs/概要设计书/auto_pilot_bus.drawio b/docs/概要设计书/auto_pilot_bus.drawio deleted file mode 100644 index d09ff70..0000000 --- a/docs/概要设计书/auto_pilot_bus.drawio +++ /dev/null @@ -1 +0,0 @@ -7Vhdb5swFP01PK4CTFh5XJOse9ikaam07Wlywy24MpgaE2C/fnawA06aj2rJirY9xff4+uuc6xMLB02z5pbjIv3EYqCO78aNg2aO73suupY/Cmk7JAy8Dkg4iTvI7YEF+QlmpEYrEkOpsQ4SjFFBChtcsjyHpbAwzDmr7bQHRmMLKHAC1jYUsFhiCjtpX0ksUo2G7iD9A5Ak1UtHpiPDJlkDZYpjVg8gNHfQlDMmulbWTIEq8mxe3u/p3WyMQy5OGXD3ME2qpP1yk9GndP44S0p+9ybUexOtOTDE8vw6ZFykLGE5pvMeveGsymNQs7oy6nM+MlZI0JPgIwjRajFxJZiEUpFR3Ss3zNtvavzVxITf9XTrYNZYUauj3RNrEkpW8SUcOKapHMwTEAfy/C5PcTBYQPN5CywDuR+ZwIFiQVZ2jWBdaskmTw99xzluBwkFI7koBzN/VoBM0LcGhVE3o74zfmApKxvdjCYabK2H1uq/oBKu/1fCMA+duxIG6r1cHD3vCtNKr+T4IRWKTNVKVCvDJL9aGlwu03ftSNsLp1SoUyJgUeA1cbX0cVukvWSvgAtoDtKje4Ngq6KNvdcDTzVGmQ7sNHQvxaj/b9T7ZRxtx7K8t7bAgb8lXHfh9Kgt7c7gXl70GnL+tixHbcjck5H40OYt87fR7I2L5v12j4ynywev4IxS4Lbpo9GYPvJsT0D+M6bvPmP6k0uZPjqB1/uq/EHYWDkN3bFxGp3A6VMFvB0rpZ6356/r1Sg1pn+sTsfKKPKDo4xGf5TQA+/nDW0cEzpWRifu8Ro9E6My7L9JdM+z/ssOmv8C7VnbctowEP0aPaZjW74+2lzSNs0MU6aT5KmjYgUrNRYR4uJ+fSVbxteQUBKgmTyhXa1kcc7Z1RoA7M02lwzNo2sa4hgYWrgBsA8MQ9egKz6kJ809tqnnjikjoQoqHWPyBxcrlXdJQryoBXJKY07mdeeEJgme8JoPMUbX9bB7GtefOkdT3HKMJyhue29IyCPltTWtnPiMyTRSj/aKiRkqgpVjEaGQrisuOACwxyjl+Wi26eFYglfgkq8bPjG7PRjDCX/JAp8/3mx6X4OhcYsMZzQZXaTownDU4XhafGMcCgCUSRmP6JQmKB6U3mCyZCssd9WFwegyCTNLE1a54BulcxXygDlPFbVoyalwRXwWq1lxfJbeqvWZcSeNT1Zh9jfVyX5aWPGvDM4VZpwIwoSrDYlCaUGXbIJ34QCVthCbYr4r0MwDJUqVRyjILzGdYXFIEcBwjDhZ1WWElBqn2zi11GcMpZWAOSUJX1R2HkmHCFCJJXSW76jSytQa5D8TD2EtXgzyExRW5auUrkxQ+4jL+xDXfuKyXltcFYL/gT917hWKl+pRYOABrw88Dwxs4PeBLzwOcH0Q2NLjasDVW6SXLEpK1hHheDxHGWRrcWvUGXsSZkkF3uyEpZjVG2J3lL2uVPCiLEeV4m1rhyM5ukq//wjWjzQaW1+ufuKHy+v1RRuT5xPhFbVfyv2upvZu7R8gdPM/FbrZIXQLuB5w+2DggmAIvODksoZWQ9baEWXdiRvUWqCcrsDXRa7vX+DxhvB8J1NUvtzebiXG5U7SSCvGCDMiEMXs8AyyXppB8Cz6EFPTa5q0n+lDdEfbFf82fQg0zkemOji0DylkqlckqjZ6UqTHEOR5NMZWQ2Cmt1uQzfjjNMZWx31jgsCVnZQaBPIG8geywzq3i8e0T91PGd33tbimddmPeibwhrsQFXe6PwSBI3vWQAduG2MBDa8DueCM/sY9GlNZ5hOayCpxT+K44UIxmSbCnAjA5Y0QFLnrq4kZCcOsxHQxV680r0CeARsC160WeXYHd/CtuOt6qch4cXvZK4QLRMp+cNf1ImMZ7cQ7KndddcsCXg/4bpaAuhzLBLSyV0QH+EE2yHIz2EnruyWxmYBd1fOoJDrdxdPNCCooe7d0mEajHnonpsPbqxdol8p3y5TV/M3SfbObS5jlD/F5l1f+nQEHfwE=7VpLk6M2EP41OmYL8RDSEWy8k1Q2lao55HHTGo1NFiMXlsd2fn0kIcwAmrHjGRs28cmo1QLc3V9/rRbAm6z2n0u6Xn7hKcuB66R74E2B60LHw/JHSQ6VBPmwEizKLDVKjeAx+5vVK410m6Vs01IUnOciW7eFc14UbC5aMlqWfNdWe+J5+6lrumA9weOc5n3pb1kqlpWUOE4jf2DZYlk/GdUzK1orG8FmSVO+eyHyEuBNSs5FdbXaT1iujFfbpVo3e2X2+GIlK8Q5C7xsUbIf939G6S/rn6bh7gt6gD9A37ycONT/mKXSAGbIS7HkC17QPGmksfwnazVrbM5LKSv5tkiZepQjR826nzlfSyGUwr+YEAfjYboVXIqWYpWbWfkvysPvav2noB7+YW6nB9N9a3Qwo5x+ZXlM598W+hUmPFfvM03ZE93m0jDxEy/EjK6yXK14YPkzE9mcmgnzOhCacX85K9JIxZH6vzndbLK5soAo+TfWV+77xLhpw7flnL3lCBPbtFww8YaeW+kpJ714gPH4Z8ZXTBpHKpQspyJ7bkcxNWBYHPWaeJEXJmT+TfhU932m+dY8CSQIEARwCBIfxDGIEUgwiGbqOgkAnqlZqRNJIVQSMgUktOlgEE+VWkIAhoB4+s4BiB11geVUope7AE+0ZKIfGig5iUASgmiq7xOqVVHQi/MmYpXzd8tMsMc11U7ayVzWjs5XHfvMSsH2b7rCzKI6pZlMGJjhrkkrsM4VyxcpBTnXcl7fJnfsD4F990zse6PCvmvFPiYaqoFCqIJqoFBsJEQJJR5xpNOCVHYUtMcGTEgGR2Z4R+YokOmdiUx/VMj0LMjUdCgRqACZABxofk1qZI6SID04NA7RBTC8GuTgCchdHuX+mVEejCrKIb4nyVEkyXPDp4bzSOLHHR/Jwlb0NMF0jx/tMDSq+PEtLCupVG5kfbMJlozbZ1nJxDE0O10imTju8+6Sr75uNzfi3KDFub5n4Vxo4Vx8Lc69BJXvRuDlwRucGbwfvnfTSyU86eGFwppnhdi8uPOvStC4G6NOieU7HYdVd2zcd3y1yz0aWICCQBzW7Z4IRE7dAAr1FATYVX0fggGZGVSRfmDcukDFTsd64dAFKraYtm/IY3NMd+SifstX/n/RtlY7yxe8UDB7yvK8I6J5tigUP0irMkWGypqSY/LITKyyNNUYtbmnjdsP8FCI2x7yLR5CFgd5V9vJu0Oks9tvIWqKOF0EwlGRuHs//xhHEXh2ALnjCqD6vU+Ugf02KFLsFml2Iw6IkD668AH29YmFAzCypPIhS8WAuJ/axWKALfwXBDcsFuElHZr7Hu4K8B3s/PKiOhg6brtQ6ByeX6cQro3UyRUnUT++Sph09xGDV8KQWGyLlK3UURPRF/53Uwq/E/Qf4GEUtj0cuANX0q6NaGsSvXvxlR1rJ80FlqPN23rRGx1hHzn5f0XY7vdF2EGn9RKizsduJ/Rvwu+und9P7wWOFxjEM0BioxwTszsg+kspOTSfTRAQVZ9MQUVn7yoGhs9R3WPf0NaCvmkt4do6lvU27U415xUMyLI5vC3VIIsXddPZfEs41SV1BTnnPwMnz2v7wfcHh5OtS913xL00P7cR43UbMTYffxDW5LD5RL0iyuZDfy/5Bw==7VnbcpswEP0aPabDxWDxCL407aQz6WSmubx0FJCBRiBGyLGdr68EkjGGuEk9jpPWLx7paNdIu+fsChvYo2z5maEi+UYjTIBlREtgj4FlQdcRnxJY1YBjD2ogZmlUQ2YDXKVPWIGGQudphMuWIaeU8LRogyHNcxzyFoYYo4u22YyS9lMLFOMOcBUi0kWv04gnNeoZRoOf4zRO9JNdvZIhbayAMkERXWxA9gTYI0Ypr0fZcoSJjJ2OS+03fWZ1vTGGc/4Sh8z6YcFgenvtPXy/9clNMvWeznSYS77SJ8aRCICaUsYTGtMckUmDBuIkhVxVMadMYIzO8wjLRxli1vhdUFoI0BTgL8z5SmUYzTkVUMIzolbFKdjqRvp/cvT0Vn1dNRkvW7OVmhF0j0mAwoe42sKIErmfcYRnaE5EYIIZzfkUZSmRHueYPGKehkgtqO2Yppp33XEe+ZJH8rwElWUayghwRh9w17gOpozgs0lSUEnnLFRWd1+shF9cLqyvd7hwfrLFzb15psmOWIz5rgyuqSQkiGmGRXCEH8ME8fSxvQ+kxBCv7Rq+iIGiTD99dm3yEZG5ehKYQOBPQRCAiQPgFHiuRoZg4oLABNCqliDwhtWSCXzYIWFDJ5mZRZJyfFWgKmALUWfa1Nkzw+oMmHG83J22bpiVg+0qHakqZ2pdLZqaYepCkGzUC+23T2b6aWF2YnoS9lsL+3nBvkDY8I2EvWuTLWEPpao9r1KvGPvVwANwLGUcCKkHUuFC8EFl4xnA65LwgwvbGhxd2NZJ2O9T2PCFwvaOKWzYI2xXytjX3RiOKhmPKmELhfsS/MdkbA+PLmP73cnYbIm40fR/JmPvjfpz5SpOiFYbBgVNc15ufPOlBBoiO1tEduytl74/2A8MY4u69Q4aIq+Psge3B++O28aJ26/h9r4vlX/FbWv4Om5v2+v5Qbnt9fTP6m3WH6jbry/a5gAEEMBADww18P2e1iqR6g25vjP77sZ1WjfkTvtNaHY/Lz9E63WcdgXyelqv3dN64cFar9Obwzr225EWB+ftkLZlmtNcVq9ZSsgWhEga51LgIlBYVjMZRhF84quFLI2iqvT15bBd+o6fxvUPsjqNPS9Cbk8W7YNl0e29ydZSOmWxP4ud68DhsiimzW/bdfVt/iCwJ78B7Vpbc6s2EP41ekwHcecRfGlOJ71mTpP25YxiFCBHIA+WY7u/vhJIEAF2fOrEdnr8kkGrXbPa/b7dRRNgjfL1jyWapz/TGBNgGvEaWGNgmr7r8L9CsKkFjmXXgqTM4loEW8Ft9g+WQkNKl1mMF5oio5SwbK4LZ7Qo8IxpMlSWdKWrPVKiv3WOEtwT3M4Q6UvvspiltTQwjFZ+jbMkVW921U6OlLIULFIU09ULkTUB1qiklNVP+XqEiYidikttN92y2zhW4oLtY3Bzt3n6hO7vkpufok9Pv/7xZz5zrkzpG9uoA+OYn18uaclSmtACkUkrjfhB5mJXhpyWXFbSZRFj8SaDr1q7G0rnXAi58AkztpEJRktGuShlOZG7/BDl5l7Y/+Co5V/y56rFeK2tNnJF0AMmEZp9TSoXRpQIf8YxfkRLwuMSPdKCTVGeEWFxjckzZtkMyQ3pDoRy3TfHRRwKGInzErRYZDMRAVbSr7ivXAdTRHBrjqRoQZflTEX874fPSeZfreP7368Xv3jzL87nK4V1VCaY7UggbJDEGYhpjnlwuF2JCWLZs+4HklxIGr0WLvxBImYYPbucfEZkKd8EJj4IpyCKwMQB/hQErpJ4YOKCCALfrLZ8EHjVFgSh3wNhCyeRmVWaMXw7R1XAVrzM6NA5MMPyDLhkeL07bf0wSwPLkRyXRQ6q6rVqSwZUdSB9US5c4/DMDMPiQuzTE3s7Yfch9rGYvctLjdmeoHUQVPTlz2H1EAB/LHgcca5HguKc8VGlExgggD0UfnBmm/apmR2cC7HPiqD/tcq8IbHtPYntH8hrafobzbiHDVBtqAO1mUPVT9R+SasOBhs3DigYzrngsoEC1IDQ4uI7azj74vLQflOZ8hOizQuFucDbYjtsHUuHrQM7HzGv6Jue0UFz7cGbYtseaIbVCBvasuOF4+qhmnTr1hfywTcQ063okzaIJqJDCp1R1TC5eSh2e+0xpfnDcvEhWqPtaKmwvYHWaA20Rv/dhl6jF89T1yDjUoOanqfXoO0flMeuQc2splqnv7sGdfWhfYQa5A/UoNeryccetl3r1MM2tM6lovxfKwPc93vYPrA0HIYD+1xwsK2zmN9ra9kbQG/y3fWtvcXqzKuWt7u3dPVd5xX9bsl0jtCL4NDtkC0m3dAT10SBDYKpugsyKkkIfHvgJvgjj7+dyFv7Nqv3G3/d4Rmhino30vzgTA+pztWCFqKGPWaEdESIZEkhWM4DhUVNE2HkwSeh3MizOK4K4FAO9QJ4+jR2701ss59GdyCL1rtl0RvIovqkvGRxOIsNqVQWB65pj5pFhaILFw/gojNwo3DcLA41ugsXd2exe0X3jlzky/b/J+rppv0nFGvyLw==7VrJbtswEP0aHltoX46Sl6RIgxbIIc2RsWhJDS0aMr3160tKpGVKiu04XpNcAnE4tMiZ996MiACzM1rc5HCc3JMIYWBo0QKYXWAYnmOzv9ywLA22aZWGOE+j0qRXhof0HxJGTVinaYQmiiMlBNN0rBoHJMvQgCo2mOdkrroNCVbfOoYxahgeBhA3rY9pRJPS6mtaZb9FaZzINztyZgSlszBMEhiR+ZrJ7AGzkxNCy6fRooMwj52MS7mu/8rsamM5yuguC5ZxOL17vBvr89n90zBf/oC/sm/iVyZ0KQ+MInZ+MSQ5TUhMMoh7lTVkBxnzWRFykjNbTqZZhPibNDaq1v0kZMyMOjP+RZQuRYLhlBJmSugIi1l2iHz5h6//bsvhk/i5YtBdKKOlGGH4jHAIBy9xsYUOwXw/3QgN4RSzuIRDktE+HKWYr7hFeIZoOoBiQmxH18W4uRxlUcBhxM+L4WSSDngEaE5eUNO5mRIZXzLNB2hDHgwBbZjHiG7wE+ThSVp7gUj4DSIjxILDHHKEIU1nKoih4EK88qvgwh4EYt6AHrHrGcRT8SbQ80DQB2EIejbw+sB3pMUFPQeEOvCMYsoDvltM6SDwGiCs4MQzM09Sih7GsIjgnMmMCp13ZvjVpM1QTtFiY5jFrGkLjguR06V6zSvJ0KUOJGty4WhHyoz5xeuL4LW1I69146KIbbUQ2+Ws9v2Cvew5KB584HU5jUNG9ZAznBE+LHx8DfjN6nLlxDascxPbvhRiXxRB91WZ/Ynt7khs/9C8Fkt/k5RteQVUS1eBumpD5U+UGxWrahhcbWN/WDqXAssVEnQFBxUsPna92RWWB+8ji6XshHC55jDmcJu8jlrbVFFr67VPmC3+hqvVwFzu4KDQdltqYdHABpYoeEG3eCj63LLyBazt9Xlvy8ukBcIeL5Dcp1PUS7Y84LON6piQ0fN0chWV0bKVVFhuS2U0Wyqjd6zK2PyKOLcEaZ9SgvwdJejgHe9eErTq1GTh9DZLUN1ft04gQX6LBG0Xk+tutR3z3K22bKnOrygfRBnkR+5WaXAPLQ3vw8EFXpKqlcX4JKVlZwAd56vrrbXFrLWrpru5ttT9HXuLf10y7RPUIpkDpRhZvNENXH5J5FvA78ubIK2wBMCzWq6Br7n7rUXe3LVYHa371c32HqGIej3S7JRUDanK1YxkXMOGKcY1E8RpnHGWs9ghrmk8Ziz4OBATozSKCgFsy6EqgOdPY/3WxDKaaXRasmgeLYttF6/yi/Iri+1ZXJFKZrHlkva0WbS/uPhuLtotFwqnzaLzxcU3Z7F+Q3dELrJh9c8TZXdT/QeK2fsP7ZnbcpswEIafxjPthTMSR/vWh7pN2ySNm7TJTUZjFFALiJGFgTx9wUgGjO24mSSonVzZu9Jy+P5ddrF7+jhIZwxF3lfqYL+nASft6ZOepkGgD/KPwpOVHsuApcNlxBGbKsecPGAZKbwxcfCysZFT6nMSNZ0LGoZ4wRs+xBhNmtvuqd88a4Rc3HLMF8hve38Qh3uldwhA5f+IievJM1tyJUBys3AsPeTQpObSpz19zCjl5bcgHWO/gCe5lHEf9qxuLozhkB8TwAZ35zfu+fTCzGxguKOzIGV9qIuL45m8Y+zkAIRJGfeoS0PkTyvvaBGzFS6OCnOD0Th01hbIrSrgC6WR2PILc54JaVHMae7yeOCLVZwS/rMIP9FMYd7UliapOPTayKQRcpaVUYY2lI4irg9OALSkp4peW43wC8xIgDlmwtkGKhgvacwWgs6Mx6PrmCTf727vSZ/PrOv4ti8TEzEX8wO0zXJfQbh2AiHXDNP8aliWb2DYR5ysmimIRCa7m32V2PkXofffaG+oo31NeHBim8dqb5p2Xftcel1N5WFXyo/p2ec7MjyF/aVxmsEHql/97lvdC1/TsKHgI/K9vFJ2V0oduuoV8mNxpgCR8N37loCVIgXexCMczyO0JpLknblJfy/FFWYcpwfvW6zqtmhroq8bwkyqJgll5/NqDdICL/U00/7vpD70WHk0qYdqNZ5WUl9i5IxpeE9cBVIbmmYjteGg89y2u8/tzZRmP2FKg41yqKrj2QvCPLYfKzaKDd4EfmaBLaUE3tzfm8DPJLB8ACsyUqv0Hv0UfYvXZmBtiTx8TOanv00dq/1O2JpS0pv/uPSgw9LeCdRQ6tFt7pxWP4VRzBUYVnWg2rBqt3hdMBLyOUccKwDM0oBiwIYtYGOGc1iXiPhLBYgNmsB02DUw2C7JkthVNIqX32LMMgWwbX4SEdw0u3Nu1h5uE5qEKpGDWxln7SBnviY5KVO9CcQFMhVobeWZ8Zp5dmg8q8GaYB8rVp6G2WF5Hhp7WtgUq85tcC9ZnblZ/UG6Xqv9zaxP/wA=5ZZRb5swEMc/DdL6sAlwGrWvDWSr1EaqoirtU+XFN/BkOOSYAv30NeEcgmii7mFZpD3B/Xxnn/9nn+yxWVZ/17xI71GA8kJf1B6LvDAMfHZlPy1pOjKdBB1ItBTk1IOlfAMXSbSUAjYDR4OojCyGcI15DmszYFxrrIZuv1ANVy14AiOwXHM1pispTNrRa9/v+Q+QSepWnrqRjDtnApuUC6z2EIs9NtOIpvvL6hmoVjynSxc3PzC6S0xDbj4TsFjMn/2X6P5WBs3Tz1W8emTx10vKzTRuwyDs/slEbVJMMOcq7umNxjIX0M7qW6v3uUMsLAws/A3GNFRMXhq0KDWZolGbsG6e2vhvl858pum2RlQPrIasLtc2wYMSENpgqddwZN/uKHGdgDniF+4KZU84YAY2HxunQXEjX4d5cDpqyc6vr4b9oYL8QXFo3leuSlopAgUGHoubcvNQgm6+XIzq11enlbpKpYFlwbdiVPaKDitBC4A2UB/XdKxB7a5CF9G4e0t21d+WYEIs3bspU/8vqRaOVJvLXCxsZzoDtXbykFwh+0Cu8JRyTf/TDsA+2QEm/7IDsAMdIMIqP6MewIJzawKTc24CLDxdE7Bm/8TYju091Fj8Dg== \ No newline at end of file diff --git a/docs/概要设计书/main模块函数调用.png b/docs/概要设计书/main模块函数调用.png deleted file mode 100644 index e70889e..0000000 Binary files a/docs/概要设计书/main模块函数调用.png and /dev/null differ diff --git a/docs/概要设计书/main模块流程图.png b/docs/概要设计书/main模块流程图.png deleted file mode 100644 index 164ac50..0000000 Binary files a/docs/概要设计书/main模块流程图.png and /dev/null differ diff --git a/docs/概要设计书/query模块函数调用.png b/docs/概要设计书/query模块函数调用.png deleted file mode 100644 index 8a82003..0000000 Binary files a/docs/概要设计书/query模块函数调用.png and /dev/null differ diff --git a/docs/概要设计书/先来先服务流程图.png b/docs/概要设计书/先来先服务流程图.png deleted file mode 100644 index c00a8f5..0000000 Binary files a/docs/概要设计书/先来先服务流程图.png and /dev/null differ diff --git a/docs/概要设计书/最短寻找时间优先策略.png b/docs/概要设计书/最短寻找时间优先策略.png deleted file mode 100644 index e8eeaf2..0000000 Binary files a/docs/概要设计书/最短寻找时间优先策略.png and /dev/null differ diff --git a/docs/概要设计书/概要设计书.md b/docs/概要设计书/概要设计书.md deleted file mode 100644 index 75e3ade..0000000 --- a/docs/概要设计书/概要设计书.md +++ /dev/null @@ -1,274 +0,0 @@ -# 概要设计 - -## main函数流程 - -![](main模块流程图.png) - -## 轨道模块 - -> 轨道模块是比较基础的模块,许多模块都建立在这个模块的基础上 - -模块的主体是一个表示每个轨道节点的结构体。 - -### 创建结构体 - -```C -/** - * 创建轨道列表 - * @param length 站点之间的距离 - * @param node_num 站点的个数 - * @return 指向首站的指针 - */ -rail_node_t * CreateRails(int length, int node_num); -``` - -这个函数的难点应该是创建一个双向的循环链表。 - -### 寻找指定的站点 - -```C -/** - * 查找指定编号的站点指针 - * @param rails 轨道的头节点地址 - * @param id 需要查找的站点编号 - * @return 需要查找站点指针 - */ -rail_node_t *FindNode(rail_node_t rails, int id); -``` - -比较重要的工具函数,给定编号寻找对应的站点站点指针,不过没啥难度。 - -## 公交车模块 - -> 公交车模块就是比较复杂的模块了。 - -模块的主体是一个表示公交车的结构体。 - -### 运行公交车 - -```C -/** - * 每个时刻使公交车前进 - * @param rails 轨道链表 - * @param direction 公交车前进的方向 - * @param bus 公交车 - * @return 公交车是否到达站点 - */ -int RunBus(rail_node_t* rails, bus_t bus, int direction); -``` - -这个函数不难,就是根据指定的方向让公交车前进,同时判断公交车是否到站。 - -## 请求模块 - -请求模块的核心是一个表示请求的结构体。 - -### 创建请求 - -```C -/** - * 创建请求 - * @param query 请求链表队列 - * @param type 请求的类型 - * @param node 请求产生/指向的站点 - */ -void CreateQuery(bus_query_t query, int type, rail_node_t node); -``` - -还是一个简单的链表创建函数,主要的关键点在于说明的第五点第四条: - -> 如果在某个请求没有完成时再有相同的请求(请求类型和站点全部相同)发生,则该请求被抛弃 - -也就是在创建的时候要判断是否已存在相同的请求。 - -### 删除请求 - -> 删除请求其实就是处理请求的同义词 - -这个函数没啥意思,就是删除一个链表节点。 - -## 控制器模块 - -> 全程序最复杂的模块 - -### 时间计算 - -一个`int`类型的全局变量储存全局的时间。 - -```C -/** - * 时间增加 - */ -void AddTime(); -``` - -一个可有可无的函数,负责将时间加一。 - -> 可能后期删除,作用不明显。 - -### 策略简述 - -策略的相关函数会在公交车到站的时候调用。 - -策略一般包括两个函数,方向控制函数和请求处理函数。 - -### 先来先服务策略(FCFS) - -> first come first serve -> -> 对于先来先服务策略,车一次停站只完成一个请求,即使在这个站点上即有乘车请求,车内也有到该站的请求,也只能按策略完成已经调度的那个请求。但是完成当前请求后,如果发现时间序列上后续的一个或多个连续请求都恰好在同一站点(即连续的同站点请求位置相同,但请求类型不同),则可以立即完成这些连续的同站点请求,也就是说特殊情况下,一次停车的1秒内可完成多个请求。 - -#### 方向 - -```C -/** - * 在先来先服务策略下应该前进的方向 - * @param bus 公交车 - * @param queries 请求队列链表 - * @return 前进的方向 - */ -int FCFSDirection(bus_t bus, bus_query_t queries); -``` - -直接给出最先的一个请求就可以了。 - -将给定的请求赋给全局变量。 - -#### 请求 - -```C -/** - * 在先来先服务策略下给出处理的请求 - * @param bus 公交车 - * @param queries 请求队列链表 - * @return 需要处理的请求 - */ -bus_query_t FCFSQuery(bus_t bus, bus_query_t queries); -``` - -按照指定的策略给出现在可以处理的请求。 - -在这里是当前所在站点和第一个请求指向站点相同是即可处理,而且连续处理。 - -### 最短寻找时间优先(SSTF) - -> 对于最短寻找时间优先策略,一次服务的目标请求一旦确定,即使中途产生更优的请求也不可以更改。但如果新的请求恰好可以顺便服务(同方向的站台请求或车内请求),可以为新的请求停站。具体为:程序计算离当前车的位置最近的请求,如果没有请求则原地不动,否则按最近的路线(顺、逆时针)去接(送)。如果车途中遇到与车目前同方向的上车或下车请求,可以停下一秒解决,反方向的上车请求不停车。车服务完目标后,反复此过程,直到end。特别地,当车到达目标站点时,可以停一次车(1秒钟)完成该站点已接收的所有类型请求(区别于顺便站停靠)。 - -#### 方向 - -```C -/** - * 在最短寻找时间策略下应该前进的方向 - * @param bus 公交车 - * @param queries 请求队列链表 - * @return 前进的方向 - */ -int SSTFDirection(bus_t bus, bus_query_t queries); -``` - -这个函数比较难,求出最短前进的方向即可。 - -将处理的请求赋给全局变量。 - -#### 请求 - -```C -/** - * 在最短寻找时间策略给出处理的请求 - * @param bus 公交车 - * @param queries 请求队列链表 - * @return 需要处理的请求 - */ -bus_query_t SSTFQuery(bus_t bus, bus_query_t queries); -``` - -给出当前需要处理的请求。注意有些请求时可以处理的,有些请求时不能顺便处理的。 - -### 顺便服务策略(SCAN) - -#### 方向 - -```C -/** - * 顺便服务的前进方向 - * @param bus 公交车 - * @param queries 请求队列链表 - * @return 前进的方向 - */ -int SCANDirection(bus_t bus, bus_query_t queries); -``` - -也是判断最短的前进方向,但是 - -## 输入输出模块 - -> 输入输出模块是比较基础的模块,主要作用就是调用其他模块实现的功能。 - -### 配置文件读取 - -```C -/** - * 读取配置文件,创建轨道链表,同时读取需要使用的策略 - * @return 指向轨道链表的指针 - */ -rail_node_t* ReadConfigFile(); -``` - -这个函数需要完成三个任务: - -- 解析配置文件。(重点) -- 调用函数创建轨道列表。 -- 读取指定的策略。 - -### 打印当前状态 - -```C -/** - * 打印当前的状态 - * @param rails 轨道链表 - * @return 返回需输出的字符串 - */ -char* PrintState(); -``` - -输出的格式如下: - -``` -TIME:秒数 -BUS: -position:0 -target: 0000000000 -STATION: -clockwise: 0000000000 -counterclockwise: 0000000000 -``` - -这个函数的实现应该不难,遍历几个链表就结束了。 - -> 返回一个字符串是为了便于测试,直接`printf`出来不好测试,也不符合解耦的设计策略。 - -### 读取输入 - -```C -/** - * 读取标准输入流中的输入 - * @param inputString 输入的字符串 - * @return 当前读取的状态 - */ -int ReadInput(char* inputString); -``` - -这个函数的实现比较困难,在于读取对应的输入并调用相关的函数。 - -输出的`int`值是一系列定义的宏: - -```C -#define IO_CLOCK 0 // 读取时钟指令 -#define IO_READING 1 // 读取请求指令 -#define IO_END 2 // 读取结束指令 -``` - -便于main函数确定下一步的行为。 - - - diff --git a/docs/概要设计书/模块结构图.png b/docs/概要设计书/模块结构图.png deleted file mode 100644 index 53c6405..0000000 Binary files a/docs/概要设计书/模块结构图.png and /dev/null differ diff --git a/docs/概要设计书/自动机状态图.png b/docs/概要设计书/自动机状态图.png deleted file mode 100644 index 34be03f..0000000 Binary files a/docs/概要设计书/自动机状态图.png and /dev/null differ diff --git a/docs/概要设计书/顺便服务策略.png b/docs/概要设计书/顺便服务策略.png deleted file mode 100644 index e8eeaf2..0000000 Binary files a/docs/概要设计书/顺便服务策略.png and /dev/null differ diff --git a/docs/生产环境/1.png b/docs/生产环境/1.png deleted file mode 100644 index 522c1fb..0000000 Binary files a/docs/生产环境/1.png and /dev/null differ diff --git a/docs/生产环境/10.png b/docs/生产环境/10.png deleted file mode 100644 index 9b592f5..0000000 Binary files a/docs/生产环境/10.png and /dev/null differ diff --git a/docs/生产环境/11.png b/docs/生产环境/11.png deleted file mode 100644 index 61bd0ea..0000000 Binary files a/docs/生产环境/11.png and /dev/null differ diff --git a/docs/生产环境/12.png b/docs/生产环境/12.png deleted file mode 100644 index 91d5eb0..0000000 Binary files a/docs/生产环境/12.png and /dev/null differ diff --git a/docs/生产环境/13.png b/docs/生产环境/13.png deleted file mode 100644 index 7672965..0000000 Binary files a/docs/生产环境/13.png and /dev/null differ diff --git a/docs/生产环境/14.png b/docs/生产环境/14.png deleted file mode 100644 index c214d80..0000000 Binary files a/docs/生产环境/14.png and /dev/null differ diff --git a/docs/生产环境/15.png b/docs/生产环境/15.png deleted file mode 100644 index 264fd47..0000000 Binary files a/docs/生产环境/15.png and /dev/null differ diff --git a/docs/生产环境/16.png b/docs/生产环境/16.png deleted file mode 100644 index 4ca0aaa..0000000 Binary files a/docs/生产环境/16.png and /dev/null differ diff --git a/docs/生产环境/17.png b/docs/生产环境/17.png deleted file mode 100644 index 4a1b51f..0000000 Binary files a/docs/生产环境/17.png and /dev/null differ diff --git a/docs/生产环境/18.png b/docs/生产环境/18.png deleted file mode 100644 index 358d2ef..0000000 Binary files a/docs/生产环境/18.png and /dev/null differ diff --git a/docs/生产环境/19.png b/docs/生产环境/19.png deleted file mode 100644 index 84590cb..0000000 Binary files a/docs/生产环境/19.png and /dev/null differ diff --git a/docs/生产环境/2.png b/docs/生产环境/2.png deleted file mode 100644 index 2fcf3a0..0000000 Binary files a/docs/生产环境/2.png and /dev/null differ diff --git a/docs/生产环境/20.png b/docs/生产环境/20.png deleted file mode 100644 index 6232da9..0000000 Binary files a/docs/生产环境/20.png and /dev/null differ diff --git a/docs/生产环境/21.png b/docs/生产环境/21.png deleted file mode 100644 index 5345717..0000000 Binary files a/docs/生产环境/21.png and /dev/null differ diff --git a/docs/生产环境/22.png b/docs/生产环境/22.png deleted file mode 100644 index fdea15e..0000000 Binary files a/docs/生产环境/22.png and /dev/null differ diff --git a/docs/生产环境/3.png b/docs/生产环境/3.png deleted file mode 100644 index 652f4e5..0000000 Binary files a/docs/生产环境/3.png and /dev/null differ diff --git a/docs/生产环境/4.png b/docs/生产环境/4.png deleted file mode 100644 index f970a36..0000000 Binary files a/docs/生产环境/4.png and /dev/null differ diff --git a/docs/生产环境/5.png b/docs/生产环境/5.png deleted file mode 100644 index 409bd67..0000000 Binary files a/docs/生产环境/5.png and /dev/null differ diff --git a/docs/生产环境/6.png b/docs/生产环境/6.png deleted file mode 100644 index fe046ae..0000000 Binary files a/docs/生产环境/6.png and /dev/null differ diff --git a/docs/生产环境/7.png b/docs/生产环境/7.png deleted file mode 100644 index 6a00249..0000000 Binary files a/docs/生产环境/7.png and /dev/null differ diff --git a/docs/生产环境/8.png b/docs/生产环境/8.png deleted file mode 100644 index b21baf2..0000000 Binary files a/docs/生产环境/8.png and /dev/null differ diff --git a/docs/生产环境/9.png b/docs/生产环境/9.png deleted file mode 100644 index 72c93c9..0000000 Binary files a/docs/生产环境/9.png and /dev/null differ diff --git a/docs/生产环境/生产环境.md b/docs/生产环境/生产环境.md deleted file mode 100644 index cfb7fe8..0000000 --- a/docs/生产环境/生产环境.md +++ /dev/null @@ -1,291 +0,0 @@ - - -# 生产环境 - -> 遇到任何的问题都可以告诉我!! - -## 软件安装 - -![](1.png) - -在`Program.zip`压缩包中有两个程序,分别是`cmake`和`VSCode`。 - -这两个软件的安装都比较的简单。先解压缩文件,分别双击两个安装程序安装就可以了。在安装的过程应该只用无脑下一步。 - -> 在安装`VSCode`的过程中可能需要选择为”所有用户“还是”当前用户“安装,一般选择当前用户就可以了。 - -## 编译器的安装 - -编译器的安装算是比较复杂的。 - -首先解压缩`mingw64.zip`这个压缩包,然后把这个文件夹放在一个**你自己记得到**而且**文件路径中间没有空格没有中文没有什么奇奇怪怪字符**的地方。 - -> 这里表示把工具添加进入环境变量,我们就不用再运行程序的时候指定程序所在的位置,系统会根据我们提供的名称在我们指定的路径下去搜索可执行的程序。 - -然后同时按下`win`和`s`组合键,打开搜索面板,搜索`环境变量`,选择`编辑系统环境变量` - -![](2.png) - -打开这个界面 - -![](3.png) - -点击右下方的`环境变量...`,打开下面的界面 - -![](4.png) - -我的界面可能和你们的看起来相当的不一样,尤其是里面的内容。 - -选中上面那一块区域,也就是“用户变量”中的`path`,就像下图所示 - -![](5.png) - -然后点击中间那三个按钮中的“编辑”,打开下一个界面 - -![](6.png) - -> 可能我们的界面看起来相当的不一样,我设置了相当数量的环境变量,这也侧面说明了设置这个是非常重要的( - -点击右侧的“新建”按钮, - -![](7.png) - -然后再点击右边的“浏览”按钮, - -![](8.png) - -选择到之前解压的编译器路径下,指向`bin`文件夹。 - -![](9.png) - -点击确定。 - -然后再次点击右侧的“新建”-“浏览”,但是这次选择`C:\Program Files\cmake\bin`这个文件夹,然后一路点击确定。 - -编译器的安装就算是结束了。 - -## 测试环境的安装 - -现在将第三个压缩包`auto_drived_bus.zip`解压到你打算写代码的地方,这个地方的路径同样需要具有**没有中文没有空格没有什么奇奇怪怪的字符**的buff。 - -然后打开`VSCode`,选择打开文件夹,打开刚才解压的那个文件,现在界面应该是这样的。 - -![](10.png) - -然后按下`ctrl`和`~`组合键,打开终端。 - -![](11.png) - -依次输入下列三条命令 - -```bash -cd build -``` - -```bash -cmake .. -G "MinGW Makefiles" -``` - -```bash -cmake --build . -``` - -> 在输入的时候不要遗漏了`.`这类符号。 - -![](12.png) - -![](13.png) - -然后输入 - -```bash -bus.exe -``` - -![](14.png) - -说明everything works well。 - -## 原理的简单解释 - -### 多文件编译 - -在之前的学习中我们接触的都是单文件的编译 - -```bash -gcc example.c -o example.exe -``` - -在上面的命令中`gcc`是编译器,`example.c`是源文件,`example.exe`是编译之后生成的可执行文件。 - -但是如果我们现在是多文件编译呢?我们假设现在有两个文件`lib.c`和`main.c`,`lib.c`是一个库的源文件,里面有一些函数是我们需要的,我们会在`main.c`中调用这些函数。 - -那现在我们需要解决两个问题: - -- `main.c`文件中没有`lib.c`中编写函数的定义 -- 如何才能将两个文件编译为一个可以运行的可执行文件 - -对于第一个问题,我们使用头文件来解决,`lib.h`这个头文件中就包含了在`lib.c`中编写的所有函数的声明,当我们在`main.c`文件中添加 - -```C -#include "lib.h" -``` - -之后,我们就可以在`main.c`文件中愉快的使用`lib.c`中的函数了。 - -对于第二个问题,我们使用一种名叫“链接”的方法解决 - -```bash -gcc lib.c -o lib.o # 生成lib.c对应的可执行文件 -gcc main.c -o main.o # 生成main.c对应的可执行文件 -gcc mian.o lib.o -o main.exe # 将两个可执行文件链接在一个生成一个可执行文件 -``` - -> 我们常常使用的`stdio.h`等的头文件对应的可执行文件通过差不多的原理实现的。 - -然后我们假设一下,如果我们的文件数一多,编译起来要输很多行代码,是不是就很崩溃! - -然后我们使用了`cmake`工具。这是一个跨平台的编译工具,~~用过的人都说好~~。 - -我们只用在`CMakeLists.txt`这个文件中一次写明我们需要使用的文件,就可以一直套用这个模板编译软件。 - -```bash -cmake .. -G "MinGw Makefiles" -``` - -这一行的命令表示在我们目前所在的`build`文件夹中生成用于构建程序的一些文件,`..`是一个指针,指向当前文件的上一级目录,也就是`CMakeLists.txt`以及我们程序源代码所在的地方,`-G "MinGw Makefiles"`表示的是生成的文件是我们使用的编译器`mingw64`可以识别的格式。 - -```bash -cmake --build . -``` - -这一行是用我们刚刚生成的生成文件调用编译器生成可执行文件,`.`也是一个指针,它指向当前目录。 - -注意,如果在之后我们没有修改过`CMakeLists.txt`文件,那我们每次修改了源代码之后就只用执行 - -```bash -cmake --build . -``` - -来重新生成可执行文件; - -如果我们修改了`CMakeLists.txt`文件,我们就需要在执行 - -```bash -cmake .. -``` - -来重新生成那个辅助文件。 - -> 这里我们不用加上 `-G "MinGw Makefiles"` ,编译器只用指定一次。 - -### 在工程的实际 - -在初步了解了相关的知识之后,我们就可以开始把他们运用在工程中了。 - -我们的实际项目结构如下 - -![](22.png) - -`include`目录下是我们各个模块的头文件,现在的示例是`print`模块的`print.h`,而这个模块的源文件是在`src`目录下的`print.c`文件。 - -`src`目录下就是我们当前各个模块和主程序的源代码文件。 - -> CMakeLists.txt由我编写,我会写上比较详尽的注释,你们可以观摩。 - -那我们第一阶段的架构设计实际上就是头文件的编写。为啥?头文件包括我们各个模块中需要使用的函数的定义,在项目中会使用到的结构体、自行定义的类型等的都会写在我们的头文件里面,实际上,编写头文件的过程就是架构设计的过程。 - -在编写完成我们的头文件之后,我们只需在对应的源文件中实现相关的函数,我们的开发就算是完成了。 - -## VSCode的配置 - -### 安装扩展 - -为了能在`VSCode`中流畅的写`C\C++`,我们需要在`VSCode`中安装几个插件。 - -在`VSCode`的主界面上选择“插件”图标,也就是右侧的最后一个 - -![](15.png) - -> 图中的最下面那个图标 - -打开这个界面 - -![](16.png) - -在搜索栏中只用数一个字母`C`, - -![](17.png) - -选择这个`C/C++ Extension Pack`,这是一个辅助`C/C++`编写的扩展的合集,只用安装这个扩展我们就可以愉快~~并不~~的在`VSCode`中写代码了。 - -> 如果对`VSCode`的全英文界面感到不适,也可以搜索`Chinese`,安装简体中文的扩展包。 - -### 加载CMake项目 - -在`VSCode`中也有扩展提供了对于`Cmake`的支持,让我们可以不用在一次次的输入命令来编译。 - -在安装完扩展之后,我们重新启动`VSCode`,再次打开我们的工程文件夹,这个时候左下角应该会弹出来一个气泡, - -![](18.png) - -这个气泡就是`cmake`插件在询问你是否设置这个名为`auto_drived_bus`的工程,我们选择"Yes", 这时`cmake`扩展就会使用系统中安装的`cmake`来设置我们的项目。 - -![](19.png) - -这时在我们`VSCode`底部的状态栏就会出现一些`cmake`的选项,我们逐个来看 - -![](20.png) - -第一个表示`cmake`目前使用的是`debug`模式,我们可以点击切换不同的生成模式 - -![](21.png) - -第二个表示我们当前使用的编译器,如果我们在电脑上安装了不同的编译器,例如微软的`msvc`就可以在点击切换,当然,这里切换不仅是编译器的选项,生成的编译文件也从`makefile`变成了`vcporj`。 - -第三个按钮`build`是编译按钮,点击这个按钮就会生成可执行文件。 - -第四个按钮`all`是选择生成的对象,在一般情况下不用改动。 - -> 在这里我们的生成对象主要有两个,一个是我们的库,另一个是我们的主程序。 - -第五六个是两个按钮,长得像虫一样的那个表示调试按钮,说明这是用来抓`bug`的,下一个的那个就是一个简单的运行按钮,点一下就会自动开始编译运行。 - -> 我们也可以使用一些快捷键来代替上面的一些东西,比如`F5`表示运行,`ctrl`和`F5`同时按表示运行,按`F7`表示编译。 - -> 我这边的建议是使用`F7`编译之后,再在终端中执行,这样和OJ上的执行比较的近似。 - -## 下一步... - -### 关于Git - -再实际使用Git之前,先推荐这篇MIT的英文教程[VERSION CONTROL](https://missing.csail.mit.edu/2020/version-control/),这边文章没有像一般的Git教程一样扔给你一大堆的命令,而是介绍了Git的原理,我觉得这样可能更加易懂。 - -> 如果看英文有困难,可以看这个[翻译版](https://missing-semester-cn.github.io/2020/version-control/) - -如果黄海还不发`Gitlab`的文档的话,我就会打算在`gitee`上建立仓库开始干活了,我们在实践中学习`git`。 - -> 高情商:在实践中学习 -> -> 低情商:你们自己摸索 - -### 关于typora - -用`markdown`撰写文档是我一直的习惯,用word写东西实在不是碳基生物能干的活。不过由于我们需要叫word格式的文档,我结合`markdown`转`word`的效果和大家的意见在做决定。 - -> 最后再次强调,有什么问题一定要问!! - -## 写在最后 - -你们可能嫌我为啥要搞这么麻烦,为啥不直接简简单单的一个文件和`Dev C++`开发了事。 - -我当时想的是既然这是一次“大作业”,而且黄海也反复强调“软件工程”,那我们不如好好的体验一下“现代”的`C/C++`开发是什么样子的。 - -我最开始的想法仅仅是统一用`VSCode`进行开发,但是使用`VSCode`进行开发涉及到一个比较麻烦的环境配置问题。为了确保只用配置一次环境之后就可以在不同的电脑上获得流畅的编码体验,我就使用现在流行的`Cmake`工具进行统一的环境配置。 - -使用这个工具的好处有以下几点: - -- 不必关心比较复杂的`VSCode`设置 -- 可以进行比较舒适的模块化开发,避免的繁琐的编译 -- 便于后期引入图形库进行图形界面的开发 -- `CMake`是现在`C/C++`项目开发的事实标准。 \ No newline at end of file diff --git a/docs/说明文档/document_of_oj.md b/docs/说明文档/document_of_oj.md deleted file mode 100644 index 0617573..0000000 --- a/docs/说明文档/document_of_oj.md +++ /dev/null @@ -1,498 +0,0 @@ -# 公交车调度说明(OJ版) - -## 站点说明 - -环形轨道,一辆车,车辆可以双向任意行驶。我们规定**车辆的原始位置为0**(该位置**也是车站1的位置**),按顺时针方向每个单位位置坐标加1。如果轨道总长为10,则按顺时针方向走,位置9的下一个为位置0。车站编号同理,也是按顺时针方向依次递增。**车速固定,每秒一个单位**。停车接人或乘客下车时需要**停车一秒钟**。无论一次停站完成几个服务停留时间统一为1秒钟。各站之间距离相等,车辆经过站点时,根据调度策略,车辆可以停也可以不停。其他位置不允许停车。车辆只能在站点停站时才能改变行驶方向。 - -## 配置文件 - -各站之间距离可配置,站点个数可配置,调度策略可配置。这三个参数保存在配置文件中,程序要通过读配置文件获取。**配置文件的名字为`dict.dic`**。 - -配置文件为**文本文件**,以#号开头的行是注释,井号只可能出现在每一行的开头。 - -每行一个参数,格式为: - -参数 = 值 - -的形式。每个参数前无空格,参数名、等号、参数值用空格分隔。 - -其中参数有三个,即TOTAL_STATION,代表**站点总数,为大于1且小于等于20的整数**;DISTANCE,代表**每站之间的距离,为大于0且小于6的整数**;STRATEGY,代表调度策略,只能是FCFS(先来先服务),SSTF(最短寻找时间优先)和 -SCAN(顺便服务)之一。 - -另外: - -1、如果某个参数没有出现在配置文件中,则该参数取缺省值。 - -三个参数的缺省值如下: - -``` -TOTAL_STATION = 5 - -STRATEGY = FCFS - -DISTANCE = 2 -``` - -2、**三个参数在文件中的顺序没有规定**。 - -3、显然,**TOTAL_STATION与DISTANCE乘积就是轨道总长度**,所以配置文件中没有这个参数。 - -## 输入格式 - -若干行,每行一个指令。 - -指令共5种。分别为end、clock、counterclockwise、clockwise 和target。 - -**其中end是程序退出指令(不是停运指令,是时钟停止,程序退出的意思),只在最后一行出现一次**; - -clock是时钟指令,每出现一次代表过了一秒钟; - -counterclockwise、clockwise、target为请求指令,如果它们出现,同一行内后边一定有一个整数。如果是counterclockwise和clockwise,代表站台上的请求,后边的整数代表请求发生的站点号,counterclockwise表示逆时针方向乘车请求,clockwise代表顺时针方向乘车请求。如果是target,代表车厢内下车请求,后边的整数代表要去的站点号。 - -## 输出格式 - -程序开始,**先输出一次初始状态**,然后**每个clock输出一次当前状态**;程序**退出时输出end**。每次输出的格式如下,冒号后面没有空格,最后一次输出end后有一个换行。 - -> **TIME:秒数** -> -> **BUS:** -> -> position:0 -> -> target:0000000000 -> -> STATION: -> -> clockwise:0000000000 -> -> counterclockwise:0000000000 -> - -**首先输出当前的时间,即已过的秒数。** - -然后三行代表车辆,BUS:固定不变,position:固定不变,后边的数字代表当前车辆位置,target:固定不变,后边一排数字依次代表车内站点请求情况,0表示没有请求,1表示有请求。 - -最后三行代表各站点的状态, - -STATION: 固定不变, - -clockwise:固定不变,后边的数字依次代表各站点顺时针方向的请求情况,0表示没有请求,1表示有请求。 - -counterclockwise:固定不变,后边的数字依次代表各站点逆时针方向的请求情况,0表示没有请求,1表示有请求。 - -具体可参考输入样例。 - -## 策略补充说明 - -1. 公交车在没有任何请求时,留在当前位置静止不动,处于空闲状态;只有收到上车或下车请求,确定服务目标后,才进入行驶状态。 -2. 每一个请求均为单独的服务,即车内请求与站台请求没有必然联系。 -3. 当公交车在空闲状态,或者完成上次请求 (到达目标站点并停满1秒)后,开始一次新的调度。调度时,以之前收到的请求以及当前1秒内新发生的所有请求作为候选,按照调度规则选择出目标请求,整个调度过程执行时间忽略不计,即公交车在1秒的最开始完成上述所有动作,然后立即服务目标请求。 -4. 当车服务目标时要选择路程短的方向行驶,如果两个方向路程相同则选择顺时针方向; -5. 如果在某个请求没有完成时再有相同的请求(请求类型和站点全部相同)发生,则该请求被抛弃。如果已完成的请求再次发生时应按新请求处理。 -6. 对于先来先服务策略,车一次停站只完成一个请求,即使在这个站点上即有乘车请求,车内也有到该站的请求,也只能按策略完成已经调度的那个请求。但是完成当前请求后,如果发现时间序列上后续的一个或多个连续请求都恰好在同一站点(即连续的同站点请求位置相同,但请求类型不同),则可以立即完成这些连续的同站点请求,也就是说特殊情况下,一次停车的1秒内可完成多个请求。 -7. 对于最短寻找时间优先策略,一次服务的目标请求一旦确定,即使中途产生更优的请求也不可以更改。但如果新的请求恰好可以顺便服务(同方向的站台请求或车内请求),可以为新的请求停站。具体为:程序计算离当前车的位置最近的请求,如果没有请求则原地不动,否则按最近的路线(顺、逆时针)去接(送)。如果车途中遇到与车目前同方向的上车或下车请求,可以停下一秒解决,反方向的上车请求不停车。车服务完目标后,反复此过程,直到end。特别地,当车到达目标站点时,可以停一次车(1秒钟)完成该站点已接收的所有类型请求(区别于顺便站停靠)。 -8. 对于顺便服务策略。第一次行驶方向由时间最短请求站点决定。确定方向后,每次调度都按照当前方向,选择寻找时间最短的请求(不区分类型或方向)作为服务目标。如果去往服务目标站点行驶的距离超过轨道一半时,则需要切换行驶方向服务该请求。车辆行驶过程中,如果经过的站点有服务请求(上车或下车),则不管这个请求的类型或方向,一律停站并完成此请求。这意味着一次停车可能同时完成3个服务请求(上车(顺时、逆时)和下车)。车辆没有请求时则原地不动,直到有新的请求时再按照上述规则继续运行。 -9. 对于后两种策略(最短寻找时间、顺便服务),如果车辆途经某站点本没有停车计划,则新的请求只要在车辆到达该站点前产生,就能允许停车服务。 -10. 车处于停止状态开始一次新调度时(空闲状态或者完成上一次服务后),如果本站有请求且根据规则可以为该请求服务,则该请求立即完成,不再停1秒钟。 - -### 不保熟的策略详细说明 - -**(1)调度策略配置** - -公交车的调度策略只有如下三种: - -(a)先来先服务策略(FCFS):所有请求按照发出时间先后顺序来逐一完成 - -(b)最短寻找时间优先策略(SSTF):每次寻找完成时间最短(即距公交车位置最近)的请求并完成。 - -(c)顺便服务策略(SCAN):依照车辆行驶方向来完成请求,车辆行驶方向按照要求进行改变。 - -在默认情况下,我们设置调度策略为先来先服务策略(FCFS)。 - -**(2)策略详细说明** - -(a)先来先服务策略(FCFS): - -按照请求先后顺序来逐一完成,即谁请求在前,谁先执行。 - -> 就是按照文件输入中指令的先后顺序来执行 - -站点请求的顺逆方向对请求执行顺序无影响,车辆在完成请求时按照距离最近原则来选择行驶方向。 - -> 例:总共五站点,公交车在2站点完成请求后,下一请求是到达3站点,则选择顺时针方向行驶,而不是逆时针 - -在这种策略下,车一次停站只完成一个请求。 - -> 也就是说按照指令先后顺序来执行,在相邻请求所要求站点不同的情况下,车一次停站也就只能完成一个请求,即使在该站点有多个请求。 - -但是如果下一个请求恰好在同一站点,则可以一次停站完成2个或2个以上的请求。 - -> 在相邻请求所要求站点相同的情况下可以完成多个请求,例如:公交车接下来请求分别是在clockwise2, counterclockwise2, target3,则公交车到达2站点后可以一次性完成3个请求 -> -> 请求之前夹杂着的clock指令无影响 - -(b)最短寻找时间优先策略(SSTF): - -每次按照完成时间最短(即距离最近)来完成相应请求。 - -程序计算离当前车的位置最近的target、counterclockwise、clockwise请求, - -> 与先来先服务策略不同,这种策略的执行顺序主要依靠公交车的当前状态,即当前状态target,clockwise,counterclockwise中的请求,判断哪一个请求离公交车当前位置最近,然后执行 - -如果都没有请求则原地不动,否则按最近的路线(顺、逆时针)去接(送),直至完成请求。反复此过程,直到end。 - -一次服务的请求(目标)一旦确定,即使中途产生更优的请求也不可以更改。 - -> 请求只能一个一个地完成,中途不能更改当前正在执行的请求 - -但如果新的请求恰好可以顺便服务,即如果车途中遇到与车目前同方向的上车请求或下车请求可以停下一秒解决,反方向的上车请求忽略。 - -当车到达目标地点时,该站点恰好有两个相反的请求,可以停一次车完成这2个服务。 - ->该站点有多个请求时,到达该站点之后可以同时完成 -> ->与顺便服务不同,在去往目标站点的行驶过程中,如果有关于目标站点的新请求出现时,则不必要求其一定要在到达目标站点前起码1秒钟前提出,例如:公交车当前目标是行驶到3站点,如果车在到达3站点之后,立刻有一个关于3站点的另一个新请求,则这几个请求可以一起完成。 - -(c)顺便服务策略(SCAN): - -依照车辆行驶方向来完成请求,可以顺便服务(对车辆行驶方向无要求)。 - -> 与SSTF不同,这个策略中的顺便服务不会判断站台请求要求的方向与车辆行驶方向是否相同 - -第一次行驶方向由第一个请求出现后1秒钟内全部请求中时间最短(即距离最短)的那个请求决定。在行使过程中,如果所有的请求按照当前的行驶方向找出的最短完成时间都超过跑完轨道一半距离时间时,应该切换行驶方向。这是唯一的一个切换方向的规则。 - -> 分析:在确定最初行驶方向后,车辆切换方向有且仅有一种可能,即在当前请求完成之后再去改变方向。因为在车辆行驶至目标站点的过程中,其与目标站点的距离一定小于等于轨道总长度的一半,所以不能切换方向 -> -> 每次执行完一次操作后都要判断当前行驶方向是否满足要求,不行就切换方向 - -车辆行驶过程中如果经过的站点有服务请求,则不管这个请求的类型一律停站,并认为此请求完成。这意味着一次停车可能完成3个服务。 - -> 公交车可以到达目标站点后一次性完成所有请求 - -**(3)策略补充说明** - -(a)每一个请求均为单独的服务,就是说车内请求与站台请求没有必然联系。 - -(b)在寻找时间最短(即距离最近)的请求时,如果两个方向路程相同则选择顺时针方向。 - -(c)如果在某个请求没有完成时再有相同的请求发生,则该请求被抛弃。如果已完成的请求再次发生时应按新请求处理。 - -(d)对于SSTF和SCAN策略,如果车辆在某站点本没有停车计划,新的请求要至少要提前1秒钟产生才能享受顺便服务,忽略到达该请求地时再提出的请求。 - -## 样例 - -> 配置参数为TOTAL_STATION = 10、STRATEGY = FCFS、DISTANCE = 3 - -### 输入样例 - -clock - -counterclockwise 3 - -clock - -clock - -clock - -clock - -clock - -clock - -target 10 - -clock - -clock - -clock - -clock - -clock - -clock - -clock - -clock - -clock - -clock - -clock - -end - -### 输出样例 - -**TIME:0** - -BUS: - -position:0 - -target:0000000000 - -STATION: - -clockwise:0000000000 - -counterclockwise:0000000000 - -**TIME:1** - -BUS: - -position:0 - -target:0000000000 - -STATION: - -clockwise:0000000000 - -counterclockwise:0000000000 - -**TIME:2** - -BUS: - -position:1 - -target:0000000000 - -STATION: - -clockwise:0000000000 - -counterclockwise:0010000000 - -**TIME:3** - -BUS: - -position:2 - -target:0000000000 - -STATION: - -clockwise:0000000000 - -counterclockwise:0010000000 - -**TIME:4** - -BUS: - -position:3 - -target:0000000000 - -STATION: - -clockwise:0000000000 - -counterclockwise:0010000000 - -**TIME:5** - -BUS: - -position:4 - -target:0000000000 - -STATION: - -clockwise:0000000000 - -counterclockwise:0010000000 - -**TIME:6** - -BUS: - -position:5 - -target:0000000000 - -STATION: - -clockwise:0000000000 - -counterclockwise:0010000000 - -**TIME:7** - -BUS: - -position:6 - -target:0000000000 - -STATION: - -clockwise:0000000000 - -counterclockwise:0010000000 - -**TIME:8** - -BUS: - -position:6 - -target:0000000001 - -STATION: - -clockwise:0000000000 - -counterclockwise:0000000000 - -**TIME:9** - -BUS: - -position:5 - -target:0000000001 - -STATION: - -clockwise:0000000000 - -counterclockwise:0000000000 - -**TIME:10** - -BUS: - -position:4 - -target:0000000001 - -STATION: - -clockwise:0000000000 - -counterclockwise:0000000000 - -**TIME:11** - -BUS: - -position:3 - -target:0000000001 - -STATION: - -clockwise:0000000000 - -counterclockwise:0000000000 - -**TIME:12** - -BUS: - -position:2 - -target:0000000001 - -STATION: - -clockwise:0000000000 - -counterclockwise:0000000000 - -**TIME:13** - -BUS: - -position:1 - -target:0000000001 - -STATION: - -clockwise:0000000000 - -counterclockwise:0000000000 - -**TIME:14** - -BUS: - -position:0 - -target:0000000001 - -STATION: - -clockwise:0000000000 - -counterclockwise:0000000000 - -**TIME:15** - -BUS: - -position:29 - -target:0000000001 - -STATION: - -clockwise:0000000000 - -counterclockwise:0000000000 - -**TIME:16** - -BUS: - -position:28 - -target:0000000001 - -STATION: - -clockwise:0000000000 - -counterclockwise:0000000000 - -**TIME:17** - -BUS: - -position:27 - -target:0000000001 - -STATION: - -clockwise:0000000000 - -counterclockwise:0000000000 - -**TIME:18** - -BUS: - -position:27 - -target:0000000000 - -STATION: - -clockwise:0000000000 - -counterclockwise:0000000000 - -end diff --git a/include/bus.h b/include/bus.h deleted file mode 100644 index acc3b17..0000000 --- a/include/bus.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef AUTO_PILOT_BUS_BUS_H -#define AUTO_PILOT_BUS_BUS_H - -#include "define.h" -#include "rail.h" -#include "query.h" - -struct bus { - /** - * 指向站点的指针 - */ - rail_node_t* rail_node_pos; - /** - * 当前行进的距离 - */ - int distance; -}; - -/** - * 表示公交车的结构体 - */ -typedef struct bus bus_t; - -/** - * 全局的公交车变量 - */ -extern bus_t *the_bus; - -/** - * 每个时刻使公交车前进 - * @param direction 公交车前进的方向 - */ -void RunBus(int direction); - -/** - * 判断公交车是否到站 - * @return BUS_TRUE为到站,BUS_FALSE为未到站 - */ -int JudgeOnStation(); - -/** - * 获得公交车当前所在的位置 - * @return 公交车当前所在的位置 - */ -int GetBusPosition(); - -/** - * 给出在指定的方向下,指定的请求于公交车当前位置的距离 - * @param query 指定的请求 - * @param orientation 指定的方向 BUS_CLOCK_WISE BUS_COUNTER_CLOCK_WISE - * @return 距离 - */ -int GetQueryDistance(bus_query_t *query, int orientation); -#endif //AUTO_PILOT_BUS_BUS_H diff --git a/include/bus_io.h b/include/bus_io.h deleted file mode 100644 index c7c3735..0000000 --- a/include/bus_io.h +++ /dev/null @@ -1,38 +0,0 @@ -// -// Created by ricardo on 2022/5/6. -// - -#ifndef AUTO_PILOT_BUS_BUS_IO_H -#define AUTO_PILOT_BUS_BUS_IO_H -#include "rail.h" -#include "query.h" -#include "define.h" -#include "controller.h" -#include "string.h" -#include "stdio.h" - -/** - * 读取配置文件,创建轨道链表,同时读取需要使用的策略 - * @return 指向轨道链表的指针 - */ -rail_node_t* ReadConfigFile(); - -/** - * 读取标准输入流中的输入 - * @param inputString 输入的字符串 - * @return 当前读取的状态 - */ -int ReadInput(char* inputString); - -/** - * 打印当前的状态 - */ -void PrintState(); - -/** - * 打印当前状态的函数,供all_test使用,在oj上有问题 - * @param str 需要打印的内容 - */ -void PrintStateInner(char *str); - -#endif //AUTO_PILOT_BUS_BUS_IO_H diff --git a/include/controller.h b/include/controller.h deleted file mode 100644 index 4f63cc7..0000000 --- a/include/controller.h +++ /dev/null @@ -1,75 +0,0 @@ -// -// Created by ricardo on 2022/5/6. -// - -#ifndef AUTO_PILOT_BUS_CONTROLLER_H -#define AUTO_PILOT_BUS_CONTROLLER_H -#include "stdlib.h" - -#include "rail.h" -#include "query.h" -#include "bus.h" - -/** - * 当前正在处理的请求 - */ -extern bus_query_t *target_query; -/** - * 当前选择的策略 - */ -extern int chosen_strategy; - -/** - * 在先来先服务策略下应该前进的方向 - * @return 前进的方向 - */ -int FCFSDirection(); - -/** - * 在先来先服务策略下给出处理的请求 - * @return 需要处理的请求 - */ -bus_query_t *FCFSQuery(); - -/** - * 获得在SSTF策略下应该处理的请求 - * @return 指向需要处理的请求的指针 - */ -bus_query_t *SSTFGetQuery(); - -/** - * 根据指定的请求获得前进的方向,也就是前往指定的请求最近的方向 - * 在SSTF策略中使用 - * @param query 指定完成的请求 - * @return 前进的方向 - */ -int SSTFDirection(bus_query_t* query); - -/** - * 在当前站上可以顺便服务的请求 - * @param direction 当前公交车前进的方向 - * @return 服务的请求指针 - */ -bus_query_t *SSTFBTWQuery(int direction); - -/** - * 获得在SCAN策略下应该处理的请求 - * @return 指向需要处理的请求的指针 - */ -bus_query_t *SCANGetQuery(int direction); - -/** - * 根据指定的请求获得前进的方向 - * 在SCAN策略中使用 - * @param query 指定完成的请求 - * @return 前进的方向 - */ -int SCANDirection(bus_query_t *query, int orientation); - -/** - * 在当前站上可以顺便服务的请求 - * @return 服务的请求指针 - */ -bus_query_t *SCANBTWQuery(); - -#endif //AUTO_PILOT_BUS_CONTROLLER_H \ No newline at end of file diff --git a/include/define.h b/include/define.h deleted file mode 100644 index 80fe0ad..0000000 --- a/include/define.h +++ /dev/null @@ -1,21 +0,0 @@ -// -// Created by ricardo on 2022/5/6. -// - -#ifndef AUTO_PILOT_BUS_DEFINE_H -#define AUTO_PILOT_BUS_DEFINE_H - -#define BUS_CLOCK_WISE 0 // 顺时针 -#define BUS_COUNTER_CLOCK_WISE 1 // 逆时针 -#define BUS_TARGET 2 // 目标 -#define BUS_STOP 2 // 停止 -#define BUS_TRUE 1 // 真 -#define BUS_FAlSE 0 // 假 -#define IO_CLOCK 0 // 读取时钟指令 -#define IO_READING 1 // 读取请求指令 -#define IO_END 2 // 读取结束指令 -#define BUS_FCFS 0 // 先来先服务 -#define BUS_SSTF 1 // 最短寻找时间优先 -#define BUS_SCAN 2 // 顺便服务 - -#endif //AUTO_PILOT_BUS_DEFINE_H diff --git a/include/query.h b/include/query.h deleted file mode 100644 index 7337ef0..0000000 --- a/include/query.h +++ /dev/null @@ -1,57 +0,0 @@ -// -// Created by ricardo on 2022/5/6. -// - -#ifndef AUTO_PILOT_BUS_QUERY_H -#define AUTO_PILOT_BUS_QUERY_H -#include "stdlib.h" -#include "rail.h" -#include "define.h" - -struct bus_query { - /** - * 请求产生的时间 - */ - int time; - /** - * 请求的类型 - */ - int type; - /** - * 请求产生/指向的站点 - */ - rail_node_t *node; - /** - * 指向下一个请求的指针 - */ - struct bus_query *next_node; -}; - -typedef struct bus_query bus_query_t; - -/** - * 全局的请求链表头节点 - */ -extern bus_query_t *queries; - -/** - * 创建请求链表节点 - * @param type 请求的类型 - * @param node 请求产生/指向的站点 - * @return 当前创建的链表节点地址 - */ -bus_query_t *CreateQuery(int type, rail_node_t *node); - -/** - * 删除请求 - * @param target_query 需要删除的请求 - */ -void DeleteQuery(bus_query_t *target_query); - -/** - * 释放请求链表占据的空间 - * @param head 请求链表的头节点 - */ -void FreeQueries(bus_query_t *head); - -#endif //AUTO_PILOT_BUS_QUERY_H diff --git a/include/rail.h b/include/rail.h deleted file mode 100644 index 7ff4f07..0000000 --- a/include/rail.h +++ /dev/null @@ -1,74 +0,0 @@ -#ifndef AUTO_PILOT_BUS_RAIL_H -#define AUTO_PILOT_BUS_RAIL_H -#include "stdlib.h" - -struct rail_node { - /** - * 站点的编号 - */ - int id; - /** - * 距离上一个站点的距离 - */ - int last_node_distance; - /** - * 距离下一个站点的距离 - */ - int next_node_distance; - /** - * 指向上一个站点的指针 - */ - struct rail_node* last_node; - /** - * 指向下一个站点的指针 - */ - struct rail_node* next_node; -}; - -/** - * 表示轨道上的一个站点的结构体 - */ -typedef struct rail_node rail_node_t; - -/** - * 全局的轨道链表头节点,也就是第一个公交站 - */ -extern rail_node_t *rails; - -/** - * 轨道的总长度 - */ -extern int all_distance; - -/** - * 全局的计时器 - */ -extern int bus_time; - -/** - * 查找指定编号的站点指针 - * @param head 轨道的头节点地址 - * @param id 需要查找的站点编号 - * @return 需要查找站点指针 - */ -rail_node_t *FindNode(rail_node_t *head, int id); - -/** - * 创建轨道列表 - * @param length 站点之间的距离 - * @param node_num 站点的个数 - * @return 指向首站的指针 - */ -rail_node_t *CreateRails(int length, int node_num); - -/** - * 释放分配的内存空间 - * @param railNode 轨道链表的头节点 - */ -void FreeRails(rail_node_t *head); - -/** - * 时间走过一秒 - */ -void AddTime(); -#endif //AUTO_PILOT_BUS_RAIL_H diff --git a/main.c b/main.c deleted file mode 100644 index b96ac24..0000000 --- a/main.c +++ /dev/null @@ -1,218 +0,0 @@ -#include "bus_io.h" - -/** - * @brief 程序的主函数 - * - * @return int 程序结束的状态,0表示成功 - */ -int main() -{ - /** - * 输入的字符串 - */ - char input[30]; - /** - * the_bus指针的本体 - */ - bus_t main_bus; - /** - * 公交车前进的方向 - */ - int direction; - /** - * 完成的请求 - */ - bus_query_t *finished_query; - - // 读取配置文件 - rails = ReadConfigFile(); - - // 制造公交车 - the_bus = &main_bus; - the_bus->distance = 0; - the_bus->rail_node_pos = FindNode(rails, 1); - - // 开始时公交车应该是停下的 - direction = BUS_STOP; - - PrintState(); - - for(;;) - { - fgets(input, sizeof input, stdin); - - int result = ReadInput(input); - if(result == IO_CLOCK) - { - // 时间流动 - AddTime(); - switch (chosen_strategy) - { - case BUS_FCFS: - // 如果到站,处理请求和 - if(JudgeOnStation() == BUS_TRUE) - { - direction = FCFSDirection(); //在开始得判断一次方向 - finished_query = FCFSQuery(); - - if(finished_query != NULL) // 有请求就处理请求 - { - // 循环处理所有可以处理的请求,总共消耗一秒 - while (finished_query != NULL) - { - DeleteQuery(finished_query); - finished_query = FCFSQuery(); - } - - // 请求处理完再进行方向的判断 - direction = FCFSDirection(); - } - else //如果没有请求就继续前进 - { - RunBus(direction); - } - } - else - { - RunBus(direction); - } - break; - case BUS_SSTF: - if(JudgeOnStation() == BUS_TRUE) - { - // 在没有目标请求的时候,获取一个目标站点 - if(target_query == NULL) - { - target_query = SSTFGetQuery(); - direction = SSTFDirection(target_query); - - // 处理下一个需要处理的请求就在脚底下的情况 - if(target_query != NULL && target_query->node == the_bus->rail_node_pos) - { - while (target_query != NULL && target_query->node == the_bus->rail_node_pos) - { - DeleteQuery(target_query); - target_query = SSTFGetQuery(); - direction = SSTFDirection(target_query); - } - } - RunBus(direction); - } - else - { - bus_query_t *btw_query = SSTFBTWQuery(direction); - // 如果到站了 - if(target_query->node == the_bus->rail_node_pos) - { - // 如果刚好在站点上就有不少请求,处理一波 - // 这里利用了&&运算符的短路特性,如果第一个判断为假,则不进行下一个判断,也就避免了段错误 - while (target_query != NULL && target_query->node == the_bus->rail_node_pos) - { - DeleteQuery(target_query); - target_query = SSTFGetQuery(); - direction = SSTFDirection(target_query); - } - } - else if(btw_query != NULL) - { - // 如果没有到站就看看能不能顺便服务 - while (btw_query != NULL) - { - DeleteQuery(btw_query); - btw_query = SSTFBTWQuery(direction); - } - } - else - { - // 如果啥也不能做就走吧 - RunBus(direction); - } - } - } - else - { - // 没到站的话那就走吧 - RunBus(direction); - } - break; - case BUS_SCAN: - // 如果没有指定的请求就获得指定的请求 - if(JudgeOnStation() == BUS_TRUE) - { - // 在没有目标请求的时候,获取一个目标站点 - if(target_query == NULL) - { - target_query = SCANGetQuery(direction); - direction = SCANDirection(target_query, direction); - - // 处理下一个需要处理的请求就在脚底下的情况 - if(target_query != NULL && direction == BUS_STOP && target_query->node == the_bus->rail_node_pos) - { - while (target_query != NULL && direction == BUS_STOP && target_query->node == the_bus->rail_node_pos) - { - DeleteQuery(target_query); - target_query = SCANGetQuery(direction); - direction = SCANDirection(target_query, direction); - } - } - RunBus(direction); - } - else - { - bus_query_t *btw_query = SCANBTWQuery(); - // 如果到站了 - if(target_query->node == the_bus->rail_node_pos) - { - // 如果刚好在站点上就有不少请求,处理一波 - // 这里利用了&&运算符的短路特性,如果第一个判断为假,则不进行下一个判断,也就避免了段错误 - while (target_query != NULL && target_query->node == the_bus->rail_node_pos) - { - DeleteQuery(target_query); - target_query = SCANGetQuery(direction); - direction = SCANDirection(target_query, direction); - } - } - else if(btw_query != NULL) - { - // 如果没有到站就看看能不能顺便服务 - while (btw_query != NULL) - { - DeleteQuery(btw_query); - btw_query = SCANBTWQuery(); - } - } - else - { - // 如果啥也不能做就走吧 - RunBus(direction); - } - } - } - else - { - // 没到站的话那就走吧 - RunBus(direction); - } - break; - default: - // 这个分支只是为了符合代码规范而存在,理论上不会用到这个分支 - break; - } - PrintState(); - } - else if(result == IO_END) - { - printf("end\n"); - - FreeRails(rails); - FreeQueries(queries); - break; - } - else - { - //在读取到创建请求的情况下,不做任何事 - } - } - - return 0; -} \ No newline at end of file diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..74e51d3 --- /dev/null +++ b/main.cpp @@ -0,0 +1,10 @@ +#include "QApplication" +#include "mainwindow.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + MainWindow main_window; + main_window.show(); + return QApplication::exec(); +} diff --git a/main.py b/main.py deleted file mode 100644 index 97d60bf..0000000 --- a/main.py +++ /dev/null @@ -1,66 +0,0 @@ -import os - -input_file = open("all.c", "w", encoding="utf-8") -include_path: str = "./include/" -src_path: str = "./src/" - -# 写入需要用到的头文件 -input_file.write( - """#include -#include -#include -#define BUS_CLOCK_WISE 0 // 顺时针 -#define BUS_COUNTER_CLOCK_WISE 1 // 逆时针 -#define BUS_TARGET 2 // 目标 -#define BUS_STOP 2 // 停止 -#define BUS_TRUE 1 // 真 -#define BUS_FAlSE 0 // 假 -#define IO_CLOCK 0 // 读取时钟指令 -#define IO_READING 1 // 读取请求指令 -#define IO_END 2 // 读取结束指令 -#define BUS_FCFS 0 // 先来先服务 -#define BUS_SSTF 1 // 最短寻找时间优先 -#define BUS_SCAN 2 // 顺便服务 - """ -) - -# 读取include, src两个文件夹 -# include文件的顺序需要手动指定 -include_list: list = ["rail.h", "query.h", "bus.h", "bus_io.h", "controller.h", "define.h"] -src_list: list = os.listdir(src_path) - -for file_name in include_list: - file_name = include_path + file_name - with open(file_name, "r", encoding="utf-8") as include_file: - while True: - line: str = include_file.readline() - if not line: - break - elif line[0] == "#": - continue - else: - input_file.write(line) - -for file_name in src_list: - file_name = src_path + file_name - with open(file_name, "r", encoding="utf-8") as src_file: - while True: - line: str = src_file.readline() - if not line: - break - elif line[0] == "#": - continue - else: - input_file.write(line) - -with open("main.c", "r", encoding="utf-8") as main_file: - while True: - line: str = main_file.readline() - if not line: - break - elif line[0] == "#": - continue - else: - input_file.write(line) - -input_file.close() diff --git a/src/bus.c b/src/bus.c deleted file mode 100644 index 6c49450..0000000 --- a/src/bus.c +++ /dev/null @@ -1,111 +0,0 @@ -#include "bus.h" - -bus_t *the_bus = NULL; - -void RunBus(int direction) -{ - if(direction == BUS_CLOCK_WISE)//顺时针 - { - the_bus->distance++; - } - else if(direction == BUS_COUNTER_CLOCK_WISE) - { - the_bus->distance--; - } -} - -int GetBusPosition() -{ - int distance = 0; - rail_node_t *now_pos = the_bus->rail_node_pos; - rail_node_t *p = rails; - - // 先计算当前所在站点距离起始站点的距离 - distance += p ->next_node_distance; - p = p->next_node; - while (p != now_pos) - { - distance += p->next_node_distance; - p = p->next_node; - } - - if(now_pos == rails) // 起始点特殊处理 - { - // 公交车偏离起始点的位置 - int length = the_bus->distance; - if(length >= 0) - { - return length; - } - else - { - return distance + length; - } - } - else if(now_pos == rails->last_node) - { - int length = the_bus->distance; - if(length == now_pos->next_node_distance) // 处理一种极为特殊的情况 公交车在即将到达起始站时 - { - return 0; - } - else - { - return distance + length; - } - } - else - { - return distance + the_bus->distance; - } -} - -int JudgeOnStation() -{ - if (the_bus->distance == - the_bus->rail_node_pos->last_node_distance)//表示逆时针 - { - the_bus->distance = 0; - the_bus->rail_node_pos = the_bus->rail_node_pos->last_node;//逆时针往上一个 - return BUS_TRUE; - } - else if (the_bus->distance == the_bus->rail_node_pos->next_node_distance)//表示顺时针 - { - the_bus->distance = 0; - the_bus->rail_node_pos = the_bus->rail_node_pos->next_node;//顺时针往下一个 - return BUS_TRUE; - } - else if(the_bus->distance == 0) //在站点上原地不动 - { - return BUS_TRUE; - } - else - { - return BUS_FAlSE; - } -} - -int GetQueryDistance(bus_query_t *query, int orientation) -{ - rail_node_t *target_node = query->node; - rail_node_t *now_node = the_bus->rail_node_pos; - int distance = 0; - - if(orientation == BUS_CLOCK_WISE) - { - while (now_node != target_node) - { - distance += now_node->next_node_distance; - now_node = now_node->next_node; - } - } - else if(orientation == BUS_COUNTER_CLOCK_WISE) - { - while (now_node != target_node) - { - distance += now_node->last_node_distance; - now_node = now_node->last_node; - } - } - - return distance; -} \ No newline at end of file diff --git a/src/bus_io.c b/src/bus_io.c deleted file mode 100644 index 47951cf..0000000 --- a/src/bus_io.c +++ /dev/null @@ -1,264 +0,0 @@ -// -// Created by ricardo on 2022/5/6. -// -#include "bus_io.h" - -int ReadInput(char *inputString) -{ - - char src[20]; - int num; - - sscanf(inputString, "%[a-z] %d", src, &num); - - if (0 == strcmp("clock", src)) - { - return IO_CLOCK; - } - else if (0 == strcmp("counterclockwise", src)) - { - CreateQuery(BUS_COUNTER_CLOCK_WISE, FindNode(rails, num)); - return IO_READING; - } - else if (0 == strcmp("clockwise", src)) - { - CreateQuery(BUS_CLOCK_WISE, FindNode(rails, num)); - return IO_READING; - } - else if (0 == strcmp("target", src)) - { - CreateQuery(BUS_TARGET, FindNode(rails, num)); - return IO_READING; - } - else if (0 == strcmp("end", src)) - { - return IO_END; - } - else - { - // 匹配失败则返回-1 - return -1; - } -} - -rail_node_t *ReadConfigFile() -{ - FILE *config_file = NULL; - char buffer[30]; - int total_station = 0; - int distance = 0; - - config_file = fopen("dict.dic", "r"); - - // 循环读取文件的每一行 - while (fgets(buffer, sizeof buffer, config_file) != NULL) - { - char first_char = buffer[0]; - char *p; - - switch (first_char) - { - case '#': - // 如果读取到#什么都不做 - break; - case 'T': - // TOTAL_STATION - p = buffer; - - // 把数字前面的所有字符全部干掉 - while (*p < '0' || *p > '9') - { - p++; - } - - // 讲道理,应该只有两位数,所以就这样处理了 - if (*(p + 1) == '\n' || *(p + 1) == '\0') - { - total_station = *p - 48; - } - else - { - total_station = (*p - 48) * 10 + *(p + 1) - 48; - } - - break; - case 'S': - // STRATEGY - p = buffer; - - // 将=前的字符全部略去 - while (*p != '=') - { - p++; - } - // =也去掉 - p++; - // =和策略之间的空格也去掉 - while (*p == ' ') - { - p++; - } - - if (*p == 'F' && *(p + 1) == 'C') //FCFS - { - chosen_strategy = BUS_FCFS; - } - else if (*p == 'S' && *(p + 1) == 'S') //SSTF - { - chosen_strategy = BUS_SSTF; - } - else if (*p == 'S' && *(p + 1) == 'C') //SCAN - { - chosen_strategy = BUS_SCAN; - } - else - { - // 读取失败 - chosen_strategy = -1; - } - - break; - case 'D': - // DISTANCE - p = buffer; - - // 把数字前面的所有字符全部干掉 - while (*p < '0' || *p > '9') - { - p++; - } - - if (*(p + 1) == '\n' || *(p + 1) == '\0') - { - distance = *p - 48; - } - - break; - default: - continue; - } - } - - // 处理参数去缺省值的情况 - if (distance == 0) - { - distance = 2; - } - if (total_station == 0) - { - total_station = 5; - } - if(chosen_strategy == -1) - { - chosen_strategy = BUS_FCFS; - } - - all_distance = distance * total_station; - rail_node_t *head = CreateRails(distance, total_station); - return head; -} - -void PrintState() -{ - int count, flag = 1; //flag用于标记,为使下面第一个循环能够进入 - rail_node_t *p = NULL; - char target[25], clockwise[25], counterclockwise[25]; - - for (count = 0, p = rails; flag == 1 || p != rails; p = p->next_node, count++) - { - flag=0; - target[count] = '0'; - clockwise[count] = '0'; - counterclockwise[count] = '0'; - } //遍历轨道链表,将所有站点初始化为0,即:无任何请求; - // 在字符串的末尾填0 - target[count] = '\0'; - clockwise[count] = '\0'; - counterclockwise[count] = '\0'; - - bus_query_t *t = NULL; - int i; - for (t = queries; t != NULL; t = t->next_node) - { - i = t->node->id - 1; - if (t->type == 0) - { - clockwise[i] = '1'; - } - else if(t->type==BUS_COUNTER_CLOCK_WISE) - { - counterclockwise[i] = '1'; - } - else if(t->type==BUS_TARGET) - { - target[i] = '1'; - } - } //遍历请求链表,将有请求的站点按照不同类型标记为1 - - printf("TIME:%d\n", bus_time); - printf("BUS:\n"); - printf("position:%d\n", GetBusPosition()); - printf("target:%s\n", target); - printf("STATION:\n"); - printf("clockwise:%s\n", clockwise); - printf("counterclockwise:%s\n", counterclockwise); -} - -void PrintStateInner(char *str) -{ - memset(str, 0, 150); - - int count, flag = 1; //flag用于标记,为使下面第一个循环能够进入 - rail_node_t *p = NULL; - char target[25], clockwise[25], counterclockwise[25]; - - for (count = 0, p = rails; flag == 1 || p != rails; p = p->next_node, count++) - { - flag=0; - target[count] = '0'; - clockwise[count] = '0'; - counterclockwise[count] = '0'; - } //遍历轨道链表,将所有站点初始化为0,即:无任何请求; - // 在字符串的末尾填0 - target[count] = '\0'; - clockwise[count] = '\0'; - counterclockwise[count] = '\0'; - - bus_query_t *t = NULL; - int i; - for (t = queries; t != NULL; t = t->next_node) - { - i = t->node->id - 1; - if (t->type == 0) - { - clockwise[i] = '1'; - } - else if(t->type==BUS_COUNTER_CLOCK_WISE) - { - counterclockwise[i] = '1'; - } - else if(t->type==BUS_TARGET) - { - target[i] = '1'; - } - } //遍历请求链表,将有请求的站点按照不同类型标记为1 - - char line1[100], line2[10], line3[15], line4[100], line5[10], line6[100], line7[100]; - - sprintf(line1, "TIME:%d\n", bus_time); - sprintf(line2, "BUS:\n"); - sprintf(line3, "position:%d\n", GetBusPosition()); - sprintf(line4, "target:%s\n", target); - sprintf(line5, "STATION:\n"); - sprintf(line6, "clockwise:%s\n", clockwise); - sprintf(line7, "counterclockwise:%s\n", counterclockwise); //分别得到每一行的字符串 - - strcat(line1, line2); - strcat(line1, line3); - strcat(line1, line4); - strcat(line1, line5); - strcat(line1, line6); - strcat(line1, line7);//将7行字符串合并在一起 - - strcat(str, line1); -} \ No newline at end of file diff --git a/src/centralwidget.cpp b/src/centralwidget.cpp new file mode 100644 index 0000000..aa56e87 --- /dev/null +++ b/src/centralwidget.cpp @@ -0,0 +1,20 @@ +// +// Created by ricardo on 2022/6/10. +// + +// You may need to build the project (run Qt uic code generator) to get "ui_CentralWidget.h" resolved + +#include "header/moc_centralwidget.cpp" +#include "form/ui_CentralWidget.h" + + +CentralWidget::CentralWidget(QWidget *parent) : + QWidget(parent), ui(new Ui::CentralWidget) +{ + ui->setupUi(this); +} + +CentralWidget::~CentralWidget() +{ + delete ui; +} diff --git a/src/controller.c b/src/controller.c deleted file mode 100644 index ab7b075..0000000 --- a/src/controller.c +++ /dev/null @@ -1,286 +0,0 @@ -// -// Created by ricardo on 2022/5/6. -// -#include "controller.h" - -bus_query_t *target_query = NULL; -int chosen_strategy = -1; - -int FCFSDirection() -{ - bus_query_t *p = queries; - - if(p == NULL) - { - return BUS_STOP; - } //如果没有请求,公交车停止 - - else - { - int clockwise = 0; - int counterclockwise = 0; //用于顺,逆时针方向所经站台计数 - - /** - * 公交车当前所在位置 - */ - rail_node_t *now_position = the_bus->rail_node_pos; - /** - * 公交车应该前进的方向 - */ - rail_node_t *target_position = p->node; - - rail_node_t *pos = now_position; - while (pos != target_position) //顺时针计数 - { - clockwise++; - pos = pos->next_node; - } - - pos = now_position; - while (pos != target_position) //逆时针计数 - { - counterclockwise++; - pos = pos->last_node; - } - - if(clockwise <= counterclockwise) - { - return BUS_CLOCK_WISE; - }//若顺时针距离短(或顺逆相等),公交车顺时针运行 - else - { - return BUS_COUNTER_CLOCK_WISE; - }//若逆时针距离短,公交车逆时针运行 - } -} - -bus_query_t *FCFSQuery() -{ - bus_query_t *result = NULL; - - if(queries != NULL) - { - if(the_bus->rail_node_pos == queries->node) - { - result = queries; - } - } - - return result; -} - -bus_query_t *SSTFGetQuery() -{ - // 当前没有请求 - if(queries == NULL) - { - return NULL; - } - int distance = 9999; - bus_query_t *query = NULL; - bus_query_t *p = queries; - - // 遍历顺时针方向 - // 在两个方向路程相同时选择顺时针方向 - // 所以先遍历顺时针方向 - while (p != NULL) - { - int temp = GetQueryDistance(p, BUS_CLOCK_WISE); - if(temp < distance) - { - distance = temp; - query = p; - } - p = p->next_node; - } - - // 遍历逆时针方向 - p = queries; - while (p != NULL) - { - int temp = GetQueryDistance(p, BUS_COUNTER_CLOCK_WISE); - if(temp < distance) - { - distance = temp; - query = p; - } - p = p->next_node; - } - - return query; -} - -int SSTFDirection(bus_query_t* query) -{ - if (query == NULL) - { - return BUS_STOP; - } - - int distance = GetQueryDistance(query, BUS_CLOCK_WISE); - if(distance > all_distance / 2) - { - return BUS_COUNTER_CLOCK_WISE; - } - else if(distance == 0) - { - return BUS_STOP; - } - else - { - return BUS_CLOCK_WISE; - } -} - -bus_query_t *SSTFBTWQuery(int direction) -{ - bus_query_t *query = queries; - bus_query_t *allow_query = NULL; - rail_node_t *now_node = the_bus->rail_node_pos; - - while (query != NULL) - { - if(query->node == now_node) - { - // 这里是设计上的缺陷,在bus_time显示时间的前一秒,公交车就实际上到达站台了 - if(query->time < bus_time - 1) - { - if(query->type == direction || query->type == BUS_TARGET) - { - allow_query = query; - break; - } - } - } - query = query->next_node; - } - - return allow_query; -} - -bus_query_t *SCANGetQuery(int direction) -{ - // 当前没有请求 - if(queries == NULL) - { - return NULL; - } - - if(direction == BUS_STOP) - { - // 在停止的状态下第一次开始选择方向 - int distance = 9999; - bus_query_t *query = NULL; - bus_query_t *p = queries; - - // 遍历顺时针方向 - // 在两个方向路程相同时选择顺时针方向 - // 所以先遍历顺时针方向 - while (p != NULL) - { - int temp = GetQueryDistance(p, BUS_CLOCK_WISE); - if(temp < distance) - { - distance = temp; - query = p; - } - p = p->next_node; - } - - // 遍历逆时针方向 - p = queries; - while (p != NULL) - { - int temp = GetQueryDistance(p, BUS_COUNTER_CLOCK_WISE); - if(temp < distance) - { - distance = temp; - query = p; - } - p = p->next_node; - } - - return query; - } - else - { - // 在已经有方向的情况下处理方向 - int distance = 9999; - bus_query_t *query = NULL; - bus_query_t *p = queries; - - while (p != NULL) - { - int temp = GetQueryDistance(p, direction); - if(temp < distance) - { - query = p; - distance = temp; - } - p = p->next_node; - } - - return query; - } -} - -int SCANDirection(bus_query_t *query, int orientation) -{ - if(query == NULL) - { - return BUS_STOP; - } - - if(orientation == BUS_STOP) - { - int distance = GetQueryDistance(query, BUS_CLOCK_WISE); - if(distance > all_distance / 2) - { - return BUS_COUNTER_CLOCK_WISE; - } - else - { - return BUS_CLOCK_WISE; - } - } - else - { - int distance = GetQueryDistance(query, orientation); - if(distance > all_distance / 2) - { - if(orientation == BUS_CLOCK_WISE) - { - return BUS_COUNTER_CLOCK_WISE; - } - else - { - return BUS_CLOCK_WISE; - } - } - else - { - return orientation; - } - } -} - -bus_query_t *SCANBTWQuery() -{ - rail_node_t *now_position = the_bus->rail_node_pos; - //获取公交车当前所在站点 - bus_query_t *p = queries; - - while(p != NULL) - { - if(p->node == now_position) - { - if(p->time < bus_time - 1) - { - return p; - } - } - p = p->next_node; - }//遍历请求链表,判断是否有可以顺便处理的请求 - - return NULL; -} \ No newline at end of file diff --git a/src/form/centralwidget.ui b/src/form/centralwidget.ui new file mode 100644 index 0000000..2023b11 --- /dev/null +++ b/src/form/centralwidget.ui @@ -0,0 +1,71 @@ + + + CentralWidget + + + + 0 + 0 + 865 + 635 + + + + CentralWidget + + + + + 0 + 0 + 661 + 421 + + + + + + + 659 + -1 + 201 + 421 + + + + + + + 控制面板 + + + + + + + + + 0 + 420 + 861 + 221 + + + + true + + + + + 0 + 0 + 859 + 219 + + + + + + + + diff --git a/src/form/mainwindow.ui b/src/form/mainwindow.ui new file mode 100644 index 0000000..6f6b6d2 --- /dev/null +++ b/src/form/mainwindow.ui @@ -0,0 +1,47 @@ + + + MainWindow + + + + 0 + 0 + 900 + 600 + + + + MainWindow + + + + + 0 + 0 + 900 + 22 + + + + + File + + + + + + + + + Read ConfigFile + + + + + Exit + + + + + + diff --git a/src/header/centralwidget.h b/src/header/centralwidget.h new file mode 100644 index 0000000..2795173 --- /dev/null +++ b/src/header/centralwidget.h @@ -0,0 +1,32 @@ +// +// Created by ricardo on 2022/6/10. +// + +#ifndef AUTO_BUS_GUI_CENTRALWIDGET_H +#define AUTO_BUS_GUI_CENTRALWIDGET_H + +#include + + +QT_BEGIN_NAMESPACE +namespace Ui +{ + class CentralWidget; +} +QT_END_NAMESPACE + +class CentralWidget : public QWidget +{ +Q_OBJECT + +public: + explicit CentralWidget(QWidget *parent = nullptr); + + ~CentralWidget() override; + +private: + Ui::CentralWidget *ui; +}; + + +#endif //AUTO_BUS_GUI_CENTRALWIDGET_H diff --git a/src/header/mainwindow.h b/src/header/mainwindow.h new file mode 100644 index 0000000..00d523d --- /dev/null +++ b/src/header/mainwindow.h @@ -0,0 +1,36 @@ +// +// Created by ricardo on 2022/6/10. +// + +#ifndef AUTO_BUS_GUI_MAINWINDOW_H +#define AUTO_BUS_GUI_MAINWINDOW_H + +#include +#include "centralwidget.h" + + +QT_BEGIN_NAMESPACE +namespace Ui +{ + class MainWindow; +} +QT_END_NAMESPACE + +class MainWindow : public QMainWindow +{ +Q_OBJECT + +public: + explicit MainWindow(QWidget *parent = nullptr); + + ~MainWindow() override; + +private: + Ui::MainWindow *ui; + CentralWidget *central_widget; + + void SetMenuBarConnection(); +}; + + +#endif //AUTO_BUS_GUI_MAINWINDOW_H diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp new file mode 100644 index 0000000..15ec911 --- /dev/null +++ b/src/mainwindow.cpp @@ -0,0 +1,31 @@ +// +// Created by ricardo on 2022/6/10. +// + +// You may need to build the project (run Qt uic code generator) to get "ui_MainWindow.h" resolved + +#include "header/moc_mainwindow.cpp" +#include "form/ui_MainWindow.h" + + +MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) +{ + ui = new Ui::MainWindow; + central_widget = new CentralWidget; + + ui->setupUi(this); + this->setCentralWidget(central_widget); + SetMenuBarConnection(); + +} + +MainWindow::~MainWindow() +{ + delete ui; + delete central_widget; +} + +void MainWindow::SetMenuBarConnection() +{ + QObject::connect(ui->actionExit, SIGNAL(triggered()), this, SLOT(close())); +} diff --git a/src/query.c b/src/query.c deleted file mode 100644 index 87f1e0b..0000000 --- a/src/query.c +++ /dev/null @@ -1,96 +0,0 @@ -// -// Created by ricardo on 2022/5/6. -// -#include "query.h" - -bus_query_t *queries = NULL; - -bus_query_t *CreateQuery(int type, rail_node_t *node) -{ - bus_query_t *p = (bus_query_t *)malloc(sizeof (bus_query_t)); - p->node = node; - p->type = type; - p->time = bus_time; - p->next_node = NULL; - - if (queries == NULL) - { - // 如果头指针是空指针,便没有必要排查是否重复 - queries = p; - return p; - } - else - { - bus_query_t *query = queries; - int flag = BUS_FAlSE; - - // 排查是否有重复的请求 - while (query != NULL) - { - if(query->node == p->node && query->type == p->type) - { - flag = BUS_TRUE; - break; - } - query = query->next_node; - } - - if(flag == BUS_TRUE) - { - // 如果存在相同的请求,这个请求就被放弃 - free(p); - return NULL; - } - else - { - // 找到请求链表的最后一个节点 - bus_query_t *last_query = queries; - - while (last_query->next_node != NULL) - { - last_query = last_query->next_node; - } - - last_query->next_node = p; - return p; - } - } -} - -void DeleteQuery(bus_query_t *target) -{ - if(target == queries) - { - queries = target->next_node; - } - else - { - bus_query_t *node = queries; - - // 找到被删除节点的上一个节点 - while(node->next_node != target) - { - node = node->next_node; - } - - node->next_node = target->next_node; - } - - free(target); -} - -void FreeQueries(bus_query_t *head) -{ - bus_query_t *p = head; - - while (p != NULL) - { - bus_query_t *temp = p; - p = p->next_node; - free(temp); - } - - // 将全局的请求列表头指针置为空 - queries = NULL; -} - diff --git a/src/rail.c b/src/rail.c deleted file mode 100644 index f905a58..0000000 --- a/src/rail.c +++ /dev/null @@ -1,88 +0,0 @@ -#include "rail.h" - -rail_node_t *rails = NULL; -int bus_time = 0; -int all_distance = 0; - -rail_node_t *CreateRails(int length, int node_num) -{ - /** - * 表示轨道的头节点 - */ - rail_node_t *head = NULL; - rail_node_t *node = NULL; - - head = (rail_node_t*) malloc(sizeof (rail_node_t)); - head->id = 1; - head->last_node_distance = length; - head->next_node_distance = length; - - node = head; - // 循环创建每一个节点 - for(int i = 2; i <= node_num; i++) - { - rail_node_t *p = (rail_node_t*) malloc(sizeof (rail_node_t)); - - p->id = i; - p->last_node_distance = length; - p->next_node_distance = length; - p->last_node = node; - node->next_node = p; - node = p; - } - - // 循环结束时node就是最后一个节点 - node->next_node = head; - head->last_node = node; - - return head; -} - -rail_node_t *FindNode(rail_node_t *head, int id) -{ - // 排除头节点为空的情况 - if(head == NULL) - { - return NULL; - } - - rail_node_t *result = NULL; - rail_node_t *p = head; - - do - { - if(p->id == id) - { - result = p; - break; - } - p = p->next_node; - } - while (p != head); - - return result; -} - -void FreeRails(rail_node_t *head) -{ - rail_node_t *p = head; - - // 断开头尾节点 - head->last_node->next_node = NULL; - - while (p != NULL) - { - rail_node_t *temp = p; - p = p->next_node; - free(temp); - } - - // 将全局的轨道指针置为空 - rails = NULL; -} - -void AddTime() -{ - bus_time++; -} - diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt deleted file mode 100644 index 5c87630..0000000 --- a/test/CMakeLists.txt +++ /dev/null @@ -1,30 +0,0 @@ -cmake_minimum_required(VERSION 3.0) -project(bus_test) - -set(CMAKE_CXX_STANDARD 11) - -add_subdirectory(./GTest) - -include_directories(GTest/googletest/include) -include_directories(GTest/googlemock/include) -include_directories(../include) - -aux_source_directory("../src/" SRCS) -aux_source_directory("${CMAKE_CURRENT_SOURCE_DIR}" TEST_SRCS) - -add_executable(bus_test ${SRCS} ${TEST_SRCS}) - -target_link_libraries(bus_test - PRIVATE - gtest - gtest_main - gmock - gmock_main - pthread -) - -add_custom_command(TARGET bus_test POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_if_different - "${CMAKE_CURRENT_SOURCE_DIR}/dict.dic" - $ - ) \ No newline at end of file diff --git a/test/GTest/.gitignore b/test/GTest/.gitignore deleted file mode 100644 index f08cb72..0000000 --- a/test/GTest/.gitignore +++ /dev/null @@ -1,84 +0,0 @@ -# Ignore CI build directory -build/ -xcuserdata -cmake-build-debug/ -.idea/ -bazel-bin -bazel-genfiles -bazel-googletest -bazel-out -bazel-testlogs -# python -*.pyc - -# Visual Studio files -.vs -*.sdf -*.opensdf -*.VC.opendb -*.suo -*.user -_ReSharper.Caches/ -Win32-Debug/ -Win32-Release/ -x64-Debug/ -x64-Release/ - -# Ignore autoconf / automake files -Makefile.in -aclocal.m4 -configure -build-aux/ -autom4te.cache/ -googletest/m4/libtool.m4 -googletest/m4/ltoptions.m4 -googletest/m4/ltsugar.m4 -googletest/m4/ltversion.m4 -googletest/m4/lt~obsolete.m4 -googlemock/m4 - -# Ignore generated directories. -googlemock/fused-src/ -googletest/fused-src/ - -# macOS files -.DS_Store -googletest/.DS_Store -googletest/xcode/.DS_Store - -# Ignore cmake generated directories and files. -CMakeFiles -CTestTestfile.cmake -Makefile -cmake_install.cmake -googlemock/CMakeFiles -googlemock/CTestTestfile.cmake -googlemock/Makefile -googlemock/cmake_install.cmake -googlemock/gtest -/bin -/googlemock/gmock.dir -/googlemock/gmock_main.dir -/googlemock/RUN_TESTS.vcxproj.filters -/googlemock/RUN_TESTS.vcxproj -/googlemock/INSTALL.vcxproj.filters -/googlemock/INSTALL.vcxproj -/googlemock/gmock_main.vcxproj.filters -/googlemock/gmock_main.vcxproj -/googlemock/gmock.vcxproj.filters -/googlemock/gmock.vcxproj -/googlemock/gmock.sln -/googlemock/ALL_BUILD.vcxproj.filters -/googlemock/ALL_BUILD.vcxproj -/lib -/Win32 -/ZERO_CHECK.vcxproj.filters -/ZERO_CHECK.vcxproj -/RUN_TESTS.vcxproj.filters -/RUN_TESTS.vcxproj -/INSTALL.vcxproj.filters -/INSTALL.vcxproj -/googletest-distribution.sln -/CMakeCache.txt -/ALL_BUILD.vcxproj.filters -/ALL_BUILD.vcxproj diff --git a/test/GTest/BUILD.bazel b/test/GTest/BUILD.bazel deleted file mode 100644 index 965c518..0000000 --- a/test/GTest/BUILD.bazel +++ /dev/null @@ -1,190 +0,0 @@ -# Copyright 2017 Google Inc. -# All Rights Reserved. -# -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are -# met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# * Redistributions in binary form must reproduce the above -# copyright notice, this list of conditions and the following disclaimer -# in the documentation and/or other materials provided with the -# distribution. -# * Neither the name of Google Inc. nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# -# Bazel Build for Google C++ Testing Framework(Google Test) - -load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") - -package(default_visibility = ["//visibility:public"]) - -licenses(["notice"]) - -exports_files(["LICENSE"]) - -config_setting( - name = "windows", - constraint_values = ["@platforms//os:windows"], -) - -config_setting( - name = "msvc_compiler", - flag_values = { - "@bazel_tools//tools/cpp:compiler": "msvc-cl", - }, - visibility = [":__subpackages__"], -) - -config_setting( - name = "has_absl", - values = {"define": "absl=1"}, -) - -# Library that defines the FRIEND_TEST macro. -cc_library( - name = "gtest_prod", - hdrs = ["googletest/include/gtest/gtest_prod.h"], - includes = ["googletest/include"], -) - -# Google Test including Google Mock -cc_library( - name = "gtest", - srcs = glob( - include = [ - "googletest/src/*.cc", - "googletest/src/*.h", - "googletest/include/gtest/**/*.h", - "googlemock/src/*.cc", - "googlemock/include/gmock/**/*.h", - ], - exclude = [ - "googletest/src/gtest-all.cc", - "googletest/src/gtest_main.cc", - "googlemock/src/gmock-all.cc", - "googlemock/src/gmock_main.cc", - ], - ), - hdrs = glob([ - "googletest/include/gtest/*.h", - "googlemock/include/gmock/*.h", - ]), - copts = select({ - ":windows": [], - "//conditions:default": ["-pthread"], - }), - defines = select({ - ":has_absl": ["GTEST_HAS_ABSL=1"], - "//conditions:default": [], - }), - features = select({ - ":windows": ["windows_export_all_symbols"], - "//conditions:default": [], - }), - includes = [ - "googlemock", - "googlemock/include", - "googletest", - "googletest/include", - ], - linkopts = select({ - ":windows": [], - "//conditions:default": ["-pthread"], - }), - deps = select({ - ":has_absl": [ - "@com_google_absl//absl/debugging:failure_signal_handler", - "@com_google_absl//absl/debugging:stacktrace", - "@com_google_absl//absl/debugging:symbolize", - "@com_google_absl//absl/strings", - "@com_google_absl//absl/types:any", - "@com_google_absl//absl/types:optional", - "@com_google_absl//absl/types:variant", - ], - "//conditions:default": [], - }), -) - -cc_library( - name = "gtest_main", - srcs = ["googlemock/src/gmock_main.cc"], - features = select({ - ":windows": ["windows_export_all_symbols"], - "//conditions:default": [], - }), - deps = [":gtest"], -) - -# The following rules build samples of how to use gTest. -cc_library( - name = "gtest_sample_lib", - srcs = [ - "googletest/samples/sample1.cc", - "googletest/samples/sample2.cc", - "googletest/samples/sample4.cc", - ], - hdrs = [ - "googletest/samples/prime_tables.h", - "googletest/samples/sample1.h", - "googletest/samples/sample2.h", - "googletest/samples/sample3-inl.h", - "googletest/samples/sample4.h", - ], - features = select({ - ":windows": ["windows_export_all_symbols"], - "//conditions:default": [], - }), -) - -cc_test( - name = "gtest_samples", - size = "small", - # All Samples except: - # sample9 (main) - # sample10 (main and takes a command line option and needs to be separate) - srcs = [ - "googletest/samples/sample1_unittest.cc", - "googletest/samples/sample2_unittest.cc", - "googletest/samples/sample3_unittest.cc", - "googletest/samples/sample4_unittest.cc", - "googletest/samples/sample5_unittest.cc", - "googletest/samples/sample6_unittest.cc", - "googletest/samples/sample7_unittest.cc", - "googletest/samples/sample8_unittest.cc", - ], - linkstatic = 0, - deps = [ - "gtest_sample_lib", - ":gtest_main", - ], -) - -cc_test( - name = "sample9_unittest", - size = "small", - srcs = ["googletest/samples/sample9_unittest.cc"], - deps = [":gtest"], -) - -cc_test( - name = "sample10_unittest", - size = "small", - srcs = ["googletest/samples/sample10_unittest.cc"], - deps = [":gtest"], -) diff --git a/test/GTest/CMakeLists.txt b/test/GTest/CMakeLists.txt deleted file mode 100644 index ea81ab1..0000000 --- a/test/GTest/CMakeLists.txt +++ /dev/null @@ -1,32 +0,0 @@ -# Note: CMake support is community-based. The maintainers do not use CMake -# internally. - -cmake_minimum_required(VERSION 2.8.12) - -if (POLICY CMP0048) - cmake_policy(SET CMP0048 NEW) -endif (POLICY CMP0048) - -project(googletest-distribution) -set(GOOGLETEST_VERSION 1.11.0) - -if (CMAKE_VERSION VERSION_GREATER "3.0.2") - if(NOT CYGWIN AND NOT MSYS AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL QNX) - set(CMAKE_CXX_EXTENSIONS OFF) - endif() -endif() - -enable_testing() - -include(CMakeDependentOption) -include(GNUInstallDirs) - -#Note that googlemock target already builds googletest -option(BUILD_GMOCK "Builds the googlemock subproject" ON) -option(INSTALL_GTEST "Enable installation of googletest. (Projects embedding googletest may want to turn this OFF.)" ON) - -if(BUILD_GMOCK) - add_subdirectory( googlemock ) -else() - add_subdirectory( googletest ) -endif() diff --git a/test/GTest/googlemock/CMakeLists.txt b/test/GTest/googlemock/CMakeLists.txt deleted file mode 100644 index e7df8ec..0000000 --- a/test/GTest/googlemock/CMakeLists.txt +++ /dev/null @@ -1,218 +0,0 @@ -######################################################################## -# Note: CMake support is community-based. The maintainers do not use CMake -# internally. -# -# CMake build script for Google Mock. -# -# To run the tests for Google Mock itself on Linux, use 'make test' or -# ctest. You can select which tests to run using 'ctest -R regex'. -# For more options, run 'ctest --help'. - -option(gmock_build_tests "Build all of Google Mock's own tests." OFF) - -# A directory to find Google Test sources. -if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/gtest/CMakeLists.txt") - set(gtest_dir gtest) -else() - set(gtest_dir ../googletest) -endif() - -# Defines pre_project_set_up_hermetic_build() and set_up_hermetic_build(). -include("${gtest_dir}/cmake/hermetic_build.cmake" OPTIONAL) - -if (COMMAND pre_project_set_up_hermetic_build) - # Google Test also calls hermetic setup functions from add_subdirectory, - # although its changes will not affect things at the current scope. - pre_project_set_up_hermetic_build() -endif() - -######################################################################## -# -# Project-wide settings - -# Name of the project. -# -# CMake files in this project can refer to the root source directory -# as ${gmock_SOURCE_DIR} and to the root binary directory as -# ${gmock_BINARY_DIR}. -# Language "C" is required for find_package(Threads). -if (CMAKE_VERSION VERSION_LESS 3.0) - project(gmock CXX C) -else() - cmake_policy(SET CMP0048 NEW) - project(gmock VERSION ${GOOGLETEST_VERSION} LANGUAGES CXX C) -endif() -cmake_minimum_required(VERSION 2.8.12) - -if (COMMAND set_up_hermetic_build) - set_up_hermetic_build() -endif() - -# Instructs CMake to process Google Test's CMakeLists.txt and add its -# targets to the current scope. We are placing Google Test's binary -# directory in a subdirectory of our own as VC compilation may break -# if they are the same (the default). -add_subdirectory("${gtest_dir}" "${gmock_BINARY_DIR}/${gtest_dir}") - - -# These commands only run if this is the main project -if(CMAKE_PROJECT_NAME STREQUAL "gmock" OR CMAKE_PROJECT_NAME STREQUAL "googletest-distribution") - # BUILD_SHARED_LIBS is a standard CMake variable, but we declare it here to - # make it prominent in the GUI. - option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)." OFF) -else() - mark_as_advanced(gmock_build_tests) -endif() - -# Although Google Test's CMakeLists.txt calls this function, the -# changes there don't affect the current scope. Therefore we have to -# call it again here. -config_compiler_and_linker() # from ${gtest_dir}/cmake/internal_utils.cmake - -# Adds Google Mock's and Google Test's header directories to the search path. -set(gmock_build_include_dirs - "${gmock_SOURCE_DIR}/include" - "${gmock_SOURCE_DIR}" - "${gtest_SOURCE_DIR}/include" - # This directory is needed to build directly from Google Test sources. - "${gtest_SOURCE_DIR}") -include_directories(${gmock_build_include_dirs}) - -######################################################################## -# -# Defines the gmock & gmock_main libraries. User tests should link -# with one of them. - -# Google Mock libraries. We build them using more strict warnings than what -# are used for other targets, to ensure that Google Mock can be compiled by -# a user aggressive about warnings. -if (MSVC) - cxx_library(gmock - "${cxx_strict}" - "${gtest_dir}/src/gtest-all.cc" - src/gmock-all.cc) - - cxx_library(gmock_main - "${cxx_strict}" - "${gtest_dir}/src/gtest-all.cc" - src/gmock-all.cc - src/gmock_main.cc) -else() - cxx_library(gmock "${cxx_strict}" src/gmock-all.cc) - target_link_libraries(gmock PUBLIC gtest) - set_target_properties(gmock PROPERTIES VERSION ${GOOGLETEST_VERSION}) - cxx_library(gmock_main "${cxx_strict}" src/gmock_main.cc) - target_link_libraries(gmock_main PUBLIC gmock) - set_target_properties(gmock_main PROPERTIES VERSION ${GOOGLETEST_VERSION}) -endif() -# If the CMake version supports it, attach header directory information -# to the targets for when we are part of a parent build (ie being pulled -# in via add_subdirectory() rather than being a standalone build). -if (DEFINED CMAKE_VERSION AND NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11") - target_include_directories(gmock SYSTEM INTERFACE - "$" - "$/${CMAKE_INSTALL_INCLUDEDIR}>") - target_include_directories(gmock_main SYSTEM INTERFACE - "$" - "$/${CMAKE_INSTALL_INCLUDEDIR}>") -endif() - -######################################################################## -# -# Install rules -install_project(gmock gmock_main) - -######################################################################## -# -# Google Mock's own tests. -# -# You can skip this section if you aren't interested in testing -# Google Mock itself. -# -# The tests are not built by default. To build them, set the -# gmock_build_tests option to ON. You can do it by running ccmake -# or specifying the -Dgmock_build_tests=ON flag when running cmake. - -if (gmock_build_tests) - # This must be set in the root directory for the tests to be run by - # 'make test' or ctest. - enable_testing() - - if (MINGW OR CYGWIN) - if (CMAKE_VERSION VERSION_LESS "2.8.12") - add_compile_options("-Wa,-mbig-obj") - else() - add_definitions("-Wa,-mbig-obj") - endif() - endif() - - ############################################################ - # C++ tests built with standard compiler flags. - - cxx_test(gmock-actions_test gmock_main) - cxx_test(gmock-cardinalities_test gmock_main) - cxx_test(gmock_ex_test gmock_main) - cxx_test(gmock-function-mocker_test gmock_main) - cxx_test(gmock-internal-utils_test gmock_main) - cxx_test(gmock-matchers_test gmock_main) - cxx_test(gmock-more-actions_test gmock_main) - cxx_test(gmock-nice-strict_test gmock_main) - cxx_test(gmock-port_test gmock_main) - cxx_test(gmock-spec-builders_test gmock_main) - cxx_test(gmock_link_test gmock_main test/gmock_link2_test.cc) - cxx_test(gmock_test gmock_main) - - if (DEFINED GTEST_HAS_PTHREAD) - cxx_test(gmock_stress_test gmock) - endif() - - # gmock_all_test is commented to save time building and running tests. - # Uncomment if necessary. - # cxx_test(gmock_all_test gmock_main) - - ############################################################ - # C++ tests built with non-standard compiler flags. - - if (MSVC) - cxx_library(gmock_main_no_exception "${cxx_no_exception}" - "${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc) - - cxx_library(gmock_main_no_rtti "${cxx_no_rtti}" - "${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc) - - else() - cxx_library(gmock_main_no_exception "${cxx_no_exception}" src/gmock_main.cc) - target_link_libraries(gmock_main_no_exception PUBLIC gmock) - - cxx_library(gmock_main_no_rtti "${cxx_no_rtti}" src/gmock_main.cc) - target_link_libraries(gmock_main_no_rtti PUBLIC gmock) - endif() - cxx_test_with_flags(gmock-more-actions_no_exception_test "${cxx_no_exception}" - gmock_main_no_exception test/gmock-more-actions_test.cc) - - cxx_test_with_flags(gmock_no_rtti_test "${cxx_no_rtti}" - gmock_main_no_rtti test/gmock-spec-builders_test.cc) - - cxx_shared_library(shared_gmock_main "${cxx_default}" - "${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc) - - # Tests that a binary can be built with Google Mock as a shared library. On - # some system configurations, it may not possible to run the binary without - # knowing more details about the system configurations. We do not try to run - # this binary. To get a more robust shared library coverage, configure with - # -DBUILD_SHARED_LIBS=ON. - cxx_executable_with_flags(shared_gmock_test_ "${cxx_default}" - shared_gmock_main test/gmock-spec-builders_test.cc) - set_target_properties(shared_gmock_test_ - PROPERTIES - COMPILE_DEFINITIONS "GTEST_LINKED_AS_SHARED_LIBRARY=1") - - ############################################################ - # Python tests. - - cxx_executable(gmock_leak_test_ test gmock_main) - py_test(gmock_leak_test) - - cxx_executable(gmock_output_test_ test gmock) - py_test(gmock_output_test) -endif() diff --git a/test/GTest/googlemock/README.md b/test/GTest/googlemock/README.md deleted file mode 100644 index ead6883..0000000 --- a/test/GTest/googlemock/README.md +++ /dev/null @@ -1,44 +0,0 @@ -# Googletest Mocking (gMock) Framework - -### Overview - -Google's framework for writing and using C++ mock classes. It can help you -derive better designs of your system and write better tests. - -It is inspired by: - -* [jMock](http://www.jmock.org/) -* [EasyMock](http://www.easymock.org/) -* [Hamcrest](http://code.google.com/p/hamcrest/) - -It is designed with C++'s specifics in mind. - -gMock: - -- Provides a declarative syntax for defining mocks. -- Can define partial (hybrid) mocks, which are a cross of real and mock - objects. -- Handles functions of arbitrary types and overloaded functions. -- Comes with a rich set of matchers for validating function arguments. -- Uses an intuitive syntax for controlling the behavior of a mock. -- Does automatic verification of expectations (no record-and-replay needed). -- Allows arbitrary (partial) ordering constraints on function calls to be - expressed. -- Lets a user extend it by defining new matchers and actions. -- Does not use exceptions. -- Is easy to learn and use. - -Details and examples can be found here: - -* [gMock for Dummies](https://google.github.io/googletest/gmock_for_dummies.html) -* [Legacy gMock FAQ](https://google.github.io/googletest/gmock_faq.html) -* [gMock Cookbook](https://google.github.io/googletest/gmock_cook_book.html) -* [gMock Cheat Sheet](https://google.github.io/googletest/gmock_cheat_sheet.html) - -Please note that code under scripts/generator/ is from the -[cppclean project](http://code.google.com/p/cppclean/) and under the Apache -License, which is different from GoogleMock's license. - -GoogleMock is a part of -[GoogleTest C++ testing framework](http://github.com/google/googletest/) and a -subject to the same requirements. diff --git a/test/GTest/googlemock/cmake/gmock.pc.in b/test/GTest/googlemock/cmake/gmock.pc.in deleted file mode 100644 index 23c67b5..0000000 --- a/test/GTest/googlemock/cmake/gmock.pc.in +++ /dev/null @@ -1,10 +0,0 @@ -libdir=@CMAKE_INSTALL_FULL_LIBDIR@ -includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ - -Name: gmock -Description: GoogleMock (without main() function) -Version: @PROJECT_VERSION@ -URL: https://github.com/google/googletest -Requires: gtest = @PROJECT_VERSION@ -Libs: -L${libdir} -lgmock @CMAKE_THREAD_LIBS_INIT@ -Cflags: -I${includedir} @GTEST_HAS_PTHREAD_MACRO@ diff --git a/test/GTest/googlemock/cmake/gmock_main.pc.in b/test/GTest/googlemock/cmake/gmock_main.pc.in deleted file mode 100644 index 66ffea7..0000000 --- a/test/GTest/googlemock/cmake/gmock_main.pc.in +++ /dev/null @@ -1,10 +0,0 @@ -libdir=@CMAKE_INSTALL_FULL_LIBDIR@ -includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ - -Name: gmock_main -Description: GoogleMock (with main() function) -Version: @PROJECT_VERSION@ -URL: https://github.com/google/googletest -Requires: gmock = @PROJECT_VERSION@ -Libs: -L${libdir} -lgmock_main @CMAKE_THREAD_LIBS_INIT@ -Cflags: -I${includedir} @GTEST_HAS_PTHREAD_MACRO@ diff --git a/test/GTest/googlemock/docs/README.md b/test/GTest/googlemock/docs/README.md deleted file mode 100644 index 1bc57b7..0000000 --- a/test/GTest/googlemock/docs/README.md +++ /dev/null @@ -1,4 +0,0 @@ -# Content Moved - -We are working on updates to the GoogleTest documentation, which has moved to -the top-level [docs](../../docs) directory. diff --git a/test/GTest/googlemock/include/gmock/gmock-actions.h b/test/GTest/googlemock/include/gmock/gmock-actions.h deleted file mode 100644 index f2393bd..0000000 --- a/test/GTest/googlemock/include/gmock/gmock-actions.h +++ /dev/null @@ -1,1687 +0,0 @@ -// Copyright 2007, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - -// Google Mock - a framework for writing C++ mock classes. -// -// The ACTION* family of macros can be used in a namespace scope to -// define custom actions easily. The syntax: -// -// ACTION(name) { statements; } -// -// will define an action with the given name that executes the -// statements. The value returned by the statements will be used as -// the return value of the action. Inside the statements, you can -// refer to the K-th (0-based) argument of the mock function by -// 'argK', and refer to its type by 'argK_type'. For example: -// -// ACTION(IncrementArg1) { -// arg1_type temp = arg1; -// return ++(*temp); -// } -// -// allows you to write -// -// ...WillOnce(IncrementArg1()); -// -// You can also refer to the entire argument tuple and its type by -// 'args' and 'args_type', and refer to the mock function type and its -// return type by 'function_type' and 'return_type'. -// -// Note that you don't need to specify the types of the mock function -// arguments. However rest assured that your code is still type-safe: -// you'll get a compiler error if *arg1 doesn't support the ++ -// operator, or if the type of ++(*arg1) isn't compatible with the -// mock function's return type, for example. -// -// Sometimes you'll want to parameterize the action. For that you can use -// another macro: -// -// ACTION_P(name, param_name) { statements; } -// -// For example: -// -// ACTION_P(Add, n) { return arg0 + n; } -// -// will allow you to write: -// -// ...WillOnce(Add(5)); -// -// Note that you don't need to provide the type of the parameter -// either. If you need to reference the type of a parameter named -// 'foo', you can write 'foo_type'. For example, in the body of -// ACTION_P(Add, n) above, you can write 'n_type' to refer to the type -// of 'n'. -// -// We also provide ACTION_P2, ACTION_P3, ..., up to ACTION_P10 to support -// multi-parameter actions. -// -// For the purpose of typing, you can view -// -// ACTION_Pk(Foo, p1, ..., pk) { ... } -// -// as shorthand for -// -// template -// FooActionPk Foo(p1_type p1, ..., pk_type pk) { ... } -// -// In particular, you can provide the template type arguments -// explicitly when invoking Foo(), as in Foo(5, false); -// although usually you can rely on the compiler to infer the types -// for you automatically. You can assign the result of expression -// Foo(p1, ..., pk) to a variable of type FooActionPk. This can be useful when composing actions. -// -// You can also overload actions with different numbers of parameters: -// -// ACTION_P(Plus, a) { ... } -// ACTION_P2(Plus, a, b) { ... } -// -// While it's tempting to always use the ACTION* macros when defining -// a new action, you should also consider implementing ActionInterface -// or using MakePolymorphicAction() instead, especially if you need to -// use the action a lot. While these approaches require more work, -// they give you more control on the types of the mock function -// arguments and the action parameters, which in general leads to -// better compiler error messages that pay off in the long run. They -// also allow overloading actions based on parameter types (as opposed -// to just based on the number of parameters). -// -// CAVEAT: -// -// ACTION*() can only be used in a namespace scope as templates cannot be -// declared inside of a local class. -// Users can, however, define any local functors (e.g. a lambda) that -// can be used as actions. -// -// MORE INFORMATION: -// -// To learn more about using these macros, please search for 'ACTION' on -// https://github.com/google/googletest/blob/master/docs/gmock_cook_book.md - -// GOOGLETEST_CM0002 DO NOT DELETE - -#ifndef GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_ -#define GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_ - -#ifndef _WIN32_WCE -# include -#endif - -#include -#include -#include -#include -#include -#include -#include - -#include "gmock/internal/gmock-internal-utils.h" -#include "gmock/internal/gmock-port.h" -#include "gmock/internal/gmock-pp.h" - -#ifdef _MSC_VER -# pragma warning(push) -# pragma warning(disable:4100) -#endif - -namespace testing { - -// To implement an action Foo, define: -// 1. a class FooAction that implements the ActionInterface interface, and -// 2. a factory function that creates an Action object from a -// const FooAction*. -// -// The two-level delegation design follows that of Matcher, providing -// consistency for extension developers. It also eases ownership -// management as Action objects can now be copied like plain values. - -namespace internal { - -// BuiltInDefaultValueGetter::Get() returns a -// default-constructed T value. BuiltInDefaultValueGetter::Get() crashes with an error. -// -// This primary template is used when kDefaultConstructible is true. -template -struct BuiltInDefaultValueGetter { - static T Get() { return T(); } -}; -template -struct BuiltInDefaultValueGetter { - static T Get() { - Assert(false, __FILE__, __LINE__, - "Default action undefined for the function return type."); - return internal::Invalid(); - // The above statement will never be reached, but is required in - // order for this function to compile. - } -}; - -// BuiltInDefaultValue::Get() returns the "built-in" default value -// for type T, which is NULL when T is a raw pointer type, 0 when T is -// a numeric type, false when T is bool, or "" when T is string or -// std::string. In addition, in C++11 and above, it turns a -// default-constructed T value if T is default constructible. For any -// other type T, the built-in default T value is undefined, and the -// function will abort the process. -template -class BuiltInDefaultValue { - public: - // This function returns true if and only if type T has a built-in default - // value. - static bool Exists() { - return ::std::is_default_constructible::value; - } - - static T Get() { - return BuiltInDefaultValueGetter< - T, ::std::is_default_constructible::value>::Get(); - } -}; - -// This partial specialization says that we use the same built-in -// default value for T and const T. -template -class BuiltInDefaultValue { - public: - static bool Exists() { return BuiltInDefaultValue::Exists(); } - static T Get() { return BuiltInDefaultValue::Get(); } -}; - -// This partial specialization defines the default values for pointer -// types. -template -class BuiltInDefaultValue { - public: - static bool Exists() { return true; } - static T* Get() { return nullptr; } -}; - -// The following specializations define the default values for -// specific types we care about. -#define GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(type, value) \ - template <> \ - class BuiltInDefaultValue { \ - public: \ - static bool Exists() { return true; } \ - static type Get() { return value; } \ - } - -GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(void, ); // NOLINT -GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(::std::string, ""); -GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(bool, false); -GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned char, '\0'); -GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed char, '\0'); -GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(char, '\0'); - -// There's no need for a default action for signed wchar_t, as that -// type is the same as wchar_t for gcc, and invalid for MSVC. -// -// There's also no need for a default action for unsigned wchar_t, as -// that type is the same as unsigned int for gcc, and invalid for -// MSVC. -#if GMOCK_WCHAR_T_IS_NATIVE_ -GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(wchar_t, 0U); // NOLINT -#endif - -GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned short, 0U); // NOLINT -GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed short, 0); // NOLINT -GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned int, 0U); -GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed int, 0); -GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned long, 0UL); // NOLINT -GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed long, 0L); // NOLINT -GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned long long, 0); // NOLINT -GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed long long, 0); // NOLINT -GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(float, 0); -GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(double, 0); - -#undef GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_ - -// Simple two-arg form of std::disjunction. -template -using disjunction = typename ::std::conditional::type; - -} // namespace internal - -// When an unexpected function call is encountered, Google Mock will -// let it return a default value if the user has specified one for its -// return type, or if the return type has a built-in default value; -// otherwise Google Mock won't know what value to return and will have -// to abort the process. -// -// The DefaultValue class allows a user to specify the -// default value for a type T that is both copyable and publicly -// destructible (i.e. anything that can be used as a function return -// type). The usage is: -// -// // Sets the default value for type T to be foo. -// DefaultValue::Set(foo); -template -class DefaultValue { - public: - // Sets the default value for type T; requires T to be - // copy-constructable and have a public destructor. - static void Set(T x) { - delete producer_; - producer_ = new FixedValueProducer(x); - } - - // Provides a factory function to be called to generate the default value. - // This method can be used even if T is only move-constructible, but it is not - // limited to that case. - typedef T (*FactoryFunction)(); - static void SetFactory(FactoryFunction factory) { - delete producer_; - producer_ = new FactoryValueProducer(factory); - } - - // Unsets the default value for type T. - static void Clear() { - delete producer_; - producer_ = nullptr; - } - - // Returns true if and only if the user has set the default value for type T. - static bool IsSet() { return producer_ != nullptr; } - - // Returns true if T has a default return value set by the user or there - // exists a built-in default value. - static bool Exists() { - return IsSet() || internal::BuiltInDefaultValue::Exists(); - } - - // Returns the default value for type T if the user has set one; - // otherwise returns the built-in default value. Requires that Exists() - // is true, which ensures that the return value is well-defined. - static T Get() { - return producer_ == nullptr ? internal::BuiltInDefaultValue::Get() - : producer_->Produce(); - } - - private: - class ValueProducer { - public: - virtual ~ValueProducer() {} - virtual T Produce() = 0; - }; - - class FixedValueProducer : public ValueProducer { - public: - explicit FixedValueProducer(T value) : value_(value) {} - T Produce() override { return value_; } - - private: - const T value_; - GTEST_DISALLOW_COPY_AND_ASSIGN_(FixedValueProducer); - }; - - class FactoryValueProducer : public ValueProducer { - public: - explicit FactoryValueProducer(FactoryFunction factory) - : factory_(factory) {} - T Produce() override { return factory_(); } - - private: - const FactoryFunction factory_; - GTEST_DISALLOW_COPY_AND_ASSIGN_(FactoryValueProducer); - }; - - static ValueProducer* producer_; -}; - -// This partial specialization allows a user to set default values for -// reference types. -template -class DefaultValue { - public: - // Sets the default value for type T&. - static void Set(T& x) { // NOLINT - address_ = &x; - } - - // Unsets the default value for type T&. - static void Clear() { address_ = nullptr; } - - // Returns true if and only if the user has set the default value for type T&. - static bool IsSet() { return address_ != nullptr; } - - // Returns true if T has a default return value set by the user or there - // exists a built-in default value. - static bool Exists() { - return IsSet() || internal::BuiltInDefaultValue::Exists(); - } - - // Returns the default value for type T& if the user has set one; - // otherwise returns the built-in default value if there is one; - // otherwise aborts the process. - static T& Get() { - return address_ == nullptr ? internal::BuiltInDefaultValue::Get() - : *address_; - } - - private: - static T* address_; -}; - -// This specialization allows DefaultValue::Get() to -// compile. -template <> -class DefaultValue { - public: - static bool Exists() { return true; } - static void Get() {} -}; - -// Points to the user-set default value for type T. -template -typename DefaultValue::ValueProducer* DefaultValue::producer_ = nullptr; - -// Points to the user-set default value for type T&. -template -T* DefaultValue::address_ = nullptr; - -// Implement this interface to define an action for function type F. -template -class ActionInterface { - public: - typedef typename internal::Function::Result Result; - typedef typename internal::Function::ArgumentTuple ArgumentTuple; - - ActionInterface() {} - virtual ~ActionInterface() {} - - // Performs the action. This method is not const, as in general an - // action can have side effects and be stateful. For example, a - // get-the-next-element-from-the-collection action will need to - // remember the current element. - virtual Result Perform(const ArgumentTuple& args) = 0; - - private: - GTEST_DISALLOW_COPY_AND_ASSIGN_(ActionInterface); -}; - -// An Action is a copyable and IMMUTABLE (except by assignment) -// object that represents an action to be taken when a mock function -// of type F is called. The implementation of Action is just a -// std::shared_ptr to const ActionInterface. Don't inherit from Action! -// You can view an object implementing ActionInterface as a -// concrete action (including its current state), and an Action -// object as a handle to it. -template -class Action { - // Adapter class to allow constructing Action from a legacy ActionInterface. - // New code should create Actions from functors instead. - struct ActionAdapter { - // Adapter must be copyable to satisfy std::function requirements. - ::std::shared_ptr> impl_; - - template - typename internal::Function::Result operator()(Args&&... args) { - return impl_->Perform( - ::std::forward_as_tuple(::std::forward(args)...)); - } - }; - - template - using IsCompatibleFunctor = std::is_constructible, G>; - - public: - typedef typename internal::Function::Result Result; - typedef typename internal::Function::ArgumentTuple ArgumentTuple; - - // Constructs a null Action. Needed for storing Action objects in - // STL containers. - Action() {} - - // Construct an Action from a specified callable. - // This cannot take std::function directly, because then Action would not be - // directly constructible from lambda (it would require two conversions). - template < - typename G, - typename = typename std::enable_if, std::is_constructible, - G>>::value>::type> - Action(G&& fun) { // NOLINT - Init(::std::forward(fun), IsCompatibleFunctor()); - } - - // Constructs an Action from its implementation. - explicit Action(ActionInterface* impl) - : fun_(ActionAdapter{::std::shared_ptr>(impl)}) {} - - // This constructor allows us to turn an Action object into an - // Action, as long as F's arguments can be implicitly converted - // to Func's and Func's return type can be implicitly converted to F's. - template - explicit Action(const Action& action) : fun_(action.fun_) {} - - // Returns true if and only if this is the DoDefault() action. - bool IsDoDefault() const { return fun_ == nullptr; } - - // Performs the action. Note that this method is const even though - // the corresponding method in ActionInterface is not. The reason - // is that a const Action means that it cannot be re-bound to - // another concrete action, not that the concrete action it binds to - // cannot change state. (Think of the difference between a const - // pointer and a pointer to const.) - Result Perform(ArgumentTuple args) const { - if (IsDoDefault()) { - internal::IllegalDoDefault(__FILE__, __LINE__); - } - return internal::Apply(fun_, ::std::move(args)); - } - - private: - template - friend class Action; - - template - void Init(G&& g, ::std::true_type) { - fun_ = ::std::forward(g); - } - - template - void Init(G&& g, ::std::false_type) { - fun_ = IgnoreArgs::type>{::std::forward(g)}; - } - - template - struct IgnoreArgs { - template - Result operator()(const Args&...) const { - return function_impl(); - } - - FunctionImpl function_impl; - }; - - // fun_ is an empty function if and only if this is the DoDefault() action. - ::std::function fun_; -}; - -// The PolymorphicAction class template makes it easy to implement a -// polymorphic action (i.e. an action that can be used in mock -// functions of than one type, e.g. Return()). -// -// To define a polymorphic action, a user first provides a COPYABLE -// implementation class that has a Perform() method template: -// -// class FooAction { -// public: -// template -// Result Perform(const ArgumentTuple& args) const { -// // Processes the arguments and returns a result, using -// // std::get(args) to get the N-th (0-based) argument in the tuple. -// } -// ... -// }; -// -// Then the user creates the polymorphic action using -// MakePolymorphicAction(object) where object has type FooAction. See -// the definition of Return(void) and SetArgumentPointee(value) for -// complete examples. -template -class PolymorphicAction { - public: - explicit PolymorphicAction(const Impl& impl) : impl_(impl) {} - - template - operator Action() const { - return Action(new MonomorphicImpl(impl_)); - } - - private: - template - class MonomorphicImpl : public ActionInterface { - public: - typedef typename internal::Function::Result Result; - typedef typename internal::Function::ArgumentTuple ArgumentTuple; - - explicit MonomorphicImpl(const Impl& impl) : impl_(impl) {} - - Result Perform(const ArgumentTuple& args) override { - return impl_.template Perform(args); - } - - private: - Impl impl_; - }; - - Impl impl_; -}; - -// Creates an Action from its implementation and returns it. The -// created Action object owns the implementation. -template -Action MakeAction(ActionInterface* impl) { - return Action(impl); -} - -// Creates a polymorphic action from its implementation. This is -// easier to use than the PolymorphicAction constructor as it -// doesn't require you to explicitly write the template argument, e.g. -// -// MakePolymorphicAction(foo); -// vs -// PolymorphicAction(foo); -template -inline PolymorphicAction MakePolymorphicAction(const Impl& impl) { - return PolymorphicAction(impl); -} - -namespace internal { - -// Helper struct to specialize ReturnAction to execute a move instead of a copy -// on return. Useful for move-only types, but could be used on any type. -template -struct ByMoveWrapper { - explicit ByMoveWrapper(T value) : payload(std::move(value)) {} - T payload; -}; - -// Implements the polymorphic Return(x) action, which can be used in -// any function that returns the type of x, regardless of the argument -// types. -// -// Note: The value passed into Return must be converted into -// Function::Result when this action is cast to Action rather than -// when that action is performed. This is important in scenarios like -// -// MOCK_METHOD1(Method, T(U)); -// ... -// { -// Foo foo; -// X x(&foo); -// EXPECT_CALL(mock, Method(_)).WillOnce(Return(x)); -// } -// -// In the example above the variable x holds reference to foo which leaves -// scope and gets destroyed. If copying X just copies a reference to foo, -// that copy will be left with a hanging reference. If conversion to T -// makes a copy of foo, the above code is safe. To support that scenario, we -// need to make sure that the type conversion happens inside the EXPECT_CALL -// statement, and conversion of the result of Return to Action is a -// good place for that. -// -// The real life example of the above scenario happens when an invocation -// of gtl::Container() is passed into Return. -// -template -class ReturnAction { - public: - // Constructs a ReturnAction object from the value to be returned. - // 'value' is passed by value instead of by const reference in order - // to allow Return("string literal") to compile. - explicit ReturnAction(R value) : value_(new R(std::move(value))) {} - - // This template type conversion operator allows Return(x) to be - // used in ANY function that returns x's type. - template - operator Action() const { // NOLINT - // Assert statement belongs here because this is the best place to verify - // conditions on F. It produces the clearest error messages - // in most compilers. - // Impl really belongs in this scope as a local class but can't - // because MSVC produces duplicate symbols in different translation units - // in this case. Until MS fixes that bug we put Impl into the class scope - // and put the typedef both here (for use in assert statement) and - // in the Impl class. But both definitions must be the same. - typedef typename Function::Result Result; - GTEST_COMPILE_ASSERT_( - !std::is_reference::value, - use_ReturnRef_instead_of_Return_to_return_a_reference); - static_assert(!std::is_void::value, - "Can't use Return() on an action expected to return `void`."); - return Action(new Impl(value_)); - } - - private: - // Implements the Return(x) action for a particular function type F. - template - class Impl : public ActionInterface { - public: - typedef typename Function::Result Result; - typedef typename Function::ArgumentTuple ArgumentTuple; - - // The implicit cast is necessary when Result has more than one - // single-argument constructor (e.g. Result is std::vector) and R - // has a type conversion operator template. In that case, value_(value) - // won't compile as the compiler doesn't known which constructor of - // Result to call. ImplicitCast_ forces the compiler to convert R to - // Result without considering explicit constructors, thus resolving the - // ambiguity. value_ is then initialized using its copy constructor. - explicit Impl(const std::shared_ptr& value) - : value_before_cast_(*value), - value_(ImplicitCast_(value_before_cast_)) {} - - Result Perform(const ArgumentTuple&) override { return value_; } - - private: - GTEST_COMPILE_ASSERT_(!std::is_reference::value, - Result_cannot_be_a_reference_type); - // We save the value before casting just in case it is being cast to a - // wrapper type. - R value_before_cast_; - Result value_; - - GTEST_DISALLOW_COPY_AND_ASSIGN_(Impl); - }; - - // Partially specialize for ByMoveWrapper. This version of ReturnAction will - // move its contents instead. - template - class Impl, F> : public ActionInterface { - public: - typedef typename Function::Result Result; - typedef typename Function::ArgumentTuple ArgumentTuple; - - explicit Impl(const std::shared_ptr& wrapper) - : performed_(false), wrapper_(wrapper) {} - - Result Perform(const ArgumentTuple&) override { - GTEST_CHECK_(!performed_) - << "A ByMove() action should only be performed once."; - performed_ = true; - return std::move(wrapper_->payload); - } - - private: - bool performed_; - const std::shared_ptr wrapper_; - }; - - const std::shared_ptr value_; -}; - -// Implements the ReturnNull() action. -class ReturnNullAction { - public: - // Allows ReturnNull() to be used in any pointer-returning function. In C++11 - // this is enforced by returning nullptr, and in non-C++11 by asserting a - // pointer type on compile time. - template - static Result Perform(const ArgumentTuple&) { - return nullptr; - } -}; - -// Implements the Return() action. -class ReturnVoidAction { - public: - // Allows Return() to be used in any void-returning function. - template - static void Perform(const ArgumentTuple&) { - static_assert(std::is_void::value, "Result should be void."); - } -}; - -// Implements the polymorphic ReturnRef(x) action, which can be used -// in any function that returns a reference to the type of x, -// regardless of the argument types. -template -class ReturnRefAction { - public: - // Constructs a ReturnRefAction object from the reference to be returned. - explicit ReturnRefAction(T& ref) : ref_(ref) {} // NOLINT - - // This template type conversion operator allows ReturnRef(x) to be - // used in ANY function that returns a reference to x's type. - template - operator Action() const { - typedef typename Function::Result Result; - // Asserts that the function return type is a reference. This - // catches the user error of using ReturnRef(x) when Return(x) - // should be used, and generates some helpful error message. - GTEST_COMPILE_ASSERT_(std::is_reference::value, - use_Return_instead_of_ReturnRef_to_return_a_value); - return Action(new Impl(ref_)); - } - - private: - // Implements the ReturnRef(x) action for a particular function type F. - template - class Impl : public ActionInterface { - public: - typedef typename Function::Result Result; - typedef typename Function::ArgumentTuple ArgumentTuple; - - explicit Impl(T& ref) : ref_(ref) {} // NOLINT - - Result Perform(const ArgumentTuple&) override { return ref_; } - - private: - T& ref_; - }; - - T& ref_; -}; - -// Implements the polymorphic ReturnRefOfCopy(x) action, which can be -// used in any function that returns a reference to the type of x, -// regardless of the argument types. -template -class ReturnRefOfCopyAction { - public: - // Constructs a ReturnRefOfCopyAction object from the reference to - // be returned. - explicit ReturnRefOfCopyAction(const T& value) : value_(value) {} // NOLINT - - // This template type conversion operator allows ReturnRefOfCopy(x) to be - // used in ANY function that returns a reference to x's type. - template - operator Action() const { - typedef typename Function::Result Result; - // Asserts that the function return type is a reference. This - // catches the user error of using ReturnRefOfCopy(x) when Return(x) - // should be used, and generates some helpful error message. - GTEST_COMPILE_ASSERT_( - std::is_reference::value, - use_Return_instead_of_ReturnRefOfCopy_to_return_a_value); - return Action(new Impl(value_)); - } - - private: - // Implements the ReturnRefOfCopy(x) action for a particular function type F. - template - class Impl : public ActionInterface { - public: - typedef typename Function::Result Result; - typedef typename Function::ArgumentTuple ArgumentTuple; - - explicit Impl(const T& value) : value_(value) {} // NOLINT - - Result Perform(const ArgumentTuple&) override { return value_; } - - private: - T value_; - }; - - const T value_; -}; - -// Implements the polymorphic ReturnRoundRobin(v) action, which can be -// used in any function that returns the element_type of v. -template -class ReturnRoundRobinAction { - public: - explicit ReturnRoundRobinAction(std::vector values) { - GTEST_CHECK_(!values.empty()) - << "ReturnRoundRobin requires at least one element."; - state_->values = std::move(values); - } - - template - T operator()(Args&&...) const { - return state_->Next(); - } - - private: - struct State { - T Next() { - T ret_val = values[i++]; - if (i == values.size()) i = 0; - return ret_val; - } - - std::vector values; - size_t i = 0; - }; - std::shared_ptr state_ = std::make_shared(); -}; - -// Implements the polymorphic DoDefault() action. -class DoDefaultAction { - public: - // This template type conversion operator allows DoDefault() to be - // used in any function. - template - operator Action() const { return Action(); } // NOLINT -}; - -// Implements the Assign action to set a given pointer referent to a -// particular value. -template -class AssignAction { - public: - AssignAction(T1* ptr, T2 value) : ptr_(ptr), value_(value) {} - - template - void Perform(const ArgumentTuple& /* args */) const { - *ptr_ = value_; - } - - private: - T1* const ptr_; - const T2 value_; -}; - -#if !GTEST_OS_WINDOWS_MOBILE - -// Implements the SetErrnoAndReturn action to simulate return from -// various system calls and libc functions. -template -class SetErrnoAndReturnAction { - public: - SetErrnoAndReturnAction(int errno_value, T result) - : errno_(errno_value), - result_(result) {} - template - Result Perform(const ArgumentTuple& /* args */) const { - errno = errno_; - return result_; - } - - private: - const int errno_; - const T result_; -}; - -#endif // !GTEST_OS_WINDOWS_MOBILE - -// Implements the SetArgumentPointee(x) action for any function -// whose N-th argument (0-based) is a pointer to x's type. -template -struct SetArgumentPointeeAction { - A value; - - template - void operator()(const Args&... args) const { - *::std::get(std::tie(args...)) = value; - } -}; - -// Implements the Invoke(object_ptr, &Class::Method) action. -template -struct InvokeMethodAction { - Class* const obj_ptr; - const MethodPtr method_ptr; - - template - auto operator()(Args&&... args) const - -> decltype((obj_ptr->*method_ptr)(std::forward(args)...)) { - return (obj_ptr->*method_ptr)(std::forward(args)...); - } -}; - -// Implements the InvokeWithoutArgs(f) action. The template argument -// FunctionImpl is the implementation type of f, which can be either a -// function pointer or a functor. InvokeWithoutArgs(f) can be used as an -// Action as long as f's type is compatible with F. -template -struct InvokeWithoutArgsAction { - FunctionImpl function_impl; - - // Allows InvokeWithoutArgs(f) to be used as any action whose type is - // compatible with f. - template - auto operator()(const Args&...) -> decltype(function_impl()) { - return function_impl(); - } -}; - -// Implements the InvokeWithoutArgs(object_ptr, &Class::Method) action. -template -struct InvokeMethodWithoutArgsAction { - Class* const obj_ptr; - const MethodPtr method_ptr; - - using ReturnType = - decltype((std::declval()->*std::declval())()); - - template - ReturnType operator()(const Args&...) const { - return (obj_ptr->*method_ptr)(); - } -}; - -// Implements the IgnoreResult(action) action. -template -class IgnoreResultAction { - public: - explicit IgnoreResultAction(const A& action) : action_(action) {} - - template - operator Action() const { - // Assert statement belongs here because this is the best place to verify - // conditions on F. It produces the clearest error messages - // in most compilers. - // Impl really belongs in this scope as a local class but can't - // because MSVC produces duplicate symbols in different translation units - // in this case. Until MS fixes that bug we put Impl into the class scope - // and put the typedef both here (for use in assert statement) and - // in the Impl class. But both definitions must be the same. - typedef typename internal::Function::Result Result; - - // Asserts at compile time that F returns void. - static_assert(std::is_void::value, "Result type should be void."); - - return Action(new Impl(action_)); - } - - private: - template - class Impl : public ActionInterface { - public: - typedef typename internal::Function::Result Result; - typedef typename internal::Function::ArgumentTuple ArgumentTuple; - - explicit Impl(const A& action) : action_(action) {} - - void Perform(const ArgumentTuple& args) override { - // Performs the action and ignores its result. - action_.Perform(args); - } - - private: - // Type OriginalFunction is the same as F except that its return - // type is IgnoredValue. - typedef typename internal::Function::MakeResultIgnoredValue - OriginalFunction; - - const Action action_; - }; - - const A action_; -}; - -template -struct WithArgsAction { - InnerAction action; - - // The inner action could be anything convertible to Action. - // We use the conversion operator to detect the signature of the inner Action. - template - operator Action() const { // NOLINT - using TupleType = std::tuple; - Action::type...)> - converted(action); - - return [converted](Args... args) -> R { - return converted.Perform(std::forward_as_tuple( - std::get(std::forward_as_tuple(std::forward(args)...))...)); - }; - } -}; - -template -struct DoAllAction { - private: - template - using NonFinalType = - typename std::conditional::value, T, const T&>::type; - - template - std::vector Convert(IndexSequence) const { - return {ActionT(std::get(actions))...}; - } - - public: - std::tuple actions; - - template - operator Action() const { // NOLINT - struct Op { - std::vector...)>> converted; - Action last; - R operator()(Args... args) const { - auto tuple_args = std::forward_as_tuple(std::forward(args)...); - for (auto& a : converted) { - a.Perform(tuple_args); - } - return last.Perform(std::move(tuple_args)); - } - }; - return Op{Convert...)>>( - MakeIndexSequence()), - std::get(actions)}; - } -}; - -template -struct ReturnNewAction { - T* operator()() const { - return internal::Apply( - [](const Params&... unpacked_params) { - return new T(unpacked_params...); - }, - params); - } - std::tuple params; -}; - -template -struct ReturnArgAction { - template - auto operator()(const Args&... args) const -> - typename std::tuple_element>::type { - return std::get(std::tie(args...)); - } -}; - -template -struct SaveArgAction { - Ptr pointer; - - template - void operator()(const Args&... args) const { - *pointer = std::get(std::tie(args...)); - } -}; - -template -struct SaveArgPointeeAction { - Ptr pointer; - - template - void operator()(const Args&... args) const { - *pointer = *std::get(std::tie(args...)); - } -}; - -template -struct SetArgRefereeAction { - T value; - - template - void operator()(Args&&... args) const { - using argk_type = - typename ::std::tuple_element>::type; - static_assert(std::is_lvalue_reference::value, - "Argument must be a reference type."); - std::get(std::tie(args...)) = value; - } -}; - -template -struct SetArrayArgumentAction { - I1 first; - I2 last; - - template - void operator()(const Args&... args) const { - auto value = std::get(std::tie(args...)); - for (auto it = first; it != last; ++it, (void)++value) { - *value = *it; - } - } -}; - -template -struct DeleteArgAction { - template - void operator()(const Args&... args) const { - delete std::get(std::tie(args...)); - } -}; - -template -struct ReturnPointeeAction { - Ptr pointer; - template - auto operator()(const Args&...) const -> decltype(*pointer) { - return *pointer; - } -}; - -#if GTEST_HAS_EXCEPTIONS -template -struct ThrowAction { - T exception; - // We use a conversion operator to adapt to any return type. - template - operator Action() const { // NOLINT - T copy = exception; - return [copy](Args...) -> R { throw copy; }; - } -}; -#endif // GTEST_HAS_EXCEPTIONS - -} // namespace internal - -// An Unused object can be implicitly constructed from ANY value. -// This is handy when defining actions that ignore some or all of the -// mock function arguments. For example, given -// -// MOCK_METHOD3(Foo, double(const string& label, double x, double y)); -// MOCK_METHOD3(Bar, double(int index, double x, double y)); -// -// instead of -// -// double DistanceToOriginWithLabel(const string& label, double x, double y) { -// return sqrt(x*x + y*y); -// } -// double DistanceToOriginWithIndex(int index, double x, double y) { -// return sqrt(x*x + y*y); -// } -// ... -// EXPECT_CALL(mock, Foo("abc", _, _)) -// .WillOnce(Invoke(DistanceToOriginWithLabel)); -// EXPECT_CALL(mock, Bar(5, _, _)) -// .WillOnce(Invoke(DistanceToOriginWithIndex)); -// -// you could write -// -// // We can declare any uninteresting argument as Unused. -// double DistanceToOrigin(Unused, double x, double y) { -// return sqrt(x*x + y*y); -// } -// ... -// EXPECT_CALL(mock, Foo("abc", _, _)).WillOnce(Invoke(DistanceToOrigin)); -// EXPECT_CALL(mock, Bar(5, _, _)).WillOnce(Invoke(DistanceToOrigin)); -typedef internal::IgnoredValue Unused; - -// Creates an action that does actions a1, a2, ..., sequentially in -// each invocation. All but the last action will have a readonly view of the -// arguments. -template -internal::DoAllAction::type...> DoAll( - Action&&... action) { - return {std::forward_as_tuple(std::forward(action)...)}; -} - -// WithArg(an_action) creates an action that passes the k-th -// (0-based) argument of the mock function to an_action and performs -// it. It adapts an action accepting one argument to one that accepts -// multiple arguments. For convenience, we also provide -// WithArgs(an_action) (defined below) as a synonym. -template -internal::WithArgsAction::type, k> -WithArg(InnerAction&& action) { - return {std::forward(action)}; -} - -// WithArgs(an_action) creates an action that passes -// the selected arguments of the mock function to an_action and -// performs it. It serves as an adaptor between actions with -// different argument lists. -template -internal::WithArgsAction::type, k, ks...> -WithArgs(InnerAction&& action) { - return {std::forward(action)}; -} - -// WithoutArgs(inner_action) can be used in a mock function with a -// non-empty argument list to perform inner_action, which takes no -// argument. In other words, it adapts an action accepting no -// argument to one that accepts (and ignores) arguments. -template -internal::WithArgsAction::type> -WithoutArgs(InnerAction&& action) { - return {std::forward(action)}; -} - -// Creates an action that returns 'value'. 'value' is passed by value -// instead of const reference - otherwise Return("string literal") -// will trigger a compiler error about using array as initializer. -template -internal::ReturnAction Return(R value) { - return internal::ReturnAction(std::move(value)); -} - -// Creates an action that returns NULL. -inline PolymorphicAction ReturnNull() { - return MakePolymorphicAction(internal::ReturnNullAction()); -} - -// Creates an action that returns from a void function. -inline PolymorphicAction Return() { - return MakePolymorphicAction(internal::ReturnVoidAction()); -} - -// Creates an action that returns the reference to a variable. -template -inline internal::ReturnRefAction ReturnRef(R& x) { // NOLINT - return internal::ReturnRefAction(x); -} - -// Prevent using ReturnRef on reference to temporary. -template -internal::ReturnRefAction ReturnRef(R&&) = delete; - -// Creates an action that returns the reference to a copy of the -// argument. The copy is created when the action is constructed and -// lives as long as the action. -template -inline internal::ReturnRefOfCopyAction ReturnRefOfCopy(const R& x) { - return internal::ReturnRefOfCopyAction(x); -} - -// Modifies the parent action (a Return() action) to perform a move of the -// argument instead of a copy. -// Return(ByMove()) actions can only be executed once and will assert this -// invariant. -template -internal::ByMoveWrapper ByMove(R x) { - return internal::ByMoveWrapper(std::move(x)); -} - -// Creates an action that returns an element of `vals`. Calling this action will -// repeatedly return the next value from `vals` until it reaches the end and -// will restart from the beginning. -template -internal::ReturnRoundRobinAction ReturnRoundRobin(std::vector vals) { - return internal::ReturnRoundRobinAction(std::move(vals)); -} - -// Creates an action that returns an element of `vals`. Calling this action will -// repeatedly return the next value from `vals` until it reaches the end and -// will restart from the beginning. -template -internal::ReturnRoundRobinAction ReturnRoundRobin( - std::initializer_list vals) { - return internal::ReturnRoundRobinAction(std::vector(vals)); -} - -// Creates an action that does the default action for the give mock function. -inline internal::DoDefaultAction DoDefault() { - return internal::DoDefaultAction(); -} - -// Creates an action that sets the variable pointed by the N-th -// (0-based) function argument to 'value'. -template -internal::SetArgumentPointeeAction SetArgPointee(T value) { - return {std::move(value)}; -} - -// The following version is DEPRECATED. -template -internal::SetArgumentPointeeAction SetArgumentPointee(T value) { - return {std::move(value)}; -} - -// Creates an action that sets a pointer referent to a given value. -template -PolymorphicAction > Assign(T1* ptr, T2 val) { - return MakePolymorphicAction(internal::AssignAction(ptr, val)); -} - -#if !GTEST_OS_WINDOWS_MOBILE - -// Creates an action that sets errno and returns the appropriate error. -template -PolymorphicAction > -SetErrnoAndReturn(int errval, T result) { - return MakePolymorphicAction( - internal::SetErrnoAndReturnAction(errval, result)); -} - -#endif // !GTEST_OS_WINDOWS_MOBILE - -// Various overloads for Invoke(). - -// Legacy function. -// Actions can now be implicitly constructed from callables. No need to create -// wrapper objects. -// This function exists for backwards compatibility. -template -typename std::decay::type Invoke(FunctionImpl&& function_impl) { - return std::forward(function_impl); -} - -// Creates an action that invokes the given method on the given object -// with the mock function's arguments. -template -internal::InvokeMethodAction Invoke(Class* obj_ptr, - MethodPtr method_ptr) { - return {obj_ptr, method_ptr}; -} - -// Creates an action that invokes 'function_impl' with no argument. -template -internal::InvokeWithoutArgsAction::type> -InvokeWithoutArgs(FunctionImpl function_impl) { - return {std::move(function_impl)}; -} - -// Creates an action that invokes the given method on the given object -// with no argument. -template -internal::InvokeMethodWithoutArgsAction InvokeWithoutArgs( - Class* obj_ptr, MethodPtr method_ptr) { - return {obj_ptr, method_ptr}; -} - -// Creates an action that performs an_action and throws away its -// result. In other words, it changes the return type of an_action to -// void. an_action MUST NOT return void, or the code won't compile. -template -inline internal::IgnoreResultAction IgnoreResult(const A& an_action) { - return internal::IgnoreResultAction(an_action); -} - -// Creates a reference wrapper for the given L-value. If necessary, -// you can explicitly specify the type of the reference. For example, -// suppose 'derived' is an object of type Derived, ByRef(derived) -// would wrap a Derived&. If you want to wrap a const Base& instead, -// where Base is a base class of Derived, just write: -// -// ByRef(derived) -// -// N.B. ByRef is redundant with std::ref, std::cref and std::reference_wrapper. -// However, it may still be used for consistency with ByMove(). -template -inline ::std::reference_wrapper ByRef(T& l_value) { // NOLINT - return ::std::reference_wrapper(l_value); -} - -// The ReturnNew(a1, a2, ..., a_k) action returns a pointer to a new -// instance of type T, constructed on the heap with constructor arguments -// a1, a2, ..., and a_k. The caller assumes ownership of the returned value. -template -internal::ReturnNewAction::type...> ReturnNew( - Params&&... params) { - return {std::forward_as_tuple(std::forward(params)...)}; -} - -// Action ReturnArg() returns the k-th argument of the mock function. -template -internal::ReturnArgAction ReturnArg() { - return {}; -} - -// Action SaveArg(pointer) saves the k-th (0-based) argument of the -// mock function to *pointer. -template -internal::SaveArgAction SaveArg(Ptr pointer) { - return {pointer}; -} - -// Action SaveArgPointee(pointer) saves the value pointed to -// by the k-th (0-based) argument of the mock function to *pointer. -template -internal::SaveArgPointeeAction SaveArgPointee(Ptr pointer) { - return {pointer}; -} - -// Action SetArgReferee(value) assigns 'value' to the variable -// referenced by the k-th (0-based) argument of the mock function. -template -internal::SetArgRefereeAction::type> SetArgReferee( - T&& value) { - return {std::forward(value)}; -} - -// Action SetArrayArgument(first, last) copies the elements in -// source range [first, last) to the array pointed to by the k-th -// (0-based) argument, which can be either a pointer or an -// iterator. The action does not take ownership of the elements in the -// source range. -template -internal::SetArrayArgumentAction SetArrayArgument(I1 first, - I2 last) { - return {first, last}; -} - -// Action DeleteArg() deletes the k-th (0-based) argument of the mock -// function. -template -internal::DeleteArgAction DeleteArg() { - return {}; -} - -// This action returns the value pointed to by 'pointer'. -template -internal::ReturnPointeeAction ReturnPointee(Ptr pointer) { - return {pointer}; -} - -// Action Throw(exception) can be used in a mock function of any type -// to throw the given exception. Any copyable value can be thrown. -#if GTEST_HAS_EXCEPTIONS -template -internal::ThrowAction::type> Throw(T&& exception) { - return {std::forward(exception)}; -} -#endif // GTEST_HAS_EXCEPTIONS - -namespace internal { - -// A macro from the ACTION* family (defined later in gmock-generated-actions.h) -// defines an action that can be used in a mock function. Typically, -// these actions only care about a subset of the arguments of the mock -// function. For example, if such an action only uses the second -// argument, it can be used in any mock function that takes >= 2 -// arguments where the type of the second argument is compatible. -// -// Therefore, the action implementation must be prepared to take more -// arguments than it needs. The ExcessiveArg type is used to -// represent those excessive arguments. In order to keep the compiler -// error messages tractable, we define it in the testing namespace -// instead of testing::internal. However, this is an INTERNAL TYPE -// and subject to change without notice, so a user MUST NOT USE THIS -// TYPE DIRECTLY. -struct ExcessiveArg {}; - -// Builds an implementation of an Action<> for some particular signature, using -// a class defined by an ACTION* macro. -template struct ActionImpl; - -template -struct ImplBase { - struct Holder { - // Allows each copy of the Action<> to get to the Impl. - explicit operator const Impl&() const { return *ptr; } - std::shared_ptr ptr; - }; - using type = typename std::conditional::value, - Impl, Holder>::type; -}; - -template -struct ActionImpl : ImplBase::type { - using Base = typename ImplBase::type; - using function_type = R(Args...); - using args_type = std::tuple; - - ActionImpl() = default; // Only defined if appropriate for Base. - explicit ActionImpl(std::shared_ptr impl) : Base{std::move(impl)} { } - - R operator()(Args&&... arg) const { - static constexpr size_t kMaxArgs = - sizeof...(Args) <= 10 ? sizeof...(Args) : 10; - return Apply(MakeIndexSequence{}, - MakeIndexSequence<10 - kMaxArgs>{}, - args_type{std::forward(arg)...}); - } - - template - R Apply(IndexSequence, IndexSequence, - const args_type& args) const { - // Impl need not be specific to the signature of action being implemented; - // only the implementing function body needs to have all of the specific - // types instantiated. Up to 10 of the args that are provided by the - // args_type get passed, followed by a dummy of unspecified type for the - // remainder up to 10 explicit args. - static constexpr ExcessiveArg kExcessArg{}; - return static_cast(*this).template gmock_PerformImpl< - /*function_type=*/function_type, /*return_type=*/R, - /*args_type=*/args_type, - /*argN_type=*/typename std::tuple_element::type...>( - /*args=*/args, std::get(args)..., - ((void)excess_id, kExcessArg)...); - } -}; - -// Stores a default-constructed Impl as part of the Action<>'s -// std::function<>. The Impl should be trivial to copy. -template -::testing::Action MakeAction() { - return ::testing::Action(ActionImpl()); -} - -// Stores just the one given instance of Impl. -template -::testing::Action MakeAction(std::shared_ptr impl) { - return ::testing::Action(ActionImpl(std::move(impl))); -} - -#define GMOCK_INTERNAL_ARG_UNUSED(i, data, el) \ - , const arg##i##_type& arg##i GTEST_ATTRIBUTE_UNUSED_ -#define GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_ \ - const args_type& args GTEST_ATTRIBUTE_UNUSED_ GMOCK_PP_REPEAT( \ - GMOCK_INTERNAL_ARG_UNUSED, , 10) - -#define GMOCK_INTERNAL_ARG(i, data, el) , const arg##i##_type& arg##i -#define GMOCK_ACTION_ARG_TYPES_AND_NAMES_ \ - const args_type& args GMOCK_PP_REPEAT(GMOCK_INTERNAL_ARG, , 10) - -#define GMOCK_INTERNAL_TEMPLATE_ARG(i, data, el) , typename arg##i##_type -#define GMOCK_ACTION_TEMPLATE_ARGS_NAMES_ \ - GMOCK_PP_TAIL(GMOCK_PP_REPEAT(GMOCK_INTERNAL_TEMPLATE_ARG, , 10)) - -#define GMOCK_INTERNAL_TYPENAME_PARAM(i, data, param) , typename param##_type -#define GMOCK_ACTION_TYPENAME_PARAMS_(params) \ - GMOCK_PP_TAIL(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_TYPENAME_PARAM, , params)) - -#define GMOCK_INTERNAL_TYPE_PARAM(i, data, param) , param##_type -#define GMOCK_ACTION_TYPE_PARAMS_(params) \ - GMOCK_PP_TAIL(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_TYPE_PARAM, , params)) - -#define GMOCK_INTERNAL_TYPE_GVALUE_PARAM(i, data, param) \ - , param##_type gmock_p##i -#define GMOCK_ACTION_TYPE_GVALUE_PARAMS_(params) \ - GMOCK_PP_TAIL(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_TYPE_GVALUE_PARAM, , params)) - -#define GMOCK_INTERNAL_GVALUE_PARAM(i, data, param) \ - , std::forward(gmock_p##i) -#define GMOCK_ACTION_GVALUE_PARAMS_(params) \ - GMOCK_PP_TAIL(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_GVALUE_PARAM, , params)) - -#define GMOCK_INTERNAL_INIT_PARAM(i, data, param) \ - , param(::std::forward(gmock_p##i)) -#define GMOCK_ACTION_INIT_PARAMS_(params) \ - GMOCK_PP_TAIL(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_INIT_PARAM, , params)) - -#define GMOCK_INTERNAL_FIELD_PARAM(i, data, param) param##_type param; -#define GMOCK_ACTION_FIELD_PARAMS_(params) \ - GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_FIELD_PARAM, , params) - -#define GMOCK_INTERNAL_ACTION(name, full_name, params) \ - template \ - class full_name { \ - public: \ - explicit full_name(GMOCK_ACTION_TYPE_GVALUE_PARAMS_(params)) \ - : impl_(std::make_shared( \ - GMOCK_ACTION_GVALUE_PARAMS_(params))) { } \ - full_name(const full_name&) = default; \ - full_name(full_name&&) noexcept = default; \ - template \ - operator ::testing::Action() const { \ - return ::testing::internal::MakeAction(impl_); \ - } \ - private: \ - class gmock_Impl { \ - public: \ - explicit gmock_Impl(GMOCK_ACTION_TYPE_GVALUE_PARAMS_(params)) \ - : GMOCK_ACTION_INIT_PARAMS_(params) {} \ - template \ - return_type gmock_PerformImpl(GMOCK_ACTION_ARG_TYPES_AND_NAMES_) const; \ - GMOCK_ACTION_FIELD_PARAMS_(params) \ - }; \ - std::shared_ptr impl_; \ - }; \ - template \ - inline full_name name( \ - GMOCK_ACTION_TYPE_GVALUE_PARAMS_(params)) { \ - return full_name( \ - GMOCK_ACTION_GVALUE_PARAMS_(params)); \ - } \ - template \ - template \ - return_type full_name::gmock_Impl:: \ - gmock_PerformImpl(GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const - -} // namespace internal - -// Similar to GMOCK_INTERNAL_ACTION, but no bound parameters are stored. -#define ACTION(name) \ - class name##Action { \ - public: \ - explicit name##Action() noexcept {} \ - name##Action(const name##Action&) noexcept {} \ - template \ - operator ::testing::Action() const { \ - return ::testing::internal::MakeAction(); \ - } \ - private: \ - class gmock_Impl { \ - public: \ - template \ - return_type gmock_PerformImpl(GMOCK_ACTION_ARG_TYPES_AND_NAMES_) const; \ - }; \ - }; \ - inline name##Action name() GTEST_MUST_USE_RESULT_; \ - inline name##Action name() { return name##Action(); } \ - template \ - return_type name##Action::gmock_Impl::gmock_PerformImpl( \ - GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const - -#define ACTION_P(name, ...) \ - GMOCK_INTERNAL_ACTION(name, name##ActionP, (__VA_ARGS__)) - -#define ACTION_P2(name, ...) \ - GMOCK_INTERNAL_ACTION(name, name##ActionP2, (__VA_ARGS__)) - -#define ACTION_P3(name, ...) \ - GMOCK_INTERNAL_ACTION(name, name##ActionP3, (__VA_ARGS__)) - -#define ACTION_P4(name, ...) \ - GMOCK_INTERNAL_ACTION(name, name##ActionP4, (__VA_ARGS__)) - -#define ACTION_P5(name, ...) \ - GMOCK_INTERNAL_ACTION(name, name##ActionP5, (__VA_ARGS__)) - -#define ACTION_P6(name, ...) \ - GMOCK_INTERNAL_ACTION(name, name##ActionP6, (__VA_ARGS__)) - -#define ACTION_P7(name, ...) \ - GMOCK_INTERNAL_ACTION(name, name##ActionP7, (__VA_ARGS__)) - -#define ACTION_P8(name, ...) \ - GMOCK_INTERNAL_ACTION(name, name##ActionP8, (__VA_ARGS__)) - -#define ACTION_P9(name, ...) \ - GMOCK_INTERNAL_ACTION(name, name##ActionP9, (__VA_ARGS__)) - -#define ACTION_P10(name, ...) \ - GMOCK_INTERNAL_ACTION(name, name##ActionP10, (__VA_ARGS__)) - -} // namespace testing - -#ifdef _MSC_VER -# pragma warning(pop) -#endif - -#endif // GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_ diff --git a/test/GTest/googlemock/include/gmock/gmock-cardinalities.h b/test/GTest/googlemock/include/gmock/gmock-cardinalities.h deleted file mode 100644 index fc7f803..0000000 --- a/test/GTest/googlemock/include/gmock/gmock-cardinalities.h +++ /dev/null @@ -1,157 +0,0 @@ -// Copyright 2007, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - -// Google Mock - a framework for writing C++ mock classes. -// -// This file implements some commonly used cardinalities. More -// cardinalities can be defined by the user implementing the -// CardinalityInterface interface if necessary. - -// GOOGLETEST_CM0002 DO NOT DELETE - -#ifndef GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_ -#define GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_ - -#include -#include -#include // NOLINT -#include "gmock/internal/gmock-port.h" -#include "gtest/gtest.h" - -GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \ -/* class A needs to have dll-interface to be used by clients of class B */) - -namespace testing { - -// To implement a cardinality Foo, define: -// 1. a class FooCardinality that implements the -// CardinalityInterface interface, and -// 2. a factory function that creates a Cardinality object from a -// const FooCardinality*. -// -// The two-level delegation design follows that of Matcher, providing -// consistency for extension developers. It also eases ownership -// management as Cardinality objects can now be copied like plain values. - -// The implementation of a cardinality. -class CardinalityInterface { - public: - virtual ~CardinalityInterface() {} - - // Conservative estimate on the lower/upper bound of the number of - // calls allowed. - virtual int ConservativeLowerBound() const { return 0; } - virtual int ConservativeUpperBound() const { return INT_MAX; } - - // Returns true if and only if call_count calls will satisfy this - // cardinality. - virtual bool IsSatisfiedByCallCount(int call_count) const = 0; - - // Returns true if and only if call_count calls will saturate this - // cardinality. - virtual bool IsSaturatedByCallCount(int call_count) const = 0; - - // Describes self to an ostream. - virtual void DescribeTo(::std::ostream* os) const = 0; -}; - -// A Cardinality is a copyable and IMMUTABLE (except by assignment) -// object that specifies how many times a mock function is expected to -// be called. The implementation of Cardinality is just a std::shared_ptr -// to const CardinalityInterface. Don't inherit from Cardinality! -class GTEST_API_ Cardinality { - public: - // Constructs a null cardinality. Needed for storing Cardinality - // objects in STL containers. - Cardinality() {} - - // Constructs a Cardinality from its implementation. - explicit Cardinality(const CardinalityInterface* impl) : impl_(impl) {} - - // Conservative estimate on the lower/upper bound of the number of - // calls allowed. - int ConservativeLowerBound() const { return impl_->ConservativeLowerBound(); } - int ConservativeUpperBound() const { return impl_->ConservativeUpperBound(); } - - // Returns true if and only if call_count calls will satisfy this - // cardinality. - bool IsSatisfiedByCallCount(int call_count) const { - return impl_->IsSatisfiedByCallCount(call_count); - } - - // Returns true if and only if call_count calls will saturate this - // cardinality. - bool IsSaturatedByCallCount(int call_count) const { - return impl_->IsSaturatedByCallCount(call_count); - } - - // Returns true if and only if call_count calls will over-saturate this - // cardinality, i.e. exceed the maximum number of allowed calls. - bool IsOverSaturatedByCallCount(int call_count) const { - return impl_->IsSaturatedByCallCount(call_count) && - !impl_->IsSatisfiedByCallCount(call_count); - } - - // Describes self to an ostream - void DescribeTo(::std::ostream* os) const { impl_->DescribeTo(os); } - - // Describes the given actual call count to an ostream. - static void DescribeActualCallCountTo(int actual_call_count, - ::std::ostream* os); - - private: - std::shared_ptr impl_; -}; - -// Creates a cardinality that allows at least n calls. -GTEST_API_ Cardinality AtLeast(int n); - -// Creates a cardinality that allows at most n calls. -GTEST_API_ Cardinality AtMost(int n); - -// Creates a cardinality that allows any number of calls. -GTEST_API_ Cardinality AnyNumber(); - -// Creates a cardinality that allows between min and max calls. -GTEST_API_ Cardinality Between(int min, int max); - -// Creates a cardinality that allows exactly n calls. -GTEST_API_ Cardinality Exactly(int n); - -// Creates a cardinality from its implementation. -inline Cardinality MakeCardinality(const CardinalityInterface* c) { - return Cardinality(c); -} - -} // namespace testing - -GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251 - -#endif // GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_ diff --git a/test/GTest/googlemock/include/gmock/gmock-function-mocker.h b/test/GTest/googlemock/include/gmock/gmock-function-mocker.h deleted file mode 100644 index 0fc6f6f..0000000 --- a/test/GTest/googlemock/include/gmock/gmock-function-mocker.h +++ /dev/null @@ -1,479 +0,0 @@ -// Copyright 2007, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Google Mock - a framework for writing C++ mock classes. -// -// This file implements MOCK_METHOD. - -// GOOGLETEST_CM0002 DO NOT DELETE - -#ifndef GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_FUNCTION_MOCKER_H_ // NOLINT -#define GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_FUNCTION_MOCKER_H_ // NOLINT - -#include // IWYU pragma: keep -#include // IWYU pragma: keep - -#include "gmock/gmock-spec-builders.h" -#include "gmock/internal/gmock-internal-utils.h" -#include "gmock/internal/gmock-pp.h" - -namespace testing { -namespace internal { -template -using identity_t = T; - -template -struct ThisRefAdjuster { - template - using AdjustT = typename std::conditional< - std::is_const::type>::value, - typename std::conditional::value, - const T&, const T&&>::type, - typename std::conditional::value, T&, - T&&>::type>::type; - - template - static AdjustT Adjust(const MockType& mock) { - return static_cast>(const_cast(mock)); - } -}; - -} // namespace internal - -// The style guide prohibits "using" statements in a namespace scope -// inside a header file. However, the FunctionMocker class template -// is meant to be defined in the ::testing namespace. The following -// line is just a trick for working around a bug in MSVC 8.0, which -// cannot handle it if we define FunctionMocker in ::testing. -using internal::FunctionMocker; -} // namespace testing - -#define MOCK_METHOD(...) \ - GMOCK_PP_VARIADIC_CALL(GMOCK_INTERNAL_MOCK_METHOD_ARG_, __VA_ARGS__) - -#define GMOCK_INTERNAL_MOCK_METHOD_ARG_1(...) \ - GMOCK_INTERNAL_WRONG_ARITY(__VA_ARGS__) - -#define GMOCK_INTERNAL_MOCK_METHOD_ARG_2(...) \ - GMOCK_INTERNAL_WRONG_ARITY(__VA_ARGS__) - -#define GMOCK_INTERNAL_MOCK_METHOD_ARG_3(_Ret, _MethodName, _Args) \ - GMOCK_INTERNAL_MOCK_METHOD_ARG_4(_Ret, _MethodName, _Args, ()) - -#define GMOCK_INTERNAL_MOCK_METHOD_ARG_4(_Ret, _MethodName, _Args, _Spec) \ - GMOCK_INTERNAL_ASSERT_PARENTHESIS(_Args); \ - GMOCK_INTERNAL_ASSERT_PARENTHESIS(_Spec); \ - GMOCK_INTERNAL_ASSERT_VALID_SIGNATURE( \ - GMOCK_PP_NARG0 _Args, GMOCK_INTERNAL_SIGNATURE(_Ret, _Args)); \ - GMOCK_INTERNAL_ASSERT_VALID_SPEC(_Spec) \ - GMOCK_INTERNAL_MOCK_METHOD_IMPL( \ - GMOCK_PP_NARG0 _Args, _MethodName, GMOCK_INTERNAL_HAS_CONST(_Spec), \ - GMOCK_INTERNAL_HAS_OVERRIDE(_Spec), GMOCK_INTERNAL_HAS_FINAL(_Spec), \ - GMOCK_INTERNAL_GET_NOEXCEPT_SPEC(_Spec), \ - GMOCK_INTERNAL_GET_CALLTYPE(_Spec), GMOCK_INTERNAL_GET_REF_SPEC(_Spec), \ - (GMOCK_INTERNAL_SIGNATURE(_Ret, _Args))) - -#define GMOCK_INTERNAL_MOCK_METHOD_ARG_5(...) \ - GMOCK_INTERNAL_WRONG_ARITY(__VA_ARGS__) - -#define GMOCK_INTERNAL_MOCK_METHOD_ARG_6(...) \ - GMOCK_INTERNAL_WRONG_ARITY(__VA_ARGS__) - -#define GMOCK_INTERNAL_MOCK_METHOD_ARG_7(...) \ - GMOCK_INTERNAL_WRONG_ARITY(__VA_ARGS__) - -#define GMOCK_INTERNAL_WRONG_ARITY(...) \ - static_assert( \ - false, \ - "MOCK_METHOD must be called with 3 or 4 arguments. _Ret, " \ - "_MethodName, _Args and optionally _Spec. _Args and _Spec must be " \ - "enclosed in parentheses. If _Ret is a type with unprotected commas, " \ - "it must also be enclosed in parentheses.") - -#define GMOCK_INTERNAL_ASSERT_PARENTHESIS(_Tuple) \ - static_assert( \ - GMOCK_PP_IS_ENCLOSED_PARENS(_Tuple), \ - GMOCK_PP_STRINGIZE(_Tuple) " should be enclosed in parentheses.") - -#define GMOCK_INTERNAL_ASSERT_VALID_SIGNATURE(_N, ...) \ - static_assert( \ - std::is_function<__VA_ARGS__>::value, \ - "Signature must be a function type, maybe return type contains " \ - "unprotected comma."); \ - static_assert( \ - ::testing::tuple_size::ArgumentTuple>::value == _N, \ - "This method does not take " GMOCK_PP_STRINGIZE( \ - _N) " arguments. Parenthesize all types with unprotected commas.") - -#define GMOCK_INTERNAL_ASSERT_VALID_SPEC(_Spec) \ - GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_ASSERT_VALID_SPEC_ELEMENT, ~, _Spec) - -#define GMOCK_INTERNAL_MOCK_METHOD_IMPL(_N, _MethodName, _Constness, \ - _Override, _Final, _NoexceptSpec, \ - _CallType, _RefSpec, _Signature) \ - typename ::testing::internal::Function::Result \ - GMOCK_INTERNAL_EXPAND(_CallType) \ - _MethodName(GMOCK_PP_REPEAT(GMOCK_INTERNAL_PARAMETER, _Signature, _N)) \ - GMOCK_PP_IF(_Constness, const, ) _RefSpec _NoexceptSpec \ - GMOCK_PP_IF(_Override, override, ) GMOCK_PP_IF(_Final, final, ) { \ - GMOCK_MOCKER_(_N, _Constness, _MethodName) \ - .SetOwnerAndName(this, #_MethodName); \ - return GMOCK_MOCKER_(_N, _Constness, _MethodName) \ - .Invoke(GMOCK_PP_REPEAT(GMOCK_INTERNAL_FORWARD_ARG, _Signature, _N)); \ - } \ - ::testing::MockSpec gmock_##_MethodName( \ - GMOCK_PP_REPEAT(GMOCK_INTERNAL_MATCHER_PARAMETER, _Signature, _N)) \ - GMOCK_PP_IF(_Constness, const, ) _RefSpec { \ - GMOCK_MOCKER_(_N, _Constness, _MethodName).RegisterOwner(this); \ - return GMOCK_MOCKER_(_N, _Constness, _MethodName) \ - .With(GMOCK_PP_REPEAT(GMOCK_INTERNAL_MATCHER_ARGUMENT, , _N)); \ - } \ - ::testing::MockSpec gmock_##_MethodName( \ - const ::testing::internal::WithoutMatchers&, \ - GMOCK_PP_IF(_Constness, const, )::testing::internal::Function< \ - GMOCK_PP_REMOVE_PARENS(_Signature)>*) const _RefSpec _NoexceptSpec { \ - return ::testing::internal::ThisRefAdjuster::Adjust(*this) \ - .gmock_##_MethodName(GMOCK_PP_REPEAT( \ - GMOCK_INTERNAL_A_MATCHER_ARGUMENT, _Signature, _N)); \ - } \ - mutable ::testing::FunctionMocker \ - GMOCK_MOCKER_(_N, _Constness, _MethodName) - -#define GMOCK_INTERNAL_EXPAND(...) __VA_ARGS__ - -// Five Valid modifiers. -#define GMOCK_INTERNAL_HAS_CONST(_Tuple) \ - GMOCK_PP_HAS_COMMA(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_DETECT_CONST, ~, _Tuple)) - -#define GMOCK_INTERNAL_HAS_OVERRIDE(_Tuple) \ - GMOCK_PP_HAS_COMMA( \ - GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_DETECT_OVERRIDE, ~, _Tuple)) - -#define GMOCK_INTERNAL_HAS_FINAL(_Tuple) \ - GMOCK_PP_HAS_COMMA(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_DETECT_FINAL, ~, _Tuple)) - -#define GMOCK_INTERNAL_GET_NOEXCEPT_SPEC(_Tuple) \ - GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_NOEXCEPT_SPEC_IF_NOEXCEPT, ~, _Tuple) - -#define GMOCK_INTERNAL_NOEXCEPT_SPEC_IF_NOEXCEPT(_i, _, _elem) \ - GMOCK_PP_IF( \ - GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_NOEXCEPT(_i, _, _elem)), \ - _elem, ) - -#define GMOCK_INTERNAL_GET_REF_SPEC(_Tuple) \ - GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_REF_SPEC_IF_REF, ~, _Tuple) - -#define GMOCK_INTERNAL_REF_SPEC_IF_REF(_i, _, _elem) \ - GMOCK_PP_IF(GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_REF(_i, _, _elem)), \ - GMOCK_PP_CAT(GMOCK_INTERNAL_UNPACK_, _elem), ) - -#define GMOCK_INTERNAL_GET_CALLTYPE(_Tuple) \ - GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_GET_CALLTYPE_IMPL, ~, _Tuple) - -#define GMOCK_INTERNAL_ASSERT_VALID_SPEC_ELEMENT(_i, _, _elem) \ - static_assert( \ - (GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_CONST(_i, _, _elem)) + \ - GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_OVERRIDE(_i, _, _elem)) + \ - GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_FINAL(_i, _, _elem)) + \ - GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_NOEXCEPT(_i, _, _elem)) + \ - GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_REF(_i, _, _elem)) + \ - GMOCK_INTERNAL_IS_CALLTYPE(_elem)) == 1, \ - GMOCK_PP_STRINGIZE( \ - _elem) " cannot be recognized as a valid specification modifier."); - -// Modifiers implementation. -#define GMOCK_INTERNAL_DETECT_CONST(_i, _, _elem) \ - GMOCK_PP_CAT(GMOCK_INTERNAL_DETECT_CONST_I_, _elem) - -#define GMOCK_INTERNAL_DETECT_CONST_I_const , - -#define GMOCK_INTERNAL_DETECT_OVERRIDE(_i, _, _elem) \ - GMOCK_PP_CAT(GMOCK_INTERNAL_DETECT_OVERRIDE_I_, _elem) - -#define GMOCK_INTERNAL_DETECT_OVERRIDE_I_override , - -#define GMOCK_INTERNAL_DETECT_FINAL(_i, _, _elem) \ - GMOCK_PP_CAT(GMOCK_INTERNAL_DETECT_FINAL_I_, _elem) - -#define GMOCK_INTERNAL_DETECT_FINAL_I_final , - -#define GMOCK_INTERNAL_DETECT_NOEXCEPT(_i, _, _elem) \ - GMOCK_PP_CAT(GMOCK_INTERNAL_DETECT_NOEXCEPT_I_, _elem) - -#define GMOCK_INTERNAL_DETECT_NOEXCEPT_I_noexcept , - -#define GMOCK_INTERNAL_DETECT_REF(_i, _, _elem) \ - GMOCK_PP_CAT(GMOCK_INTERNAL_DETECT_REF_I_, _elem) - -#define GMOCK_INTERNAL_DETECT_REF_I_ref , - -#define GMOCK_INTERNAL_UNPACK_ref(x) x - -#define GMOCK_INTERNAL_GET_CALLTYPE_IMPL(_i, _, _elem) \ - GMOCK_PP_IF(GMOCK_INTERNAL_IS_CALLTYPE(_elem), \ - GMOCK_INTERNAL_GET_VALUE_CALLTYPE, GMOCK_PP_EMPTY) \ - (_elem) - -// TODO(iserna): GMOCK_INTERNAL_IS_CALLTYPE and -// GMOCK_INTERNAL_GET_VALUE_CALLTYPE needed more expansions to work on windows -// maybe they can be simplified somehow. -#define GMOCK_INTERNAL_IS_CALLTYPE(_arg) \ - GMOCK_INTERNAL_IS_CALLTYPE_I( \ - GMOCK_PP_CAT(GMOCK_INTERNAL_IS_CALLTYPE_HELPER_, _arg)) -#define GMOCK_INTERNAL_IS_CALLTYPE_I(_arg) GMOCK_PP_IS_ENCLOSED_PARENS(_arg) - -#define GMOCK_INTERNAL_GET_VALUE_CALLTYPE(_arg) \ - GMOCK_INTERNAL_GET_VALUE_CALLTYPE_I( \ - GMOCK_PP_CAT(GMOCK_INTERNAL_IS_CALLTYPE_HELPER_, _arg)) -#define GMOCK_INTERNAL_GET_VALUE_CALLTYPE_I(_arg) \ - GMOCK_PP_IDENTITY _arg - -#define GMOCK_INTERNAL_IS_CALLTYPE_HELPER_Calltype - -// Note: The use of `identity_t` here allows _Ret to represent return types that -// would normally need to be specified in a different way. For example, a method -// returning a function pointer must be written as -// -// fn_ptr_return_t (*method(method_args_t...))(fn_ptr_args_t...) -// -// But we only support placing the return type at the beginning. To handle this, -// we wrap all calls in identity_t, so that a declaration will be expanded to -// -// identity_t method(method_args_t...) -// -// This allows us to work around the syntactic oddities of function/method -// types. -#define GMOCK_INTERNAL_SIGNATURE(_Ret, _Args) \ - ::testing::internal::identity_t( \ - GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_GET_TYPE, _, _Args)) - -#define GMOCK_INTERNAL_GET_TYPE(_i, _, _elem) \ - GMOCK_PP_COMMA_IF(_i) \ - GMOCK_PP_IF(GMOCK_PP_IS_BEGIN_PARENS(_elem), GMOCK_PP_REMOVE_PARENS, \ - GMOCK_PP_IDENTITY) \ - (_elem) - -#define GMOCK_INTERNAL_PARAMETER(_i, _Signature, _) \ - GMOCK_PP_COMMA_IF(_i) \ - GMOCK_INTERNAL_ARG_O(_i, GMOCK_PP_REMOVE_PARENS(_Signature)) \ - gmock_a##_i - -#define GMOCK_INTERNAL_FORWARD_ARG(_i, _Signature, _) \ - GMOCK_PP_COMMA_IF(_i) \ - ::std::forward(gmock_a##_i) - -#define GMOCK_INTERNAL_MATCHER_PARAMETER(_i, _Signature, _) \ - GMOCK_PP_COMMA_IF(_i) \ - GMOCK_INTERNAL_MATCHER_O(_i, GMOCK_PP_REMOVE_PARENS(_Signature)) \ - gmock_a##_i - -#define GMOCK_INTERNAL_MATCHER_ARGUMENT(_i, _1, _2) \ - GMOCK_PP_COMMA_IF(_i) \ - gmock_a##_i - -#define GMOCK_INTERNAL_A_MATCHER_ARGUMENT(_i, _Signature, _) \ - GMOCK_PP_COMMA_IF(_i) \ - ::testing::A() - -#define GMOCK_INTERNAL_ARG_O(_i, ...) \ - typename ::testing::internal::Function<__VA_ARGS__>::template Arg<_i>::type - -#define GMOCK_INTERNAL_MATCHER_O(_i, ...) \ - const ::testing::Matcher::template Arg<_i>::type>& - -#define MOCK_METHOD0(m, ...) GMOCK_INTERNAL_MOCK_METHODN(, , m, 0, __VA_ARGS__) -#define MOCK_METHOD1(m, ...) GMOCK_INTERNAL_MOCK_METHODN(, , m, 1, __VA_ARGS__) -#define MOCK_METHOD2(m, ...) GMOCK_INTERNAL_MOCK_METHODN(, , m, 2, __VA_ARGS__) -#define MOCK_METHOD3(m, ...) GMOCK_INTERNAL_MOCK_METHODN(, , m, 3, __VA_ARGS__) -#define MOCK_METHOD4(m, ...) GMOCK_INTERNAL_MOCK_METHODN(, , m, 4, __VA_ARGS__) -#define MOCK_METHOD5(m, ...) GMOCK_INTERNAL_MOCK_METHODN(, , m, 5, __VA_ARGS__) -#define MOCK_METHOD6(m, ...) GMOCK_INTERNAL_MOCK_METHODN(, , m, 6, __VA_ARGS__) -#define MOCK_METHOD7(m, ...) GMOCK_INTERNAL_MOCK_METHODN(, , m, 7, __VA_ARGS__) -#define MOCK_METHOD8(m, ...) GMOCK_INTERNAL_MOCK_METHODN(, , m, 8, __VA_ARGS__) -#define MOCK_METHOD9(m, ...) GMOCK_INTERNAL_MOCK_METHODN(, , m, 9, __VA_ARGS__) -#define MOCK_METHOD10(m, ...) \ - GMOCK_INTERNAL_MOCK_METHODN(, , m, 10, __VA_ARGS__) - -#define MOCK_CONST_METHOD0(m, ...) \ - GMOCK_INTERNAL_MOCK_METHODN(const, , m, 0, __VA_ARGS__) -#define MOCK_CONST_METHOD1(m, ...) \ - GMOCK_INTERNAL_MOCK_METHODN(const, , m, 1, __VA_ARGS__) -#define MOCK_CONST_METHOD2(m, ...) \ - GMOCK_INTERNAL_MOCK_METHODN(const, , m, 2, __VA_ARGS__) -#define MOCK_CONST_METHOD3(m, ...) \ - GMOCK_INTERNAL_MOCK_METHODN(const, , m, 3, __VA_ARGS__) -#define MOCK_CONST_METHOD4(m, ...) \ - GMOCK_INTERNAL_MOCK_METHODN(const, , m, 4, __VA_ARGS__) -#define MOCK_CONST_METHOD5(m, ...) \ - GMOCK_INTERNAL_MOCK_METHODN(const, , m, 5, __VA_ARGS__) -#define MOCK_CONST_METHOD6(m, ...) \ - GMOCK_INTERNAL_MOCK_METHODN(const, , m, 6, __VA_ARGS__) -#define MOCK_CONST_METHOD7(m, ...) \ - GMOCK_INTERNAL_MOCK_METHODN(const, , m, 7, __VA_ARGS__) -#define MOCK_CONST_METHOD8(m, ...) \ - GMOCK_INTERNAL_MOCK_METHODN(const, , m, 8, __VA_ARGS__) -#define MOCK_CONST_METHOD9(m, ...) \ - GMOCK_INTERNAL_MOCK_METHODN(const, , m, 9, __VA_ARGS__) -#define MOCK_CONST_METHOD10(m, ...) \ - GMOCK_INTERNAL_MOCK_METHODN(const, , m, 10, __VA_ARGS__) - -#define MOCK_METHOD0_T(m, ...) MOCK_METHOD0(m, __VA_ARGS__) -#define MOCK_METHOD1_T(m, ...) MOCK_METHOD1(m, __VA_ARGS__) -#define MOCK_METHOD2_T(m, ...) MOCK_METHOD2(m, __VA_ARGS__) -#define MOCK_METHOD3_T(m, ...) MOCK_METHOD3(m, __VA_ARGS__) -#define MOCK_METHOD4_T(m, ...) MOCK_METHOD4(m, __VA_ARGS__) -#define MOCK_METHOD5_T(m, ...) MOCK_METHOD5(m, __VA_ARGS__) -#define MOCK_METHOD6_T(m, ...) MOCK_METHOD6(m, __VA_ARGS__) -#define MOCK_METHOD7_T(m, ...) MOCK_METHOD7(m, __VA_ARGS__) -#define MOCK_METHOD8_T(m, ...) MOCK_METHOD8(m, __VA_ARGS__) -#define MOCK_METHOD9_T(m, ...) MOCK_METHOD9(m, __VA_ARGS__) -#define MOCK_METHOD10_T(m, ...) MOCK_METHOD10(m, __VA_ARGS__) - -#define MOCK_CONST_METHOD0_T(m, ...) MOCK_CONST_METHOD0(m, __VA_ARGS__) -#define MOCK_CONST_METHOD1_T(m, ...) MOCK_CONST_METHOD1(m, __VA_ARGS__) -#define MOCK_CONST_METHOD2_T(m, ...) MOCK_CONST_METHOD2(m, __VA_ARGS__) -#define MOCK_CONST_METHOD3_T(m, ...) MOCK_CONST_METHOD3(m, __VA_ARGS__) -#define MOCK_CONST_METHOD4_T(m, ...) MOCK_CONST_METHOD4(m, __VA_ARGS__) -#define MOCK_CONST_METHOD5_T(m, ...) MOCK_CONST_METHOD5(m, __VA_ARGS__) -#define MOCK_CONST_METHOD6_T(m, ...) MOCK_CONST_METHOD6(m, __VA_ARGS__) -#define MOCK_CONST_METHOD7_T(m, ...) MOCK_CONST_METHOD7(m, __VA_ARGS__) -#define MOCK_CONST_METHOD8_T(m, ...) MOCK_CONST_METHOD8(m, __VA_ARGS__) -#define MOCK_CONST_METHOD9_T(m, ...) MOCK_CONST_METHOD9(m, __VA_ARGS__) -#define MOCK_CONST_METHOD10_T(m, ...) MOCK_CONST_METHOD10(m, __VA_ARGS__) - -#define MOCK_METHOD0_WITH_CALLTYPE(ct, m, ...) \ - GMOCK_INTERNAL_MOCK_METHODN(, ct, m, 0, __VA_ARGS__) -#define MOCK_METHOD1_WITH_CALLTYPE(ct, m, ...) \ - GMOCK_INTERNAL_MOCK_METHODN(, ct, m, 1, __VA_ARGS__) -#define MOCK_METHOD2_WITH_CALLTYPE(ct, m, ...) \ - GMOCK_INTERNAL_MOCK_METHODN(, ct, m, 2, __VA_ARGS__) -#define MOCK_METHOD3_WITH_CALLTYPE(ct, m, ...) \ - GMOCK_INTERNAL_MOCK_METHODN(, ct, m, 3, __VA_ARGS__) -#define MOCK_METHOD4_WITH_CALLTYPE(ct, m, ...) \ - GMOCK_INTERNAL_MOCK_METHODN(, ct, m, 4, __VA_ARGS__) -#define MOCK_METHOD5_WITH_CALLTYPE(ct, m, ...) \ - GMOCK_INTERNAL_MOCK_METHODN(, ct, m, 5, __VA_ARGS__) -#define MOCK_METHOD6_WITH_CALLTYPE(ct, m, ...) \ - GMOCK_INTERNAL_MOCK_METHODN(, ct, m, 6, __VA_ARGS__) -#define MOCK_METHOD7_WITH_CALLTYPE(ct, m, ...) \ - GMOCK_INTERNAL_MOCK_METHODN(, ct, m, 7, __VA_ARGS__) -#define MOCK_METHOD8_WITH_CALLTYPE(ct, m, ...) \ - GMOCK_INTERNAL_MOCK_METHODN(, ct, m, 8, __VA_ARGS__) -#define MOCK_METHOD9_WITH_CALLTYPE(ct, m, ...) \ - GMOCK_INTERNAL_MOCK_METHODN(, ct, m, 9, __VA_ARGS__) -#define MOCK_METHOD10_WITH_CALLTYPE(ct, m, ...) \ - GMOCK_INTERNAL_MOCK_METHODN(, ct, m, 10, __VA_ARGS__) - -#define MOCK_CONST_METHOD0_WITH_CALLTYPE(ct, m, ...) \ - GMOCK_INTERNAL_MOCK_METHODN(const, ct, m, 0, __VA_ARGS__) -#define MOCK_CONST_METHOD1_WITH_CALLTYPE(ct, m, ...) \ - GMOCK_INTERNAL_MOCK_METHODN(const, ct, m, 1, __VA_ARGS__) -#define MOCK_CONST_METHOD2_WITH_CALLTYPE(ct, m, ...) \ - GMOCK_INTERNAL_MOCK_METHODN(const, ct, m, 2, __VA_ARGS__) -#define MOCK_CONST_METHOD3_WITH_CALLTYPE(ct, m, ...) \ - GMOCK_INTERNAL_MOCK_METHODN(const, ct, m, 3, __VA_ARGS__) -#define MOCK_CONST_METHOD4_WITH_CALLTYPE(ct, m, ...) \ - GMOCK_INTERNAL_MOCK_METHODN(const, ct, m, 4, __VA_ARGS__) -#define MOCK_CONST_METHOD5_WITH_CALLTYPE(ct, m, ...) \ - GMOCK_INTERNAL_MOCK_METHODN(const, ct, m, 5, __VA_ARGS__) -#define MOCK_CONST_METHOD6_WITH_CALLTYPE(ct, m, ...) \ - GMOCK_INTERNAL_MOCK_METHODN(const, ct, m, 6, __VA_ARGS__) -#define MOCK_CONST_METHOD7_WITH_CALLTYPE(ct, m, ...) \ - GMOCK_INTERNAL_MOCK_METHODN(const, ct, m, 7, __VA_ARGS__) -#define MOCK_CONST_METHOD8_WITH_CALLTYPE(ct, m, ...) \ - GMOCK_INTERNAL_MOCK_METHODN(const, ct, m, 8, __VA_ARGS__) -#define MOCK_CONST_METHOD9_WITH_CALLTYPE(ct, m, ...) \ - GMOCK_INTERNAL_MOCK_METHODN(const, ct, m, 9, __VA_ARGS__) -#define MOCK_CONST_METHOD10_WITH_CALLTYPE(ct, m, ...) \ - GMOCK_INTERNAL_MOCK_METHODN(const, ct, m, 10, __VA_ARGS__) - -#define MOCK_METHOD0_T_WITH_CALLTYPE(ct, m, ...) \ - MOCK_METHOD0_WITH_CALLTYPE(ct, m, __VA_ARGS__) -#define MOCK_METHOD1_T_WITH_CALLTYPE(ct, m, ...) \ - MOCK_METHOD1_WITH_CALLTYPE(ct, m, __VA_ARGS__) -#define MOCK_METHOD2_T_WITH_CALLTYPE(ct, m, ...) \ - MOCK_METHOD2_WITH_CALLTYPE(ct, m, __VA_ARGS__) -#define MOCK_METHOD3_T_WITH_CALLTYPE(ct, m, ...) \ - MOCK_METHOD3_WITH_CALLTYPE(ct, m, __VA_ARGS__) -#define MOCK_METHOD4_T_WITH_CALLTYPE(ct, m, ...) \ - MOCK_METHOD4_WITH_CALLTYPE(ct, m, __VA_ARGS__) -#define MOCK_METHOD5_T_WITH_CALLTYPE(ct, m, ...) \ - MOCK_METHOD5_WITH_CALLTYPE(ct, m, __VA_ARGS__) -#define MOCK_METHOD6_T_WITH_CALLTYPE(ct, m, ...) \ - MOCK_METHOD6_WITH_CALLTYPE(ct, m, __VA_ARGS__) -#define MOCK_METHOD7_T_WITH_CALLTYPE(ct, m, ...) \ - MOCK_METHOD7_WITH_CALLTYPE(ct, m, __VA_ARGS__) -#define MOCK_METHOD8_T_WITH_CALLTYPE(ct, m, ...) \ - MOCK_METHOD8_WITH_CALLTYPE(ct, m, __VA_ARGS__) -#define MOCK_METHOD9_T_WITH_CALLTYPE(ct, m, ...) \ - MOCK_METHOD9_WITH_CALLTYPE(ct, m, __VA_ARGS__) -#define MOCK_METHOD10_T_WITH_CALLTYPE(ct, m, ...) \ - MOCK_METHOD10_WITH_CALLTYPE(ct, m, __VA_ARGS__) - -#define MOCK_CONST_METHOD0_T_WITH_CALLTYPE(ct, m, ...) \ - MOCK_CONST_METHOD0_WITH_CALLTYPE(ct, m, __VA_ARGS__) -#define MOCK_CONST_METHOD1_T_WITH_CALLTYPE(ct, m, ...) \ - MOCK_CONST_METHOD1_WITH_CALLTYPE(ct, m, __VA_ARGS__) -#define MOCK_CONST_METHOD2_T_WITH_CALLTYPE(ct, m, ...) \ - MOCK_CONST_METHOD2_WITH_CALLTYPE(ct, m, __VA_ARGS__) -#define MOCK_CONST_METHOD3_T_WITH_CALLTYPE(ct, m, ...) \ - MOCK_CONST_METHOD3_WITH_CALLTYPE(ct, m, __VA_ARGS__) -#define MOCK_CONST_METHOD4_T_WITH_CALLTYPE(ct, m, ...) \ - MOCK_CONST_METHOD4_WITH_CALLTYPE(ct, m, __VA_ARGS__) -#define MOCK_CONST_METHOD5_T_WITH_CALLTYPE(ct, m, ...) \ - MOCK_CONST_METHOD5_WITH_CALLTYPE(ct, m, __VA_ARGS__) -#define MOCK_CONST_METHOD6_T_WITH_CALLTYPE(ct, m, ...) \ - MOCK_CONST_METHOD6_WITH_CALLTYPE(ct, m, __VA_ARGS__) -#define MOCK_CONST_METHOD7_T_WITH_CALLTYPE(ct, m, ...) \ - MOCK_CONST_METHOD7_WITH_CALLTYPE(ct, m, __VA_ARGS__) -#define MOCK_CONST_METHOD8_T_WITH_CALLTYPE(ct, m, ...) \ - MOCK_CONST_METHOD8_WITH_CALLTYPE(ct, m, __VA_ARGS__) -#define MOCK_CONST_METHOD9_T_WITH_CALLTYPE(ct, m, ...) \ - MOCK_CONST_METHOD9_WITH_CALLTYPE(ct, m, __VA_ARGS__) -#define MOCK_CONST_METHOD10_T_WITH_CALLTYPE(ct, m, ...) \ - MOCK_CONST_METHOD10_WITH_CALLTYPE(ct, m, __VA_ARGS__) - -#define GMOCK_INTERNAL_MOCK_METHODN(constness, ct, Method, args_num, ...) \ - GMOCK_INTERNAL_ASSERT_VALID_SIGNATURE( \ - args_num, ::testing::internal::identity_t<__VA_ARGS__>); \ - GMOCK_INTERNAL_MOCK_METHOD_IMPL( \ - args_num, Method, GMOCK_PP_NARG0(constness), 0, 0, , ct, , \ - (::testing::internal::identity_t<__VA_ARGS__>)) - -#define GMOCK_MOCKER_(arity, constness, Method) \ - GTEST_CONCAT_TOKEN_(gmock##constness##arity##_##Method##_, __LINE__) - -#endif // GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_FUNCTION_MOCKER_H_ diff --git a/test/GTest/googlemock/include/gmock/gmock-matchers.h b/test/GTest/googlemock/include/gmock/gmock-matchers.h deleted file mode 100644 index 86be9c1..0000000 --- a/test/GTest/googlemock/include/gmock/gmock-matchers.h +++ /dev/null @@ -1,5392 +0,0 @@ -// Copyright 2007, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - -// Google Mock - a framework for writing C++ mock classes. -// -// The MATCHER* family of macros can be used in a namespace scope to -// define custom matchers easily. -// -// Basic Usage -// =========== -// -// The syntax -// -// MATCHER(name, description_string) { statements; } -// -// defines a matcher with the given name that executes the statements, -// which must return a bool to indicate if the match succeeds. Inside -// the statements, you can refer to the value being matched by 'arg', -// and refer to its type by 'arg_type'. -// -// The description string documents what the matcher does, and is used -// to generate the failure message when the match fails. Since a -// MATCHER() is usually defined in a header file shared by multiple -// C++ source files, we require the description to be a C-string -// literal to avoid possible side effects. It can be empty, in which -// case we'll use the sequence of words in the matcher name as the -// description. -// -// For example: -// -// MATCHER(IsEven, "") { return (arg % 2) == 0; } -// -// allows you to write -// -// // Expects mock_foo.Bar(n) to be called where n is even. -// EXPECT_CALL(mock_foo, Bar(IsEven())); -// -// or, -// -// // Verifies that the value of some_expression is even. -// EXPECT_THAT(some_expression, IsEven()); -// -// If the above assertion fails, it will print something like: -// -// Value of: some_expression -// Expected: is even -// Actual: 7 -// -// where the description "is even" is automatically calculated from the -// matcher name IsEven. -// -// Argument Type -// ============= -// -// Note that the type of the value being matched (arg_type) is -// determined by the context in which you use the matcher and is -// supplied to you by the compiler, so you don't need to worry about -// declaring it (nor can you). This allows the matcher to be -// polymorphic. For example, IsEven() can be used to match any type -// where the value of "(arg % 2) == 0" can be implicitly converted to -// a bool. In the "Bar(IsEven())" example above, if method Bar() -// takes an int, 'arg_type' will be int; if it takes an unsigned long, -// 'arg_type' will be unsigned long; and so on. -// -// Parameterizing Matchers -// ======================= -// -// Sometimes you'll want to parameterize the matcher. For that you -// can use another macro: -// -// MATCHER_P(name, param_name, description_string) { statements; } -// -// For example: -// -// MATCHER_P(HasAbsoluteValue, value, "") { return abs(arg) == value; } -// -// will allow you to write: -// -// EXPECT_THAT(Blah("a"), HasAbsoluteValue(n)); -// -// which may lead to this message (assuming n is 10): -// -// Value of: Blah("a") -// Expected: has absolute value 10 -// Actual: -9 -// -// Note that both the matcher description and its parameter are -// printed, making the message human-friendly. -// -// In the matcher definition body, you can write 'foo_type' to -// reference the type of a parameter named 'foo'. For example, in the -// body of MATCHER_P(HasAbsoluteValue, value) above, you can write -// 'value_type' to refer to the type of 'value'. -// -// We also provide MATCHER_P2, MATCHER_P3, ..., up to MATCHER_P$n to -// support multi-parameter matchers. -// -// Describing Parameterized Matchers -// ================================= -// -// The last argument to MATCHER*() is a string-typed expression. The -// expression can reference all of the matcher's parameters and a -// special bool-typed variable named 'negation'. When 'negation' is -// false, the expression should evaluate to the matcher's description; -// otherwise it should evaluate to the description of the negation of -// the matcher. For example, -// -// using testing::PrintToString; -// -// MATCHER_P2(InClosedRange, low, hi, -// std::string(negation ? "is not" : "is") + " in range [" + -// PrintToString(low) + ", " + PrintToString(hi) + "]") { -// return low <= arg && arg <= hi; -// } -// ... -// EXPECT_THAT(3, InClosedRange(4, 6)); -// EXPECT_THAT(3, Not(InClosedRange(2, 4))); -// -// would generate two failures that contain the text: -// -// Expected: is in range [4, 6] -// ... -// Expected: is not in range [2, 4] -// -// If you specify "" as the description, the failure message will -// contain the sequence of words in the matcher name followed by the -// parameter values printed as a tuple. For example, -// -// MATCHER_P2(InClosedRange, low, hi, "") { ... } -// ... -// EXPECT_THAT(3, InClosedRange(4, 6)); -// EXPECT_THAT(3, Not(InClosedRange(2, 4))); -// -// would generate two failures that contain the text: -// -// Expected: in closed range (4, 6) -// ... -// Expected: not (in closed range (2, 4)) -// -// Types of Matcher Parameters -// =========================== -// -// For the purpose of typing, you can view -// -// MATCHER_Pk(Foo, p1, ..., pk, description_string) { ... } -// -// as shorthand for -// -// template -// FooMatcherPk -// Foo(p1_type p1, ..., pk_type pk) { ... } -// -// When you write Foo(v1, ..., vk), the compiler infers the types of -// the parameters v1, ..., and vk for you. If you are not happy with -// the result of the type inference, you can specify the types by -// explicitly instantiating the template, as in Foo(5, -// false). As said earlier, you don't get to (or need to) specify -// 'arg_type' as that's determined by the context in which the matcher -// is used. You can assign the result of expression Foo(p1, ..., pk) -// to a variable of type FooMatcherPk. This -// can be useful when composing matchers. -// -// While you can instantiate a matcher template with reference types, -// passing the parameters by pointer usually makes your code more -// readable. If, however, you still want to pass a parameter by -// reference, be aware that in the failure message generated by the -// matcher you will see the value of the referenced object but not its -// address. -// -// Explaining Match Results -// ======================== -// -// Sometimes the matcher description alone isn't enough to explain why -// the match has failed or succeeded. For example, when expecting a -// long string, it can be very helpful to also print the diff between -// the expected string and the actual one. To achieve that, you can -// optionally stream additional information to a special variable -// named result_listener, whose type is a pointer to class -// MatchResultListener: -// -// MATCHER_P(EqualsLongString, str, "") { -// if (arg == str) return true; -// -// *result_listener << "the difference: " -/// << DiffStrings(str, arg); -// return false; -// } -// -// Overloading Matchers -// ==================== -// -// You can overload matchers with different numbers of parameters: -// -// MATCHER_P(Blah, a, description_string1) { ... } -// MATCHER_P2(Blah, a, b, description_string2) { ... } -// -// Caveats -// ======= -// -// When defining a new matcher, you should also consider implementing -// MatcherInterface or using MakePolymorphicMatcher(). These -// approaches require more work than the MATCHER* macros, but also -// give you more control on the types of the value being matched and -// the matcher parameters, which may leads to better compiler error -// messages when the matcher is used wrong. They also allow -// overloading matchers based on parameter types (as opposed to just -// based on the number of parameters). -// -// MATCHER*() can only be used in a namespace scope as templates cannot be -// declared inside of a local class. -// -// More Information -// ================ -// -// To learn more about using these macros, please search for 'MATCHER' -// on -// https://github.com/google/googletest/blob/master/docs/gmock_cook_book.md -// -// This file also implements some commonly used argument matchers. More -// matchers can be defined by the user implementing the -// MatcherInterface interface if necessary. -// -// See googletest/include/gtest/gtest-matchers.h for the definition of class -// Matcher, class MatcherInterface, and others. - -// GOOGLETEST_CM0002 DO NOT DELETE - -#ifndef GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_ -#define GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_ - -#include -#include -#include -#include -#include -#include -#include // NOLINT -#include -#include -#include -#include -#include - -#include "gmock/internal/gmock-internal-utils.h" -#include "gmock/internal/gmock-port.h" -#include "gmock/internal/gmock-pp.h" -#include "gtest/gtest.h" - -// MSVC warning C5046 is new as of VS2017 version 15.8. -#if defined(_MSC_VER) && _MSC_VER >= 1915 -#define GMOCK_MAYBE_5046_ 5046 -#else -#define GMOCK_MAYBE_5046_ -#endif - -GTEST_DISABLE_MSC_WARNINGS_PUSH_( - 4251 GMOCK_MAYBE_5046_ /* class A needs to have dll-interface to be used by - clients of class B */ - /* Symbol involving type with internal linkage not defined */) - -namespace testing { - -// To implement a matcher Foo for type T, define: -// 1. a class FooMatcherImpl that implements the -// MatcherInterface interface, and -// 2. a factory function that creates a Matcher object from a -// FooMatcherImpl*. -// -// The two-level delegation design makes it possible to allow a user -// to write "v" instead of "Eq(v)" where a Matcher is expected, which -// is impossible if we pass matchers by pointers. It also eases -// ownership management as Matcher objects can now be copied like -// plain values. - -// A match result listener that stores the explanation in a string. -class StringMatchResultListener : public MatchResultListener { - public: - StringMatchResultListener() : MatchResultListener(&ss_) {} - - // Returns the explanation accumulated so far. - std::string str() const { return ss_.str(); } - - // Clears the explanation accumulated so far. - void Clear() { ss_.str(""); } - - private: - ::std::stringstream ss_; - - GTEST_DISALLOW_COPY_AND_ASSIGN_(StringMatchResultListener); -}; - -// Anything inside the 'internal' namespace IS INTERNAL IMPLEMENTATION -// and MUST NOT BE USED IN USER CODE!!! -namespace internal { - -// The MatcherCastImpl class template is a helper for implementing -// MatcherCast(). We need this helper in order to partially -// specialize the implementation of MatcherCast() (C++ allows -// class/struct templates to be partially specialized, but not -// function templates.). - -// This general version is used when MatcherCast()'s argument is a -// polymorphic matcher (i.e. something that can be converted to a -// Matcher but is not one yet; for example, Eq(value)) or a value (for -// example, "hello"). -template -class MatcherCastImpl { - public: - static Matcher Cast(const M& polymorphic_matcher_or_value) { - // M can be a polymorphic matcher, in which case we want to use - // its conversion operator to create Matcher. Or it can be a value - // that should be passed to the Matcher's constructor. - // - // We can't call Matcher(polymorphic_matcher_or_value) when M is a - // polymorphic matcher because it'll be ambiguous if T has an implicit - // constructor from M (this usually happens when T has an implicit - // constructor from any type). - // - // It won't work to unconditionally implicit_cast - // polymorphic_matcher_or_value to Matcher because it won't trigger - // a user-defined conversion from M to T if one exists (assuming M is - // a value). - return CastImpl(polymorphic_matcher_or_value, - std::is_convertible>{}, - std::is_convertible{}); - } - - private: - template - static Matcher CastImpl(const M& polymorphic_matcher_or_value, - std::true_type /* convertible_to_matcher */, - std::integral_constant) { - // M is implicitly convertible to Matcher, which means that either - // M is a polymorphic matcher or Matcher has an implicit constructor - // from M. In both cases using the implicit conversion will produce a - // matcher. - // - // Even if T has an implicit constructor from M, it won't be called because - // creating Matcher would require a chain of two user-defined conversions - // (first to create T from M and then to create Matcher from T). - return polymorphic_matcher_or_value; - } - - // M can't be implicitly converted to Matcher, so M isn't a polymorphic - // matcher. It's a value of a type implicitly convertible to T. Use direct - // initialization to create a matcher. - static Matcher CastImpl(const M& value, - std::false_type /* convertible_to_matcher */, - std::true_type /* convertible_to_T */) { - return Matcher(ImplicitCast_(value)); - } - - // M can't be implicitly converted to either Matcher or T. Attempt to use - // polymorphic matcher Eq(value) in this case. - // - // Note that we first attempt to perform an implicit cast on the value and - // only fall back to the polymorphic Eq() matcher afterwards because the - // latter calls bool operator==(const Lhs& lhs, const Rhs& rhs) in the end - // which might be undefined even when Rhs is implicitly convertible to Lhs - // (e.g. std::pair vs. std::pair). - // - // We don't define this method inline as we need the declaration of Eq(). - static Matcher CastImpl(const M& value, - std::false_type /* convertible_to_matcher */, - std::false_type /* convertible_to_T */); -}; - -// This more specialized version is used when MatcherCast()'s argument -// is already a Matcher. This only compiles when type T can be -// statically converted to type U. -template -class MatcherCastImpl > { - public: - static Matcher Cast(const Matcher& source_matcher) { - return Matcher(new Impl(source_matcher)); - } - - private: - class Impl : public MatcherInterface { - public: - explicit Impl(const Matcher& source_matcher) - : source_matcher_(source_matcher) {} - - // We delegate the matching logic to the source matcher. - bool MatchAndExplain(T x, MatchResultListener* listener) const override { - using FromType = typename std::remove_cv::type>::type>::type; - using ToType = typename std::remove_cv::type>::type>::type; - // Do not allow implicitly converting base*/& to derived*/&. - static_assert( - // Do not trigger if only one of them is a pointer. That implies a - // regular conversion and not a down_cast. - (std::is_pointer::type>::value != - std::is_pointer::type>::value) || - std::is_same::value || - !std::is_base_of::value, - "Can't implicitly convert from to "); - - // Do the cast to `U` explicitly if necessary. - // Otherwise, let implicit conversions do the trick. - using CastType = - typename std::conditional::value, - T&, U>::type; - - return source_matcher_.MatchAndExplain(static_cast(x), - listener); - } - - void DescribeTo(::std::ostream* os) const override { - source_matcher_.DescribeTo(os); - } - - void DescribeNegationTo(::std::ostream* os) const override { - source_matcher_.DescribeNegationTo(os); - } - - private: - const Matcher source_matcher_; - }; -}; - -// This even more specialized version is used for efficiently casting -// a matcher to its own type. -template -class MatcherCastImpl > { - public: - static Matcher Cast(const Matcher& matcher) { return matcher; } -}; - -// Template specialization for parameterless Matcher. -template -class MatcherBaseImpl { - public: - MatcherBaseImpl() = default; - - template - operator ::testing::Matcher() const { // NOLINT(runtime/explicit) - return ::testing::Matcher(new - typename Derived::template gmock_Impl()); - } -}; - -// Template specialization for Matcher with parameters. -template