phoneuis/bubblemanager2/tsrc/unit/ut_bubblecontainerwidget/ut_bubblecontainerwidget.cpp
branchGCC_SURGE
changeset 51 f39ed5e045e0
parent 30 ebdbd102c78a
parent 46 bc5a64e5bc3c
equal deleted inserted replaced
40:bab96b7ed1a4 51:f39ed5e045e0
    22 #include <hbmainwindow.h>
    22 #include <hbmainwindow.h>
    23 #include <hbaction.h>
    23 #include <hbaction.h>
    24 #include <hbmainwindow.h>
    24 #include <hbmainwindow.h>
    25 #include <hbinstance.h>
    25 #include <hbinstance.h>
    26 #include <hbstyle.h>
    26 #include <hbstyle.h>
       
    27 #include <hbframeitem.h>
    27 
    28 
    28 #include "bubbletest.h"
    29 #include "bubbletest.h"
    29 #include "bubblecontainerwidget.h"
    30 #include "bubblecontainerwidget.h"
       
    31 
       
    32 class TestBubbleContainerWidget : public BubbleContainerWidget
       
    33 {
       
    34 public:
       
    35     TestBubbleContainerWidget() {};
       
    36     ~TestBubbleContainerWidget() {};
       
    37 
       
    38     void testMouseMove(QGraphicsSceneMouseEvent *event)
       
    39          { BubbleContainerWidget::mouseMoveEvent(event); };
       
    40 };
    30 
    41 
    31 class ut_BubbleContainerWidget : public QObject
    42 class ut_BubbleContainerWidget : public QObject
    32 {
    43 {
    33     Q_OBJECT
    44     Q_OBJECT
    34 
    45 
    39     void testLeftMouseClick();
    50     void testLeftMouseClick();
    40     void testRightMouseClick();
    51     void testRightMouseClick();
    41     void testMouseMove();
    52     void testMouseMove();
    42 
    53 
    43 private:
    54 private:
    44     BubbleContainerWidget* mContainer;
    55     TestBubbleContainerWidget* mContainer;
    45     HbMainWindow* mMainWindow;
    56     HbMainWindow* mMainWindow;
    46     int mStyleBaseId;
       
    47 };
    57 };
    48 
    58 
    49 void ut_BubbleContainerWidget::initTestCase()
    59 void ut_BubbleContainerWidget::initTestCase()
    50 {
    60 {
    51     mMainWindow = new HbMainWindow();
    61     mMainWindow = new HbMainWindow();
    52     mContainer = new BubbleContainerWidget();
    62     mContainer = new TestBubbleContainerWidget();
    53     mMainWindow->addView(mContainer);
    63     mMainWindow->addView(mContainer);
    54     mMainWindow->show();
    64     mMainWindow->show();
       
    65 
       
    66     HbFrameItem* frame =
       
    67         qgraphicsitem_cast<HbFrameItem*>(
       
    68             static_cast<HbWidget*>(mContainer)->primitive("background"));
       
    69     QVERIFY(frame->frameDrawer().frameGraphicsName()=="qtg_fr_list_normal");
       
    70     QVERIFY(frame->isVisible()==false);
    55 }
    71 }
    56 
    72 
    57 void ut_BubbleContainerWidget::cleanupTestCase()
    73 void ut_BubbleContainerWidget::cleanupTestCase()
    58 {
    74 {
    59     delete mMainWindow;
    75     delete mMainWindow;
    88     QSignalSpy spy(mContainer,SIGNAL(clicked()));
   104     QSignalSpy spy(mContainer,SIGNAL(clicked()));
    89 
   105 
    90     QPointF clickPos = mContainer->scenePos() +
   106     QPointF clickPos = mContainer->scenePos() +
    91                        mContainer->rect().center();
   107                        mContainer->rect().center();
    92     QPoint windowPos = mMainWindow->mapFromScene( clickPos );
   108     QPoint windowPos = mMainWindow->mapFromScene( clickPos );
    93     QPoint windowPos2 = windowPos+QPoint(10,10);
   109 
       
   110     // move within
       
   111     QTest::mousePress( mMainWindow->viewport(), Qt::LeftButton, 0, windowPos, 100 );
    94 
   112 
    95     // QTest::mouseMove() doesn't work
   113     // QTest::mouseMove() doesn't work
    96     QTest::mouseMove( mMainWindow->viewport(), windowPos2 );
   114     QGraphicsSceneMouseEvent moveEvent(QEvent::MouseMove);
    97     QCOMPARE( spy.count(), 0 );
   115     moveEvent.setButtons(Qt::LeftButton);
       
   116     moveEvent.setPos(windowPos-QPointF(1,1));
       
   117     mContainer->testMouseMove(&moveEvent);
       
   118 
       
   119     QTest::mouseRelease( mMainWindow->viewport(), Qt::LeftButton, 0, windowPos, 100 );
       
   120     QCOMPARE( spy.count(), 1 );
       
   121 
       
   122 
       
   123     // move out
       
   124     QTest::mousePress( mMainWindow->viewport(), Qt::LeftButton, 0, windowPos, 100 );
       
   125     moveEvent.setPos(QPointF(-10,-10));
       
   126     mContainer->testMouseMove(&moveEvent);
       
   127 
       
   128     QTest::mouseRelease( mMainWindow->viewport(), Qt::LeftButton, 0, windowPos, 100 );
       
   129     QCOMPARE( spy.count(), 1 );
       
   130 
       
   131     // move in
       
   132     QTest::mousePress( mMainWindow->viewport(), Qt::LeftButton, 0, QPoint(1,1), 100 );
       
   133     moveEvent.setPos(QPointF(windowPos));
       
   134     mContainer->testMouseMove(&moveEvent);
       
   135 
       
   136     QTest::mouseRelease( mMainWindow->viewport(), Qt::LeftButton, 0, windowPos, 100 );
       
   137     QCOMPARE( spy.count(), 1 );
       
   138 
    98 }
   139 }
    99 
   140 
   100 BUBBLE_TEST_MAIN(ut_BubbleContainerWidget)
   141 BUBBLE_TEST_MAIN(ut_BubbleContainerWidget)
   101 #include "ut_bubblecontainerwidget.moc"
   142 #include "ut_bubblecontainerwidget.moc"