58 lines
1.7 KiB
C++
58 lines
1.7 KiB
C++
#include "document_test_helpers.hpp"
|
|
#include "pdfengine/pdf_document.hpp"
|
|
#include "pdfengine/edit_session.hpp"
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace pdfengine {
|
|
|
|
TEST(EditSessionTest, StartEditSessionAndBasics) {
|
|
SKIP_IF_NO_PDFIUM();
|
|
|
|
auto path = getCorpusPath("basic", "hello_world.pdf");
|
|
if (!std::filesystem::exists(path)) {
|
|
GTEST_SKIP() << "hello_world.pdf not found in corpus.";
|
|
}
|
|
|
|
auto docRes = PdfDocument::loadFromFile(path.string());
|
|
ASSERT_TRUE(docRes.has_value());
|
|
auto doc = *docRes;
|
|
|
|
auto session = EditSession::StartEditSession(doc, 0, "para_1");
|
|
ASSERT_NE(session, nullptr);
|
|
|
|
// Initial Layout check (Mocked initial text: "Mock initial text for paragraph.")
|
|
auto layout = session->GetLayoutView();
|
|
EXPECT_FALSE(layout.lines.empty());
|
|
EXPECT_FALSE(layout.glyphs.empty());
|
|
|
|
// HitTest against mocked coordinates
|
|
// We mocked columnLeft at 100.0, advance 6.0 per char
|
|
// Char 0 at x=100.0
|
|
int hit = session->HitTest(102.0, 700.0);
|
|
EXPECT_EQ(hit, 0); // Closest to first cluster
|
|
|
|
// Char 1 at x=106.0
|
|
hit = session->HitTest(108.0, 700.0);
|
|
EXPECT_EQ(hit, 1); // Closest to second cluster
|
|
|
|
// GetCaretRect
|
|
Rect caret0 = session->GetCaretRect(0);
|
|
EXPECT_EQ(caret0.x, 100.0);
|
|
EXPECT_EQ(caret0.y, 690.0); // 700 - 10(ascent)
|
|
|
|
Rect caret1 = session->GetCaretRect(1);
|
|
EXPECT_EQ(caret1.x, 106.0);
|
|
|
|
// ApplyEdit sets dirty flag
|
|
session->ApplyEdit("append:!");
|
|
|
|
auto layout2 = session->GetLayoutView();
|
|
EXPECT_GT(layout2.glyphs.size(), layout.glyphs.size()); // Appended '!'
|
|
|
|
bool committed = session->CommitEdit();
|
|
EXPECT_TRUE(committed);
|
|
}
|
|
|
|
} // namespace pdfengine
|