Back to index

nux  3.0.0
gtest-nux-area.cpp
Go to the documentation of this file.
00001 #include <string>
00002 #include <fstream>
00003 
00004 #include <iostream>
00005 #include <gmock/gmock.h>
00006 #include <boost/filesystem.hpp>
00007 #include <glib.h>
00008 
00009 #include "Nux/Nux.h"
00010 #include "Nux/HLayout.h"
00011 #include "Nux/StaticText.h"
00012 #include "Nux/ProgramFramework/TestView.h"
00013 
00014 
00015 using namespace testing;
00016 
00017 namespace {
00018 
00019 TEST(TestArea, TestAreaSize)
00020 {
00021   nux::NuxInitialize(0);
00022   nux::WindowThread *wnd_thread = nux::CreateNuxWindow("Area Test", 300, 200,
00023     nux::WINDOWSTYLE_NORMAL, NULL, false, NULL, NULL);
00024 
00025   nux::TestView* test_view = new nux::TestView("");
00026 
00027   EXPECT_EQ(test_view->GetMinimumWidth(), nux::AREA_MIN_WIDTH);
00028   EXPECT_EQ(test_view->GetMaximumWidth(), nux::AREA_MAX_WIDTH);
00029   EXPECT_EQ(test_view->GetMinimumHeight(), nux::AREA_MIN_HEIGHT);
00030   EXPECT_EQ(test_view->GetMaximumHeight(), nux::AREA_MAX_HEIGHT);
00031 
00032   test_view->SetMinimumWidth(100);
00033   EXPECT_EQ(test_view->GetMinimumWidth(), 100);
00034 
00035   test_view->SetMaximumWidth(1111);
00036   EXPECT_EQ(test_view->GetMaximumWidth(), 1111);
00037 
00038   test_view->SetMinimumHeight(123);
00039   EXPECT_EQ(test_view->GetMinimumHeight(), 123);
00040 
00041   test_view->SetMaximumHeight(1234);
00042   EXPECT_EQ(test_view->GetMaximumHeight(), 1234);
00043 
00044   test_view->SetMaximumSize(4321, 1234);
00045   test_view->SetMinimumSize(123, 432);
00046 
00047   EXPECT_EQ(test_view->GetMinimumWidth(), 123);
00048   EXPECT_EQ(test_view->GetMaximumWidth(), 4321);
00049   EXPECT_EQ(test_view->GetMinimumHeight(), 432);
00050   EXPECT_EQ(test_view->GetMaximumHeight(), 1234);
00051 
00052   test_view->UnReference();
00053   delete wnd_thread;
00054 }
00055 
00056 TEST(TestArea, TestAreaGeometry)
00057 {
00058   nux::NuxInitialize(0);
00059   nux::WindowThread *wnd_thread = nux::CreateNuxWindow("Area Test", 300, 200,
00060     nux::WINDOWSTYLE_NORMAL, NULL, false, NULL, NULL);
00061 
00062   nux::TestView* test_view = new nux::TestView("");
00063 
00064   static_cast<nux::Area*>(test_view)->SetGeometry(0, 0, 100, 100);
00065 
00066   EXPECT_EQ(test_view->GetBaseX(), 0);
00067   EXPECT_EQ(test_view->GetBaseX(), 0);
00068   EXPECT_EQ(test_view->GetBaseWidth(), 100);
00069   EXPECT_EQ(test_view->GetBaseHeight(), 100);
00070 
00071 
00072   test_view->UnReference();
00073   delete wnd_thread;
00074 }
00075 
00076 static bool object_destroyed = false;
00077 void OnObjectDestroyed(nux::Object* object)
00078 {
00079   object_destroyed = true;
00080 }
00081 
00082 TEST(TestArea, TestUnParentKeyFocus)
00083 {
00084   nux::NuxInitialize(0);
00085   nux::WindowThread *wnd_thread = nux::CreateNuxWindow("Area Test", 300, 200,
00086     nux::WINDOWSTYLE_NORMAL, NULL, false, NULL, NULL);
00087 
00088   nux::HLayout* layout = new nux::HLayout();
00089   nux::TestView* test_view = new nux::TestView("");
00090   test_view->object_destroyed.connect(sigc::ptr_fun(&OnObjectDestroyed));
00091 
00092   test_view->Reference();
00093   
00094   layout->AddView(test_view, 1);
00095 
00096   wnd_thread->SetLayout(layout);
00097 
00098   EXPECT_EQ(test_view->HasKeyFocus(), false);
00099   nux::GetWindowThread()->GetWindowCompositor().SetKeyFocusArea(test_view);
00100   EXPECT_EQ(test_view->HasKeyFocus(), true);
00101   layout->RemoveChildObject(test_view);
00102   EXPECT_EQ(test_view->HasKeyFocus(), false);
00103   test_view->UnReference();
00104   EXPECT_EQ(object_destroyed, true);
00105 
00106   delete wnd_thread;
00107 }
00108 
00109 }