-
Notifications
You must be signed in to change notification settings - Fork 721
Added Common++ unit test project based on Gtest. #1507
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from 78 commits
5f02028
0687ddd
a004e3c
94a3b0e
be20d78
3395ac7
55fdf10
f447d9c
5b37a1f
12e4599
0f20bb9
a2718d8
e29190a
0f3f927
c8d04de
a67ebe7
a93a202
66d1937
aa92f72
d191cdb
bd8ecd9
70708fd
d45b54d
a9cd1b8
4803471
9e77c18
63a8fbe
d503bcd
bf9c3ca
f1baa83
6b50130
706fb4b
012df84
e875c0b
3a97325
f07b0bf
01b5cc1
ddf1d3a
c20e5d3
4b71919
2c461f0
db34edb
84d7d32
e9f7930
1b02e45
b09fc3c
977abb4
67c6a22
e5cf5fb
5076d29
4d0c5d1
d7046d7
3fa3dfd
fc0ea18
3c7285b
e45d5a9
6a88fd8
6fb03e8
6722666
453943a
21f16f5
4df5ddb
2b9a148
3b4d4d3
782623d
62d48da
58aa8ec
bf81cbe
5f8a763
37cb883
dae7b6b
40efcd5
b76fa62
247da32
463b632
bc03910
44f6094
3d57ddd
00e8f94
2b9a0ba
7a1d6d7
a3fddb8
68eaf83
36bea65
480f802
86a0e5b
a6cd38b
5d8e0af
ac73ed8
1e0df40
532678a
fc2873d
a0f005a
789a17e
9b4db8b
888a5a1
c98dff8
3f78f4d
5e477f1
29ff777
449c523
340e2af
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
cmake_minimum_required(VERSION 3.14) | ||
|
||
include(FetchContent) | ||
|
||
# TODO: This may have issues with brew as it doesn't allow the use of FetchContent. | ||
FetchContent_Declare(googletest GIT_REPOSITORY https://github.com/google/googletest.git GIT_TAG v1.16.0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah. Tbh, we could possibly have a copy of the lib in I am unsure if we could use the brew version since we need to use up to 1.16 as 1.17 (current newest) requires cpp17. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, putting it in Though I'm still not sure that we want to merge this PR. Having 2 test frameworks doesn't look like a good idea, and converting all of our tests to Gtest will be an extremely hard task There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did start another branch [1] off of this one, for the Packet++ tests, to see how it would go. You can take a look, if you want. The new project is It actually mostly involves trivial changes, like macro replacements.
The only non-trivial assertion so far has been The loading utilities needed a revamp, as I didn't want to use macros everywhere and the current ones had a limitation of always using the current working directory (has issues with out of source builds). For the majority of the cases the code: timeval time;
gettimeofday(&time, nullptr);
READ_FILE_AND_CREATE_PACKET(1, "PacketExamples/TcpPacketNoOptions.dat");
// rest of test case ended up being a one liner: // std::unique_ptr<RawPacket>
auto rawPacket1 = test::createPacketFromHexResource("PacketExamples/TcpPacketWithOptions3.dat", /* optional packet factory */, /* optional data loader */); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure how we'll be able to review these huge PRs... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah ok, that makes sense. I just wanted to confirm that we're not missing anything. So I guess we decided to go with Gtest? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @seladb I guess so. IMO, the first thing to do would be to disable building the tests in Unless anyone has any objections? @egecetin @clementperon @tigercosmos There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes I think that's a good idea 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Opened a PR to disable the tests in Also found a bug when examining the build. It placed the test executables inside the Our test projects don't really support out of source builds currently, so I plan on fixing this in the Gtest rework. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Homebrew has also been updated Homebrew/homebrew-core#233719 Conan needs no update as we already don't build tests there on install. |
||
|
||
if(WIN32) | ||
# Prevent overriding the parent project's compiler/linker settings. | ||
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) | ||
endif() | ||
|
||
FetchContent_MakeAvailable(googletest) | ||
|
||
add_executable( | ||
Common++Test | ||
"main.cpp" | ||
"Tests/GeneralUtilsTests.cpp" | ||
"Tests/IPAddressTests.cpp" | ||
"Tests/LoggerTests.cpp" | ||
"Tests/LRUListTests.cpp" | ||
"Tests/MacAddressTests.cpp" | ||
"Tests/ObjectPoolTests.cpp" | ||
"Tests/PointerVectorTests.cpp" | ||
"Tests/SystemUtilsTests.cpp" | ||
"Tests/TimespecTimevalTests.cpp" | ||
) | ||
|
||
target_link_libraries(Common++Test PRIVATE Common++ memplumber gtest gmock) | ||
|
||
target_include_directories(Common++Test PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/header>) | ||
target_precompile_headers(Common++Test PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/header/pch.h>) | ||
|
||
if(MSVC) | ||
# This executable requires getopt.h not available on VStudio | ||
target_link_libraries(Common++Test PRIVATE Getopt-for-Visual-Studio) | ||
endif() | ||
|
||
set_property(TARGET Common++Test PROPERTY RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/Bin") | ||
set_property(TARGET Common++Test PROPERTY RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_CURRENT_SOURCE_DIR}/Bin") | ||
set_property(TARGET Common++Test PROPERTY RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_CURRENT_SOURCE_DIR}/Bin") | ||
|
||
enable_testing() | ||
|
||
add_test(NAME Common++Test COMMAND $<TARGET_FILE:Common++Test> WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include "pch.h" | ||
|
||
#include <cstring> | ||
|
||
#include "GeneralUtils.h" | ||
|
||
namespace pcpp | ||
{ | ||
TEST(GeneralUtilsTests, byteArrayToHexString) | ||
{ | ||
std::array<uint8_t, 3> byteArr = { 0xaa, 0x2b, 0x10 }; | ||
EXPECT_EQ(byteArrayToHexString(byteArr.data(), byteArr.size()), "aa2b10"); | ||
}; | ||
|
||
TEST(GeneralUtilsTests, hexStringToByteArray) | ||
{ | ||
std::array<uint8_t, 3> resultByteArr = { 0 }; | ||
EXPECT_EQ(hexStringToByteArray("aa2b10", resultByteArr.data(), resultByteArr.size()), 3); | ||
EXPECT_EQ(resultByteArr, (std::array<uint8_t, 3>{ 0xaa, 0x2b, 0x10 })); | ||
}; | ||
|
||
TEST(GeneralUtilsTests, cross_platform_memmem) | ||
{ | ||
const char haystack[] = "Hello, World!"; | ||
const char needle[] = "World"; | ||
EXPECT_EQ(cross_platform_memmem(haystack, sizeof(haystack), needle, | ||
sizeof(needle) - 1 /* ignore the null terminator */), | ||
haystack + 7); | ||
}; | ||
|
||
TEST(GeneralUtilsTests, align) | ||
{ | ||
EXPECT_EQ(align<4>(3), 4); | ||
EXPECT_EQ(align<4>(4), 4); | ||
EXPECT_EQ(align<4>(5), 8); | ||
}; | ||
} // namespace pcpp |
Uh oh!
There was an error while loading. Please reload this page.