Skip to content

Commit 59d3050

Browse files
committed
Covering 100% of current code
1 parent 545da40 commit 59d3050

File tree

3 files changed

+56
-20
lines changed

3 files changed

+56
-20
lines changed

include/XmlJoiner.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class XmlJoiner
5050
QStringList _files;
5151

5252
QMap<QString, QString> _totalProperties; // tests, failures, errors
53-
std::vector<TestSuite *> _suites;
53+
std::vector<TestSuite *> _suites;
5454
}; // ----- end of class XmlJoiner -----
5555

5656
}

src/XmlJoiner.cpp

+17-19
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,18 @@ XmlJoiner::~XmlJoiner()
2626
void XmlJoiner::processFolder(const QString folder)
2727
{
2828
QDir xmlDir(folder);
29+
if (xmlDir.exists() == false)
30+
throw std::logic_error("processFolder - folder doesn't exist");
31+
2932
QStringList extensions("*.xml");
30-
foreach(const QString &file, xmlDir.entryList(extensions,
31-
QDir::Files | QDir::NoDotAndDotDot, QDir::Name))
33+
QStringList xmlFiles = xmlDir.entryList(extensions,
34+
QDir::Files | QDir::NoDotAndDotDot,
35+
QDir::Name);
36+
37+
if (xmlFiles.empty())
38+
throw std::logic_error("processFolder - folder doesn't contain xml files");
39+
40+
foreach(const QString &file, xmlFiles)
3241
{
3342
processFile(xmlDir.absoluteFilePath(file));
3443
}
@@ -40,11 +49,10 @@ void XmlJoiner::processFile(const QString absolutePath)
4049

4150
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
4251
{
43-
throw std::runtime_error("Error opening file " + absolutePath.toStdString());
52+
throw std::logic_error("ProcessFile - Error opening file " + absolutePath.toStdString());
4453
}
4554

4655
QXmlStreamReader xml(&file);
47-
4856
while(!xml.atEnd() && !xml.hasError())
4957
{
5058
QXmlStreamReader::TokenType token = xml.readNext();
@@ -64,7 +72,8 @@ void XmlJoiner::processFile(const QString absolutePath)
6472

6573
if(xml.hasError())
6674
{
67-
throw std::runtime_error("Error parsing the xml file " + absolutePath.toStdString());
75+
throw std::logic_error("ProcessFile - Error parsing the xml file " +
76+
absolutePath.toStdString());
6877
}
6978
}
7079

@@ -83,17 +92,11 @@ void XmlJoiner::processTestCaseAttrs(const QXmlStreamAttributes attrs)
8392

8493
if(attrs.hasAttribute("status")) // google tests case
8594
{
86-
if(attrs.value("status") != "run")
87-
{
88-
valid = attrs.value("status").toString();
89-
}
95+
/// \todo do specific stuff with google test xml file
9096
}
9197
else if(attrs.hasAttribute("result")) // qt tests case
9298
{
93-
if(attrs.value("result") != "pass")
94-
{
95-
valid = attrs.value("result").toString();
96-
}
99+
/// \todo do specific stuff with qtest xml file
97100
}
98101

99102
TestSuite *suite = _suites.back();
@@ -104,13 +107,8 @@ void XmlJoiner::processTestCaseAttrs(const QXmlStreamAttributes attrs)
104107
void XmlJoiner::writeOutput(const QString pathFile)
105108
{
106109
QFile outFile(pathFile);
107-
108110
if(!outFile.open(QIODevice::WriteOnly | QIODevice::Text))
109-
{
110-
qDebug() << "Error opening output file for writing";
111-
/// \todo throw exception and delete debug message
112-
exit(-1);
113-
}
111+
throw std::logic_error("writeOutput - Invalid output file for writting the combined XML");
114112

115113
QXmlStreamWriter xmlOut(&outFile);
116114
outputXmlHeader(xmlOut);

tests/TestXmlJoiner.cpp

+38
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "XmlJoiner.h"
1010

11+
#include <QDir>
1112
#include <gtest/gtest.h>
1213
#include <argtable2.h>
1314

@@ -40,8 +41,45 @@ TEST_F(TestXmlJoiner, shouldProcessExistingFolderWithXmls)
4041
ASSERT_NO_THROW(_joiner->processFolder(argPath->sval[0]));
4142
}
4243

44+
TEST_F(TestXmlJoiner, shouldNotProcessNonExistingFolder)
45+
{
46+
ASSERT_THROW(_joiner->processFolder("nonExistingFolder"), std::logic_error);
47+
}
48+
49+
TEST_F(TestXmlJoiner, shouldNotProcessExistingFolderWithoutXmlFiles)
50+
{
51+
ASSERT_THROW(_joiner->processFolder("CMakeFiles"), std::logic_error);
52+
}
53+
54+
TEST_F(TestXmlJoiner, shouldProcessExistingXmlFile)
55+
{
56+
QDir xmlDir(argPath->sval[0]);
57+
QStringList extensions("*.xml");
58+
QStringList xmlFiles = xmlDir.entryList(extensions,
59+
QDir::Files | QDir::NoDotAndDotDot,
60+
QDir::Name);
61+
if (xmlFiles.empty() == false)
62+
ASSERT_THROW(_joiner->processFile(xmlFiles[0]), std::logic_error);
63+
}
64+
65+
TEST_F(TestXmlJoiner, shouldNotProcessNonExistingFile)
66+
{
67+
ASSERT_THROW(_joiner->processFile("nonExistingFile"), std::logic_error);
68+
}
69+
70+
TEST_F(TestXmlJoiner, shouldNotProcessNonXmlFile)
71+
{
72+
ASSERT_THROW(_joiner->processFile("CMakeCache.txt"), std::logic_error);
73+
}
74+
4375
TEST_F(TestXmlJoiner, shouldWriteOutputFile)
4476
{
4577
ASSERT_NO_THROW(_joiner->processFolder(argPath->sval[0]));
4678
ASSERT_NO_THROW(_joiner->writeOutput("prueba"));
4779
}
80+
81+
TEST_F(TestXmlJoiner, shouldNotWriteOutputFile)
82+
{
83+
ASSERT_NO_THROW(_joiner->processFolder(argPath->sval[0]));
84+
ASSERT_THROW(_joiner->writeOutput("/root/prueba"), std::logic_error);
85+
}

0 commit comments

Comments
 (0)