Back to index

unity  6.0.0
test_resultviewgrid.cpp
Go to the documentation of this file.
00001 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
00002 /*
00003  * Copyright 2012 Canonical Ltd.
00004  *
00005  * This program is free software: you can redistribute it and/or modify it
00006  * under the terms of the GNU Lesser General Public License version 3, as
00007  * published by the  Free Software Foundation.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranties of
00011  * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
00012  * PURPOSE.  See the applicable version of the GNU Lesser General Public
00013  * License for more details.
00014  *
00015  * You should have received a copy of both the GNU Lesser General Public
00016  * License version 3 along with this program.  If not, see
00017  * <http://www.gnu.org/licenses/>
00018  *
00019  * Authored by: Andrea Azzarone <azzaronea@gmail.com>
00020  *
00021  */
00022 
00023 #include <gtest/gtest.h>
00024 #include <gmock/gmock.h>
00025 using namespace testing;
00026 
00027 #include "ResultViewGrid.h"
00028 using namespace unity;
00029 
00030 namespace
00031 {
00032 
00033 class MockResultViewGrid : public dash::ResultViewGrid
00034 {
00035 public:
00036   MockResultViewGrid(NUX_FILE_LINE_DECL) : dash::ResultViewGrid(NUX_FILE_LINE_PARAM) {}
00037 
00038   MOCK_METHOD0(QueueDraw, void());
00039   MOCK_METHOD2(GetIndexAtPosition, uint(int x, int y));
00040 
00041   void FakeMouseMoveSignal(int x = 0, int y = 0, int dx = 0, int dy = 0, unsigned long mouse_button_state = 0, unsigned long special_keys_state = 0)
00042   {
00043     EmitMouseMoveSignal(x, y, dy, dy, mouse_button_state, special_keys_state);
00044   }
00045 };
00046 
00047 class TestResultViewGrid : public Test
00048 {
00049 public:
00050   virtual void SetUp()
00051   {
00052     view.Adopt(new MockResultViewGrid(NUX_TRACKER_LOCATION));
00053     renderer.Adopt(new dash::ResultRenderer(NUX_TRACKER_LOCATION));
00054 
00055     view->SetModelRenderer(renderer.GetPointer());
00056     nux::GetWindowCompositor().SetKeyFocusArea(view.GetPointer());
00057   }
00058 
00059   nux::ObjectPtr<MockResultViewGrid> view;
00060   nux::ObjectPtr<dash::ResultRenderer> renderer;
00061 };
00062 
00063 
00064 TEST_F(TestResultViewGrid, TestQueueDrawMouseMoveInsideUnfocusedIcon)
00065 {
00066   EXPECT_CALL(*view, QueueDraw())
00067     .Times(1);
00068 
00069   EXPECT_CALL(*view, GetIndexAtPosition(_, _))
00070     .WillOnce(Return(7));
00071 
00072   view->FakeMouseMoveSignal();
00073 }
00074 
00075 
00076 TEST_F(TestResultViewGrid, TestQueueDrawMouseMoveInsideFocusedIcon)
00077 {
00078   EXPECT_CALL(*view, GetIndexAtPosition(_, _))
00079     .WillRepeatedly(Return(7));
00080 
00081   view->FakeMouseMoveSignal();
00082 
00083   EXPECT_CALL(*view, QueueDraw())
00084     .Times(0);
00085 
00086   view->FakeMouseMoveSignal();
00087 }
00088 
00089 
00090 TEST_F(TestResultViewGrid, TestQueueDrawMouseMoveOutside)
00091 {
00092   EXPECT_CALL(*view, GetIndexAtPosition(_, _))
00093     .WillRepeatedly(Return(-1));
00094 
00095   view->FakeMouseMoveSignal();
00096 
00097   EXPECT_CALL(*view, QueueDraw())
00098     .Times(0);
00099 
00100   view->FakeMouseMoveSignal();
00101 }
00102 
00103 }