-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add(test): add test for get_valid_confg_file_path, use gtest
- Loading branch information
Showing
5 changed files
with
167 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: GOOGLE_TEST | ||
on: [push] | ||
jobs: | ||
run-google-test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: build | ||
run: | | ||
cmake -S . -B build | ||
cmake --build build | ||
- name: run-all-test | ||
run: | | ||
cd build | ||
ctest || cat Testing/LastTest.log | ||
- uses: sarisia/actions-status-discord@v1 | ||
if: always() | ||
with: | ||
webhook: ${{ secrets.DISCORD_WEBHOOK }} | ||
status: ${{ job.status }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,8 +22,9 @@ | |
!Makefile | ||
!CPPLINT.cfg | ||
!webserv.drawio | ||
!CMakeLists.txt | ||
|
||
.idea | ||
.vscode | ||
.DS_Store | ||
CMakeLists.txt | ||
CMakeCache.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
cmake_minimum_required(VERSION 3.23) | ||
project(webserv) | ||
|
||
set(CMAKE_CXX_STANDARD 98) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
||
|
||
# google test ------------------------------------------------------------------ | ||
include(FetchContent) | ||
include(GoogleTest) | ||
|
||
FetchContent_Declare( | ||
googletest | ||
DOWNLOAD_EXTRACT_TIMESTAMP true | ||
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip | ||
) | ||
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) | ||
FetchContent_MakeAvailable(googletest) | ||
enable_testing() | ||
|
||
|
||
# when you .cpp or .hpp is added, add the following | ||
# include, webserv srcs, unit_test_srcs | ||
# includes --------------------------------------------------------------------- | ||
include_directories( | ||
includes | ||
) | ||
|
||
# webserv_srcs ----------------------------------------------------------------- | ||
set(webserv_srcs | ||
srcs/get_valid_config_file_path.cpp | ||
) | ||
|
||
#add_executable(webserv | ||
# srcs/main.cpp | ||
# ${webserv_srcs} | ||
#) | ||
|
||
# unit_test_srcs --------------------------------------------------------------- | ||
set (unit_test_srcs | ||
test/unit_test/is_valid_file_path/test_get_valid_config_file_path.cpp) | ||
|
||
add_executable(unit_test | ||
${webserv_srcs} | ||
${unit_test_srcs} | ||
) | ||
|
||
# test ------------------------------------------------------------------------- | ||
target_link_libraries( | ||
unit_test | ||
GTest::gtest_main | ||
) | ||
|
||
gtest_discover_tests(unit_test) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
test/unit_test/is_valid_file_path/test_get_valid_config_file_path.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#include "gtest/gtest.h" | ||
#include "webserv.hpp" | ||
|
||
TEST(TEST_get_valid_config_file_path, simple_test) { | ||
EXPECT_EQ("../test/unit_test/is_valid_file_path/files/file.conf", get_valid_config_file_path((char *)"../test/unit_test/is_valid_file_path/files/file.conf")); | ||
|
||
EXPECT_EQ("../test/unit_test/is_valid_file_path/files/file.CONF", get_valid_config_file_path((char *)"../test/unit_test/is_valid_file_path/files/file.CONF")); | ||
EXPECT_EQ("../test/unit_test/is_valid_file_path/files/file.Conf", get_valid_config_file_path((char *)"../test/unit_test/is_valid_file_path/files/file.Conf")); | ||
EXPECT_EQ("../test/unit_test/is_valid_file_path/files/file.conF", get_valid_config_file_path((char *)"../test/unit_test/is_valid_file_path/files/file.conF")); | ||
|
||
EXPECT_ANY_THROW(get_valid_config_file_path((char *)"../test/unit_test/is_valid_file_path/files/file")); | ||
EXPECT_ANY_THROW(get_valid_config_file_path((char *)"../test/unit_test/is_valid_file_path/files/nothing.conf")); | ||
EXPECT_ANY_THROW(get_valid_config_file_path((char *)"../test/unit_test/is_valid_file_path/files/nothing")); | ||
EXPECT_ANY_THROW(get_valid_config_file_path((char *)"../test/unit_test/is_valid_file_path/files/.conf")); | ||
EXPECT_ANY_THROW(get_valid_config_file_path((char *)"../test/unit_test/is_valid_file_path/files/conf")); | ||
|
||
EXPECT_EQ("../test/unit_test/is_valid_file_path/files/a.conf", get_valid_config_file_path((char *)"../test/unit_test/is_valid_file_path/files/a.conf")); | ||
EXPECT_ANY_THROW(get_valid_config_file_path((char *)"../test/unit_test/is_valid_file_path/files/ a.conf")); | ||
EXPECT_ANY_THROW(get_valid_config_file_path((char *)"../test/unit_test/is_valid_file_path/files/a.conf ")); | ||
EXPECT_ANY_THROW(get_valid_config_file_path((char *)"../test/unit_test/is_valid_file_path/files/ a.conf ")); | ||
EXPECT_ANY_THROW(get_valid_config_file_path((char *)"../test/unit_test/is_valid_file_path/files/X.conf")); | ||
|
||
EXPECT_EQ("../test/unit_test/is_valid_file_path/files/a.b.conf", get_valid_config_file_path((char *)"../test/unit_test/is_valid_file_path/files/a.b.conf")); | ||
EXPECT_ANY_THROW(get_valid_config_file_path((char *)"../test/unit_test/is_valid_file_path/files/a.conf.b")); | ||
EXPECT_ANY_THROW(get_valid_config_file_path((char *)"../test/unit_test/is_valid_file_path/files/conf.a")); | ||
EXPECT_ANY_THROW(get_valid_config_file_path((char *)"../test/unit_test/is_valid_file_path/files/conf.a.")); | ||
|
||
EXPECT_ANY_THROW(get_valid_config_file_path((char *)"")); | ||
EXPECT_ANY_THROW(get_valid_config_file_path((char *)".")); | ||
EXPECT_ANY_THROW(get_valid_config_file_path((char *)"..")); | ||
|
||
EXPECT_ANY_THROW(get_valid_config_file_path((char *)"../test/unit_test/is_valid_file_path/files/dir.conf")); | ||
} | ||
|
||
TEST(TEST_get_valid_config_file_path, test_dir_rwx) { | ||
EXPECT_EQ("../test/unit_test/is_valid_file_path/files/dir/file_rrr.conf", get_valid_config_file_path((char *)"../test/unit_test/is_valid_file_path/files/dir/file_rrr.conf")); | ||
EXPECT_EQ("../test/unit_test/is_valid_file_path/files/dir/file_rr-.conf", get_valid_config_file_path((char *)"../test/unit_test/is_valid_file_path/files/dir/file_rr-.conf")); | ||
EXPECT_EQ("../test/unit_test/is_valid_file_path/files/dir/file_r-r.conf", get_valid_config_file_path((char *)"../test/unit_test/is_valid_file_path/files/dir/file_r-r.conf")); | ||
// EXPECT_ANY_THROW(get_valid_config_file_path((char *)"../test/unit_test/is_valid_file_path/files/dir/file_-rr")); | ||
EXPECT_EQ("../test/unit_test/is_valid_file_path/files/dir/file_r--.conf", get_valid_config_file_path((char *)"../test/unit_test/is_valid_file_path/files/dir/file_rrr.conf")); | ||
// EXPECT_ANY_THROW(get_valid_config_file_path((char *)"../test/unit_test/is_valid_file_path/files/dir/file_-r-")); | ||
// EXPECT_ANY_THROW(get_valid_config_file_path((char *)"../test/unit_test/is_valid_file_path/files/dir/file_--r")); | ||
// EXPECT_ANY_THROW(get_valid_config_file_path((char *)"../test/unit_test/is_valid_file_path/files/dir/file_---")); | ||
EXPECT_ANY_THROW(get_valid_config_file_path((char *)"../test/unit_test/is_valid_file_path/files/dir/this_is_dir.conf")); | ||
|
||
EXPECT_ANY_THROW(get_valid_config_file_path((char *)"../test/unit_test/is_valid_file_path/files/dir/file_rrr")); | ||
EXPECT_ANY_THROW(get_valid_config_file_path((char *)"../test/unit_test/is_valid_file_path/files/dir/file_rrr")); | ||
EXPECT_ANY_THROW(get_valid_config_file_path((char *)"../test/unit_test/is_valid_file_path/files/dir/file_rr-")); | ||
// EXPECT_ANY_THROW(get_valid_config_file_path((char *)"../test/unit_test/is_valid_file_path/files/dir/file_-rr")); | ||
EXPECT_ANY_THROW(get_valid_config_file_path((char *)"../test/unit_test/is_valid_file_path/files/dir/file_r-r")); | ||
// EXPECT_ANY_THROW(get_valid_config_file_path((char *)"../test/unit_test/is_valid_file_path/files/dir/file_-r-")); | ||
// EXPECT_ANY_THROW(get_valid_config_file_path((char *)"../test/unit_test/is_valid_file_path/files/dir/file_--r")); | ||
// EXPECT_ANY_THROW(get_valid_config_file_path((char *)"../test/unit_test/is_valid_file_path/files/dir/file_---")); | ||
EXPECT_ANY_THROW(get_valid_config_file_path((char *)"../test/unit_test/is_valid_file_path/files/dir/file_r--")); | ||
|
||
EXPECT_ANY_THROW(get_valid_config_file_path((char *)"../test/unit_test/is_valid_file_path/files/dir/this_is_dir")); | ||
|
||
} | ||
|
||
TEST(TEST_get_valid_config_file_path, test_dir_rw) { | ||
EXPECT_ANY_THROW(get_valid_config_file_path((char *)"../test/unit_test/is_valid_file_path/files/no_x_dir/file_rrr.conf")); | ||
EXPECT_ANY_THROW(get_valid_config_file_path((char *)"../test/unit_test/is_valid_file_path/files/no_x_dir/file_rr-.conf")); | ||
EXPECT_ANY_THROW(get_valid_config_file_path((char *)"../test/unit_test/is_valid_file_path/files/no_x_dir/file_r-r.conf")); | ||
// EXPECT_ANY_THROW(get_valid_config_file_path((char *)"../test/unit_test/is_valid_file_path/files/no_x_dir/file_-rr.conf")); | ||
EXPECT_ANY_THROW(get_valid_config_file_path((char *)"../test/unit_test/is_valid_file_path/files/no_x_dir/file_r--.conf")); | ||
// EXPECT_ANY_THROW(get_valid_config_file_path((char *)"../test/unit_test/is_valid_file_path/files/no_x_dir/file_-r-.conf")); | ||
// EXPECT_ANY_THROW(get_valid_config_file_path((char *)"../test/unit_test/is_valid_file_path/files/no_x_dir/file_--r.conf")); | ||
// EXPECT_ANY_THROW(get_valid_config_file_path((char *)"../test/unit_test/is_valid_file_path/files/no_x_dir/file_---.conf")); | ||
EXPECT_ANY_THROW(get_valid_config_file_path((char *)"../test/unit_test/is_valid_file_path/files/no_x_dir/thid_is_dir.conf")); | ||
|
||
EXPECT_ANY_THROW(get_valid_config_file_path((char *)"../test/unit_test/is_valid_file_path/files/no_x_dir/file_rrr")); | ||
EXPECT_ANY_THROW(get_valid_config_file_path((char *)"../test/unit_test/is_valid_file_path/files/no_x_dir/file_rr-")); | ||
EXPECT_ANY_THROW(get_valid_config_file_path((char *)"../test/unit_test/is_valid_file_path/files/no_x_dir/file_r-r")); | ||
// EXPECT_ANY_THROW(get_valid_config_file_path((char *)"../test/unit_test/is_valid_file_path/files/no_x_dir/file_-rr")); | ||
EXPECT_ANY_THROW(get_valid_config_file_path((char *)"../test/unit_test/is_valid_file_path/files/no_x_dir/file_r--")); | ||
// EXPECT_ANY_THROW(get_valid_config_file_path((char *)"../test/unit_test/is_valid_file_path/files/no_x_dir/file_-r-")); | ||
// EXPECT_ANY_THROW(get_valid_config_file_path((char *)"../test/unit_test/is_valid_file_path/files/no_x_dir/file_--r")); | ||
// EXPECT_ANY_THROW(get_valid_config_file_path((char *)"../test/unit_test/is_valid_file_path/files/no_x_dir/file_---")); | ||
EXPECT_ANY_THROW(get_valid_config_file_path((char *)"../test/unit_test/is_valid_file_path/files/no_x_dir/thid_is_dir")); | ||
} |