Skip to content

Commit

Permalink
Fix windows tests, apply warnings flags
Browse files Browse the repository at this point in the history
  • Loading branch information
rzblue committed Sep 19, 2023
1 parent 4d3bea7 commit 568299d
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 42 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ jobs:
run: python -m pip install jinja2

- name: configure
run: cmake -S . -B build -G "Ninja" ${{ matrix.flags }}
run: cmake -S . -B build -G "Ninja" -DCMAKE_BUILD_TYPE=RelWithDebInfo ${{ matrix.flags }}

- name: build
working-directory: build
run: cmake --build .
run: cmake --build . --parallel $(nproc)

- name: test
working-directory: build
Expand All @@ -75,8 +75,8 @@ jobs:
run: python -m pip install jinja2

- name: configure
run: cmake -S . -B build -G "Ninja Multi-Config" -DCMAKE_BUILD_TYPE=Release -DWITH_JAVA=OFF -DWITH_EXAMPLES=ON -DWITH_TESTS=OFF -DUSE_SYSTEM_FMTLIB=ON -DUSE_SYSTEM_LIBUV=ON -DUSE_SYSTEM_EIGEN=ON -DCMAKE_TOOLCHAIN_FILE=${{ runner.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_INSTALL_OPTIONS=--clean-after-build -DVCPKG_TARGET_TRIPLET=x64-windows-release -DVCPKG_HOST_TRIPLET=x64-windows-release
run: cmake -S . -B build -G "Ninja" -DCMAKE_BUILD_TYPE=RelWithDebInfo -DWITH_JAVA=OFF -DWITH_EXAMPLES=ON -DUSE_SYSTEM_FMTLIB=ON -DUSE_SYSTEM_LIBUV=ON -DUSE_SYSTEM_EIGEN=ON -DCMAKE_TOOLCHAIN_FILE=${{ runner.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_INSTALL_OPTIONS=--clean-after-build -DVCPKG_TARGET_TRIPLET=x64-windows-release -DVCPKG_HOST_TRIPLET=x64-windows-release

- name: build
working-directory: build
run: cmake --build . --parallel 1 --config Release
run: cmake --build . --parallel 1
1 change: 1 addition & 0 deletions glass/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ endif()

add_executable(glass ${glass_src} ${glass_resources_src} ${glass_rc} ${APP_ICON_MACOSX})
wpilib_link_macos_gui(glass)
wpilib_target_warnings(glass)
target_link_libraries(glass libglassnt libglass)

if (WIN32)
Expand Down
2 changes: 2 additions & 0 deletions googletest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ endif()

target_compile_features(gtest PUBLIC cxx_std_20)
target_compile_features(gtest_main PUBLIC cxx_std_20)
target_compile_features(gmock PUBLIC cxx_std_20)
target_compile_features(gmock_main PUBLIC cxx_std_20)
1 change: 1 addition & 0 deletions ntcore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ if (WITH_JAVA)
endif()

add_executable(ntcoredev src/dev/native/cpp/main.cpp)
wpilib_target_warnings(ntcoredev)
target_link_libraries(ntcoredev ntcore)

if (WITH_TESTS)
Expand Down
56 changes: 33 additions & 23 deletions ntcore/src/test/native/cpp/LocalStorageTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,11 @@ TEST_F(LocalStorageTest, PubUnpubPub) {
EXPECT_CALL(network, Publish(_, fooTopic, std::string_view{"foo"},
std::string_view{"boolean"}, wpi::json::object(),
IsDefaultPubSubOptions()));
EXPECT_CALL(logger, Call(NT_LOG_INFO, _, _,
"local subscribe to 'foo' disabled due to type "
"mismatch (wanted 'int', published as 'boolean')"));
EXPECT_CALL(logger,
Call(NT_LOG_INFO, _, _,
std::string_view{
"local subscribe to 'foo' disabled due to type "
"mismatch (wanted 'int', published as 'boolean')"}));
auto pub = storage.Publish(fooTopic, NT_BOOLEAN, "boolean", {}, {});

auto val = Value::MakeBoolean(true, 5);
Expand Down Expand Up @@ -298,9 +300,11 @@ TEST_F(LocalStorageTest, LocalPubConflict) {
IsDefaultPubSubOptions()));
auto pub1 = storage.Publish(fooTopic, NT_BOOLEAN, "boolean", {}, {});

EXPECT_CALL(logger, Call(NT_LOG_INFO, _, _,
"local publish to 'foo' disabled due to type "
"mismatch (wanted 'int', currently 'boolean')"));
EXPECT_CALL(
logger,
Call(NT_LOG_INFO, _, _,
std::string_view{"local publish to 'foo' disabled due to type "
"mismatch (wanted 'int', currently 'boolean')"}));
auto pub2 = storage.Publish(fooTopic, NT_INTEGER, "int", {}, {});

EXPECT_EQ(storage.GetTopicType(fooTopic), NT_BOOLEAN);
Expand Down Expand Up @@ -337,9 +341,11 @@ TEST_F(LocalStorageTest, LocalSubConflict) {

EXPECT_CALL(network, Subscribe(_, wpi::SpanEq({std::string{"foo"}}),
IsDefaultPubSubOptions()));
EXPECT_CALL(logger, Call(NT_LOG_INFO, _, _,
"local subscribe to 'foo' disabled due to type "
"mismatch (wanted 'int', published as 'boolean')"));
EXPECT_CALL(logger,
Call(NT_LOG_INFO, _, _,
std::string_view{
"local subscribe to 'foo' disabled due to type "
"mismatch (wanted 'int', published as 'boolean')"}));
storage.Subscribe(fooTopic, NT_INTEGER, "int", {});
}

Expand All @@ -350,9 +356,11 @@ TEST_F(LocalStorageTest, RemotePubConflict) {

storage.Publish(fooTopic, NT_BOOLEAN, "boolean", {}, {});

EXPECT_CALL(logger, Call(NT_LOG_INFO, _, _,
"network announce of 'foo' overriding local publish "
"(was 'boolean', now 'int')"));
EXPECT_CALL(logger,
Call(NT_LOG_INFO, _, _,
std::string_view{
"network announce of 'foo' overriding local publish "
"(was 'boolean', now 'int')"}));

storage.NetworkAnnounce("foo", "int", wpi::json::object(), {});

Expand Down Expand Up @@ -476,11 +484,10 @@ TEST_F(LocalStorageTest, SetValueEmptyUntypedEntry) {
}

TEST_F(LocalStorageTest, PublishUntyped) {
EXPECT_CALL(
logger,
Call(
NT_LOG_ERROR, _, _,
"cannot publish 'foo' with an unassigned type or empty type string"));
EXPECT_CALL(logger,
Call(NT_LOG_ERROR, _, _,
std::string_view{"cannot publish 'foo' with an unassigned "
"type or empty type string"}));

EXPECT_EQ(storage.Publish(fooTopic, NT_UNASSIGNED, "", {}, {}), 0u);
}
Expand Down Expand Up @@ -697,8 +704,9 @@ void LocalStorageNumberVariantsTest::CreateSubscriber(
void LocalStorageNumberVariantsTest::CreateSubscribers() {
EXPECT_CALL(logger,
Call(NT_LOG_INFO, _, _,
"local subscribe to 'foo' disabled due to type "
"mismatch (wanted 'boolean', published as 'double')"));
std::string_view{
"local subscribe to 'foo' disabled due to type "
"mismatch (wanted 'boolean', published as 'double')"}));
CreateSubscriber(&sub1, "subDouble", NT_DOUBLE, "double");
CreateSubscriber(&sub2, "subInteger", NT_INTEGER, "int");
CreateSubscriber(&sub3, "subFloat", NT_FLOAT, "float");
Expand All @@ -708,10 +716,12 @@ void LocalStorageNumberVariantsTest::CreateSubscribers() {
}

void LocalStorageNumberVariantsTest::CreateSubscribersArray() {
EXPECT_CALL(logger,
Call(NT_LOG_INFO, _, _,
"local subscribe to 'foo' disabled due to type "
"mismatch (wanted 'boolean[]', published as 'double[]')"));
EXPECT_CALL(
logger,
Call(NT_LOG_INFO, _, _,
std::string_view{
"local subscribe to 'foo' disabled due to type "
"mismatch (wanted 'boolean[]', published as 'double[]')"}));
CreateSubscriber(&sub1, "subDouble", NT_DOUBLE_ARRAY, "double[]");
CreateSubscriber(&sub2, "subInteger", NT_INTEGER_ARRAY, "int[]");
CreateSubscriber(&sub3, "subFloat", NT_FLOAT_ARRAY, "float[]");
Expand Down
4 changes: 2 additions & 2 deletions ntcore/src/test/native/cpp/TableListenerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ TEST_F(TableListenerTest, AddListener) {
MockTableEventListener listener;
table->AddListener(NT_EVENT_TOPIC | NT_EVENT_IMMEDIATE,
listener.AsStdFunction());
EXPECT_CALL(listener, Call(table.get(), "foovalue", _));
EXPECT_CALL(listener, Call(table.get(), std::string_view{"foovalue"}, _));
PublishTopics();
EXPECT_TRUE(m_inst.WaitForListenerQueue(1.0));
}
Expand All @@ -55,7 +55,7 @@ TEST_F(TableListenerTest, AddSubTableListener) {
auto table = m_inst.GetTable("/foo");
MockSubTableListener listener;
table->AddSubTableListener(listener.AsStdFunction());
EXPECT_CALL(listener, Call(table.get(), "bar", _));
EXPECT_CALL(listener, Call(table.get(), std::string_view{"bar"}, _));
PublishTopics();
EXPECT_TRUE(m_inst.WaitForListenerQueue(1.0));
}
32 changes: 19 additions & 13 deletions ntcore/src/test/native/cpp/net/ServerImplTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ using ::testing::Field;
using ::testing::IsEmpty;
using ::testing::Property;
using ::testing::Return;
using ::testing::StrEq;

using MockSetPeriodicFunc = ::testing::MockFunction<void(uint32_t repeatMs)>;
using MockConnected3Func =
Expand Down Expand Up @@ -127,12 +128,15 @@ TEST_F(ServerImplTest, PublishLocal) {
NT_Topic topicHandle3 = nt::Handle{0, 3, nt::Handle::kTopic};
{
::testing::InSequence seq;
EXPECT_CALL(local, NetworkAnnounce("test", "double", wpi::json::object(),
pubHandle));
EXPECT_CALL(local, NetworkAnnounce("test2", "double", wpi::json::object(),
pubHandle2));
EXPECT_CALL(local, NetworkAnnounce("test3", "double", wpi::json::object(),
pubHandle3));
EXPECT_CALL(local, NetworkAnnounce(std::string_view{"test"},
std::string_view{"double"},
wpi::json::object(), pubHandle));
EXPECT_CALL(local, NetworkAnnounce(std::string_view{"test2"},
std::string_view{"double"},
wpi::json::object(), pubHandle2));
EXPECT_CALL(local, NetworkAnnounce(std::string_view{"test3"},
std::string_view{"double"},
wpi::json::object(), pubHandle3));
}

{
Expand All @@ -158,15 +162,15 @@ TEST_F(ServerImplTest, PublishLocal) {
"test", 3, "double", std::nullopt, wpi::json::object()}});
smsgs.emplace_back(net::ServerMessage{net::AnnounceMsg{
"test2", 8, "double", std::nullopt, wpi::json::object()}});
EXPECT_CALL(wire, Text(EncodeText(smsgs))); // SendControl()
EXPECT_CALL(wire, Text(StrEq(EncodeText(smsgs)))); // SendControl()
}
EXPECT_CALL(wire, Flush()); // SendControl()
EXPECT_CALL(wire, Ready()).WillOnce(Return(true)); // SendControl()
{
std::vector<net::ServerMessage> smsgs;
smsgs.emplace_back(net::ServerMessage{net::AnnounceMsg{
"test3", 11, "double", std::nullopt, wpi::json::object()}});
EXPECT_CALL(wire, Text(EncodeText(smsgs))); // SendControl()
EXPECT_CALL(wire, Text(StrEq(EncodeText(smsgs)))); // SendControl()
}
EXPECT_CALL(wire, Flush()); // SendControl()
}
Expand Down Expand Up @@ -207,8 +211,9 @@ TEST_F(ServerImplTest, ClientSubTopicOnlyThenValue) {
server.SetLocal(&local);
NT_Publisher pubHandle = nt::Handle{0, 1, nt::Handle::kPublisher};
NT_Topic topicHandle = nt::Handle{0, 1, nt::Handle::kTopic};
EXPECT_CALL(
local, NetworkAnnounce("test", "double", wpi::json::object(), pubHandle));
EXPECT_CALL(local, NetworkAnnounce(std::string_view{"test"},
std::string_view{"double"},
wpi::json::object(), pubHandle));

{
std::vector<net::ClientMessage> msgs;
Expand All @@ -231,7 +236,7 @@ TEST_F(ServerImplTest, ClientSubTopicOnlyThenValue) {
std::vector<net::ServerMessage> smsgs;
smsgs.emplace_back(net::ServerMessage{net::AnnounceMsg{
"test", 3, "double", std::nullopt, wpi::json::object()}});
EXPECT_CALL(wire, Text(EncodeText(smsgs))); // SendValues()
EXPECT_CALL(wire, Text(StrEq(EncodeText(smsgs)))); // SendValues()
}
EXPECT_CALL(wire, Flush()); // SendValues()
EXPECT_CALL(setPeriodic, Call(100)); // ClientSubscribe()
Expand Down Expand Up @@ -289,8 +294,9 @@ TEST_F(ServerImplTest, ZeroTimestampNegativeTime) {
Value value = Value::MakeDouble(5, -10);
{
::testing::InSequence seq;
EXPECT_CALL(local, NetworkAnnounce("test", "double", wpi::json::object(),
pubHandle))
EXPECT_CALL(local, NetworkAnnounce(std::string_view{"test"},
std::string_view{"double"},
wpi::json::object(), pubHandle))
.WillOnce(Return(topicHandle));
EXPECT_CALL(local, NetworkSetValue(topicHandle, defaultValue));
EXPECT_CALL(local, NetworkSetValue(topicHandle, value));
Expand Down
1 change: 1 addition & 0 deletions outlineviewer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ endif()

add_executable(outlineviewer ${outlineviewer_src} ${outlineviewer_resources_src} ${outlineviewer_rc} ${APP_ICON_MACOSX})
wpilib_link_macos_gui(outlineviewer)
wpilib_target_warnings(outlineviewer)
target_link_libraries(outlineviewer libglassnt libglass)

if (WIN32)
Expand Down
1 change: 1 addition & 0 deletions wpigui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ endif()

add_executable(wpiguidev src/dev/native/cpp/main.cpp)
wpilib_link_macos_gui(wpiguidev)
wpilib_target_warnings(wpiguidev)
target_link_libraries(wpiguidev wpigui)

install(TARGETS wpigui EXPORT wpigui)
Expand Down

0 comments on commit 568299d

Please sign in to comment.