mirror of
https://github.com/koreader/koreader.git
synced 2025-12-13 20:36:53 +01:00
fix all the tests
This commit is contained in:
2
base
2
base
Submodule base updated: 3ca13f3f2c...b5c82144e2
@@ -132,7 +132,8 @@ function ReaderBookmark:onToggleBookmark()
|
||||
pn_or_xp = self.ui.document:getXPointer()
|
||||
end
|
||||
self:toggleBookmark(pn_or_xp)
|
||||
self.view.dogear_visible = not self.view.dogear_visible
|
||||
self.ui:handleEvent(Event:new("SetDogearVisibility",
|
||||
not self.view.dogear_visible))
|
||||
UIManager:setDirty(self.view.dialog, "ui")
|
||||
return true
|
||||
end
|
||||
|
||||
@@ -255,7 +255,6 @@ function ReaderHighlight:onHoldPan(_, ges)
|
||||
return true
|
||||
end
|
||||
local page_area = self.view:getScreenPageArea(self.hold_pos.page)
|
||||
DEBUG("current page area", page_area)
|
||||
if ges.pos:notIntersectWith(page_area) then
|
||||
DEBUG("not inside page area", ges, page_area)
|
||||
return true
|
||||
|
||||
@@ -8,7 +8,7 @@ local UIManager = require("ui/uimanager")
|
||||
local Screen = require("device").screen
|
||||
local Geom = require("ui/geometry")
|
||||
local Event = require("ui/event")
|
||||
local DEBUG = require("dbg")
|
||||
local dbg = require("dbg")
|
||||
local Blitbuffer = require("ffi/blitbuffer")
|
||||
local _ = require("gettext")
|
||||
|
||||
@@ -118,7 +118,7 @@ function ReaderView:resetLayout()
|
||||
end
|
||||
|
||||
function ReaderView:paintTo(bb, x, y)
|
||||
DEBUG("painting", self.visible_area, "to", x, y)
|
||||
dbg("painting", self.visible_area, "to", x, y)
|
||||
if self.page_scroll then
|
||||
self:drawPageBackground(bb, x, y)
|
||||
else
|
||||
@@ -142,7 +142,7 @@ function ReaderView:paintTo(bb, x, y)
|
||||
|
||||
-- dim last read area
|
||||
if self.dim_area.w ~= 0 and self.dim_area.h ~= 0 then
|
||||
--DEBUG("dim area", self.dim_area)
|
||||
--dbg("dim area", self.dim_area)
|
||||
if self.page_overlap_style == "dim" then
|
||||
bb:dimRect(
|
||||
self.dim_area.x, self.dim_area.y,
|
||||
@@ -189,7 +189,7 @@ function ReaderView:screenToPageTransform(pos)
|
||||
else
|
||||
pos.page = self.ui.document:getCurrentPage()
|
||||
-- local last_y = self.ui.document:getCurrentPos()
|
||||
DEBUG("document has no pages at", pos)
|
||||
dbg("document has no pages at", pos)
|
||||
return pos
|
||||
end
|
||||
end
|
||||
@@ -519,14 +519,14 @@ function ReaderView:recalculate()
|
||||
end
|
||||
|
||||
function ReaderView:PanningUpdate(dx, dy)
|
||||
DEBUG("pan by", dx, dy)
|
||||
dbg("pan by", dx, dy)
|
||||
local old = self.visible_area:copy()
|
||||
self.visible_area:offsetWithin(self.page_area, dx, dy)
|
||||
if self.visible_area ~= old then
|
||||
-- flag a repaint
|
||||
UIManager:setDirty(self.dialog, "partial")
|
||||
DEBUG("on pan: page_area", self.page_area)
|
||||
DEBUG("on pan: visible_area", self.visible_area)
|
||||
dbg("on pan: page_area", self.page_area)
|
||||
dbg("on pan: visible_area", self.visible_area)
|
||||
self.ui:handleEvent(
|
||||
Event:new("ViewRecalculate", self.visible_area, self.page_area))
|
||||
end
|
||||
@@ -534,7 +534,7 @@ function ReaderView:PanningUpdate(dx, dy)
|
||||
end
|
||||
|
||||
function ReaderView:PanningStart(x, y)
|
||||
DEBUG("panning start", x, y)
|
||||
dbg("panning start", x, y)
|
||||
if not self.panning_visible_area then
|
||||
self.panning_visible_area = self.visible_area:copy()
|
||||
end
|
||||
@@ -611,7 +611,7 @@ function ReaderView:onSetDimensions(dimensions)
|
||||
end
|
||||
|
||||
function ReaderView:onRestoreDimensions(dimensions)
|
||||
--DEBUG("restore dimen", dimensions)
|
||||
--dbg("restore dimen", dimensions)
|
||||
self:resetLayout()
|
||||
self.dimen = dimensions
|
||||
-- recalculate view
|
||||
|
||||
@@ -98,7 +98,7 @@ function Cache:insert(key, object)
|
||||
-- make sure that one key only exists once: delete existing
|
||||
self:drop(key)
|
||||
-- guarantee that we have enough memory in cache
|
||||
if(object.size > self.max_memsize) then
|
||||
if (object.size > self.max_memsize) then
|
||||
DEBUG("too much memory claimed for", key)
|
||||
return
|
||||
end
|
||||
|
||||
@@ -202,7 +202,7 @@ function CreDocument:getScreenBoxesFromPositions(pos0, pos1)
|
||||
local line_boxes = {}
|
||||
if pos0 and pos1 then
|
||||
local word_boxes = self._document:getWordBoxesFromPositions(pos0, pos1)
|
||||
--DEBUG("word boxes", word_boxes)
|
||||
-- DEBUG("word boxes", word_boxes)
|
||||
for i = 1, #word_boxes do
|
||||
local line_box = word_boxes[i]
|
||||
table.insert(line_boxes, Geom:new{
|
||||
@@ -433,7 +433,8 @@ end
|
||||
|
||||
function CreDocument:findText(pattern, origin, reverse, caseInsensitive)
|
||||
DEBUG("CreDocument: find text", pattern, origin, reverse, caseInsensitive)
|
||||
return self._document:findText(pattern, origin, reverse, caseInsensitive and 1 or 0)
|
||||
return self._document:findText(
|
||||
pattern, origin, reverse, caseInsensitive and 1 or 0)
|
||||
end
|
||||
|
||||
function CreDocument:register(registry)
|
||||
|
||||
@@ -257,10 +257,13 @@ function Document:getFullPageHash(pageno, zoom, rotation, gamma, render_mode)
|
||||
end
|
||||
|
||||
function Document:renderPage(pageno, rect, zoom, rotation, gamma, render_mode)
|
||||
local hash_excerpt
|
||||
local hash = self:getFullPageHash(pageno, zoom, rotation, gamma, render_mode)
|
||||
local hash_excerpt = hash.."|"..tostring(rect)
|
||||
|
||||
local tile = Cache:check(hash, TileCacheItem) or Cache:check(hash_excerpt)
|
||||
local tile = Cache:check(hash, TileCacheItem)
|
||||
if not tile then
|
||||
hash_excerpt = hash.."|"..tostring(rect)
|
||||
tile = Cache:check(hash_excerpt)
|
||||
end
|
||||
if tile then return tile end
|
||||
|
||||
local page_size = self:getPageDimensions(pageno, zoom, rotation)
|
||||
|
||||
1
kodev
1
kodev
@@ -321,6 +321,7 @@ OPTIONS:
|
||||
test_path="${test_path}/$2"
|
||||
fi
|
||||
busted --lua=./luajit ${opts} \
|
||||
--no-auto-insulate \
|
||||
--lazy \
|
||||
-o ./spec/$1/unit/verbose_print \
|
||||
--exclude-tags=notest ${test_path}
|
||||
|
||||
@@ -179,7 +179,7 @@ end
|
||||
function ReaderStatistics:getCurrentStat()
|
||||
local dates = {}
|
||||
for k, v in pairs(self.data.performance_in_pages) do
|
||||
dates[os.date("%Y-%m-%d", k)] = ""
|
||||
dates[os.date("%Y-%m-%d", k)] = true
|
||||
end
|
||||
local total_days = util.tableSize(dates)
|
||||
|
||||
|
||||
@@ -38,5 +38,6 @@ describe("PDF reflowing benchmark", function()
|
||||
logDuration("pdf_reflowing.log", pageno, dur)
|
||||
end
|
||||
doc:close()
|
||||
doc.configurable.text_wrap = 0
|
||||
end)
|
||||
|
||||
|
||||
@@ -1,15 +1,21 @@
|
||||
require("commonrequire")
|
||||
local DocumentRegistry = require("document/documentregistry")
|
||||
local Cache = require("cache")
|
||||
local DEBUG = require("dbg")
|
||||
|
||||
describe("Cache module", function()
|
||||
local sample_pdf = "spec/front/unit/data/sample.pdf"
|
||||
local doc = DocumentRegistry:openDocument(sample_pdf)
|
||||
local DocumentRegistry, Cache, DEBUG
|
||||
local doc
|
||||
local max_page = 1
|
||||
setup(function()
|
||||
require("commonrequire")
|
||||
DocumentRegistry = require("document/documentregistry")
|
||||
Cache = require("cache")
|
||||
DEBUG = require("dbg")
|
||||
|
||||
local sample_pdf = "spec/front/unit/data/sample.pdf"
|
||||
doc = DocumentRegistry:openDocument(sample_pdf)
|
||||
end)
|
||||
|
||||
it("should clear cache", function()
|
||||
Cache:clear()
|
||||
end)
|
||||
local max_page = 1
|
||||
|
||||
it("should serialize blitbuffer", function()
|
||||
for pageno = 1, math.min(max_page, doc.info.number_of_pages) do
|
||||
doc:renderPage(pageno, nil, 1, 0, 1.0, 0)
|
||||
@@ -17,12 +23,14 @@ describe("Cache module", function()
|
||||
end
|
||||
Cache:clear()
|
||||
end)
|
||||
|
||||
it("should deserialize blitbuffer", function()
|
||||
for pageno = 1, math.min(max_page, doc.info.number_of_pages) do
|
||||
doc:hintPage(pageno, 1, 0, 1.0, 0)
|
||||
end
|
||||
Cache:clear()
|
||||
end)
|
||||
|
||||
it("should serialize koptcontext", function()
|
||||
doc.configurable.text_wrap = 1
|
||||
for pageno = 1, math.min(max_page, doc.info.number_of_pages) do
|
||||
@@ -31,7 +39,9 @@ describe("Cache module", function()
|
||||
Cache:serialize()
|
||||
end
|
||||
Cache:clear()
|
||||
doc.configurable.text_wrap = 0
|
||||
end)
|
||||
|
||||
it("should deserialize koptcontext", function()
|
||||
for pageno = 1, math.min(max_page, doc.info.number_of_pages) do
|
||||
doc:renderPage(pageno, nil, 1, 0, 1.0, 0)
|
||||
|
||||
@@ -11,6 +11,7 @@ describe("Dbg module", function()
|
||||
dbg:turnOn()
|
||||
assert.is_not.same(old_call, getmetatable(dbg).__call)
|
||||
assert.is_not.same(old_guard, dbg.guard)
|
||||
dbg:turnOff()
|
||||
end)
|
||||
|
||||
it("should call pre_gard callback", function()
|
||||
@@ -26,6 +27,7 @@ describe("Dbg module", function()
|
||||
dbg:guard(foo, 'bar', function() called = true end)
|
||||
foo:bar()
|
||||
assert.is.truthy(called)
|
||||
dbg:turnOff()
|
||||
end)
|
||||
|
||||
it("should call post_gard callback", function()
|
||||
@@ -41,6 +43,7 @@ describe("Dbg module", function()
|
||||
dbg:guard(foo, 'bar', nil, function() called = true end)
|
||||
foo:bar()
|
||||
assert.is.truthy(called)
|
||||
dbg:turnOff()
|
||||
end)
|
||||
|
||||
it("should return all values returned by the guarded function", function()
|
||||
@@ -61,5 +64,6 @@ describe("Dbg module", function()
|
||||
assert.is.falsy(called)
|
||||
re = {foo:bar()}
|
||||
assert.is.same(re, {1, 2, 3})
|
||||
dbg:turnOff()
|
||||
end)
|
||||
end)
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
require("commonrequire")
|
||||
local DocumentRegistry = require("document/documentregistry")
|
||||
|
||||
describe("PDF document module", function()
|
||||
local sample_pdf = "spec/front/unit/data/tall.pdf"
|
||||
local DocumentRegistry
|
||||
|
||||
setup(function()
|
||||
require("commonrequire")
|
||||
DocumentRegistry = require("document/documentregistry")
|
||||
end)
|
||||
|
||||
local doc
|
||||
it("should open document", function()
|
||||
local sample_pdf = "spec/front/unit/data/tall.pdf"
|
||||
doc = DocumentRegistry:openDocument(sample_pdf)
|
||||
assert.truthy(doc)
|
||||
end)
|
||||
@@ -44,9 +48,16 @@ describe("PDF document module", function()
|
||||
end)
|
||||
|
||||
describe("EPUB document module", function()
|
||||
local sample_epub = "spec/front/unit/data/leaves.epub"
|
||||
local DocumentRegistry
|
||||
|
||||
setup(function()
|
||||
require("commonrequire")
|
||||
DocumentRegistry = require("document/documentregistry")
|
||||
end)
|
||||
|
||||
local doc
|
||||
it("should open document", function()
|
||||
local sample_epub = "spec/front/unit/data/leaves.epub"
|
||||
doc = DocumentRegistry:openDocument(sample_epub)
|
||||
assert.truthy(doc)
|
||||
end)
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
require("commonrequire")
|
||||
local ImageWidget = require("ui/widget/imagewidget")
|
||||
|
||||
describe("ImageWidget module", function()
|
||||
local ImageWidget
|
||||
setup(function()
|
||||
require("commonrequire")
|
||||
ImageWidget = require("ui/widget/imagewidget")
|
||||
end)
|
||||
|
||||
it("should render without error", function()
|
||||
local imgw = ImageWidget:new{
|
||||
file = "resources/icons/appbar.chevron.up.png"
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
require("commonrequire")
|
||||
local DocumentRegistry = require("document/documentregistry")
|
||||
local Koptinterface = require("document/koptinterface")
|
||||
local Cache = require("cache")
|
||||
local DEBUG = require("dbg")
|
||||
DEBUG:turnOn()
|
||||
|
||||
describe("Koptinterface module", function()
|
||||
local DocumentRegistry, Koptinterface, Cache
|
||||
setup(function()
|
||||
require("commonrequire")
|
||||
DocumentRegistry = require("document/documentregistry")
|
||||
Koptinterface = require("document/koptinterface")
|
||||
Cache = require("cache")
|
||||
end)
|
||||
|
||||
local sample_pdf = "spec/front/unit/data/tall.pdf"
|
||||
local doc
|
||||
|
||||
@@ -55,6 +56,7 @@ describe("Koptinterface module", function()
|
||||
doc.configurable.text_wrap = 1
|
||||
local kc = Koptinterface:getCachedContext(doc, 1)
|
||||
assert.truthy(kc)
|
||||
doc.configurable.text_wrap = 0
|
||||
end)
|
||||
|
||||
it("should hint reflowed page in background", function()
|
||||
@@ -63,6 +65,7 @@ describe("Koptinterface module", function()
|
||||
-- and wait for reflowing to complete
|
||||
local kc = Koptinterface:getCachedContext(doc, 1)
|
||||
assert.truthy(kc)
|
||||
doc.configurable.text_wrap = 0
|
||||
end)
|
||||
|
||||
it("should get native text boxes", function()
|
||||
@@ -78,6 +81,6 @@ describe("Koptinterface module", function()
|
||||
local boxes = Koptinterface:getReflowedTextBoxes(doc, 1)
|
||||
local lines_in_reflowed_page = #boxes
|
||||
assert.truthy(lines_in_reflowed_page > 60)
|
||||
doc.configurable.text_wrap = 0
|
||||
end)
|
||||
|
||||
end)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
describe("ReaderBookmark module", function()
|
||||
local DocumentRegistry, ReaderUI, UIManager, Screen, Geom, DEBUG, DocSettings
|
||||
local DocumentRegistry, ReaderUI, UIManager, Screen, Geom, dbg, DocSettings
|
||||
local sample_epub, sample_pdf
|
||||
|
||||
setup(function()
|
||||
@@ -10,7 +10,7 @@ describe("ReaderBookmark module", function()
|
||||
UIManager = require("ui/uimanager")
|
||||
Screen = require("device").screen
|
||||
Geom = require("ui/geometry")
|
||||
DEBUG = require("dbg")
|
||||
dbg = require("dbg")
|
||||
|
||||
sample_epub = "spec/front/unit/data/juliet.epub"
|
||||
sample_pdf = "spec/front/unit/data/sample.pdf"
|
||||
@@ -22,6 +22,7 @@ describe("ReaderBookmark module", function()
|
||||
readerui.highlight:onHoldRelease()
|
||||
assert.truthy(readerui.highlight.highlight_dialog)
|
||||
readerui.highlight:onHighlight()
|
||||
-- TODO: replace scheduleIn with nextTick
|
||||
UIManager:scheduleIn(1, function()
|
||||
UIManager:close(readerui.highlight.highlight_dialog)
|
||||
UIManager:close(readerui)
|
||||
@@ -70,14 +71,16 @@ describe("ReaderBookmark module", function()
|
||||
{ notes = 'foo', page = 1, pos0 = 0, pos1 = 2, }))
|
||||
end)
|
||||
it("should show dogear after togglering non-bookmarked page", function()
|
||||
assert.falsy(readerui.view.dogear_visible)
|
||||
toggler_dogear(readerui)
|
||||
Screen:shot("screenshots/reader_bookmark_dogear_epub.png")
|
||||
assert.truthy(readerui.view.dogear_visible)
|
||||
end)
|
||||
it("should not show dogear after togglering bookmarked page", function()
|
||||
assert.truthy(readerui.view.dogear_visible)
|
||||
toggler_dogear(readerui)
|
||||
Screen:shot("screenshots/reader_bookmark_nodogear_epub.png")
|
||||
assert.truthy(not readerui.view.dogear_visible)
|
||||
assert.falsy(readerui.view.dogear_visible)
|
||||
end)
|
||||
it("should sort bookmarks with descending page numbers", function()
|
||||
local pages = {1, 20, 5, 30, 10, 40, 15, 25, 35, 45}
|
||||
@@ -92,6 +95,7 @@ describe("ReaderBookmark module", function()
|
||||
end)
|
||||
it("should keep descending page numbers after removing bookmarks", function()
|
||||
local pages = {1, 30, 10, 40, 20}
|
||||
readerui.bookmark.bookmarks = {}
|
||||
for _, page in ipairs(pages) do
|
||||
readerui.rolling:onGotoPage(page)
|
||||
toggler_dogear(readerui)
|
||||
@@ -102,7 +106,9 @@ describe("ReaderBookmark module", function()
|
||||
assert.are.same(5, #readerui.bookmark.bookmarks)
|
||||
end)
|
||||
it("should add bookmark by highlighting", function()
|
||||
highlight_text(readerui, Geom:new{ x = 260, y = 60 }, Geom:new{ x = 260, y = 90 })
|
||||
highlight_text(readerui,
|
||||
Geom:new{ x = 260, y = 60 },
|
||||
Geom:new{ x = 260, y = 90 })
|
||||
readerui.bookmark:onShowBookmark()
|
||||
show_bookmark_menu(readerui)
|
||||
Screen:shot("screenshots/reader_bookmark_6marks_epub.png")
|
||||
@@ -111,14 +117,16 @@ describe("ReaderBookmark module", function()
|
||||
it("should get previous bookmark for certain page", function()
|
||||
local xpointer = readerui.document:getXPointer()
|
||||
local bm_xpointer = readerui.bookmark:getPreviousBookmarkedPage(xpointer)
|
||||
assert.are.same(5, readerui.document:getPageFromXPointer(bm_xpointer))
|
||||
assert.are.same(6, #readerui.bookmark.bookmarks)
|
||||
assert.are.same(1, readerui.document:getPageFromXPointer(bm_xpointer))
|
||||
end)
|
||||
it("should get next bookmark for certain page", function()
|
||||
local xpointer = readerui.document:getXPointer()
|
||||
local bm_xpointer = readerui.bookmark:getNextBookmarkedPage(xpointer)
|
||||
assert.are.same(15, readerui.document:getPageFromXPointer(bm_xpointer))
|
||||
assert.are.same(20, readerui.document:getPageFromXPointer(bm_xpointer))
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("bookmark for PDF document", function()
|
||||
local readerui
|
||||
setup(function()
|
||||
|
||||
@@ -1,16 +1,20 @@
|
||||
require("commonrequire")
|
||||
local DocumentRegistry = require("document/documentregistry")
|
||||
local ReaderUI = require("apps/reader/readerui")
|
||||
local lfs = require("libs/libkoreader-lfs")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local Screen = require("device").screen
|
||||
local Event = require("ui/event")
|
||||
local DEBUG = require("dbg")
|
||||
|
||||
describe("Readerdictionary module", function()
|
||||
local sample_epub = "spec/front/unit/data/leaves.epub"
|
||||
local DocumentRegistry, ReaderUI, lfs, UIManager, Screen, Event, DEBUG
|
||||
|
||||
setup(function()
|
||||
require("commonrequire")
|
||||
DocumentRegistry = require("document/documentregistry")
|
||||
ReaderUI = require("apps/reader/readerui")
|
||||
lfs = require("libs/libkoreader-lfs")
|
||||
UIManager = require("ui/uimanager")
|
||||
Screen = require("device").screen
|
||||
Event = require("ui/event")
|
||||
DEBUG = require("dbg")
|
||||
end)
|
||||
|
||||
local readerui, rolling, dictionary
|
||||
setup(function()
|
||||
local sample_epub = "spec/front/unit/data/leaves.epub"
|
||||
readerui = ReaderUI:new{
|
||||
document = DocumentRegistry:openDocument(sample_epub),
|
||||
}
|
||||
|
||||
@@ -1,13 +1,18 @@
|
||||
require("commonrequire")
|
||||
local DocumentRegistry = require("document/documentregistry")
|
||||
local ReaderUI = require("apps/reader/readerui")
|
||||
local DocSettings = require("docsettings")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local DEBUG = require("dbg")
|
||||
local purgeDir = require("ffi/util").purgeDir
|
||||
local Screen = require("device").screen
|
||||
|
||||
describe("Readerfooter module", function()
|
||||
local DocumentRegistry, ReaderUI, DocSettings, UIManager, DEBUG
|
||||
local purgeDir, Screen
|
||||
|
||||
setup(function()
|
||||
require("commonrequire")
|
||||
DocumentRegistry = require("document/documentregistry")
|
||||
ReaderUI = require("apps/reader/readerui")
|
||||
DocSettings = require("docsettings")
|
||||
UIManager = require("ui/uimanager")
|
||||
DEBUG = require("dbg")
|
||||
purgeDir = require("ffi/util").purgeDir
|
||||
Screen = require("device").screen
|
||||
end)
|
||||
|
||||
before_each(function()
|
||||
G_reader_settings:saveSetting("footer", {
|
||||
disabled = false,
|
||||
@@ -37,7 +42,7 @@ describe("Readerfooter module", function()
|
||||
footer:updateFooter()
|
||||
timeinfo = footer:getTimeInfo()
|
||||
-- stats has not been initialized here, so we get na TB and TC
|
||||
assert.are.same('B:0% | '..timeinfo..' | 1 / 202 | => 0 | R:0% | TB: na | TC: na',
|
||||
assert.are.same('B:0% | '..timeinfo..' | 1 / 204 | => 1 | R:0% | TB: na | TC: na',
|
||||
footer.progress_text.text)
|
||||
end)
|
||||
|
||||
@@ -137,8 +142,8 @@ describe("Readerfooter module", function()
|
||||
assert.are.same(365, footer.text_width)
|
||||
|
||||
footer:onPageUpdate(100)
|
||||
assert.are.same(183, footer.progress_bar.width)
|
||||
assert.are.same(397, footer.text_width)
|
||||
assert.are.same(191, footer.progress_bar.width)
|
||||
assert.are.same(389, footer.text_width)
|
||||
end)
|
||||
|
||||
it("should support chapter markers", function()
|
||||
@@ -152,10 +157,10 @@ describe("Readerfooter module", function()
|
||||
local footer = readerui.view.footer
|
||||
footer:onPageUpdate(1)
|
||||
assert.are.same({
|
||||
2, 4, 7, 8, 24, 31, 38, 45, 55, 56, 59, 71, 77, 92, 97, 100, 113,
|
||||
121, 131, 134, 148, 156, 160, 163, 166, 175, 180, 182
|
||||
3, 6, 9, 10, 26, 33, 40, 47, 57, 58, 61, 73, 79, 94, 99, 102, 115,
|
||||
123, 133, 136, 151, 159, 163, 167, 170, 179, 184, 186,
|
||||
}, footer.progress_bar.ticks)
|
||||
assert.are.same(202, footer.progress_bar.last)
|
||||
assert.are.same(204, footer.progress_bar.last)
|
||||
end)
|
||||
|
||||
it("should schedule/unschedule auto refresh time task", function()
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
require("commonrequire")
|
||||
local DocumentRegistry = require("document/documentregistry")
|
||||
local ReaderUI = require("apps/reader/readerui")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local Screen = require("device").screen
|
||||
local Geom = require("ui/geometry")
|
||||
local DEBUG = require("dbg")
|
||||
|
||||
local sample_epub = "spec/front/unit/data/juliet.epub"
|
||||
local sample_pdf = "spec/front/unit/data/sample.pdf"
|
||||
|
||||
describe("Readerhighlight module", function()
|
||||
local DocumentRegistry, ReaderUI, UIManager, Screen, Geom, dbg
|
||||
setup(function()
|
||||
require("commonrequire")
|
||||
DocumentRegistry = require("document/documentregistry")
|
||||
ReaderUI = require("apps/reader/readerui")
|
||||
UIManager = require("ui/uimanager")
|
||||
Screen = require("device").screen
|
||||
Geom = require("ui/geometry")
|
||||
dbg = require("dbg")
|
||||
end)
|
||||
|
||||
local function highlight_single_word(readerui, pos0)
|
||||
readerui.highlight:onHold(nil, { pos = pos0 })
|
||||
readerui.highlight:onHoldRelease()
|
||||
@@ -41,24 +41,30 @@ describe("Readerhighlight module", function()
|
||||
UIManager:close(readerui.highlight.highlight_dialog)
|
||||
readerui.highlight:onTap(nil, { pos = pos2 })
|
||||
assert.truthy(readerui.highlight.edit_highlight_dialog)
|
||||
UIManager:scheduleIn(2, function()
|
||||
UIManager:nextTick(function()
|
||||
UIManager:close(readerui.highlight.edit_highlight_dialog)
|
||||
UIManager:close(readerui)
|
||||
end)
|
||||
UIManager:run()
|
||||
end
|
||||
|
||||
describe("highlight for EPUB documents", function()
|
||||
local page = 10
|
||||
local readerui
|
||||
setup(function()
|
||||
local sample_epub = "spec/front/unit/data/juliet.epub"
|
||||
readerui = ReaderUI:new{
|
||||
document = DocumentRegistry:openDocument(sample_epub),
|
||||
}
|
||||
end)
|
||||
before_each(function()
|
||||
UIManager:quit()
|
||||
UIManager:show(readerui)
|
||||
readerui.rolling:onGotoPage(page)
|
||||
UIManager:show(readerui)
|
||||
-- HACK: Mock UIManager:run x and y for readerui.dimen
|
||||
-- TODO: refactor readerview's dimen handling so we can get rid of
|
||||
-- this workaround
|
||||
readerui:paintTo(Screen.bb, 0, 0)
|
||||
end)
|
||||
after_each(function()
|
||||
readerui.highlight:clear()
|
||||
@@ -69,18 +75,25 @@ describe("Readerhighlight module", function()
|
||||
assert.truthy(readerui.view.highlight.saved[page])
|
||||
end)
|
||||
it("should highlight text", function()
|
||||
highlight_text(readerui, Geom:new{ x = 260, y = 60 }, Geom:new{ x = 260, y = 90 })
|
||||
highlight_text(readerui,
|
||||
Geom:new{ x = 260, y = 60 },
|
||||
Geom:new{ x = 260, y = 90 })
|
||||
Screen:shot("screenshots/reader_highlight_text_epub.png")
|
||||
assert.truthy(readerui.view.highlight.saved[page])
|
||||
end)
|
||||
it("should response on tap gesture", function()
|
||||
tap_highlight_text(readerui, Geom:new{ x = 260, y = 60 }, Geom:new{ x = 260, y = 90 }, Geom:new{ x = 260, y = 80 })
|
||||
tap_highlight_text(readerui,
|
||||
Geom:new{ x = 62, y = 374 },
|
||||
Geom:new{ x = 484, y = 374 },
|
||||
Geom:new{ x = 331, y = 374 })
|
||||
Screen:shot("screenshots/reader_tap_highlight_text_epub.png")
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("highlight for PDF documents", function()
|
||||
local readerui
|
||||
setup(function()
|
||||
local sample_pdf = "spec/front/unit/data/sample.pdf"
|
||||
readerui = ReaderUI:new{
|
||||
document = DocumentRegistry:openDocument(sample_pdf),
|
||||
}
|
||||
@@ -103,7 +116,10 @@ describe("Readerhighlight module", function()
|
||||
Screen:shot("screenshots/reader_highlight_text_pdf.png")
|
||||
end)
|
||||
it("should response on tap gesture", function()
|
||||
tap_highlight_text(readerui, Geom:new{ x = 260, y = 70 }, Geom:new{ x = 260, y = 150 }, Geom:new{ x = 280, y = 110 })
|
||||
tap_highlight_text(readerui,
|
||||
Geom:new{ x = 260, y = 70 },
|
||||
Geom:new{ x = 260, y = 150 },
|
||||
Geom:new{ x = 280, y = 110 })
|
||||
Screen:shot("screenshots/reader_tap_highlight_text_pdf.png")
|
||||
end)
|
||||
end)
|
||||
@@ -138,6 +154,7 @@ describe("Readerhighlight module", function()
|
||||
end)
|
||||
after_each(function()
|
||||
readerui.highlight:clear()
|
||||
readerui.document.configurable.text_wrap = 0
|
||||
end)
|
||||
it("should highlight single word", function()
|
||||
highlight_single_word(readerui, Geom:new{ x = 260, y = 70 })
|
||||
|
||||
@@ -91,6 +91,8 @@ describe("ReaderLink module", function()
|
||||
local readerui = ReaderUI:new{
|
||||
document = DocumentRegistry:openDocument(sample_pdf),
|
||||
}
|
||||
readerui.paging:onGotoPage(1)
|
||||
assert.is.same(1, readerui.paging.current_page)
|
||||
readerui.view:onSetScrollMode(true)
|
||||
assert.is.same(true, readerui.view.page_scroll)
|
||||
readerui.paging:onTapForward()
|
||||
|
||||
@@ -28,6 +28,11 @@ describe("Readerpaging module", function()
|
||||
|
||||
describe("Scroll mode", function()
|
||||
setup(function()
|
||||
local purgeDir = require("ffi/util").purgeDir
|
||||
local DocSettings = require("docsettings")
|
||||
purgeDir(DocSettings:getSidecarDir(sample_pdf))
|
||||
os.remove(DocSettings:getHistoryPath(sample_pdf))
|
||||
|
||||
readerui = require("apps/reader/readerui"):new{
|
||||
document = require("document/documentregistry"):openDocument(sample_pdf),
|
||||
}
|
||||
|
||||
@@ -1,15 +1,21 @@
|
||||
require("commonrequire")
|
||||
local DocumentRegistry = require("document/documentregistry")
|
||||
local ReaderUI = require("apps/reader/readerui")
|
||||
local Event = require("ui/event")
|
||||
local DEBUG = require("dbg")
|
||||
|
||||
describe("Readerrolling module", function()
|
||||
local sample_epub = "spec/front/unit/data/juliet.epub"
|
||||
local readerui = ReaderUI:new{
|
||||
document = DocumentRegistry:openDocument(sample_epub),
|
||||
}
|
||||
local rolling = readerui.rolling
|
||||
local DocumentRegistry, ReaderUI, Event, DEBUG
|
||||
local readerui, rolling
|
||||
|
||||
setup(function()
|
||||
require("commonrequire")
|
||||
DocumentRegistry = require("document/documentregistry")
|
||||
ReaderUI = require("apps/reader/readerui")
|
||||
Event = require("ui/event")
|
||||
DEBUG = require("dbg")
|
||||
|
||||
local sample_epub = "spec/front/unit/data/juliet.epub"
|
||||
readerui = ReaderUI:new{
|
||||
document = DocumentRegistry:openDocument(sample_epub),
|
||||
}
|
||||
rolling = readerui.rolling
|
||||
end)
|
||||
|
||||
describe("test in portrait screen mode", function()
|
||||
it("should goto portrait screen mode", function()
|
||||
readerui:handleEvent(Event:new("ChangeScreenMode", "portrait"))
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
require("commonrequire")
|
||||
local DocumentRegistry = require("document/documentregistry")
|
||||
local ReaderUI = require("apps/reader/readerui")
|
||||
local DEBUG = require("dbg")
|
||||
|
||||
local sample_epub = "spec/front/unit/data/juliet.epub"
|
||||
local sample_pdf = "spec/front/unit/data/sample.pdf"
|
||||
|
||||
describe("Readersearch module", function()
|
||||
local sample_epub = "spec/front/unit/data/juliet.epub"
|
||||
local sample_pdf = "spec/front/unit/data/sample.pdf"
|
||||
local DocumentRegistry, ReaderUI, dbg
|
||||
|
||||
setup(function()
|
||||
require("commonrequire")
|
||||
DocumentRegistry = require("document/documentregistry")
|
||||
ReaderUI = require("apps/reader/readerui")
|
||||
dbg = require("dbg")
|
||||
end)
|
||||
|
||||
describe("search API for EPUB documents", function()
|
||||
local doc, search, rolling
|
||||
setup(function()
|
||||
@@ -26,7 +29,7 @@ describe("Readersearch module", function()
|
||||
if words then
|
||||
for _, word in ipairs(words) do
|
||||
local pageno = doc:getPageFromXPointer(word.start)
|
||||
--DEBUG("found at pageno", pageno)
|
||||
--dbg("found at pageno", pageno)
|
||||
assert.truthy(pageno <= i)
|
||||
end
|
||||
end
|
||||
@@ -41,7 +44,7 @@ describe("Readersearch module", function()
|
||||
if words then
|
||||
for _, word in ipairs(words) do
|
||||
local pageno = doc:getPageFromXPointer(word.start)
|
||||
--DEBUG("found at pageno", pageno)
|
||||
--dbg("found at pageno", pageno)
|
||||
assert.truthy(pageno >= i)
|
||||
end
|
||||
end
|
||||
@@ -53,7 +56,7 @@ describe("Readersearch module", function()
|
||||
local words = search:searchFromStart("Verona")
|
||||
assert.truthy(words)
|
||||
local pageno = doc:getPageFromXPointer(words[1].start)
|
||||
assert.are.equal(7, pageno)
|
||||
assert.are.equal(9, pageno)
|
||||
end
|
||||
for i = 1, 5, 1 do
|
||||
rolling:onGotoPage(i)
|
||||
@@ -67,7 +70,7 @@ describe("Readersearch module", function()
|
||||
local words = search:searchFromEnd("Verona")
|
||||
assert.truthy(words)
|
||||
local pageno = doc:getPageFromXPointer(words[1].start)
|
||||
assert.are.equal(199, pageno)
|
||||
assert.are.equal(203, pageno)
|
||||
end
|
||||
for i = 230, 235, 1 do
|
||||
rolling:onGotoPage(i)
|
||||
@@ -82,7 +85,7 @@ describe("Readersearch module", function()
|
||||
while words do
|
||||
count = count + #words
|
||||
for _, word in ipairs(words) do
|
||||
--DEBUG("found word", word.start)
|
||||
--dbg("found word", word.start)
|
||||
end
|
||||
doc:gotoXPointer(words[1].start)
|
||||
words = search:searchNext("Verona", 0)
|
||||
@@ -135,7 +138,7 @@ describe("Readersearch module", function()
|
||||
paging:onGotoPage(i)
|
||||
local words = search:searchFromCurrent("test", 1)
|
||||
if words then
|
||||
DEBUG("search backward: found at page", words.page)
|
||||
dbg("search backward: found at page", words.page)
|
||||
assert.truthy(words.page <= i)
|
||||
end
|
||||
end
|
||||
@@ -147,7 +150,7 @@ describe("Readersearch module", function()
|
||||
paging:onGotoPage(i)
|
||||
local words = search:searchFromCurrent("test", 0)
|
||||
if words then
|
||||
DEBUG("search forward: found at page", words.page)
|
||||
dbg("search forward: found at page", words.page)
|
||||
assert.truthy(words.page >= i)
|
||||
end
|
||||
end
|
||||
@@ -184,7 +187,7 @@ describe("Readersearch module", function()
|
||||
local words = search:searchFromCurrent("test", 0)
|
||||
while words do
|
||||
count = count + #words
|
||||
--DEBUG("found words", #words, words.page)
|
||||
--dbg("found words", #words, words.page)
|
||||
paging:onGotoPage(words.page)
|
||||
words = search:searchNext("test", 0)
|
||||
end
|
||||
|
||||
@@ -1,15 +1,20 @@
|
||||
require("commonrequire")
|
||||
local DocumentRegistry = require("document/documentregistry")
|
||||
local ReaderUI = require("apps/reader/readerui")
|
||||
local DEBUG = require("dbg")
|
||||
|
||||
describe("Readertoc module", function()
|
||||
local sample_epub = "spec/front/unit/data/juliet.epub"
|
||||
local readerui = ReaderUI:new{
|
||||
document = DocumentRegistry:openDocument(sample_epub),
|
||||
}
|
||||
local toc = readerui.toc
|
||||
local toc_max_depth = nil
|
||||
local DocumentRegistry, ReaderUI, DEBUG
|
||||
local readerui, toc, toc_max_depth
|
||||
|
||||
setup(function()
|
||||
require("commonrequire")
|
||||
DocumentRegistry = require("document/documentregistry")
|
||||
ReaderUI = require("apps/reader/readerui")
|
||||
DEBUG = require("dbg")
|
||||
|
||||
local sample_epub = "spec/front/unit/data/juliet.epub"
|
||||
readerui = ReaderUI:new{
|
||||
document = DocumentRegistry:openDocument(sample_epub),
|
||||
}
|
||||
toc = readerui.toc
|
||||
end)
|
||||
|
||||
it("should get max toc depth", function()
|
||||
toc_max_depth = toc:getMaxDepth()
|
||||
assert.are.same(2, toc_max_depth)
|
||||
@@ -50,24 +55,24 @@ describe("Readertoc module", function()
|
||||
end)
|
||||
end)
|
||||
it("should get page of next chapter", function()
|
||||
assert.are.same(24, toc:getNextChapter(10, 0))
|
||||
assert.are.same(113, toc:getNextChapter(100, 0))
|
||||
assert.are.same(26, toc:getNextChapter(10, 0))
|
||||
assert.are.same(102, toc:getNextChapter(100, 0))
|
||||
assert.are.same(nil, toc:getNextChapter(200, 0))
|
||||
end)
|
||||
it("should get page of previous chapter", function()
|
||||
assert.are.same(8, toc:getPreviousChapter(10, 0))
|
||||
assert.are.same(97, toc:getPreviousChapter(100, 0))
|
||||
assert.are.same(182, toc:getPreviousChapter(200, 0))
|
||||
assert.are.same(9, toc:getPreviousChapter(10, 0))
|
||||
assert.are.same(99, toc:getPreviousChapter(100, 0))
|
||||
assert.are.same(186, toc:getPreviousChapter(200, 0))
|
||||
end)
|
||||
it("should get page left of chapter", function()
|
||||
assert.are.same(13, toc:getChapterPagesLeft(10, 0))
|
||||
assert.are.same(12, toc:getChapterPagesLeft(100, 0))
|
||||
assert.are.same(15, toc:getChapterPagesLeft(10, 0))
|
||||
assert.are.same(12, toc:getChapterPagesLeft(102, 0))
|
||||
assert.are.same(nil, toc:getChapterPagesLeft(200, 0))
|
||||
end)
|
||||
it("should get page done of chapter", function()
|
||||
assert.are.same(2, toc:getChapterPagesDone(10, 0))
|
||||
assert.are.same(0, toc:getChapterPagesDone(100, 0))
|
||||
assert.are.same(18, toc:getChapterPagesDone(200, 0))
|
||||
assert.are.same(2, toc:getChapterPagesDone(12, 0))
|
||||
assert.are.same(0, toc:getChapterPagesDone(99, 0))
|
||||
assert.are.same(18, toc:getChapterPagesDone(204, 0))
|
||||
end)
|
||||
describe("collasible TOC", function()
|
||||
it("should collapse the secondary toc nodes by default", function()
|
||||
|
||||
Reference in New Issue
Block a user