diff options
Diffstat (limited to '')
-rw-r--r-- | cpp/sca/modules/atom/atom-test.cpp | 72 |
1 files changed, 58 insertions, 14 deletions
diff --git a/cpp/sca/modules/atom/atom-test.cpp b/cpp/sca/modules/atom/atom-test.cpp index 0cef6b3b60..618f534001 100644 --- a/cpp/sca/modules/atom/atom-test.cpp +++ b/cpp/sca/modules/atom/atom-test.cpp @@ -31,8 +31,9 @@ #include "atom.hpp" namespace tuscany { +namespace atom { -std::ostringstream* atomWriter(std::ostringstream* os, const std::string& s) { +std::ostringstream* writer(std::ostringstream* os, const std::string& s) { (*os) << s; return os; } @@ -49,22 +50,49 @@ std::string itemEntry("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" "<link href=\"cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b\"/>" "</entry>\n"); -bool testATOMEntry() { +std::string incompleteEntry("<entry xmlns=\"http://www.w3.org/2005/Atom\">" + "<title>item</title><content type=\"text/xml\">" + "<Item xmlns=\"http://services/\">" + "<name xmlns=\"\">Orange</name>" + "<price xmlns=\"\">3.55</price>" + "</Item>" + "</content>" + "</entry>"); + +std::string completedEntry("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<entry xmlns=\"http://www.w3.org/2005/Atom\">" + "<title type=\"text\">item</title>" + "<id></id>" + "<content type=\"application/xml\">" + "<Item xmlns=\"http://services/\">" + "<name xmlns=\"\">Orange</name>" + "<price xmlns=\"\">3.55</price>" + "</Item>" + "</content><link href=\"\"/>" + "</entry>\n"); + +bool testEntry() { { const list<value> i = list<value>() << element << "item" << (list<value>() << element << "name" << std::string("Apple")) << (list<value>() << element << "price" << std::string("$2.99")); const list<value> a = mklist<value>(std::string("item"), std::string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"), i); std::ostringstream os; - writeATOMEntry<std::ostringstream*>(atomWriter, &os, a); + writeEntry<std::ostringstream*>(writer, &os, a); assert(os.str() == itemEntry); } { - const list<value> a = readATOMEntry(mklist(itemEntry)); + const list<value> a = readEntry(mklist(itemEntry)); std::ostringstream os; - writeATOMEntry<std::ostringstream*>(atomWriter, &os, a); + writeEntry<std::ostringstream*>(writer, &os, a); assert(os.str() == itemEntry); } + { + const list<value> a = readEntry(mklist(incompleteEntry)); + std::ostringstream os; + writeEntry<std::ostringstream*>(writer, &os, a); + assert(os.str() == completedEntry); + } return true; } @@ -100,16 +128,16 @@ std::string itemFeed("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" "</entry>" "</feed>\n"); -bool testATOMFeed() { +bool testFeed() { { std::ostringstream os; - writeATOMFeed<std::ostringstream*>(atomWriter, &os, mklist<value>("Feed", "1234")); + writeFeed<std::ostringstream*>(writer, &os, mklist<value>("Feed", "1234")); assert(os.str() == emptyFeed); } { - const list<value> a = readATOMFeed(mklist(emptyFeed)); + const list<value> a = readFeed(mklist(emptyFeed)); std::ostringstream os; - writeATOMFeed<std::ostringstream*>(atomWriter, &os, a); + writeFeed<std::ostringstream*>(writer, &os, a); assert(os.str() == emptyFeed); } { @@ -124,25 +152,41 @@ bool testATOMFeed() { << (list<value>() << element << "price" << "$3.55"))); const list<value> a = cons<value>("Feed", cons<value>("1234", i)); std::ostringstream os; - writeATOMFeed<std::ostringstream*>(atomWriter, &os, a); + writeFeed<std::ostringstream*>(writer, &os, a); assert(os.str() == itemFeed); } { - const list<value> a = readATOMFeed(mklist(itemFeed)); + const list<value> i = list<value>() + << (list<value>() << "item" << "cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b" + << valueToElement(list<value>() << "item" + << (list<value>() << "name" << "Apple") + << (list<value>() << "price" << "$2.99"))) + << (list<value>() << "item" << "cart-53d67a61-aa5e-4e5e-8401-39edeba8b83c" + << valueToElement(list<value>() << "item" + << (list<value>() << "name" << "Orange") + << (list<value>() << "price" << "$3.55"))); + const list<value> a = cons<value>("Feed", cons<value>("1234", i)); std::ostringstream os; - writeATOMFeed<std::ostringstream*>(atomWriter, &os, a); + writeFeed<std::ostringstream*>(writer, &os, a); + assert(os.str() == itemFeed); + } + { + const list<value> a = readFeed(mklist(itemFeed)); + std::ostringstream os; + writeFeed<std::ostringstream*>(writer, &os, a); assert(os.str() == itemFeed); } return true; } } +} int main() { std::cout << "Testing..." << std::endl; - tuscany::testATOMEntry(); - tuscany::testATOMFeed(); + tuscany::atom::testEntry(); + tuscany::atom::testFeed(); std::cout << "OK" << std::endl; |