Commit 3934436e authored by BenRejeb Iyed's avatar BenRejeb Iyed

belcard tester modifié

parent 44673761
......@@ -19,8 +19,8 @@
#ifndef belcard_parser_hpp
#define belcard_parser_hpp
#include <belr/grammarbuilder.h>
#include <belr/abnf.h>
#include <belr/grammarbuilder.hh>
#include <belr/abnf.hh>
#include "belcard_utils.hpp"
......@@ -41,6 +41,7 @@ namespace belcard {
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);
......
......@@ -93,6 +93,67 @@ BelCardParser::BelCardParser() {
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);
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() {
delete _parser;
}
......
......@@ -28,6 +28,7 @@
#include <sstream>
#include <string>
using namespace::belr;
using namespace::std;
using namespace::belcard;
......@@ -83,6 +84,46 @@ 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;
......@@ -140,6 +181,8 @@ 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