From 6b90c6c8762da5f0dcd6c0f87a60f06cd0584ee6 Mon Sep 17 00:00:00 2001 From: Jasper van de Gronde Date: Tue, 1 Jul 2008 18:18:32 +0000 Subject: CxxTest unit tests can now be built on Windows, also adds CxxTest versions of most UTEST unit tests. (These new CxxTest tests are not part of make check on Linux yet.) (bzr r6106) --- src/xml/quote-test.h | 59 +++++++++++++++++++++++++++++++++++- src/xml/repr-action-test.h | 74 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 131 insertions(+), 2 deletions(-) (limited to 'src/xml') 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 +/* Initial author: Peter Moulder. + Hereby released into the Public Domain. */ + +#include +#include + +/* 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\"bd;!@#$%^*(\\)?", 30} + }; + for(size_t i=0; i", ">"}, + {"a\"bd;!@#$%^*(\\)?", "a"b<c>d;!@#$%^*(\\)?"} + }; + for(size_t i=0; i +#include +#include + +#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 ... */ + }; /* -- cgit v1.2.3