Skip to content

Commit

Permalink
unittest: Add fileio_test
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Weil <sw@weilnetz.de>
  • Loading branch information
stweil committed Oct 12, 2018
1 parent d3cf423 commit 420a028
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
7 changes: 7 additions & 0 deletions unittest/Makefile.am
Expand Up @@ -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

Expand Down Expand Up @@ -82,6 +85,7 @@ check_PROGRAMS = \
cleanapi_test \
colpartition_test \
denorm_test \
fileio_test \
heap_test \
indexmapbidi_test \
intfeaturemap_test \
Expand Down Expand Up @@ -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)

Expand Down
21 changes: 18 additions & 3 deletions unittest/fileio_test.cc
@@ -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;
Expand Down Expand Up @@ -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]);
Expand Down

0 comments on commit 420a028

Please sign in to comment.