Changeset View
Changeset View
Standalone View
Standalone View
autotests/kconfigtest.cpp
Show First 20 Lines • Show All 524 Lines • ▼ Show 20 Line(s) | 520 | { | |||
---|---|---|---|---|---|
525 | QCOMPARE(sc3.entryMap()["homepath"], HOMEPATH); | 525 | QCOMPARE(sc3.entryMap()["homepath"], HOMEPATH); | ||
526 | 526 | | |||
527 | qputenv("WITHSLASH", "/a/"); | 527 | qputenv("WITHSLASH", "/a/"); | ||
528 | { | 528 | { | ||
529 | QFile file(testConfigDir() + "/pathtest"); | 529 | QFile file(testConfigDir() + "/pathtest"); | ||
530 | file.open(QIODevice::WriteOnly | QIODevice::Text); | 530 | file.open(QIODevice::WriteOnly | QIODevice::Text); | ||
531 | QTextStream out(&file); | 531 | QTextStream out(&file); | ||
532 | out.setCodec("UTF-8"); | 532 | out.setCodec("UTF-8"); | ||
533 | out << "[Test Group]" << endl | 533 | out << "[Test Group]\n" | ||
534 | << "homePath=$HOME/foo" << endl | 534 | << "homePath=$HOME/foo\n" | ||
535 | << "homePath2=file://$HOME/foo" << endl | 535 | << "homePath2=file://$HOME/foo\n" | ||
536 | << "withSlash=$WITHSLASH/foo" << endl | 536 | << "withSlash=$WITHSLASH/foo\n" | ||
537 | << "withSlash2=$WITHSLASH" << endl | 537 | << "withSlash2=$WITHSLASH\n" | ||
538 | << "withBraces[$e]=file://${HOME}/foo" << endl | 538 | << "withBraces[$e]=file://${HOME}/foo\n" | ||
539 | << "URL[$e]=file://${HOME}/foo" << endl | 539 | << "URL[$e]=file://${HOME}/foo\n" | ||
540 | << "hostname[$e]=$(hostname)" << endl | 540 | << "hostname[$e]=$(hostname)\n" | ||
541 | << "escapes=aaa,bb/b,ccc\\,ccc" << endl | 541 | << "escapes=aaa,bb/b,ccc\\,ccc\n" | ||
542 | << "noeol=foo" // no EOL | 542 | << "noeol=foo" // no EOL | ||
543 | ; | 543 | ; | ||
544 | } | 544 | } | ||
545 | KConfig cf2(TEST_SUBDIR "pathtest"); | 545 | KConfig cf2(TEST_SUBDIR "pathtest"); | ||
546 | KConfigGroup group = cf2.group("Test Group"); | 546 | KConfigGroup group = cf2.group("Test Group"); | ||
547 | QVERIFY(group.hasKey("homePath")); | 547 | QVERIFY(group.hasKey("homePath")); | ||
548 | QCOMPARE(group.readPathEntry("homePath", QString()), HOMEPATH); | 548 | QCOMPARE(group.readPathEntry("homePath", QString()), HOMEPATH); | ||
549 | QVERIFY(group.hasKey("homePath2")); | 549 | QVERIFY(group.hasKey("homePath2")); | ||
Show All 37 Lines | |||||
587 | 587 | | |||
588 | void KConfigTest::testPathQtHome() | 588 | void KConfigTest::testPathQtHome() | ||
589 | { | 589 | { | ||
590 | { | 590 | { | ||
591 | QFile file(testConfigDir() + "/pathtest"); | 591 | QFile file(testConfigDir() + "/pathtest"); | ||
592 | file.open(QIODevice::WriteOnly | QIODevice::Text); | 592 | file.open(QIODevice::WriteOnly | QIODevice::Text); | ||
593 | QTextStream out(&file); | 593 | QTextStream out(&file); | ||
594 | out.setCodec("UTF-8"); | 594 | out.setCodec("UTF-8"); | ||
595 | out << "[Test Group]" << endl | 595 | out << "[Test Group]\n" | ||
596 | << "dataDir[$e]=$QT_DATA_HOME/kconfigtest" << endl | 596 | << "dataDir[$e]=$QT_DATA_HOME/kconfigtest\n" | ||
597 | << "cacheDir[$e]=$QT_CACHE_HOME/kconfigtest" << endl | 597 | << "cacheDir[$e]=$QT_CACHE_HOME/kconfigtest\n" | ||
598 | << "configDir[$e]=$QT_CONFIG_HOME/kconfigtest" << endl; | 598 | << "configDir[$e]=$QT_CONFIG_HOME/kconfigtest\n"; | ||
599 | } | 599 | } | ||
600 | KConfig cf2(TEST_SUBDIR "pathtest"); | 600 | KConfig cf2(TEST_SUBDIR "pathtest"); | ||
601 | KConfigGroup group = cf2.group("Test Group"); | 601 | KConfigGroup group = cf2.group("Test Group"); | ||
602 | qunsetenv("QT_DATA_HOME"); | 602 | qunsetenv("QT_DATA_HOME"); | ||
603 | qunsetenv("QT_CACHE_HOME"); | 603 | qunsetenv("QT_CACHE_HOME"); | ||
604 | qunsetenv("QT_CONFIG_HOME"); | 604 | qunsetenv("QT_CONFIG_HOME"); | ||
605 | QVERIFY(group.hasKey("dataDir")); | 605 | QVERIFY(group.hasKey("dataDir")); | ||
606 | QCOMPARE(group.readEntry("dataDir", QString()), QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation).append(QStringLiteral("/kconfigtest"))); | 606 | QCOMPARE(group.readEntry("dataDir", QString()), QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation).append(QStringLiteral("/kconfigtest"))); | ||
▲ Show 20 Lines • Show All 369 Lines • ▼ Show 20 Line(s) | 974 | #ifdef Q_XDG_PLATFORM | |||
976 | QTemporaryDir globalDir; | 976 | QTemporaryDir globalDir; | ||
977 | qputenv("XDG_CONFIG_DIRS", qPrintable(middleDir.path() + QString(":") + globalDir.path())); | 977 | qputenv("XDG_CONFIG_DIRS", qPrintable(middleDir.path() + QString(":") + globalDir.path())); | ||
978 | 978 | | |||
979 | const QString globalConfigDir = globalDir.path() + "/" TEST_SUBDIR; | 979 | const QString globalConfigDir = globalDir.path() + "/" TEST_SUBDIR; | ||
980 | QVERIFY(QDir().mkpath(globalConfigDir)); | 980 | QVERIFY(QDir().mkpath(globalConfigDir)); | ||
981 | QFile global(globalConfigDir + "foo.desktop"); | 981 | QFile global(globalConfigDir + "foo.desktop"); | ||
982 | QVERIFY(global.open(QIODevice::WriteOnly | QIODevice::Text)); | 982 | QVERIFY(global.open(QIODevice::WriteOnly | QIODevice::Text)); | ||
983 | QTextStream globalOut(&global); | 983 | QTextStream globalOut(&global); | ||
984 | globalOut << "[Group]" << endl | 984 | globalOut << "[Group]\n" | ||
985 | << "FromGlobal=true" << endl | 985 | << "FromGlobal=true\n" | ||
986 | << "FromGlobal[fr]=vrai" << endl | 986 | << "FromGlobal[fr]=vrai\n" | ||
987 | << "Name=Testing" << endl | 987 | << "Name=Testing\n" | ||
988 | << "Name[fr]=FR" << endl | 988 | << "Name[fr]=FR\n" | ||
989 | << "Other=Global" << endl | 989 | << "Other=Global\n" | ||
990 | << "Other[fr]=Global_FR" << endl; | 990 | << "Other[fr]=Global_FR\n"; | ||
991 | global.close(); | 991 | global.close(); | ||
992 | 992 | | |||
993 | const QString middleConfigDir = middleDir.path() + "/" TEST_SUBDIR; | 993 | const QString middleConfigDir = middleDir.path() + "/" TEST_SUBDIR; | ||
994 | QVERIFY(QDir().mkpath(middleConfigDir)); | 994 | QVERIFY(QDir().mkpath(middleConfigDir)); | ||
995 | QFile local(middleConfigDir + "foo.desktop"); | 995 | QFile local(middleConfigDir + "foo.desktop"); | ||
996 | QVERIFY(local.open(QIODevice::WriteOnly | QIODevice::Text)); | 996 | QVERIFY(local.open(QIODevice::WriteOnly | QIODevice::Text)); | ||
997 | QTextStream out(&local); | 997 | QTextStream out(&local); | ||
998 | out << "[Group]" << endl | 998 | out << "[Group]\n" | ||
999 | << "FromLocal=true" << endl | 999 | << "FromLocal=true\n" | ||
1000 | << "FromLocal[fr]=vrai" << endl | 1000 | << "FromLocal[fr]=vrai\n" | ||
1001 | << "Name=Local Testing" << endl | 1001 | << "Name=Local Testing\n" | ||
1002 | << "Name[fr]=FR" << endl | 1002 | << "Name[fr]=FR\n" | ||
1003 | << "Other=English Only" << endl; | 1003 | << "Other=English Only\n"; | ||
1004 | local.close(); | 1004 | local.close(); | ||
1005 | 1005 | | |||
1006 | KConfig config(TEST_SUBDIR "foo.desktop"); | 1006 | KConfig config(TEST_SUBDIR "foo.desktop"); | ||
1007 | KConfigGroup group = config.group("Group"); | 1007 | KConfigGroup group = config.group("Group"); | ||
1008 | QCOMPARE(group.readEntry("FromGlobal"), QString("true")); | 1008 | QCOMPARE(group.readEntry("FromGlobal"), QString("true")); | ||
1009 | QCOMPARE(group.readEntry("FromLocal"), QString("true")); | 1009 | QCOMPARE(group.readEntry("FromLocal"), QString("true")); | ||
1010 | QCOMPARE(group.readEntry("Name"), QString("Local Testing")); | 1010 | QCOMPARE(group.readEntry("Name"), QString("Local Testing")); | ||
1011 | config.setLocale(QStringLiteral("fr")); | 1011 | config.setLocale(QStringLiteral("fr")); | ||
Show All 15 Lines | 1020 | { | |||
1027 | cg.writeEntry("another entry", "blah blah blah"); | 1027 | cg.writeEntry("another entry", "blah blah blah"); | ||
1028 | 1028 | | |||
1029 | { | 1029 | { | ||
1030 | // simulate writing by another process | 1030 | // simulate writing by another process | ||
1031 | QFile file(testConfigDir() + "/mergetest"); | 1031 | QFile file(testConfigDir() + "/mergetest"); | ||
1032 | file.open(QIODevice::WriteOnly | QIODevice::Text); | 1032 | file.open(QIODevice::WriteOnly | QIODevice::Text); | ||
1033 | QTextStream out(&file); | 1033 | QTextStream out(&file); | ||
1034 | out.setCodec("UTF-8"); | 1034 | out.setCodec("UTF-8"); | ||
1035 | out << "[Merged Group]" << endl | 1035 | out << "[Merged Group]\n" | ||
1036 | << "entry1=Testing" << endl | 1036 | << "entry1=Testing\n" | ||
1037 | << "entry2=More Testing" << endl | 1037 | << "entry2=More Testing\n" | ||
1038 | << "[some group]" << endl | 1038 | << "[some group]\n" | ||
1039 | << "entry[fr]=French" << endl | 1039 | << "entry[fr]=French\n" | ||
1040 | << "entry[es]=Spanish" << endl | 1040 | << "entry[es]=Spanish\n" | ||
1041 | << "entry[de]=German" << endl; | 1041 | << "entry[de]=German\n"; | ||
1042 | } | 1042 | } | ||
1043 | QVERIFY(config.sync()); | 1043 | QVERIFY(config.sync()); | ||
1044 | 1044 | | |||
1045 | { | 1045 | { | ||
1046 | QList<QByteArray> lines; | 1046 | QList<QByteArray> lines; | ||
1047 | // this is what the file should look like | 1047 | // this is what the file should look like | ||
1048 | lines << "[Merged Group]\n" | 1048 | lines << "[Merged Group]\n" | ||
1049 | << "entry1=Testing\n" | 1049 | << "entry1=Testing\n" | ||
Show All 15 Lines | |||||
1065 | 1065 | | |||
1066 | void KConfigTest::testImmutable() | 1066 | void KConfigTest::testImmutable() | ||
1067 | { | 1067 | { | ||
1068 | { | 1068 | { | ||
1069 | QFile file(testConfigDir() + "/immutabletest"); | 1069 | QFile file(testConfigDir() + "/immutabletest"); | ||
1070 | file.open(QIODevice::WriteOnly | QIODevice::Text); | 1070 | file.open(QIODevice::WriteOnly | QIODevice::Text); | ||
1071 | QTextStream out(&file); | 1071 | QTextStream out(&file); | ||
1072 | out.setCodec("UTF-8"); | 1072 | out.setCodec("UTF-8"); | ||
1073 | out << "[$i]" << endl | 1073 | out << "[$i]\n" | ||
1074 | << "entry1=Testing" << endl | 1074 | << "entry1=Testing\n" | ||
1075 | << "[group][$i]" << endl | 1075 | << "[group][$i]\n" | ||
1076 | << "[group][subgroup][$i]" << endl; | 1076 | << "[group][subgroup][$i]\n"; | ||
1077 | } | 1077 | } | ||
1078 | 1078 | | |||
1079 | KConfig config(TEST_SUBDIR "immutabletest", KConfig::SimpleConfig); | 1079 | KConfig config(TEST_SUBDIR "immutabletest", KConfig::SimpleConfig); | ||
1080 | QVERIFY(config.isGroupImmutable(QByteArray())); | 1080 | QVERIFY(config.isGroupImmutable(QByteArray())); | ||
1081 | KConfigGroup cg = config.group(QByteArray()); | 1081 | KConfigGroup cg = config.group(QByteArray()); | ||
1082 | QVERIFY(cg.isEntryImmutable("entry1")); | 1082 | QVERIFY(cg.isEntryImmutable("entry1")); | ||
1083 | KConfigGroup cg1 = config.group("group"); | 1083 | KConfigGroup cg1 = config.group("group"); | ||
1084 | QVERIFY(cg1.isImmutable()); | 1084 | QVERIFY(cg1.isImmutable()); | ||
1085 | KConfigGroup cg1a = cg.group("group"); | 1085 | KConfigGroup cg1a = cg.group("group"); | ||
1086 | QVERIFY(cg1a.isImmutable()); | 1086 | QVERIFY(cg1a.isImmutable()); | ||
1087 | KConfigGroup cg2 = cg1.group("subgroup"); | 1087 | KConfigGroup cg2 = cg1.group("subgroup"); | ||
1088 | QVERIFY(cg2.isImmutable()); | 1088 | QVERIFY(cg2.isImmutable()); | ||
1089 | } | 1089 | } | ||
1090 | 1090 | | |||
1091 | void KConfigTest::testOptionOrder() | 1091 | void KConfigTest::testOptionOrder() | ||
1092 | { | 1092 | { | ||
1093 | { | 1093 | { | ||
1094 | QFile file(testConfigDir() + "/doubleattrtest"); | 1094 | QFile file(testConfigDir() + "/doubleattrtest"); | ||
1095 | file.open(QIODevice::WriteOnly | QIODevice::Text); | 1095 | file.open(QIODevice::WriteOnly | QIODevice::Text); | ||
1096 | QTextStream out(&file); | 1096 | QTextStream out(&file); | ||
1097 | out.setCodec("UTF-8"); | 1097 | out.setCodec("UTF-8"); | ||
1098 | out << "[group3]" << endl | 1098 | out << "[group3]\n" | ||
1099 | << "entry2=unlocalized" << endl | 1099 | << "entry2=unlocalized\n" | ||
1100 | << "entry2[$i][de_DE]=t2" << endl; | 1100 | << "entry2[$i][de_DE]=t2\n"; | ||
1101 | } | 1101 | } | ||
1102 | KConfig config(TEST_SUBDIR "doubleattrtest", KConfig::SimpleConfig); | 1102 | KConfig config(TEST_SUBDIR "doubleattrtest", KConfig::SimpleConfig); | ||
1103 | config.setLocale(QStringLiteral("de_DE")); | 1103 | config.setLocale(QStringLiteral("de_DE")); | ||
1104 | KConfigGroup cg3 = config.group("group3"); | 1104 | KConfigGroup cg3 = config.group("group3"); | ||
1105 | QVERIFY(!cg3.isImmutable()); | 1105 | QVERIFY(!cg3.isImmutable()); | ||
1106 | QCOMPARE(cg3.readEntry("entry2", ""), QString("t2")); | 1106 | QCOMPARE(cg3.readEntry("entry2", ""), QString("t2")); | ||
1107 | QVERIFY(cg3.isEntryImmutable("entry2")); | 1107 | QVERIFY(cg3.isEntryImmutable("entry2")); | ||
1108 | config.setLocale(QStringLiteral("C")); | 1108 | config.setLocale(QStringLiteral("C")); | ||
▲ Show 20 Lines • Show All 722 Lines • ▼ Show 20 Line(s) | |||||
1831 | 1831 | | |||
1832 | } | 1832 | } | ||
1833 | 1833 | | |||
1834 | void KConfigTest::testXdgListEntry() | 1834 | void KConfigTest::testXdgListEntry() | ||
1835 | { | 1835 | { | ||
1836 | QTemporaryFile file; | 1836 | QTemporaryFile file; | ||
1837 | QVERIFY(file.open()); | 1837 | QVERIFY(file.open()); | ||
1838 | QTextStream out(&file); | 1838 | QTextStream out(&file); | ||
1839 | out << "[General]" << endl | 1839 | out << "[General]\n" | ||
1840 | << "Key1=" << endl // empty list | 1840 | << "Key1=\n" // empty list | ||
1841 | // emtpty entries | 1841 | // emtpty entries | ||
1842 | << "Key2=;" << endl | 1842 | << "Key2=;\n" | ||
1843 | << "Key3=;;" << endl | 1843 | << "Key3=;;\n" | ||
1844 | << "Key4=;;;" << endl | 1844 | << "Key4=;;;\n" | ||
1845 | << "Key5=\\;" << endl | 1845 | << "Key5=\\;\n" | ||
1846 | << "Key6=1;2\\;3;;" << endl; | 1846 | << "Key6=1;2\\;3;;\n"; | ||
1847 | out.flush(); | 1847 | out.flush(); | ||
1848 | file.close(); | 1848 | file.close(); | ||
1849 | KConfig anonConfig(file.fileName(), KConfig::SimpleConfig); | 1849 | KConfig anonConfig(file.fileName(), KConfig::SimpleConfig); | ||
1850 | KConfigGroup grp = anonConfig.group("General"); | 1850 | KConfigGroup grp = anonConfig.group("General"); | ||
1851 | QStringList invalidList; // use this as a default when an empty list is expected | 1851 | QStringList invalidList; // use this as a default when an empty list is expected | ||
1852 | invalidList << QStringLiteral("Error! Default value read!"); | 1852 | invalidList << QStringLiteral("Error! Default value read!"); | ||
1853 | QCOMPARE(grp.readXdgListEntry("Key1", invalidList), QStringList()); | 1853 | QCOMPARE(grp.readXdgListEntry("Key1", invalidList), QStringList()); | ||
1854 | QCOMPARE(grp.readXdgListEntry("Key2", invalidList), QStringList() << QString()); | 1854 | QCOMPARE(grp.readXdgListEntry("Key2", invalidList), QStringList() << QString()); | ||
▲ Show 20 Lines • Show All 110 Lines • Show Last 20 Lines |