summaryrefslogtreecommitdiff
path: root/indra/llmessage/tests/commtest.h
diff options
context:
space:
mode:
authorNat Goodspeed <nat@lindenlab.com>2011-06-09 12:58:47 -0400
committerNat Goodspeed <nat@lindenlab.com>2011-06-09 12:58:47 -0400
commit92caead4bae194bc2c50d18e2f617710b5df69a2 (patch)
tree2256c7e7ff8ca23d713f011322cacfad300a5133 /indra/llmessage/tests/commtest.h
parent68a7c4cb83aca58e6ad9162be9e5022d6f801eac (diff)
parent7e322d837f7958eba62844583e2db55f6c69268f (diff)
Automated merge with http://hg.secondlife.com/viewer-development
Diffstat (limited to 'indra/llmessage/tests/commtest.h')
-rw-r--r--indra/llmessage/tests/commtest.h64
1 files changed, 57 insertions, 7 deletions
diff --git a/indra/llmessage/tests/commtest.h b/indra/llmessage/tests/commtest.h
index 0fef596df2..0d149b5258 100644
--- a/indra/llmessage/tests/commtest.h
+++ b/indra/llmessage/tests/commtest.h
@@ -34,6 +34,7 @@
#include "llsd.h"
#include "llhost.h"
#include "stringize.h"
+#include <map>
#include <string>
#include <stdexcept>
#include <boost/lexical_cast.hpp>
@@ -43,6 +44,58 @@ struct CommtestError: public std::runtime_error
CommtestError(const std::string& what): std::runtime_error(what) {}
};
+static bool query_verbose()
+{
+ const char* cbose = getenv("INTEGRATION_TEST_VERBOSE");
+ if (! cbose)
+ {
+ cbose = "1";
+ }
+ std::string strbose(cbose);
+ return (! (strbose == "0" || strbose == "off" ||
+ strbose == "false" || strbose == "quiet"));
+}
+
+bool verbose()
+{
+ // This should only be initialized once.
+ static bool vflag = query_verbose();
+ return vflag;
+}
+
+static int query_port(const std::string& var)
+{
+ const char* cport = getenv(var.c_str());
+ if (! cport)
+ {
+ throw CommtestError(STRINGIZE("missing environment variable" << var));
+ }
+ // This will throw, too, if the value of PORT isn't numeric.
+ int port(boost::lexical_cast<int>(cport));
+ if (verbose())
+ {
+ std::cout << "getport('" << var << "') = " << port << std::endl;
+ }
+ return port;
+}
+
+static int getport(const std::string& var)
+{
+ typedef std::map<std::string, int> portsmap;
+ static portsmap ports;
+ // We can do this with a single map lookup with map::insert(). Either it
+ // returns an existing entry and 'false' (not newly inserted), or it
+ // inserts the specified value and 'true'.
+ std::pair<portsmap::iterator, bool> inserted(ports.insert(portsmap::value_type(var, 0)));
+ if (inserted.second)
+ {
+ // We haven't yet seen this var. Remember its value.
+ inserted.first->second = query_port(var);
+ }
+ // Return the (existing or new) iterator's value.
+ return inserted.first->second;
+}
+
/**
* This struct is shared by a couple of standalone comm tests (ADD_COMM_BUILD_TEST).
*/
@@ -71,13 +124,10 @@ struct commtest_data
static int getport(const std::string& var)
{
- const char* port = getenv(var.c_str());
- if (! port)
- {
- throw CommtestError("missing $PORT environment variable");
- }
- // This will throw, too, if the value of PORT isn't numeric.
- return boost::lexical_cast<int>(port);
+ // We have a couple consumers of commtest_data::getport(). But we've
+ // since moved it out to the global namespace. So this is just a
+ // facade.
+ return ::getport(var);
}
bool outcome(const LLSD& _result, bool _success)