~ubuntu-branches/debian/sid/python-feather-format/sid

« back to all changes in this revision

Viewing changes to src/feather/io-test.cc

  • Committer: Package Import Robot
  • Author(s): ChangZhuo Chen (陳昌倬)
  • Date: 2016-03-30 19:01:30 UTC
  • Revision ID: package-import@ubuntu.com-20160330190130-b7o770i7o2drepi1
Tags: upstream-0.1.0
Import upstream version 0.1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2016 Feather Developers
 
2
//
 
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
 
6
//
 
7
// http://www.apache.org/licenses/LICENSE-2.0
 
8
//
 
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.
 
14
 
 
15
#include <gtest/gtest.h>
 
16
 
 
17
#include <cstdint>
 
18
#include <memory>
 
19
 
 
20
#include "feather/buffer.h"
 
21
#include "feather/io.h"
 
22
#include "feather/status.h"
 
23
#include "feather/test-common.h"
 
24
 
 
25
namespace feather {
 
26
 
 
27
TEST(TestBufferReader, Basics) {
 
28
  std::vector<uint8_t> data = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
 
29
 
 
30
  auto data_buffer = std::make_shared<Buffer>(&data[0], data.size());
 
31
  std::unique_ptr<BufferReader> reader(new BufferReader(data_buffer));
 
32
 
 
33
  ASSERT_EQ(0, reader->Tell());
 
34
  ASSERT_EQ(10, reader->size());
 
35
 
 
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());
 
41
 
 
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());
 
46
}
 
47
 
 
48
TEST(TestInMemoryOutputStream, Basics) {
 
49
  std::unique_ptr<InMemoryOutputStream> stream(new InMemoryOutputStream(8));
 
50
 
 
51
  std::vector<uint8_t> data = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
 
52
 
 
53
  ASSERT_OK(stream->Write(&data[0], 4));
 
54
  ASSERT_EQ(4, stream->Tell());
 
55
  ASSERT_OK(stream->Write(&data[4], data.size() - 4));
 
56
 
 
57
  std::shared_ptr<Buffer> buffer = stream->Finish();
 
58
  ASSERT_EQ(0, memcmp(buffer->data(), &data[0], data.size()));
 
59
}
 
60
 
 
61
TEST(LocalFileReader, NonExistentFile) {
 
62
  LocalFileReader reader;
 
63
 
 
64
  Status s = reader.Open("foo");
 
65
  ASSERT_FALSE(s.ok());
 
66
  ASSERT_TRUE(s.IsIOError());
 
67
}
 
68
 
 
69
} // namespace feather