[TEST] increase coverage

This commit is contained in:
Edouard DUPIN 2016-04-13 23:39:22 +02:00
parent 401f6905e1
commit 58109b07b6
15 changed files with 284 additions and 84 deletions

View File

@ -33,6 +33,7 @@ namespace exml {
* @brief Enable or diasable the case sensitive (must be done before the call of parsing)
* @param[in] _val true if enable; false else.
*/
// TODO: Naming error, it is insensitive ...
virtual void setCaseSensitive(bool _val) {
m_caseSensitive = _val;
};

View File

@ -31,7 +31,18 @@ def get_maintainer():
def create(target, module_name):
my_module = module.Module(__file__, module_name, get_type())
my_module.add_src_file([
'test/main.cpp'
'test/main.cpp',
'test/exmlTestAll.cpp',
'test/exmlTestComment.cpp',
'test/exmlTestElement.cpp',
'test/exmlTestAttribute.cpp',
'test/exmlTestCommon.cpp',
'test/exmlTestDeclaration.cpp',
'test/exmlTestDeclarationXML.cpp',
'test/exmlTestParseComment.cpp',
'test/exmlTestParseElement.cpp',
'test/exmlTestParseAttribute.cpp',
'test/exmlTestParseDeclaration.cpp'
])
my_module.add_module_depend(['exml', 'gtest', 'test-debug'])
return my_module

View File

@ -1,11 +1,10 @@
/**
/** @file
* @author Edouard DUPIN
*
* @copyright 2014, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
#pragma once
#include "exmlTestCommon.h"
#include <gtest/gtest.h>
@ -38,4 +37,20 @@ TEST(TestAll, testError) {
1);
}
TEST(TestAll, testCaseSensitive) {
exmlLocalTest( "<exemple>\n"
" <ex2 ploppp-plpl:erer=\"dfsdfsdfsdf\" lkmjmlk=\"156235\" sdfsdf=\"456321\"/>\n"
" <exlkjl-_dsfg./>\n"
" <ex2>Text example ...</ex2>\n"
"</exemple>\n",
"< exemple\n >\n"
" <ex2 ploppp-plpl:erer=\"dfsdfsdfsdf\" lkmjmlk=\"156235\" sdfsdf=456321 />\n"
" <exlkjl-_dsfg./>\n"
" <ex2>\n"
" Text example ...\n"
" </ex2>\n"
"</exemple>\n",
1,
false);
}

View File

@ -0,0 +1,31 @@
/** @file
* @author Edouard DUPIN
*
* @copyright 2014, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
#include <gtest/gtest.h>
#include <exml/exml.h>
#include <exml/Attribute.h>
TEST(TestAttribute, create) {
exml::Attribute myAttribute("nameAttribute", "valueAttribute");
EXPECT_EQ(myAttribute.getType(), exml::nodeType_attribute);
}
TEST(TestAttribute, createCopy) {
exml::Attribute myAttribute("nameAttribute", "valueAttribute");
exml::Attribute myOtherAttribute(myAttribute);
//EXPECT_EQ(myAttribute, myOtherAttribute);
}
TEST(TestAttribute, createAssignement) {
exml::Attribute myAttribute("nameAttribute", "valueAttribute");
exml::Attribute myOtherAttribute = myAttribute;
//EXPECT_EQ(myAttribute, myOtherAttribute);
}

28
test/exmlTestComment.cpp Normal file
View File

@ -0,0 +1,28 @@
/** @file
* @author Edouard DUPIN
*
* @copyright 2014, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
#include <gtest/gtest.h>
#include <exml/exml.h>
#include <exml/Comment.h>
TEST(TestComment, create) {
exml::Comment myComment("my Comment");
EXPECT_EQ(myComment.getType(), exml::nodeType_comment);
}
TEST(TestComment, createCopy) {
exml::Comment myComment("my Comment");
exml::Comment myOtherComment(myComment);
//EXPECT_EQ(myComment, myOtherComment);
}
TEST(TestComment, createAssignement) {
exml::Comment myComment("my comment");
exml::Comment myOtherComment = myComment;
//EXPECT_EQ(myComment, myOtherComment);
}

44
test/exmlTestCommon.cpp Normal file
View File

@ -0,0 +1,44 @@
/** @file
* @author Edouard DUPIN
*
* @copyright 2014, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
#include <etk/types.h>
#include <test-debug/debug.h>
#include <exml/exml.h>
#include <gtest/gtest.h>
// _errorPos : -1 : no error , 1 : parsing error, 2 generation error, 3 comparaison error ????
void exmlLocalTest(const std::string& _ref,
const std::string& _input,
int32_t _errorPos,
bool _caseInSensitive=false) {
exml::Document doc;
//doc.setCaseSensitive(!_caseInSensitive);
//EXML_DEBUG("parse : \n" << l_list[iii].m_input);
bool retParse = doc.parse(_input);
if (_errorPos == 1) {
EXPECT_EQ(retParse, false);
return;
} else {
EXPECT_EQ(retParse, true);
}
std::string out("");
bool retGenerate = doc.generate(out);
if (_errorPos == 2) {
EXPECT_EQ(retGenerate, false);
return;
} else {
EXPECT_EQ(retGenerate, true);
}
if (_errorPos == 3) {
EXPECT_NE(_ref, out);
return;
} else {
EXPECT_EQ(_ref, out);
}
}

View File

@ -1,4 +1,4 @@
/**
/** @file
* @author Edouard DUPIN
*
* @copyright 2014, Edouard DUPIN, all right reserved
@ -8,33 +8,10 @@
#pragma once
#include <etk/types.h>
#include <test-debug/debug.h>
#include <exml/exml.h>
// _errorPos : -1 : no error , 1 : parsing error, 2 generation error, 3 comparaison error ????
static void exmlLocalTest(const std::string& _ref, const std::string& _input, int32_t _errorPos) {
exml::Document doc;
//EXML_DEBUG("parse : \n" << l_list[iii].m_input);
bool retParse = doc.parse(_input);
if (_errorPos == 1) {
EXPECT_EQ(retParse, false);
return;
} else {
EXPECT_EQ(retParse, true);
}
std::string out("");
bool retGenerate = doc.generate(out);
if (_errorPos == 2) {
EXPECT_EQ(retGenerate, false);
return;
} else {
EXPECT_EQ(retGenerate, true);
}
if (_errorPos == 3) {
EXPECT_NE(_ref, out);
return;
} else {
EXPECT_EQ(_ref, out);
}
}
void exmlLocalTest(const std::string& _ref,
const std::string& _input,
int32_t _errorPos,
bool _caseInSensitive=false);

View File

@ -0,0 +1,29 @@
/** @file
* @author Edouard DUPIN
*
* @copyright 2014, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
#include <gtest/gtest.h>
#include <exml/exml.h>
#include <exml/Declaration.h>
TEST(TestDeclaration, create) {
exml::Declaration myDeclaration("type");
EXPECT_EQ(myDeclaration.getType(), exml::nodeType_declaration);
}
TEST(TestDeclaration, createCopy) {
exml::Declaration myDeclaration("type");
exml::Declaration myOtherDeclaration(myDeclaration);
//EXPECT_EQ(myDeclaration, myOtherDeclaration);
}
TEST(TestDeclaration, createAssignement) {
exml::Declaration myDeclaration("type");
exml::Declaration myOtherDeclaration = myDeclaration;
//EXPECT_EQ(myDeclaration, myOtherDeclaration);
}

View File

@ -0,0 +1,29 @@
/** @file
* @author Edouard DUPIN
*
* @copyright 2014, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
#include <gtest/gtest.h>
#include <exml/exml.h>
#include <exml/Declaration.h>
TEST(TestDeclarationXML, create) {
exml::DeclarationXML myDeclarationXML("1.0", "UTF-8", true);
EXPECT_EQ(myDeclarationXML.getType(), exml::nodeType_declaration);
}
TEST(TestDeclarationXML, createCopy) {
exml::DeclarationXML myDeclarationXML("1.0", "UTF-8", true);
exml::DeclarationXML myOtherDeclarationXML(myDeclarationXML);
//EXPECT_EQ(myDeclarationXML, myOtherDeclarationXML);
}
TEST(TestDeclarationXML, createAssignement) {
exml::DeclarationXML myDeclarationXML("1.0", "UTF-8", true);
exml::DeclarationXML myOtherDeclarationXML = myDeclarationXML;
//EXPECT_EQ(myDeclarationXML, myOtherDeclarationXML);
}

30
test/exmlTestElement.cpp Normal file
View File

@ -0,0 +1,30 @@
/** @file
* @author Edouard DUPIN
*
* @copyright 2014, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
#include <gtest/gtest.h>
#include <exml/exml.h>
#include <exml/Element.h>
TEST(TestElement, create) {
exml::Element myElement("NodeName");
//EXPECT_EQ(myElement.getType(), exml::nodeType_element);
}
TEST(TestElement, createCopy) {
exml::Element myElement("NodeName");
exml::Element myOtherElement(myElement);
//EXPECT_EQ(myElement, myOtherElement);
}
TEST(TestElement, createAssignement) {
exml::Element myElement("NodeName");
exml::Element myOtherElement = myElement;
//EXPECT_EQ(myElement, myOtherElement);
}

View File

@ -1,58 +1,71 @@
/**
/** @file
* @author Edouard DUPIN
*
* @copyright 2014, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
#pragma once
#include "exmlTestCommon.h"
#include <gtest/gtest.h>
TEST(TestAttribute, testBase) {
TEST(TestParseAttribute, testBase) {
exmlLocalTest("<elementtt attr=\"plop\"/>\n",
"<elementtt attr=\"plop\"/>\n",
-1);
}
TEST(TestAttribute, testNoQuote) {
TEST(TestParseAttribute, testNoQuote) {
exmlLocalTest("<elementtt attr=\"plop\"/>\n",
"<elementtt attr=plop/>\n",
-1);
}
TEST(TestAttribute, testNoQuoteNumber) {
TEST(TestParseAttribute, testNoQuoteNumber) {
exmlLocalTest("<elementtt attr=\"234345@3452345_.'\"/>\n",
"<elementtt attr=234345@3452345_.' />\n",
-1);
}
TEST(TestAttribute, testSpace1) {
TEST(TestParseAttribute, testSpace1) {
exmlLocalTest("<elementtt attr=\"plop\"/>\n",
"<elementtt attr =\"plop\"/>\n",
-1);
}
TEST(TestAttribute, testSpace2) {
TEST(TestParseAttribute, testSpace2) {
exmlLocalTest("<elementtt attr=\"plop\"/>\n",
"<elementtt attr= \"plop\"/>\n",
-1);
}
TEST(TestAttribute, testMultiline) {
TEST(TestParseAttribute, testMultiline) {
exmlLocalTest("<elementtt attr=\"plop\"/>\n",
"<elementtt attr\n=\n\"plop\"/>\n",
-1);
}
TEST(TestAttribute, testMultilineNoQuote) {
TEST(TestParseAttribute, testMultilineNoQuote) {
exmlLocalTest("<elementtt attr=\"plop\"/>\n",
"<elementtt attr \n = \n\t plop/>\n",
-1);
}
TEST(TestAttribute, testEmptyAttribute) {
TEST(TestParseAttribute, testEmptyAttribute) {
exmlLocalTest("<elementtt attr=\"\"/>\n",
"<elementtt attr=\"\"/>\n",
-1);
}
TEST(TestAttribute, testEmptyAttributeNoQuote) {
TEST(TestParseAttribute, testEmptyAttributeNoQuote) {
exmlLocalTest("<elementtt attr=\"\"/>\n",
"<elementtt attr=/>\n",
-1);
}
TEST(TestParseAttribute, testEndAttributeError) {
exmlLocalTest("",
"<elementtt attr",
1);
}
TEST(TestParseAttribute, testEndAttributeErrorMissingEqual) {
exmlLocalTest("",
"<elementtt attr \"kjlkj\"/>\n",
1);
}

View File

@ -1,38 +1,38 @@
/**
/** @file
* @author Edouard DUPIN
*
* @copyright 2014, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
#pragma once
#include "exmlTestCommon.h"
#include <gtest/gtest.h>
TEST(TestComment, testBase) {
TEST(TestParseComment, testBase) {
exmlLocalTest("<!--exemple-->\n", "<!--exemple-->\n", -1);
}
TEST(TestComment, testMultiline) {
TEST(TestParseComment, testMultiline) {
exmlLocalTest("<!--exemple-->\n", "<!-- \t \t\t exemple \n\n\n\t-->\n", -1);
}
TEST(TestComment, testTiretInComment) {
TEST(TestParseComment, testTiretInComment) {
exmlLocalTest("<!---- exemple-->\n", "<!-- -- exemple -->\n", -1);
}
TEST(TestComment, testWrongEndParsing) {
TEST(TestParseComment, testWrongEndParsing) {
exmlLocalTest("<!--> exemple-->\n", "<!--> exemple -->\n", -1);
}
TEST(TestComment, testMultipleEnd) {
TEST(TestParseComment, testMultipleEnd) {
exmlLocalTest("<!--exemple-->\n", "<!-- ---> exemple -->\n", 1);
}
TEST(TestComment, testEndError) {
TEST(TestParseComment, testEndError) {
exmlLocalTest("<!--exemple-->\n", "<!-- ssdfgdfg >\n", 1);
}
TEST(TestComment, testNoCharInComment) {
TEST(TestParseComment, testNoCharInComment) {
exmlLocalTest("<!---->\n", "<!---->\n", -1);
}
TEST(TestComment, testAll) {
TEST(TestParseComment, testAll) {
exmlLocalTest("<!--<.:!*%^$0945- '(- &<<< >>> '& ( '( '-' <elementPouris>-->\n",
"<!-- <.:!*%^$0945- '(- &<<< >>> '& ( '( '-' <elementPouris> -->\n",
-1);

View File

@ -1,38 +1,38 @@
/**
/** @file
* @author Edouard DUPIN
*
* @copyright 2014, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
#pragma once
#include "exmlTestCommon.h"
#include <gtest/gtest.h>
TEST(TestDeclaration, testBase) {
TEST(TestParseDeclaration, testBase) {
exmlLocalTest("<?testDeclaration?>\n", "<?testDeclaration?>\n", -1);
}
TEST(TestDeclaration, testAttribute) {
TEST(TestParseDeclaration, testAttribute) {
exmlLocalTest("<?xml attr=\"plop\"?>\n", "<?xml attr=\"plop\"?>\n", -1);
}
TEST(TestDeclaration, testNoQuote) {
TEST(TestParseDeclaration, testNoQuote) {
exmlLocalTest("<?xml attr=\"plop\"?>\n", "<?xml attr=plop?>\n", -1);
}
TEST(TestDeclaration, testNumberNoQuote) {
TEST(TestParseDeclaration, testNumberNoQuote) {
exmlLocalTest("<?xml attr=\"234345@3452345_.'\"?>\n", "<?xml attr=234345@3452345_.' ?>\n", -1);
}
TEST(TestDeclaration, testSpace1) {
TEST(TestParseDeclaration, testSpace1) {
exmlLocalTest("<?xml attr=\"plop\"?>\n", "<?xml attr =\"plop\"?>\n", -1);
}
TEST(TestDeclaration, testSpace2) {
TEST(TestParseDeclaration, testSpace2) {
exmlLocalTest("<?xml attr=\"plop\"?>\n", "<?xml attr= \"plop\"?>\n", -1);
}
TEST(TestDeclaration, testMultiline) {
TEST(TestParseDeclaration, testMultiline) {
exmlLocalTest("<?xml attr=\"plop\"?>\n", "<?xml attr\n=\n\"plop\"?>\n", -1);
}
TEST(TestDeclaration, testAll) {
TEST(TestParseDeclaration, testAll) {
exmlLocalTest("<?xml attr=\"p65421lop\"?>\n", "<?xml attr \n = \n\t p65421lop?>\n", -1);
}

View File

@ -1,11 +1,10 @@
/**
/** @file
* @author Edouard DUPIN
*
* @copyright 2014, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
#pragma once
#include "exmlTestCommon.h"
#include <gtest/gtest.h>
@ -13,44 +12,44 @@
static std::string refOutputElement("<exemple/>\n");
TEST(TestElement, testBase) {
TEST(TestParseElement, testBase) {
exmlLocalTest(refOutputElement, "<exemple/>\n", -1);
}
TEST(TestElement, testMultiline) {
TEST(TestParseElement, testMultiline) {
exmlLocalTest(refOutputElement, "< \t\r exemple/>\n", -1);
}
TEST(TestElement, testMultilineMultiTabbed) {
TEST(TestParseElement, testMultilineMultiTabbed) {
exmlLocalTest(refOutputElement, "< \t\r exemple \t\r\r\r\n \t\t />\n", -1);
}
TEST(TestElement, testWrongStart) {
TEST(TestParseElement, testWrongStart) {
exmlLocalTest(refOutputElement, "< exemple < >\n", 1);
}
TEST(TestElement, testMultipleSlash) {
TEST(TestParseElement, testMultipleSlash) {
exmlLocalTest(refOutputElement, "< exemple / />\n", 1);
}
TEST(TestElement, testExclamationPresence) {
TEST(TestParseElement, testExclamationPresence) {
exmlLocalTest(refOutputElement, "< exemple ? />\n", 1);
}
TEST(TestElement, testStarPresence) {
TEST(TestParseElement, testStarPresence) {
exmlLocalTest(refOutputElement, "< exemple * />\n", 1);
}
TEST(TestElement, testDotPresent) {
TEST(TestParseElement, testDotPresent) {
exmlLocalTest(refOutputElement, "< . exemple < />\n", 1);
}
TEST(TestElement, testWrong1) {
TEST(TestParseElement, testWrong1) {
exmlLocalTest(refOutputElement, "<! exemple < />\n", 1);
}
TEST(TestElement, testWrong2) {
TEST(TestParseElement, testWrong2) {
exmlLocalTest(refOutputElement, "<!- exemple < />\n", 1);
}
TEST(TestElement, testWrong3) {
TEST(TestParseElement, testWrong3) {
exmlLocalTest(refOutputElement, "< exemple < />\n", 1);
}
TEST(TestElement, testBase2) {
TEST(TestParseElement, testBase2) {
exmlLocalTest("<exemple--/>\n", "<exemple-->\n", 1);
}
TEST(TestElement, testBase3) {
TEST(TestParseElement, testBase3) {
exmlLocalTest("<exemple/>\n", "<exemple>\n</exemple sdfgsdfg>\n", 1);
}

View File

@ -7,17 +7,10 @@
*/
#include <test-debug/debug.h>
#include <vector>
#include <gtest/gtest.h>
#include <etk/os/FSNode.h>
#include <etk/etk.h>
//#include "exmlTestDocument.h"
#include "exmlTestElement.h"
#include "exmlTestAttribute.h"
#include "exmlTestDeclaration.h"
#include "exmlTestAll.h"
int main(int argc, const char *argv[]) {
// init Google test :
::testing::InitGoogleTest(&argc, const_cast<char **>(argv));