llapp_tut.cpp

Go to the documentation of this file.
00001 
00033 #include <tut/tut.h>
00034 
00035 #include "linden_common.h"
00036 #include "llapp.h"
00037 #include "lltut.h"
00038 
00039 
00040 namespace tut
00041 {
00042         struct application
00043         {
00044                 class LLTestApp : public LLApp
00045                 {
00046                 public:
00047                         virtual bool init() { return true; }
00048                         virtual bool cleanup() { return true; }
00049                         virtual bool mainLoop() { return true; }
00050                 };
00051                 LLTestApp* mApp;
00052                 application()
00053                 {
00054                         mApp = new LLTestApp;
00055                 }
00056                 ~application()
00057                 {
00058                         delete mApp;
00059                 }
00060         };
00061 
00062         typedef test_group<application> application_t;
00063         typedef application_t::object application_object_t;
00064         tut::application_t tut_application("application");
00065 
00066         template<> template<>
00067         void application_object_t::test<1>()
00068         {
00069                 LLSD defaults;
00070                 defaults["template"] = "../../scripts/messages/message_template.msg";
00071                 defaults["configdir"] = ".";
00072                 defaults["db_host"] = "mysql.durga.lindenlab.com";
00073                 defaults["db_user"] = "linden";
00074                 defaults["db_password"] = "gomez";
00075                 defaults["datadir"] = "data";
00076                 mApp->setOptionData(LLApp::PRIORITY_DEFAULT, defaults);
00077 
00078                 LLSD db_user_sd = mApp->getOption("db_user");
00079                 ensure_equals("data type", db_user_sd.type(), LLSD::TypeString);
00080                 ensure_equals(
00081                         "data value", db_user_sd.asString(), std::string("linden"));
00082         }
00083 
00084         template<> template<>
00085         void application_object_t::test<2>()
00086         {
00087                 const int ARGC = 13;
00088                 char* ARGV[ARGC] =
00089                 {
00090                         "", // argv[0] is usually the application name
00091                         "-crashcount",
00092                         "2",
00093                         "-space",
00094                         "spaceserver.grid.lindenlab.com",
00095                         "-db_host",
00096                         "localhost",
00097                         "--allowlslhttprequests",
00098                         "-asset-uri",
00099                         "http://asset.grid.lindenlab.com/assets",
00100                         "-data",
00101                         "127.0.0.1",
00102                         "--smtp"
00103                 };
00104                 bool ok = mApp->parseCommandOptions(ARGC, ARGV);
00105                 ensure("command line parsed", ok);
00106                 ensure_equals(
00107                         "crashcount", mApp->getOption("crashcount").asInteger(), 2);
00108                 ensure_equals(
00109                         "space",
00110                         mApp->getOption("space").asString(),
00111                         std::string("spaceserver.grid.lindenlab.com"));
00112                 ensure_equals(
00113                         "db_host",
00114                         mApp->getOption("db_host").asString(),
00115                         std::string("localhost"));
00116                 ensure("allowlshlttprequests", mApp->getOption("smtp"));
00117                 ensure_equals(
00118                         "asset-uri",
00119                         mApp->getOption("asset-uri").asString(),
00120                         std::string("http://asset.grid.lindenlab.com/assets"));
00121                 ensure_equals(
00122                         "data",
00123                         mApp->getOption("data").asString(),
00124                         std::string("127.0.0.1"));
00125                 ensure("smtp", mApp->getOption("smtp"));
00126         }
00127 
00128         template<> template<>
00129         void application_object_t::test<3>()
00130         {
00131                 const int ARGC = 4;
00132                 char* ARGV[ARGC] =
00133                 {
00134                         "", // argv[0] is usually the application name
00135                         "crashcount",
00136                         "2",
00137                         "--space"
00138                 };
00139                 bool ok = mApp->parseCommandOptions(ARGC, ARGV);
00140                 ensure("command line parse failure", !ok);
00141         }
00142 
00143         template<> template<>
00144         void application_object_t::test<4>()
00145         {
00146                 const int ARGC = 4;
00147                 char* ARGV[ARGC] =
00148                 {
00149                         "", // argv[0] is usually the application name
00150                         "--crashcount",
00151                         "2",
00152                         "space"
00153                 };
00154                 bool ok = mApp->parseCommandOptions(ARGC, ARGV);
00155                 ensure("command line parse failure", !ok);
00156         }
00157 
00158 
00159         template<> template<>
00160         void application_object_t::test<5>()
00161         {
00162                 LLSD options;
00163                 options["boolean-test"] = true;
00164                 mApp->setOptionData(LLApp::PRIORITY_GENERAL_CONFIGURATION, options);
00165                 ensure("bool set", mApp->getOption("boolean-test").asBoolean());
00166                 options["boolean-test"] = false;
00167                 mApp->setOptionData(LLApp::PRIORITY_RUNTIME_OVERRIDE, options);
00168                 ensure("bool unset", !mApp->getOption("boolean-test").asBoolean());
00169         }
00170 }

Generated on Thu Jul 1 06:08:19 2010 for Second Life Viewer by  doxygen 1.4.7