From b27b41748a314f1217ac0aab88feb52604257fd7 Mon Sep 17 00:00:00 2001 From: joncruz Date: Mon, 1 May 2006 08:11:44 +0000 Subject: [PATCH] Moved four more tests to CxxTest --- ChangeLog | 9 ++ src/Makefile.am | 8 - src/Makefile_insert | 17 +-- src/attributes-test.h | 5 + src/color-profile-test.h | 63 ++++---- src/mod360-test.cpp | 70 --------- src/mod360-test.h | 58 +++++++ src/round-test.cpp | 91 ----------- src/round-test.h | 91 +++++++++++ ...p-gradient-test.cpp => sp-gradient-test.h} | 135 +++++++++------- ...yle-elem-test.cpp => sp-style-elem-test.h} | 144 +++++++++++------- src/style-test.h | 27 ++++ src/test-helpers.h | 64 ++++++++ 13 files changed, 452 insertions(+), 330 deletions(-) delete mode 100644 src/mod360-test.cpp create mode 100644 src/mod360-test.h delete mode 100644 src/round-test.cpp create mode 100644 src/round-test.h rename src/{sp-gradient-test.cpp => sp-gradient-test.h} (54%) rename src/{sp-style-elem-test.cpp => sp-style-elem-test.h} (50%) create mode 100644 src/style-test.h create mode 100644 src/test-helpers.h diff --git a/ChangeLog b/ChangeLog index ea23609aa..e98b0264e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2006-05-01 Jon A. Cruz + + * 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 * src/display/nr-arena-item.cpp: diff --git a/src/Makefile.am b/src/Makefile.am index 1f6bcefab..6155568a2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -166,10 +166,6 @@ EXTRA_PROGRAMS = \ 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) \ @@ -198,10 +194,6 @@ TESTS = \ 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 18f6b7b03..531882f8d 100644 --- a/src/Makefile_insert +++ b/src/Makefile_insert @@ -319,18 +319,6 @@ inkscape_LDFLAGS = --export-dynamic $(kdeldflags) 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) @@ -342,4 +330,9 @@ test_all_includes = \ 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 ffef1b244..8bf6c70cb 100644 --- a/src/attributes-test.h +++ b/src/attributes-test.h @@ -1,4 +1,7 @@ +#ifndef SEEN_ATTRIBUTES_TEST_H +#define SEEN_ATTRIBUTES_TEST_H + #include #include @@ -478,6 +481,8 @@ struct {char const *attr; bool supported;} const all_attrs[] = { } }; +#endif // SEEN_ATTRIBUTES_TEST_H + /* Local Variables: mode:c++ diff --git a/src/color-profile-test.h b/src/color-profile-test.h index 56134ef4a..5cd58c15c 100644 --- a/src/color-profile-test.h +++ b/src/color-profile-test.h @@ -1,61 +1,53 @@ +#ifndef SEEN_COLOR_PROFILE_TEST_H +#define SEEN_COLOR_PROFILE_TEST_H #include #include -#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(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(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( createSuiteSubclass ); return suite; } @@ -64,9 +56,8 @@ public: delete suite; } - - SPDocument* _doc; - + // --------------------------------------------------------------- + // --------------------------------------------------------------- // --------------------------------------------------------------- void testSetRenderingIntent() @@ -147,6 +138,8 @@ public: } }; +#endif // SEEN_COLOR_PROFILE_TEST_H + /* Local Variables: mode:c++ diff --git a/src/mod360-test.cpp b/src/mod360-test.cpp deleted file mode 100644 index 83f0feba7..000000000 --- a/src/mod360-test.cpp +++ /dev/null @@ -1,70 +0,0 @@ -#include -#include "mod360.h" -#include -#include - -/** 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 new file mode 100644 index 000000000..3f276b24e --- /dev/null +++ b/src/mod360-test.h @@ -0,0 +1,58 @@ + +#ifndef SEEN_MOD_360_TEST_H +#define SEEN_MOD_360_TEST_H + +#include + +#include + +#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 deleted file mode 100644 index efb4b3e83..000000000 --- a/src/round-test.cpp +++ /dev/null @@ -1,91 +0,0 @@ -#include -#include -#include - -#include -#include -#include - -static Case1 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 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 > - ("non-neg round", - Inkscape::round, - G_N_ELEMENTS(nonneg_round_cases), nonneg_round_cases); - - fill_nonpos_round_cases(); - - test_1ary_cases > - ("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 - -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 new file mode 100644 index 000000000..f2918583a --- /dev/null +++ b/src/round-test.h @@ -0,0 +1,91 @@ + +#ifndef SEEN_ROUND_TEST_H +#define SEEN_ROUND_TEST_H + +#include + +#include +#include + +class RoundTest : public CxxTest::TestSuite +{ +public: + struct Case { + double arg0; + double ret; + }; + + std::vector nonneg_round_cases; + std::vector 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.h similarity index 54% rename from src/sp-gradient-test.cpp rename to src/sp-gradient-test.h index 051beb928..7906a3d48 100644 --- a/src/sp-gradient-test.cpp +++ b/src/sp-gradient-test.h @@ -1,53 +1,78 @@ -#include "attributes.h" -#include "inkscape-private.h" + +#ifndef SEEN_SP_GRADIENT_TEST_H +#define SEEN_SP_GRADIENT_TEST_H + +#include "document-using-test.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() +class SPGradientTest : public DocumentUsingTest { - utest_start("gradient"); - UTEST_TEST("init") { +public: + SPDocument* _doc; + + SPGradientTest() : + _doc(0) + { + } + + virtual ~SPGradientTest() + { + if ( _doc ) + { + sp_document_unref( _doc ); + } + } + + static void createSuiteSubclass( SPGradientTest *& dst ) + { SPGradient *gr = static_cast(g_object_new(SP_TYPE_GRADIENT, NULL)); - UTEST_ASSERT(gr->gradientTransform.test_identity()); - UTEST_ASSERT(gr->gradientTransform == NR::identity()); - g_object_unref(gr); + if ( gr ) { + UTEST_ASSERT(gr->gradientTransform.test_identity()); + UTEST_ASSERT(gr->gradientTransform == NR::identity()); + g_object_unref(gr); + + dst = new SPGradientTest(); + } } - /* Create the global inkscape object. */ - static_cast(g_object_new(inkscape_get_type(), NULL)); + static SPGradientTest *createSuite() + { + return Inkscape::createSuiteAndDocument( createSuiteSubclass ); + } + static void destroySuite( SPGradientTest *suite ) { delete suite; } - SPDocument *doc = sp_document_new_dummy(); +// ------------------------------------------------------------------------- +// ------------------------------------------------------------------------- - UTEST_TEST("sp_object_set(\"gradientTransform\")") { + void testSetGradientTransform() + { SPGradient *gr = static_cast(g_object_new(SP_TYPE_GRADIENT, NULL)); - SP_OBJECT(gr)->document = doc; + 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))); + TS_ASSERT_EQUALS( gr->gradientTransform, NR::Matrix(NR::translate(5, 8)) ); + sp_object_set(SP_OBJECT(gr), SP_ATTR_GRADIENTTRANSFORM, ""); - UTEST_ASSERT(gr->gradientTransform == NR::identity()); + TS_ASSERT_EQUALS( gr->gradientTransform, NR::identity() ); + sp_object_set(SP_OBJECT(gr), SP_ATTR_GRADIENTTRANSFORM, "rotate(90)"); - UTEST_ASSERT(gr->gradientTransform == NR::Matrix(rotate_degrees(90))); + TS_ASSERT_EQUALS( gr->gradientTransform, NR::Matrix(rotate_degrees(90)) ); + g_object_unref(gr); } - UTEST_TEST("write") { + + void testWrite() + { SPGradient *gr = static_cast(g_object_new(SP_TYPE_GRADIENT, NULL)); - SP_OBJECT(gr)->document = doc; + 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); @@ -55,15 +80,18 @@ test_gradient() 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))); + TS_ASSERT( valid ); + TS_ASSERT_EQUALS( svd, NR::Matrix(rotate_degrees(90)) ); } + g_object_unref(gr); } - UTEST_TEST("get_g2d, get_gs2d, set_gs2d") { + + void testGetG2dGetGs2dSetGs2d() + { SPGradient *gr = static_cast(g_object_new(SP_TYPE_GRADIENT, NULL)); - SP_OBJECT(gr)->document = doc; + SP_OBJECT(gr)->document = _doc; NR::Matrix const grXform(2, 1, 1, 3, 4, 6); @@ -72,11 +100,11 @@ test_gradient() { 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)); + 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); - UTEST_ASSERT(NR::matrix_equalp(gr->gradientTransform, grXform, 1e-12)); + TS_ASSERT( NR::matrix_equalp(gr->gradientTransform, grXform, 1e-12) ); } gr->gradientTransform = grXform; @@ -86,11 +114,11 @@ test_gradient() { 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)); + 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); - UTEST_ASSERT(NR::matrix_equalp(gr->gradientTransform, grXform, 1e-12)); + TS_ASSERT( NR::matrix_equalp(gr->gradientTransform, grXform, 1e-12) ); } gr->gradientTransform = grXform; @@ -98,34 +126,27 @@ test_gradient() { 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)); + 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); - UTEST_ASSERT(NR::matrix_equalp(gr->gradientTransform, grXform, 1e-12)); + 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)); - UTEST_ASSERT(user_g2d == funny); - UTEST_ASSERT(NR::matrix_equalp(user_gs2d, gr->gradientTransform * user_g2d, 1e-12)); + TS_ASSERT_EQUALS( user_g2d, funny ); + TS_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 ); -} + +#endif // SEEN_SP_GRADIENT_TEST_H /* Local Variables: diff --git a/src/sp-style-elem-test.cpp b/src/sp-style-elem-test.h similarity index 50% rename from src/sp-style-elem-test.cpp rename to src/sp-style-elem-test.h index 97be4fead..e5b2e8a48 100644 --- a/src/sp-style-elem-test.cpp +++ b/src/sp-style-elem-test.h @@ -1,75 +1,110 @@ -#include "attributes.h" -#include "document.h" -#include "inkscape-private.h" + +#ifndef SEEN_SP_STYLE_ELEM_TEST_H +#define SEEN_SP_STYLE_ELEM_TEST_H + +#include + +#include "test-helpers.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() +class SPStyleElemTest : public CxxTest::TestSuite { - utest_start("SPStyleElem"); -//#if 0 - UTEST_TEST("init") { +public: + SPDocument* _doc; + + SPStyleElemTest() : + _doc(0) + { + } + + virtual ~SPStyleElemTest() + { + if ( _doc ) + { + sp_document_unref( _doc ); + } + } + + static void createSuiteSubclass( SPStyleElemTest *& dst ) + { SPStyleElem *style_elem = static_cast(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); + 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(); + } } -//#endif - /* Create the global inkscape object. */ - static_cast(g_object_new(inkscape_get_type(), NULL)); + static SPStyleElemTest *createSuite() + { + return Inkscape::createSuiteAndDocument( createSuiteSubclass ); + } + + static void destroySuite( SPStyleElemTest *suite ) { delete suite; } -//#if 0 - SPDocument *doc = sp_document_new_dummy(); +// ------------------------------------------------------------------------- +// ------------------------------------------------------------------------- - UTEST_TEST("sp_object_set(\"type\")") { + + void testSetType() + { SPStyleElem *style_elem = static_cast(g_object_new(SP_TYPE_STYLE_ELEM, NULL)); - SP_OBJECT(style_elem)->document = doc; + SP_OBJECT(style_elem)->document = _doc; + sp_object_set(SP_OBJECT(style_elem), SP_ATTR_TYPE, "something unrecognized"); - UTEST_ASSERT(!style_elem->is_css); + TS_ASSERT( !style_elem->is_css ); + sp_object_set(SP_OBJECT(style_elem), SP_ATTR_TYPE, "text/css"); - UTEST_ASSERT(style_elem->is_css); + TS_ASSERT( style_elem->is_css ); + sp_object_set(SP_OBJECT(style_elem), SP_ATTR_TYPE, "atext/css"); - UTEST_ASSERT(!style_elem->is_css); + TS_ASSERT( !style_elem->is_css ); + sp_object_set(SP_OBJECT(style_elem), SP_ATTR_TYPE, "text/cssx"); - UTEST_ASSERT(!style_elem->is_css); + TS_ASSERT( !style_elem->is_css ); + g_object_unref(style_elem); } - UTEST_TEST("write") { + void testWrite() + { SPStyleElem *style_elem = SP_STYLE_ELEM(g_object_new(SP_TYPE_STYLE_ELEM, NULL)); - SP_OBJECT(style_elem)->document = doc; + 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")); + TS_ASSERT( typ != NULL ); + if ( typ ) + { + TS_ASSERT_EQUALS( std::string(typ), std::string("text/css") ); + } } + g_object_unref(style_elem); } - UTEST_TEST("build") { + 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); - UTEST_ASSERT(style_elem.is_css); - UTEST_ASSERT(style_elem.media.print); - UTEST_ASSERT(style_elem.media.screen); + 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(_doc->style_cascade); + CRStyleSheet const *const stylesheet = cr_cascade_get_sheet(_doc->style_cascade, ORIGIN_AUTHOR); g_assert(stylesheet); g_assert(stylesheet->statements == NULL); } @@ -78,33 +113,28 @@ test_style_elem() Inkscape::GC::release(repr); } - UTEST_TEST("read_content") { + 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); - 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); + 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 - return utest_end(); -} -int main() -{ - g_type_init(); - Inkscape::GC::init(); - return ( test_style_elem() - ? EXIT_SUCCESS - : EXIT_FAILURE ); -} +}; + + +#endif // SEEN_SP_STYLE_ELEM_TEST_H /* Local Variables: diff --git a/src/style-test.h b/src/style-test.h new file mode 100644 index 000000000..135d03927 --- /dev/null +++ b/src/style-test.h @@ -0,0 +1,27 @@ + +#ifndef SEEN_STYLE_TEST_H +#define SEEN_STYLE_TEST_H + +#include + + +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 new file mode 100644 index 000000000..594f4b7ae --- /dev/null +++ b/src/test-helpers.h @@ -0,0 +1,64 @@ + +#ifndef SEEN_TEST_HELPERS_H +#define SEEN_TEST_HELPERS_H + + +#include + +#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 +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(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 : -- 2.30.2