diff options
author | janx@chromium.org <janx@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-19 21:46:57 +0000 |
---|---|---|
committer | janx@chromium.org <janx@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-19 21:46:57 +0000 |
commit | 5ec696b726e034bfeb3293def9e15b9cebea9760 (patch) | |
tree | 74b343f349f8b2392dc77cadb095aa4dbb864cbf /content/browser/speech/google_streaming_remote_engine_unittest.cc | |
parent | 8ab77e8332c0d0ee218ccac3980d507e55c6a6a1 (diff) | |
download | chromium_src-5ec696b726e034bfeb3293def9e15b9cebea9760.zip chromium_src-5ec696b726e034bfeb3293def9e15b9cebea9760.tar.gz chromium_src-5ec696b726e034bfeb3293def9e15b9cebea9760.tar.bz2 |
Refactor GoogleStreamingRemoteEngine's unit tests to use HostToNet32.
The GoogleStreamingRemoteEngine unit tests were reimplementing a 32 bit
byte swapping method to communicate big endian values over the network.
This makes them use the common base::HostToNet32 function instead.
Review URL: https://chromiumcodereview.appspot.com/23483050
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@224213 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/speech/google_streaming_remote_engine_unittest.cc')
-rw-r--r-- | content/browser/speech/google_streaming_remote_engine_unittest.cc | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/content/browser/speech/google_streaming_remote_engine_unittest.cc b/content/browser/speech/google_streaming_remote_engine_unittest.cc index 08a3df7c..3972506 100644 --- a/content/browser/speech/google_streaming_remote_engine_unittest.cc +++ b/content/browser/speech/google_streaming_remote_engine_unittest.cc @@ -6,7 +6,9 @@ #include "base/memory/scoped_ptr.h" #include "base/message_loop/message_loop.h" +#include "base/safe_numerics.h" #include "base/strings/utf_string_conversions.h" +#include "base/sys_byteorder.h" #include "content/browser/speech/audio_buffer.h" #include "content/browser/speech/google_streaming_remote_engine.h" #include "content/browser/speech/proto/google_streaming_api.pb.h" @@ -17,6 +19,8 @@ #include "net/url_request/url_request_status.h" #include "testing/gtest/include/gtest/gtest.h" +using base::HostToNet32; +using base::checked_numeric_cast; using net::URLRequestStatus; using net::TestURLFetcher; using net::TestURLFetcherFactory; @@ -62,7 +66,6 @@ class GoogleStreamingRemoteEngineTest : public SpeechRecognitionEngineDelegate, const SpeechRecognitionResults& b); static std::string SerializeProtobufResponse( const proto::SpeechRecognitionEvent& msg); - static std::string ToBigEndian32(uint32 value); TestURLFetcher* GetUpstreamFetcher(); TestURLFetcher* GetDownstreamFetcher(); @@ -487,17 +490,10 @@ std::string GoogleStreamingRemoteEngineTest::SerializeProtobufResponse( // Prepend 4 byte prefix length indication to the protobuf message as // envisaged by the google streaming recognition webservice protocol. - msg_string.insert(0, ToBigEndian32(msg_string.size())); - return msg_string; -} + uint32 prefix = HostToNet32(checked_numeric_cast<uint32>(msg_string.size())); + msg_string.insert(0, reinterpret_cast<char*>(&prefix), sizeof(prefix)); -std::string GoogleStreamingRemoteEngineTest::ToBigEndian32(uint32 value) { - char raw_data[4]; - raw_data[0] = static_cast<uint8>((value >> 24) & 0xFF); - raw_data[1] = static_cast<uint8>((value >> 16) & 0xFF); - raw_data[2] = static_cast<uint8>((value >> 8) & 0xFF); - raw_data[3] = static_cast<uint8>(value & 0xFF); - return std::string(raw_data, sizeof(raw_data)); + return msg_string; } } // namespace content |