diff options
Diffstat (limited to 'src/xml')
| -rw-r--r-- | src/xml/quote-test.h | 59 | ||||
| -rw-r--r-- | src/xml/repr-action-test.h | 74 |
2 files changed, 131 insertions, 2 deletions
diff --git a/src/xml/quote-test.h b/src/xml/quote-test.h index 39f7e6167..7f5372844 100644 --- a/src/xml/quote-test.h +++ b/src/xml/quote-test.h @@ -1,5 +1,25 @@ #include <cxxtest/TestSuite.h> +/* Initial author: Peter Moulder. + Hereby released into the Public Domain. */ + +#include <cstring> +#include <functional> + +/* mental disclaims all responsibility for this evil idea for testing + static functions. The main disadvantages are that we retain any + #define's and `using' directives of the included file. */ +#include "quote.cpp" + +struct streq_free2 { + bool operator()(char const *exp, char *got) const + { + bool const ret = (strcmp(exp, got) == 0); + g_free(got); + return ret; + } +}; + class XmlQuoteTest : public CxxTest::TestSuite { public: @@ -14,8 +34,45 @@ public: static XmlQuoteTest *createSuite() { return new XmlQuoteTest(); } static void destroySuite( XmlQuoteTest *suite ) { delete suite; } - void testFoo() + void testXmlQuotedStrlen() + { + struct { + char const *s; + size_t len; + } cases[] = { + {"", 0}, + {"x", 1}, + {"Foo", 3}, + {"\"", 6}, + {"&", 5}, + {"<", 4}, + {">", 4}, + {"a\"b", 8}, + {"a\"b<c>d;!@#$%^*(\\)?", 30} + }; + for(size_t i=0; i<G_N_ELEMENTS(cases); i++) { + TS_ASSERT_EQUALS( xml_quoted_strlen(cases[i].s) , cases[i].len ); + } + } + + void testXmlQuoteStrdup() { + struct { + char const * s1; + char const * s2; + } cases[] = { + {"", ""}, + {"x", "x"}, + {"Foo", "Foo"}, + {"\"", """}, + {"&", "&"}, + {"<", "<"}, + {">", ">"}, + {"a\"b<c>d;!@#$%^*(\\)?", "a"b<c>d;!@#$%^*(\\)?"} + }; + for(size_t i=0; i<G_N_ELEMENTS(cases); i++) { + TS_ASSERT_RELATION( streq_free2, cases[i].s2, xml_quote_strdup(cases[i].s1) ); + } } }; diff --git a/src/xml/repr-action-test.h b/src/xml/repr-action-test.h index 10f7d52f1..8fe1327af 100644 --- a/src/xml/repr-action-test.h +++ b/src/xml/repr-action-test.h @@ -1,11 +1,30 @@ #include <cxxtest/TestSuite.h> +#include <cstdlib> +#include <glib.h> + +#include "repr.h" +#include "event-fns.h" + +static void * const null_ptr = 0; + class XmlReprActionTest : public CxxTest::TestSuite { + Inkscape::XML::Document *document; + Inkscape::XML::Node *a, *b, *c, *root; + public: XmlReprActionTest() { + Inkscape::GC::init(); + + document = sp_repr_document_new("test"); + root = document->root(); + + a = document->createElement("a"); + b = document->createElement("b"); + c = document->createElement("c"); } virtual ~XmlReprActionTest() {} @@ -14,9 +33,62 @@ public: static XmlReprActionTest *createSuite() { return new XmlReprActionTest(); } static void destroySuite( XmlReprActionTest *suite ) { delete suite; } - void testFoo() + void testRollbackOfNodeAddition() + { + sp_repr_begin_transaction(document); + TS_ASSERT_EQUALS(sp_repr_parent(a) , null_ptr); + + root->appendChild(a); + TS_ASSERT_EQUALS(sp_repr_parent(a) , root); + + sp_repr_rollback(document); + TS_ASSERT_EQUALS(sp_repr_parent(a) , null_ptr); + } + + void testRollbackOfNodeRemoval() + { + root->appendChild(a); + + sp_repr_begin_transaction(document); + TS_ASSERT_EQUALS(sp_repr_parent(a) , root); + + sp_repr_unparent(a); + TS_ASSERT_EQUALS(sp_repr_parent(a) , null_ptr); + + sp_repr_rollback(document); + TS_ASSERT_EQUALS(sp_repr_parent(a) , root); + + sp_repr_unparent(a); + } + + void testRollbackOfNodeReordering() { + root->appendChild(a); + root->appendChild(b); + root->appendChild(c); + + sp_repr_begin_transaction(document); + TS_ASSERT_EQUALS(sp_repr_next(a) , b); + TS_ASSERT_EQUALS(sp_repr_next(b) , c); + TS_ASSERT_EQUALS(sp_repr_next(c) , null_ptr); + + root->changeOrder(b, c); + TS_ASSERT_EQUALS(sp_repr_next(a) , c); + TS_ASSERT_EQUALS(sp_repr_next(b) , null_ptr); + TS_ASSERT_EQUALS(sp_repr_next(c) , b); + + sp_repr_rollback(document); + TS_ASSERT_EQUALS(sp_repr_next(a) , b); + TS_ASSERT_EQUALS(sp_repr_next(b) , c); + TS_ASSERT_EQUALS(sp_repr_next(c) , null_ptr); + + sp_repr_unparent(a); + sp_repr_unparent(b); + sp_repr_unparent(c); } + + /* lots more tests needed ... */ + }; /* |
