diff --git a/.clang-format b/.clang-format index 45ccffe..ec2cf0e 100644 --- a/.clang-format +++ b/.clang-format @@ -6,4 +6,5 @@ UseTab: Never DerivePointerAlignment: false PointerAlignment: Right ColumnLimit: 80 +IncludeBlocks: Preserve ... diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d87b12b..9d4d720 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,13 +4,13 @@ on: [push] jobs: clang_check: - runs-on: ubuntu-18.04 + runs-on: ubuntu-22.04 steps: - name: Set-up repository uses: actions/checkout@v2 - name: Install environment run: | - sudo apt install -y clang-format-8 + sudo apt install -y clang-format - name: Run clang formatter run: | ./tool/format.sh @@ -32,35 +32,38 @@ jobs: mkdir build cd build cmake -DOPENSSL_ROOT_DIR="$(ls -rd -- /usr/local/Cellar/openssl@1.1/* | head -n 1)" -DCMAKE_INSTALL_PREFIX=/usr/local -DBUILD_TESTING=ON -DBUILD_TESTING_INTEGRATION=ON -DC_WARNINGS_AS_ERRORS=ON -DCPP_WARNINGS_AS_ERRORS=ON .. - make + cmake --build . --parallel ctest -E "example|integration" sudo make install build_and_test_linux: strategy: matrix: - platform: [ubuntu-18.04] + platform: [ubuntu-20.04, ubuntu-22.04] + mgversion: ["2.0.0", "2.3.0"] + packages: ["gcc g++ clang"] + gcc-postfix: [""] + clang-postfix: [""] + include: + - {platform: [ubuntu-18.04], mgversion: "2.0.0", packages: "gcc-8 g++-8 clang-8 clang++-8", gcc-postfix: "-8", clang-postfix: "-8"} runs-on: ${{ matrix.platform }} - env: - MG_VERSION: "1.4.0" steps: - name: Set-up repository uses: actions/checkout@v1 - name: Install environment run: | - sudo apt install -y gcc-8 g++-8 clang-8 clang++-8 - + sudo apt install -y ${{ matrix.packages }} - name: Cache Memgraph Docker image id: cache-memgraph-docker uses: actions/cache@v1 with: path: ~/memgraph - key: cache-memgraph-v${{ env.MG_VERSION }}-docker-image + key: cache-memgraph-v${{ matrix.mgversion }}-docker-image - name: Download Memgraph Docker image if: steps.cache-memgraph-docker.outputs.cache-hit != 'true' run: | mkdir ~/memgraph - curl -L https://memgraph.com/download/memgraph/v${MG_VERSION}/docker/memgraph-${MG_VERSION}-community-docker.tar.gz > ~/memgraph/memgraph-docker.tar.gz + curl -L https://memgraph.com/download/memgraph/v${{ matrix.mgversion }}/docker/memgraph-${{ matrix.mgversion }}-docker.tar.gz > ~/memgraph/memgraph-docker.tar.gz - name: Load and run Memgraph Docker image run: | docker load -i ~/memgraph/memgraph-docker.tar.gz @@ -69,15 +72,15 @@ jobs: - name: Build with gcc, test and install mgclient run: | mkdir build-gcc && cd build-gcc - cmake -DCMAKE_C_COMPILER=gcc-8 -DCMAKE_CXX_COMPILER=g++-8 -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON -DBUILD_TESTING_INTEGRATION=ON -DC_WARNINGS_AS_ERRORS=ON -DCPP_WARNINGS_AS_ERRORS=ON .. - make + cmake -DCMAKE_C_COMPILER=gcc${{ matrix.gcc-postfix }} -DCMAKE_CXX_COMPILER=g++${{ matrix.gcc-postfix }} -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON -DBUILD_TESTING_INTEGRATION=ON -DC_WARNINGS_AS_ERRORS=ON -DCPP_WARNINGS_AS_ERRORS=ON .. + cmake --build . --parallel ctest --output-on-failure sudo make install - name: Build with clang, test and install mgclient run: | mkdir build-clang && cd build-clang - cmake -DCMAKE_C_COMPILER=clang-8 -DCMAKE_CXX_COMPILER=clang++-8 -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON -DBUILD_TESTING_INTEGRATION=ON -DC_WARNINGS_AS_ERRORS=ON -DCPP_WARNINGS_AS_ERRORS=ON .. - make + cmake -DCMAKE_C_COMPILER=clang${{ matrix.clang-postfix }} -DCMAKE_CXX_COMPILER=clang++${{ matrix.clang-postfix }} -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON -DBUILD_TESTING_INTEGRATION=ON -DC_WARNINGS_AS_ERRORS=ON -DCPP_WARNINGS_AS_ERRORS=ON .. + cmake --build . --parallel ctest --output-on-failure sudo make install @@ -126,7 +129,7 @@ jobs: mkdir build cd build cmake .. -G "MinGW Makefiles" -DBUILD_TESTING=ON -DBUILD_TESTING_INTEGRATION=ON -DC_WARNINGS_AS_ERRORS=ON -DCPP_WARNINGS_AS_ERRORS=ON - cmake --build . + cmake --build . --parallel ctest --verbose -R "allocator|value|example_basic|integration_basic" build_and_test_linux_wasm: @@ -140,7 +143,7 @@ jobs: - name: Build with clang run: | - mkdir build + mkdir build cd build cmake .. -DCMAKE_BUILD_TYPE=Release -DC_WARNINGS_AS_ERRORS=ON -DWASM=ON make diff --git a/src/apple/mgsocket.c b/src/apple/mgsocket.c index 529ef46..0805879 100644 --- a/src/apple/mgsocket.c +++ b/src/apple/mgsocket.c @@ -12,10 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "mgsocket.h" + #include #include "mgcommon.h" -#include "mgsocket.h" #define MG_RETRY_ON_EINTR(expression) \ __extension__({ \ diff --git a/src/mgsession.c b/src/mgsession.c index f2043e7..69b0d88 100644 --- a/src/mgsession.c +++ b/src/mgsession.c @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "mgsession.h" + #include #include #include @@ -26,7 +28,6 @@ #include "mgcommon.h" #include "mgconstants.h" -#include "mgsession.h" #include "mgtransport.h" int mg_session_status(const mg_session *session) { diff --git a/src/mgtransport.h b/src/mgtransport.h index 615b0f5..34a9778 100644 --- a/src/mgtransport.h +++ b/src/mgtransport.h @@ -19,15 +19,15 @@ extern "C" { #endif +#include +#include + #ifndef __EMSCRIPTEN__ #include #include #include #endif -#include -#include - #include "mgallocator.h" #include "mgcommon.h" diff --git a/src/windows/mgsocket.c b/src/windows/mgsocket.c index 353eda0..95da20b 100644 --- a/src/windows/mgsocket.c +++ b/src/windows/mgsocket.c @@ -12,10 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include - #include "mgsocket.h" +#include + // Please refer to https://docs.microsoft.com/en-us/windows/win32/api/winsock2/ // for more details about Windows system calls. diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 80755f4..9621821 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -54,9 +54,11 @@ set_target_properties(${GTEST_MAIN_LIBRARY} PROPERTIES INTERFACE_LINK_LIBRARIES "${CMAKE_THREAD_LIBS_INIT}") add_dependencies(${GTEST_MAIN_LIBRARY} gtest-proj) +set(TESTS_ROOT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) + macro(add_gtest target_name target_path) add_executable(${target_name} ${target_path}) - target_include_directories(${target_name} PRIVATE ${GTEST_INCLUDE_DIRS} "${PROJECT_SOURCE_DIR}/src") + target_include_directories(${target_name} PRIVATE ${GTEST_INCLUDE_DIRS} "${PROJECT_SOURCE_DIR}/src" "${TESTS_ROOT_DIRECTORY}") target_link_libraries(${target_name} mgclient-static mgclient_cpp gtest gtest-main project_cpp_warnings) if (ENABLE_COVERAGE) diff --git a/tests/bolt-testdata.hpp b/tests/bolt-testdata.hpp index 2105c87..c7f67e9 100644 --- a/tests/bolt-testdata.hpp +++ b/tests/bolt-testdata.hpp @@ -321,10 +321,10 @@ std::vector UnboundRelationshipTestCases() { std::vector PathTestCases() { std::vector inputs; { - mg_node *nodes[] = {mg_node_make(1, 0, NULL, mg_map_make_empty(0)), - mg_node_make(2, 0, NULL, mg_map_make_empty(0)), - mg_node_make(3, 0, NULL, mg_map_make_empty(0)), - mg_node_make(4, 0, NULL, mg_map_make_empty(0))}; + mg_node *nodes[] = {mg_node_make(1, 0, nullptr, mg_map_make_empty(0)), + mg_node_make(2, 0, nullptr, mg_map_make_empty(0)), + mg_node_make(3, 0, nullptr, mg_map_make_empty(0)), + mg_node_make(4, 0, nullptr, mg_map_make_empty(0))}; mg_unbound_relationship *relationships[] = { mg_unbound_relationship_make(12, mg_string_make("EDGE"), mg_map_make_empty(0)), diff --git a/tests/client.cpp b/tests/client.cpp index 9cdc813..50e15b8 100644 --- a/tests/client.cpp +++ b/tests/client.cpp @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include #include #include @@ -23,6 +22,8 @@ #include "mgcommon.h" #include "mgsession.h" #include "mgsocket.h" + +#include "gmock_wrapper.h" #include "test-common.hpp" using namespace std::string_literals; @@ -99,8 +100,8 @@ int __wrap_mg_secure_transport_init(int sockfd, const char *cert, ttransport->send = mg_raw_transport_send; ttransport->recv = mg_raw_transport_recv; ttransport->destroy = test_transport_destroy; - ttransport->suspend_until_ready_to_read = NULL; - ttransport->suspend_until_ready_to_write = NULL; + ttransport->suspend_until_ready_to_read = nullptr; + ttransport->suspend_until_ready_to_write = nullptr; ttransport->peer_pubkey_type = "rsaEncryption"; ttransport->peer_pubkey_fp = TEST_KEY_FP; *transport = (mg_secure_transport *)ttransport; @@ -188,7 +189,7 @@ class ConnectTest : public ::testing::Test { void RunServer(const std::function &server_func) { server_thread = std::thread([this, server_func] { - int sockfd = accept(ss, NULL, NULL); + int sockfd = accept(ss, nullptr, nullptr); if (sockfd < 0) { abort(); } @@ -792,9 +793,9 @@ void RunTest::ProtocolViolation(int version) { }); session->version = version; - ASSERT_EQ( - mg_session_run(session, "MATCH (n) RETURN n", NULL, NULL, NULL, NULL), - MG_ERROR_PROTOCOL_VIOLATION); + ASSERT_EQ(mg_session_run(session, "MATCH (n) RETURN n", nullptr, nullptr, + nullptr, nullptr), + MG_ERROR_PROTOCOL_VIOLATION); ASSERT_EQ(mg_session_status(session), MG_SESSION_BAD); mg_session_destroy(session); StopServer(); @@ -863,9 +864,9 @@ void RunTest::InvalidStatement(int version) { mg_session_destroy(session); }); session->version = version; - ASSERT_EQ( - mg_session_run(session, "MATCH (n) RETURN m", NULL, NULL, NULL, NULL), - MG_ERROR_CLIENT_ERROR); + ASSERT_EQ(mg_session_run(session, "MATCH (n) RETURN m", nullptr, nullptr, + nullptr, nullptr), + MG_ERROR_CLIENT_ERROR); ASSERT_THAT(std::string(mg_session_error(session)), HasSubstr("Unbound variable: m")); ASSERT_EQ(mg_session_status(session), MG_SESSION_READY); @@ -943,12 +944,13 @@ void RunTest::OkNoResults(int version) { session->version = version; - ASSERT_EQ( - mg_session_run(session, "MATCH (n) RETURN n", NULL, NULL, NULL, NULL), 0); + ASSERT_EQ(mg_session_run(session, "MATCH (n) RETURN n", nullptr, nullptr, + nullptr, nullptr), + 0); ASSERT_EQ(mg_session_status(session), MG_SESSION_EXECUTING); mg_result *result; - ASSERT_EQ(mg_session_pull(session, NULL), 0); + ASSERT_EQ(mg_session_pull(session, nullptr), 0); ASSERT_EQ(mg_session_fetch(session, &result), 0); ASSERT_TRUE(CheckColumns(result, std::vector{"n"})); ASSERT_TRUE(CheckSummary(result, 0.01)); @@ -1045,7 +1047,7 @@ void RunTest::MultipleQueries(int version) { for (int i = 0; i < 10; ++i) { ASSERT_EQ(mg_session_run(session, ("RETURN " + std::to_string(i) + " AS n").c_str(), - NULL, NULL, NULL, NULL), + nullptr, nullptr, nullptr, nullptr), 0); ASSERT_EQ(mg_session_status(session), MG_SESSION_EXECUTING); @@ -1053,7 +1055,7 @@ void RunTest::MultipleQueries(int version) { mg_result *result; // Check result. - ASSERT_EQ(mg_session_pull(session, NULL), 0); + ASSERT_EQ(mg_session_pull(session, nullptr), 0); ASSERT_EQ(mg_session_status(session), MG_SESSION_FETCHING); ASSERT_EQ(mg_session_fetch(session, &result), 1); ASSERT_EQ(mg_session_status(session), MG_SESSION_FETCHING); @@ -1162,13 +1164,13 @@ void RunTest::OkWithResults(int version) { ASSERT_EQ( mg_session_run(session, "UNWIND [1, 2, 3] AS n RETURN n, n + 5 AS m", - NULL, NULL, NULL, NULL), + nullptr, nullptr, nullptr, nullptr), 0); ASSERT_EQ(mg_session_status(session), MG_SESSION_EXECUTING); mg_result *result; - ASSERT_EQ(mg_session_pull(session, NULL), 0); + ASSERT_EQ(mg_session_pull(session, nullptr), 0); ASSERT_EQ(mg_session_status(session), MG_SESSION_FETCHING); // Check results. @@ -1293,14 +1295,14 @@ void RunTest::QueryRuntimeError(int version) { session->version = version; - ASSERT_EQ(mg_session_run(session, "MATCH (n) RETURN size(n.prop)", NULL, NULL, - NULL, NULL), + ASSERT_EQ(mg_session_run(session, "MATCH (n) RETURN size(n.prop)", nullptr, + nullptr, nullptr, nullptr), 0); ASSERT_EQ(mg_session_status(session), MG_SESSION_EXECUTING); mg_result *result; - ASSERT_EQ(mg_session_pull(session, NULL), 0); + ASSERT_EQ(mg_session_pull(session, nullptr), 0); ASSERT_EQ(mg_session_fetch(session, &result), MG_ERROR_CLIENT_ERROR); ASSERT_EQ(mg_session_status(session), MG_SESSION_READY); @@ -1378,14 +1380,14 @@ void RunTest::QueryDatabaseError(int version) { session->version = version; - ASSERT_EQ(mg_session_run(session, "MATCH (n) RETURN size(n.prop)", NULL, NULL, - NULL, NULL), + ASSERT_EQ(mg_session_run(session, "MATCH (n) RETURN size(n.prop)", nullptr, + nullptr, nullptr, nullptr), 0); ASSERT_EQ(mg_session_status(session), MG_SESSION_EXECUTING); mg_result *result; - ASSERT_EQ(mg_session_pull(session, NULL), 0); + ASSERT_EQ(mg_session_pull(session, nullptr), 0); ASSERT_NE(mg_session_fetch(session, &result), 0); ASSERT_EQ(mg_session_status(session), MG_SESSION_BAD); @@ -1481,14 +1483,14 @@ void RunTest::RunWithParams(int version) { mg_map *params = mg_map_make_empty(1); mg_map_insert_unsafe(params, "param", mg_value_make_integer(42)); - ASSERT_EQ(mg_session_run(session, "WITH $param AS x RETURN x", params, NULL, - NULL, NULL), + ASSERT_EQ(mg_session_run(session, "WITH $param AS x RETURN x", params, + nullptr, nullptr, nullptr), 0); mg_map_destroy(params); mg_result *result; { - ASSERT_EQ(mg_session_pull(session, NULL), 0); + ASSERT_EQ(mg_session_pull(session, nullptr), 0); ASSERT_EQ(mg_session_fetch(session, &result), 1); ASSERT_TRUE(CheckColumns(result, std::vector{"x"})); const mg_list *row = mg_result_row(result); @@ -1636,7 +1638,7 @@ TEST_F(RunTest, MultipleResultPull) { ASSERT_EQ( mg_session_run(session, "UNWIND [1, 2, 3] AS n RETURN n, n + 5 AS m", - NULL, NULL, NULL, NULL), + nullptr, nullptr, nullptr, nullptr), 0); ASSERT_EQ(mg_session_status(session), MG_SESSION_EXECUTING); @@ -1791,17 +1793,18 @@ TEST_F(RunTest, TransactionBasic) { session->version = 4; - ASSERT_EQ(mg_session_begin_transaction(session, NULL), 0); + ASSERT_EQ(mg_session_begin_transaction(session, nullptr), 0); - ASSERT_EQ( - mg_session_run(session, "MATCH (n) RETURN n", NULL, NULL, NULL, NULL), 0); + ASSERT_EQ(mg_session_run(session, "MATCH (n) RETURN n", nullptr, nullptr, + nullptr, nullptr), + 0); ASSERT_EQ(mg_session_status(session), MG_SESSION_EXECUTING); mg_result *result; ASSERT_EQ(mg_session_rollback_transaction(session, &result), MG_ERROR_BAD_CALL); - ASSERT_EQ(mg_session_pull(session, NULL), 0); + ASSERT_EQ(mg_session_pull(session, nullptr), 0); ASSERT_EQ(mg_session_fetch(session, &result), 0); ASSERT_TRUE(CheckColumns(result, std::vector{"n"})); ASSERT_TRUE(CheckSummary(result, 0.01)); @@ -1994,18 +1997,18 @@ TEST_F(RunTest, TransactionWithMultipleRuns) { session->version = 4; - ASSERT_EQ(mg_session_begin_transaction(session, NULL), 0); + ASSERT_EQ(mg_session_begin_transaction(session, nullptr), 0); ASSERT_EQ(mg_session_status(session), MG_SESSION_READY); int64_t r1_qid; ASSERT_EQ(mg_session_run(session, "UNWIND [1, 2] AS n RETURN n, n + 5 AS m", - NULL, NULL, NULL, &r1_qid), + nullptr, nullptr, nullptr, &r1_qid), 0); ASSERT_EQ(mg_session_status(session), MG_SESSION_EXECUTING); int64_t r2_qid; ASSERT_EQ(mg_session_run(session, "UNWIND [3, 4] AS n RETURN n, n + 5 AS m", - NULL, NULL, NULL, &r2_qid), + nullptr, nullptr, nullptr, &r2_qid), 0); ASSERT_EQ(mg_session_status(session), MG_SESSION_EXECUTING); @@ -2054,7 +2057,7 @@ TEST_F(RunTest, TransactionWithMultipleRuns) { // Send third RUN int64_t r3_qid; ASSERT_EQ(mg_session_run(session, "UNWIND [5, 6] AS n RETURN n, n + 5 AS m", - NULL, NULL, NULL, &r3_qid), + nullptr, nullptr, nullptr, &r3_qid), 0); ASSERT_EQ(mg_session_status(session), MG_SESSION_EXECUTING); diff --git a/tests/decoder.cpp b/tests/decoder.cpp index 4317036..c89de0b 100644 --- a/tests/decoder.cpp +++ b/tests/decoder.cpp @@ -12,12 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include - #include #include #include +#include + #include "mgclient.h" #include "mgcommon.h" #include "mgsession.h" diff --git a/tests/encoder.cpp b/tests/encoder.cpp index 816ed5b..b3261ca 100644 --- a/tests/encoder.cpp +++ b/tests/encoder.cpp @@ -12,11 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include - #include #include +#include + #include "mgclient.h" #include "mgcommon.h" #include "mgconstants.h" diff --git a/tests/gmock_wrapper.h b/tests/gmock_wrapper.h new file mode 100644 index 0000000..935770a --- /dev/null +++ b/tests/gmock_wrapper.h @@ -0,0 +1,15 @@ +#pragma once + +// On older versions of clang/gcc deprecated-copy might not exist + +#pragma GCC diagnostic push + +#if (defined(__clang_major__) && __clang_major__ >= 10 && \ + !defined(__APPLE__)) || \ + (defined(__GNUC__) && __GNUC__ >= 10) +#pragma GCC diagnostic ignored "-Wdeprecated-copy" +#endif + +#include + +#pragma GCC diagnostic pop diff --git a/tests/integration/basic_c.cpp b/tests/integration/basic_c.cpp index 8334bff..16205bb 100644 --- a/tests/integration/basic_c.cpp +++ b/tests/integration/basic_c.cpp @@ -12,11 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include #include #include "mgclient.h" +#include "gmock_wrapper.h" + template T GetEnvOrDefault(const std::string &value_name, const T &default_value) { const char *char_value = std::getenv(value_name.c_str()); @@ -110,16 +111,17 @@ class MemgraphConnection : public ::testing::Test { mg_result *result; const char *delete_all_query = "MATCH (n) DETACH DELETE n"; - ASSERT_EQ(mg_session_run(session, delete_all_query, NULL, NULL, NULL, NULL), + ASSERT_EQ(mg_session_run(session, delete_all_query, nullptr, nullptr, + nullptr, nullptr), 0); - ASSERT_EQ(mg_session_pull(session, NULL), 0); + ASSERT_EQ(mg_session_pull(session, nullptr), 0); ASSERT_EQ(mg_session_fetch(session, &result), 0); ASSERT_EQ(mg_session_fetch(session, &result), MG_ERROR_BAD_CALL); } }; TEST_F(MemgraphConnection, InsertAndRetriveFromMemegraph) { - ASSERT_EQ(mg_session_begin_transaction(session, NULL), 0); + ASSERT_EQ(mg_session_begin_transaction(session, nullptr), 0); mg_result *result; int status = 0, rows = 0; const char *create_query = @@ -128,13 +130,17 @@ TEST_F(MemgraphConnection, InsertAndRetriveFromMemegraph) { "'test2', is_deleted: false})"; const char *get_query = "MATCH (n)-[r]->(m) RETURN n, r, m"; - ASSERT_EQ(mg_session_run(session, create_query, NULL, NULL, NULL, NULL), 0); - ASSERT_EQ(mg_session_pull(session, NULL), 0); + ASSERT_EQ( + mg_session_run(session, create_query, nullptr, nullptr, nullptr, nullptr), + 0); + ASSERT_EQ(mg_session_pull(session, nullptr), 0); ASSERT_EQ(mg_session_fetch(session, &result), 0); ASSERT_EQ(mg_session_fetch(session, &result), MG_ERROR_BAD_CALL); - ASSERT_EQ(mg_session_run(session, get_query, NULL, NULL, NULL, NULL), 0); - ASSERT_EQ(mg_session_pull(session, NULL), 0); + ASSERT_EQ( + mg_session_run(session, get_query, nullptr, nullptr, nullptr, nullptr), + 0); + ASSERT_EQ(mg_session_pull(session, nullptr), 0); while ((status = mg_session_fetch(session, &result)) == 1) { const mg_list *mg_columns = mg_result_columns(result); const mg_list *mg_row = mg_result_row(result); @@ -190,9 +196,9 @@ TEST_F(MemgraphConnection, InsertAndRetriveFromMemegraph) { "CREATE (n:ValuesTest {int: 1, string:'Name', " "float: 2.3, bool: True, " "list: [1, 2], map: {key: 'value'}}) RETURN n;", - NULL, NULL, NULL, NULL), + nullptr, nullptr, nullptr, nullptr), 0); - ASSERT_EQ(mg_session_pull(session, NULL), 0); + ASSERT_EQ(mg_session_pull(session, nullptr), 0); mg_result *result; ASSERT_EQ(mg_session_fetch(session, &result), 1); const mg_list *mg_columns = mg_result_columns(result); diff --git a/tests/integration/basic_cpp.cpp b/tests/integration/basic_cpp.cpp index 8a8d714..b5ff5a8 100644 --- a/tests/integration/basic_cpp.cpp +++ b/tests/integration/basic_cpp.cpp @@ -12,11 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include #include #include "mgclient.hpp" +#include "gmock_wrapper.h" + template T GetEnvOrDefault(const std::string &value_name, const T &default_value) { const char *char_value = std::getenv(value_name.c_str()); diff --git a/tests/test-common.hpp b/tests/test-common.hpp index b1da228..5053502 100644 --- a/tests/test-common.hpp +++ b/tests/test-common.hpp @@ -62,7 +62,7 @@ struct tracking_allocator { void *tracking_allocator_malloc(mg_allocator *allocator, size_t size) { std::set *allocated = &((tracking_allocator *)allocator)->allocated; void *buf = malloc(size); - if (buf != NULL) { + if (buf != nullptr) { allocated->insert(buf); } return buf; @@ -72,14 +72,14 @@ void *tracking_allocator_realloc(mg_allocator *allocator, void *buf, size_t size) { std::set *allocated = &((tracking_allocator *)allocator)->allocated; assert(size > 0); - if (buf == NULL) { + if (buf == nullptr) { return tracking_allocator_malloc(allocator, size); } else { auto it = allocated->find(buf); assert(it != allocated->end()); allocated->erase(it); void *new_buf = realloc(buf, size); - if (new_buf != NULL) { + if (new_buf != nullptr) { allocated->insert(new_buf); } return new_buf; @@ -88,7 +88,7 @@ void *tracking_allocator_realloc(mg_allocator *allocator, void *buf, void tracking_allocator_free(mg_allocator *allocator, void *buf) { std::set *allocated = &((tracking_allocator *)allocator)->allocated; - if (buf != NULL) { + if (buf != nullptr) { auto it = allocated->find(buf); assert(it != allocated->end()); allocated->erase(it); diff --git a/tests/transport.cpp b/tests/transport.cpp index 42c54eb..6b8cbe0 100644 --- a/tests/transport.cpp +++ b/tests/transport.cpp @@ -14,15 +14,15 @@ // TODO(mtomic): Maybe add test for raw transport. -#include -#include - #include #include #include #include #include +#include +#include + #if MGCLIENT_ON_WINDOWS // NOTE: // https://stackoverflow.com/questions/49504648/x509-name-macro-in-c-wont-compile @@ -37,17 +37,22 @@ extern "C" { #include "mgtransport.h" } +#include "gmock_wrapper.h" #include "test-common.hpp" std::pair MakeCertAndKey(const char *name) { +#if OPENSSL_VERSION_NUMBER < 0x30000000L RSA *rsa = RSA_new(); BIGNUM *bne = BN_new(); BN_set_word(bne, RSA_F4); - RSA_generate_key_ex(rsa, 2048, bne, NULL); + RSA_generate_key_ex(rsa, 2048, bne, nullptr); BN_free(bne); EVP_PKEY *pkey = EVP_PKEY_new(); EVP_PKEY_assign_RSA(pkey, rsa); +#else + EVP_PKEY *pkey = EVP_RSA_gen(2048); +#endif X509 *x509 = X509_new(); ASN1_INTEGER_set(X509_get_serialNumber(x509), 1); @@ -78,6 +83,7 @@ class SecureTransportTest : public ::testing::Test { #endif } virtual void SetUp() override { + OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS, nullptr); int sv[2]; ASSERT_EQ(mg_socket_pair(AF_UNIX, SOCK_STREAM, 0, sv), 0); sc = sv[0]; @@ -115,7 +121,8 @@ class SecureTransportTest : public ::testing::Test { client_key_path = std::filesystem::temp_directory_path() / "client.key"; BIO *key_file = BIO_new_file(client_key_path.string().c_str(), "w"); - PEM_write_bio_PrivateKey(key_file, client_key, NULL, NULL, 0, NULL, NULL); + PEM_write_bio_PrivateKey(key_file, client_key, nullptr, nullptr, 0, nullptr, + nullptr); BIO_free(key_file); X509_free(client_cert); @@ -180,7 +187,7 @@ TEST_F(SecureTransportTest, NoCertificate) { }); mg_transport *transport; - ASSERT_EQ(mg_secure_transport_init(sc, NULL, NULL, + ASSERT_EQ(mg_secure_transport_init(sc, nullptr, nullptr, (mg_secure_transport **)&transport, (mg_allocator *)&allocator), 0); @@ -211,7 +218,7 @@ TEST_F(SecureTransportTest, WithCertificate) { X509_STORE_add_cert(store, ca_cert); } SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT, - NULL); + nullptr); ASSERT_TRUE(ctx); SSL *ssl = SSL_new(ctx); diff --git a/tests/value.cpp b/tests/value.cpp index 720e69e..05e52f4 100644 --- a/tests/value.cpp +++ b/tests/value.cpp @@ -424,10 +424,10 @@ TEST(Value, Path) { EXPECT_EQ(mg_path_relationship_reversed_at(path, 6), -1); EXPECT_EQ(mg_path_relationship_reversed_at(path, 83291038), -1); }; - mg_node *nodes[] = {mg_node_make(1, 0, NULL, mg_map_make_empty(0)), - mg_node_make(2, 0, NULL, mg_map_make_empty(0)), - mg_node_make(3, 0, NULL, mg_map_make_empty(0)), - mg_node_make(4, 0, NULL, mg_map_make_empty(0))}; + mg_node *nodes[] = {mg_node_make(1, 0, nullptr, mg_map_make_empty(0)), + mg_node_make(2, 0, nullptr, mg_map_make_empty(0)), + mg_node_make(3, 0, nullptr, mg_map_make_empty(0)), + mg_node_make(4, 0, nullptr, mg_map_make_empty(0))}; mg_unbound_relationship *relationships[] = { mg_unbound_relationship_make(12, mg_string_make("EDGE"), mg_map_make_empty(0)), diff --git a/tool/format.sh b/tool/format.sh index 296ef9b..0037ddf 100755 --- a/tool/format.sh +++ b/tool/format.sh @@ -7,7 +7,7 @@ cd "$DIR/.." ALL_FILES_TO_CHECK=$(find . -type f -regex ".*\.\(cpp\|hpp\|c\|h\)$" -print | paste -sd " ") for file in ${ALL_FILES_TO_CHECK}; do - clang-format-8 -i -verbose "${file}" + clang-format -i -verbose "${file}" done changes="$(git diff)" if [[ ! -z "${changes}" ]]; then