1
// Copyright 2016 Feather Developers
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
7
// http://www.apache.org/licenses/LICENSE-2.0
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
15
#include <gtest/gtest.h>
20
#include "feather/buffer.h"
21
#include "feather/io.h"
22
#include "feather/status.h"
23
#include "feather/test-common.h"
27
TEST(TestBufferReader, Basics) {
28
std::vector<uint8_t> data = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
30
auto data_buffer = std::make_shared<Buffer>(&data[0], data.size());
31
std::unique_ptr<BufferReader> reader(new BufferReader(data_buffer));
33
ASSERT_EQ(0, reader->Tell());
34
ASSERT_EQ(10, reader->size());
36
std::shared_ptr<Buffer> buffer;
37
ASSERT_OK(reader->Read(4, &buffer));
38
ASSERT_EQ(4, buffer->size());
39
ASSERT_EQ(0, memcmp(buffer->data(), &data[0], buffer->size()));
40
ASSERT_EQ(4, reader->Tell());
42
ASSERT_OK(reader->Read(10, &buffer));
43
ASSERT_EQ(6, buffer->size());
44
ASSERT_EQ(0, memcmp(buffer->data(), &data[4], buffer->size()));
45
ASSERT_EQ(10, reader->Tell());
48
TEST(TestInMemoryOutputStream, Basics) {
49
std::unique_ptr<InMemoryOutputStream> stream(new InMemoryOutputStream(8));
51
std::vector<uint8_t> data = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
53
ASSERT_OK(stream->Write(&data[0], 4));
54
ASSERT_EQ(4, stream->Tell());
55
ASSERT_OK(stream->Write(&data[4], data.size() - 4));
57
std::shared_ptr<Buffer> buffer = stream->Finish();
58
ASSERT_EQ(0, memcmp(buffer->data(), &data[0], data.size()));
61
TEST(LocalFileReader, NonExistentFile) {
62
LocalFileReader reader;
64
Status s = reader.Open("foo");
66
ASSERT_TRUE(s.IsIOError());
69
} // namespace feather