Make the Context parameter optional in BodyStream public Read methods. (#2046)
* Make the Context parameter optional in BodyStream public Read methods. * Add some basic unit tests. * Fix end of line.
This commit is contained in:
parent
d638d1ff3d
commit
93bc8c4218
@ -84,7 +84,10 @@ namespace Azure { namespace Core { namespace IO {
|
||||
*
|
||||
* @return Number of bytes read.
|
||||
*/
|
||||
int64_t Read(uint8_t* buffer, int64_t count, Azure::Core::Context const& context)
|
||||
int64_t Read(
|
||||
uint8_t* buffer,
|
||||
int64_t count,
|
||||
Azure::Core::Context const& context = Azure::Core::Context())
|
||||
{
|
||||
context.ThrowIfCancelled();
|
||||
return OnRead(buffer, count, context);
|
||||
@ -100,7 +103,10 @@ namespace Azure { namespace Core { namespace IO {
|
||||
*
|
||||
* @return Number of bytes read.
|
||||
*/
|
||||
int64_t ReadToCount(uint8_t* buffer, int64_t count, Azure::Core::Context const& context);
|
||||
int64_t ReadToCount(
|
||||
uint8_t* buffer,
|
||||
int64_t count,
|
||||
Azure::Core::Context const& context = Azure::Core::Context());
|
||||
|
||||
/**
|
||||
* @brief Read #Azure::Core::IO::BodyStream until the stream is read to end, allocating memory
|
||||
@ -110,7 +116,7 @@ namespace Azure { namespace Core { namespace IO {
|
||||
*
|
||||
* @return A vector of bytes containing the entirety of data read from the \p body.
|
||||
*/
|
||||
std::vector<uint8_t> ReadToEnd(Azure::Core::Context const& context);
|
||||
std::vector<uint8_t> ReadToEnd(Azure::Core::Context const& context = Azure::Core::Context());
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -75,3 +75,49 @@ TEST(FileBodyStream, Length)
|
||||
stream.Rewind();
|
||||
EXPECT_EQ(stream.Length(), FileSize);
|
||||
}
|
||||
|
||||
TEST(FileBodyStream, Read)
|
||||
{
|
||||
std::string testDataPath(AZURE_TEST_DATA_PATH);
|
||||
testDataPath.append("/fileData");
|
||||
|
||||
Azure::Core::IO::FileBodyStream stream(testDataPath);
|
||||
|
||||
// ReadToEnd
|
||||
auto readResult = stream.ReadToEnd();
|
||||
EXPECT_EQ(readResult.size(), FileSize);
|
||||
|
||||
stream.Rewind();
|
||||
|
||||
readResult = stream.ReadToEnd(Azure::Core::Context::GetApplicationContext());
|
||||
EXPECT_EQ(readResult.size(), FileSize);
|
||||
|
||||
stream.Rewind();
|
||||
|
||||
// ReadToCount
|
||||
std::vector<uint8_t> buffer(FileSize * 2);
|
||||
|
||||
int64_t readSize = stream.ReadToCount(buffer.data(), 10);
|
||||
EXPECT_EQ(readSize, 10);
|
||||
EXPECT_EQ(buffer[10], 0);
|
||||
|
||||
stream.Rewind();
|
||||
|
||||
readSize = stream.ReadToCount(buffer.data(), 10, Azure::Core::Context::GetApplicationContext());
|
||||
EXPECT_EQ(readSize, 10);
|
||||
EXPECT_EQ(buffer[10], 0);
|
||||
|
||||
stream.Rewind();
|
||||
|
||||
// Read
|
||||
readSize = stream.Read(buffer.data(), buffer.size());
|
||||
EXPECT_EQ(readSize, FileSize);
|
||||
EXPECT_EQ(buffer[FileSize], 0);
|
||||
|
||||
stream.Rewind();
|
||||
|
||||
readSize
|
||||
= stream.Read(buffer.data(), buffer.size(), Azure::Core::Context::GetApplicationContext());
|
||||
EXPECT_EQ(readSize, FileSize);
|
||||
EXPECT_EQ(buffer[FileSize], 0);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user