Changeset View
Changeset View
Standalone View
Standalone View
autotests/kconfigtest.cpp
Show First 20 Lines • Show All 1970 Lines • ▼ Show 20 Line(s) | 1954 | { | |||
---|---|---|---|---|---|
1971 | QCOMPARE(generalLocal.readEntry("testRestore", "defaultcpp"), "restore"); | 1971 | QCOMPARE(generalLocal.readEntry("testRestore", "defaultcpp"), "restore"); | ||
1972 | 1972 | | |||
1973 | // Revert to default testRestore key and we expect to get default value and not the global one | 1973 | // Revert to default testRestore key and we expect to get default value and not the global one | ||
1974 | generalLocal.revertToDefault("testRestore"); | 1974 | generalLocal.revertToDefault("testRestore"); | ||
1975 | local.sync(); | 1975 | local.sync(); | ||
1976 | local.reparseConfiguration(); | 1976 | local.reparseConfiguration(); | ||
1977 | QCOMPARE(generalLocal.readEntry("testRestore", "defaultcpp"), "defaultcpp"); | 1977 | QCOMPARE(generalLocal.readEntry("testRestore", "defaultcpp"), "defaultcpp"); | ||
1978 | } | 1978 | } | ||
1979 | | ||||
1980 | void KConfigTest::testDefaultFromFile() | ||||
1981 | { | ||||
1982 | // Add "configdefault" value to testKeyDefault in system.kdekdeglobals (this file provide default value) | ||||
1983 | KConfig glob(QStringLiteral("system.kdeglobals")); | ||||
1984 | KConfigGroup generalGlob(&glob, "General"); | ||||
1985 | generalGlob.writeEntry("testKeyDefault", "configdefault"); | ||||
1986 | QVERIFY(glob.sync()); | ||||
1987 | | ||||
1988 | const char *localFile = TEST_SUBDIR "testdefaultfromfilerc"; | ||||
1989 | KConfig local(QStringLiteral(TEST_SUBDIR "testdefaultfromfilerc")); | ||||
1990 | KConfigGroup generalLocal(&local, "General"); | ||||
1991 | // Check if we get global and not the default value from cpp (defaultcpp) when reading data from testdefaultfromfilerc | ||||
dfaure: Bug in the comment, the file isn't called restorerc. | |||||
1992 | QCOMPARE(generalLocal.readEntry("testKeyDefault", "defaultcpp"), "configdefault"); | ||||
1993 | | ||||
1994 | // Write configdefault to local file | ||||
1995 | generalLocal.writeEntry("testKeyDefault", "configdefault"); | ||||
1996 | QVERIFY(local.sync()); | ||||
1997 | local.reparseConfiguration(); | ||||
1998 | // We expect to get configdefault value and configdefault not written to local file (file will not exist) | ||||
dfaure: s/wrote/written/ | |||||
1999 | QCOMPARE(generalLocal.readEntry("testKeyDefault", "defaultcpp"), "configdefault"); | ||||
2000 | QVERIFY(!QFile::exists(localFile)); | ||||
2001 | | ||||
2002 | // Write a custom value, we expect this value to be written to local file | ||||
dfaure: s/wrote/written/ | |||||
2003 | generalLocal.writeEntry("testKeyDefault", "custom"); | ||||
2004 | QVERIFY(local.sync()); | ||||
2005 | local.reparseConfiguration(); | ||||
2006 | QCOMPARE(generalLocal.readEntry("testKeyDefault", "defaultcpp"), "custom"); | ||||
2007 | QList<QByteArray> lines = readLines(localFile); | ||||
2008 | Q_ASSERT(lines.contains("testKeyDefault=custom\n")); | ||||
2009 | | ||||
2010 | // Revert to default, we expect to get default value from file and local file don't exist | ||||
2011 | // To revert to file default we need to write same value | ||||
2012 | generalLocal.writeEntry("testKeyDefault", "configdefault"); | ||||
2013 | QVERIFY(local.sync()); | ||||
2014 | local.reparseConfiguration(); | ||||
2015 | QCOMPARE(generalLocal.readEntry("testKeyDefault", "defaultcpp"), "configdefault"); | ||||
2016 | | ||||
2017 | // Now we change default value from system.globals to ensure new one is used | ||||
2018 | glob.deleteGroup("General"); | ||||
2019 | glob.sync(); | ||||
2020 | glob.reparseConfiguration(); | ||||
2021 | generalGlob.writeEntry("testKeyDefault", "configdefault-new"); | ||||
2022 | QVERIFY(generalGlob.sync()); | ||||
2023 | local.reparseConfiguration(); | ||||
2024 | QCOMPARE(generalLocal.readEntry("testKeyDefault", "defaultcpp"), "configdefault-new"); | ||||
2025 | | ||||
2026 | // Set value to defaultcpp, this one need to be wrote to local file (so we don't end up with default from global file) | ||||
2027 | generalLocal.writeEntry("testKeyDefault", "defaultcpp"); | ||||
2028 | QVERIFY(local.sync()); | ||||
2029 | local.reparseConfiguration(); | ||||
2030 | QCOMPARE(generalLocal.readEntry("testKeyDefault", "defaultcpp"), "defaultcpp"); | ||||
2031 | lines = readLines(localFile); | ||||
2032 | Q_ASSERT(lines.contains("testKeyDefault=defaultcpp\n")); | ||||
2033 | } |
Bug in the comment, the file isn't called restorerc.