summaryrefslogtreecommitdiff
path: root/src/mongo/unittest/unittest.h
diff options
context:
space:
mode:
authorMathias Stearn <mathias@10gen.com>2013-05-09 14:55:47 -0400
committerMathias Stearn <mathias@10gen.com>2013-05-13 17:02:27 -0400
commitae40ceb967a9b0f1d936ebe2e3594ee6b99ce24f (patch)
treeca24c940d5807fbf5dd7f57e2014a6f3ccf63079 /src/mongo/unittest/unittest.h
parent08a2fa3f08f72f02958c5a7128121f7e75ce602e (diff)
downloadmongo-ae40ceb967a9b0f1d936ebe2e3594ee6b99ce24f.tar.gz
Don't convert static strings (__FILE__ and macro #arg) to std::strings in unittests
Speeds up a test I'm writing by >3x
Diffstat (limited to 'src/mongo/unittest/unittest.h')
-rw-r--r--src/mongo/unittest/unittest.h24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/mongo/unittest/unittest.h b/src/mongo/unittest/unittest.h
index f96a2c31a57..ef5faee4e73 100644
--- a/src/mongo/unittest/unittest.h
+++ b/src/mongo/unittest/unittest.h
@@ -348,7 +348,11 @@ namespace mongo {
class TestAssertion : private boost::noncopyable {
public:
- TestAssertion( const std::string& file, unsigned line );
+ /**
+ * file string must stay in scope and remain unchanged for the lifetime
+ * of the TestAssertion object.
+ */
+ TestAssertion( const char* file, unsigned line );
~TestAssertion();
MONGO_COMPILER_NORETURN void fail( const std::string& message) const;
@@ -357,7 +361,7 @@ namespace mongo {
}
private:
- const std::string _file;
+ const char* _file;
const unsigned _line;
};
@@ -366,8 +370,12 @@ namespace mongo {
*/
class ComparisonAssertion : private TestAssertion {
public:
- ComparisonAssertion( const std::string& aexp , const std::string& bexp ,
- const std::string& file , unsigned line );
+ /**
+ * All char* arguments must stay in scope and remain unchanged for the lifetime
+ * of the ComparisonAssertion object.
+ */
+ ComparisonAssertion( const char* aexp , const char* bexp ,
+ const char* file , unsigned line );
template<typename A,typename B>
void assertEqual( const A& a , const B& b ) {
@@ -416,17 +424,17 @@ namespace mongo {
std::string getComparisonFailureMessage(const std::string &theOperator,
const A& a, const B& b);
- std::string _aexp;
- std::string _bexp;
+ const char* _aexp;
+ const char* _bexp;
};
/**
* Helper for ASSERT_APPROX_EQUAL to ensure that the arguments are evaluated only once.
*/
template < typename A, typename B, typename ABSOLUTE_ERR >
- inline void assertApproxEqual(const std::string& aexp, const std::string& bexp,
+ inline void assertApproxEqual(const char* aexp, const char* bexp,
const A& a, const B& b, const ABSOLUTE_ERR& absoluteErr,
- const std::string& file , unsigned line) {
+ const char* file , unsigned line) {
if (std::abs(a - b) <= absoluteErr)
return;
TestAssertion(file, line).fail(mongoutils::str::stream()