Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions rviz_common/src/rviz_common/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,10 @@ bool Config::mapGetFloat(const QString & key, float * value_out) const

bool Config::mapGetBool(const QString & key, bool * value_out) const
{
if (value_out == nullptr) {
return false;
}

QVariant v;
if (mapGetValue(key, &v) && (v.type() == QVariant::Bool || v.type() == QVariant::String)) {
*value_out = v.toBool();
Expand Down
11 changes: 11 additions & 0 deletions rviz_common/test/config_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,17 @@ TEST(Config, mapGetValue_key_not_found_null_check) {
EXPECT_EQ(s_default, "my_default_value");
}

TEST(Config, handle_mixed_type_values_for_keys) {
rviz_common::Config c;
c.mapSetValue("mixed_key", "123abc");
EXPECT_FALSE(c.mapGetInt("mixed_key", nullptr));
EXPECT_FALSE(c.mapGetBool("mixed_key", nullptr));
EXPECT_FALSE(c.mapGetFloat("mixed_key", nullptr));
QString string_value;
EXPECT_TRUE(c.mapGetString("mixed_key", &string_value));
EXPECT_EQ(string_value, "123abc");
}

int main(int argc, char ** argv)
{
testing::InitGoogleTest(&argc, argv);
Expand Down