mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2024-11-24 02:59:07 +08:00
Improve some unit tests.
This commit is contained in:
parent
0c19e1e14d
commit
6cc00aa332
@ -38,7 +38,7 @@ class QuickTest : public testing::Test {
|
|||||||
protected:
|
protected:
|
||||||
virtual void SetUp() { start_time_ = time(nullptr); }
|
virtual void SetUp() { start_time_ = time(nullptr); }
|
||||||
virtual void TearDown() {
|
virtual void TearDown() {
|
||||||
#if defined(DEBUG)
|
#ifndef NDEBUG
|
||||||
// Debug builds can be very slow, so allow 4 min for OCR of a test image.
|
// Debug builds can be very slow, so allow 4 min for OCR of a test image.
|
||||||
// apitest_example including disabled tests takes about 18 min on ARMv7.
|
// apitest_example including disabled tests takes about 18 min on ARMv7.
|
||||||
const time_t MAX_SECONDS_FOR_TEST = 240;
|
const time_t MAX_SECONDS_FOR_TEST = 240;
|
||||||
|
@ -30,24 +30,29 @@ TEST(OutputBufferTest, WriteString) {
|
|||||||
const int kMaxBufSize = 128;
|
const int kMaxBufSize = 128;
|
||||||
char buffer[kMaxBufSize];
|
char buffer[kMaxBufSize];
|
||||||
for (int i = 0; i < kMaxBufSize; ++i) buffer[i] = '\0';
|
for (int i = 0; i < kMaxBufSize; ++i) buffer[i] = '\0';
|
||||||
FILE* fp = fmemopen(buffer, kMaxBufSize, "w");
|
FILE* fp = tmpfile();
|
||||||
CHECK(fp != nullptr);
|
CHECK(fp != nullptr);
|
||||||
|
|
||||||
{
|
std::unique_ptr<OutputBuffer> output(new OutputBuffer(fp));
|
||||||
std::unique_ptr<OutputBuffer> output(new OutputBuffer(fp));
|
output->WriteString("Hello ");
|
||||||
output->WriteString("Hello ");
|
output->WriteString("world!");
|
||||||
output->WriteString("world!");
|
|
||||||
}
|
rewind(fp);
|
||||||
EXPECT_STREQ("Hello world!", buffer);
|
auto s = "Hello world!";
|
||||||
|
fread(buffer, strlen(s), 1, fp);
|
||||||
|
EXPECT_STREQ(s, buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(InputBufferTest, Read) {
|
TEST(InputBufferTest, Read) {
|
||||||
const int kMaxBufSize = 128;
|
const int kMaxBufSize = 128;
|
||||||
char buffer[kMaxBufSize];
|
char buffer[kMaxBufSize];
|
||||||
snprintf(buffer, kMaxBufSize, "Hello\n world!");
|
auto s = "Hello\n world!";
|
||||||
EXPECT_STREQ("Hello\n world!", buffer);
|
snprintf(buffer, kMaxBufSize, s);
|
||||||
FILE* fp = fmemopen(buffer, kMaxBufSize, "r");
|
EXPECT_STREQ(s, buffer);
|
||||||
|
FILE* fp = tmpfile();
|
||||||
CHECK(fp != nullptr);
|
CHECK(fp != nullptr);
|
||||||
|
fwrite(buffer, strlen(s), 1, fp);
|
||||||
|
rewind(fp);
|
||||||
|
|
||||||
std::string str;
|
std::string str;
|
||||||
std::unique_ptr<InputBuffer> input(new InputBuffer(fp));
|
std::unique_ptr<InputBuffer> input(new InputBuffer(fp));
|
||||||
|
@ -9,18 +9,21 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
|
|
||||||
|
#include "include_gunit.h"
|
||||||
|
#include "log.h" // for LOG
|
||||||
|
|
||||||
#include "recodebeam.h"
|
#include "recodebeam.h"
|
||||||
#include "matrix.h"
|
#include "matrix.h"
|
||||||
#include "pageres.h"
|
#include "pageres.h"
|
||||||
#include "ratngs.h"
|
#include "ratngs.h"
|
||||||
#include <tesseract/genericvector.h>
|
|
||||||
#include <tesseract/helpers.h>
|
|
||||||
#include "unicharcompress.h"
|
#include "unicharcompress.h"
|
||||||
#include "normstrngs.h"
|
#include "normstrngs.h"
|
||||||
#include "unicharset_training_utils.h"
|
#include "unicharset_training_utils.h"
|
||||||
|
|
||||||
#include "include_gunit.h"
|
#include <tesseract/genericvector.h>
|
||||||
#include "log.h" // for LOG
|
#include <tesseract/helpers.h>
|
||||||
|
|
||||||
#include "absl/strings/str_format.h" // for absl::StrFormat
|
#include "absl/strings/str_format.h" // for absl::StrFormat
|
||||||
|
|
||||||
namespace tesseract {
|
namespace tesseract {
|
||||||
|
Loading…
Reference in New Issue
Block a user