mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11:42 +00:00
[wpilibc] Clean up integration tests (#3400)
The command and shuffleboard integration tests were removed because their unit tests counterparts already provide adequate coverage. Java already removed these.
This commit is contained in:
@@ -6,12 +6,10 @@
|
||||
|
||||
#include "frc/smartdashboard/SendableRegistry.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
MockActuatorSendable::MockActuatorSendable(wpi::StringRef name) {
|
||||
SendableRegistry::GetInstance().Add(this, name);
|
||||
MockActuatorSendable::MockActuatorSendable(std::string_view name) {
|
||||
frc::SendableRegistry::GetInstance().Add(this, name);
|
||||
}
|
||||
|
||||
void MockActuatorSendable::InitSendable(SendableBuilder& builder) {
|
||||
void MockActuatorSendable::InitSendable(frc::SendableBuilder& builder) {
|
||||
builder.SetActuator(true);
|
||||
}
|
||||
|
||||
@@ -4,44 +4,43 @@
|
||||
|
||||
#include "frc/shuffleboard/ShuffleboardInstance.h" // NOLINT(build/include_order)
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
#include <networktables/NetworkTableEntry.h>
|
||||
#include <networktables/NetworkTableInstance.h>
|
||||
|
||||
#include "frc/shuffleboard/ShuffleboardInstance.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "shuffleboard/MockActuatorSendable.h"
|
||||
|
||||
using namespace frc;
|
||||
class NTWrapper {
|
||||
public:
|
||||
NTWrapper() { inst = nt::NetworkTableInstance::Create(); }
|
||||
|
||||
class ShuffleboardInstanceTest : public testing::Test {
|
||||
void SetUp() override {
|
||||
m_ntInstance = nt::NetworkTableInstance::Create();
|
||||
m_shuffleboardInstance =
|
||||
std::make_unique<detail::ShuffleboardInstance>(m_ntInstance);
|
||||
}
|
||||
~NTWrapper() { nt::NetworkTableInstance::Destroy(inst); }
|
||||
|
||||
protected:
|
||||
nt::NetworkTableInstance m_ntInstance;
|
||||
std::unique_ptr<detail::ShuffleboardInstance> m_shuffleboardInstance;
|
||||
nt::NetworkTableInstance inst;
|
||||
};
|
||||
|
||||
TEST_F(ShuffleboardInstanceTest, PathFluent) {
|
||||
auto entry = m_shuffleboardInstance->GetTab("Tab Title")
|
||||
.GetLayout("List Layout", "List")
|
||||
TEST(ShuffleboardInstanceTest, PathFluent) {
|
||||
NTWrapper ntInst;
|
||||
frc::detail::ShuffleboardInstance shuffleboardInst{ntInst.inst};
|
||||
|
||||
auto entry = shuffleboardInst.GetTab("Tab Title")
|
||||
.GetLayout("List", "List Layout")
|
||||
.Add("Data", "string")
|
||||
.WithWidget("Text View")
|
||||
.GetEntry();
|
||||
|
||||
EXPECT_EQ("string", entry.GetString("")) << "Wrong entry value";
|
||||
EXPECT_EQ("/Shuffleboard/Tab Title/List Layout/Data", entry.GetName())
|
||||
EXPECT_EQ("/Shuffleboard/Tab Title/List/Data", entry.GetName())
|
||||
<< "Entry path generated incorrectly";
|
||||
}
|
||||
|
||||
TEST_F(ShuffleboardInstanceTest, NestedLayoutsFluent) {
|
||||
auto entry = m_shuffleboardInstance->GetTab("Tab")
|
||||
TEST(ShuffleboardInstanceTest, NestedLayoutsFluent) {
|
||||
NTWrapper ntInst;
|
||||
frc::detail::ShuffleboardInstance shuffleboardInst{ntInst.inst};
|
||||
|
||||
auto entry = shuffleboardInst.GetTab("Tab")
|
||||
.GetLayout("First", "List")
|
||||
.GetLayout("Second", "List")
|
||||
.GetLayout("Third", "List")
|
||||
@@ -55,13 +54,16 @@ TEST_F(ShuffleboardInstanceTest, NestedLayoutsFluent) {
|
||||
<< "Entry path generated incorrectly";
|
||||
}
|
||||
|
||||
TEST_F(ShuffleboardInstanceTest, NestedLayoutsOop) {
|
||||
ShuffleboardTab& tab = m_shuffleboardInstance->GetTab("Tab");
|
||||
ShuffleboardLayout& first = tab.GetLayout("First", "List");
|
||||
ShuffleboardLayout& second = first.GetLayout("Second", "List");
|
||||
ShuffleboardLayout& third = second.GetLayout("Third", "List");
|
||||
ShuffleboardLayout& fourth = third.GetLayout("Fourth", "List");
|
||||
SimpleWidget& widget = fourth.Add("Value", "string");
|
||||
TEST(ShuffleboardInstanceTest, NestedLayoutsOop) {
|
||||
NTWrapper ntInst;
|
||||
frc::detail::ShuffleboardInstance shuffleboardInst{ntInst.inst};
|
||||
|
||||
frc::ShuffleboardTab& tab = shuffleboardInst.GetTab("Tab");
|
||||
frc::ShuffleboardLayout& first = tab.GetLayout("First", "List");
|
||||
frc::ShuffleboardLayout& second = first.GetLayout("Second", "List");
|
||||
frc::ShuffleboardLayout& third = second.GetLayout("Third", "List");
|
||||
frc::ShuffleboardLayout& fourth = third.GetLayout("Fourth", "List");
|
||||
frc::SimpleWidget& widget = fourth.Add("Value", "string");
|
||||
auto entry = widget.GetEntry();
|
||||
|
||||
EXPECT_EQ("string", entry.GetString("")) << "Wrong entry value";
|
||||
@@ -70,23 +72,27 @@ TEST_F(ShuffleboardInstanceTest, NestedLayoutsOop) {
|
||||
<< "Entry path generated incorrectly";
|
||||
}
|
||||
|
||||
TEST_F(ShuffleboardInstanceTest, LayoutTypeIsSet) {
|
||||
std::string layoutType = "Type";
|
||||
m_shuffleboardInstance->GetTab("Tab").GetLayout("Title", layoutType);
|
||||
m_shuffleboardInstance->Update();
|
||||
nt::NetworkTableEntry entry = m_ntInstance.GetEntry(
|
||||
TEST(ShuffleboardInstanceTest, LayoutTypeIsSet) {
|
||||
NTWrapper ntInst;
|
||||
frc::detail::ShuffleboardInstance shuffleboardInst{ntInst.inst};
|
||||
|
||||
std::string_view layoutType = "Type";
|
||||
shuffleboardInst.GetTab("Tab").GetLayout("Title", layoutType);
|
||||
shuffleboardInst.Update();
|
||||
auto entry = ntInst.inst.GetEntry(
|
||||
"/Shuffleboard/.metadata/Tab/Title/PreferredComponent");
|
||||
EXPECT_EQ(layoutType, entry.GetString("Not Set")) << "Layout type not set";
|
||||
}
|
||||
|
||||
TEST_F(ShuffleboardInstanceTest, NestedActuatorWidgetsAreDisabled) {
|
||||
TEST(ShuffleboardInstanceTest, NestedActuatorWidgetsAreDisabled) {
|
||||
NTWrapper ntInst;
|
||||
frc::detail::ShuffleboardInstance shuffleboardInst{ntInst.inst};
|
||||
|
||||
MockActuatorSendable sendable("Actuator");
|
||||
m_shuffleboardInstance->GetTab("Tab")
|
||||
.GetLayout("Title", "Type")
|
||||
.Add(sendable);
|
||||
shuffleboardInst.GetTab("Tab").GetLayout("Title", "Layout").Add(sendable);
|
||||
auto controllableEntry =
|
||||
m_ntInstance.GetEntry("/Shuffleboard/Tab/Title/Actuator/.controllable");
|
||||
m_shuffleboardInstance->Update();
|
||||
ntInst.inst.GetEntry("/Shuffleboard/Tab/Title/Actuator/.controllable");
|
||||
shuffleboardInst.Update();
|
||||
|
||||
// Note: we use the unsafe `GetBoolean()` method because if the value is NOT
|
||||
// a boolean, or if it is not present, then something has clearly gone very,
|
||||
@@ -95,7 +101,7 @@ TEST_F(ShuffleboardInstanceTest, NestedActuatorWidgetsAreDisabled) {
|
||||
// Sanity check
|
||||
EXPECT_TRUE(controllable)
|
||||
<< "The nested actuator widget should be enabled by default";
|
||||
m_shuffleboardInstance->DisableActuatorWidgets();
|
||||
shuffleboardInst.DisableActuatorWidgets();
|
||||
controllable = controllableEntry.GetValue()->GetBoolean();
|
||||
EXPECT_FALSE(controllable)
|
||||
<< "The nested actuator widget should have been disabled";
|
||||
|
||||
@@ -3,15 +3,10 @@
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include "frc/shuffleboard/Shuffleboard.h"
|
||||
#include "frc/shuffleboard/ShuffleboardTab.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
class ShuffleboardTest : public testing::Test {};
|
||||
|
||||
TEST_F(ShuffleboardTest, TabObjectsCached) {
|
||||
ShuffleboardTab& tab1 = Shuffleboard::GetTab("testTabObjectsCached");
|
||||
ShuffleboardTab& tab2 = Shuffleboard::GetTab("testTabObjectsCached");
|
||||
TEST(ShuffleboardTest, TabObjectsCached) {
|
||||
auto& tab1 = frc::Shuffleboard::GetTab("testTabObjectsCached");
|
||||
auto& tab2 = frc::Shuffleboard::GetTab("testTabObjectsCached");
|
||||
EXPECT_EQ(&tab1, &tab2) << "Tab objects were not cached";
|
||||
}
|
||||
|
||||
@@ -11,52 +11,55 @@
|
||||
|
||||
using namespace frc;
|
||||
|
||||
class SuppliedValueWidgetTest : public testing::Test {
|
||||
void SetUp() override {
|
||||
m_ntInstance = nt::NetworkTableInstance::Create();
|
||||
m_instance = std::make_unique<detail::ShuffleboardInstance>(m_ntInstance);
|
||||
m_tab = &(m_instance->GetTab("Tab"));
|
||||
}
|
||||
class NTWrapper {
|
||||
public:
|
||||
NTWrapper() { inst = nt::NetworkTableInstance::Create(); }
|
||||
|
||||
~NTWrapper() { nt::NetworkTableInstance::Destroy(inst); }
|
||||
|
||||
nt::NetworkTableInstance inst;
|
||||
};
|
||||
|
||||
class SuppliedValueWidgetTest : public testing::Test {
|
||||
protected:
|
||||
nt::NetworkTableInstance m_ntInstance;
|
||||
ShuffleboardTab* m_tab;
|
||||
std::unique_ptr<detail::ShuffleboardInstance> m_instance;
|
||||
NTWrapper m_ntInst;
|
||||
frc::detail::ShuffleboardInstance m_shuffleboardInst{m_ntInst.inst};
|
||||
frc::ShuffleboardTab* m_tab = &(m_shuffleboardInst.GetTab("Tab"));
|
||||
};
|
||||
|
||||
TEST_F(SuppliedValueWidgetTest, AddString) {
|
||||
std::string str = "foo";
|
||||
m_tab->AddString("String", [&str]() { return str; });
|
||||
auto entry = m_ntInstance.GetEntry("/Shuffleboard/Tab/String");
|
||||
auto entry = m_ntInst.inst.GetEntry("/Shuffleboard/Tab/String");
|
||||
|
||||
m_instance->Update();
|
||||
m_shuffleboardInst.Update();
|
||||
EXPECT_EQ("foo", entry.GetValue()->GetString());
|
||||
}
|
||||
|
||||
TEST_F(SuppliedValueWidgetTest, AddNumber) {
|
||||
int num = 0;
|
||||
m_tab->AddNumber("Num", [&num]() { return ++num; });
|
||||
auto entry = m_ntInstance.GetEntry("/Shuffleboard/Tab/Num");
|
||||
auto entry = m_ntInst.inst.GetEntry("/Shuffleboard/Tab/Num");
|
||||
|
||||
m_instance->Update();
|
||||
m_shuffleboardInst.Update();
|
||||
EXPECT_FLOAT_EQ(1.0, entry.GetValue()->GetDouble());
|
||||
}
|
||||
|
||||
TEST_F(SuppliedValueWidgetTest, AddBoolean) {
|
||||
bool value = true;
|
||||
m_tab->AddBoolean("Bool", [&value]() { return value; });
|
||||
auto entry = m_ntInstance.GetEntry("/Shuffleboard/Tab/Bool");
|
||||
auto entry = m_ntInst.inst.GetEntry("/Shuffleboard/Tab/Bool");
|
||||
|
||||
m_instance->Update();
|
||||
m_shuffleboardInst.Update();
|
||||
EXPECT_EQ(true, entry.GetValue()->GetBoolean());
|
||||
}
|
||||
|
||||
TEST_F(SuppliedValueWidgetTest, AddStringArray) {
|
||||
std::vector<std::string> strings = {"foo", "bar"};
|
||||
m_tab->AddStringArray("Strings", [&strings]() { return strings; });
|
||||
auto entry = m_ntInstance.GetEntry("/Shuffleboard/Tab/Strings");
|
||||
auto entry = m_ntInst.inst.GetEntry("/Shuffleboard/Tab/Strings");
|
||||
|
||||
m_instance->Update();
|
||||
m_shuffleboardInst.Update();
|
||||
auto actual = entry.GetValue()->GetStringArray();
|
||||
|
||||
EXPECT_EQ(strings.size(), actual.size());
|
||||
@@ -68,9 +71,9 @@ TEST_F(SuppliedValueWidgetTest, AddStringArray) {
|
||||
TEST_F(SuppliedValueWidgetTest, AddNumberArray) {
|
||||
std::vector<double> nums = {0, 1, 2, 3};
|
||||
m_tab->AddNumberArray("Numbers", [&nums]() { return nums; });
|
||||
auto entry = m_ntInstance.GetEntry("/Shuffleboard/Tab/Numbers");
|
||||
auto entry = m_ntInst.inst.GetEntry("/Shuffleboard/Tab/Numbers");
|
||||
|
||||
m_instance->Update();
|
||||
m_shuffleboardInst.Update();
|
||||
auto actual = entry.GetValue()->GetDoubleArray();
|
||||
|
||||
EXPECT_EQ(nums.size(), actual.size());
|
||||
@@ -82,9 +85,9 @@ TEST_F(SuppliedValueWidgetTest, AddNumberArray) {
|
||||
TEST_F(SuppliedValueWidgetTest, AddBooleanArray) {
|
||||
std::vector<int> bools = {true, false};
|
||||
m_tab->AddBooleanArray("Booleans", [&bools]() { return bools; });
|
||||
auto entry = m_ntInstance.GetEntry("/Shuffleboard/Tab/Booleans");
|
||||
auto entry = m_ntInst.inst.GetEntry("/Shuffleboard/Tab/Booleans");
|
||||
|
||||
m_instance->Update();
|
||||
m_shuffleboardInst.Update();
|
||||
auto actual = entry.GetValue()->GetBooleanArray();
|
||||
|
||||
EXPECT_EQ(bools.size(), actual.size());
|
||||
@@ -96,9 +99,9 @@ TEST_F(SuppliedValueWidgetTest, AddBooleanArray) {
|
||||
TEST_F(SuppliedValueWidgetTest, AddRaw) {
|
||||
wpi::StringRef bytes = "\1\2\3";
|
||||
m_tab->AddRaw("Raw", [&bytes]() { return bytes; });
|
||||
auto entry = m_ntInstance.GetEntry("/Shuffleboard/Tab/Raw");
|
||||
auto entry = m_ntInst.inst.GetEntry("/Shuffleboard/Tab/Raw");
|
||||
|
||||
m_instance->Update();
|
||||
m_shuffleboardInst.Update();
|
||||
auto actual = entry.GetValue()->GetRaw();
|
||||
EXPECT_EQ(bytes, actual);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user