Commit 7524da1a authored by Ronan's avatar Ronan

Revert "belcard tester modifié"

This reverts commit 3934436e.
parent 3934436e
...@@ -19,8 +19,8 @@ ...@@ -19,8 +19,8 @@
#ifndef belcard_parser_hpp #ifndef belcard_parser_hpp
#define belcard_parser_hpp #define belcard_parser_hpp
#include <belr/grammarbuilder.hh> #include <belr/grammarbuilder.h>
#include <belr/abnf.hh> #include <belr/abnf.h>
#include "belcard_utils.hpp" #include "belcard_utils.hpp"
...@@ -28,22 +28,21 @@ namespace belcard { ...@@ -28,22 +28,21 @@ namespace belcard {
class BelCardGeneric; class BelCardGeneric;
class BelCardList; class BelCardList;
class BelCard; class BelCard;
class BelCardParser { class BelCardParser {
friend class BelCardProperty; friend class BelCardProperty;
private: private:
belr::Parser<std::shared_ptr<BelCardGeneric>> *_parser; belr::Parser<std::shared_ptr<BelCardGeneric>> *_parser;
protected: protected:
std::shared_ptr<BelCardGeneric> _parse(const std::string &input, const std::string &rule); std::shared_ptr<BelCardGeneric> _parse(const std::string &input, const std::string &rule);
public: public:
BELCARD_PUBLIC static std::shared_ptr<BelCardParser> getInstance(); BELCARD_PUBLIC static std::shared_ptr<BelCardParser> getInstance();
BELCARD_PUBLIC BelCardParser(); BELCARD_PUBLIC BelCardParser();
BELCARD_PUBLIC BelCardParser(std::string fileName);
BELCARD_PUBLIC ~BelCardParser(); BELCARD_PUBLIC ~BelCardParser();
BELCARD_PUBLIC std::shared_ptr<BelCard> parseOne(const std::string &input); BELCARD_PUBLIC std::shared_ptr<BelCard> parseOne(const std::string &input);
BELCARD_PUBLIC std::shared_ptr<BelCardList> parse(const std::string &input); BELCARD_PUBLIC std::shared_ptr<BelCardList> parse(const std::string &input);
BELCARD_PUBLIC std::shared_ptr<BelCardList> parseFile(const std::string &filename); BELCARD_PUBLIC std::shared_ptr<BelCardList> parseFile(const std::string &filename);
......
...@@ -38,76 +38,16 @@ BelCardParser::BelCardParser() { ...@@ -38,76 +38,16 @@ BelCardParser::BelCardParser() {
ABNFGrammarBuilder grammar_builder; ABNFGrammarBuilder grammar_builder;
shared_ptr<Grammar> grammar = grammar_builder.createFromAbnf((const char*)vcard_grammar, make_shared<CoreRules>()); shared_ptr<Grammar> grammar = grammar_builder.createFromAbnf((const char*)vcard_grammar, make_shared<CoreRules>());
_parser = new Parser<shared_ptr<BelCardGeneric>>(grammar); _parser = new Parser<shared_ptr<BelCardGeneric>>(grammar);
BelCardList::setHandlerAndCollectors(_parser);
BelCard::setHandlerAndCollectors(_parser);
BelCardParam::setAllParamsHandlersAndCollectors(_parser);
BelCardProperty::setHandlerAndCollectors(_parser);
BelCardSource::setHandlerAndCollectors(_parser);
BelCardKind::setHandlerAndCollectors(_parser);
BelCardXML::setHandlerAndCollectors(_parser);
BelCardFullName::setHandlerAndCollectors(_parser);
BelCardName::setHandlerAndCollectors(_parser);
BelCardNickname::setHandlerAndCollectors(_parser);
BelCardPhoto::setHandlerAndCollectors(_parser);
BelCardBirthday::setHandlerAndCollectors(_parser);
BelCardAnniversary::setHandlerAndCollectors(_parser);
BelCardGender::setHandlerAndCollectors(_parser);
BelCardAddress::setHandlerAndCollectors(_parser);
BelCardPhoneNumber::setHandlerAndCollectors(_parser);
BelCardEmail::setHandlerAndCollectors(_parser);
BelCardImpp::setHandlerAndCollectors(_parser);
BelCardLang::setHandlerAndCollectors(_parser);
BelCardTimezone::setHandlerAndCollectors(_parser);
BelCardGeo::setHandlerAndCollectors(_parser);
BelCardTitle::setHandlerAndCollectors(_parser);
BelCardRole::setHandlerAndCollectors(_parser);
BelCardLogo::setHandlerAndCollectors(_parser);
BelCardOrganization::setHandlerAndCollectors(_parser);
BelCardMember::setHandlerAndCollectors(_parser);
BelCardRelated::setHandlerAndCollectors(_parser);
BelCardCategories::setHandlerAndCollectors(_parser);
BelCardNote::setHandlerAndCollectors(_parser);
BelCardProductId::setHandlerAndCollectors(_parser);
BelCardRevision::setHandlerAndCollectors(_parser);
BelCardSound::setHandlerAndCollectors(_parser);
BelCardUniqueId::setHandlerAndCollectors(_parser);
BelCardClientProductIdMap::setHandlerAndCollectors(_parser);
BelCardURL::setHandlerAndCollectors(_parser);
BelCardKey::setHandlerAndCollectors(_parser);
BelCardFBURL::setHandlerAndCollectors(_parser);
BelCardCALADRURI::setHandlerAndCollectors(_parser);
BelCardCALURI::setHandlerAndCollectors(_parser);
BelCardBirthPlace::setHandlerAndCollectors(_parser);
BelCardDeathPlace::setHandlerAndCollectors(_parser);
BelCardDeathDate::setHandlerAndCollectors(_parser);
}
BelCardParser::BelCardParser(std::string fileName) {
shared_ptr<Grammar> grammar = Grammar::loadVectRulesMap(fileName);
_parser = new Parser<shared_ptr<BelCardGeneric>>(grammar);
BelCardList::setHandlerAndCollectors(_parser); BelCardList::setHandlerAndCollectors(_parser);
BelCard::setHandlerAndCollectors(_parser); BelCard::setHandlerAndCollectors(_parser);
BelCardParam::setAllParamsHandlersAndCollectors(_parser); BelCardParam::setAllParamsHandlersAndCollectors(_parser);
BelCardProperty::setHandlerAndCollectors(_parser); BelCardProperty::setHandlerAndCollectors(_parser);
BelCardSource::setHandlerAndCollectors(_parser); BelCardSource::setHandlerAndCollectors(_parser);
BelCardKind::setHandlerAndCollectors(_parser); BelCardKind::setHandlerAndCollectors(_parser);
BelCardXML::setHandlerAndCollectors(_parser); BelCardXML::setHandlerAndCollectors(_parser);
BelCardFullName::setHandlerAndCollectors(_parser); BelCardFullName::setHandlerAndCollectors(_parser);
BelCardName::setHandlerAndCollectors(_parser); BelCardName::setHandlerAndCollectors(_parser);
BelCardNickname::setHandlerAndCollectors(_parser); BelCardNickname::setHandlerAndCollectors(_parser);
...@@ -115,24 +55,24 @@ BelCardParser::BelCardParser(std::string fileName) { ...@@ -115,24 +55,24 @@ BelCardParser::BelCardParser(std::string fileName) {
BelCardBirthday::setHandlerAndCollectors(_parser); BelCardBirthday::setHandlerAndCollectors(_parser);
BelCardAnniversary::setHandlerAndCollectors(_parser); BelCardAnniversary::setHandlerAndCollectors(_parser);
BelCardGender::setHandlerAndCollectors(_parser); BelCardGender::setHandlerAndCollectors(_parser);
BelCardAddress::setHandlerAndCollectors(_parser); BelCardAddress::setHandlerAndCollectors(_parser);
BelCardPhoneNumber::setHandlerAndCollectors(_parser); BelCardPhoneNumber::setHandlerAndCollectors(_parser);
BelCardEmail::setHandlerAndCollectors(_parser); BelCardEmail::setHandlerAndCollectors(_parser);
BelCardImpp::setHandlerAndCollectors(_parser); BelCardImpp::setHandlerAndCollectors(_parser);
BelCardLang::setHandlerAndCollectors(_parser); BelCardLang::setHandlerAndCollectors(_parser);
BelCardTimezone::setHandlerAndCollectors(_parser); BelCardTimezone::setHandlerAndCollectors(_parser);
BelCardGeo::setHandlerAndCollectors(_parser); BelCardGeo::setHandlerAndCollectors(_parser);
BelCardTitle::setHandlerAndCollectors(_parser); BelCardTitle::setHandlerAndCollectors(_parser);
BelCardRole::setHandlerAndCollectors(_parser); BelCardRole::setHandlerAndCollectors(_parser);
BelCardLogo::setHandlerAndCollectors(_parser); BelCardLogo::setHandlerAndCollectors(_parser);
BelCardOrganization::setHandlerAndCollectors(_parser); BelCardOrganization::setHandlerAndCollectors(_parser);
BelCardMember::setHandlerAndCollectors(_parser); BelCardMember::setHandlerAndCollectors(_parser);
BelCardRelated::setHandlerAndCollectors(_parser); BelCardRelated::setHandlerAndCollectors(_parser);
BelCardCategories::setHandlerAndCollectors(_parser); BelCardCategories::setHandlerAndCollectors(_parser);
BelCardNote::setHandlerAndCollectors(_parser); BelCardNote::setHandlerAndCollectors(_parser);
BelCardProductId::setHandlerAndCollectors(_parser); BelCardProductId::setHandlerAndCollectors(_parser);
...@@ -141,19 +81,18 @@ BelCardParser::BelCardParser(std::string fileName) { ...@@ -141,19 +81,18 @@ BelCardParser::BelCardParser(std::string fileName) {
BelCardUniqueId::setHandlerAndCollectors(_parser); BelCardUniqueId::setHandlerAndCollectors(_parser);
BelCardClientProductIdMap::setHandlerAndCollectors(_parser); BelCardClientProductIdMap::setHandlerAndCollectors(_parser);
BelCardURL::setHandlerAndCollectors(_parser); BelCardURL::setHandlerAndCollectors(_parser);
BelCardKey::setHandlerAndCollectors(_parser); BelCardKey::setHandlerAndCollectors(_parser);
BelCardFBURL::setHandlerAndCollectors(_parser); BelCardFBURL::setHandlerAndCollectors(_parser);
BelCardCALADRURI::setHandlerAndCollectors(_parser); BelCardCALADRURI::setHandlerAndCollectors(_parser);
BelCardCALURI::setHandlerAndCollectors(_parser); BelCardCALURI::setHandlerAndCollectors(_parser);
BelCardBirthPlace::setHandlerAndCollectors(_parser); BelCardBirthPlace::setHandlerAndCollectors(_parser);
BelCardDeathPlace::setHandlerAndCollectors(_parser); BelCardDeathPlace::setHandlerAndCollectors(_parser);
BelCardDeathDate::setHandlerAndCollectors(_parser); BelCardDeathDate::setHandlerAndCollectors(_parser);
} }
BelCardParser::~BelCardParser() { BelCardParser::~BelCardParser() {
delete _parser; delete _parser;
} }
......
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
#include <sstream> #include <sstream>
#include <string> #include <string>
using namespace::belr;
using namespace::std; using namespace::std;
using namespace::belcard; using namespace::belcard;
...@@ -84,46 +83,6 @@ static void vcards_parsing(void) { ...@@ -84,46 +83,6 @@ static void vcards_parsing(void) {
delete(parser); delete(parser);
} }
static void vcard_parsing_serialized(void) {
string vcard = openFile("vcards/vcard.vcf");
remove("vcardGrammarDump.bin");
string fileName = "vcardGrammarDump.bin";
belr::ABNFGrammarBuilder grammar_builder;
shared_ptr<belr::Grammar> grammar = grammar_builder.createFromAbnf((const char*)vcard_grammar, make_shared<belr::CoreRules>());
grammar->createGrammarDump(fileName);
BelCardParser *parser = new BelCardParser("vcardGrammarDump.bin");
shared_ptr<BelCard> belCard = parser->parseOne(vcard);
if (!BC_ASSERT_TRUE(belCard!=NULL)) return;
BC_ASSERT_TRUE(belCard->assertRFCCompliance());
string vcard2 = belCard->toFoldedString();
BC_ASSERT_EQUAL(vcard2.compare(vcard), 0, int, "%d");
delete(parser);
}
static void vcards_parsing_serialized(void) {
string vcards = openFile("vcards/vcards.vcf");
string fileName = "vcardGrammarDump.bin";
remove("vcardGrammarDump.bin");
belr::ABNFGrammarBuilder grammar_builder;
shared_ptr<belr::Grammar> grammar = grammar_builder.createFromAbnf((const char*)vcard_grammar, make_shared<belr::CoreRules>());
grammar->createGrammarDump(fileName);
BelCardParser *parser = new BelCardParser(fileName);
shared_ptr<BelCardList> belCards = parser->parse(vcards);
if (!BC_ASSERT_TRUE(belCards!=NULL)) return;
BC_ASSERT_EQUAL((unsigned int)belCards->getCards().size(), 2, unsigned int, "%u");
string vcards2 = belCards->toString();
BC_ASSERT_EQUAL(vcards2.compare(vcards), 0, int, "%d");
delete(parser);
}
static void create_vcard_from_api(void) { static void create_vcard_from_api(void) {
shared_ptr<BelCard> belCard = BelCard::create<BelCard>(); shared_ptr<BelCard> belCard = BelCard::create<BelCard>();
if (!BC_ASSERT_TRUE(belCard!=NULL)) return; if (!BC_ASSERT_TRUE(belCard!=NULL)) return;
...@@ -134,7 +93,7 @@ static void create_vcard_from_api(void) { ...@@ -134,7 +93,7 @@ static void create_vcard_from_api(void) {
belCard->setFullName(fn); belCard->setFullName(fn);
BC_ASSERT_TRUE(belCard->assertRFCCompliance()); BC_ASSERT_TRUE(belCard->assertRFCCompliance());
BC_ASSERT_STRING_EQUAL(belCard->getFullName()->toString().c_str(), fn->toString().c_str()); BC_ASSERT_STRING_EQUAL(belCard->getFullName()->toString().c_str(), fn->toString().c_str());
fn = BelCard::create<BelCardFullName>(); fn = BelCard::create<BelCardFullName>();
fn->setValue("Belcard Tester"); fn->setValue("Belcard Tester");
belCard->setFullName(fn); belCard->setFullName(fn);
...@@ -167,10 +126,10 @@ static void property_sort_using_pref_param(void) { ...@@ -167,10 +126,10 @@ static void property_sort_using_pref_param(void) {
BC_ASSERT_EQUAL((unsigned int)imppList.size(), 2, unsigned int, "%u"); BC_ASSERT_EQUAL((unsigned int)imppList.size(), 2, unsigned int, "%u");
BC_ASSERT_TRUE(imppList.front() == impp2); BC_ASSERT_TRUE(imppList.front() == impp2);
BC_ASSERT_TRUE(imppList.back() == impp1); BC_ASSERT_TRUE(imppList.back() == impp1);
const list<shared_ptr<BelCardProperty>> propertiesList = belCard->getProperties(); const list<shared_ptr<BelCardProperty>> propertiesList = belCard->getProperties();
BC_ASSERT_EQUAL((unsigned int)propertiesList.size(), 2, unsigned int, "%u"); BC_ASSERT_EQUAL((unsigned int)propertiesList.size(), 2, unsigned int, "%u");
belCard->removeImpp(impp1); belCard->removeImpp(impp1);
BC_ASSERT_EQUAL((unsigned int)belCard->getImpp().size(), 1, unsigned int, "%u"); BC_ASSERT_EQUAL((unsigned int)belCard->getImpp().size(), 1, unsigned int, "%u");
BC_ASSERT_EQUAL((unsigned int)belCard->getProperties().size(), 1, unsigned int, "%u"); BC_ASSERT_EQUAL((unsigned int)belCard->getProperties().size(), 1, unsigned int, "%u");
...@@ -181,8 +140,6 @@ static test_t tests[] = { ...@@ -181,8 +140,6 @@ static test_t tests[] = {
TEST_NO_TAG("Unfolding", unfolding), TEST_NO_TAG("Unfolding", unfolding),
TEST_NO_TAG("VCard parsing", vcard_parsing), TEST_NO_TAG("VCard parsing", vcard_parsing),
TEST_NO_TAG("VCards parsing", vcards_parsing), TEST_NO_TAG("VCards parsing", vcards_parsing),
TEST_NO_TAG("VCard parsing serialized", vcard_parsing_serialized),
TEST_NO_TAG("VCards parsing serialized", vcards_parsing_serialized),
TEST_NO_TAG("VCard created from scratch", create_vcard_from_api), TEST_NO_TAG("VCard created from scratch", create_vcard_from_api),
TEST_NO_TAG("Property sort using pref param", property_sort_using_pref_param), TEST_NO_TAG("Property sort using pref param", property_sort_using_pref_param),
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment