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

Fixed GEO property according to RFC 6350 Errata ID: 3846 + Added properties from RFC 6474

parent e6968f2f
......@@ -13,6 +13,7 @@ belcard_include_HEADERS = belcard.hpp \
belcard_explanatory.hpp \
belcard_security.hpp \
belcard_calendar.hpp \
belcard_rfc6474.hpp \
belcard_parser.hpp \
vcard_grammar.hpp \
belcard_utils.hpp
......
......@@ -94,6 +94,7 @@ namespace belcard {
virtual void addParam(const shared_ptr<BelCardParam> &param);
virtual const list<shared_ptr<BelCardParam>> &getParams() const;
virtual void removeParam(const shared_ptr<BelCardParam> &param);
virtual void serialize(ostream &output) const;
};
......
#ifndef belcard_rfc6474_hpp
#define belcard_rfc6474_hpp
#include "belcard_property.hpp"
#include <belr/grammarbuilder.hh>
#include <belr/abnf.hh>
#include <string>
#include <sstream>
using namespace::std;
using namespace::belr;
namespace belcard {
class BelCardBirthPlace : public BelCardProperty {
private:
public:
static shared_ptr<BelCardBirthPlace> parse(const string& input);
static void setHandlerAndCollectors(Parser<shared_ptr<BelCardGeneric>> *parser);
BelCardBirthPlace();
};
class BelCardDeathPlace : public BelCardProperty {
private:
public:
static shared_ptr<BelCardDeathPlace> parse(const string& input);
static void setHandlerAndCollectors(Parser<shared_ptr<BelCardGeneric>> *parser);
BelCardDeathPlace();
};
class BelCardDeathDate : public BelCardProperty {
private:
public:
static shared_ptr<BelCardDeathDate> parse(const string& input);
static void setHandlerAndCollectors(Parser<shared_ptr<BelCardGeneric>> *parser);
BelCardDeathDate();
};
}
#endif
\ No newline at end of file
......@@ -18,6 +18,7 @@ libbelcard_la_SOURCES=belcard_parser.cpp \
belcard_explanatory.cpp \
belcard_security.cpp \
belcard_calendar.cpp \
belcard_rfc6474.cpp \
vcard_grammar.cpp \
belcard_utils.cpp
......
......@@ -42,6 +42,9 @@ const string &BelCardProperty::getValue() const {
}
void BelCardProperty::setLanguageParam(const shared_ptr<BelCardLanguageParam> &param) {
if (_lang_param) {
removeParam(_lang_param);
}
_lang_param = param;
_params.push_back(_lang_param);
}
......@@ -50,6 +53,9 @@ const shared_ptr<BelCardLanguageParam> &BelCardProperty::getLanguageParam() cons
}
void BelCardProperty::setValueParam(const shared_ptr<BelCardValueParam> &param) {
if (_value_param) {
removeParam(_value_param);
}
_value_param = param;
_params.push_back(_value_param);
}
......@@ -58,6 +64,9 @@ const shared_ptr<BelCardValueParam> &BelCardProperty::getValueParam() const {
}
void BelCardProperty::setPrefParam(const shared_ptr<BelCardPrefParam> &param) {
if (_pref_param) {
removeParam(_pref_param);
}
_pref_param = param;
_params.push_back(_pref_param);
}
......@@ -66,6 +75,9 @@ const shared_ptr<BelCardPrefParam> &BelCardProperty::getPrefParam() const {
}
void BelCardProperty::setAlternativeIdParam(const shared_ptr<BelCardAlternativeIdParam> &param) {
if (_altid_param) {
removeParam(_altid_param);
}
_altid_param = param;
_params.push_back(_altid_param);
}
......@@ -74,6 +86,9 @@ const shared_ptr<BelCardAlternativeIdParam> &BelCardProperty::getAlternativeIdPa
}
void BelCardProperty::setParamIdParam(const shared_ptr<BelCardParamIdParam> &param) {
if (_pid_param) {
removeParam(_pid_param);
}
_pid_param = param;
_params.push_back(_pid_param);
}
......@@ -82,6 +97,9 @@ const shared_ptr<BelCardParamIdParam> &BelCardProperty::getParamIdParam() const
}
void BelCardProperty::setTypeParam(const shared_ptr<BelCardTypeParam> &param) {
if (_type_param) {
removeParam(_type_param);
}
_type_param = param;
_params.push_back(_type_param);
}
......@@ -90,6 +108,9 @@ const shared_ptr<BelCardTypeParam> &BelCardProperty::getTypeParam() const {
}
void BelCardProperty::setMediaTypeParam(const shared_ptr<BelCardMediaTypeParam> &param) {
if (_mediatype_param) {
removeParam(_mediatype_param);
}
_mediatype_param = param;
_params.push_back(_mediatype_param);
}
......@@ -98,6 +119,9 @@ const shared_ptr<BelCardMediaTypeParam> &BelCardProperty::getMediaTypeParam() co
}
void BelCardProperty::setCALSCALEParam(const shared_ptr<BelCardCALSCALEParam> &param) {
if (_calscale_param) {
removeParam(_calscale_param);
}
_calscale_param = param;
_params.push_back(_calscale_param);
}
......@@ -106,6 +130,9 @@ const shared_ptr<BelCardCALSCALEParam> &BelCardProperty::getCALSCALEParam() cons
}
void BelCardProperty::setSortAsParam(const shared_ptr<BelCardSortAsParam> &param) {
if (_sort_as_param) {
removeParam(_sort_as_param);
}
_sort_as_param = param;
_params.push_back(_sort_as_param);
}
......@@ -114,6 +141,9 @@ const shared_ptr<BelCardSortAsParam> &BelCardProperty::getSortAsParam() const {
}
void BelCardProperty::setGeoParam(const shared_ptr<BelCardGeoParam> &param) {
if (_geo_param) {
removeParam(_geo_param);
}
_geo_param = param;
_params.push_back(_geo_param);
}
......@@ -122,6 +152,9 @@ const shared_ptr<BelCardGeoParam> &BelCardProperty::getGeoParam() const {
}
void BelCardProperty::setTimezoneParam(const shared_ptr<BelCardTimezoneParam> &param) {
if (_tz_param) {
removeParam(_tz_param);
}
_tz_param = param;
_params.push_back(_tz_param);
}
......@@ -135,6 +168,9 @@ void BelCardProperty::addParam(const shared_ptr<BelCardParam> &param) {
const list<shared_ptr<BelCardParam>> &BelCardProperty::getParams() const {
return _params;
}
void BelCardProperty::removeParam(const shared_ptr<BelCardParam> &param) {
_params.remove(param);
}
void BelCardProperty::serialize(ostream& output) const {
if (getGroup().length() > 0) {
......
#include "belcard/belcard_rfc6474.hpp"
using namespace::std;
using namespace::belr;
using namespace::belcard;
shared_ptr<BelCardBirthPlace> BelCardBirthPlace::parse(const string& input) {
return BelCardProperty::parseProperty<BelCardBirthPlace>("BIRTHPLACE", input);
}
void BelCardBirthPlace::setHandlerAndCollectors(Parser<shared_ptr<BelCardGeneric>> *parser) {
parser->setHandler("BIRTHPLACE", make_fn(BelCardGeneric::create<BelCardBirthPlace>))
->setCollector("group", make_sfn(&BelCardProperty::setGroup))
->setCollector("any-param", make_sfn(&BelCardProperty::addParam))
->setCollector("VALUE-param", make_sfn(&BelCardProperty::setValueParam))
->setCollector("ALTID-param", make_sfn(&BelCardProperty::setAlternativeIdParam))
->setCollector("LANGUAGE-param", make_sfn(&BelCardProperty::setLanguageParam))
->setCollector("BIRTHPLACE-value", make_sfn(&BelCardProperty::setValue));
}
BelCardBirthPlace::BelCardBirthPlace() : BelCardProperty() {
setName("BIRTHPLACE");
}
shared_ptr<BelCardDeathPlace> BelCardDeathPlace::parse(const string& input) {
return BelCardProperty::parseProperty<BelCardDeathPlace>("DEATHPLACE", input);
}
void BelCardDeathPlace::setHandlerAndCollectors(Parser<shared_ptr<BelCardGeneric>> *parser) {
parser->setHandler("DEATHPLACE", make_fn(BelCardGeneric::create<BelCardDeathPlace>))
->setCollector("group", make_sfn(&BelCardProperty::setGroup))
->setCollector("any-param", make_sfn(&BelCardProperty::addParam))
->setCollector("VALUE-param", make_sfn(&BelCardProperty::setValueParam))
->setCollector("ALTID-param", make_sfn(&BelCardProperty::setAlternativeIdParam))
->setCollector("LANGUAGE-param", make_sfn(&BelCardProperty::setLanguageParam))
->setCollector("DEATHPLACE-value", make_sfn(&BelCardProperty::setValue));
}
BelCardDeathPlace::BelCardDeathPlace() : BelCardProperty() {
setName("DEATHPLACE");
}
shared_ptr<BelCardDeathDate> BelCardDeathDate::parse(const string& input) {
return BelCardProperty::parseProperty<BelCardDeathDate>("DEATHDATE", input);
}
void BelCardDeathDate::setHandlerAndCollectors(Parser<shared_ptr<BelCardGeneric>> *parser) {
parser->setHandler("DEATHDATE", make_fn(BelCardGeneric::create<BelCardDeathDate>))
->setCollector("group", make_sfn(&BelCardProperty::setGroup))
->setCollector("any-param", make_sfn(&BelCardProperty::addParam))
->setCollector("VALUE-param", make_sfn(&BelCardProperty::setValueParam))
->setCollector("ALTID-param", make_sfn(&BelCardProperty::setAlternativeIdParam))
->setCollector("LANGUAGE-param", make_sfn(&BelCardProperty::setLanguageParam))
->setCollector("CALSCALE-param", make_sfn(&BelCardProperty::setCALSCALEParam))
->setCollector("DEATHDATE-value", make_sfn(&BelCardProperty::setValue));
}
BelCardDeathDate::BelCardDeathDate() : BelCardProperty() {
setName("DEATHDATE");
}
\ No newline at end of file
......@@ -14,6 +14,7 @@ property = SOURCE / KIND / XML
/ CATEGORIES / NOTE / PRODID / REV / SOUND / UID / CLIENTPIDMAP / URL
/ KEY
/ FBURL / CALADRURI / CALURI
/ BIRTHPLACE / DEATHPLACE / DEATHDATE
/ X-PROPERTY
X-PROPERTY = [group "."] X-PROPERTY-name *(";" X-PROPERTY-param) ":" X-PROPERTY-value CRLF
......@@ -116,7 +117,7 @@ TZ-value = text / URI / utc-offset
GEO = [group "."] "GEO" *(";" GEO-param) ":" GEO-value CRLF
GEO-param = VALUE-param / PID-param / PREF-param / TYPE-param / MEDIATYPE-param / ALTID-param / any-param
GEO-value = URI
GEO-value = text / URI
TITLE = [group "."] "TITLE" *(";" TITLE-param) ":" TITLE-value CRLF
TITLE-param = VALUE-param / LANGUAGE-param / PID-param / PREF-param
......@@ -199,6 +200,18 @@ CALURI = [group "."] "CALURI" *(";" CALURI-param) ":" CALURI-value CRLF
CALURI-param = VALUE-param / PID-param / PREF-param / TYPE-param
/ MEDIATYPE-param / ALTID-param / any-param
CALURI-value = URI
BIRTHPLACE = [group "."] "BIRTHPLACE" *(";" BIRTHPLACE-param) ":" BIRTHPLACE-value CRLF
BIRTHPLACE-param = VALUE-param / ALTID-param / LANGUAGE-param / any-param
BIRTHPLACE-value = text / URI
DEATHPLACE = [group "."] "DEATHPLACE" *(";" DEATHPLACE-param) ":" DEATHPLACE-value CRLF
DEATHPLACE-param = VALUE-param / ALTID-param / LANGUAGE-param / any-param
DEATHPLACE-value = text / URI
DEATHDATE = [group "."] "DEATHDATE" *(";" DEATHDATE-param) ":" DEATHDATE-value CRLF
DEATHDATE-param = VALUE-param / ALTID-param / LANGUAGE-param / any-param
DEATHDATE-value = date-and-or-time / text
group = 1*(ALPHA / DIGIT / "-")
......
......@@ -15,6 +15,7 @@ belcard_tester_SOURCES=belcard-tester.cpp belcard-tester.hpp common/bc_tester_ut
belcard-explanatory-tester.cpp \
belcard-security-tester.cpp \
belcard-calendar-tester.cpp \
belcard-rfc6474-tester.cpp \
belcard-vcard-tester.cpp
belcard_tester_LDADD=$(top_builddir)/src/libbelcard.la -lbelr $(CUNIT_LIBS)
......
......@@ -9,7 +9,7 @@ static void tz_property(void) {
}
static void geo_property(void) {
test_property<BelCardGeo>("GEO:geo:45.159612,5.732511\r\n");
test_property<BelCardGeo>("GEO:geo:45.159612\\,5.732511\r\n");
}
static test_t tests[] = {
......
#include "belcard/belcard_rfc6474.hpp"
#include "belcard-tester.hpp"
using namespace::std;
using namespace::belcard;
static void birth_place_property(void) {
test_property<BelCardBirthPlace>("BIRTHPLACE:Babies'R'Us Hospital\r\n");
test_property<BelCardBirthPlace>("BIRTHPLACE;VALUE=uri:http://example.com/hospitals/babiesrus.vcf\r\n");
test_property<BelCardBirthPlace>("BIRTHPLACE;VALUE=uri:geo:46.769307\\,-71.283079\r\n");
}
static void death_place_property(void) {
test_property<BelCardDeathPlace>("DEATHPLACE:Aboard the Titanic\\, near Newfoundland\r\n");
test_property<BelCardDeathPlace>("DEATHPLACE;VALUE=uri:http://example.com/ships/titanic.vcf\r\n");
test_property<BelCardDeathPlace>("DEATHPLACE;VALUE=uri:geo:41.731944\\,-49.945833\r\n");
}
static void death_date_property(void) {
test_property<BelCardDeathDate>("DEATHDATE:19960415\r\n");
test_property<BelCardDeathDate>("DEATHDATE:--0415\r\n");
test_property<BelCardDeathDate>("DEATHDATE:19531015T231000Z\r\n");
test_property<BelCardDeathDate>("DEATHDATE;VALUE=text:circa 1800\r\n");
}
static test_t tests[] = {
{ "Birth place", birth_place_property },
{ "Death place", death_place_property },
{ "Death date", death_date_property },
};
test_suite_t vcard_rfc6474_properties_test_suite = {
"RFC 6474",
NULL,
NULL,
NULL,
NULL,
sizeof(tests) / sizeof(tests[0]),
tests
};
\ No newline at end of file
......@@ -61,6 +61,7 @@ void belcard_tester_init(void(*ftester_printf)(int level, const char *fmt, va_li
bc_tester_add_suite(&vcard_explanatory_properties_test_suite);
bc_tester_add_suite(&vcard_security_properties_test_suite);
bc_tester_add_suite(&vcard_calendar_properties_test_suite);
bc_tester_add_suite(&vcard_rfc6474_properties_test_suite);
bc_tester_add_suite(&vcard_test_suite);
}
......
......@@ -21,6 +21,7 @@ extern test_suite_t vcard_organizational_properties_test_suite;
extern test_suite_t vcard_explanatory_properties_test_suite;
extern test_suite_t vcard_security_properties_test_suite;
extern test_suite_t vcard_calendar_properties_test_suite;
extern test_suite_t vcard_rfc6474_properties_test_suite;
extern test_suite_t vcard_test_suite;
void belcard_tester_init(void(*ftester_printf)(int level, const char *fmt, va_list args));
......@@ -33,7 +34,11 @@ void belcard_tester_uninit(void);
template<typename T>
void test_property(const std::string& input) {
std::shared_ptr<T> ptr = T::parse(input);
if (ptr == NULL) {
std::cout << "Couldn't parse " << input << std::endl;
}
BC_ASSERT_TRUE_FATAL(ptr != NULL);
std::string str = ptr->toString();
int compare = input.compare(str);
BC_ASSERT_EQUAL(compare, 0, int, "%d");
......
This diff was suppressed by a .gitattributes entry.
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