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

Added missing check for ProductID + new tests

parent 44402ff5
......@@ -43,7 +43,7 @@ namespace belcard {
}
template<typename T>
static bool isValid(const shared_ptr<T> &property) {
BELCARD_PUBLIC static bool isValid(const shared_ptr<T> &property) {
return T::parse(property->toString()) != NULL;
}
......
......@@ -182,7 +182,9 @@ void BelCard::_setProductId(const shared_ptr<BelCardProductId> &pid) {
set(_pid, pid);
}
void BelCard::setProductId(const shared_ptr<BelCardProductId> &pid) {
_setProductId(pid);
if (BelCardGeneric::isValid(pid)) {
_setProductId(pid);
}
}
const shared_ptr<BelCardProductId> &BelCard::getProductId() const {
return _pid;
......
......@@ -201,4 +201,4 @@ void BelCardProperty::serialize(ostream& output) const {
output << ";" << (**it);
}
output << ":" << getValue() << "\r\n";
}
\ No newline at end of file
}
......@@ -36,6 +36,18 @@ static void prodid_property(void) {
static void rev_property(void) {
test_property<BelCardRevision>("REV:19951031T222710Z\r\n");
shared_ptr<BelCard> card = BelCardGeneric::create<BelCard>();
shared_ptr<BelCardRevision> rev = BelCardGeneric::create<BelCardRevision>();
rev->setValue("AZERTY");
BC_ASSERT_FALSE(BelCardGeneric::isValid(rev));
card->setRevision(rev);
BC_ASSERT_TRUE(card->getRevision() == NULL);
rev->setValue("19951031T222710Z");
BC_ASSERT_TRUE(BelCardGeneric::isValid(rev));
card->setRevision(rev);
BC_ASSERT_TRUE(card->getRevision() != NULL);
}
static void sound_property(void) {
......
......@@ -29,6 +29,18 @@ static void kind_property(void) {
static void source_property(void) {
test_property<BelCardSource>("SOURCE:ldap://ldap.example.com/cn=Babs%20Jensen,%20o=Babsco,%20c=US\r\n");
test_property<BelCardSource>("SOURCE:http://directory.example.com/addressbooks/jdoe/Jean%20Dupont.vcf\r\n");
shared_ptr<BelCard> card = BelCardGeneric::create<BelCard>();
shared_ptr<BelCardSource> source = BelCardGeneric::create<BelCardSource>();
source->setValue("AZERTY");
BC_ASSERT_FALSE(BelCardGeneric::isValid(source));
card->addSource(source);
BC_ASSERT_TRUE(card->getSource().size() == 0);
source->setValue("https://www.linphone.org/");
BC_ASSERT_TRUE(BelCardGeneric::isValid(source));
card->addSource(source);
BC_ASSERT_TRUE(card->getSource().size() == 1);
}
static void xml_property(void) {
......
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