Re: How to temporarily change KConfig-data for a unit test?
Am 2018-02-13 21:44, schrieb Michael Heidelbach: On 13.02.2018 20:38, Martin Flöser wrote: Am 2018-02-13 15:42, schrieb Aleix Pol: On Tue, Feb 13, 2018 at 1:14 PM, Michael Heidelbachwrote: Hi! Currently I'm working on baloo-widgets. For a unit test I need to temporarily change KConfig data. My approach would be like this: initTestCase() KConfig config("baloofileinformationrc", KConfig::NoGlobals); KConfigGroup settings = config.group("Show"); set everything to true here. Revert the changes incleanupTestCase(); How is this done most efficiently and without messing too much with baloofileinformationrc? Ideally you should QStandardPaths::setTestModeEnabled(true), then you can do as you please with config files which should end up in ~/.qttest. A different approach could be to use a KSharedConfig::openConfig(QString(), KConfig::SimpleConfig) This creates an in-memory KConfig not backed by a file. That's what I use in KWin to mock config. All the objects interacting with config have a setConfig(KSharedConfigPtr) method which I can use to inject the mocked config. Cheers Martin Thanks Martin, that sounds very interesting too. By looking at some of kwin's autotests, I got the impression I could learn a lot about testing from reading those. But for now, could you please point me to an example for 'setConfig(KSharedConfigPtr)' or even better teach me how to find one myself within KWin? find yourself: git grep ::setConfig Multiple examples are directly in KWin's main.h file Cheers Martin
Re: How to temporarily change KConfig-data for a unit test?
On 13.02.2018 20:38, Martin Flöser wrote: Am 2018-02-13 15:42, schrieb Aleix Pol: On Tue, Feb 13, 2018 at 1:14 PM, Michael Heidelbachwrote: Hi! Currently I'm working on baloo-widgets. For a unit test I need to temporarily change KConfig data. My approach would be like this: initTestCase() KConfig config("baloofileinformationrc", KConfig::NoGlobals); KConfigGroup settings = config.group("Show"); set everything to true here. Revert the changes incleanupTestCase(); How is this done most efficiently and without messing too much with baloofileinformationrc? Ideally you should QStandardPaths::setTestModeEnabled(true), then you can do as you please with config files which should end up in ~/.qttest. A different approach could be to use a KSharedConfig::openConfig(QString(), KConfig::SimpleConfig) This creates an in-memory KConfig not backed by a file. That's what I use in KWin to mock config. All the objects interacting with config have a setConfig(KSharedConfigPtr) method which I can use to inject the mocked config. Cheers Martin Thanks Martin, that sounds very interesting too. By looking at some of kwin's autotests, I got the impression I could learn a lot about testing from reading those. But for now, could you please point me to an example for 'setConfig(KSharedConfigPtr)' or even better teach me how to find one myself within KWin? Cheers, Michael
Re: How to temporarily change KConfig-data for a unit test?
Am 2018-02-13 15:42, schrieb Aleix Pol: On Tue, Feb 13, 2018 at 1:14 PM, Michael Heidelbachwrote: Hi! Currently I'm working on baloo-widgets. For a unit test I need to temporarily change KConfig data. My approach would be like this: initTestCase() KConfig config("baloofileinformationrc", KConfig::NoGlobals); KConfigGroup settings = config.group("Show"); set everything to true here. Revert the changes incleanupTestCase(); How is this done most efficiently and without messing too much with baloofileinformationrc? Ideally you should QStandardPaths::setTestModeEnabled(true), then you can do as you please with config files which should end up in ~/.qttest. A different approach could be to use a KSharedConfig::openConfig(QString(), KConfig::SimpleConfig) This creates an in-memory KConfig not backed by a file. That's what I use in KWin to mock config. All the objects interacting with config have a setConfig(KSharedConfigPtr) method which I can use to inject the mocked config. Cheers Martin
Re: How to temporarily change KConfig-data for a unit test?
On 13.02.2018 15:42, Aleix Pol wrote: On Tue, Feb 13, 2018 at 1:14 PM, Michael Heidelbachwrote: Hi! Currently I'm working on baloo-widgets. For a unit test I need to temporarily change KConfig data. My approach would be like this: initTestCase() KConfig config("baloofileinformationrc", KConfig::NoGlobals); KConfigGroup settings = config.group("Show"); set everything to true here. Revert the changes incleanupTestCase(); How is this done most efficiently and without messing too much with baloofileinformationrc? Ideally you should QStandardPaths::setTestModeEnabled(true), then you can do as you please with config files which should end up in ~/.qttest. Aleix Works like a charm, thank you.
Re: How to temporarily change KConfig-data for a unit test?
On Tue, Feb 13, 2018 at 1:14 PM, Michael Heidelbachwrote: > Hi! > > Currently I'm working on baloo-widgets. For a unit test I need to > temporarily change KConfig data. > > My approach would be like this: > > initTestCase() > > KConfig config("baloofileinformationrc", KConfig::NoGlobals); > KConfigGroup settings = config.group("Show"); > > set everything to true here. > > Revert the changes incleanupTestCase(); > > How is this done most efficiently and without messing too much with > baloofileinformationrc? Ideally you should QStandardPaths::setTestModeEnabled(true), then you can do as you please with config files which should end up in ~/.qttest. Aleix
How to temporarily change KConfig-data for a unit test?
Hi! Currently I'm working on baloo-widgets. For a unit test I need to temporarily change KConfig data. My approach would be like this: initTestCase() KConfig config("baloofileinformationrc", KConfig::NoGlobals); KConfigGroup settings = config.group("Show"); set everything to true here. Revert the changes incleanupTestCase(); How is this done most efficiently and without messing too much with baloofileinformationrc? Cheers, Michael