diff --git a/.busted b/.busted new file mode 100644 index 000000000..4343ab3d9 --- /dev/null +++ b/.busted @@ -0,0 +1,6 @@ +return { + default = { + verbose = true, + ROOT = "spec/front/unit", + }, +} diff --git a/.gitignore b/.gitignore index 6aabe7d43..e4a04a2d8 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ git-rev tags test/* *.tar +spec/unit/data emu diff --git a/Makefile b/Makefile index 1af9ad9ca..320f765db 100644 --- a/Makefile +++ b/Makefile @@ -38,6 +38,11 @@ endif for f in $(INSTALL_FILES); do \ ln -sf ../../$$f $(INSTALL_DIR)/koreader/; \ done + # install front spec + cd $(INSTALL_DIR)/koreader/spec && test -e front || \ + ln -sf ../../../../spec ./front + cd $(INSTALL_DIR)/koreader/spec/front/unit && test -e data || \ + ln -sf ../../test ./data # install plugins cp -r plugins/* $(INSTALL_DIR)/koreader/plugins/ cp -rpL resources/fonts/* $(INSTALL_DIR)/koreader/fonts/ @@ -54,8 +59,16 @@ endif $(KOR_BASE)/$(OUTPUT_DIR)/luajit: $(MAKE) -C $(KOR_BASE) +$(INSTALL_DIR)/koreader/.busted: + test -e $(INSTALL_DIR)/koreader/.busted || \ + ln -sf ../../.busted $(INSTALL_DIR)/koreader + +testfront: $(INSTALL_DIR)/koreader/.busted + cd $(INSTALL_DIR)/koreader && busted -l ./luajit + test: $(MAKE) -C $(KOR_BASE) test + $(MAKE) testfront .PHONY: test diff --git a/frontend/ui/device.lua b/frontend/ui/device.lua index 735b6ec43..2526b50c3 100644 --- a/frontend/ui/device.lua +++ b/frontend/ui/device.lua @@ -2,7 +2,7 @@ local KindlePowerD = require("ui/device/kindlepowerd") local KoboPowerD = require("ui/device/kobopowerd") local BasePowerD = require("ui/device/basepowerd") local Screen = require("ui/device/screen") --- util +local util = require("ffi/util") -- lfs local Device = { diff --git a/spec/unit/document_spec.lua b/spec/unit/document_spec.lua new file mode 100644 index 000000000..73ed68895 --- /dev/null +++ b/spec/unit/document_spec.lua @@ -0,0 +1,62 @@ +require "defaults" +require "libs/libkoreader-luagettext" +package.path = "?.lua;common/?.lua;frontend/?.lua" +package.cpath = "?.so;common/?.so;/usr/lib/lua/?.so" + +-- global einkfb for Screen +einkfb = require("ffi/framebuffer") +-- do not show SDL window +einkfb.dummy = true + +local Screen = require("ui/screen") +local DocSettings = require("docsettings") +G_reader_settings = DocSettings:open(".reader") +local DocumentRegistry = require("document/documentregistry") +local DEBUG = require("dbg") + +-- screen should be inited for crengine +Screen:init() + +describe("PDF document module", function() + local sample_pdf = "spec/front/unit/data/tall.pdf" + it("should open document", function() + doc = DocumentRegistry:openDocument(sample_pdf) + assert.truthy(doc) + end) + it("should get page dimensions", function() + local dimen = doc:getPageDimensions(1, 1, 0) + assert.are.same(dimen.w, 567) + assert.are.same(dimen.h, 1418) + end) + local pos0 = {page = 1, x = 0, y = 20} + local pos1 = {page = 1, x = 300, y = 120} + local pboxes = { + {x = 26, y = 42, w = 240, h = 22}, + {x = 48, y = 82, w = 185, h = 22}, + } + it("should clip page rect to PNG file", function() + doc:clipPagePNGFile(pos0, pos1, nil, nil, "/tmp/clip0.png") + doc:clipPagePNGFile(pos0, pos1, pboxes, "lighten", "/tmp/clip1.png") + end) + it("should clip page rect to PNG string", function() + local clip0 = doc:clipPagePNGString(pos0, pos1, nil, nil) + assert.truthy(clip0) + local clip1 = doc:clipPagePNGString(pos0, pos1, pboxes, "lighten") + assert.truthy(clip1) + end) + it("should close document", function() + doc:close() + end) +end) + +describe("EPUB document module", function() + local sample_epub = "spec/front/unit/data/leaves_of_grass.epub" + it("should open document", function() + doc = DocumentRegistry:openDocument(sample_epub) + assert.truthy(doc) + doc:close() + end) + it("should close document", function() + doc:close() + end) +end)