コード例 #1
0
Tstring & TestMeanSql::gen_value(GenCtx & pCtx, Tstring & pResult)
{
	size_t i;
	Tstring lV;
	std::ostringstream lOs;
	// Either generate a good value...
	if (pCtx.doGood())
	{
		int const lType = MVTRand::getRange(0, 15);
		switch (lType)
		{
			// Note: We don't generate collections here, because it's not (yet) a recursive structure, and here we're supposed to be 'good'.
			case 0: default: MVTRand::getString(lV, 5, 15, true, true); lOs << "'" << lV << "'"; break;
			case 1: lOs << MVTRand::getRange(0, std::numeric_limits<int>::max()); if (MVTRand::getBool()) lOs << "U"; break;
			case 2: lOs << MVTRand::getFloatRange(0.0, std::numeric_limits<float>::max()) << "f"; break;
			case 3: lOs << MVTRand::getDoubleRange(0.0, std::numeric_limits<double>::max()); break;
			case 4: lOs << (MVTRand::getBool() ? "TRUE" : "FALSE"); break;
			case 5: MVTRand::getString(lV, 5, 15, true, true); lOs << "U'http://" << lV << "'"; break;
			case 6: MVTRand::getString(lV, 5, 15, true, true); lOs << "X'"; for (i = 0; i < lV.length(); i++) { lOs << std::hex << std::setw(2) << std::setfill('0') << (int)lV.at(i); } lOs << std::dec << "'"; break;
			case 7: lOs << "INTERVAL'" << MVTRand::getRange(0, std::numeric_limits<int>::max()) << ":" << std::setw(2) << std::setfill('0') << MVTRand::getRange(0, 59) << ":" << MVTRand::getRange(0, 59) << ".12345'"; break;
			case 8: lOs << "TIMESTAMP'" << std::setw(4) << std::setfill('0') << MVTRand::getRange(0, 2200) << "-" << std::setw(2) << MVTRand::getRange(1, 12) << "-" << MVTRand::getRange(1, 31) << " " << MVTRand::getRange(0, 23) << ":" << MVTRand::getRange(0, 59) << ":" << MVTRand::getRange(0, 59); break;
			case 9: lOs << "@" << std::hex << MVTRand::getRange(0x50001, 0x500001) << std::dec; break;
			case 10: lOs << "@" << std::hex << MVTRand::getRange(0x50001, 0x500001) << "." << randomProperty() << std::dec; break;
			case 11: lOs << "@" << std::hex << MVTRand::getRange(0x50001, 0x500001) << "." << randomProperty() << std::dec << "["; if (MVTRand::getBool()) lOs << ":FIRST"; else lOs << MVTRand::getRange(0, 100); lOs << "]"; break;
			case 12: lOs << gen_SELECT(pCtx, lV); break; // Not necessarily 'good' currently, but who cares...
			case 13: lOs << "${" << gen_SELECT(pCtx, lV) << "}"; break;
		}
	}
	// Or generate a bad value...
	else
	{
		int const lType = MVTRand::getRange(0, 18);
		switch (lType)
		{
			// Note: We do generate collections here, because here all is permitted :).
			case 0: default:
				#if TEST_ISSUE_DOUBLE_QUOTED_VAL
					MVTRand::getString(lV, 5, 15, true, true); lOs << "\"" << lV << "\""; break;
				#endif
			case 1: lOs << MVTRand::getRange(0, std::numeric_limits<int>::max()) << "bla"; break;
			case 2: lOs << MVTRand::getRange(0, std::numeric_limits<int>::max()) << MVTRand::getRange(0, std::numeric_limits<int>::max()) << MVTRand::getRange(0, std::numeric_limits<int>::max()); break;
			case 3: lOs << MVTRand::getFloatRange(0.0, std::numeric_limits<float>::max()) << "fbla"; break;
			case 4: lOs << MVTRand::getDoubleRange(0.0, std::numeric_limits<double>::max()) << "bla"; break;
			case 5: lOs << MVTRand::getDoubleRange(0.0, std::numeric_limits<double>::max()) << MVTRand::getDoubleRange(0.0, std::numeric_limits<double>::max()); break;
			case 6: lOs << randomKeyword(); break;
			case 7: lOs << gen_collection(pCtx, lV); break;
			case 8: lOs << "MAYBE"; break;
			case 9: MVTRand::getString(lV, 5, 15, true, true); lOs << "U'http://" << lV << (pCtx.doGood() ? "'" : ""); break;
			case 10: MVTRand::getString(lV, 5, 15, true, true); lOs << "X'"; for (i = 0; i < lV.length(); i++) { lOs << std::hex << (int)lV.at(i); } lOs << std::dec << (pCtx.doGood() ? "'" : ""); break;
			case 11: lOs << "INTERVAL'"; if (pCtx.doGood()) lOs << MVTRand::getRange(0, std::numeric_limits<int>::max()); else lOs << MVTRand::getString(lV, 5, 15, false, true); lOs << ":" << MVTRand::getRange(0, pCtx.doGood() ? 59 : 1000) << (pCtx.doGood() ? ":" : ";") << MVTRand::getRange(0, pCtx.doGood() ? 59 : 1000) << ".12345'"; break;
			case 12: lOs << "TIMESTAMP'" << MVTRand::getRange(0, 10000) << "-" << MVTRand::getRange(1, pCtx.doGood() ? 12 : 1000) << "-" << MVTRand::getRange(1, pCtx.doGood() ? 31 : 1000) << " " << MVTRand::getRange(0, pCtx.doGood() ? 23 : 1000) << ":" << MVTRand::getRange(0, 59) << ":" << MVTRand::getRange(0, 59); break;
			case 13: lOs << "@"; if (pCtx.doGood()) lOs << std::hex << MVTRand::getRange(0x50001, 0x500001) << std::dec; else lOs << MVTRand::getString(lV, 5, 15, false, true); break;
			case 14: lOs << "@" << std::hex << MVTRand::getRange(0x50001, 0x500001) << "." << (pCtx.doGood() ? randomProperty() : randomWord()) << std::dec; break;
			case 15: lOs << "@" << std::hex << MVTRand::getRange(0x50001, 0x500001) << "." << randomProperty() << std::dec << "["; if (pCtx.doGood()) lOs << MVTRand::getRange(0, 100); else lOs << randomWord(); lOs << "]"; break;
			case 16: lOs << "${" << gen_whatever(pCtx, lV) << "}"; break;
		}
	}
	return pResult = lOs.str();
}
コード例 #2
0
ファイル: in_openmpt.cpp プロジェクト: Sappharad/modizer
static inline Tstring StringReplace( Tstring str, const Tstring2 & oldStr_, const Tstring3 & newStr_ ) {
	std::size_t pos = 0;
	const Tstring oldStr = oldStr_;
	const Tstring newStr = newStr_;
	while ( ( pos = str.find( oldStr, pos ) ) != Tstring::npos ) {
		str.replace( pos, oldStr.length(), newStr );
		pos += newStr.length();
	}
	return str;
}
コード例 #3
0
ファイル: GPacket.cpp プロジェクト: danieljiang0415/gh
VOID   CGPacket::Replace(Tstring& strKey, Tstring& strData)
{
	DWORD dwStrKeyLen, dwStrDataLen, dwHexKeySize, dwHexDataSize;
	LPBYTE lpbKeyBuf, lpbDataBuf;

	dwStrKeyLen = strKey.length();
	lpbKeyBuf = new BYTE[dwStrKeyLen];
	memset(lpbKeyBuf, 0, dwStrKeyLen);
	dwHexKeySize = Utility::StringLib::Tstring2Hex(strKey.c_str(), lpbKeyBuf);

	dwStrDataLen = strKey.length();
	lpbDataBuf = new BYTE[dwStrDataLen];
	memset(lpbDataBuf, 0, dwStrDataLen);
	dwHexDataSize = Utility::StringLib::Tstring2Hex(strData.c_str(), lpbDataBuf);

	Replace(lpbKeyBuf, dwHexKeySize, lpbDataBuf, dwHexDataSize);

	delete[]lpbKeyBuf;
	delete[]lpbDataBuf;

}
コード例 #4
0
		virtual size_t read(void * buf, size_t maxLength) 
		{
			size_t const lLength = MvStoreSerialization::PrimitivesOutDbg::mymin(mLength - mSeek, maxLength); 

			if ( lLength == 0 ) return 0 ;

			for (size_t i = 0; i < lLength; i++) 
				((char*)buf)[i] = getCharAt(mSeek + i, mStartChar);

			// Algorithm below assumes read is only called once (it could be fixed
			// if this is found not to be the case)

			if ( rndm < maxLength ) 
			{
				//insert my search string at the offset rndm in the stream
				//(i.e. 0 for begining).
				Tstring tmpString = srchString;

				tmpString.insert(0," ");
				tmpString += " " ;

				// If this fails we are about to do a buffer overrun because we need to insert the
				// string too near the end of the buffer.  This is just a unlikely bug in the test
				assert( rndm + tmpString.length() < maxLength ) ; 

				// memcpy instread of string copy so that the string terminator isn't copied
				memcpy((char*)buf+rndm,tmpString.c_str(), tmpString.length());
			}
			else
			{	
				// Need to add it in a later call to read
				rndm -= maxLength ;
			}

			mSeek += lLength; // Position for the next read calls
			return lLength; 
		}
コード例 #5
0
ファイル: GPacket.cpp プロジェクト: danieljiang0415/gh
BOOL   CGPacket::Find(Tstring& strKey)
{
	DWORD dwStrKeyLen, dwKeyBufSize;
	LPBYTE lpbKeyBuf;

	dwStrKeyLen = strKey.length();
	lpbKeyBuf = new BYTE[dwStrKeyLen];
	memset(lpbKeyBuf, 0, dwStrKeyLen);
	dwKeyBufSize = Utility::StringLib::Tstring2Hex(strKey.c_str(), lpbKeyBuf);


	BOOL bRet = Find(lpbKeyBuf, dwKeyBufSize);
	delete[]lpbKeyBuf;
	return bRet;
}