mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
StorageTest: Add fixture classes, add GetEntryInfo test.
This commit is contained in:
@@ -13,17 +13,30 @@ namespace nt {
|
||||
|
||||
class StorageTest : public ::testing::Test {
|
||||
public:
|
||||
void PopulateTrue() {
|
||||
storage.SetEntryTypeValue("foo", Value::MakeBoolean(true));
|
||||
ASSERT_EQ(1u, updates().size());
|
||||
updates().pop();
|
||||
}
|
||||
|
||||
Storage::EntriesMap& entries() { return storage.m_entries; }
|
||||
Storage::UpdateQueue& updates() { return storage.updates(); }
|
||||
Storage storage;
|
||||
};
|
||||
|
||||
class StorageTestPopulateOne : public StorageTest {
|
||||
public:
|
||||
StorageTestPopulateOne() {
|
||||
storage.SetEntryTypeValue("foo", Value::MakeBoolean(true));
|
||||
while (!updates().empty()) updates().pop();
|
||||
}
|
||||
};
|
||||
|
||||
class StorageTestPopulated : public StorageTest {
|
||||
public:
|
||||
StorageTestPopulated() {
|
||||
storage.SetEntryTypeValue("foo", Value::MakeBoolean(true));
|
||||
storage.SetEntryTypeValue("foo2", Value::MakeDouble(0.0));
|
||||
storage.SetEntryTypeValue("bar", Value::MakeDouble(1.0));
|
||||
storage.SetEntryTypeValue("bar2", Value::MakeBoolean(false));
|
||||
while (!updates().empty()) updates().pop();
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(StorageTest, Construct) {
|
||||
ASSERT_TRUE(entries().empty());
|
||||
ASSERT_TRUE(updates().empty());
|
||||
@@ -78,8 +91,7 @@ TEST_F(StorageTest, SetEntryTypeValueAssignNew) {
|
||||
EXPECT_EQ(Storage::Update::kAssign, update.kind);
|
||||
}
|
||||
|
||||
TEST_F(StorageTest, SetEntryTypeValueAssignTypeChange) {
|
||||
PopulateTrue();
|
||||
TEST_F(StorageTestPopulateOne, SetEntryTypeValueAssignTypeChange) {
|
||||
// update with different type results in assignment message
|
||||
auto value = Value::MakeDouble(0.0);
|
||||
storage.SetEntryTypeValue("foo", value);
|
||||
@@ -91,8 +103,7 @@ TEST_F(StorageTest, SetEntryTypeValueAssignTypeChange) {
|
||||
EXPECT_EQ(Storage::Update::kAssign, update.kind);
|
||||
}
|
||||
|
||||
TEST_F(StorageTest, SetEntryTypeValueEqualValue) {
|
||||
PopulateTrue();
|
||||
TEST_F(StorageTestPopulateOne, SetEntryTypeValueEqualValue) {
|
||||
// update with same type and same value: change value contents but no update
|
||||
// message is issued (minimizing bandwidth usage)
|
||||
auto value = Value::MakeBoolean(true);
|
||||
@@ -102,8 +113,7 @@ TEST_F(StorageTest, SetEntryTypeValueEqualValue) {
|
||||
ASSERT_TRUE(updates().empty());
|
||||
}
|
||||
|
||||
TEST_F(StorageTest, SetEntryTypeValueDifferentValue) {
|
||||
PopulateTrue();
|
||||
TEST_F(StorageTestPopulateOne, SetEntryTypeValueDifferentValue) {
|
||||
// update with same type and different value results in value update message
|
||||
auto value = Value::MakeBoolean(false);
|
||||
storage.SetEntryTypeValue("foo", value);
|
||||
@@ -140,8 +150,7 @@ TEST_F(StorageTest, SetEntryValueAssignNew) {
|
||||
EXPECT_EQ(Storage::Update::kAssign, update.kind);
|
||||
}
|
||||
|
||||
TEST_F(StorageTest, SetEntryValueAssignTypeChange) {
|
||||
PopulateTrue();
|
||||
TEST_F(StorageTestPopulateOne, SetEntryValueAssignTypeChange) {
|
||||
// update with different type results in error and no message
|
||||
auto value = Value::MakeDouble(0.0);
|
||||
EXPECT_FALSE(storage.SetEntryValue("foo", value));
|
||||
@@ -150,8 +159,7 @@ TEST_F(StorageTest, SetEntryValueAssignTypeChange) {
|
||||
ASSERT_TRUE(updates().empty());
|
||||
}
|
||||
|
||||
TEST_F(StorageTest, SetEntryValueEqualValue) {
|
||||
PopulateTrue();
|
||||
TEST_F(StorageTestPopulateOne, SetEntryValueEqualValue) {
|
||||
// update with same type and same value: change value contents but no update
|
||||
// message is issued (minimizing bandwidth usage)
|
||||
auto value = Value::MakeBoolean(true);
|
||||
@@ -161,8 +169,7 @@ TEST_F(StorageTest, SetEntryValueEqualValue) {
|
||||
ASSERT_TRUE(updates().empty());
|
||||
}
|
||||
|
||||
TEST_F(StorageTest, SetEntryValueDifferentValue) {
|
||||
PopulateTrue();
|
||||
TEST_F(StorageTestPopulateOne, SetEntryValueDifferentValue) {
|
||||
// update with same type and different value results in value update message
|
||||
auto value = Value::MakeBoolean(false);
|
||||
EXPECT_TRUE(storage.SetEntryValue("foo", value));
|
||||
@@ -194,8 +201,7 @@ TEST_F(StorageTest, SetEntryFlagsNew) {
|
||||
ASSERT_TRUE(updates().empty());
|
||||
}
|
||||
|
||||
TEST_F(StorageTest, SetEntryFlagsEqualValue) {
|
||||
PopulateTrue();
|
||||
TEST_F(StorageTestPopulateOne, SetEntryFlagsEqualValue) {
|
||||
// update with same value: no update message is issued (minimizing bandwidth
|
||||
// usage)
|
||||
storage.SetEntryFlags("foo", 0u);
|
||||
@@ -204,8 +210,7 @@ TEST_F(StorageTest, SetEntryFlagsEqualValue) {
|
||||
ASSERT_TRUE(updates().empty());
|
||||
}
|
||||
|
||||
TEST_F(StorageTest, SetEntryFlagsDifferentValue) {
|
||||
PopulateTrue();
|
||||
TEST_F(StorageTestPopulateOne, SetEntryFlagsDifferentValue) {
|
||||
// update with different value results in flags update message
|
||||
storage.SetEntryFlags("foo", 1u);
|
||||
auto entry = storage.GetEntry("foo");
|
||||
@@ -227,8 +232,7 @@ TEST_F(StorageTest, GetEntryFlagsNotExist) {
|
||||
ASSERT_TRUE(entries().empty());
|
||||
}
|
||||
|
||||
TEST_F(StorageTest, GetEntryFlagsExist) {
|
||||
PopulateTrue();
|
||||
TEST_F(StorageTestPopulateOne, GetEntryFlagsExist) {
|
||||
storage.SetEntryFlags("foo", 1u);
|
||||
while (!updates().empty()) updates().pop();
|
||||
ASSERT_EQ(1u, storage.GetEntryFlags("foo"));
|
||||
@@ -239,8 +243,7 @@ TEST_F(StorageTest, DeleteEntryNotExist) {
|
||||
ASSERT_TRUE(updates().empty());
|
||||
}
|
||||
|
||||
TEST_F(StorageTest, DeleteEntryExist) {
|
||||
PopulateTrue();
|
||||
TEST_F(StorageTestPopulateOne, DeleteEntryExist) {
|
||||
auto entry = storage.GetEntry("foo");
|
||||
storage.DeleteEntry("foo");
|
||||
ASSERT_TRUE(entries().empty());
|
||||
@@ -255,8 +258,7 @@ TEST_F(StorageTest, DeleteAllEntriesEmpty) {
|
||||
ASSERT_TRUE(updates().empty());
|
||||
}
|
||||
|
||||
TEST_F(StorageTest, DeleteAllEntries) {
|
||||
PopulateTrue();
|
||||
TEST_F(StorageTestPopulated, DeleteAllEntries) {
|
||||
storage.DeleteAllEntries();
|
||||
ASSERT_TRUE(entries().empty());
|
||||
ASSERT_EQ(1u, updates().size());
|
||||
@@ -265,4 +267,46 @@ TEST_F(StorageTest, DeleteAllEntries) {
|
||||
EXPECT_EQ(Storage::Update::kDeleteAll, update.kind);
|
||||
}
|
||||
|
||||
TEST_F(StorageTestPopulated, GetEntryInfoAll) {
|
||||
auto info = storage.GetEntryInfo("", 0u);
|
||||
ASSERT_EQ(4u, info.size());
|
||||
}
|
||||
|
||||
TEST_F(StorageTestPopulated, GetEntryInfoPrefix) {
|
||||
auto info = storage.GetEntryInfo("foo", 0u);
|
||||
ASSERT_EQ(2u, info.size());
|
||||
if (info[0].name == "foo") {
|
||||
EXPECT_EQ("foo", info[0].name);
|
||||
EXPECT_EQ(NT_BOOLEAN, info[0].type);
|
||||
EXPECT_EQ("foo2", info[1].name);
|
||||
EXPECT_EQ(NT_DOUBLE, info[1].type);
|
||||
} else {
|
||||
EXPECT_EQ("foo2", info[0].name);
|
||||
EXPECT_EQ(NT_DOUBLE, info[0].type);
|
||||
EXPECT_EQ("foo", info[1].name);
|
||||
EXPECT_EQ(NT_BOOLEAN, info[1].type);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(StorageTestPopulated, GetEntryInfoTypes) {
|
||||
auto info = storage.GetEntryInfo("", NT_DOUBLE);
|
||||
ASSERT_EQ(2u, info.size());
|
||||
EXPECT_EQ(NT_DOUBLE, info[0].type);
|
||||
EXPECT_EQ(NT_DOUBLE, info[1].type);
|
||||
if (info[0].name == "foo2") {
|
||||
EXPECT_EQ("foo2", info[0].name);
|
||||
EXPECT_EQ("bar", info[1].name);
|
||||
} else {
|
||||
EXPECT_EQ("bar", info[0].name);
|
||||
EXPECT_EQ("foo2", info[1].name);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(StorageTestPopulated, GetEntryInfoPrefixTypes) {
|
||||
auto info = storage.GetEntryInfo("bar", NT_BOOLEAN);
|
||||
ASSERT_EQ(1u, info.size());
|
||||
EXPECT_EQ("bar2", info[0].name);
|
||||
EXPECT_EQ(NT_BOOLEAN, info[0].type);
|
||||
}
|
||||
|
||||
} // namespace nt
|
||||
|
||||
Reference in New Issue
Block a user