Back to index

nux  3.0.0
gtest-nux-scrollview.cpp
Go to the documentation of this file.
00001 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
00002 /*
00003  * Copyright 2012 Inalogic® Inc.
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, as
00007  * published by the  Free Software Foundation; either version 2.1 or 3.0
00008  * of the License.
00009  *
00010  * This program is distributed in the hope that it will be useful, but
00011  * WITHOUT ANY WARRANTY; without even the implied warranties of
00012  * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
00013  * PURPOSE.  See the applicable version of the GNU Lesser General Public
00014  * License for more details.
00015  *
00016  * You should have received a copy of both the GNU Lesser General Public
00017  * License along with this program. If not, see <http://www.gnu.org/licenses/>
00018  *
00019  * Authored by: Andrea Azzarone <azzaronea@gmail.com>
00020  *
00021  */
00022 
00023 #include <gmock/gmock.h>
00024 
00025 #include "Nux/Nux.h"
00026 #include "Nux/ScrollView.h"
00027 #include "Nux/VLayout.h"
00028 
00029 using namespace testing;
00030 
00031 namespace {
00032 
00033 class MockScrollView : public nux::ScrollView
00034 {
00035 public:
00036   MOCK_METHOD0(QueueDraw, void());
00037 
00038   void FakeMouseWheelSignal(int x, int y, int wheel_delta, unsigned long mouse_button_state, unsigned long special_keys_state)
00039   {
00040      EmitMouseWheelSignal(x, y, wheel_delta, mouse_button_state, special_keys_state);
00041   }
00042 };
00043 
00044 class TestScrollView : public ::testing::Test
00045 {
00046 public:
00047   virtual void SetUp()
00048   {
00049     nux::NuxInitialize(0);
00050     wnd_thread.reset(nux::CreateNuxWindow("ScrollView test", 300, 200, nux::WINDOWSTYLE_NORMAL, NULL, false, NULL, NULL));
00051 
00052     scrollview.Adopt(new MockScrollView());
00053     scrollview->SetLayout(new nux::VLayout());
00054   }
00055 
00056   std::unique_ptr<nux::WindowThread> wnd_thread;
00057   nux::ObjectPtr<MockScrollView> scrollview;
00058 };
00059 
00060 TEST_F(TestScrollView, TestQueueDrawScrollDownNoScrollbars)
00061 {
00062   EXPECT_CALL(*scrollview, QueueDraw())
00063     .Times(0);
00064 
00065   scrollview->FakeMouseWheelSignal(0, 0, -NUX_MOUSEWHEEL_DELTA, 0, 0);
00066 }
00067 
00068 
00069 TEST_F(TestScrollView, TestQueueDrawScrollUpNoScrollbars)
00070 {
00071   EXPECT_CALL(*scrollview, QueueDraw())
00072     .Times(0);
00073 
00074   scrollview->FakeMouseWheelSignal(0, 0, NUX_MOUSEWHEEL_DELTA, 0, 0);
00075 }
00076 
00077 
00078 TEST_F(TestScrollView, TestQueueDrawScrollDown)
00079 {
00080   scrollview->m_ViewContentHeight = 500;
00081   scrollview->m_ViewHeight = 400;
00082 
00083   EXPECT_CALL(*scrollview, QueueDraw())
00084     .Times(1);
00085 
00086   scrollview->FakeMouseWheelSignal(0, 0, -NUX_MOUSEWHEEL_DELTA, 0, 0);
00087 }
00088 
00089 
00090 TEST_F(TestScrollView, TestQueueDrawScrollUp)
00091 {
00092   scrollview->m_ViewContentHeight = 500;
00093   scrollview->m_ViewHeight = 400;
00094   scrollview->ScrollDown(1, 10);
00095 
00096   EXPECT_CALL(*scrollview, QueueDraw())
00097     .Times(1);
00098 
00099   scrollview->FakeMouseWheelSignal(0, 0, NUX_MOUSEWHEEL_DELTA, 0, 0);
00100 }
00101 
00102 
00103 TEST_F(TestScrollView, TestQueueDrawScrollDownEnd)
00104 {
00105   scrollview->m_ViewContentHeight = 500;
00106   scrollview->m_ViewHeight = 400;
00107   scrollview->ScrollDown(1, 100);
00108 
00109   EXPECT_CALL(*scrollview, QueueDraw())
00110     .Times(0);
00111 
00112   scrollview->FakeMouseWheelSignal(0, 0, -NUX_MOUSEWHEEL_DELTA, 0, 0);
00113 }
00114 
00115 
00116 TEST_F(TestScrollView, TestQueueDrawScrollUpStart)
00117 {
00118   scrollview->m_ViewContentHeight = 500;
00119   scrollview->m_ViewHeight = 400;
00120 
00121   EXPECT_CALL(*scrollview, QueueDraw())
00122     .Times(0);
00123 
00124   scrollview->FakeMouseWheelSignal(0, 0, NUX_MOUSEWHEEL_DELTA, 0, 0);
00125 }
00126 
00127 }