PageRenderTime 33ms CodeModel.GetById 19ms 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
Possible License(s): LGPL-2.1
  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. #include "llui_libtest.h"
  28. // project includes
  29. #include "llwidgetreg.h"
  30. // linden library includes
  31. #include "llcontrol.h" // LLControlGroup
  32. #include "lldir.h"
  33. #include "lldiriterator.h"
  34. #include "llerrorcontrol.h"
  35. #include "llfloater.h"
  36. #include "llfontfreetype.h"
  37. #include "llfontgl.h"
  38. #include "lltransutil.h"
  39. #include "llui.h"
  40. #include "lluictrlfactory.h"
  41. #include <iostream>
  42. // *TODO: switch to using TUT
  43. // *TODO: teach Parabuild about this program, run automatically after full builds
  44. // I believe these must be globals, not stack variables. JC
  45. LLControlGroup gSavedSettings("Global"); // saved at end of session
  46. LLControlGroup gSavedPerAccountSettings("PerAccount"); // saved at end of session
  47. LLControlGroup gWarningSettings("Warnings"); // persists ignored dialogs/warnings
  48. // We can't create LLImageGL objects because we have no window or rendering
  49. // context. Provide enough of an LLUIImage to test the LLUI library without
  50. // an underlying image.
  51. class TestUIImage : public LLUIImage
  52. {
  53. public:
  54. TestUIImage()
  55. : LLUIImage( std::string(), NULL ) // NULL ImageGL, don't deref!
  56. { }
  57. /*virtual*/ S32 getWidth() const
  58. {
  59. return 16;
  60. }
  61. /*virtual*/ S32 getHeight() const
  62. {
  63. return 16;
  64. }
  65. };
  66. class LLTexture ;
  67. // We need to supply dummy images
  68. class TestImageProvider : public LLImageProviderInterface
  69. {
  70. public:
  71. /*virtual*/ LLPointer<LLUIImage> getUIImage(const std::string& name, S32 priority)
  72. {
  73. return makeImage();
  74. }
  75. /*virtual*/ LLPointer<LLUIImage> getUIImageByID(const LLUUID& id, S32 priority)
  76. {
  77. return makeImage();
  78. }
  79. /*virtual*/ void cleanUp()
  80. {
  81. }
  82. LLPointer<LLUIImage> makeImage()
  83. {
  84. LLPointer<LLTexture> image_gl;
  85. LLPointer<LLUIImage> image = new TestUIImage(); //LLUIImage( std::string(), image_gl);
  86. mImageList.push_back(image);
  87. return image;
  88. }
  89. public:
  90. // Unclear if we need this, hold on to one copy of each image we make
  91. std::vector<LLPointer<LLUIImage> > mImageList;
  92. };
  93. TestImageProvider gTestImageProvider;
  94. static std::string get_xui_dir()
  95. {
  96. std::string delim = gDirUtilp->getDirDelimiter();
  97. return gDirUtilp->getSkinBaseDir() + delim + "default" + delim + "xui" + delim;
  98. }
  99. void init_llui()
  100. {
  101. // Font lookup needs directory support
  102. #if LL_DARWIN
  103. const char* newview_path = "../../../../newview";
  104. #else
  105. const char* newview_path = "../../../newview";
  106. #endif
  107. gDirUtilp->initAppDirs("SecondLife", newview_path);
  108. gDirUtilp->setSkinFolder("default");
  109. // colors are no longer stored in a LLControlGroup file
  110. LLUIColorTable::instance().loadFromSettings();
  111. std::string config_filename = gDirUtilp->getExpandedFilename(
  112. LL_PATH_APP_SETTINGS, "settings.xml");
  113. gSavedSettings.loadFromFile(config_filename);
  114. // See LLAppViewer::init()
  115. LLUI::settings_map_t settings;
  116. settings["config"] = &gSavedSettings;
  117. settings["ignores"] = &gWarningSettings;
  118. settings["floater"] = &gSavedSettings;
  119. settings["account"] = &gSavedPerAccountSettings;
  120. // Don't use real images as we don't have a GL context
  121. LLUI::initClass(settings, &gTestImageProvider);
  122. const bool no_register_widgets = false;
  123. LLWidgetReg::initClass( no_register_widgets );
  124. // Unclear if this is needed
  125. LLUI::setupPaths();
  126. // Otherwise we get translation warnings when setting up floaters
  127. // (tooltips for buttons)
  128. std::set<std::string> default_args;
  129. LLTransUtil::parseStrings("strings.xml", default_args);
  130. LLTransUtil::parseLanguageStrings("language_settings.xml");
  131. LLFontManager::initClass();
  132. // Creating widgets apparently requires fonts to be initialized,
  133. // otherwise it crashes.
  134. LLFontGL::initClass(96.f, 1.f, 1.f,
  135. gDirUtilp->getAppRODataDir(),
  136. LLUI::getXUIPaths(),
  137. false ); // don't create gl textures
  138. LLFloaterView::Params fvparams;
  139. fvparams.name("Floater View");
  140. fvparams.rect( LLRect(0,480,640,0) );
  141. fvparams.mouse_opaque(false);
  142. fvparams.follows.flags(FOLLOWS_ALL);
  143. fvparams.tab_stop(false);
  144. gFloaterView = LLUICtrlFactory::create<LLFloaterView> (fvparams);
  145. }
  146. void export_test_floaters()
  147. {
  148. // Convert all test floaters to new XML format
  149. std::string delim = gDirUtilp->getDirDelimiter();
  150. std::string xui_dir = get_xui_dir() + "en" + delim;
  151. std::string filename;
  152. LLDirIterator iter(xui_dir, "floater_test_*.xml");
  153. while (iter.next(filename))
  154. {
  155. if (filename.find("_new.xml") != std::string::npos)
  156. {
  157. // don't re-export other test floaters
  158. continue;
  159. }
  160. llinfos << "Converting " << filename << llendl;
  161. // Build a floater and output new attributes
  162. LLXMLNodePtr output_node = new LLXMLNode();
  163. LLFloater* floater = new LLFloater(LLSD());
  164. floater->buildFromFile( filename,
  165. // FALSE, // don't open floater
  166. output_node);
  167. std::string out_filename = xui_dir + filename;
  168. std::string::size_type extension_pos = out_filename.rfind(".xml");
  169. out_filename.resize(extension_pos);
  170. out_filename += "_new.xml";
  171. llinfos << "Output: " << out_filename << llendl;
  172. LLFILE* floater_file = LLFile::fopen(out_filename.c_str(), "w");
  173. LLXMLNode::writeHeaderToFile(floater_file);
  174. output_node->writeToFile(floater_file);
  175. fclose(floater_file);
  176. }
  177. }
  178. int main(int argc, char** argv)
  179. {
  180. // Must init LLError for llerrs to actually cause errors.
  181. LLError::initForApplication(".");
  182. init_llui();
  183. export_test_floaters();
  184. return 0;
  185. }