Commit ce8a6e57 authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

Improved tester

parent eb369a38
......@@ -94,9 +94,7 @@ BelCardParser::BelCardParser() {
}
BelCardParser::BelCardParser(std::string fileName) {
shared_ptr<Grammar> grammar = Grammar::loadVectRulesMap(fileName);
_parser = new Parser<shared_ptr<BelCardGeneric>>(grammar);
BelCardList::setHandlerAndCollectors(_parser);
......
......@@ -17,6 +17,7 @@
*/
#include <belr/belr.h>
#include "belcard/belcard.hpp"
#include "belcard/belcard_parser.hpp"
#include "belcard/belcard_utils.hpp"
......@@ -29,6 +30,7 @@
#include <string>
using namespace::std;
using namespace::belr;
using namespace::belcard;
static string openFile(const char *name) {
......@@ -135,20 +137,27 @@ static void property_sort_using_pref_param(void) {
BC_ASSERT_EQUAL((unsigned int)belCard->getProperties().size(), 1, unsigned int, "%u");
}
static void vcard_grammar_from_binary_dump(void) {
string grammarDumpFileName = bc_tester_file("vcardGrammarDump.bin");
remove(grammarDumpFileName.c_str());
ABNFGrammarBuilder grammar_builder;
shared_ptr<Grammar> grammar = grammar_builder.createFromAbnf((const char*)vcard_grammar, make_shared<CoreRules>());
grammar->createGrammarDump(grammarDumpFileName);
shared_ptr<Grammar> grammar2 = Grammar::loadVectRulesMap(grammarDumpFileName);
BC_ASSERT_TRUE(grammar->equal(grammar2));
}
static void vcard_parsing_serialized(void) {
string vcard = openFile("vcards/vcard.vcf");
remove("vcardGrammarDump.bin");
string grammarDump = bc_tester_file("grammarDump.bin");
remove(grammarDump.c_str());
string grammarDumpFileName = bc_tester_file("vcardGrammarDump.bin");
remove(grammarDumpFileName.c_str());
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(grammarDump);
remove(grammarDump.c_str());
grammar->createGrammarDump(grammarDumpFileName);
BelCardParser *parser = new BelCardParser(grammarDumpFileName);
shared_ptr<BelCard> belCard = parser->parseOne(vcard);
if (!BC_ASSERT_TRUE(belCard!=NULL)) return;
BC_ASSERT_TRUE(belCard->assertRFCCompliance());
......@@ -160,14 +169,9 @@ static void vcard_parsing_serialized(void) {
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);
string grammarDumpFileName = bc_tester_file("vcardGrammarDump.bin");
BelCardParser *parser = new BelCardParser(fileName);
BelCardParser *parser = new BelCardParser(grammarDumpFileName);
shared_ptr<BelCardList> belCards = parser->parse(vcards);
if (!BC_ASSERT_TRUE(belCards!=NULL)) return;
......@@ -185,6 +189,7 @@ static test_t tests[] = {
TEST_NO_TAG("VCards parsing", vcards_parsing),
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("VCard grammar from binary dump", vcard_grammar_from_binary_dump),
TEST_NO_TAG("VCard parsing serialized", vcard_parsing_serialized),
TEST_NO_TAG("VCards parsing serialized", vcards_parsing_serialized),
};
......
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