nux-1.16.0
|
00001 /* 00002 * Copyright (C) 2011 Canonical Ltd 00003 * 00004 * This program is free software: you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License version 3 as 00006 * published by the Free Software Foundation. 00007 * 00008 * This program is distributed in the hope that it will be useful, 00009 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 * GNU General Public License for more details. 00012 * 00013 * You should have received a copy of the GNU General Public License 00014 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00015 * 00016 * Authored by: Mirco Müller <mirco.mueller@canonical.com 00017 */ 00018 00019 #include <gtest/gtest.h> 00020 #include <gmock/gmock.h> 00021 00022 #include "Nux/CairoWrapper.h" 00023 00024 #include <string> 00025 #include <fstream> 00026 00027 #include <iostream> 00028 00029 typedef void (*TestFunc)(void); 00030 00031 nux::TimerFunctor* g_timer = NULL; 00032 nux::TimerHandle g_handler = NULL; 00033 00034 void 00035 callback_one (nux::Geometry const& geom, cairo_t* cr) 00036 { 00037 if (cairo_status (cr) != CAIRO_STATUS_SUCCESS) 00038 return; 00039 00040 cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR); 00041 cairo_paint (cr); 00042 cairo_set_operator (cr, CAIRO_OPERATOR_OVER); 00043 cairo_scale (cr, 1.0, 1.0); 00044 cairo_set_source_rgba (cr, 1.0, 0.5, 0.25, 1.0); 00045 cairo_rectangle (cr, 00046 5.0, 00047 5.0, 00048 (double) geom.width - 10.0, 00049 (double) geom.height - 10.0); 00050 cairo_fill (cr); 00051 } 00052 00053 void 00054 callback_two (nux::Geometry const& geom, cairo_t* cr) 00055 { 00056 if (cairo_status (cr) != CAIRO_STATUS_SUCCESS) 00057 return; 00058 00059 cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR); 00060 cairo_paint (cr); 00061 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); 00062 cairo_scale (cr, 1.0, 1.0); 00063 cairo_set_source_rgba (cr, 0.25, 0.5, 1.0, 1.0); 00064 cairo_rectangle (cr, 00065 2.0, 00066 2.0, 00067 (double) geom.width - 4.0, 00068 (double) geom.height - 4.0); 00069 cairo_fill (cr); 00070 } 00071 00072 void 00073 terminate (void* data) 00074 { 00075 nux::WindowThread* thread = NUX_STATIC_CAST (nux::WindowThread*, data); 00076 thread->TerminateThread (); 00077 } 00078 00079 void 00080 init (nux::NThread* thread, void* data) 00081 { 00082 TestFunc func = (TestFunc) data; 00083 00084 (func) (); 00085 00086 g_timer = new nux::TimerFunctor (); 00087 g_timer->OnTimerExpired.connect (sigc::ptr_fun (&terminate)); 00088 g_handler = nux::GetTimer().AddTimerHandler (100, 00089 g_timer, 00090 nux::GetWindowThread ()); 00091 } 00092 00093 void 00094 run_test (TestFunc func) 00095 { 00096 nux::WindowThread* wt = NULL; 00097 00098 wt = nux::CreateGUIThread (TEXT ("Canvas Test"), 400, 400, 0, &init, (void*) func); 00099 wt->Run (NULL); 00100 delete wt; 00101 delete g_timer; 00102 g_timer = NULL; 00103 } 00104 00105 void 00106 test_construction () 00107 { 00108 nux::Geometry geom_one = {0, 0, 100, 100}; 00109 nux::Geometry geom_two = {0, 0, 200, 200}; 00110 nux::CairoWrapper wrapper (geom_one, sigc::ptr_fun (callback_one)); 00111 00112 EXPECT_FALSE (wrapper.Invalidate (geom_one)); 00113 EXPECT_TRUE (wrapper.Invalidate (geom_two)); 00114 } 00115 00116 void 00117 test_invalidate () 00118 { 00119 nux::Geometry geom_one = {0, 0, 100, 100}; 00120 nux::Geometry geom_two = {0, 0, 150, 75}; 00121 nux::CairoWrapper wrapper (geom_one, sigc::ptr_fun (callback_one)); 00122 00123 EXPECT_FALSE (wrapper.Invalidate (geom_one)); 00124 EXPECT_TRUE (wrapper.Invalidate (geom_two)); 00125 } 00126 00127 void 00128 test_get_cairo_surface () 00129 { 00130 nux::Geometry geom = {0, 0, 100, 100}; 00131 nux::CairoWrapper wrapper (geom, sigc::ptr_fun (callback_one)); 00132 00133 cairo_surface_t* surf = wrapper.GetCairoSurface (); 00134 EXPECT_FALSE (surf == NULL); 00135 } 00136 00137 void 00138 test_get_cairo_context () 00139 { 00140 nux::Geometry geom = {0, 0, 100, 100}; 00141 nux::CairoWrapper wrapper (geom, sigc::ptr_fun (callback_one)); 00142 00143 EXPECT_TRUE (wrapper.GetCairoContext ()); 00144 } 00145 00146 void 00147 test_dump_to_file () 00148 { 00149 nux::Geometry geom = {0, 0, 100, 100}; 00150 nux::CairoWrapper wrapper (geom, sigc::ptr_fun (callback_one)); 00151 00152 EXPECT_TRUE (wrapper.DumpToFile ("/tmp/dump.png")); 00153 } 00154 00155 void 00156 test_get_texture () 00157 { 00158 nux::Geometry geom = {0, 0, 100, 100}; 00159 nux::CairoWrapper wrapper (geom, sigc::ptr_fun (callback_one)); 00160 00161 EXPECT_TRUE (wrapper.GetTexture ()); 00162 } 00163 00164 void 00165 test_get_bitmap () 00166 { 00167 nux::Geometry geom = {0, 0, 100, 100}; 00168 nux::CairoWrapper wrapper (geom, sigc::ptr_fun (callback_one)); 00169 00170 EXPECT_TRUE (wrapper.GetBitmap ()); 00171 } 00172 00173 namespace { 00174 00175 TEST (DISABLED_TestCairoWrapper, TestConstruction) { 00176 run_test (test_construction); 00177 } 00178 00179 TEST (DISABLED_TestCairoWrapper, TestInvalidate) { 00180 run_test (test_invalidate); 00181 } 00182 00183 TEST (DISABLED_TestCairoWrapper, TestGetCairoSurface) { 00184 run_test (test_get_cairo_surface); 00185 } 00186 00187 TEST (DISABLED_TestCairoWrapper, TestGetCairoContext) { 00188 run_test (test_get_cairo_context); 00189 } 00190 00191 TEST (DISABLED_TestCairoWrapper, TestDumpToFile) { 00192 run_test (test_dump_to_file); 00193 } 00194 00195 TEST (DISABLED_TestCairoWrapper, TestGetTexture) { 00196 run_test (test_get_texture); 00197 } 00198 00199 TEST (DISABLED_TestCairoWrapper, TestGetBitmap) { 00200 run_test (test_get_bitmap); 00201 } 00202 }