gstreamer/tests/check/python/test_group.py
Thibault Saunier 2fae9ee50d group: Make deep copying actually copy deep
Allowing pasting groups paste exactly what had been copied

And not the new version of the contained objects

This technically breaks the C API but this is a new API and I believe
and hope nobody is using it right now.

Reviewed-by: Thibault Saunier <thibault.saunier@collabora.com>
Differential Revision: https://phabricator.freedesktop.org/D616
2016-01-17 09:23:35 +01:00

123 lines
3.8 KiB
Python

# -*- coding: utf-8 -*-
#
# Copyright (c) 2015, Thibault Saunier
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, write to the
# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301, USA.
import gi
gi.require_version("Gst", "1.0")
gi.require_version("GES", "1.0")
from gi.repository import Gst # noqa
from gi.repository import GES # noqa
import unittest # noqa
Gst.init(None)
GES.init()
class TestCopyPaste(unittest.TestCase):
def setUp(self):
self.timeline = GES.Timeline.new_audio_video()
self.assertEqual(len(self.timeline.get_tracks()), 2)
self.layer = self.timeline.append_layer()
def testCopyGroup(self):
clip1 = GES.TestClip.new()
clip1.props.duration = 10
self.layer.add_clip(clip1)
self.assertEqual(len(clip1.get_children(False)), 2)
group = GES.Group.new()
self.assertTrue(group.add(clip1))
self.assertEqual(len(group.get_children(False)), 1)
group_copy = group.copy(True)
self.assertEqual(len(group_copy.get_children(False)), 0)
self.assertTrue(group_copy.paste(10))
clips = self.layer.get_clips()
self.assertEqual(len(clips), 2)
self.assertEqual(clips[1].props.start, 10)
clips[1].edit([], 1, GES.EditMode.EDIT_NORMAL, GES.Edge.EDGE_NONE, 10)
clips = self.layer.get_clips()
self.assertEqual(len(clips), 1)
def testPasteChangedGroup(self):
clip1 = GES.TestClip.new()
clip1.props.duration = 10
clip2 = GES.TestClip.new()
clip2.props.start = 20
clip2.props.duration = 10
self.layer.add_clip(clip1)
self.layer.add_clip(clip2)
self.assertEqual(len(clip1.get_children(False)), 2)
group = GES.Group.new()
self.assertTrue(group.add(clip1))
self.assertEqual(len(group.get_children(False)), 1)
group_copy = group.copy(True)
self.assertEqual(len(group_copy.get_children(False)), 0)
self.assertTrue(group.add(clip2))
self.assertEqual(len(group.get_children(False)), 2)
self.assertEqual(len(group_copy.get_children(False)), 0)
self.assertTrue(group_copy.paste(10))
clips = self.layer.get_clips()
self.assertEqual(len(clips), 3)
self.assertEqual(clips[1].props.start, 10)
def testPasteChangedGroup(self):
clip1 = GES.TestClip.new()
clip1.props.duration = 10
clip2 = GES.TestClip.new()
clip2.props.start = 20
clip2.props.duration = 10
self.layer.add_clip(clip1)
self.layer.add_clip(clip2)
self.assertEqual(len(clip1.get_children(False)), 2)
group = GES.Group.new()
self.assertTrue(group.add(clip1))
self.assertEqual(len(group.get_children(False)), 1)
group_copy = group.copy(True)
self.assertEqual(len(group_copy.get_children(False)), 0)
self.assertTrue(group.add(clip2))
self.assertEqual(len(group.get_children(False)), 2)
self.assertEqual(len(group_copy.get_children(False)), 0)
self.assertTrue(group_copy.paste(10))
clips = self.layer.get_clips()
self.assertEqual(len(clips), 3)
self.assertEqual(clips[1].props.start, 10)