diff --git a/tests/cpp/security/CredentialGenerator.hpp b/tests/cpp/security/CredentialGenerator.hpp index d35b4e380b..bf9661a0a8 100644 --- a/tests/cpp/security/CredentialGenerator.hpp +++ b/tests/cpp/security/CredentialGenerator.hpp @@ -129,11 +129,7 @@ class CredentialGenerator { ID id() { return m_id; } std::string name() { return m_name; } - std::string toString() { - char chID[5]; - sprintf(chID, "%d", m_id); - return std::string(chID) + m_name; - } + std::string toString() { return std::to_string(m_id) + m_name; } static void dump(); void hashCode() {} @@ -141,18 +137,11 @@ class CredentialGenerator { void getAuthInit(std::shared_ptr& prop); std::string getPublickeyfile() { - char* tempPath = nullptr; - tempPath = ACE_OS::getenv("TESTSRC"); - std::string path = ""; - if (!tempPath) { - tempPath = ACE_OS::getenv("BUILDDIR"); - path = std::string(tempPath) + "/framework/data"; - } else { - path = std::string(tempPath); - } - char pubfile[1000] = {'\0'}; - sprintf(pubfile, "%s/keystore/publickeyfile", path.c_str()); - return std::string(pubfile); + auto path = + ACE_OS::getenv("TESTSRC") + ? std::string(ACE_OS::getenv("TESTSRC")) + : std::string(ACE_OS::getenv("BUILDDIR")) + "/framework/data"; + return path + "/keystore/publickeyfile"; } std::string getServerCmdParams(std::string securityParams, diff --git a/tests/cpp/security/PkcsCredentialGenerator.cpp b/tests/cpp/security/PkcsCredentialGenerator.cpp index f09b19b9c2..1207bd4673 100644 --- a/tests/cpp/security/PkcsCredentialGenerator.cpp +++ b/tests/cpp/security/PkcsCredentialGenerator.cpp @@ -61,18 +61,14 @@ std::string PKCSCredentialGenerator::getInitArgs(std::string workingDir, bool) { void PKCSCredentialGenerator::getValidCredentials( std::shared_ptr& p) { - char username[20] = {'\0'}; - sprintf(username, "geode%d", randomValue(1, 10)); - setPKCSProperties(p, username); + setPKCSProperties(p, "geode" + std::to_string(randomValue(1, 10))); BOOST_LOG_TRIVIAL(info) << "inserted valid security-username " << p->find("security-username")->value(); } void PKCSCredentialGenerator::getInvalidCredentials( std::shared_ptr& p) { - char username[20] = {'\0'}; - sprintf(username, "%dgeode", randomValue(1, 11)); - setPKCSProperties(p, username); + setPKCSProperties(p, std::to_string(randomValue(1, 11)) + "geode"); BOOST_LOG_TRIVIAL(info) << "inserted invalid security-username " << p->find("security-username")->value(); } diff --git a/tests/cpp/security/PkcsCredentialGenerator.hpp b/tests/cpp/security/PkcsCredentialGenerator.hpp index c3943f9d59..53f6e261ea 100644 --- a/tests/cpp/security/PkcsCredentialGenerator.hpp +++ b/tests/cpp/security/PkcsCredentialGenerator.hpp @@ -69,30 +69,19 @@ class PKCSCredentialGenerator : public CredentialGenerator { } void insertKeyStorePath(std::shared_ptr& p, - const char* username) { - char keystoreFilePath[1024]; - char* tempPath = nullptr; - tempPath = ACE_OS::getenv("TESTSRC"); - std::string path = ""; - if (!tempPath) { - tempPath = ACE_OS::getenv("BUILDDIR"); - path = std::string(tempPath) + "/framework/data"; - } else { - path = std::string(tempPath); - } - - sprintf(keystoreFilePath, "%s/keystore/%s.keystore", path.c_str(), - username); - p->insert(KEYSTORE_FILE_PATH, keystoreFilePath); + const std::string& username) { + auto path = + ACE_OS::getenv("TESTSRC") + ? std::string(ACE_OS::getenv("TESTSRC")) + : std::string(ACE_OS::getenv("BUILDDIR")) + "/framework/data"; + p->insert(KEYSTORE_FILE_PATH, path + "/keystore/" + username + ".keystore"); } - void setPKCSProperties(std::shared_ptr& p, char* username) { - char keyStorePassWord[1024]; - - sprintf(keyStorePassWord, "%s", "geode"); + void setPKCSProperties(std::shared_ptr& p, + const std::string& username) { p->insert(SECURITY_USERNAME, "geode"); p->insert(KEYSTORE_ALIAS, username); - p->insert(KEYSTORE_PASSWORD, keyStorePassWord); + p->insert(KEYSTORE_PASSWORD, "geode"); insertKeyStorePath(p, username); } diff --git a/tests/cpp/security/XmlAuthzCredentialGenerator.cpp b/tests/cpp/security/XmlAuthzCredentialGenerator.cpp index 89cecd42ae..9226862bd5 100644 --- a/tests/cpp/security/XmlAuthzCredentialGenerator.cpp +++ b/tests/cpp/security/XmlAuthzCredentialGenerator.cpp @@ -46,22 +46,23 @@ void XmlAuthzCredentialGenerator::getAllowedDummyAuthz(ROLES role) { role = getRequiredRole(); validity = "valid"; } - char userName[100]; + + std::string userName; switch (role) { case READER_ROLE: - sprintf(userName, kPRiUsername, "reader", randomValue(2)); + userName = "reader" + std::to_string(randomValue(2)); break; case WRITER_ROLE: - sprintf(userName, kPRiUsername, "writer", randomValue(2)); + userName = "writer" + std::to_string(randomValue(2)); break; case QUERY_ROLE: - sprintf(userName, kPRiUsername, "reader", randomValue(1) + 3); + userName = "reader" + std::to_string(randomValue(1) + 3); break; case ADMIN_ROLE: - sprintf(userName, "%s", adminUsers[randomValue(adminUsrSz)]); + userName = adminUsers[randomValue(adminUsrSz)]; break; case NO_ROLE: - sprintf(userName, kPRiUsername, "user", randomValue(2)); + userName = "user" + std::to_string(randomValue(2)); break; } @@ -93,29 +94,29 @@ std::string XmlAuthzCredentialGenerator::getAllowedUser(ROLES role) { role = getRequiredRole(); validity = "valid"; } - char userName[256]; + std::string userName; switch (role) { case READER_ROLE: - sprintf(userName, kPRiUsername, userPrefix.c_str(), - readerIndices[randomValue(readerIndSz)]); + userName = + userPrefix + std::to_string(readerIndices[randomValue(readerIndSz)]); break; case WRITER_ROLE: - sprintf(userName, kPRiUsername, userPrefix.c_str(), - writerIndices[randomValue(writerIndSz)]); + userName = + userPrefix + std::to_string(writerIndices[randomValue(writerIndSz)]); break; case QUERY_ROLE: - sprintf(userName, kPRiUsername, userPrefix.c_str(), - queryIndices[randomValue(queryIndSz)]); + userName = + userPrefix + std::to_string(queryIndices[randomValue(queryIndSz)]); break; case ADMIN_ROLE: case NO_ROLE: - sprintf(userName, kPRiUsername, userPrefix.c_str(), - adminIndices[randomValue(adminIndSz)]); + userName = + userPrefix + std::to_string(adminIndices[randomValue(adminIndSz)]); break; } BOOST_LOG_TRIVIAL(info) << "inserted " << validity << " username " << userName; - return std::string(userName); + return userName; } void XmlAuthzCredentialGenerator::getAllowedLdapAuthz(ROLES role) { diff --git a/tests/cpp/security/XmlAuthzCredentialGenerator.hpp b/tests/cpp/security/XmlAuthzCredentialGenerator.hpp index 64545f05d8..c9f95e1f71 100644 --- a/tests/cpp/security/XmlAuthzCredentialGenerator.hpp +++ b/tests/cpp/security/XmlAuthzCredentialGenerator.hpp @@ -55,8 +55,6 @@ const opCodeList::value_type QArr[] = {OP_QUERY, OP_REGISTER_CQ}; const stringList::value_type QRArr[] = {"Portfolios", "Positions"}; -static const char* kPRiUsername = "%s%d"; - class XmlAuthzCredentialGenerator; class XmlAuthzCredentialGenerator { diff --git a/tests/cpp/testobject/BatchObject.cpp b/tests/cpp/testobject/BatchObject.cpp index a2f8635fcf..c1ea92a5b2 100644 --- a/tests/cpp/testobject/BatchObject.cpp +++ b/tests/cpp/testobject/BatchObject.cpp @@ -17,6 +17,8 @@ #include "BatchObject.hpp" +#include + namespace testobject { using apache::geode::client::CacheableBytes; @@ -42,12 +44,11 @@ void BatchObject::fromData(apache::geode::client::DataInput& input) { byteArray = std::dynamic_pointer_cast(input.readObject()); } std::string BatchObject::toString() const { - char buf[102500]; - sprintf(buf, - "BatchObject:[index = %d timestamp = %" PRIu64 - " batch = %d byteArray=%d ]", - index, timestamp, batch, byteArray->length()); - return buf; + std::stringstream strm; + + strm << "BatchObject:[index = " << index << " timestamp = " << timestamp + << " batch = " << batch << " byteArray = " << byteArray->length() << "]"; + return strm.str(); } } // namespace testobject diff --git a/tests/cpp/testobject/DeltaFastAssetAccount.hpp b/tests/cpp/testobject/DeltaFastAssetAccount.hpp index 96620047a2..0a99ebc1f5 100644 --- a/tests/cpp/testobject/DeltaFastAssetAccount.hpp +++ b/tests/cpp/testobject/DeltaFastAssetAccount.hpp @@ -21,6 +21,7 @@ #define GEODE_TESTOBJECT_DELTAFASTASSETACCOUNT_H_ #include +#include #include #include @@ -72,12 +73,12 @@ class TESTOBJECT_EXPORT DeltaFastAssetAccount : public DataSerializable, void fromDelta(apache::geode::client::DataInput& input) override; std::string toString() const override { - char buf[102500]; - sprintf(buf, - "DeltaFastAssetAccount:[acctId = %d customerName = %s netWorth = " - "%f timestamp = %" PRIu64 "]", - acctId, customerName->toString().c_str(), netWorth, timestamp); - return buf; + std::stringstream strm; + + strm << "DeltaFastAssetAccount:[acctId = " << acctId + << " customerName = " << customerName->toString() + << " netWorth = " << netWorth << " timestamp = " << timestamp << "]"; + return strm.str(); } int getAcctId() { return acctId; } diff --git a/tests/cpp/testobject/DeltaPSTObject.cpp b/tests/cpp/testobject/DeltaPSTObject.cpp index f055100336..e981393618 100644 --- a/tests/cpp/testobject/DeltaPSTObject.cpp +++ b/tests/cpp/testobject/DeltaPSTObject.cpp @@ -18,6 +18,7 @@ #include "DeltaPSTObject.hpp" #include +#include #include "ArrayOfByte.hpp" @@ -59,12 +60,12 @@ void DeltaPSTObject::fromData(apache::geode::client::DataInput& input) { valueData = std::dynamic_pointer_cast(input.readObject()); } std::string DeltaPSTObject::toString() const { - char buf[102500]; - sprintf(buf, - "DeltaPSTObject:[timestamp = %" PRIu64 - " field1 = %d field2 = %c valueData=%d ]", - timestamp, field1, field2, valueData->length()); - return buf; + std::stringstream strm; + + strm << "DeltaPSTObject:[timestamp = " << timestamp << " field1 = " << field1 + << " field2 = " << field2 << " valueData = " << valueData->length() + << "]"; + return strm.str(); } } // namespace testobject diff --git a/tests/cpp/testobject/DeltaTestImpl.cpp b/tests/cpp/testobject/DeltaTestImpl.cpp index 2babb2e5c9..db2301c6e4 100644 --- a/tests/cpp/testobject/DeltaTestImpl.cpp +++ b/tests/cpp/testobject/DeltaTestImpl.cpp @@ -17,6 +17,8 @@ #include "DeltaTestImpl.hpp" +#include + namespace testobject { uint8_t DeltaTestImpl::INT_MASK = 0x1; @@ -128,10 +130,11 @@ void DeltaTestImpl::fromDelta(DataInput& input) { } std::string DeltaTestImpl::toString() const { - char buf[102500]; - sprintf(buf, "DeltaTestImpl[hasDelta=%d int=%d double=%f str=%s \n", - m_hasDelta, intVar, doubleVar, str->toString().c_str()); - return buf; + std::stringstream strm; + + strm << "DeltaTestImpl[hasDelta=" << m_hasDelta << " int = " << intVar + << " double = " << doubleVar << " str = " << str->toString() << "\n"; + return strm.str(); } } // namespace testobject diff --git a/tests/cpp/testobject/DeltaTestObj.hpp b/tests/cpp/testobject/DeltaTestObj.hpp index d6de7a046a..5c318fa95e 100644 --- a/tests/cpp/testobject/DeltaTestObj.hpp +++ b/tests/cpp/testobject/DeltaTestObj.hpp @@ -20,6 +20,8 @@ * limitations under the License. */ +#include + #include "DeltaTestImpl.hpp" #include "testobject_export.h" @@ -65,12 +67,12 @@ class TESTOBJECT_EXPORT DeltaTestObj : public DeltaTestImpl { void setFromDeltaCounter(int counter) { fromDeltaCounter = counter; } void setToDeltaCounter(int counter) { toDeltaCounter = counter; } std::string toString() const { - char buf[102500]; - sprintf(buf, - "DeltaTestObj: toDeltaCounter = %lld fromDeltaCounter = %lld\n", - toDeltaCounter, fromDeltaCounter); - // DeltaTestImpl::toString(); - return buf; + std::stringstream strm; + + strm << "DeltaTestObj: toDeltaCounter = " << toDeltaCounter + << ", fromDeltaCounter = " << fromDeltaCounter << "\n"; + + return strm.str(); } static Serializable* create() { return new DeltaTestObj(); } int32_t classId() const override { return 32; } diff --git a/tests/cpp/testobject/EqStruct.cpp b/tests/cpp/testobject/EqStruct.cpp index 30b31a361b..8fd99bbe55 100644 --- a/tests/cpp/testobject/EqStruct.cpp +++ b/tests/cpp/testobject/EqStruct.cpp @@ -17,6 +17,8 @@ #include "EqStruct.hpp" +#include + #include #include @@ -197,10 +199,11 @@ void EqStruct::fromData(apache::geode::client::DataInput& in) { discretionOffset = in.readDouble(); } std::string EqStruct::toString() const { - char buf[102500]; - sprintf(buf, "EqStruct:[timestamp = %" PRIu64 " myIndex = %d cxlQty = %d ]", - timestamp, myIndex, cxlQty); - return buf; + std::stringstream strm; + + strm << "EqStruct:[timestamp = " << timestamp << " myIndex = " << myIndex + << " cxlQty = " << cxlQty << "]"; + return strm.str(); } } // namespace testobject diff --git a/tests/cpp/testobject/EqStruct.hpp b/tests/cpp/testobject/EqStruct.hpp index 0e33539d0a..120ff9c0fa 100644 --- a/tests/cpp/testobject/EqStruct.hpp +++ b/tests/cpp/testobject/EqStruct.hpp @@ -108,9 +108,9 @@ class TESTOBJECT_EXPORT EqStruct : public TimestampedObject { void validate(int index) { int encodedIndex = myIndex; if (encodedIndex != index) { - char logmsg[2048]; - sprintf(logmsg, "Expected index %d , got %d.\n", index, encodedIndex); - throw FwkException(logmsg); + throw FwkException(std::string("Expected index ") + + std::to_string(index) + ", got " + + std::to_string(encodedIndex) + ".\n"); } } void update() { diff --git a/tests/cpp/testobject/FastAssetAccount.cpp b/tests/cpp/testobject/FastAssetAccount.cpp index 3946e69742..bbcbb106cf 100644 --- a/tests/cpp/testobject/FastAssetAccount.cpp +++ b/tests/cpp/testobject/FastAssetAccount.cpp @@ -18,6 +18,7 @@ #include "FastAssetAccount.hpp" #include +#include #include "FastAsset.hpp" @@ -62,12 +63,12 @@ void FastAssetAccount::fromData(apache::geode::client::DataInput& input) { } std::string FastAssetAccount::toString() const { - char buf[102500]; - sprintf(buf, - "FastAssetAccount:[acctId = %d customerName = %s netWorth = %f " - "timestamp = %" PRIu64 "]", - acctId, customerName->toString().c_str(), netWorth, timestamp); - return buf; + std::stringstream strm; + + strm << "FastAssetAccount:[acctId = " << acctId + << " customerName = " << customerName->toString() + << " netWorth = " << netWorth << "timestamp = " << timestamp; + return strm.str(); } } // namespace testobject diff --git a/tests/cpp/testobject/InvalidPdxUsage.cpp b/tests/cpp/testobject/InvalidPdxUsage.cpp index 5532250026..1f49653b26 100644 --- a/tests/cpp/testobject/InvalidPdxUsage.cpp +++ b/tests/cpp/testobject/InvalidPdxUsage.cpp @@ -744,12 +744,7 @@ void InvalidPdxUsage::fromData(PdxReader& pr) { fromDataexceptionCounter, exceptionCounter); } std::string InvalidPdxUsage::toString() const { - char idbuf[1024]; - // sprintf(idbuf,"PdxObject: [ m_bool=%d ] [m_byte=%d] [m_int16=%d] - // [m_int32=%d] [m_float=%f] [m_double=%lf] [ m_string=%s ]",m_bool, m_byte, - // m_int16, m_int32, m_float, m_double, m_string); - sprintf(idbuf, "PdxObject:[m_int32=%d]", m_int32); - return idbuf; + return "PdxObject:[m_int32=" + std::to_string(m_int32) + "]"; } bool InvalidPdxUsage::equals(PdxTests::InvalidPdxUsage& other, diff --git a/tests/cpp/testobject/InvalidPdxUsage.hpp b/tests/cpp/testobject/InvalidPdxUsage.hpp index 1be93f9079..bab9579ee3 100644 --- a/tests/cpp/testobject/InvalidPdxUsage.hpp +++ b/tests/cpp/testobject/InvalidPdxUsage.hpp @@ -26,6 +26,7 @@ * Author: npatel */ +#include #include #include @@ -75,9 +76,10 @@ class TESTOBJECT_EXPORT CharTypesWithInvalidUsage : public PdxSerializable { CharTypesWithInvalidUsage() { init(); } std::string toString() const override { - char idbuf[1024]; - sprintf(idbuf, "%c %c %c", m_ch, m_chArray[0], m_chArray[1]); - return idbuf; + std::stringstream strm; + + strm << m_ch << " " << m_chArray[0] << " " << m_chArray[1]; + return strm.str(); } bool equals(CharTypesWithInvalidUsage& other) const { diff --git a/tests/cpp/testobject/NestedPdxObject.cpp b/tests/cpp/testobject/NestedPdxObject.cpp index 44fc86e5fa..8e8b404186 100644 --- a/tests/cpp/testobject/NestedPdxObject.cpp +++ b/tests/cpp/testobject/NestedPdxObject.cpp @@ -21,6 +21,8 @@ #include "NestedPdxObject.hpp" +#include + namespace testobject { void ChildPdx::toData(PdxWriter& pw) const { @@ -107,11 +109,12 @@ void ParentPdx::fromData(PdxReader& pr) { } std::string ParentPdx::toString() const { - char idbuf[1024]; - sprintf(idbuf, - "ParentPdx: [m_parentId=%d] [ m_parentName=%s ] [m_childPdx = %s ] ", - m_parentId, m_parentName.c_str(), m_childPdx->toString().c_str()); - return idbuf; + std::stringstream strm; + + strm << "ParentPdx: [m_parentId=" << m_parentId + << "][m_parentName = " << m_parentName << "][m_childPdx = " << m_childPdx + << "] "; + return strm.str(); } bool ParentPdx::equals(const ParentPdx& other, bool isPdxReadSerialized) const { diff --git a/tests/cpp/testobject/PSTObject.cpp b/tests/cpp/testobject/PSTObject.cpp index d9e55ef180..465554b666 100644 --- a/tests/cpp/testobject/PSTObject.cpp +++ b/tests/cpp/testobject/PSTObject.cpp @@ -18,6 +18,7 @@ #include "PSTObject.hpp" #include +#include #include "ArrayOfByte.hpp" @@ -49,12 +50,12 @@ void PSTObject::fromData(apache::geode::client::DataInput& input) { valueData = std::dynamic_pointer_cast(input.readObject()); } std::string PSTObject::toString() const { - char buf[102500]; - sprintf(buf, - "PSTObject:[timestamp = %" PRIu64 - " field1 = %d field2 = %c valueData=%d ]", - timestamp, field1, field2, valueData->length()); - return buf; + std::stringstream strm; + + strm << "PSTObject:[timestamp = " << timestamp << " field1 = " << field1 + << " field2 = " << field2 << " valueData = " << valueData->length() + << "]"; + return strm.str(); } } // namespace testobject diff --git a/tests/cpp/testobject/PdxClassV1.cpp b/tests/cpp/testobject/PdxClassV1.cpp index 830e07f698..23b07ccd9d 100644 --- a/tests/cpp/testobject/PdxClassV1.cpp +++ b/tests/cpp/testobject/PdxClassV1.cpp @@ -17,6 +17,8 @@ #include "PdxClassV1.hpp" +#include + namespace PdxTests { using apache::geode::client::Exception; @@ -145,19 +147,11 @@ void PdxType1V1::fromData(PdxReader& pr) { LOGDEBUG("PdxObject::fromData() End..."); } std::string PdxType1V1::toString() const { - char idbuf[4096]; - // sprintf(idbuf,"PdxObject: [ m_bool=%d ] [m_byte=%d] [m_int16=%d] - // [m_int32=%d] [m_long=%lld] [m_float=%f] [ m_string=%s ]",m_bool, m_byte, - // m_int16, m_int32, m_long, m_float, m_string); - // sprintf(idbuf,"PdxObject: [ m_bool=%d ] [m_byte=%d] [m_int16=%d] - // [m_int32=%d] [m_long=%lld] [m_float=%f] [m_double=%Lf] [ m_string=%s - // ]",m_bool, m_byte, m_int16, m_int32, m_long, m_float, m_double, m_string); - // sprintf(idbuf,"PdxObject: [ m_bool=%d ] [m_byte=%d] [m_int16=%d] - // [m_int32=%d] [m_float=%f] [m_double=%lf] [ m_string=%s ]",m_bool, m_byte, - // m_int16, m_int32, m_float, m_double, m_string); - sprintf(idbuf, "PdxType1V1:[ m_i1=%d ] [ m_i2=%d ] [ m_i3=%d ] [ m_i4=%d ]", - m_i1, m_i2, m_i3, m_i4); - return idbuf; + std::stringstream strm; + + strm << "PdxType1V1:[m_i1 = " << m_i1 << " ][m_i2 = " << m_i2 + << "][m_i3 = " << m_i3 << "][m_i4 = " << m_i4 << "]"; + return strm.str(); } /************************************************************ @@ -226,10 +220,11 @@ void PdxType2V1::fromData(PdxReader& pr) { m_i4 = pr.readInt("i4"); } std::string PdxType2V1::toString() const { - char idbuf[4096]; - sprintf(idbuf, "PdxType2V1:[ m_i1=%d ] [ m_i2=%d ] [ m_i3=%d ] [ m_i4=%d ]", - m_i1, m_i2, m_i3, m_i4); - return idbuf; + std::stringstream strm; + + strm << "PdxType2V1:[m_i1 = " << m_i1 << " ][m_i2 = " << m_i2 + << "][m_i3 = " << m_i3 << "][m_i4 = " << m_i4 << "]"; + return strm.str(); } /************************************************************ @@ -392,10 +387,11 @@ void PdxTypesV1R1::fromData(PdxReader& pr) { m_i4 = pr.readInt("i4"); } std::string PdxTypesV1R1::toString() const { - char idbuf[4096]; - sprintf(idbuf, "PdxTypesV1R1:[ m_i1=%d ] [ m_i2=%d ] [ m_i3=%d ] [ m_i4=%d ]", - m_i1, m_i2, m_i3, m_i4); - return idbuf; + std::stringstream strm; + + strm << "PdxTypesV1R1:[m_i1 = " << m_i1 << " ][m_i2 = " << m_i2 + << "][m_i3 = " << m_i3 << "][m_i4 = " << m_i4 << "]"; + return strm.str(); } /************************************************************ @@ -461,10 +457,11 @@ void PdxTypesV1R2::fromData(PdxReader& pr) { m_i4 = pr.readInt("i4"); } std::string PdxTypesV1R2::toString() const { - char idbuf[4096]; - sprintf(idbuf, "PdxTypesV1R1:[ m_i1=%d ] [ m_i2=%d ] [ m_i3=%d ] [ m_i4=%d ]", - m_i1, m_i2, m_i3, m_i4); - return idbuf; + std::stringstream strm; + + strm << "PdxTypesV1R2:[m_i1 = " << m_i1 << " ][m_i2 = " << m_i2 + << "][m_i3 = " << m_i3 << "][m_i4 = " << m_i4 << "]"; + return strm.str(); } /************************************************************ @@ -541,10 +538,12 @@ void PdxTypesIgnoreUnreadFieldsV1::fromData(PdxReader& pr) { if (!hasField) throw Exception("i4 is an valid field"); } std::string PdxTypesIgnoreUnreadFieldsV1::toString() const { - char idbuf[4096]; - sprintf(idbuf, "PdxTypesV1R1:[ m_i1=%d ] [ m_i2=%d ] [ m_i3=%d ] [ m_i4=%d ]", - m_i1, m_i2, m_i3, m_i4); - return idbuf; + std::stringstream strm; + + strm << "PdxTypesIgnoreUnreadFieldsV1:[m_i1 = " << m_i1 + << " ][m_i2 = " << m_i2 << "][m_i3 = " << m_i3 << "][m_i4 = " << m_i4 + << "]"; + return strm.str(); } /************************************************************ @@ -648,12 +647,7 @@ void PdxVersionedV1::fromData(PdxReader& pr) { m_floatArray = pr.readFloatArray("m_floatArray"); m_doubleArray = pr.readDoubleArray("m_doubleArray"); } -std::string PdxVersionedV1::toString() const { - char idbuf[4096]; - // sprintf(idbuf,"PdxTypesV1R1:[ m_i1=%d ] [ m_i2=%d ] [ m_i3=%d ] [ m_i4=%d - // ]", m_i1, m_i2, m_i3, m_i4 ); - return idbuf; -} +std::string PdxVersionedV1::toString() const { return ""; } /************************************************************ * TestKey @@ -717,9 +711,10 @@ void TestEqualsV1::fromData(PdxReader& pr) { // sArr = (string[]) reader.ReadObject("sArrObject"); } std::string TestEqualsV1::toString() const { - char idbuf[1024]; - sprintf(idbuf, "TestEqualsV1:[i1=%d ] [i2=%d] ", i1, i2); - return idbuf; + std::stringstream strm; + + strm << "TestEqualsV1:[i1 = " << i1 << " ][i2 = " << i2 << "]"; + return strm.str(); } } // namespace PdxTests diff --git a/tests/cpp/testobject/PdxClassV2.cpp b/tests/cpp/testobject/PdxClassV2.cpp index 624d571d58..de717f3651 100644 --- a/tests/cpp/testobject/PdxClassV2.cpp +++ b/tests/cpp/testobject/PdxClassV2.cpp @@ -17,6 +17,8 @@ #include "PdxClassV2.hpp" +#include + namespace PdxTests { using apache::geode::client::Exception; @@ -106,12 +108,13 @@ void PdxTypes1V2::fromData(PdxReader& pr) { // LOGDEBUG("PdxType1V2::fromData() End..."); } std::string PdxTypes1V2::toString() const { - char idbuf[4096]; - sprintf(idbuf, - "PdxType1V1:[ m_i1=%d ] [ m_i2=%d ] [ m_i3=%d ] [ m_i4=%d ] [ " - "m_i5=%d ] [ m_i6=%d ] [ m_diffInExtraFields=%d ]", - m_i1, m_i2, m_i3, m_i4, m_i5, m_i6, m_diffInExtraFields); - return idbuf; + std::stringstream strm; + + strm << "PdxTypes1V2:[m_i1 = " << m_i1 << " ][m_i2 = " << m_i2 + << "][m_i3 = " << m_i3 << "][m_i4 = " << m_i4 << "]" + << "[m_i5 = " << m_i5 << "][m_i6 = " << m_i6 + << "][m_diffInExtraFields = " << m_diffInExtraFields << "]"; + return strm.str(); } /************************************************************ @@ -193,12 +196,12 @@ void PdxTypes2V2::fromData(PdxReader& pr) { m_i4 = pr.readInt("i4"); } std::string PdxTypes2V2::toString() const { - char idbuf[4096]; - sprintf(idbuf, - "PdxTypes2V2:[ m_i1=%d ] [ m_i2=%d ] [ m_i3=%d ] [ m_i4=%d ] [ " - "m_i5=%d ] [ m_i6=%d ]", - m_i1, m_i2, m_i3, m_i4, m_i5, m_i6); - return idbuf; + std::stringstream strm; + + strm << "PdxTypes2V2:[m_i1 = " << m_i1 << " ][m_i2 = " << m_i2 + << "][m_i3 = " << m_i3 << "][m_i4 = " << m_i4 << "]" + << "[m_i5 = " << m_i5 << "][m_i6 = " << m_i6 << "]"; + return strm.str(); } /************************************************************ @@ -379,12 +382,12 @@ void PdxTypesR1V2::fromData(PdxReader& pr) { m_i6 = pr.readInt("i6"); } std::string PdxTypesR1V2::toString() const { - char idbuf[4096]; - sprintf(idbuf, - "PdxTypesR1V2:[ m_i1=%d ] [ m_i2=%d ] [ m_i3=%d ] [ m_i4=%d ] [ " - "m_i5=%d ] [ m_i6=%d ]", - m_i1, m_i2, m_i3, m_i4, m_i5, m_i6); - return idbuf; + std::stringstream strm; + + strm << "PdxTypesR1V2:[m_i1 = " << m_i1 << " ][m_i2 = " << m_i2 + << "][m_i3 = " << m_i3 << "][m_i4 = " << m_i4 << "]" + << "[m_i5 = " << m_i5 << "][m_i6 = " << m_i6 << "]"; + return strm.str(); } /************************************************************ @@ -456,9 +459,7 @@ void PdxTypesR2V2::toData(PdxWriter& pw) const { m_diffInExtraFields++; m_diffInSameFields++; - char tmpBuf[512] = {0}; - sprintf(tmpBuf, "%d", m_diffInExtraFields); - pw.writeString("m_str1", tmpBuf); + pw.writeString("m_str1", std::to_string(m_diffInExtraFields)); } void PdxTypesR2V2::fromData(PdxReader& pr) { @@ -587,12 +588,13 @@ void PdxTypesIgnoreUnreadFieldsV2::fromData(PdxReader& pr) { m_i6 = pr.readInt("i6"); } std::string PdxTypesIgnoreUnreadFieldsV2::toString() const { - char idbuf[4096]; - sprintf(idbuf, - "PdxTypesV1R1:[m_i1=%d] [m_i2=%d] [m_i3=%d] [m_i4=%d] [m_i5=%d] " - "[m_i6=%d]", - m_i1, m_i2, m_i3, m_i4, m_i5, m_i6); - return idbuf; + std::stringstream strm; + + strm << "PdxTypesIgnoreUnreadFieldsV2:[m_i1 = " << m_i1 + << " ][m_i2 = " << m_i2 << "][m_i3 = " << m_i3 << "][m_i4 = " << m_i4 + << "]" + << "[m_i5 = " << m_i5 << "][m_i6 = " << m_i6 << "]"; + return strm.str(); } /************************************************************ @@ -694,12 +696,7 @@ void PdxVersionedV2::fromData(PdxReader& pr) { m_floatArray = pr.readFloatArray("m_floatArray"); m_doubleArray = pr.readDoubleArray("m_doubleArray"); } -std::string PdxVersionedV2::toString() const { - char idbuf[4096]; - // sprintf(idbuf,"PdxTypesV1R1:[ m_i1=%d ] [ m_i2=%d ] [ m_i3=%d ] [ m_i4=%d - // ]", m_i1, m_i2, m_i3, m_i4 ); - return idbuf; -} +std::string PdxVersionedV2::toString() const { return ""; } /************************************************************ * TestKeyV2 diff --git a/tests/cpp/testobject/PdxType.cpp b/tests/cpp/testobject/PdxType.cpp index 1b734c2f2c..e998375ca1 100644 --- a/tests/cpp/testobject/PdxType.cpp +++ b/tests/cpp/testobject/PdxType.cpp @@ -259,12 +259,7 @@ void PdxTests::PdxType::fromData(PdxReader& pr) { LOGINFO("PdxObject::readObject() for enum Done..."); } std::string PdxTests::PdxType::toString() const { - char idbuf[1024]; - // sprintf(idbuf,"PdxObject: [ m_bool=%d ] [m_byte=%d] [m_int16=%d] - // [m_int32=%d] [m_float=%f] [m_double=%lf] [ m_string=%s ]",m_bool, m_byte, - // m_int16, m_int32, m_float, m_double, m_string); - sprintf(idbuf, "PdxObject:[m_int32=%d]", m_int32); - return idbuf; + return "PdxObject:[m_int32=" + std::to_string(m_int32) + "]"; } bool PdxTests::PdxType::equals(PdxTests::PdxType& other, diff --git a/tests/cpp/testobject/PdxType.hpp b/tests/cpp/testobject/PdxType.hpp index 390cfc676a..665f6ecb9f 100644 --- a/tests/cpp/testobject/PdxType.hpp +++ b/tests/cpp/testobject/PdxType.hpp @@ -20,6 +20,7 @@ #ifndef GEODE_TESTOBJECT_PDXTYPE_H_ #define GEODE_TESTOBJECT_PDXTYPE_H_ +#include #include #include @@ -106,9 +107,11 @@ class TESTOBJECT_EXPORT Child : public Parent, public PdxSerializable { int32_t getMember_f() { return m_f; } std::string toString() const override { - char idbuf[512]; - sprintf(idbuf, " Child:: %d %d %d %d %d %d ", m_a, m_b, m_c, m_d, m_e, m_f); - return idbuf; + std::stringstream strm; + + strm << "Child:: " << m_a << " " << m_b << " " << m_c << " " << m_d << " " + << m_e << " " << m_f; + return strm.str(); } const std::string& getClassName() const override { @@ -179,9 +182,10 @@ class TESTOBJECT_EXPORT CharTypes : public PdxSerializable { CharTypes() { init(); } std::string toString() const override { - char idbuf[1024]; - sprintf(idbuf, "%c %c %c", m_ch, m_chArray[0], m_chArray[1]); - return idbuf; + std::stringstream strm; + + strm << m_ch << " " << m_chArray[0] << " " << m_chArray[1]; + return strm.str(); } bool equals(CharTypes& other) const { diff --git a/tests/cpp/testobject/Position.cpp b/tests/cpp/testobject/Position.cpp index 36b3364295..8b491dbe81 100644 --- a/tests/cpp/testobject/Position.cpp +++ b/tests/cpp/testobject/Position.cpp @@ -14,11 +14,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #include "Position.hpp" #include #include +#include #include #include @@ -113,12 +115,12 @@ void Position::fromData(apache::geode::client::DataInput& input) { pid = input.readInt32(); } std::string Position::toString() const { - char buf[2048]; - sprintf(buf, - "Position Object:[ secId=%s type=%ls sharesOutstanding=%d id=%d ]", - secId->toString().c_str(), this->secType.c_str(), - this->sharesOutstanding, this->pid); - return buf; + std::stringstream strm; + + strm << "Position Object:[ secId=" << secId->toString() + << " type=" << std::string(secType.begin(), secType.end()) + << " sharesOutstanding=" << sharesOutstanding << " id=" << pid << " ]"; + return strm.str(); } } // namespace testobject diff --git a/tests/cpp/testobject/PositionPdx.cpp b/tests/cpp/testobject/PositionPdx.cpp index a680663b97..83b1d1d236 100644 --- a/tests/cpp/testobject/PositionPdx.cpp +++ b/tests/cpp/testobject/PositionPdx.cpp @@ -141,8 +141,7 @@ void PositionPdx::fromData(PdxReader& pr) { } std::string PositionPdx::toString() const { char buf[1024]; - sprintf(buf, "PositionPdx Object:[ id=%d ]", this->pid); - return buf; + return "PositionPdx Object:[ id=" + std::to_string(pid) + "]"; } } // namespace testobject diff --git a/tests/cpp/testobject/VariousPdxTypes.cpp b/tests/cpp/testobject/VariousPdxTypes.cpp index a3f9ede8e7..12812f4458 100644 --- a/tests/cpp/testobject/VariousPdxTypes.cpp +++ b/tests/cpp/testobject/VariousPdxTypes.cpp @@ -23,6 +23,7 @@ #include "VariousPdxTypes.hpp" +#include #include #include @@ -74,10 +75,11 @@ bool PdxTypes1::equals(std::shared_ptr obj) { return false; } std::string PdxTypes1::toString() const { - char idbuf[4096]; - sprintf(idbuf, "PdxTypes1:[m_i1=%d] [m_i2=%d] [m_i3=%d] [m_i4=%d]", m_i1, - m_i2, m_i3, m_i4); - return idbuf; + std::stringstream strm; + + strm << "PdxTypes1:[m_i1 = " << m_i1 << " ][m_i2 = " << m_i2 + << "][m_i3 = " << m_i3 << "][m_i4 = " << m_i4 << "]"; + return strm.str(); } void PdxTypes1::toData(PdxWriter &pw) const { @@ -131,10 +133,12 @@ bool PdxTypes2::equals(std::shared_ptr obj) { return false; } std::string PdxTypes2::toString() const { - char idbuf[4096]; - sprintf(idbuf, "PdxTypes2:[m_i1=%d] [m_i2=%d] [m_i3=%d] [m_i4=%d] [m_s1=%s]", - m_i1, m_i2, m_i3, m_i4, m_s1.c_str()); - return idbuf; + std::stringstream strm; + + strm << "PdxTypes2:[m_i1 = " << m_i1 << " ][m_i2 = " << m_i2 + << "][m_i3 = " << m_i3 << "][m_i4 = " << m_i4 << "][m_s1 = " << m_s1 + << "]"; + return strm.str(); } void PdxTypes2::toData(PdxWriter &pw) const { @@ -187,10 +191,12 @@ bool PdxTypes3::equals(std::shared_ptr obj) { return false; } std::string PdxTypes3::toString() const { - char idbuf[4096]; - sprintf(idbuf, "PdxTypes3:[m_i1=%d] [m_i2=%d] [m_i3=%d] [m_i4=%d] [m_s1=%s]", - m_i1, m_i2, m_i3, m_i4, m_s1.c_str()); - return idbuf; + std::stringstream strm; + + strm << "PdxTypes3:[m_i1 = " << m_i1 << " ][m_i2 = " << m_i2 + << "][m_i3 = " << m_i3 << "][m_i4 = " << m_i4 << "][m_s1 = " << m_s1 + << "]"; + return strm.str(); } void PdxTypes3::toData(PdxWriter &pw) const { @@ -243,10 +249,12 @@ bool PdxTypes4::equals(std::shared_ptr obj) { return false; } std::string PdxTypes4::toString() const { - char idbuf[4096]; - sprintf(idbuf, "PdxTypes4:[m_i1=%d] [m_i2=%d] [m_i3=%d] [m_i4=%d] [m_s1=%s]", - m_i1, m_i2, m_i3, m_i4, m_s1.c_str()); - return idbuf; + std::stringstream strm; + + strm << "PdxTypes4:[m_i1 = " << m_i1 << " ][m_i2 = " << m_i2 + << "][m_i3 = " << m_i3 << "][m_i4 = " << m_i4 << "][m_s1 = " << m_s1 + << "]"; + return strm.str(); } void PdxTypes4::toData(PdxWriter &pw) const { @@ -300,12 +308,12 @@ bool PdxTypes5::equals(std::shared_ptr obj) { return false; } std::string PdxTypes5::toString() const { - char idbuf[4096]; - sprintf( - idbuf, - "PdxTypes4:[m_i1=%d] [m_i2=%d] [m_i3=%d] [m_i4=%d] [m_s1=%s] [m_s2=%s]", - m_i1, m_i2, m_i3, m_i4, m_s1.c_str(), m_s2.c_str()); - return idbuf; + std::stringstream strm; + + strm << "PdxTypes5:[m_i1 = " << m_i1 << " ][m_i2 = " << m_i2 + << "][m_i3 = " << m_i3 << "][m_i4 = " << m_i4 << "]" + << "[m_s1 = " << m_s1 << "][m_s2 = " << m_s2 << "]"; + return strm.str(); } void PdxTypes5::toData(PdxWriter &pw) const { @@ -381,12 +389,12 @@ bool PdxTypes6::equals(std::shared_ptr obj) { return false; } std::string PdxTypes6::toString() const { - char idbuf[4096]; - sprintf( - idbuf, - "PdxTypes4:[m_i1=%d] [m_i2=%d] [m_i3=%d] [m_i4=%d] [m_s1=%s] [m_s2=%s]", - m_i1, m_i2, m_i3, m_i4, m_s1.c_str(), m_s2.c_str()); - return idbuf; + std::stringstream strm; + + strm << "PdxTypes6:[m_i1 = " << m_i1 << " ][m_i2 = " << m_i2 + << "][m_i3 = " << m_i3 << "][m_i4 = " << m_i4 << "]" + << "[m_s1 = " << m_s1 << "][m_s2 = " << m_s2 << "]"; + return strm.str(); } void PdxTypes6::toData(PdxWriter &pw) const { @@ -457,12 +465,12 @@ bool PdxTypes7::equals(std::shared_ptr obj) { return false; } std::string PdxTypes7::toString() const { - char idbuf[4096]; - sprintf( - idbuf, - "PdxTypes7:[m_i1=%d] [m_i2=%d] [m_i3=%d] [m_i4=%d] [m_s1=%s] [m_s2=%s]", - m_i1, m_i2, m_i3, m_i4, m_s1.c_str(), m_s2.c_str()); - return idbuf; + std::stringstream strm; + + strm << "PdxTypes7:[m_i1 = " << m_i1 << " ][m_i2 = " << m_i2 + << "][m_i3 = " << m_i3 << "][m_i4 = " << m_i4 << "]" + << "[m_s1 = " << m_s1 << "][m_s2 = " << m_s2 << "]"; + return strm.str(); } void PdxTypes7::toData(PdxWriter &pw) const { @@ -521,12 +529,12 @@ bool PdxTypes8::equals(std::shared_ptr obj) { return false; } std::string PdxTypes8::toString() const { - char idbuf[4096]; - sprintf( - idbuf, - "PdxTypes8:[m_i1=%d] [m_i2=%d] [m_i3=%d] [m_i4=%d] [m_s1=%s] [m_s2=%s]", - m_i1, m_i2, m_i3, m_i4, m_s1.c_str(), m_s2.c_str()); - return idbuf; + std::stringstream strm; + + strm << "PdxTypes8:[m_i1 = " << m_i1 << " ][m_i2 = " << m_i2 + << "][m_i3 = " << m_i3 << "][m_i4 = " << m_i4 << "]" + << "[m_s1 = " << m_s1 << "][m_s2 = " << m_s2 << "]"; + return strm.str(); } void PdxTypes8::toData(PdxWriter &pw) const { @@ -584,10 +592,12 @@ bool PdxTypes9::equals(std::shared_ptr obj) { return false; } std::string PdxTypes9::toString() const { - char idbuf[4096]; - sprintf(idbuf, "PdxTypes9:[m_s1=%s] [m_s2=%s] [m_s3=%s] [m_s4=%s] [m_s5=%s] ", - m_s1.c_str(), m_s2.c_str(), m_s3.c_str(), m_s4.c_str(), m_s5.c_str()); - return idbuf; + std::stringstream strm; + + strm << "PdxTypes9:[m_s1 = " << m_s1 << " ][m_s2 = " << m_s2 + << "][m_s3 = " << m_s3 << "][m_s4 = " << m_s4 << "]" + << "[m_s5 = " << m_s5 << "]"; + return strm.str(); } void PdxTypes9::toData(PdxWriter &pw) const { @@ -641,10 +651,12 @@ bool PdxTypes10::equals(std::shared_ptr obj) { return false; } std::string PdxTypes10::toString() const { - char idbuf[4096]; - sprintf(idbuf, "PdxTypes9:[m_s1=%s] [m_s2=%s] [m_s3=%s] [m_s4=%s] [m_s5=%s] ", - m_s1.c_str(), m_s2.c_str(), m_s3.c_str(), m_s4.c_str(), m_s5.c_str()); - return idbuf; + std::stringstream strm; + + strm << "PdxTypes10:[m_s1 = " << m_s1 << " ][m_s2 = " << m_s2 + << "][m_s3 = " << m_s3 << "][m_s4 = " << m_s4 << "]" + << "[m_s5 = " << m_s5 << "]"; + return strm.str(); } void PdxTypes10::toData(PdxWriter &pw) const { @@ -714,12 +726,12 @@ bool NestedPdx::equals(std::shared_ptr obj) { return false; } std::string NestedPdx::toString() const { - char idbuf[4096]; - sprintf( - idbuf, - "NestedPdx:[m_i1=%d] [m_i2=%d] [m_i3=%d] [m_i4=%d] [m_s1=%s] [m_s2=%s]", - m_i1, m_i2, m_i3, m_i4, m_s1.c_str(), m_s2.c_str()); - return idbuf; + std::stringstream strm; + + strm << "NestedPdx:[m_i1 = " << m_i1 << " ][m_i2 = " << m_i2 + << "][m_i3 = " << m_i3 << "][m_i4 = " << m_i4 << "]" + << "[m_s1 = " << m_s1 << "][m_s2 = " << m_s2 << "]"; + return strm.str(); } void NestedPdx::toData(PdxWriter &pw) const { @@ -795,12 +807,12 @@ bool MixedVersionNestedPdx::equals(std::shared_ptr obj) { return false; } std::string MixedVersionNestedPdx::toString() const { - char idbuf[4096]; - sprintf(idbuf, - "MixedVersionNestedPdx:[m_i1=%d] [m_i2=%d] [m_i3=%d] [m_i4=%d] " - "[m_s1=%s] [m_s2=%s]", - m_i1, m_i2, m_i3, m_i4, m_s1.c_str(), m_s2.c_str()); - return idbuf; + std::stringstream strm; + + strm << "MixedVersionNestedPdx:[m_i1 = " << m_i1 << " ][m_i2 = " << m_i2 + << "][m_i3 = " << m_i3 << "][m_i4 = " << m_i4 << "]" + << "[m_s1 = " << m_s1 << "][m_s2 = " << m_s2 << "]"; + return strm.str(); } void MixedVersionNestedPdx::toData(PdxWriter &pw) const { @@ -865,12 +877,12 @@ bool PdxInsideIGeodeSerializable::equals(std::shared_ptr obj) { return false; } std::string PdxInsideIGeodeSerializable::toString() const { - char idbuf[4096]; - sprintf(idbuf, - "PdxInsideIGeodeSerializable:[m_i1=%d] [m_i2=%d] [m_i3=%d] [m_i4=%d] " - "[m_s1=%s] [m_s2=%s]", - m_i1, m_i2, m_i3, m_i4, m_s1.c_str(), m_s2.c_str()); - return idbuf; + std::stringstream strm; + + strm << "PdxInsideIGeodeSerializable:[m_i1 = " << m_i1 << " ][m_i2 = " << m_i2 + << "][m_i3 = " << m_i3 << "][m_i4 = " << m_i4 << "]" + << "[m_s1 = " << m_s1 << "][m_s2 = " << m_s2 << "]"; + return strm.str(); } void PdxInsideIGeodeSerializable::toData(DataOutput &output) const {