summaryrefslogtreecommitdiffstats
path: root/testfiles/src/cxxtests-to-migrate
diff options
context:
space:
mode:
Diffstat (limited to 'testfiles/src/cxxtests-to-migrate')
-rw-r--r--testfiles/src/cxxtests-to-migrate/marker-test.h42
-rw-r--r--testfiles/src/cxxtests-to-migrate/mod360-test.h65
-rw-r--r--testfiles/src/cxxtests-to-migrate/preferences-test.h139
-rw-r--r--testfiles/src/cxxtests-to-migrate/sp-style-elem-test.h166
-rw-r--r--testfiles/src/cxxtests-to-migrate/test-helpers.h71
-rw-r--r--testfiles/src/cxxtests-to-migrate/verbs-test.h95
6 files changed, 578 insertions, 0 deletions
diff --git a/testfiles/src/cxxtests-to-migrate/marker-test.h b/testfiles/src/cxxtests-to-migrate/marker-test.h
new file mode 100644
index 0000000..1a77aff
--- /dev/null
+++ b/testfiles/src/cxxtests-to-migrate/marker-test.h
@@ -0,0 +1,42 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/** @file
+ * @brief Unit tests for SVG marker handling
+ *//*
+ * Authors:
+ * see git history
+ * Johan Engelen <goejendaagh@zonnet.nl>
+ *
+ * Copyright (C) 2016 Authors
+ * Released under GNU GPL v2+, read the file 'COPYING' for more information.
+ */
+
+#include <cxxtest/TestSuite.h>
+
+#include "sp-marker-loc.h"
+
+class MarkerTest : public CxxTest::TestSuite
+{
+public:
+
+ void testMarkerLoc()
+ {
+ // code depends on these *exact* values, so check them here.
+ TS_ASSERT_EQUALS(SP_MARKER_LOC, 0);
+ TS_ASSERT_EQUALS(SP_MARKER_LOC_START, 1);
+ TS_ASSERT_EQUALS(SP_MARKER_LOC_MID, 2);
+ TS_ASSERT_EQUALS(SP_MARKER_LOC_END, 3);
+ TS_ASSERT_EQUALS(SP_MARKER_LOC_QTY, 4);
+ }
+
+};
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
diff --git a/testfiles/src/cxxtests-to-migrate/mod360-test.h b/testfiles/src/cxxtests-to-migrate/mod360-test.h
new file mode 100644
index 0000000..12ee994
--- /dev/null
+++ b/testfiles/src/cxxtests-to-migrate/mod360-test.h
@@ -0,0 +1,65 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/** @file
+ * TODO: insert short description here
+ *//*
+ * Authors: see git history
+ *
+ * Copyright (C) 2016 Authors
+ * Released under GNU GPL v2+, read the file 'COPYING' for more information.
+ */
+
+#ifndef SEEN_MOD_360_TEST_H
+#define SEEN_MOD_360_TEST_H
+
+#include <cxxtest/TestSuite.h>
+#include <2geom/math-utils.h>
+#include "mod360.h"
+
+
+class Mod360Test : public CxxTest::TestSuite
+{
+public:
+ static double inf() { return INFINITY; }
+ static double nan() { return ((double)INFINITY) - ((double)INFINITY); }
+
+ void testMod360()
+ {
+ double cases[][2] = {
+ {0, 0},
+ {10, 10},
+ {360, 0},
+ {361, 1},
+ {-1, 359},
+ {-359, 1},
+ {-360, -0},
+ {-361, 359},
+ {inf(), 0},
+ {-inf(), 0},
+ {nan(), 0},
+ {720, 0},
+ {-721, 359},
+ {-1000, 80}
+ };
+
+ for ( unsigned i = 0; i < G_N_ELEMENTS(cases); i++ ) {
+ double result = mod360( cases[i][0] );
+ TS_ASSERT_EQUALS( cases[i][1], result );
+ }
+ }
+
+};
+
+
+#endif // SEEN_MOD_360_TEST_H
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
+
diff --git a/testfiles/src/cxxtests-to-migrate/preferences-test.h b/testfiles/src/cxxtests-to-migrate/preferences-test.h
new file mode 100644
index 0000000..0dc04b8
--- /dev/null
+++ b/testfiles/src/cxxtests-to-migrate/preferences-test.h
@@ -0,0 +1,139 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/** @file
+ * @brief Unit tests for the Preferences object
+ *//*
+ * Authors:
+ * see git history
+ * Krzysztof KosiƄski <tweenk.pl@gmail.com>
+ *
+ * Copyright (C) 2016 Authors
+ * Released under GNU GPL v2+, read the file 'COPYING' for more information.
+ */
+
+#include <cxxtest/TestSuite.h>
+#include "preferences.h"
+
+#include <glibmm/ustring.h>
+
+// test observer
+class TestObserver : public Inkscape::Preferences::Observer {
+public:
+ TestObserver(Glib::ustring const &path) :
+ Inkscape::Preferences::Observer(path),
+ value(0) {}
+
+ virtual void notify(Inkscape::Preferences::Entry const &val)
+ {
+ value = val.getInt();
+ }
+ int value;
+};
+
+class PreferencesTest : public CxxTest::TestSuite {
+public:
+ void setUp() {
+ prefs = Inkscape::Preferences::get();
+ }
+ void tearDown() {
+ prefs = NULL;
+ Inkscape::Preferences::unload();
+ }
+
+ void testStartingState()
+ {
+ TS_ASSERT_DIFFERS(prefs, static_cast<void*>(0));
+ TS_ASSERT_EQUALS(prefs->isWritable(), true);
+ }
+
+ void testOverwrite()
+ {
+ prefs->setInt("/test/intvalue", 123);
+ prefs->setInt("/test/intvalue", 321);
+ TS_ASSERT_EQUALS(prefs->getInt("/test/intvalue"), 321);
+ }
+
+ void testDefaultReturn()
+ {
+ TS_ASSERT_EQUALS(prefs->getInt("/this/path/does/not/exist", 123), 123);
+ }
+
+ void testLimitedReturn()
+ {
+ prefs->setInt("/test/intvalue", 1000);
+
+ // simple case
+ TS_ASSERT_EQUALS(prefs->getIntLimited("/test/intvalue", 123, 0, 500), 123);
+ // the below may seem quirky but this behaviour is intended
+ TS_ASSERT_EQUALS(prefs->getIntLimited("/test/intvalue", 123, 1001, 5000), 123);
+ // corner cases
+ TS_ASSERT_EQUALS(prefs->getIntLimited("/test/intvalue", 123, 0, 1000), 1000);
+ TS_ASSERT_EQUALS(prefs->getIntLimited("/test/intvalue", 123, 1000, 5000), 1000);
+ }
+
+ void testKeyObserverNotification()
+ {
+ Glib::ustring const path = "/some/random/path";
+ TestObserver obs("/some/random");
+ obs.value = 1;
+ prefs->setInt(path, 5);
+ TS_ASSERT_EQUALS(obs.value, 1); // no notifications sent before adding
+
+ prefs->addObserver(obs);
+ prefs->setInt(path, 10);
+ TS_ASSERT_EQUALS(obs.value, 10);
+ prefs->setInt("/some/other/random/path", 10);
+ TS_ASSERT_EQUALS(obs.value, 10); // value should not change
+
+ prefs->removeObserver(obs);
+ prefs->setInt(path, 15);
+ TS_ASSERT_EQUALS(obs.value, 10); // no notifications sent after removal
+ }
+
+ void testEntryObserverNotification()
+ {
+ Glib::ustring const path = "/some/random/path";
+ TestObserver obs(path);
+ obs.value = 1;
+ prefs->setInt(path, 5);
+ TS_ASSERT_EQUALS(obs.value, 1); // no notifications sent before adding
+
+ prefs->addObserver(obs);
+ prefs->setInt(path, 10);
+ TS_ASSERT_EQUALS(obs.value, 10);
+
+ // test that filtering works properly
+ prefs->setInt("/some/random/value", 1234);
+ TS_ASSERT_EQUALS(obs.value, 10);
+ prefs->setInt("/some/randomvalue", 1234);
+ TS_ASSERT_EQUALS(obs.value, 10);
+ prefs->setInt("/some/random/path2", 1234);
+ TS_ASSERT_EQUALS(obs.value, 10);
+
+ prefs->removeObserver(obs);
+ prefs->setInt(path, 15);
+ TS_ASSERT_EQUALS(obs.value, 10); // no notifications sent after removal
+ }
+
+ void testPreferencesEntryMethods()
+ {
+ prefs->setInt("/test/prefentry", 100);
+ Inkscape::Preferences::Entry val = prefs->getEntry("/test/prefentry");
+ TS_ASSERT(val.isValid());
+ TS_ASSERT_EQUALS(val.getPath(), "/test/prefentry");
+ TS_ASSERT_EQUALS(val.getEntryName(), "prefentry");
+ TS_ASSERT_EQUALS(val.getInt(), 100);
+ }
+private:
+ Inkscape::Preferences *prefs;
+};
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
diff --git a/testfiles/src/cxxtests-to-migrate/sp-style-elem-test.h b/testfiles/src/cxxtests-to-migrate/sp-style-elem-test.h
new file mode 100644
index 0000000..7846360
--- /dev/null
+++ b/testfiles/src/cxxtests-to-migrate/sp-style-elem-test.h
@@ -0,0 +1,166 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/** @file
+ * TODO: insert short description here
+ *//*
+ * Authors: see git history
+ *
+ * Copyright (C) 2016 Authors
+ * Released under GNU GPL v2+, read the file 'COPYING' for more information.
+ */
+#ifndef SEEN_SP_STYLE_ELEM_TEST_H
+#define SEEN_SP_STYLE_ELEM_TEST_H
+
+#include <cxxtest/TestSuite.h>
+
+#include "test-helpers.h"
+
+#include "sp-style-elem.h"
+#include "xml/repr.h"
+
+class SPStyleElemTest : public CxxTest::TestSuite
+{
+public:
+ std::unique_ptr<SPDocument> _doc;
+
+ SPStyleElemTest() = default;
+
+ virtual ~SPStyleElemTest() = default;
+
+ static void createSuiteSubclass( SPStyleElemTest *& dst )
+ {
+ SPStyleElem *style_elem = new SPStyleElem();
+
+ if ( style_elem ) {
+ TS_ASSERT(!style_elem->is_css);
+ TS_ASSERT(style_elem->media.print);
+ TS_ASSERT(style_elem->media.screen);
+ delete style_elem;
+
+ dst = new SPStyleElemTest();
+ }
+ }
+
+ static SPStyleElemTest *createSuite()
+ {
+ return Inkscape::createSuiteAndDocument<SPStyleElemTest>( createSuiteSubclass );
+ }
+
+ static void destroySuite( SPStyleElemTest *suite ) { delete suite; }
+
+// -------------------------------------------------------------------------
+// -------------------------------------------------------------------------
+
+
+ void testSetType()
+ {
+ SPStyleElem *style_elem = new SPStyleElem();
+ SP_OBJECT(style_elem)->document = _doc.get();
+
+ SP_OBJECT(style_elem)->setKeyValue( SPAttr::TYPE, "something unrecognized");
+ TS_ASSERT( !style_elem->is_css );
+
+ SP_OBJECT(style_elem)->setKeyValue( SPAttr::TYPE, "text/css");
+ TS_ASSERT( style_elem->is_css );
+
+ SP_OBJECT(style_elem)->setKeyValue( SPAttr::TYPE, "atext/css");
+ TS_ASSERT( !style_elem->is_css );
+
+ SP_OBJECT(style_elem)->setKeyValue( SPAttr::TYPE, "text/cssx");
+ TS_ASSERT( !style_elem->is_css );
+
+ delete style_elem;
+ }
+
+ void testWrite()
+ {
+ TS_ASSERT( _doc );
+ TS_ASSERT( _doc->getReprDoc() );
+ if ( !_doc->getReprDoc() ) {
+ return; // evil early return
+ }
+
+ SPStyleElem *style_elem = new SPStyleElem();
+ SP_OBJECT(style_elem)->document = _doc.get();
+
+ SP_OBJECT(style_elem)->setKeyValue( SPAttr::TYPE, "text/css");
+ Inkscape::XML::Node *repr = _doc->getReprDoc()->createElement("svg:style");
+ SP_OBJECT(style_elem)->updateRepr(_doc->getReprDoc(), repr, SP_OBJECT_WRITE_ALL);
+ {
+ gchar const *typ = repr->attribute("type");
+ TS_ASSERT( typ != NULL );
+ if ( typ )
+ {
+ TS_ASSERT_EQUALS( std::string(typ), std::string("text/css") );
+ }
+ }
+
+ delete style_elem;
+ }
+
+ void testBuild()
+ {
+ TS_ASSERT( _doc );
+ TS_ASSERT( _doc->getReprDoc() );
+ if ( !_doc->getReprDoc() ) {
+ return; // evil early return
+ }
+
+ SPStyleElem *style_elem = new SPStyleElem();
+ Inkscape::XML::Node *const repr = _doc->getReprDoc()->createElement("svg:style");
+ repr->setAttribute("type", "text/css");
+ style_elem->invoke_build( _doc.get(), repr, false);
+ TS_ASSERT( style_elem->is_css );
+ TS_ASSERT( style_elem->media.print );
+ TS_ASSERT( style_elem->media.screen );
+
+ /* Some checks relevant to the read_content test below. */
+ {
+ g_assert(_doc->style_cascade);
+ CRStyleSheet const *const stylesheet = cr_cascade_get_sheet(_doc->style_cascade, ORIGIN_AUTHOR);
+ g_assert(stylesheet);
+ g_assert(stylesheet->statements == NULL);
+ }
+
+ delete style_elem;
+ Inkscape::GC::release(repr);
+ }
+
+ void testReadContent()
+ {
+ TS_ASSERT( _doc );
+ TS_ASSERT( _doc->getReprDoc() );
+ if ( !_doc->getReprDoc() ) {
+ return; // evil early return
+ }
+
+ SPStyleElem *style_elem = new SPStyleElem();
+ Inkscape::XML::Node *const repr = _doc->getReprDoc()->createElement("svg:style");
+ repr->setAttribute("type", "text/css");
+ Inkscape::XML::Node *const content_repr = _doc->getReprDoc()->createTextNode(".myclass { }");
+ repr->addChild(content_repr, NULL);
+ style_elem->invoke_build(_doc.get(), repr, false);
+ TS_ASSERT( style_elem->is_css );
+ TS_ASSERT( _doc->style_cascade );
+ CRStyleSheet const *const stylesheet = cr_cascade_get_sheet(_doc->style_cascade, ORIGIN_AUTHOR);
+ TS_ASSERT(stylesheet != NULL);
+ TS_ASSERT(stylesheet->statements != NULL);
+
+ delete style_elem;
+ Inkscape::GC::release(repr);
+ }
+
+};
+
+
+#endif // SEEN_SP_STYLE_ELEM_TEST_H
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
diff --git a/testfiles/src/cxxtests-to-migrate/test-helpers.h b/testfiles/src/cxxtests-to-migrate/test-helpers.h
new file mode 100644
index 0000000..a6e49e5
--- /dev/null
+++ b/testfiles/src/cxxtests-to-migrate/test-helpers.h
@@ -0,0 +1,71 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/** @file
+ * TODO: insert short description here
+ *//*
+ * Authors: see git history
+ *
+ * Copyright (C) 2016 Authors
+ * Released under GNU GPL v2+, read the file 'COPYING' for more information.
+ */
+#ifndef SEEN_TEST_HELPERS_H
+#define SEEN_TEST_HELPERS_H
+
+
+#include <cxxtest/TestSuite.h>
+
+#include "document.h"
+#include "inkscape.h"
+
+
+// Dummy functions to keep linker happy
+#if !defined(DUMMY_MAIN_TEST_CALLS_SEEN)
+#define DUMMY_MAIN_TEST_CALLS_SEEN
+int sp_main_gui (int, char const**) { return 0; }
+int sp_main_console (int, char const**) { return 0; }
+#endif // DUMMY_MAIN_TEST_CALLS_SEEN
+
+namespace Inkscape
+{
+
+template <class T>
+T* createSuiteAndDocument( void (*fun)(T*&) )
+{
+ T* suite = 0;
+
+#if !GLIB_CHECK_VERSION(2,36,0)
+ g_type_init();
+#endif
+
+ Inkscape::GC::init();
+ if ( !Inkscape::Application::exists() )
+ {
+ // Create the global inkscape object.
+ Inkscape::Application::create(false);
+ }
+
+ auto tmp = std::unique_ptr<SPDocument>(SPDocument::createNewDoc(NULL, TRUE, true));
+ if ( tmp ) {
+ fun( suite );
+ if ( suite )
+ {
+ suite->_doc = std::move(tmp);
+ }
+ }
+
+ return suite;
+}
+
+} // namespace Inkscape
+
+#endif // SEEN_TEST_HELPERS_H
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
diff --git a/testfiles/src/cxxtests-to-migrate/verbs-test.h b/testfiles/src/cxxtests-to-migrate/verbs-test.h
new file mode 100644
index 0000000..b8fd299
--- /dev/null
+++ b/testfiles/src/cxxtests-to-migrate/verbs-test.h
@@ -0,0 +1,95 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/** @file
+ * TODO: insert short description here
+ *//*
+ * Authors: see git history
+ *
+ * Copyright (C) 2016 Authors
+ * Released under GNU GPL v2+, read the file 'COPYING' for more information.
+ */
+
+
+#include <cxxtest/TestSuite.h>
+
+#include "verbs.h"
+
+class VerbsTest : public CxxTest::TestSuite
+{
+public:
+
+ class TestHook : public Inkscape::Verb {
+ public:
+ static int getInternalTableSize() { return _getBaseListSize(); }
+
+ private:
+ TestHook();
+ };
+
+ void testEnumLength()
+ {
+ TS_ASSERT_DIFFERS( 0, static_cast<int>(SP_VERB_LAST) );
+ TS_ASSERT_EQUALS( static_cast<int>(SP_VERB_LAST) + 1, TestHook::getInternalTableSize() );
+ }
+
+ void testEnumFixed()
+ {
+ TS_ASSERT_EQUALS( 0, static_cast<int>(SP_VERB_INVALID) );
+ TS_ASSERT_EQUALS( 1, static_cast<int>(SP_VERB_NONE) );
+
+ TS_ASSERT_DIFFERS( 0, static_cast<int>(SP_VERB_LAST) );
+ TS_ASSERT_DIFFERS( 1, static_cast<int>(SP_VERB_LAST) );
+ }
+
+ void testFetch()
+ {
+ for ( int i = 0; i < static_cast<int>(SP_VERB_LAST); i++ )
+ {
+ char tmp[16];
+ snprintf( tmp, sizeof(tmp), "Verb# %d", i );
+ tmp[sizeof(tmp)-1] = 0;
+ std::string descr(tmp);
+
+ Inkscape::Verb* verb = Inkscape::Verb::get(i);
+ TSM_ASSERT( descr, verb );
+ if ( verb )
+ {
+ TSM_ASSERT_EQUALS( descr, verb->get_code(), static_cast<unsigned int>(i) );
+
+ if ( i != static_cast<int>(SP_VERB_INVALID) )
+ {
+ TSM_ASSERT( descr, verb->get_id() );
+ TSM_ASSERT( descr, verb->get_name() );
+
+ Inkscape::Verb* bounced = verb->getbyid( verb->get_id() );
+ // TODO - put this back once verbs are fixed
+ //TSM_ASSERT( descr, bounced );
+ if ( bounced )
+ {
+ TSM_ASSERT_EQUALS( descr, bounced->get_code(), static_cast<unsigned int>(i) );
+ }
+ else
+ {
+ TS_FAIL( std::string("Unable to getbyid() for ") + descr + std::string(" ID: '") + std::string(verb->get_id()) + std::string("'") );
+ }
+ }
+ else
+ {
+ TSM_ASSERT( std::string("SP_VERB_INVALID"), !verb->get_id() );
+ TSM_ASSERT( std::string("SP_VERB_INVALID"), !verb->get_name() );
+ }
+ }
+ }
+ }
+
+};
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :