mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2024-11-24 02:59:07 +08:00
Merge pull request #2050 from stweil/leaks
Fix some memory leaks in unit tests
This commit is contained in:
commit
ec476f908e
@ -27,6 +27,7 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <locale>
|
#include <locale>
|
||||||
|
#include <memory> // std::unique_ptr
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "baseapi.h"
|
#include "baseapi.h"
|
||||||
#include "include_gunit.h"
|
#include "include_gunit.h"
|
||||||
@ -55,7 +56,7 @@ void OCRTester(const char* imgname, const char* groundtruth,
|
|||||||
file.imbue(loc); // Use it for file input
|
file.imbue(loc); // Use it for file input
|
||||||
std::string gtText((std::istreambuf_iterator<char>(file)),
|
std::string gtText((std::istreambuf_iterator<char>(file)),
|
||||||
std::istreambuf_iterator<char>());
|
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))
|
ASSERT_FALSE(api->Init(tessdatadir, lang))
|
||||||
<< "Could not initialize tesseract.";
|
<< "Could not initialize tesseract.";
|
||||||
Pix* image = pixRead(imgname);
|
Pix* image = pixRead(imgname);
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
///////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include <memory> // std::unique_ptr
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include "baseapi.h"
|
#include "baseapi.h"
|
||||||
#include "include_gunit.h"
|
#include "include_gunit.h"
|
||||||
@ -35,7 +36,7 @@ class QuickTest : public testing::Test {
|
|||||||
};
|
};
|
||||||
|
|
||||||
void LangLoader(const char* lang, const char* tessdatadir) {
|
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))
|
ASSERT_FALSE(api->Init(tessdatadir, lang))
|
||||||
<< "Could not initialize tesseract for $lang.";
|
<< "Could not initialize tesseract for $lang.";
|
||||||
api->End();
|
api->End();
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
//#include "log.h"
|
//#include "log.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <memory> // std::unique_ptr
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "baseapi.h"
|
#include "baseapi.h"
|
||||||
#include "include_gunit.h"
|
#include "include_gunit.h"
|
||||||
@ -33,7 +34,7 @@ class TestClass : public testing::Test {
|
|||||||
|
|
||||||
void OSDTester(int expected_deg, const char* imgname, const char* tessdatadir) {
|
void OSDTester(int expected_deg, const char* imgname, const char* tessdatadir) {
|
||||||
// log.info() << tessdatadir << " for image: " << imgname << std::endl;
|
// 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"))
|
ASSERT_FALSE(api->Init(tessdatadir, "osd"))
|
||||||
<< "Could not initialize tesseract.";
|
<< "Could not initialize tesseract.";
|
||||||
Pix* image = pixRead(imgname);
|
Pix* image = pixRead(imgname);
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <locale>
|
#include <locale>
|
||||||
|
#include <memory> // std::unique_ptr
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "baseapi.h"
|
#include "baseapi.h"
|
||||||
#include "gmock/gmock.h"
|
#include "gmock/gmock.h"
|
||||||
@ -88,7 +89,7 @@ void ClassicProgressTester(const char* imgname, const char* tessdatadir,
|
|||||||
using ::testing::Return;
|
using ::testing::Return;
|
||||||
using ::testing::SaveArg;
|
using ::testing::SaveArg;
|
||||||
|
|
||||||
tesseract::TessBaseAPI* api = new tesseract::TessBaseAPI();
|
std::unique_ptr<tesseract::TessBaseAPI> api(new tesseract::TessBaseAPI());
|
||||||
ASSERT_FALSE(api->Init(tessdatadir, lang))
|
ASSERT_FALSE(api->Init(tessdatadir, lang))
|
||||||
<< "Could not initialize tesseract.";
|
<< "Could not initialize tesseract.";
|
||||||
Pix* image = pixRead(imgname);
|
Pix* image = pixRead(imgname);
|
||||||
@ -124,7 +125,7 @@ void NewProgressTester(const char* imgname, const char* tessdatadir,
|
|||||||
using ::testing::Return;
|
using ::testing::Return;
|
||||||
using ::testing::SaveArg;
|
using ::testing::SaveArg;
|
||||||
|
|
||||||
tesseract::TessBaseAPI* api = new tesseract::TessBaseAPI();
|
std::unique_ptr<tesseract::TessBaseAPI> api(new tesseract::TessBaseAPI());
|
||||||
ASSERT_FALSE(api->Init(tessdatadir, lang))
|
ASSERT_FALSE(api->Init(tessdatadir, lang))
|
||||||
<< "Could not initialize tesseract.";
|
<< "Could not initialize tesseract.";
|
||||||
Pix* image = pixRead(imgname);
|
Pix* image = pixRead(imgname);
|
||||||
@ -149,12 +150,12 @@ void NewProgressTester(const char* imgname, const char* tessdatadir,
|
|||||||
pixDestroy(&image);
|
pixDestroy(&image);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(QuickTest, ClassicProgressReporitng) {
|
TEST(QuickTest, ClassicProgressReporting) {
|
||||||
ClassicProgressTester(TESTING_DIR "/phototest.tif", TESSDATA_DIR "_fast",
|
ClassicProgressTester(TESTING_DIR "/phototest.tif", TESSDATA_DIR "_fast",
|
||||||
"eng");
|
"eng");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(QuickTest, NewProgressReporitng) {
|
TEST(QuickTest, NewProgressReporting) {
|
||||||
NewProgressTester(TESTING_DIR "/phototest.tif", TESSDATA_DIR "_fast", "eng");
|
NewProgressTester(TESTING_DIR "/phototest.tif", TESSDATA_DIR "_fast", "eng");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user