class ComponentAttachDetachListenerTest(TestCase):

    def resetVariables(self):
        # Attach
        self._attachCounter = 0
        self._attachedComponent = None
        self._attachTarget = None
        self._foundInContainer = False

        # Detach
        self._detachCounter = 0
        self._detachedComponent = None
        self._detachedTarget = None

        # Common
        self._indexOfComponent = -1
        self._componentArea = None
        self._componentPosition = None


    def setUp(self):
        super(ComponentAttachDetachListenerTest, self).setUp()

        # General variables
        self._attachCounter = 0
        self._attachedComponent = None
        self._attachTarget = None
        self._foundInContainer = False
        self._detachCounter = 0
        self._detachedComponent = None
        self._detachedTarget = None

        # Ordered layout specific variables
        self._indexOfComponent = -1

        # Grid layout specific variables
        self._componentArea = None

        # Absolute layout specific variables
        self._componentPosition = None

        self._olayout = HorizontalLayout()
        self._olayout.addListener(MyAttachListener(self),
                IComponentAttachListener)
        self._olayout.addListener(MyDetachListener(self),
                IComponentDetachListener)

        self._gridlayout = GridLayout()
        self._gridlayout.addListener(MyAttachListener(self),
                IComponentAttachListener)
        self._gridlayout.addListener(MyDetachListener(self),
                IComponentDetachListener)

        self._absolutelayout = AbsoluteLayout()
        self._absolutelayout.addListener(MyAttachListener(self),
                IComponentAttachListener)
        self._absolutelayout.addListener(MyDetachListener(self),
                IComponentDetachListener)

        self._csslayout = CssLayout()
        self._csslayout.addListener(MyAttachListener(self),
                IComponentAttachListener)
        self._csslayout.addListener(MyDetachListener(self),
                IComponentDetachListener)


    def testOrderedLayoutAttachListener(self):
        # Reset state variables
        self.resetVariables()

        # Add component -> Should trigger attach listener
        comp = Label()
        self._olayout.addComponent(comp)

        # Attach counter should get incremented
        self.assertEquals(1, self._attachCounter)

        # The attached component should be the label
        self.assertEquals(comp, self._attachedComponent)

        # The attached target should be the layout
        self.assertEquals(self._olayout, self._attachTarget)

        # The attached component should be found in the container
        self.assertTrue(self._foundInContainer)

        # The index of the component should not be -1
        self.assertFalse(self._indexOfComponent == -1)


    def testOrderedLayoutDetachListener(self):
        # Add a component to detach
        comp = Label()
        self._olayout.addComponent(comp)

        # Reset state variables (since they are set by the attach listener)
        self.resetVariables()

        # Detach the component -> triggers the detach listener
        self._olayout.removeComponent(comp)

        # Detach counter should get incremented
        self.assertEquals(1, self._detachCounter)

        # The detached component should be the label
        self.assertEquals(comp, self._detachedComponent)

        # The detached target should be the layout
        self.assertEquals(self._olayout, self._detachedTarget)

        # The detached component should not be found in the container
        self.assertFalse(self._foundInContainer)

        # The index of the component should be -1
        self.assertEquals(-1, self._indexOfComponent)


    def testGridLayoutAttachListener(self):
        # Reset state variables
        self.resetVariables()

        # Add component -> Should trigger attach listener
        comp = Label()
        self._gridlayout.addComponent(comp)

        # Attach counter should get incremented
        self.assertEquals(1, self._attachCounter)

        # The attached component should be the label
        self.assertEquals(comp, self._attachedComponent)

        # The attached target should be the layout
        self.assertEquals(self._gridlayout, self._attachTarget)

        # The attached component should be found in the container
        self.assertTrue(self._foundInContainer)

        # The grid area should not be null
        self.assertIsNotNone(self._componentArea)


    def testGridLayoutDetachListener(self):
        # Add a component to detach
        comp = Label()
        self._gridlayout.addComponent(comp)

        # Reset state variables (since they are set by the attach listener)
        self.resetVariables()

        # Detach the component -> triggers the detach listener
        self._gridlayout.removeComponent(comp)

        # Detach counter should get incremented
        self.assertEquals(1, self._detachCounter)

        # The detached component should be the label
        self.assertEquals(comp, self._detachedComponent)

        # The detached target should be the layout
        self.assertEquals(self._gridlayout, self._detachedTarget)

        # The detached component should not be found in the container
        self.assertFalse(self._foundInContainer)

        # The grid area should be null
        self.assertIsNone(self._componentArea)


    def testAbsoluteLayoutAttachListener(self):
        # Reset state variables
        self.resetVariables()

        # Add component -> Should trigger attach listener
        comp = Label()
        self._absolutelayout.addComponent(comp)

        # Attach counter should get incremented
        self.assertEquals(1, self._attachCounter)

        # The attached component should be the label
        self.assertEquals(comp, self._attachedComponent)

        # The attached target should be the layout
        self.assertEquals(self._absolutelayout, self._attachTarget)

        # The attached component should be found in the container
        self.assertTrue(self._foundInContainer)

        # The component position should not be null
        self.assertIsNotNone(self._componentPosition)


    def testAbsoluteLayoutDetachListener(self):
        # Add a component to detach
        comp = Label()
        self._absolutelayout.addComponent(comp)

        # Reset state variables (since they are set by the attach listener)
        self.resetVariables()

        # Detach the component -> triggers the detach listener
        self._absolutelayout.removeComponent(comp)

        # Detach counter should get incremented
        self.assertEquals(1, self._detachCounter)

        # The detached component should be the label
        self.assertEquals(comp, self._detachedComponent)

        # The detached target should be the layout
        self.assertEquals(self._absolutelayout, self._detachedTarget)

        # The detached component should not be found in the container
        self.assertFalse(self._foundInContainer)

        # The component position should be null
        self.assertIsNone(self._componentPosition)


    def testCSSLayoutAttachListener(self):
        # Reset state variables
        self.resetVariables()

        # Add component -> Should trigger attach listener
        comp = Label()
        self._csslayout.addComponent(comp)

        # Attach counter should get incremented
        self.assertEquals(1, self._attachCounter)

        # The attached component should be the label
        self.assertEquals(comp, self._attachedComponent)

        # The attached target should be the layout
        self.assertEquals(self._csslayout, self._attachTarget)

        # The attached component should be found in the container
        self.assertTrue(self._foundInContainer)


    def testCSSLayoutDetachListener(self):
        # Add a component to detach
        comp = Label()
        self._csslayout.addComponent(comp)

        # Reset state variables (since they are set by the attach listener)
        self.resetVariables()

        # Detach the component -> triggers the detach listener
        self._csslayout.removeComponent(comp)

        # Detach counter should get incremented
        self.assertEquals(1, self._detachCounter)

        # The detached component should be the label
        self.assertEquals(comp, self._detachedComponent)

        # The detached target should be the layout
        self.assertEquals(self._csslayout, self._detachedTarget)

        # The detached component should not be found in the container
        self.assertFalse(self._foundInContainer)
