From 420a0286fde613b581994c32ec6c9adbc38c9f89 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Fri, 12 Oct 2018 08:13:39 +0200 Subject: [PATCH] unittest: Add fileio_test Signed-off-by: Stefan Weil --- unittest/Makefile.am | 7 +++++++ unittest/fileio_test.cc | 21 ++++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/unittest/Makefile.am b/unittest/Makefile.am index 8934c92254..b3c8553ce7 100644 --- a/unittest/Makefile.am +++ b/unittest/Makefile.am @@ -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) diff --git a/unittest/fileio_test.cc b/unittest/fileio_test.cc index 19c51bdc14..698f358178 100644 --- a/unittest/fileio_test.cc +++ b/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 #include +#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 input(new InputBuffer(fp)); EXPECT_TRUE(input->Read(&str)); - std::vector lines = absl::StrSplit(str, '\n', absl::SkipEmpty()); + std::vector lines = absl::StrSplit(str, '\n', absl::SkipEmpty()); EXPECT_EQ(2, lines.size()); EXPECT_EQ("Hello", lines[0]); EXPECT_EQ(" world!", lines[1]);