unittest: Add fileio_test

Signed-off-by: Stefan Weil <sw@weilnetz.de>
This commit is contained in:
Stefan Weil 2018-10-12 08:13:39 +02:00
parent d3cf423748
commit 420a0286fd
2 changed files with 25 additions and 3 deletions

View File

@ -47,7 +47,10 @@ libabseil_la_SOURCES += ../abseil/absl/base/internal/throw_delegate.cc
libabseil_la_SOURCES += ../abseil/absl/base/internal/unscaledcycleclock.cc
libabseil_la_SOURCES += ../abseil/absl/numeric/int128.cc
libabseil_la_SOURCES += ../abseil/absl/strings/ascii.cc
libabseil_la_SOURCES += ../abseil/absl/strings/internal/memutil.cc
libabseil_la_SOURCES += ../abseil/absl/strings/str_cat.cc
libabseil_la_SOURCES += ../abseil/absl/strings/str_split.cc
libabseil_la_SOURCES += ../abseil/absl/strings/string_view.cc
libabseil_la_SOURCES += ../abseil/absl/time/clock.cc
libabseil_la_SOURCES += ../abseil/absl/time/duration.cc
@ -82,6 +85,7 @@ check_PROGRAMS = \
cleanapi_test \
colpartition_test \
denorm_test \
fileio_test \
heap_test \
indexmapbidi_test \
intfeaturemap_test \
@ -138,6 +142,9 @@ commandlineflags_test_LDADD = $(GTEST_LIBS) $(TRAINING_LIBS) $(TESS_LIBS)
denorm_test_SOURCES = denorm_test.cc
denorm_test_LDADD = $(GTEST_LIBS) $(TESS_LIBS)
fileio_test_SOURCES = fileio_test.cc
fileio_test_LDADD = $(ABSEIL_LIBS) $(GTEST_LIBS) $(TESS_LIBS)
heap_test_SOURCES = heap_test.cc
heap_test_LDADD = $(GTEST_LIBS) $(TESS_LIBS)

View File

@ -1,8 +1,23 @@
#include "tesseract/training/fileio.h"
// (C) Copyright 2017, Google Inc.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <stdio.h>
#include <memory>
#include "absl/strings/str_split.h"
#include "fileio.h"
#include "include_gunit.h"
namespace {
using tesseract::File;
@ -38,10 +53,10 @@ TEST(InputBufferTest, Read) {
FILE* fp = fmemopen(buffer, kMaxBufSize, "r");
CHECK(fp != nullptr);
string str;
std::string str;
std::unique_ptr<InputBuffer> input(new InputBuffer(fp));
EXPECT_TRUE(input->Read(&str));
std::vector<string> lines = absl::StrSplit(str, '\n', absl::SkipEmpty());
std::vector<std::string> lines = absl::StrSplit(str, '\n', absl::SkipEmpty());
EXPECT_EQ(2, lines.size());
EXPECT_EQ("Hello", lines[0]);
EXPECT_EQ(" world!", lines[1]);