mirror of https://github.com/linuxdeepin/dtkcore
fix: Can't access QStringList type data for DConfig
it's occur in DBusBackend, and we directly to get meta value that not exist cache. normal value type is automatic casted from QDBusVariant to QVariant, and QVariantList type need to cast explicitly, it's value type is QDBusArgument. because our data store backend is using QJsonValue to resolve, so we only case QVariantList and QVariantMap, it maybe error in lastly. Log: Influence: DConfig is not access stringlist data type. Change-Id: I81dbc2ea6b7933154d26ddba70def95ef79240d6
This commit is contained in:
parent
847c721c87
commit
a3503969de
|
@ -280,6 +280,27 @@ public:
|
|||
{
|
||||
const QDBusVariant &dv = config->value(key);
|
||||
const QVariant &v = dv.variant();
|
||||
if (v.canConvert<QDBusArgument>()) {
|
||||
// we use QJsonValue to resolve all data type in DConfigInfo class, so it's type is equal QJsonValue::Type,
|
||||
// now we parse Map and Array type to QVariant explicitly.
|
||||
const QDBusArgument &complexType = v.value<QDBusArgument>();
|
||||
switch (complexType.currentType()) {
|
||||
case QDBusArgument::MapType: {
|
||||
QVariantMap list;
|
||||
complexType >> list;
|
||||
return list;
|
||||
}
|
||||
case QDBusArgument::ArrayType: {
|
||||
QVariantList list;
|
||||
complexType >> list;
|
||||
return list;
|
||||
}
|
||||
default:
|
||||
qCWarning(cfLog, "Can't parse the type, it maybe need user to do it, "
|
||||
"key: %s, and QDBusArgument::ElementType: %d.", qPrintable(key), complexType.currentType());
|
||||
}
|
||||
}
|
||||
|
||||
return v.isValid() ? v : fallback;
|
||||
}
|
||||
|
||||
|
|
|
@ -31,6 +31,22 @@
|
|||
"description": "I am description",
|
||||
"permissions": "readwrite",
|
||||
"visibility": "public"
|
||||
},
|
||||
"array": {
|
||||
"value": ["value1", "value2"],
|
||||
"serial": 0,
|
||||
"flags": ["global"],
|
||||
"name": "array value type",
|
||||
"permissions": "readwrite",
|
||||
"visibility": "public"
|
||||
},
|
||||
"map": {
|
||||
"value": {"key1": "value1", "key2": "value2"},
|
||||
"serial": 0,
|
||||
"flags": ["global"],
|
||||
"name": "array value type",
|
||||
"permissions": "readwrite",
|
||||
"visibility": "public"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,14 +71,26 @@ TEST_F(ut_DConfig, isValid) {
|
|||
}
|
||||
|
||||
TEST_F(ut_DConfig, value) {
|
||||
const QStringList array{"1", "2"};
|
||||
QVariantMap map;
|
||||
map.insert("key1", "value1");
|
||||
map.insert("key2", "value2");
|
||||
{
|
||||
DConfig config(FILE_NAME);
|
||||
config.setValue("key2", "126");
|
||||
ASSERT_EQ(config.value("key2").toString(), QString("126"));
|
||||
|
||||
config.setValue("array", array);
|
||||
ASSERT_EQ(config.value("array").toStringList(), array);
|
||||
|
||||
config.setValue("map", map);
|
||||
ASSERT_EQ(config.value("map").toMap(), map);
|
||||
}
|
||||
{
|
||||
DConfig config(FILE_NAME);
|
||||
ASSERT_EQ(config.value("key2").toString(), QString("126"));
|
||||
ASSERT_EQ(config.value("array").toStringList(), array);
|
||||
ASSERT_EQ(config.value("map").toMap(), map);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -169,6 +169,12 @@ TEST_F(ut_DConfigFile, meta) {
|
|||
QScopedPointer<DConfigCache> userCache(config.createUserCache(uid));
|
||||
ASSERT_TRUE(userCache->load(LocalPrefix));
|
||||
ASSERT_EQ(config.value("key3", userCache.get()), QString("application"));
|
||||
const QStringList array{"value1", "value2"};
|
||||
ASSERT_EQ(config.value("array", userCache.get()), array);
|
||||
QVariantMap map;
|
||||
map.insert("key1", "value1");
|
||||
map.insert("key2", "value2");
|
||||
ASSERT_EQ(config.value("map", userCache.get()).toMap(), map);
|
||||
}
|
||||
|
||||
TEST_F(ut_DConfigFile, fileOverride) {
|
||||
|
|
Loading…
Reference in New Issue