summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: b77466c)
raw | patch | inline | side by side (parent: b77466c)
author | joncruz <joncruz@users.sourceforge.net> | |
Mon, 1 May 2006 08:11:44 +0000 (08:11 +0000) | ||
committer | joncruz <joncruz@users.sourceforge.net> | |
Mon, 1 May 2006 08:11:44 +0000 (08:11 +0000) |
15 files changed:
ChangeLog | patch | blob | history | |
src/Makefile.am | patch | blob | history | |
src/Makefile_insert | patch | blob | history | |
src/attributes-test.h | patch | blob | history | |
src/color-profile-test.h | patch | blob | history | |
src/mod360-test.cpp | [deleted file] | patch | blob | history |
src/mod360-test.h | [new file with mode: 0644] | patch | blob |
src/round-test.cpp | [deleted file] | patch | blob | history |
src/round-test.h | [new file with mode: 0644] | patch | blob |
src/sp-gradient-test.cpp | [deleted file] | patch | blob | history |
src/sp-gradient-test.h | [new file with mode: 0644] | patch | blob |
src/sp-style-elem-test.cpp | [deleted file] | patch | blob | history |
src/sp-style-elem-test.h | [new file with mode: 0644] | patch | blob |
src/style-test.h | [new file with mode: 0644] | patch | blob |
src/test-helpers.h | [new file with mode: 0644] | patch | blob |
diff --git a/ChangeLog b/ChangeLog
index ea23609aa152c77fbfc903b8e322750d6cffd708..e98b0264e6624886047d9f5222b612f3bb238841 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
+2006-05-01 Jon A. Cruz <jon@joncruz.org>
+
+ * src/Makefile.am, src/Makefile_insert, src/attributes-test.h,
+ src/color-profile-test.h, src/mod360-test.cpp, src/mod360-test.h,
+ src/round-test.cpp, src/round-test.h, src/sp-gradient-test.cpp,
+ src/sp-gradient-test.h, src/sp-style-elem-test.cpp,
+ src/sp-style-elem-test.h, src/style-test.h, src/test-helpers.h:
+ Replaced four more tests with CxxTest versions.
+
2006-05-01 MenTaLguY <mental@rydia.net>
* src/display/nr-arena-item.cpp:
diff --git a/src/Makefile.am b/src/Makefile.am
index 1f6bcefab4ef3219d04a5c4b6fd66c06322e01ae..6155568a23bd141a1d12e5385da0b2021acee91c 100644 (file)
--- a/src/Makefile.am
+++ b/src/Makefile.am
TESTS = \
test-all$(EXEEXT) \
- mod360-test$(EXEEXT) \
- round-test$(EXEEXT) \
- sp-gradient-test$(EXEEXT) \
- sp-style-elem-test$(EXEEXT) \
style-test$(EXEEXT) \
display/bezier-utils-test$(EXEEXT) \
helper/units-test$(EXEEXT) \
check_PROGRAMS = \
test-all \
- mod360-test \
- round-test \
- sp-gradient-test \
- sp-style-elem-test \
style-test \
display/bezier-utils-test \
helper/units-test \
diff --git a/src/Makefile_insert b/src/Makefile_insert
index 18f6b7b039b442fd3a75fc78c5155d6e07fb23a1..531882f8d295cef41ebc666e4fba60fbdac030bd 100644 (file)
--- a/src/Makefile_insert
+++ b/src/Makefile_insert
inkview_SOURCES = inkview.cpp $(win32_sources)
inkview_LDADD = $(all_libs)
-mod360_test_SOURCES = mod360-test.cpp
-mod360_test_LDADD = libinkpre.a -lglib-2.0
-
-round_test_SOURCES = round-test.cpp
-round_test_LDADD = libinkpost.a
-
-sp_gradient_test_SOURCES = sp-gradient-test.cpp
-sp_gradient_test_LDADD = $(all_libs)
-
-sp_style_elem_test_SOURCES = sp-style-elem-test.cpp
-sp_style_elem_test_LDADD = $(all_libs)
-
style_test_SOURCES = style-test.cpp
style_test_LDADD = $(all_libs)
color-profile-test.h \
dir-util-test.h \
extract-uri-test.h \
+ mod360-test.h \
+ round-test.h \
+ sp-gradient-test.h \
+ sp-style-elem-test.h \
+ style-test.h \
verbs-test.h
diff --git a/src/attributes-test.h b/src/attributes-test.h
index ffef1b24454fb6b64cceeda8a962bd9c7b87dbb4..8bf6c70cb13cc382b775940ec52327714b7cf494 100644 (file)
--- a/src/attributes-test.h
+++ b/src/attributes-test.h
+#ifndef SEEN_ATTRIBUTES_TEST_H
+#define SEEN_ATTRIBUTES_TEST_H
+
#include <cxxtest/TestSuite.h>
#include <vector>
}
};
+#endif // SEEN_ATTRIBUTES_TEST_H
+
/*
Local Variables:
mode:c++
index 56134ef4ae3fe338085f8a2c19f2c1436a2a3df7..5cd58c15cb1bde57aac4aa394c50ffc987c870eb 100644 (file)
--- a/src/color-profile-test.h
+++ b/src/color-profile-test.h
+#ifndef SEEN_COLOR_PROFILE_TEST_H
+#define SEEN_COLOR_PROFILE_TEST_H
#include <cxxtest/TestSuite.h>
#include <cassert>
-#include "inkscape-private.h"
-#include "sp-object.h"
-#include "document.h"
+#include "test-helpers.h"
+
#include "color-profile.h"
#include "color-profile-fns.h"
using Inkscape::ColorProfile;
-/// 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
-
class ColorProfileTest : public CxxTest::TestSuite
{
public:
+ SPDocument* _doc;
ColorProfileTest() :
- TestSuite(),
_doc(0)
{
}
- virtual ~ColorProfileTest() {}
-// createSuite and destroySuite get us per-suite setup and teardown
-// without us having to worry about static initialization order, etc.
- static ColorProfileTest *createSuite()
+ virtual ~ColorProfileTest()
{
- ColorProfileTest* suite = 0;
- bool canRun = false;
-
- g_type_init();
- Inkscape::GC::init();
+ if ( _doc )
+ {
+ sp_document_unref( _doc );
+ }
+ }
+ static void createSuiteSubclass( ColorProfileTest*& dst )
+ {
ColorProfile *prof = static_cast<ColorProfile *>(g_object_new(COLORPROFILE_TYPE, NULL));
- canRun = prof;
- canRun &= prof->rendering_intent == (guint)Inkscape::RENDERING_INTENT_UNKNOWN;
- TS_ASSERT_EQUALS( prof->rendering_intent, (guint)Inkscape::RENDERING_INTENT_UNKNOWN );
- g_object_unref(prof);
-
- if ( canRun ) {
- // Create the global inkscape object.
- static_cast<void>(g_object_new(inkscape_get_type(), NULL));
- SPDocument* tmp = sp_document_new_dummy();
- if ( tmp ) {
- suite = new ColorProfileTest();
- suite->_doc = tmp;
+ if ( prof ) {
+ if ( prof->rendering_intent == (guint)Inkscape::RENDERING_INTENT_UNKNOWN ) {
+ TS_ASSERT_EQUALS( prof->rendering_intent, (guint)Inkscape::RENDERING_INTENT_UNKNOWN );
+ dst = new ColorProfileTest();
}
+ g_object_unref(prof);
}
+ }
+// createSuite and destroySuite get us per-suite setup and teardown
+// without us having to worry about static initialization order, etc.
+ static ColorProfileTest *createSuite()
+ {
+ ColorProfileTest* suite = Inkscape::createSuiteAndDocument<ColorProfileTest>( createSuiteSubclass );
return suite;
}
delete suite;
}
-
- SPDocument* _doc;
-
+ // ---------------------------------------------------------------
+ // ---------------------------------------------------------------
// ---------------------------------------------------------------
void testSetRenderingIntent()
}
};
+#endif // SEEN_COLOR_PROFILE_TEST_H
+
/*
Local Variables:
mode:c++
diff --git a/src/mod360-test.cpp b/src/mod360-test.cpp
--- a/src/mod360-test.cpp
+++ /dev/null
@@ -1,70 +0,0 @@
-#include <utest/utest.h>
-#include "mod360.h"
-#include <glib.h>
-#include <math.h>
-
-/** Note: doesn't distinguish between 0.0 and -0.0. */
-static bool same_double(double const x, double const y)
-{
- return ( ( isnan(x) && isnan(y) )
- || ( x == y ) );
-}
-
-int main(int argc, char **argv)
-{
- double const inf = 1e400;
- double const nan = inf - inf;
-
- utest_start("mod360.cpp");
-
- UTEST_TEST("same_double") {
- double const sd_cases[] = {inf, -inf, nan, 0.0, -1.0, 1.0, 8.0};
- for (unsigned i = 0; i < G_N_ELEMENTS(sd_cases); ++i) {
- for (unsigned j = 0; j < G_N_ELEMENTS(sd_cases); ++j) {
- UTEST_ASSERT( same_double(sd_cases[i], sd_cases[j])
- == ( i == j ) );
- }
- }
- }
-
- UTEST_TEST("mod360") {
- struct Case {
- double x;
- double y;
- } const cases[] = {
- {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) {
- Case const &c = cases[i];
- UTEST_ASSERT(same_double(mod360(c.x), c.y));
- }
- }
-
- return ( utest_end()
- ? EXIT_SUCCESS
- : EXIT_FAILURE );
-}
-
-/*
- 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:encoding=utf-8:textwidth=99 :
diff --git a/src/mod360-test.h b/src/mod360-test.h
--- /dev/null
+++ b/src/mod360-test.h
@@ -0,0 +1,58 @@
+
+#ifndef SEEN_MOD_360_TEST_H
+#define SEEN_MOD_360_TEST_H
+
+#include <cxxtest/TestSuite.h>
+
+#include <isnan.h>
+
+#include "mod360.h"
+
+
+class Mod360Test : public CxxTest::TestSuite
+{
+public:
+ static double const inf = 1e400;
+ static double const nan = inf - inf;
+
+ 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:encoding=utf-8:textwidth=99 :
+
diff --git a/src/round-test.cpp b/src/round-test.cpp
--- a/src/round-test.cpp
+++ /dev/null
@@ -1,91 +0,0 @@
-#include <cassert>
-#include <functional>
-#include <glib/gmacros.h>
-
-#include <utest/test-1ary-cases.h>
-#include <utest/utest.h>
-#include <round.h>
-
-static Case1<double, double> const nonneg_round_cases[] = {
- { 5.0, 5.0 },
- { 0.0, 0.0 },
- { 5.4, 5.0 },
- { 5.6, 6.0 },
- { 1e-7, 0.0 },
- { 1e7 + .49, 1e7 },
- { 1e7 + .51, 1e7 + 1 },
- { 1e12 + .49, 1e12 },
- { 1e12 + .51, 1e12 + 1 },
- { 1e40, 1e40 }
-};
-
-static Case1<double, double> nonpos_round_cases[G_N_ELEMENTS(nonneg_round_cases)];
-
-static void fill_nonpos_round_cases()
-{
- assert(G_N_ELEMENTS(nonneg_round_cases) == G_N_ELEMENTS(nonpos_round_cases));
- for(unsigned i = 0; i < G_N_ELEMENTS(nonpos_round_cases); ++i) {
- nonpos_round_cases[i].f_arg0 = -nonneg_round_cases[i].f_arg0;
- nonpos_round_cases[i].valid_arg0 = -nonneg_round_cases[i].valid_arg0;
- }
-}
-
-static bool
-test_round()
-{
- utest_start("round");
- test_1ary_cases<double, double, double, std::equal_to<double> >
- ("non-neg round",
- Inkscape::round,
- G_N_ELEMENTS(nonneg_round_cases), nonneg_round_cases);
-
- fill_nonpos_round_cases();
-
- test_1ary_cases<double, double, double, std::equal_to<double> >
- ("non-pos round",
- Inkscape::round,
- G_N_ELEMENTS(nonpos_round_cases), nonpos_round_cases);
-
-#if 0
- for(unsigned i = 0; i < G_N_ELEMENTS(round_cases); ++i) {
- RoundCase const &c = round_cases[i];
- double const got = Inkscape::round(c.unrounded);
- UTEST_ASSERT( got == c.exp_rounded );
-
- double const neg_got = Inkscape::round(-c.unrounded);
- UTEST_ASSERT( neg_got = -c.exp_rounded );
- }
-#endif
- return utest_end();
-}
-
-#if 0
-/* Deliberately down here just to ensure that correct behaviour of Inkscape::round doesn't depend
- on #including decimal-round.h. (decimal-round.h already #includes round.h, so there's no point
- checking the other way around.) */
-#include <decimal-round.h>
-
-static void
-test_decimal_round()
-{
-}
-#endif
-
-int main()
-{
- int const ret = ( test_round()
- ? EXIT_SUCCESS
- : EXIT_FAILURE );
- return ret;
-}
-
-/*
- 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 :
diff --git a/src/round-test.h b/src/round-test.h
--- /dev/null
+++ b/src/round-test.h
@@ -0,0 +1,91 @@
+
+#ifndef SEEN_ROUND_TEST_H
+#define SEEN_ROUND_TEST_H
+
+#include <cxxtest/TestSuite.h>
+
+#include <vector>
+#include <round.h>
+
+class RoundTest : public CxxTest::TestSuite
+{
+public:
+ struct Case {
+ double arg0;
+ double ret;
+ };
+
+ std::vector<Case> nonneg_round_cases;
+ std::vector<Case> nonpos_round_cases;
+
+ RoundTest() :
+ TestSuite()
+ {
+ Case cases[] = {
+ { 5.0, 5.0 },
+ { 0.0, 0.0 },
+ { 5.4, 5.0 },
+ { 5.6, 6.0 },
+ { 1e-7, 0.0 },
+ { 1e7 + .49, 1e7 },
+ { 1e7 + .51, 1e7 + 1 },
+ { 1e12 + .49, 1e12 },
+ { 1e12 + .51, 1e12 + 1 },
+ { 1e40, 1e40 }
+ };
+
+ for ( size_t i = 0; i < G_N_ELEMENTS(cases); i++ )
+ {
+ nonneg_round_cases.push_back( cases[i] );
+
+ Case tmp = {-nonneg_round_cases[i].arg0, -nonneg_round_cases[i].ret};
+ nonpos_round_cases.push_back( tmp );
+ }
+ }
+
+ virtual ~RoundTest()
+ {
+ }
+
+ static RoundTest *createSuite() { return new RoundTest(); }
+ static void destroySuite( RoundTest *suite ) { delete suite; }
+
+// -------------------------------------------------------------------------
+// -------------------------------------------------------------------------
+
+
+
+ void testNonNegRound()
+ {
+ for ( size_t i = 0; i < nonneg_round_cases.size(); i++ )
+ {
+ double result = Inkscape::round( nonneg_round_cases[i].arg0 );
+ TS_ASSERT_EQUALS( result, nonneg_round_cases[i].ret );
+ }
+ }
+
+ void testNonPosRoung()
+ {
+ for ( size_t i = 0; i < nonpos_round_cases.size(); i++ )
+ {
+ double result = Inkscape::round( nonpos_round_cases[i].arg0 );
+ TS_ASSERT_EQUALS( result, nonpos_round_cases[i].ret );
+ }
+ }
+
+};
+
+
+#endif // SEEN_ROUND_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:encoding=utf-8:textwidth=99 :
+
diff --git a/src/sp-gradient-test.cpp b/src/sp-gradient-test.cpp
--- a/src/sp-gradient-test.cpp
+++ /dev/null
@@ -1,139 +0,0 @@
-#include "attributes.h"
-#include "inkscape-private.h"
-#include "sp-gradient.h"
-#include "sp-object.h"
-#include "document.h"
-#include "libnr/nr-matrix.h"
-#include "libnr/nr-matrix-fns.h"
-#include "libnr/nr-matrix-ops.h"
-#include "libnr/nr-rect.h"
-#include "libnr/nr-rotate-fns.h"
-#include "svg/svg.h"
-#include "utest/utest.h"
-#include "xml/repr.h"
-
-/// Dummy functions to keep linker happy
-int sp_main_gui (int, char const**) { return 0; }
-int sp_main_console (int, char const**) { return 0; }
-
-static bool
-test_gradient()
-{
- utest_start("gradient");
- UTEST_TEST("init") {
- SPGradient *gr = static_cast<SPGradient *>(g_object_new(SP_TYPE_GRADIENT, NULL));
- UTEST_ASSERT(gr->gradientTransform.test_identity());
- UTEST_ASSERT(gr->gradientTransform == NR::identity());
- g_object_unref(gr);
- }
-
- /* Create the global inkscape object. */
- static_cast<void>(g_object_new(inkscape_get_type(), NULL));
-
-
- SPDocument *doc = sp_document_new_dummy();
-
- UTEST_TEST("sp_object_set(\"gradientTransform\")") {
- SPGradient *gr = static_cast<SPGradient *>(g_object_new(SP_TYPE_GRADIENT, NULL));
- SP_OBJECT(gr)->document = doc;
- sp_object_set(SP_OBJECT(gr), SP_ATTR_GRADIENTTRANSFORM, "translate(5, 8)");
- UTEST_ASSERT(gr->gradientTransform == NR::Matrix(NR::translate(5, 8)));
- sp_object_set(SP_OBJECT(gr), SP_ATTR_GRADIENTTRANSFORM, "");
- UTEST_ASSERT(gr->gradientTransform == NR::identity());
- sp_object_set(SP_OBJECT(gr), SP_ATTR_GRADIENTTRANSFORM, "rotate(90)");
- UTEST_ASSERT(gr->gradientTransform == NR::Matrix(rotate_degrees(90)));
- g_object_unref(gr);
- }
-
- UTEST_TEST("write") {
- SPGradient *gr = static_cast<SPGradient *>(g_object_new(SP_TYPE_GRADIENT, NULL));
- SP_OBJECT(gr)->document = doc;
- sp_object_set(SP_OBJECT(gr), SP_ATTR_GRADIENTTRANSFORM, "matrix(0, 1, -1, 0, 0, 0)");
- Inkscape::XML::Node *repr = sp_repr_new("svg:radialGradient");
- SP_OBJECT(gr)->updateRepr(repr, SP_OBJECT_WRITE_ALL);
- {
- gchar const *tr = repr->attribute("gradientTransform");
- NR::Matrix svd;
- bool const valid = sp_svg_transform_read(tr, &svd);
- UTEST_ASSERT(valid);
- UTEST_ASSERT(svd == NR::Matrix(rotate_degrees(90)));
- }
- g_object_unref(gr);
- }
-
- UTEST_TEST("get_g2d, get_gs2d, set_gs2d") {
- SPGradient *gr = static_cast<SPGradient *>(g_object_new(SP_TYPE_GRADIENT, NULL));
- SP_OBJECT(gr)->document = doc;
- NR::Matrix const grXform(2, 1,
- 1, 3,
- 4, 6);
- gr->gradientTransform = grXform;
- NR::Rect const unit_rect(NR::Point(0, 0), NR::Point(1, 1));
- {
- NR::Matrix const g2d(sp_gradient_get_g2d_matrix(gr, NR::identity(), unit_rect));
- NR::Matrix const gs2d(sp_gradient_get_gs2d_matrix(gr, NR::identity(), unit_rect));
- UTEST_ASSERT(g2d == NR::identity());
- UTEST_ASSERT(NR::matrix_equalp(gs2d, gr->gradientTransform * g2d, 1e-12));
-
- sp_gradient_set_gs2d_matrix(gr, NR::identity(), unit_rect, gs2d);
- UTEST_ASSERT(NR::matrix_equalp(gr->gradientTransform, grXform, 1e-12));
- }
-
- gr->gradientTransform = grXform;
- NR::Matrix const funny(2, 3,
- 4, 5,
- 6, 7);
- {
- NR::Matrix const g2d(sp_gradient_get_g2d_matrix(gr, funny, unit_rect));
- NR::Matrix const gs2d(sp_gradient_get_gs2d_matrix(gr, funny, unit_rect));
- UTEST_ASSERT(g2d == funny);
- UTEST_ASSERT(NR::matrix_equalp(gs2d, gr->gradientTransform * g2d, 1e-12));
-
- sp_gradient_set_gs2d_matrix(gr, funny, unit_rect, gs2d);
- UTEST_ASSERT(NR::matrix_equalp(gr->gradientTransform, grXform, 1e-12));
- }
-
- gr->gradientTransform = grXform;
- NR::Rect const larger_rect(NR::Point(5, 6), NR::Point(8, 10));
- {
- NR::Matrix const g2d(sp_gradient_get_g2d_matrix(gr, funny, larger_rect));
- NR::Matrix const gs2d(sp_gradient_get_gs2d_matrix(gr, funny, larger_rect));
- UTEST_ASSERT(g2d == NR::Matrix(3, 0,
- 0, 4,
- 5, 6) * funny);
- UTEST_ASSERT(NR::matrix_equalp(gs2d, gr->gradientTransform * g2d, 1e-12));
-
- sp_gradient_set_gs2d_matrix(gr, funny, larger_rect, gs2d);
- UTEST_ASSERT(NR::matrix_equalp(gr->gradientTransform, grXform, 1e-12));
-
- sp_object_set(SP_OBJECT(gr), SP_ATTR_GRADIENTUNITS, "userSpaceOnUse");
- NR::Matrix const user_g2d(sp_gradient_get_g2d_matrix(gr, funny, larger_rect));
- NR::Matrix const user_gs2d(sp_gradient_get_gs2d_matrix(gr, funny, larger_rect));
- UTEST_ASSERT(user_g2d == funny);
- UTEST_ASSERT(NR::matrix_equalp(user_gs2d, gr->gradientTransform * user_g2d, 1e-12));
- }
- g_object_unref(gr);
- }
-
- return utest_end();
-}
-
-int main()
-{
- g_type_init();
- Inkscape::GC::init();
- return ( test_gradient()
- ? EXIT_SUCCESS
- : EXIT_FAILURE );
-}
-
-/*
- 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:encoding=utf-8:textwidth=99 :
diff --git a/src/sp-gradient-test.h b/src/sp-gradient-test.h
--- /dev/null
+++ b/src/sp-gradient-test.h
@@ -0,0 +1,160 @@
+
+#ifndef SEEN_SP_GRADIENT_TEST_H
+#define SEEN_SP_GRADIENT_TEST_H
+
+#include "document-using-test.h"
+
+
+#include "sp-gradient.h"
+#include "svg/svg.h"
+#include "xml/repr.h"
+
+
+class SPGradientTest : public DocumentUsingTest
+{
+public:
+ SPDocument* _doc;
+
+ SPGradientTest() :
+ _doc(0)
+ {
+ }
+
+ virtual ~SPGradientTest()
+ {
+ if ( _doc )
+ {
+ sp_document_unref( _doc );
+ }
+ }
+
+ static void createSuiteSubclass( SPGradientTest *& dst )
+ {
+ SPGradient *gr = static_cast<SPGradient *>(g_object_new(SP_TYPE_GRADIENT, NULL));
+ if ( gr ) {
+ UTEST_ASSERT(gr->gradientTransform.test_identity());
+ UTEST_ASSERT(gr->gradientTransform == NR::identity());
+ g_object_unref(gr);
+
+ dst = new SPGradientTest();
+ }
+ }
+
+ static SPGradientTest *createSuite()
+ {
+ return Inkscape::createSuiteAndDocument<SPGradientTest>( createSuiteSubclass );
+ }
+
+ static void destroySuite( SPGradientTest *suite ) { delete suite; }
+
+// -------------------------------------------------------------------------
+// -------------------------------------------------------------------------
+
+ void testSetGradientTransform()
+ {
+ SPGradient *gr = static_cast<SPGradient *>(g_object_new(SP_TYPE_GRADIENT, NULL));
+ SP_OBJECT(gr)->document = _doc;
+
+ sp_object_set(SP_OBJECT(gr), SP_ATTR_GRADIENTTRANSFORM, "translate(5, 8)");
+ TS_ASSERT_EQUALS( gr->gradientTransform, NR::Matrix(NR::translate(5, 8)) );
+
+ sp_object_set(SP_OBJECT(gr), SP_ATTR_GRADIENTTRANSFORM, "");
+ TS_ASSERT_EQUALS( gr->gradientTransform, NR::identity() );
+
+ sp_object_set(SP_OBJECT(gr), SP_ATTR_GRADIENTTRANSFORM, "rotate(90)");
+ TS_ASSERT_EQUALS( gr->gradientTransform, NR::Matrix(rotate_degrees(90)) );
+
+ g_object_unref(gr);
+ }
+
+
+ void testWrite()
+ {
+ SPGradient *gr = static_cast<SPGradient *>(g_object_new(SP_TYPE_GRADIENT, NULL));
+ SP_OBJECT(gr)->document = _doc;
+
+ sp_object_set(SP_OBJECT(gr), SP_ATTR_GRADIENTTRANSFORM, "matrix(0, 1, -1, 0, 0, 0)");
+ Inkscape::XML::Node *repr = sp_repr_new("svg:radialGradient");
+ SP_OBJECT(gr)->updateRepr(repr, SP_OBJECT_WRITE_ALL);
+ {
+ gchar const *tr = repr->attribute("gradientTransform");
+ NR::Matrix svd;
+ bool const valid = sp_svg_transform_read(tr, &svd);
+ TS_ASSERT( valid );
+ TS_ASSERT_EQUALS( svd, NR::Matrix(rotate_degrees(90)) );
+ }
+
+ g_object_unref(gr);
+ }
+
+
+ void testGetG2dGetGs2dSetGs2d()
+ {
+ SPGradient *gr = static_cast<SPGradient *>(g_object_new(SP_TYPE_GRADIENT, NULL));
+ SP_OBJECT(gr)->document = _doc;
+ NR::Matrix const grXform(2, 1,
+ 1, 3,
+ 4, 6);
+ gr->gradientTransform = grXform;
+ NR::Rect const unit_rect(NR::Point(0, 0), NR::Point(1, 1));
+ {
+ NR::Matrix const g2d(sp_gradient_get_g2d_matrix(gr, NR::identity(), unit_rect));
+ NR::Matrix const gs2d(sp_gradient_get_gs2d_matrix(gr, NR::identity(), unit_rect));
+ TS_ASSERT_EQUALS( g2d, NR::identity() );
+ TS_ASSERT( NR::matrix_equalp(gs2d, gr->gradientTransform * g2d, 1e-12) );
+
+ sp_gradient_set_gs2d_matrix(gr, NR::identity(), unit_rect, gs2d);
+ TS_ASSERT( NR::matrix_equalp(gr->gradientTransform, grXform, 1e-12) );
+ }
+
+ gr->gradientTransform = grXform;
+ NR::Matrix const funny(2, 3,
+ 4, 5,
+ 6, 7);
+ {
+ NR::Matrix const g2d(sp_gradient_get_g2d_matrix(gr, funny, unit_rect));
+ NR::Matrix const gs2d(sp_gradient_get_gs2d_matrix(gr, funny, unit_rect));
+ TS_ASSERT_EQUALS( g2d, funny );
+ TS_ASSERT( NR::matrix_equalp(gs2d, gr->gradientTransform * g2d, 1e-12) );
+
+ sp_gradient_set_gs2d_matrix(gr, funny, unit_rect, gs2d);
+ TS_ASSERT( NR::matrix_equalp(gr->gradientTransform, grXform, 1e-12) );
+ }
+
+ gr->gradientTransform = grXform;
+ NR::Rect const larger_rect(NR::Point(5, 6), NR::Point(8, 10));
+ {
+ NR::Matrix const g2d(sp_gradient_get_g2d_matrix(gr, funny, larger_rect));
+ NR::Matrix const gs2d(sp_gradient_get_gs2d_matrix(gr, funny, larger_rect));
+ TS_ASSERT_EQUALS( g2d, NR::Matrix(3, 0,
+ 0, 4,
+ 5, 6) * funny );
+ TS_ASSERT( NR::matrix_equalp(gs2d, gr->gradientTransform * g2d, 1e-12) );
+
+ sp_gradient_set_gs2d_matrix(gr, funny, larger_rect, gs2d);
+ TS_ASSERT( NR::matrix_equalp(gr->gradientTransform, grXform, 1e-12) );
+
+ sp_object_set(SP_OBJECT(gr), SP_ATTR_GRADIENTUNITS, "userSpaceOnUse");
+ NR::Matrix const user_g2d(sp_gradient_get_g2d_matrix(gr, funny, larger_rect));
+ NR::Matrix const user_gs2d(sp_gradient_get_gs2d_matrix(gr, funny, larger_rect));
+ TS_ASSERT_EQUALS( user_g2d, funny );
+ TS_ASSERT( NR::matrix_equalp(user_gs2d, gr->gradientTransform * user_g2d, 1e-12) );
+ }
+ g_object_unref(gr);
+ }
+
+};
+
+
+#endif // SEEN_SP_GRADIENT_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:encoding=utf-8:textwidth=99 :
diff --git a/src/sp-style-elem-test.cpp b/src/sp-style-elem-test.cpp
+++ /dev/null
@@ -1,118 +0,0 @@
-#include "attributes.h"
-#include "document.h"
-#include "inkscape-private.h"
-#include "sp-style-elem.h"
-#include "streq.h"
-#include "utest/utest.h"
-#include "xml/repr.h"
-
-/// Dummy functions to keep linker happy
-int sp_main_gui (int, char const**) { return 0; }
-int sp_main_console (int, char const**) { return 0; }
-
-static bool
-test_style_elem()
-{
- utest_start("SPStyleElem");
-//#if 0
- UTEST_TEST("init") {
- SPStyleElem *style_elem = static_cast<SPStyleElem *>(g_object_new(SP_TYPE_STYLE_ELEM, NULL));
- UTEST_ASSERT(!style_elem->is_css);
- UTEST_ASSERT(style_elem->media.print);
- UTEST_ASSERT(style_elem->media.screen);
- g_object_unref(style_elem);
- }
-//#endif
-
- /* Create the global inkscape object. */
- static_cast<void>(g_object_new(inkscape_get_type(), NULL));
-
-//#if 0
- SPDocument *doc = sp_document_new_dummy();
-
- UTEST_TEST("sp_object_set(\"type\")") {
- SPStyleElem *style_elem = static_cast<SPStyleElem *>(g_object_new(SP_TYPE_STYLE_ELEM, NULL));
- SP_OBJECT(style_elem)->document = doc;
- sp_object_set(SP_OBJECT(style_elem), SP_ATTR_TYPE, "something unrecognized");
- UTEST_ASSERT(!style_elem->is_css);
- sp_object_set(SP_OBJECT(style_elem), SP_ATTR_TYPE, "text/css");
- UTEST_ASSERT(style_elem->is_css);
- sp_object_set(SP_OBJECT(style_elem), SP_ATTR_TYPE, "atext/css");
- UTEST_ASSERT(!style_elem->is_css);
- sp_object_set(SP_OBJECT(style_elem), SP_ATTR_TYPE, "text/cssx");
- UTEST_ASSERT(!style_elem->is_css);
- g_object_unref(style_elem);
- }
-
- UTEST_TEST("write") {
- SPStyleElem *style_elem = SP_STYLE_ELEM(g_object_new(SP_TYPE_STYLE_ELEM, NULL));
- SP_OBJECT(style_elem)->document = doc;
- sp_object_set(SP_OBJECT(style_elem), SP_ATTR_TYPE, "text/css");
- Inkscape::XML::Node *repr = sp_repr_new("svg:style");
- SP_OBJECT(style_elem)->updateRepr(repr, SP_OBJECT_WRITE_ALL);
- {
- gchar const *typ = repr->attribute("type");
- UTEST_ASSERT(streq(typ, "text/css"));
- }
- g_object_unref(style_elem);
- }
-
- UTEST_TEST("build") {
- SPStyleElem &style_elem = *SP_STYLE_ELEM(g_object_new(SP_TYPE_STYLE_ELEM, NULL));
- Inkscape::XML::Node *const repr = sp_repr_new("svg:style");
- repr->setAttribute("type", "text/css");
- sp_object_invoke_build(&style_elem, doc, repr, false);
- UTEST_ASSERT(style_elem.is_css);
- UTEST_ASSERT(style_elem.media.print);
- UTEST_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);
- }
-
- g_object_unref(&style_elem);
- Inkscape::GC::release(repr);
- }
-
- UTEST_TEST("read_content") {
- SPStyleElem &style_elem = *SP_STYLE_ELEM(g_object_new(SP_TYPE_STYLE_ELEM, NULL));
- Inkscape::XML::Node *const repr = sp_repr_new("svg:style");
- repr->setAttribute("type", "text/css");
- Inkscape::XML::Node *const content_repr = sp_repr_new_text(".myclass { }");
- repr->addChild(content_repr, NULL);
- sp_object_invoke_build(&style_elem, doc, repr, false);
- UTEST_ASSERT(style_elem.is_css);
- UTEST_ASSERT(doc->style_cascade);
- CRStyleSheet const *const stylesheet = cr_cascade_get_sheet(doc->style_cascade, ORIGIN_AUTHOR);
- UTEST_ASSERT(stylesheet != NULL);
- UTEST_ASSERT(stylesheet->statements != NULL);
- g_object_unref(&style_elem);
- Inkscape::GC::release(repr);
- }
-//#endif
- return utest_end();
-}
-
-int main()
-{
- g_type_init();
- Inkscape::GC::init();
- return ( test_style_elem()
- ? EXIT_SUCCESS
- : EXIT_FAILURE );
-}
-
-/*
- 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:encoding=utf-8:textwidth=99 :
diff --git a/src/sp-style-elem-test.h b/src/sp-style-elem-test.h
--- /dev/null
+++ b/src/sp-style-elem-test.h
@@ -0,0 +1,148 @@
+
+#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:
+ SPDocument* _doc;
+
+ SPStyleElemTest() :
+ _doc(0)
+ {
+ }
+
+ virtual ~SPStyleElemTest()
+ {
+ if ( _doc )
+ {
+ sp_document_unref( _doc );
+ }
+ }
+
+ static void createSuiteSubclass( SPStyleElemTest *& dst )
+ {
+ SPStyleElem *style_elem = static_cast<SPStyleElem *>(g_object_new(SP_TYPE_STYLE_ELEM, NULL));
+ if ( style_elem ) {
+ UTEST_ASSERT(!style_elem->is_css);
+ UTEST_ASSERT(style_elem->media.print);
+ UTEST_ASSERT(style_elem->media.screen);
+ g_object_unref(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 = static_cast<SPStyleElem *>(g_object_new(SP_TYPE_STYLE_ELEM, NULL));
+ SP_OBJECT(style_elem)->document = _doc;
+
+ sp_object_set(SP_OBJECT(style_elem), SP_ATTR_TYPE, "something unrecognized");
+ TS_ASSERT( !style_elem->is_css );
+
+ sp_object_set(SP_OBJECT(style_elem), SP_ATTR_TYPE, "text/css");
+ TS_ASSERT( style_elem->is_css );
+
+ sp_object_set(SP_OBJECT(style_elem), SP_ATTR_TYPE, "atext/css");
+ TS_ASSERT( !style_elem->is_css );
+
+ sp_object_set(SP_OBJECT(style_elem), SP_ATTR_TYPE, "text/cssx");
+ TS_ASSERT( !style_elem->is_css );
+
+ g_object_unref(style_elem);
+ }
+
+ void testWrite()
+ {
+ SPStyleElem *style_elem = SP_STYLE_ELEM(g_object_new(SP_TYPE_STYLE_ELEM, NULL));
+ SP_OBJECT(style_elem)->document = _doc;
+
+ sp_object_set(SP_OBJECT(style_elem), SP_ATTR_TYPE, "text/css");
+ Inkscape::XML::Node *repr = sp_repr_new("svg:style");
+ SP_OBJECT(style_elem)->updateRepr(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") );
+ }
+ }
+
+ g_object_unref(style_elem);
+ }
+
+ void testBuild()
+ {
+ SPStyleElem &style_elem = *SP_STYLE_ELEM(g_object_new(SP_TYPE_STYLE_ELEM, NULL));
+ Inkscape::XML::Node *const repr = sp_repr_new("svg:style");
+ repr->setAttribute("type", "text/css");
+ sp_object_invoke_build(&style_elem, _doc, 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);
+ }
+
+ g_object_unref(&style_elem);
+ Inkscape::GC::release(repr);
+ }
+
+ void testReadContent()
+ {
+ SPStyleElem &style_elem = *SP_STYLE_ELEM(g_object_new(SP_TYPE_STYLE_ELEM, NULL));
+ Inkscape::XML::Node *const repr = sp_repr_new("svg:style");
+ repr->setAttribute("type", "text/css");
+ Inkscape::XML::Node *const content_repr = sp_repr_new_text(".myclass { }");
+ repr->addChild(content_repr, NULL);
+ sp_object_invoke_build(&style_elem, _doc, 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);
+
+ g_object_unref(&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:encoding=utf-8:textwidth=99 :
diff --git a/src/style-test.h b/src/style-test.h
--- /dev/null
+++ b/src/style-test.h
@@ -0,0 +1,27 @@
+
+#ifndef SEEN_STYLE_TEST_H
+#define SEEN_STYLE_TEST_H
+
+#include <cxxtest/TestSuite.h>
+
+
+class StyleTest : public CxxTest::TestSuite
+{
+public:
+
+
+};
+
+
+#endif // SEEN_STYLE_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:encoding=utf-8:textwidth=99 :
diff --git a/src/test-helpers.h b/src/test-helpers.h
--- /dev/null
+++ b/src/test-helpers.h
@@ -0,0 +1,64 @@
+
+#ifndef SEEN_TEST_HELPERS_H
+#define SEEN_TEST_HELPERS_H
+
+
+#include <cxxtest/TestSuite.h>
+
+#include "document.h"
+#include "inkscape-private.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;
+
+ g_type_init();
+ Inkscape::GC::init();
+ if ( !inkscape_get_instance() )
+ {
+ // Create the global inkscape object.
+ static_cast<void>(g_object_new(inkscape_get_type(), NULL));
+ }
+
+ SPDocument* tmp = sp_document_new_dummy();
+ if ( tmp ) {
+ fun( suite );
+ if ( suite )
+ {
+ suite->_doc = tmp;
+ }
+ else
+ {
+ sp_document_unref( 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:encoding=utf-8:textwidth=99 :