summaryrefslogtreecommitdiffstats
path: root/cpp/sca/modules/atom/atom-test.cpp
diff options
context:
space:
mode:
authorjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2009-10-26 05:13:06 +0000
committerjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2009-10-26 05:13:06 +0000
commitf61164c77c5c21a32b58ad61c868bd8ff6a4a79e (patch)
tree951cc581d22bac8ad615697b19e879e22578d10c /cpp/sca/modules/atom/atom-test.cpp
parent0969cc21d093f9450c36e7f63cddc4f5aa44b238 (diff)
Minor refactoring, given each module its own namespace. Added utility functions to convert between values elements/attributes and fixed XML, ATOM and JSON serialization of lists.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@829699 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r--cpp/sca/modules/atom/atom-test.cpp72
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;