예제 #2
0
class ComponentAttachDetachListenerTest(TestCase):
    def resetVariables(self):
        # Attach
        self._attachCounter = 0
        self._attachedComponent = None
        self._attachTarget = None
        self._foundInContainer = False

        # Detach
        self._detachCounter = 0
        self._detachedComponent = None
        self._detachedTarget = None

        # Common
        self._indexOfComponent = -1
        self._componentArea = None
        self._componentPosition = None

    def setUp(self):
        super(ComponentAttachDetachListenerTest, self).setUp()

        # General variables
        self._attachCounter = 0
        self._attachedComponent = None
        self._attachTarget = None
        self._foundInContainer = False
        self._detachCounter = 0
        self._detachedComponent = None
        self._detachedTarget = None

        # Ordered layout specific variables
        self._indexOfComponent = -1

        # Grid layout specific variables
        self._componentArea = None

        # Absolute layout specific variables
        self._componentPosition = None

        self._olayout = HorizontalLayout()
        listener = MyAttachListener(self)
        self._olayout.addListener(listener, IComponentAttachListener)
        listener = MyDetachListener(self)
        self._olayout.addListener(listener, IComponentDetachListener)

        self._gridlayout = GridLayout()
        listener = MyAttachListener(self)
        self._gridlayout.addListener(listener, IComponentAttachListener)
        listener = MyDetachListener(self)
        self._gridlayout.addListener(listener, IComponentDetachListener)

        self._absolutelayout = AbsoluteLayout()
        listener = MyAttachListener(self)
        self._absolutelayout.addListener(listener, IComponentAttachListener)
        listener = MyDetachListener(self)
        self._absolutelayout.addListener(listener, IComponentDetachListener)

        self._csslayout = CssLayout()
        listener = MyAttachListener(self)
        self._csslayout.addListener(listener, IComponentAttachListener)
        listener = MyDetachListener(self)
        self._csslayout.addListener(listener, IComponentDetachListener)

    def testOrderedLayoutAttachListener(self):
        # Reset state variables
        self.resetVariables()

        # Add component -> Should trigger attach listener
        comp = Label()
        self._olayout.addComponent(comp)

        # Attach counter should get incremented
        self.assertEquals(1, self._attachCounter)

        # The attached component should be the label
        self.assertEquals(comp, self._attachedComponent)

        # The attached target should be the layout
        self.assertEquals(self._olayout, self._attachTarget)

        # The attached component should be found in the container
        self.assertTrue(self._foundInContainer)

        # The index of the component should not be -1
        self.assertFalse(self._indexOfComponent == -1)

    def testOrderedLayoutDetachListener(self):
        # Add a component to detach
        comp = Label()
        self._olayout.addComponent(comp)

        # Reset state variables (since they are set by the attach listener)
        self.resetVariables()

        # Detach the component -> triggers the detach listener
        self._olayout.removeComponent(comp)

        # Detach counter should get incremented
        self.assertEquals(1, self._detachCounter)

        # The detached component should be the label
        self.assertEquals(comp, self._detachedComponent)

        # The detached target should be the layout
        self.assertEquals(self._olayout, self._detachedTarget)

        # The detached component should not be found in the container
        self.assertFalse(self._foundInContainer)

        # The index of the component should be -1
        self.assertEquals(-1, self._indexOfComponent)

    def testGridLayoutAttachListener(self):
        # Reset state variables
        self.resetVariables()

        # Add component -> Should trigger attach listener
        comp = Label()
        self._gridlayout.addComponent(comp)

        # Attach counter should get incremented
        self.assertEquals(1, self._attachCounter)

        # The attached component should be the label
        self.assertEquals(comp, self._attachedComponent)

        # The attached target should be the layout
        self.assertEquals(self._gridlayout, self._attachTarget)

        # The attached component should be found in the container
        self.assertTrue(self._foundInContainer)

        # The grid area should not be null
        self.assertIsNotNone(self._componentArea)

    def testGridLayoutDetachListener(self):
        # Add a component to detach
        comp = Label()
        self._gridlayout.addComponent(comp)

        # Reset state variables (since they are set by the attach listener)
        self.resetVariables()

        # Detach the component -> triggers the detach listener
        self._gridlayout.removeComponent(comp)

        # Detach counter should get incremented
        self.assertEquals(1, self._detachCounter)

        # The detached component should be the label
        self.assertEquals(comp, self._detachedComponent)

        # The detached target should be the layout
        self.assertEquals(self._gridlayout, self._detachedTarget)

        # The detached component should not be found in the container
        self.assertFalse(self._foundInContainer)

        # The grid area should be null
        self.assertIsNone(self._componentArea)

    def testAbsoluteLayoutAttachListener(self):
        # Reset state variables
        self.resetVariables()

        # Add component -> Should trigger attach listener
        comp = Label()
        self._absolutelayout.addComponent(comp)

        # Attach counter should get incremented
        self.assertEquals(1, self._attachCounter)

        # The attached component should be the label
        self.assertEquals(comp, self._attachedComponent)

        # The attached target should be the layout
        self.assertEquals(self._absolutelayout, self._attachTarget)

        # The attached component should be found in the container
        self.assertTrue(self._foundInContainer)

        # The component position should not be null
        self.assertIsNotNone(self._componentPosition)

    def testAbsoluteLayoutDetachListener(self):
        # Add a component to detach
        comp = Label()
        self._absolutelayout.addComponent(comp)

        # Reset state variables (since they are set by the attach listener)
        self.resetVariables()

        # Detach the component -> triggers the detach listener
        self._absolutelayout.removeComponent(comp)

        # Detach counter should get incremented
        self.assertEquals(1, self._detachCounter)

        # The detached component should be the label
        self.assertEquals(comp, self._detachedComponent)

        # The detached target should be the layout
        self.assertEquals(self._absolutelayout, self._detachedTarget)

        # The detached component should not be found in the container
        self.assertFalse(self._foundInContainer)

        # The component position should be null
        self.assertIsNone(self._componentPosition)

    def testCSSLayoutAttachListener(self):
        # Reset state variables
        self.resetVariables()

        # Add component -> Should trigger attach listener
        comp = Label()
        self._csslayout.addComponent(comp)

        # Attach counter should get incremented
        self.assertEquals(1, self._attachCounter)

        # The attached component should be the label
        self.assertEquals(comp, self._attachedComponent)

        # The attached target should be the layout
        self.assertEquals(self._csslayout, self._attachTarget)

        # The attached component should be found in the container
        self.assertTrue(self._foundInContainer)

    def testCSSLayoutDetachListener(self):
        # Add a component to detach
        comp = Label()
        self._csslayout.addComponent(comp)

        # Reset state variables (since they are set by the attach listener)
        self.resetVariables()

        # Detach the component -> triggers the detach listener
        self._csslayout.removeComponent(comp)

        # Detach counter should get incremented
        self.assertEquals(1, self._detachCounter)

        # The detached component should be the label
        self.assertEquals(comp, self._detachedComponent)

        # The detached target should be the layout
        self.assertEquals(self._csslayout, self._detachedTarget)

        # The detached component should not be found in the container
        self.assertFalse(self._foundInContainer)