diff options
author | ted.mielczarek@gmail.com <ted.mielczarek@gmail.com> | 2015-08-13 16:38:19 +0000 |
---|---|---|
committer | ted.mielczarek@gmail.com <ted.mielczarek@gmail.com> | 2015-08-13 16:38:19 +0000 |
commit | 591ba326b35cf272d7ecbdf43111be5db9125871 (patch) | |
tree | 5b3a5b390481c6bcd8d697d6eff7a7a17ffbc6df /src | |
parent | Fix format specifier in proc maps to support 32-bit architectures. (diff) | |
download | breakpad-591ba326b35cf272d7ecbdf43111be5db9125871.tar.xz |
Remove some old unused code, add a missing include
R=lei at https://codereview.chromium.org/1211963002
git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@1484 4c0a9323-5329-0410-9bdc-e9ce6186880e
Diffstat (limited to 'src')
-rw-r--r-- | src/google_breakpad/processor/minidump.h | 2 | ||||
-rw-r--r-- | src/processor/binarystream.cc | 124 | ||||
-rw-r--r-- | src/processor/binarystream.h | 92 | ||||
-rw-r--r-- | src/processor/binarystream_unittest.cc | 432 |
4 files changed, 2 insertions, 648 deletions
diff --git a/src/google_breakpad/processor/minidump.h b/src/google_breakpad/processor/minidump.h index 968cd8de..ce1af851 100644 --- a/src/google_breakpad/processor/minidump.h +++ b/src/google_breakpad/processor/minidump.h @@ -79,6 +79,8 @@ #ifndef GOOGLE_BREAKPAD_PROCESSOR_MINIDUMP_H__ #define GOOGLE_BREAKPAD_PROCESSOR_MINIDUMP_H__ +#include <stdint.h> + #ifndef _WIN32 #include <unistd.h> #endif diff --git a/src/processor/binarystream.cc b/src/processor/binarystream.cc index bf92225b..e69de29b 100644 --- a/src/processor/binarystream.cc +++ b/src/processor/binarystream.cc @@ -1,124 +0,0 @@ -// Copyright (c) 2010, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#include <arpa/inet.h> -#include <limits.h> - -#include <string> -#include <vector> - -#include "common/using_std_string.h" -#include "processor/binarystream.h" - -namespace google_breakpad { -using std::vector; - -binarystream &binarystream::operator>>(string &str) { - uint16_t length; - *this >> length; - if (eof()) - return *this; - if (length == 0) { - str.clear(); - return *this; - } - vector<char> buffer(length); - stream_.read(&buffer[0], length); - if (!eof()) - str.assign(&buffer[0], length); - return *this; -} - -binarystream &binarystream::operator>>(uint8_t &u8) { - stream_.read((char *)&u8, 1); - return *this; -} - -binarystream &binarystream::operator>>(uint16_t &u16) { - uint16_t temp; - stream_.read((char *)&temp, 2); - if (!eof()) - u16 = ntohs(temp); - return *this; -} - -binarystream &binarystream::operator>>(uint32_t &u32) { - uint32_t temp; - stream_.read((char *)&temp, 4); - if (!eof()) - u32 = ntohl(temp); - return *this; -} - -binarystream &binarystream::operator>>(uint64_t &u64) { - uint32_t lower, upper; - *this >> lower >> upper; - if (!eof()) - u64 = static_cast<uint64_t>(lower) | (static_cast<uint64_t>(upper) << 32); - return *this; -} - -binarystream &binarystream::operator<<(const string &str) { - if (str.length() > USHRT_MAX) { - // truncate to 16-bit length - *this << static_cast<uint16_t>(USHRT_MAX); - stream_.write(str.c_str(), USHRT_MAX); - } else { - *this << (uint16_t)(str.length() & 0xFFFF); - stream_.write(str.c_str(), str.length()); - } - return *this; -} - -binarystream &binarystream::operator<<(uint8_t u8) { - stream_.write((const char*)&u8, 1); - return *this; -} - -binarystream &binarystream::operator<<(uint16_t u16) { - u16 = htons(u16); - stream_.write((const char*)&u16, 2); - return *this; -} - -binarystream &binarystream::operator<<(uint32_t u32) { - u32 = htonl(u32); - stream_.write((const char*)&u32, 4); - return *this; -} - -binarystream &binarystream::operator<<(uint64_t u64) { - // write 64-bit ints as two 32-bit ints, so we can byte-swap them easily - uint32_t lower = static_cast<uint32_t>(u64 & 0xFFFFFFFF); - uint32_t upper = static_cast<uint32_t>(u64 >> 32); - *this << lower << upper; - return *this; -} - -} // namespace google_breakpad diff --git a/src/processor/binarystream.h b/src/processor/binarystream.h index 172e09b9..e69de29b 100644 --- a/src/processor/binarystream.h +++ b/src/processor/binarystream.h @@ -1,92 +0,0 @@ -// Copyright (c) 2010, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// binarystream implements part of the std::iostream interface as a -// wrapper around std::stringstream to allow reading and writing strings -// and integers of known size. - -#ifndef GOOGLE_BREAKPAD_PROCESSOR_BINARYSTREAM_H_ -#define GOOGLE_BREAKPAD_PROCESSOR_BINARYSTREAM_H_ - -#include <sstream> -#include <string> - -#include "common/using_std_string.h" -#include "google_breakpad/common/breakpad_types.h" - -namespace google_breakpad { -using std::ios_base; -using std::ios; - -class binarystream { - public: - explicit binarystream(ios_base::openmode which = ios_base::out|ios_base::in) - : stream_(which) {} - explicit binarystream(const string &str, - ios_base::openmode which = ios_base::out|ios_base::in) - : stream_(str, which) {} - explicit binarystream(const char *str, size_t size, - ios_base::openmode which = ios_base::out|ios_base::in) - : stream_(string(str, size), which) {} - - binarystream &operator>>(string &str); - binarystream &operator>>(uint8_t &u8); - binarystream &operator>>(uint16_t &u16); - binarystream &operator>>(uint32_t &u32); - binarystream &operator>>(uint64_t &u64); - - // Note: strings are truncated at 65535 characters - binarystream &operator<<(const string &str); - binarystream &operator<<(uint8_t u8); - binarystream &operator<<(uint16_t u16); - binarystream &operator<<(uint32_t u32); - binarystream &operator<<(uint64_t u64); - - // Forward a few methods directly from the stream object - bool eof() const { return stream_.eof(); } - void clear() { stream_.clear(); } - string str() const { return stream_.str(); } - void str(const string &s) { stream_.str(s); } - - // Seek both read and write pointers to the beginning of the stream. - void rewind() { - stream_.seekg (0, ios::beg); - stream_.seekp (0, ios::beg); - // This is to clear all the error flags, since only the EOF flag is cleared - // with seekg(). - stream_.clear(); - } - - private: - std::stringstream stream_; -}; - -} // namespace google_breakpad - -#endif // GOOGLE_BREAKPAD_PROCESSOR_BINARYSTREAM_H_ diff --git a/src/processor/binarystream_unittest.cc b/src/processor/binarystream_unittest.cc index bf020edb..e69de29b 100644 --- a/src/processor/binarystream_unittest.cc +++ b/src/processor/binarystream_unittest.cc @@ -1,432 +0,0 @@ -// Copyright (c) 2010, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#include <ios> -#include <string> -#include <vector> - -#include "breakpad_googletest_includes.h" -#include "common/using_std_string.h" -#include "processor/binarystream.h" - -namespace { -using std::ios_base; -using std::vector; -using google_breakpad::binarystream; - - -class BinaryStreamBasicTest : public ::testing::Test { -protected: - binarystream stream; -}; - -TEST_F(BinaryStreamBasicTest, ReadU8) { - uint8_t u8 = 0; - ASSERT_FALSE(stream.eof()); - stream >> u8; - ASSERT_TRUE(stream.eof()); - EXPECT_EQ(0U, u8); - stream.rewind(); - stream.clear(); - stream << (uint8_t)1; - ASSERT_FALSE(stream.eof()); - stream >> u8; - EXPECT_EQ(1, u8); - EXPECT_FALSE(stream.eof()); -} - -TEST_F(BinaryStreamBasicTest, ReadU16) { - uint16_t u16 = 0; - ASSERT_FALSE(stream.eof()); - stream >> u16; - ASSERT_TRUE(stream.eof()); - EXPECT_EQ(0U, u16); - stream.rewind(); - stream.clear(); - stream << (uint16_t)1; - ASSERT_FALSE(stream.eof()); - stream >> u16; - EXPECT_EQ(1, u16); - EXPECT_FALSE(stream.eof()); -} - -TEST_F(BinaryStreamBasicTest, ReadU32) { - uint32_t u32 = 0; - ASSERT_FALSE(stream.eof()); - stream >> u32; - ASSERT_TRUE(stream.eof()); - EXPECT_EQ(0U, u32); - stream.rewind(); - stream.clear(); - stream << (uint32_t)1; - ASSERT_FALSE(stream.eof()); - stream >> u32; - EXPECT_EQ(1U, u32); - EXPECT_FALSE(stream.eof()); -} - -TEST_F(BinaryStreamBasicTest, ReadU64) { - uint64_t u64 = 0; - ASSERT_FALSE(stream.eof()); - stream >> u64; - ASSERT_TRUE(stream.eof()); - EXPECT_EQ(0U, u64); - stream.rewind(); - stream.clear(); - stream << (uint64_t)1; - ASSERT_FALSE(stream.eof()); - stream >> u64; - EXPECT_EQ(1U, u64); - EXPECT_FALSE(stream.eof()); -} - -TEST_F(BinaryStreamBasicTest, ReadString) { - string s(""); - ASSERT_FALSE(stream.eof()); - stream >> s; - ASSERT_TRUE(stream.eof()); - EXPECT_EQ("", s); - // write an empty string to the stream, read it back - s = "abcd"; - stream.rewind(); - stream.clear(); - stream << string(""); - stream >> s; - EXPECT_EQ("", s); - EXPECT_FALSE(stream.eof()); - stream.rewind(); - stream.clear(); - stream << string("test"); - ASSERT_FALSE(stream.eof()); - stream >> s; - EXPECT_EQ("test", s); - EXPECT_FALSE(stream.eof()); -} - -TEST_F(BinaryStreamBasicTest, ReadEmptyString) { - string s("abc"); - stream << string(""); - stream >> s; - EXPECT_EQ("", s); -} - -TEST_F(BinaryStreamBasicTest, ReadMultiU8) { - const uint8_t ea = 0, eb = 100, ec = 200, ed = 0xFF; - uint8_t a, b, c, d, e; - stream << ea << eb << ec << ed; - stream >> a >> b >> c >> d; - ASSERT_FALSE(stream.eof()); - EXPECT_EQ(ea, a); - EXPECT_EQ(eb, b); - EXPECT_EQ(ec, c); - EXPECT_EQ(ed, d); - ASSERT_FALSE(stream.eof()); - e = 0; - stream >> e; - EXPECT_EQ(0U, e); - ASSERT_TRUE(stream.eof()); - // try reading all at once, including one past eof - stream.rewind(); - stream.clear(); - ASSERT_FALSE(stream.eof()); - a = b = c = d = e = 0; - stream << ea << eb << ec << ed; - stream >> a >> b >> c >> d >> e; - EXPECT_EQ(ea, a); - EXPECT_EQ(eb, b); - EXPECT_EQ(ec, c); - EXPECT_EQ(ed, d); - EXPECT_EQ(0U, e); - EXPECT_TRUE(stream.eof()); -} - -TEST_F(BinaryStreamBasicTest, ReadMultiU16) { - const uint16_t ea = 0, eb = 0x100, ec = 0x8000, ed = 0xFFFF; - uint16_t a, b, c, d, e; - stream << ea << eb << ec << ed; - stream >> a >> b >> c >> d; - ASSERT_FALSE(stream.eof()); - EXPECT_EQ(ea, a); - EXPECT_EQ(eb, b); - EXPECT_EQ(ec, c); - EXPECT_EQ(ed, d); - ASSERT_FALSE(stream.eof()); - e = 0; - stream >> e; - EXPECT_EQ(0U, e); - EXPECT_TRUE(stream.eof()); - // try reading all at once, including one past eof - stream.rewind(); - stream.clear(); - ASSERT_FALSE(stream.eof()); - a = b = c = d = e = 0; - stream << ea << eb << ec << ed; - stream >> a >> b >> c >> d >> e; - EXPECT_EQ(ea, a); - EXPECT_EQ(eb, b); - EXPECT_EQ(ec, c); - EXPECT_EQ(ed, d); - EXPECT_EQ(0U, e); - EXPECT_TRUE(stream.eof()); -} - -TEST_F(BinaryStreamBasicTest, ReadMultiU32) { - const uint32_t ea = 0, eb = 0x10000, ec = 0x8000000, ed = 0xFFFFFFFF; - uint32_t a, b, c, d, e; - stream << ea << eb << ec << ed; - stream >> a >> b >> c >> d; - ASSERT_FALSE(stream.eof()); - EXPECT_EQ(ea, a); - EXPECT_EQ(eb, b); - EXPECT_EQ(ec, c); - EXPECT_EQ(ed, d); - ASSERT_FALSE(stream.eof()); - e = 0; - stream >> e; - EXPECT_EQ(0U, e); - EXPECT_TRUE(stream.eof()); - // try reading all at once, including one past eof - stream.rewind(); - stream.clear(); - ASSERT_FALSE(stream.eof()); - a = b = c = d = e = 0; - stream << ea << eb << ec << ed; - stream >> a >> b >> c >> d >> e; - EXPECT_EQ(ea, a); - EXPECT_EQ(eb, b); - EXPECT_EQ(ec, c); - EXPECT_EQ(ed, d); - EXPECT_EQ(0U, e); - EXPECT_TRUE(stream.eof()); -} - -TEST_F(BinaryStreamBasicTest, ReadMultiU64) { - const uint64_t ea = 0, eb = 0x10000, ec = 0x100000000ULL, - ed = 0xFFFFFFFFFFFFFFFFULL; - uint64_t a, b, c, d, e; - stream << ea << eb << ec << ed; - stream >> a >> b >> c >> d; - ASSERT_FALSE(stream.eof()); - EXPECT_EQ(ea, a); - EXPECT_EQ(eb, b); - EXPECT_EQ(ec, c); - EXPECT_EQ(ed, d); - ASSERT_FALSE(stream.eof()); - e = 0; - stream >> e; - EXPECT_EQ(0U, e); - EXPECT_TRUE(stream.eof()); - // try reading all at once, including one past eof - stream.rewind(); - stream.clear(); - ASSERT_FALSE(stream.eof()); - a = b = c = d = e = 0; - stream << ea << eb << ec << ed; - stream >> a >> b >> c >> d >> e; - EXPECT_EQ(ea, a); - EXPECT_EQ(eb, b); - EXPECT_EQ(ec, c); - EXPECT_EQ(ed, d); - EXPECT_EQ(0U, e); - EXPECT_TRUE(stream.eof()); -} - -TEST_F(BinaryStreamBasicTest, ReadMixed) { - const uint8_t e8 = 0x10; - const uint16_t e16 = 0x2020; - const uint32_t e32 = 0x30303030; - const uint64_t e64 = 0x4040404040404040ULL; - const string es = "test"; - uint8_t u8 = 0; - uint16_t u16 = 0; - uint32_t u32 = 0; - uint64_t u64 = 0; - string s("test"); - stream << e8 << e16 << e32 << e64 << es; - stream >> u8 >> u16 >> u32 >> u64 >> s; - EXPECT_FALSE(stream.eof()); - EXPECT_EQ(e8, u8); - EXPECT_EQ(e16, u16); - EXPECT_EQ(e32, u32); - EXPECT_EQ(e64, u64); - EXPECT_EQ(es, s); -} - -TEST_F(BinaryStreamBasicTest, ReadStringMissing) { - // ensure that reading a string where only the length is present fails - uint16_t u16 = 8; - stream << u16; - stream.rewind(); - string s(""); - stream >> s; - EXPECT_EQ("", s); - EXPECT_TRUE(stream.eof()); -} - -TEST_F(BinaryStreamBasicTest, ReadStringTruncated) { - // ensure that reading a string where not all the data is present fails - uint16_t u16 = 8; - stream << u16; - stream << (uint8_t)'t' << (uint8_t)'e' << (uint8_t)'s' << (uint8_t)'t'; - stream.rewind(); - string s(""); - stream >> s; - EXPECT_EQ("", s); - EXPECT_TRUE(stream.eof()); -} - -TEST_F(BinaryStreamBasicTest, StreamByteLength) { - // Test that the stream buffer contains the right amount of data - stream << (uint8_t)0 << (uint16_t)1 << (uint32_t)2 << (uint64_t)3 - << string("test"); - string s = stream.str(); - EXPECT_EQ(21U, s.length()); -} - -TEST_F(BinaryStreamBasicTest, AppendStreamResultsByteLength) { - // Test that appending the str() results from two streams - // gives the right byte length - binarystream stream2; - stream << (uint8_t)0 << (uint16_t)1; - stream2 << (uint32_t)0 << (uint64_t)2 - << string("test"); - string s = stream.str(); - string s2 = stream2.str(); - s.append(s2); - EXPECT_EQ(21U, s.length()); -} - -TEST_F(BinaryStreamBasicTest, StreamSetStr) { - const string es("test"); - stream << es; - binarystream stream2; - stream2.str(stream.str()); - string s; - stream2 >> s; - EXPECT_FALSE(stream2.eof()); - EXPECT_EQ("test", s); - s = ""; - stream2.str(stream.str()); - stream2.rewind(); - stream2 >> s; - EXPECT_FALSE(stream2.eof()); - EXPECT_EQ("test", s); -} - -class BinaryStreamU8Test : public ::testing::Test { -protected: - binarystream stream; - - void SetUp() { - stream << (uint8_t)1; - } -}; - -TEST_F(BinaryStreamU8Test, ReadU16) { - uint16_t u16 = 0; - ASSERT_FALSE(stream.eof()); - stream >> u16; - ASSERT_TRUE(stream.eof()); - EXPECT_EQ(0U, u16); -} - -TEST_F(BinaryStreamU8Test, ReadU32) { - uint32_t u32 = 0; - ASSERT_FALSE(stream.eof()); - stream >> u32; - ASSERT_TRUE(stream.eof()); - EXPECT_EQ(0U, u32); -} - -TEST_F(BinaryStreamU8Test, ReadU64) { - uint64_t u64 = 0; - ASSERT_FALSE(stream.eof()); - stream >> u64; - ASSERT_TRUE(stream.eof()); - EXPECT_EQ(0U, u64); -} - -TEST_F(BinaryStreamU8Test, ReadString) { - string s(""); - ASSERT_FALSE(stream.eof()); - stream >> s; - ASSERT_TRUE(stream.eof()); - EXPECT_EQ("", s); -} - - -TEST(BinaryStreamTest, InitWithData) { - const char *data = "abcd"; - binarystream stream(data); - uint8_t a, b, c, d; - stream >> a >> b >> c >> d; - ASSERT_FALSE(stream.eof()); - EXPECT_EQ('a', a); - EXPECT_EQ('b', b); - EXPECT_EQ('c', c); - EXPECT_EQ('d', d); -} - -TEST(BinaryStreamTest, InitWithDataLeadingNull) { - const char *data = "\0abcd"; - binarystream stream(data, 5); - uint8_t z, a, b, c, d; - stream >> z >> a >> b >> c >> d; - ASSERT_FALSE(stream.eof()); - EXPECT_EQ(0U, z); - EXPECT_EQ('a', a); - EXPECT_EQ('b', b); - EXPECT_EQ('c', c); - EXPECT_EQ('d', d); -} - -TEST(BinaryStreamTest, InitWithDataVector) { - vector<char> data; - data.push_back('a'); - data.push_back('b'); - data.push_back('c'); - data.push_back('d'); - data.push_back('e'); - data.resize(4); - binarystream stream(&data[0], data.size()); - uint8_t a, b, c, d; - stream >> a >> b >> c >> d; - ASSERT_FALSE(stream.eof()); - EXPECT_EQ('a', a); - EXPECT_EQ('b', b); - EXPECT_EQ('c', c); - EXPECT_EQ('d', d); -} - -} // namespace - -int main(int argc, char *argv[]) { - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} |