[gtksourceviewmm/devel] Fix mime_types test.



commit da0f2f970ddf26ff937fdf8906587feb44982ee5
Author: Krzesimir Nowak <qdlacz gmail com>
Date:   Mon Jan 11 12:50:31 2010 +0100

    Fix mime_types test.
    
    * gtksourceview/src/sourcelanguagemanager.ccg:
    * gtksourceview/src/sourcelanguagemanager.hg: guess_language()
    method now interprets empty strings as NULL. Also added method
    resetting search paths.
    * tests/Makefile.am: Included mime_types test into build system.
    * tests/mime_types/main.cc: Use guess_language for finding
    languages for specific mime types.

 gtksourceview/src/sourcelanguagemanager.ccg |   23 +++++++++++++++++++++++
 gtksourceview/src/sourcelanguagemanager.hg  |   12 ++++++++++--
 tests/Makefile.am                           |    5 +++--
 tests/mime_types/main.cc                    |    5 ++---
 4 files changed, 38 insertions(+), 7 deletions(-)
---
diff --git a/gtksourceview/src/sourcelanguagemanager.ccg b/gtksourceview/src/sourcelanguagemanager.ccg
index 0767642..abb4f0f 100644
--- a/gtksourceview/src/sourcelanguagemanager.ccg
+++ b/gtksourceview/src/sourcelanguagemanager.ccg
@@ -25,5 +25,28 @@
 namespace gtksourceview
 {
 
+void
+SourceLanguageManager::reset_search_path()
+{
+  gtk_source_language_manager_set_search_path(gobj(), NULL);
+}
+
+Glib::RefPtr<SourceLanguage>
+SourceLanguageManager::guess_language(const Glib::ustring& filename, const Glib::ustring& content_type)
+{
+  Glib::RefPtr<SourceLanguage> retvalue = Glib::wrap(gtk_source_language_manager_guess_language(gobj(), (filename.empty() ? 0 : filename.c_str()), (content_type.empty() ? 0 : content_type.c_str())));
+  if (retvalue)
+  {
+    retvalue->reference(); //The function does not do a ref for us.
+  }
+  return retvalue;
+}
+
+Glib::RefPtr<const SourceLanguage>
+SourceLanguageManager::guess_language(const Glib::ustring& filename, const Glib::ustring& content_type) const
+{
+  return const_cast<SourceLanguageManager*>(this)->guess_language(filename, content_type);
+}
+
 }//end namespace gtksourceview
 
diff --git a/gtksourceview/src/sourcelanguagemanager.hg b/gtksourceview/src/sourcelanguagemanager.hg
index 459e6b0..8b43a98 100644
--- a/gtksourceview/src/sourcelanguagemanager.hg
+++ b/gtksourceview/src/sourcelanguagemanager.hg
@@ -54,12 +54,20 @@ public:
   _WRAP_METHOD(Glib::StringArrayHandle get_search_path() const, gtk_source_language_manager_get_search_path)
   _WRAP_METHOD(void set_search_path(const Glib::StringArrayHandle& dirs), gtk_source_language_manager_set_search_path)
 
+  void reset_search_path();
+
   _WRAP_METHOD(Glib::StringArrayHandle get_language_ids() const, gtk_source_language_manager_get_language_ids)
 
   _WRAP_METHOD(Glib::RefPtr<SourceLanguage> get_language(const Glib::ustring& id), gtk_source_language_manager_get_language, refreturn)
   _WRAP_METHOD(Glib::RefPtr<const SourceLanguage> get_language(const Glib::ustring& id) const, gtk_source_language_manager_get_language, constversion, refreturn)
-  _WRAP_METHOD(Glib::RefPtr<SourceLanguage> guess_language(const Glib::ustring& filename, const Glib::ustring& content_type), gtk_source_language_manager_guess_language, filename, content_type, refreturn)
-  _WRAP_METHOD(Glib::RefPtr<const SourceLanguage> guess_language(const Glib::ustring& filename, const Glib::ustring& content_type) const, gtk_source_language_manager_guess_language, filename, content_type, constversion, refreturn)
+// XXX: wrapped by hand, because empty string means NULL.
+//  _WRAP_METHOD(Glib::RefPtr<SourceLanguage> guess_language(const Glib::ustring& filename, const Glib::ustring& content_type), gtk_source_language_manager_guess_language, filename, content_type, refreturn)
+//  _WRAP_METHOD(Glib::RefPtr<const SourceLanguage> guess_language(const Glib::ustring& filename, const Glib::ustring& content_type) const, gtk_source_language_manager_guess_language, filename, content_type, constversion, refreturn)
+  _WRAP_METHOD_DOCS_ONLY(gtk_source_language_manager_guess_language)
+// TODO: change filename parameter to std::string, when we break API/ABI.
+  Glib::RefPtr<SourceLanguage> guess_language(const Glib::ustring& filename, const Glib::ustring& content_type);
+  _WRAP_METHOD_DOCS_ONLY(gtk_source_language_manager_guess_language)
+  Glib::RefPtr<const SourceLanguage> guess_language(const Glib::ustring& filename, const Glib::ustring& content_type) const;
 };
 
 } /* namespace gtksourceview */
diff --git a/tests/Makefile.am b/tests/Makefile.am
index fae9458..e5cbc40 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -4,7 +4,8 @@ check_PROGRAMS =	\
 	basic/test	\
 	langs/test	\
 	search/test	\
-	get_buffer/test
+	get_buffer/test	\
+	mime_types/test
 
 basic_test_SOURCES      = basic/main.cc
 langs_test_SOURCES      = langs/main.cc
@@ -13,7 +14,7 @@ get_buffer_test_SOURCES = get_buffer/main.cc
 
 # commented for now, since it does not compile successfully.
 # when fixed, do not forget to add mime_types/test to check_PROGRAMS!
-#mime_types_test_SOURCES = mime_types/main.cc
+mime_types_test_SOURCES = mime_types/main.cc
 
 gtksourceviewmm_includes = -I$(top_builddir)/gtksourceview $(if $(srcdir:.=),-I$(top_srcdir)/gtksourceview)
 gtksourceviewmm_ldadd    = $(top_builddir)/gtksourceview/gtksourceviewmm/libgtksourceviewmm-$(GTKSOURCEVIEWMM_API_VERSION).la
diff --git a/tests/mime_types/main.cc b/tests/mime_types/main.cc
index 6a4fd32..1ce622e 100644
--- a/tests/mime_types/main.cc
+++ b/tests/mime_types/main.cc
@@ -2,6 +2,7 @@
 #include <gtkmm.h>
 #include <gtksourceviewmm/sourcelanguagemanager.h>
 #include <gtksourceviewmm/init.h>
+#include <gtksourceview/gtksourcelanguagemanager.h>
 
 using namespace std ;
 using namespace gtksourceview ;
@@ -33,9 +34,7 @@ main (int argc, char **argv)
         cout << "Looking for language that matches mime type '"
              << s_mime_types[i]
              << "'" << std::endl;
-
-        //TODO: This function was removed in gtksourceview 2: http://live.gnome.org/GtkSourceView/PortingGuide        
-        lang = lang_mgr->get_language_from_mime_type (s_mime_types[i]) ;
+        lang = lang_mgr->guess_language(std::string(), s_mime_types[i]);
         if (lang) {
             cout << "Found language '" << lang->get_name () << "'" << std::endl;
         } else {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]