<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>Ok. I have inserted: std::cout<<"Reached\n"; just before each of the lines were I introduce the faults. Note that I only insert one of these faults in the program, not several of them at the same time. <br><br>1) In the first case that I commented, I performed the following four changes:<br><br>- In mymoneyfile.cpp, line 385: <br>a)  d->m_balanceChangedSet.remove((*it).id()); -->  d->m_valueChangedSet.remove((*it).id());<br><br>The line is reached by MyMoneyFileTest::testRemoveInstitution(), MyMoneyFileTest::testRemoveAccount(),  MyMoneyFileTest::testRemoveAccountTree() and MyMoneyFileTest::testRemovePayee().<br><br>- In mymoneyfile.cpp, line 409:<br>b) d->m_valueChangedSet.remove(id);  --> d->m_balanceChangedSet.remove(id);<br><br>In 1b.txt, you can see that many of test cases in MyMoneyFileTest reach this line (Note: search for the word "Reached" in the file. It is written just before the test cases that reach this line.)<br><br>- In mymoneyfile.cpp, line 435 and 436:<br>c) d->m_balanceChangedSet.clear(); --> d->m_valueChangedSet.clear();<br>d) d->m_valueChangedSet.clear(); -->   d->m_balanceChangedSet.clear();<br><br>The results are in 1cd.txt.<br><br><br>2) In the second case, I performed the following four changes:<br><br>- In mymoneyfile.cpp, line 177: <br>a) m_balanceCache.clear(i.first, i.second);  --> m_balanceCache.clear(i.first);<br>b) m_balanceCache.clear(i.first, i.second);  --> m_balanceCache.clear();    <br><br>In 2ab.txt, you can see that most of test cases in MyMoneyFileTest and 
some in MyMoneyForecast reach the incorrect line in the cases a y b. <br><br>- mymoneyfile.cpp, line 179:<br>c) m_balanceCache.clear(i.first); --> m_balanceCache.clear();<br><br>Never reached.<br><br>- mymoneyfile.cpp, line 762:<br>d) d->m_balanceCache.clear(acc.id()); --> d->m_balanceCache.clear();<br><br>Reached by MyMoneyFileTest::testRemoveAccount() and MyMoneyFileTest::testRemoveAccountTree()<br><br>If you need more data, let me know. Thanks!<br><br><br><br><div>> Date: Fri, 27 Feb 2015 17:55:12 +0200<br>> Subject: Re: [Kmymoney-devel] Improving the test suite for MyMoneyFile<br>> From: onet.cristian@gmail.com<br>> To: kmymoney-devel@kde.org<br>> CC: pedretti_86@hotmail.com<br>> <br>> 2015-02-20 13:24 GMT+02:00 victor <pedretti_86@hotmail.com>:<br>> > Hi,<br>> ><br>> > I have tried to become familiar with QSignalSpy. For instance, to comply<br>> > with "After adding a price 'valueChanged()' should be emitted.", I have<br>> > implemented this:<br>> ><br>> > qRegisterMetaType<MyMoneyAccount>("MyMoneyAccount");<br>> ><br>> > QSignalSpy spy(m, SIGNAL(valueChanged(MyMoneyAccount)));<br>> ><br>> ><br>> > m->addPrice(price);<br>> ><br>> > ft.commit();<br>> ><br>> ><br>> > QCOMPARE(spy.count(), 1);<br>> ><br>> ><br>> > However, I do not fully understand what this mechanism contributes in this<br>> > case as far as the test file already checks that situation just after adding<br>> > a price:<br>> ><br>> ><br>> >   QVERIFY(m_balanceChanged.count() == 0);<br>> >   QVERIFY(m_valueChanged.count() == 1);<br>> >   QVERIFY(m_valueChanged.count("A000002") == 1);<br>> ><br>> <br>> You are right the signal spy is not needed with these checks present,<br>> although for black-box tests it would be better to check for signal<br>> emission than some internal data structure change.<br>> <br>> ><br>> > Thus, I think that what I need is a scenario where a change in the "count"<br>> > of some of those signals arise after inserting the fault/s that I commented.<br>> > This is not happening at the moment with the current mymoneytestfile.cpp.<br>> <br>> Then that should be easy, when adding the incorrect code, did you<br>> check that it is actually executed when the testcase is running, we<br>> have two possible scenarios:<br>> 1) The incorrect code is executed by the current tests then just extra<br>> checks should be added<br>> 2) The incorrect code is not executed by the current tests then add a<br>> test which will trigger that code path<br>> <br>> In both cases we can help you with this. Just let us know what you find.<br>> <br>> Regards,<br>> Cristian<br>> <br>> ><br>> > Regards.<br>> ><br>> ><br>> ><br>> >> Date: Tue, 17 Feb 2015 20:18:23 +0200<br>> ><br>> >> Subject: Re: [Kmymoney-devel] Improving the test suite for MyMoneyFile<br>> >> From: onet.cristian@gmail.com<br>> >> To: pedretti_86@hotmail.com<br>> >> CC: kmymoney-devel@kde.org<br>> >><br>> >> To verify signal emission in a test case use QSignalSpy [1] (it's<br>> >> pretty well documented).<br>> >><br>> >> I'm on the run now but I'll follow up with a specific example and<br>> >> ideas about the balance cache later.<br>> >><br>> >> Regards,<br>> >> Cristian<br>> >><br>> >> [1] http://doc.qt.io/qt-5/QSignalSpy.html<br>> >><br>> >> 2015-02-17 19:24 GMT+02:00 victor <pedretti_86@hotmail.com>:<br>> >> > Thanks for your answer Cristian. I understand what you mean, but I have<br>> >> > no<br>> >> > idea about how to check that those signals are emitted since I have<br>> >> > never<br>> >> > worked with this mechanism. Could you please show me a specific example?<br>> >> ><br>> >> > Your answer refers to m_valueChangedSet and m_balanceChangedSet. Any<br>> >> > ideas<br>> >> > about the faults involving "m_balanceCache"?<br>> >> ><br>> >> >> Date: Tue, 17 Feb 2015 16:23:42 +0200<br>> >> >> Subject: Re: [Kmymoney-devel] Improving the test suite for MyMoneyFile<br>> >> >> From: onet.cristian@gmail.com<br>> >> >> To: pedretti_86@hotmail.com<br>> >> >> CC: kmymoney-devel@kde.org<br>> >> ><br>> >> >><br>> >> >> Hi,<br>> >> >><br>> >> >> Since those two members are used to implement the emit of the<br>> >> >> 'balanceChanged()' and 'valueChanged()' signals after committing<br>> >> >> changes you could write a test case that asserts that those signals<br>> >> >> are emitted properly.<br>> >> >><br>> >> >> For example:<br>> >> >> After adding a transaction 'balanceChanged()' should be emitted.<br>> >> >> After adding a price 'valueChanged()' should be emitted.<br>> >> >><br>> >> >> Regards,<br>> >> >> Cristian<br>> >> >><br>> >> >> 2015-02-17 16:13 GMT+02:00 victor <pedretti_86@hotmail.com>:<br>> >> >> > Hello,<br>> >> >> ><br>> >> >> > I am trying to improve some of the test files of KMyMoney for my<br>> >> >> > research<br>> >> >> > studies. This is a really complex task when you are not involved in<br>> >> >> > programming this application, so I need your help to achieve it.<br>> >> >> ><br>> >> >> > All the same, I'm only focusing on some specific parts. What I'm<br>> >> >> > doing<br>> >> >> > is to<br>> >> >> > introduce several concrete faults into the code and then observe if<br>> >> >> > the<br>> >> >> > fault is detected by the test suite (this would be the expected of an<br>> >> >> > adequate test suite, but we all now that this is quite difficult<br>> >> >> > sometimes).<br>> >> >> > In this sense, I have been doing this in "mymoneyfile.cpp" and<br>> >> >> > testing<br>> >> >> > it<br>> >> >> > with its corresponding file test "mymoneyfiletest.cpp". The faults<br>> >> >> > introduced are faults which are common when programming because we<br>> >> >> > sometimes<br>> >> >> > mix the name of variables of the same type, or do not call the<br>> >> >> > appropriate<br>> >> >> > method because of "copy and paste",...<br>> >> >> ><br>> >> >> > Here I show two of these faults that the test suite is not able to<br>> >> >> > detect<br>> >> >> > (the result is the same in the original program and with the inserted<br>> >> >> > fault):<br>> >> >> ><br>> >> >> > 1) The first is in the method "void<br>> >> >> > MyMoneyFile::commitTransaction(void)",<br>> >> >> > where I change:<br>> >> >> ><br>> >> >> > d->m_balanceChangedSet.remove((*it).id());<br>> >> >> ><br>> >> >> > by:<br>> >> >> ><br>> >> >> > d->m_valueChangedSet.remove((*it).id());<br>> >> >> ><br>> >> >> > Exactly the same happens in the method "void<br>> >> >> > MyMoneyFile::rollbackTransaction(void)" if, for instance, I change<br>> >> >> > "d->m_valueChangedSet.clear();" by "d->m_balanceChangedSet.clear();".<br>> >> >> > These<br>> >> >> > changes seem to be meaningful changes, but they are not detected by<br>> >> >> > the<br>> >> >> > test<br>> >> >> > suite at the moment.<br>> >> >> ><br>> >> >> > 2) The other situation that I want to report is in method "void<br>> >> >> > notify(void)" belonging to "MyMoneyFile::Private". If I change,<br>> >> >> ><br>> >> >> > m_balanceCache.clear(i.first, i.second);<br>> >> >> ><br>> >> >> > by:<br>> >> >> ><br>> >> >> > m_balanceCache.clear(i.first);<br>> >> >> ><br>> >> >> > or:<br>> >> >> ><br>> >> >> > m_balanceCache.clear();<br>> >> >> ><br>> >> >> > How could I detect that I are not calling the method "clear" in a<br>> >> >> > correct<br>> >> >> > way?<br>> >> >> ><br>> >> >> > I am aware that this is quite specific and may be difficult to create<br>> >> >> > test<br>> >> >> > cases for these situations, but I think that this is a very good<br>> >> >> > chance<br>> >> >> > to<br>> >> >> > improve the test suite of MyMoneyFile (a very important module in the<br>> >> >> > application).<br>> >> >> ><br>> >> >> > Does somebody know how to reveal the aforementioned faults modifying<br>> >> >> > existing test cases or designing a new one?<br>> >> >> ><br>> >> >> > Thanks in advance.<br>> >> >> ><br>> >> >> > _______________________________________________<br>> >> >> > KMyMoney-devel mailing list<br>> >> >> > KMyMoney-devel@kde.org<br>> >> >> > https://mail.kde.org/mailman/listinfo/kmymoney-devel<br>> >> >> ><br></div>                                        </div></body>
</html>