PageRenderTime 33ms CodeModel.GetById 1ms app.highlight 27ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/integration_tests/llui_libtest/llui_libtest.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 217 lines | 136 code | 32 blank | 49 comment | 3 complexity | 8ed0b272e509bf0eccbf6eedcca746a1 MD5 | raw file
  1/** 
  2 * @file llui_libtest.cpp
  3 * @brief Integration test for the LLUI library
  4 *
  5 * $LicenseInfo:firstyear=2009&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26#include "linden_common.h"
 27
 28#include "llui_libtest.h"
 29
 30// project includes
 31#include "llwidgetreg.h"
 32
 33// linden library includes
 34#include "llcontrol.h"		// LLControlGroup
 35#include "lldir.h"
 36#include "lldiriterator.h"
 37#include "llerrorcontrol.h"
 38#include "llfloater.h"
 39#include "llfontfreetype.h"
 40#include "llfontgl.h"
 41#include "lltransutil.h"
 42#include "llui.h"
 43#include "lluictrlfactory.h"
 44
 45#include <iostream>
 46
 47// *TODO: switch to using TUT
 48// *TODO: teach Parabuild about this program, run automatically after full builds
 49
 50// I believe these must be globals, not stack variables.  JC
 51LLControlGroup gSavedSettings("Global");	// saved at end of session
 52LLControlGroup gSavedPerAccountSettings("PerAccount"); // saved at end of session
 53LLControlGroup gWarningSettings("Warnings"); // persists ignored dialogs/warnings
 54
 55// We can't create LLImageGL objects because we have no window or rendering 
 56// context.  Provide enough of an LLUIImage to test the LLUI library without
 57// an underlying image.
 58class TestUIImage : public LLUIImage
 59{
 60public:
 61	TestUIImage()
 62	:	LLUIImage( std::string(), NULL ) // NULL ImageGL, don't deref!
 63	{ }
 64
 65	/*virtual*/ S32 getWidth() const
 66	{
 67		return 16;
 68	}
 69
 70	/*virtual*/ S32 getHeight() const
 71	{
 72		return 16;
 73	}
 74};
 75
 76
 77class LLTexture ;
 78// We need to supply dummy images
 79class TestImageProvider : public LLImageProviderInterface
 80{
 81public:
 82	/*virtual*/ LLPointer<LLUIImage> getUIImage(const std::string& name, S32 priority)
 83	{
 84		return makeImage();
 85	}
 86
 87	/*virtual*/ LLPointer<LLUIImage> getUIImageByID(const LLUUID& id, S32 priority)
 88	{
 89		return makeImage();
 90	}
 91
 92	/*virtual*/ void cleanUp()
 93	{
 94	}
 95
 96	LLPointer<LLUIImage> makeImage()
 97	{
 98		LLPointer<LLTexture> image_gl;
 99		LLPointer<LLUIImage> image = new TestUIImage(); //LLUIImage( std::string(), image_gl);
100		mImageList.push_back(image);
101		return image;
102	}
103	
104public:
105	// Unclear if we need this, hold on to one copy of each image we make
106	std::vector<LLPointer<LLUIImage> > mImageList;
107};
108TestImageProvider gTestImageProvider;
109
110static std::string get_xui_dir()
111{
112	std::string delim = gDirUtilp->getDirDelimiter();
113	return gDirUtilp->getSkinBaseDir() + delim + "default" + delim + "xui" + delim;
114}
115
116void init_llui()
117{
118	// Font lookup needs directory support
119#if LL_DARWIN
120	const char* newview_path = "../../../../newview";
121#else
122	const char* newview_path = "../../../newview";
123#endif
124	gDirUtilp->initAppDirs("SecondLife", newview_path);
125	gDirUtilp->setSkinFolder("default");
126	
127	// colors are no longer stored in a LLControlGroup file
128	LLUIColorTable::instance().loadFromSettings();
129
130	std::string config_filename = gDirUtilp->getExpandedFilename(
131																 LL_PATH_APP_SETTINGS, "settings.xml");
132	gSavedSettings.loadFromFile(config_filename);
133	
134	// See LLAppViewer::init()
135	LLUI::settings_map_t settings;
136	settings["config"] = &gSavedSettings;
137	settings["ignores"] = &gWarningSettings;
138	settings["floater"] = &gSavedSettings;
139	settings["account"] = &gSavedPerAccountSettings;
140	
141	// Don't use real images as we don't have a GL context
142	LLUI::initClass(settings, &gTestImageProvider);
143	
144	const bool no_register_widgets = false;
145	LLWidgetReg::initClass( no_register_widgets );
146	
147	// Unclear if this is needed
148	LLUI::setupPaths();
149	// Otherwise we get translation warnings when setting up floaters
150	// (tooltips for buttons)
151	std::set<std::string> default_args;
152	LLTransUtil::parseStrings("strings.xml", default_args);
153	LLTransUtil::parseLanguageStrings("language_settings.xml");
154	LLFontManager::initClass();
155	
156	// Creating widgets apparently requires fonts to be initialized,
157	// otherwise it crashes.
158	LLFontGL::initClass(96.f, 1.f, 1.f,
159						gDirUtilp->getAppRODataDir(),
160						LLUI::getXUIPaths(),
161						false );	// don't create gl textures
162	
163	LLFloaterView::Params fvparams;
164	fvparams.name("Floater View");
165	fvparams.rect( LLRect(0,480,640,0) );
166	fvparams.mouse_opaque(false);
167	fvparams.follows.flags(FOLLOWS_ALL);
168	fvparams.tab_stop(false);
169	gFloaterView = LLUICtrlFactory::create<LLFloaterView> (fvparams);
170}
171
172void export_test_floaters()
173{
174	// Convert all test floaters to new XML format
175	std::string delim = gDirUtilp->getDirDelimiter();
176	std::string xui_dir = get_xui_dir() + "en" + delim;
177	std::string filename;
178
179	LLDirIterator iter(xui_dir, "floater_test_*.xml");
180	while (iter.next(filename))
181	{
182		if (filename.find("_new.xml") != std::string::npos)
183		{
184			// don't re-export other test floaters
185			continue;
186		}
187		llinfos << "Converting " << filename << llendl;
188		// Build a floater and output new attributes
189		LLXMLNodePtr output_node = new LLXMLNode();
190		LLFloater* floater = new LLFloater(LLSD());
191		floater->buildFromFile(	filename,
192								//	 FALSE,	// don't open floater
193								output_node);
194		std::string out_filename = xui_dir + filename;
195		std::string::size_type extension_pos = out_filename.rfind(".xml");
196		out_filename.resize(extension_pos);
197		out_filename += "_new.xml";
198		
199		llinfos << "Output: " << out_filename << llendl;
200		LLFILE* floater_file = LLFile::fopen(out_filename.c_str(), "w");
201		LLXMLNode::writeHeaderToFile(floater_file);
202		output_node->writeToFile(floater_file);
203		fclose(floater_file);
204	}
205}
206
207int main(int argc, char** argv)
208{
209	// Must init LLError for llerrs to actually cause errors.
210	LLError::initForApplication(".");
211
212	init_llui();
213	
214	export_test_floaters();
215	
216	return 0;
217}