Commit 7524da1a authored by Ronan's avatar Ronan

Revert "belcard tester modifié"

This reverts commit 3934436e.
parent 3934436e
......@@ -19,8 +19,8 @@
#ifndef belcard_parser_hpp
#define belcard_parser_hpp
#include <belr/grammarbuilder.hh>
#include <belr/abnf.hh>
#include <belr/grammarbuilder.h>
#include <belr/abnf.h>
#include "belcard_utils.hpp"
......@@ -28,22 +28,21 @@ namespace belcard {
class BelCardGeneric;
class BelCardList;
class BelCard;
class BelCardParser {
friend class BelCardProperty;
private:
belr::Parser<std::shared_ptr<BelCardGeneric>> *_parser;
protected:
std::shared_ptr<BelCardGeneric> _parse(const std::string &input, const std::string &rule);
public:
BELCARD_PUBLIC static std::shared_ptr<BelCardParser> getInstance();
BELCARD_PUBLIC BelCardParser();
BELCARD_PUBLIC BelCardParser(std::string fileName);
BELCARD_PUBLIC ~BelCardParser();
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> parseFile(const std::string &filename);
......
......@@ -38,76 +38,16 @@ BelCardParser::BelCardParser() {
ABNFGrammarBuilder grammar_builder;
shared_ptr<Grammar> grammar = grammar_builder.createFromAbnf((const char*)vcard_grammar, make_shared<CoreRules>());
_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);
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);
......@@ -115,24 +55,24 @@ BelCardParser::BelCardParser(std::string fileName) {
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);
......@@ -141,19 +81,18 @@ BelCardParser::BelCardParser(std::string fileName) {
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() {
delete _parser;
}
......
......@@ -28,7 +28,6 @@
#include <sstream>
#include <string>
using namespace::belr;
using namespace::std;
using namespace::belcard;
......@@ -84,46 +83,6 @@ static void vcards_parsing(void) {
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) {
shared_ptr<BelCard> belCard = BelCard::create<BelCard>();
if (!BC_ASSERT_TRUE(belCard!=NULL)) return;
......@@ -134,7 +93,7 @@ static void create_vcard_from_api(void) {
belCard->setFullName(fn);
BC_ASSERT_TRUE(belCard->assertRFCCompliance());
BC_ASSERT_STRING_EQUAL(belCard->getFullName()->toString().c_str(), fn->toString().c_str());
fn = BelCard::create<BelCardFullName>();
fn->setValue("Belcard Tester");
belCard->setFullName(fn);
......@@ -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_TRUE(imppList.front() == impp2);
BC_ASSERT_TRUE(imppList.back() == impp1);
const list<shared_ptr<BelCardProperty>> propertiesList = belCard->getProperties();
BC_ASSERT_EQUAL((unsigned int)propertiesList.size(), 2, unsigned int, "%u");
belCard->removeImpp(impp1);
BC_ASSERT_EQUAL((unsigned int)belCard->getImpp().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[] = {
TEST_NO_TAG("Unfolding", unfolding),
TEST_NO_TAG("VCard parsing", vcard_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("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