Added stringToSizeType and its unittest #4601

This commit is contained in:
Jerry (Xinyu Hou) 2015-05-19 14:23:43 -07:00
parent c032091dd5
commit 2c74a7f5c1
5 changed files with 41 additions and 8 deletions

View File

@ -208,13 +208,22 @@ removeChar(String& subject, const char c)
} }
String String
intToString(size_t integer) sizeTypeToString(size_t n)
{ {
std::stringstream ss; std::stringstream ss;
ss << integer; ss << n;
return ss.str(); return ss.str();
} }
size_t
stringToSizeType(String string)
{
std::istringstream iss(string);
size_t value;
iss >> value;
return value;
}
// //
// CaselessCmp // CaselessCmp
// //

View File

@ -88,11 +88,17 @@ Remove all specific \c c in \c suject
*/ */
void removeChar(String& subject, const char c); void removeChar(String& subject, const char c);
//! Convert an integer to a string //! Convert a size type to a string
/*! /*!
Convert an \c integer to a string Convert an size type to a string
*/ */
String intToString(size_t integer); String sizeTypeToString(size_t n);
//! Convert a string to a size type
/*!
Convert an a \c string to an size type
*/
size_t stringToSizeType(String string);
//! Case-insensitive comparisons //! Case-insensitive comparisons
/*! /*!

View File

@ -54,7 +54,7 @@ StreamChunker::sendFile(
size_t size = (size_t)file.tellg(); size_t size = (size_t)file.tellg();
// send first message (file size) // send first message (file size)
String fileSize = synergy::string::intToString(size); String fileSize = synergy::string::sizeTypeToString(size);
FileChunk* sizeMessage = FileChunk::start(fileSize); FileChunk* sizeMessage = FileChunk::start(fileSize);
events->addEvent(Event(events->forIScreen().fileChunkSending(), eventTarget, sizeMessage)); events->addEvent(Event(events->forIScreen().fileChunkSending(), eventTarget, sizeMessage));
@ -109,7 +109,7 @@ StreamChunker::sendClipboard(
void* eventTarget) void* eventTarget)
{ {
// send first message (data size) // send first message (data size)
String dataSize = synergy::string::intToString(size); String dataSize = synergy::string::sizeTypeToString(size);
ClipboardChunk* sizeMessage = ClipboardChunk::start(id, sequence, dataSize); ClipboardChunk* sizeMessage = ClipboardChunk::start(id, sequence, dataSize);
events->addEvent(Event(events->forClientProxy().clipboardSending(), eventTarget, sizeMessage)); events->addEvent(Event(events->forClientProxy().clipboardSending(), eventTarget, sizeMessage));

View File

@ -415,7 +415,7 @@ void
NetworkTests::sendMockData(void* eventTarget) NetworkTests::sendMockData(void* eventTarget)
{ {
// send first message (file size) // send first message (file size)
String size = synergy::string::intToString(kMockDataSize); String size = synergy::string::sizeTypeToString(kMockDataSize);
FileChunk* sizeMessage = FileChunk::start(size); FileChunk* sizeMessage = FileChunk::start(size);
m_events.addEvent(Event(m_events.forIScreen().fileChunkSending(), eventTarget, sizeMessage)); m_events.addEvent(Event(m_events.forIScreen().fileChunkSending(), eventTarget, sizeMessage));

View File

@ -82,3 +82,21 @@ TEST(StringTests, removeChar)
EXPECT_EQ("fbar", subject); EXPECT_EQ("fbar", subject);
} }
TEST(StringTests, intToString)
{
size_t value = 123;
String number = string::sizeTypeToString(value);
EXPECT_EQ("123", number);
}
TEST(StringTests, stringToUint)
{
String number = "123";
size_t value = string::stringToSizeType(number);
EXPECT_EQ(123, value);
}