summaryrefslogtreecommitdiffstats
path: root/src/xml/repr-action-test.cpp
blob: d4f9d094d4f56a3709acdd9487f3bb7be07de92c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <cstdlib>
#include <glib.h>
#include "../utest/utest.h"

#include "repr.h"
#include "event-fns.h"

int sp_main_gui (int, char const**) { return 0; }
int sp_main_console (int, char const**) { return 0; }

int main(int /*argc*/, char */*argv*/[]) {
	Inkscape::XML::Document *document;
	Inkscape::XML::Node *a, *b, *c, *root;

	Inkscape::GC::init();

	document = sp_repr_document_new("test");
	root = document->root();

	utest_start("XML Transactions");

	a = document->createElement("a");
	b = document->createElement("b");
	c = document->createElement("c");

	UTEST_TEST("rollback of node addition") {
		sp_repr_begin_transaction(document);
		UTEST_ASSERT(sp_repr_parent(a) == NULL);

		root->appendChild(a);
		UTEST_ASSERT(sp_repr_parent(a) == root);

		sp_repr_rollback(document);
		UTEST_ASSERT(sp_repr_parent(a) == NULL);
	}

	UTEST_TEST("rollback of node removal") {
		root->appendChild(a);

		sp_repr_begin_transaction(document);
		UTEST_ASSERT(sp_repr_parent(a) == root);

		sp_repr_unparent(a);
		UTEST_ASSERT(sp_repr_parent(a) == NULL);

		sp_repr_rollback(document);
		UTEST_ASSERT(sp_repr_parent(a) == root);
	}

	sp_repr_unparent(a);

	UTEST_TEST("rollback of node reordering") {
		root->appendChild(a);
		root->appendChild(b);
		root->appendChild(c);

		sp_repr_begin_transaction(document);
		UTEST_ASSERT(sp_repr_next(a) == b);
		UTEST_ASSERT(sp_repr_next(b) == c);
		UTEST_ASSERT(sp_repr_next(c) == NULL);

		root->changeOrder(b, c);
		UTEST_ASSERT(sp_repr_next(a) == c);
		UTEST_ASSERT(sp_repr_next(b) == NULL);
		UTEST_ASSERT(sp_repr_next(c) == b);

		sp_repr_rollback(document);
		UTEST_ASSERT(sp_repr_next(a) == b);
		UTEST_ASSERT(sp_repr_next(b) == c);
		UTEST_ASSERT(sp_repr_next(c) == NULL);
	}

	sp_repr_unparent(a);
	sp_repr_unparent(b);
	sp_repr_unparent(c);

	/* lots more tests needed ... */

	return utest_end() ? 0 : 1;
}