From 48fe1e0232c42413ac72fc304f95dfda9122b978 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Thu, 18 Mar 2021 15:15:15 +0100 Subject: [PATCH] Replace more GenericVector by std::vector for src/unittest Signed-off-by: Stefan Weil --- unittest/doubleptr.h | 3 +-- unittest/heap_test.cc | 5 ++--- unittest/paragraphs_test.cc | 1 - unittest/tfile_test.cc | 29 ++++++++++++++--------------- 4 files changed, 17 insertions(+), 21 deletions(-) diff --git a/unittest/doubleptr.h b/unittest/doubleptr.h index dad275de..1348c0ff 100644 --- a/unittest/doubleptr.h +++ b/unittest/doubleptr.h @@ -5,7 +5,6 @@ // Description: Double-ended pointer that keeps pointing correctly even // when reallocated or copied. // Author: Ray Smith -// Created: Wed Mar 14 12:22:57 PDT 2012 // // (C) Copyright 2012, Google Inc. // Licensed under the Apache License, Version 2.0 (the "License"); @@ -34,7 +33,7 @@ namespace tesseract { // For this reason both the copy constructor and the operator= take a non-const // reference argument, and the const reference versions cannot be used. // DoublePtr is useful to incorporate into structures that are part of a -// collection such as GenericVector or STL containers, where reallocs can +// collection such as STL containers, where reallocs can // relocate the members. DoublePtr is also useful in a GenericHeap, where it // can correctly maintain the pointer to an element of the heap despite it // getting moved around on the heap. diff --git a/unittest/heap_test.cc b/unittest/heap_test.cc index abd48748..24f2b930 100644 --- a/unittest/heap_test.cc +++ b/unittest/heap_test.cc @@ -13,7 +13,6 @@ #include "doubleptr.h" #include "genericheap.h" -#include "genericvector.h" #include "kdpair.h" #include @@ -135,7 +134,7 @@ TEST_F(HeapTest, RevalueTest) { // in the vector and heap, and we test a MAX heap. typedef KDPairDec PtrPair; GenericHeap heap; - GenericVector v; + std::vector v; // Push the test data onto both the heap and the vector. for (size_t i = 0; i < countof(test_data); ++i) { PtrPair h_pair; @@ -162,7 +161,7 @@ TEST_F(HeapTest, RevalueTest) { heap.Reshuffle(pair_ptr); // After the changes, popping the heap should still match the sorted order // of the vector. - v.sort(); + std::sort(v.begin(), v.end()); EXPECT_GT(v[0].key(), v.back().key()); for (int i = 0; i < v.size(); ++i) { EXPECT_EQ(v[i].key(), heap.PeekTop().key()); diff --git a/unittest/paragraphs_test.cc b/unittest/paragraphs_test.cc index ec4c4d1e..bc6eb582 100644 --- a/unittest/paragraphs_test.cc +++ b/unittest/paragraphs_test.cc @@ -18,7 +18,6 @@ #include "include_gunit.h" // for TEST #include "log.h" // for LOG -#include "genericvector.h" // ccmain #include "paragraphs.h" #include "paragraphs_internal.h" diff --git a/unittest/tfile_test.cc b/unittest/tfile_test.cc index fcb27e06..f7347534 100644 --- a/unittest/tfile_test.cc +++ b/unittest/tfile_test.cc @@ -9,7 +9,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "genericvector.h" #include "serialis.h" #include "include_gunit.h" @@ -52,22 +51,22 @@ protected: bool Serialize(TFile *fp) { if (fp->FWrite(&num_squares_, sizeof(num_squares_), 1) != 1) return false; - if (!squares_.Serialize(fp)) + if (!fp->Serialize(squares_)) return false; if (fp->FWrite(&num_triangles_, sizeof(num_triangles_), 1) != 1) return false; - if (!triangles_.Serialize(fp)) + if (!fp->Serialize(triangles_)) return false; return true; } bool DeSerialize(TFile *fp) { if (fp->FReadEndian(&num_squares_, sizeof(num_squares_), 1) != 1) return false; - if (!squares_.DeSerialize(fp)) + if (!fp->DeSerialize(squares_)) return false; if (fp->FReadEndian(&num_triangles_, sizeof(num_triangles_), 1) != 1) return false; - if (!triangles_.DeSerialize(fp)) + if (!fp->DeSerialize(triangles_)) return false; return true; } @@ -81,44 +80,44 @@ protected: return false; for (int i = 0; i < squares_.size(); ++i) ReverseN(&squares_[i], sizeof(squares_[i])); - if (!squares_.Serialize(fp)) + if (!fp->Serialize(squares_)) return false; ReverseN(&num_triangles_, sizeof(num_triangles_)); if (fp->FWrite(&num_triangles_, sizeof(num_triangles_), 1) != 1) return false; if (fp->FWrite(&num_triangles_, sizeof(num_triangles_), 1) != 1) return false; - for (int i = 0; i < triangles_.size(); ++i) - ReverseN(&triangles_[i], sizeof(triangles_[i])); - return triangles_.Serialize(fp); + for (auto &triangle : triangles_) + ReverseN(&triangle, sizeof(triangles_[0])); + return fp->Serialize(triangles_); } bool DeSerializeBigEndian(TFile *fp) { if (fp->FReadEndian(&num_squares_, sizeof(num_squares_), 1) != 1) return false; - if (!squares_.DeSerialize(fp)) + if (!fp->DeSerialize(squares_)) return false; // The first element is the size that was written, so we will delete it // and read the last element separately. int last_element; if (fp->FReadEndian(&last_element, sizeof(last_element), 1) != 1) return false; - squares_.remove(0); + squares_.erase(squares_.begin()); squares_.push_back(last_element); if (fp->FReadEndian(&num_triangles_, sizeof(num_triangles_), 1) != 1) return false; - if (!triangles_.DeSerialize(fp)) + if (!fp->DeSerialize(triangles_)) return false; if (fp->FReadEndian(&last_element, sizeof(last_element), 1) != 1) return false; - triangles_.remove(0); + triangles_.erase(triangles_.begin()); triangles_.push_back(last_element); return true; } private: - GenericVector squares_; + std::vector squares_; int num_squares_; - GenericVector triangles_; + std::vector triangles_; int num_triangles_; }; };