tbeatResponse, AuthFailure) {
    ReplSetHeartbeatResponse hbResp;
    std::string errMsg = "Unauthorized";
    Status result = hbResp.initialize(
        BSON("ok" << 0.0 << "errmsg" << errMsg << "code" << ErrorCodes::Unauthorized), 0);
    ASSERT_EQUALS(ErrorCodes::Unauthorized, result.code());
    ASSERT_EQUALS(errMsg, result.reason());
}

TEST(ReplSetHeartbeatResponse, ServerError) {
    ReplSetHeartbeatResponse hbResp;
    std::string errMsg = "Random Error";
    Status result = hbResp.initialize(BSON("ok" << 0.0 << "errmsg" << errMsg), 0);
    ASSERT_EQUALS(ErrorCodes::UnknownError, result.code());
    ASSERT_EQUALS(errMsg, result.reason());
}

}  // namespace
}  // namespace repl
}  // namespace mongo


module java.nonstandard.XmlTranscode;

import java.lang.util;
import java.lang.exceptions;
import java.lang.Math;

/++
 + Decode XML entities into UTF8 string.
 + Eg. "&amp;" -> "&", "&#38;" -> "&", "&#x26;" -> "&"
 + Throws TextException on failure
 + The given string is modified.
 +/
String xmlUnescape( String str ){

    void error(){
        throw new RuntimeException( "xmlUnescape" );
    }
    // &lt; ...
    // &#1234;
    // &#x12AF;
    String src = str;
    String trg = str;
    while( src.length ){
        if( src[0] !is '&' ){
            //trg[0] = src[0];
            trg = trg[1..$];
            src = src[1..$];
        }
        else{
            src = src[1..$]; //  go past '&'
            if( src.length < 2 ) error();

            // search semi
            int len = Math.min( cast(int)src.length, 10 ); // limit semi search to possible longest entityname
            int semi = java.lang.util.indexOf( src[0 .. len ], ';' );
            if( semi is -1 ) error(); // no semi found

            String entityName = src[ 0 .. semi ]; // name without semi
            dchar entityValue = 0;
            switch( entityName ){
                case "lt":   entityValue = '<'; break;
                case "gt":   entityValue = '>'; break;
                case "amp":  entityValue = '&'; break;
             