Skip to content

Commit

Permalink
Merge pull request #2050 from stweil/leaks
Browse files Browse the repository at this point in the history
Fix some memory leaks in unit tests
  • Loading branch information
zdenop authored Nov 13, 2018
2 parents 4ef51d8 + ff5347c commit ec476f9
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
3 changes: 2 additions & 1 deletion unittest/apiexample_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <fstream>
#include <iostream>
#include <locale>
#include <memory> // std::unique_ptr
#include <string>
#include "baseapi.h"
#include "include_gunit.h"
Expand Down Expand Up @@ -55,7 +56,7 @@ void OCRTester(const char* imgname, const char* groundtruth,
file.imbue(loc); // Use it for file input
std::string gtText((std::istreambuf_iterator<char>(file)),
std::istreambuf_iterator<char>());
tesseract::TessBaseAPI* api = new tesseract::TessBaseAPI();
std::unique_ptr<tesseract::TessBaseAPI> api(new tesseract::TessBaseAPI());
ASSERT_FALSE(api->Init(tessdatadir, lang))
<< "Could not initialize tesseract.";
Pix* image = pixRead(imgname);
Expand Down
3 changes: 2 additions & 1 deletion unittest/loadlang_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// limitations under the License.
///////////////////////////////////////////////////////////////////////

#include <memory> // std::unique_ptr
#include <time.h>
#include "baseapi.h"
#include "include_gunit.h"
Expand All @@ -35,7 +36,7 @@ class QuickTest : public testing::Test {
};

void LangLoader(const char* lang, const char* tessdatadir) {
tesseract::TessBaseAPI* api = new tesseract::TessBaseAPI();
std::unique_ptr<tesseract::TessBaseAPI> api(new tesseract::TessBaseAPI());
ASSERT_FALSE(api->Init(tessdatadir, lang))
<< "Could not initialize tesseract for $lang.";
api->End();
Expand Down
3 changes: 2 additions & 1 deletion unittest/osd_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

//#include "log.h"
#include <iostream>
#include <memory> // std::unique_ptr
#include <string>
#include "baseapi.h"
#include "include_gunit.h"
Expand All @@ -33,7 +34,7 @@ class TestClass : public testing::Test {

void OSDTester(int expected_deg, const char* imgname, const char* tessdatadir) {
// log.info() << tessdatadir << " for image: " << imgname << std::endl;
tesseract::TessBaseAPI* api = new tesseract::TessBaseAPI();
std::unique_ptr<tesseract::TessBaseAPI> api(new tesseract::TessBaseAPI());
ASSERT_FALSE(api->Init(tessdatadir, "osd"))
<< "Could not initialize tesseract.";
Pix* image = pixRead(imgname);
Expand Down
9 changes: 5 additions & 4 deletions unittest/progress_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <fstream>
#include <iostream>
#include <locale>
#include <memory> // std::unique_ptr
#include <string>
#include "baseapi.h"
#include "gmock/gmock.h"
Expand Down Expand Up @@ -88,7 +89,7 @@ void ClassicProgressTester(const char* imgname, const char* tessdatadir,
using ::testing::Return;
using ::testing::SaveArg;

tesseract::TessBaseAPI* api = new tesseract::TessBaseAPI();
std::unique_ptr<tesseract::TessBaseAPI> api(new tesseract::TessBaseAPI());
ASSERT_FALSE(api->Init(tessdatadir, lang))
<< "Could not initialize tesseract.";
Pix* image = pixRead(imgname);
Expand Down Expand Up @@ -124,7 +125,7 @@ void NewProgressTester(const char* imgname, const char* tessdatadir,
using ::testing::Return;
using ::testing::SaveArg;

tesseract::TessBaseAPI* api = new tesseract::TessBaseAPI();
std::unique_ptr<tesseract::TessBaseAPI> api(new tesseract::TessBaseAPI());
ASSERT_FALSE(api->Init(tessdatadir, lang))
<< "Could not initialize tesseract.";
Pix* image = pixRead(imgname);
Expand All @@ -149,12 +150,12 @@ void NewProgressTester(const char* imgname, const char* tessdatadir,
pixDestroy(&image);
}

TEST(QuickTest, ClassicProgressReporitng) {
TEST(QuickTest, ClassicProgressReporting) {
ClassicProgressTester(TESTING_DIR "/phototest.tif", TESSDATA_DIR "_fast",
"eng");
}

TEST(QuickTest, NewProgressReporitng) {
TEST(QuickTest, NewProgressReporting) {
NewProgressTester(TESTING_DIR "/phototest.tif", TESSDATA_DIR "_fast", "eng");
}

Expand Down

0 comments on commit ec476f9

Please sign in to comment.