diff --git a/src/scripting/python/pythonengine.h b/src/scripting/python/pythonengine.h index a82984748..3dc2a7f97 100644 --- a/src/scripting/python/pythonengine.h +++ b/src/scripting/python/pythonengine.h @@ -20,6 +20,8 @@ #include "scripting/languageengine.h" +#include "gtest/gtest_prod.h" + struct _object; // PyObject struct _sipAPIDef; struct _sipTypeDef; @@ -27,6 +29,8 @@ struct _sipTypeDef; class PythonEngine : public LanguageEngine { Q_OBJECT + FRIEND_TEST(PythonTest, SharedPointers); + public: PythonEngine(ScriptManager* manager); ~PythonEngine(); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 6f749b295..fde0ca921 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -138,5 +138,6 @@ if(LINUX AND HAVE_DBUS) endif(LINUX AND HAVE_DBUS) if(HAVE_SCRIPTING_PYTHON) + include_directories(${PYTHON_INCLUDE_DIRS}) add_test_file(python_test.cpp true) endif (HAVE_SCRIPTING_PYTHON) diff --git a/tests/python_test.cpp b/tests/python_test.cpp index dcfd81006..d0e63d75a 100644 --- a/tests/python_test.cpp +++ b/tests/python_test.cpp @@ -15,7 +15,12 @@ along with Clementine. If not, see . */ +#include +#include + +#include "sipAPIclementine.h" #include "core/utilities.h" +#include "playlist/songplaylistitem.h" #include "scripting/script.h" #include "scripting/scriptmanager.h" #include "scripting/python/pythonengine.h" @@ -30,7 +35,6 @@ #include -namespace { class TemporaryScript : boost::noncopyable { public: @@ -147,4 +151,37 @@ TEST_F(PythonTest, ModuleConstants) { EXPECT_TRUE(log.at(n-1).contains("EnsureInitialised(); + + TemporaryScript script( + "import clementine\n" + "print clementine.item.Metadata().title()\n" + "a = clementine.item\n" + "print a.Metadata().title()\n" + "clementine.item = None\n" + "print a.Metadata().title()\n" + "a = None\n" + ); + ScriptInfo info; + info.InitFromDirectory(manager_, script.directory_); + + Song song; + song.set_title("title"); + + PlaylistItemPtr ptr(new SongPlaylistItem(song)); + EXPECT_EQ(1, ptr.use_count()); + + engine_->AddObject(&ptr, sipType_PlaylistItemPtr, "item"); + EXPECT_EQ(2, ptr.use_count()); + + engine_->CreateScript(info); + EXPECT_EQ(1, ptr.use_count()); + + const QStringList log = manager_->log_lines_plain(); + const int n = log.count(); + ASSERT_GE(n, 3); + EXPECT_TRUE(log.at(n-3).endsWith("title")); + EXPECT_TRUE(log.at(n-2).endsWith("title")); + EXPECT_TRUE(log.at(n-1).endsWith("title")); +}