Code

Extensions. Fix Color Markers extension (crashed when a fill or stroke attribute...
[inkscape.git] / src / color-profile-test.h
index 56134ef4ae3fe338085f8a2c19f2c1436a2a3df7..4b679e5b7e1eeff0dea1d1c035e49e9550085d97 100644 (file)
@@ -1,61 +1,51 @@
 
+#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();
-
-        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 ( _doc )
+        {
+            _doc->doUnref();
+        }
+    }
 
-        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;
+    static void createSuiteSubclass( ColorProfileTest*& dst )
+    {
+        Inkscape::ColorProfile *prof = static_cast<Inkscape::ColorProfile *>(g_object_new(COLORPROFILE_TYPE, NULL));
+        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;
     }
 
@@ -64,9 +54,8 @@ public:
         delete suite; 
     }
 
-
-    SPDocument* _doc;
-
+    // ---------------------------------------------------------------
+    // ---------------------------------------------------------------
     // ---------------------------------------------------------------
 
     void testSetRenderingIntent()
@@ -85,13 +74,13 @@ public:
             {"auto2", (guint)Inkscape::RENDERING_INTENT_UNKNOWN},
         };
 
-        ColorProfile *prof = static_cast<ColorProfile *>(g_object_new(COLORPROFILE_TYPE, NULL));
+        Inkscape::ColorProfile *prof = static_cast<Inkscape::ColorProfile *>(g_object_new(COLORPROFILE_TYPE, NULL));
         TS_ASSERT( prof );
         SP_OBJECT(prof)->document = _doc;
 
         for ( size_t i = 0; i < G_N_ELEMENTS( cases ); i++ ) {
             std::string descr(cases[i].attr);
-            sp_object_set(SP_OBJECT(prof), SP_ATTR_RENDERING_INTENT, cases[i].attr);
+            SP_OBJECT(prof)->setKeyValue( SP_ATTR_RENDERING_INTENT, cases[i].attr);
             TSM_ASSERT_EQUALS( descr, prof->rendering_intent, (guint)cases[i].intVal );
         }
 
@@ -105,18 +94,18 @@ public:
             "something",
         };
 
-        ColorProfile *prof = static_cast<ColorProfile *>(g_object_new(COLORPROFILE_TYPE, NULL));
+        Inkscape::ColorProfile *prof = static_cast<Inkscape::ColorProfile *>(g_object_new(COLORPROFILE_TYPE, NULL));
         TS_ASSERT( prof );
         SP_OBJECT(prof)->document = _doc;
 
         for ( size_t i = 0; i < G_N_ELEMENTS( cases ); i++ ) {
-            sp_object_set(SP_OBJECT(prof), SP_ATTR_LOCAL, cases[i]);
+            SP_OBJECT(prof)->setKeyValue( SP_ATTR_LOCAL, cases[i]);
             TS_ASSERT( prof->local );
             if ( prof->local ) {
                 TS_ASSERT_EQUALS( std::string(prof->local), std::string(cases[i]) );
             }
         }
-        sp_object_set(SP_OBJECT(prof), SP_ATTR_LOCAL, NULL);
+        SP_OBJECT(prof)->setKeyValue( SP_ATTR_LOCAL, NULL);
         TS_ASSERT_EQUALS( prof->local, (gchar*)0 );
 
         g_object_unref(prof);
@@ -129,24 +118,26 @@ public:
             "something",
         };
 
-        ColorProfile *prof = static_cast<ColorProfile *>(g_object_new(COLORPROFILE_TYPE, NULL));
+        Inkscape::ColorProfile *prof = static_cast<Inkscape::ColorProfile *>(g_object_new(COLORPROFILE_TYPE, NULL));
         TS_ASSERT( prof );
         SP_OBJECT(prof)->document = _doc;
 
         for ( size_t i = 0; i < G_N_ELEMENTS( cases ); i++ ) {
-            sp_object_set(SP_OBJECT(prof), SP_ATTR_NAME, cases[i]);
+            SP_OBJECT(prof)->setKeyValue( SP_ATTR_NAME, cases[i]);
             TS_ASSERT( prof->name );
             if ( prof->name ) {
                 TS_ASSERT_EQUALS( std::string(prof->name), std::string(cases[i]) );
             }
         }
-        sp_object_set(SP_OBJECT(prof), SP_ATTR_NAME, NULL);
+        SP_OBJECT(prof)->setKeyValue( SP_ATTR_NAME, NULL);
         TS_ASSERT_EQUALS( prof->name, (gchar*)0 );
 
         g_object_unref(prof);
     }
 };
 
+#endif // SEEN_COLOR_PROFILE_TEST_H
+
 /*
   Local Variables:
   mode:c++
@@ -156,4 +147,4 @@ public:
   fill-column:99
   End:
 */
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :