Add a test for shared pointers in python
This commit is contained in:
parent
63b6c65b8f
commit
d28e5ae09a
@ -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();
|
||||
|
@ -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)
|
||||
|
@ -15,7 +15,12 @@
|
||||
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <Python.h>
|
||||
#include <sip.h>
|
||||
|
||||
#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 <boost/noncopyable.hpp>
|
||||
|
||||
namespace {
|
||||
|
||||
class TemporaryScript : boost::noncopyable {
|
||||
public:
|
||||
@ -147,4 +151,37 @@ TEST_F(PythonTest, ModuleConstants) {
|
||||
EXPECT_TRUE(log.at(n-1).contains("<clementine.ScriptInterface object at")); // script
|
||||
}
|
||||
|
||||
} // namespace
|
||||
TEST_F(PythonTest, SharedPointers) {
|
||||
engine_->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"));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user