From 5dedd0ee386c55d6dbafcdd53c0ad67ea0b2140e Mon Sep 17 00:00:00 2001 From: "henrik.lundin@webrtc.org" Date: Tue, 18 Oct 2011 05:45:08 +0000 Subject: [PATCH] Handling of white-space in DataLog::Combine The Combine method cannot handle white-space. Adding a comment to the header file saying this, and modifying the unittests. Also, adding a new unittest to test the method. Review URL: http://webrtc-codereview.appspot.com/217001 git-svn-id: http://webrtc.googlecode.com/svn/trunk@760 4adac7df-926f-26a2-2b94-8c16560cd09d --- src/system_wrappers/source/data_log.cc | 8 +++++--- src/system_wrappers/source/data_log_unittest.cc | 5 +++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/system_wrappers/source/data_log.cc b/src/system_wrappers/source/data_log.cc index c33f24c47c..af62018719 100644 --- a/src/system_wrappers/source/data_log.cc +++ b/src/system_wrappers/source/data_log.cc @@ -283,9 +283,11 @@ void DataLog::ReturnLog() { std::string DataLog::Combine(const std::string& table_name, int table_id) { std::stringstream ss; - std::string combined_id; - ss << table_name << "_" << table_id; - ss >> combined_id; + std::string combined_id = table_name; + std::string number_suffix; + ss << "_" << table_id; + ss >> number_suffix; + combined_id += number_suffix; std::transform(combined_id.begin(), combined_id.end(), combined_id.begin(), ::tolower); return combined_id; diff --git a/src/system_wrappers/source/data_log_unittest.cc b/src/system_wrappers/source/data_log_unittest.cc index d588947f04..c64ed94d6c 100644 --- a/src/system_wrappers/source/data_log_unittest.cc +++ b/src/system_wrappers/source/data_log_unittest.cc @@ -121,6 +121,11 @@ TEST(TestDataLog, CreateReturnTest) { ASSERT_LT(DataLog::AddTable(DataLog::Combine("table failure", 1)), 0); } +TEST(TestDataLog, VerifyCombineMethod) { + EXPECT_EQ(std::string("a proper table_1"), + DataLog::Combine("a proper table", 1)); +} + TEST(TestDataLog, VerifySingleTable) { DataLog::CreateLog(); DataLog::AddTable(DataLog::Combine("table", 1));