2016-02-03 18:35:47 +00:00
|
|
|
describe("Nickel configuation module", function()
|
2016-06-02 04:32:35 +00:00
|
|
|
local lfs, NickelConf
|
|
|
|
setup(function()
|
|
|
|
require("commonrequire")
|
|
|
|
lfs = require("libs/libkoreader-lfs")
|
|
|
|
NickelConf = require("device/kobo/nickel_conf")
|
|
|
|
end)
|
|
|
|
|
2016-02-03 18:35:47 +00:00
|
|
|
describe("Frontlight module", function()
|
|
|
|
it("should read value", function()
|
|
|
|
local fn = os.tmpname()
|
|
|
|
local fd = io.open(fn, "w")
|
|
|
|
fd:write([[
|
|
|
|
[OtherThing]
|
|
|
|
foo=bar
|
|
|
|
[PowerOptions]
|
|
|
|
FrontLightLevel=55
|
2016-02-25 08:54:41 +00:00
|
|
|
FrontLightState=true
|
2016-02-03 18:35:47 +00:00
|
|
|
[YetAnotherThing]
|
|
|
|
bar=baz
|
|
|
|
]])
|
|
|
|
fd:close()
|
|
|
|
|
|
|
|
NickelConf._set_kobo_conf_path(fn)
|
|
|
|
assert.Equals(NickelConf.frontLightLevel.get(), 55)
|
2016-02-25 08:54:41 +00:00
|
|
|
assert.Equals(NickelConf.frontLightState.get(), true)
|
|
|
|
|
|
|
|
os.remove(fn)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it("should also read value", function()
|
|
|
|
local fn = os.tmpname()
|
|
|
|
local fd = io.open(fn, "w")
|
|
|
|
fd:write([[
|
|
|
|
[OtherThing]
|
|
|
|
foo=bar
|
|
|
|
[PowerOptions]
|
|
|
|
FrontLightLevel=30
|
|
|
|
FrontLightState=false
|
|
|
|
[YetAnotherThing]
|
|
|
|
bar=baz
|
|
|
|
]])
|
|
|
|
fd:close()
|
|
|
|
|
|
|
|
NickelConf._set_kobo_conf_path(fn)
|
|
|
|
assert.Equals(NickelConf.frontLightLevel.get(), 30)
|
|
|
|
assert.Equals(NickelConf.frontLightState.get(), false)
|
|
|
|
|
|
|
|
os.remove(fn)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it("should have default value", function()
|
|
|
|
local fn = os.tmpname()
|
|
|
|
local fd = io.open(fn, "w")
|
|
|
|
fd:write([[
|
|
|
|
[OtherThing]
|
|
|
|
foo=bar
|
|
|
|
[YetAnotherThing]
|
|
|
|
bar=baz
|
|
|
|
]])
|
|
|
|
fd:close()
|
|
|
|
|
|
|
|
NickelConf._set_kobo_conf_path(fn)
|
2017-06-14 17:32:16 +00:00
|
|
|
assert.Equals(NickelConf.frontLightLevel.get(), 1)
|
2016-03-02 07:09:14 +00:00
|
|
|
assert.Equals(NickelConf.frontLightState.get(), nil)
|
2016-02-03 18:35:47 +00:00
|
|
|
|
|
|
|
os.remove(fn)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it("should create section", function()
|
|
|
|
local fn = os.tmpname()
|
|
|
|
local fd = io.open(fn, "w")
|
|
|
|
fd:write([[
|
|
|
|
[OtherThing]
|
|
|
|
FrontLightLevel=6
|
|
|
|
]])
|
|
|
|
fd:close()
|
|
|
|
|
|
|
|
NickelConf._set_kobo_conf_path(fn)
|
|
|
|
NickelConf.frontLightLevel.set(100)
|
2016-02-25 08:54:41 +00:00
|
|
|
NickelConf.frontLightState.set(true)
|
2016-02-03 18:35:47 +00:00
|
|
|
|
|
|
|
fd = io.open(fn, "r")
|
|
|
|
assert.Equals(fd:read("*a"), [[
|
|
|
|
[OtherThing]
|
|
|
|
FrontLightLevel=6
|
|
|
|
[PowerOptions]
|
|
|
|
FrontLightLevel=100
|
|
|
|
]])
|
|
|
|
fd:close()
|
|
|
|
os.remove(fn)
|
|
|
|
|
|
|
|
fd = io.open(fn, "w")
|
|
|
|
fd:write("")
|
|
|
|
fd:close()
|
|
|
|
|
|
|
|
NickelConf.frontLightLevel.set(20)
|
2016-02-25 08:54:41 +00:00
|
|
|
NickelConf.frontLightState.set(false)
|
2016-02-03 18:35:47 +00:00
|
|
|
|
|
|
|
fd = io.open(fn, "r")
|
|
|
|
assert.Equals(fd:read("*a"), [[
|
|
|
|
[PowerOptions]
|
|
|
|
FrontLightLevel=20
|
|
|
|
]])
|
|
|
|
fd:close()
|
|
|
|
os.remove(fn)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it("should replace value", function()
|
|
|
|
local fn = os.tmpname()
|
|
|
|
local fd = io.open(fn, "w")
|
|
|
|
fd:write([[
|
|
|
|
[OtherThing]
|
|
|
|
foo=bar
|
|
|
|
[PowerOptions]
|
|
|
|
FrontLightLevel=6
|
2016-02-25 08:54:41 +00:00
|
|
|
FrontLightState=false
|
2016-02-03 18:35:47 +00:00
|
|
|
[YetAnotherThing]
|
|
|
|
bar=baz
|
|
|
|
]])
|
|
|
|
fd:close()
|
|
|
|
|
|
|
|
NickelConf._set_kobo_conf_path(fn)
|
|
|
|
NickelConf.frontLightLevel.set(100)
|
2016-02-25 08:54:41 +00:00
|
|
|
NickelConf.frontLightState.set(true)
|
2016-02-03 18:35:47 +00:00
|
|
|
|
|
|
|
fd = io.open(fn, "r")
|
|
|
|
assert.Equals(fd:read("*a"), [[
|
|
|
|
[OtherThing]
|
|
|
|
foo=bar
|
|
|
|
[PowerOptions]
|
|
|
|
FrontLightLevel=100
|
2016-02-25 08:54:41 +00:00
|
|
|
FrontLightState=true
|
2016-02-03 18:35:47 +00:00
|
|
|
[YetAnotherThing]
|
|
|
|
bar=baz
|
|
|
|
]])
|
|
|
|
fd:close()
|
|
|
|
os.remove(fn)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it("should insert entry", function()
|
|
|
|
local fn = os.tmpname()
|
|
|
|
local fd = io.open(fn, "w")
|
|
|
|
fd:write([[
|
|
|
|
[PowerOptions]
|
|
|
|
foo=bar
|
|
|
|
[OtherThing]
|
|
|
|
bar=baz
|
|
|
|
]])
|
|
|
|
fd:close()
|
|
|
|
|
|
|
|
NickelConf._set_kobo_conf_path(fn)
|
|
|
|
NickelConf.frontLightLevel.set(1)
|
2016-02-25 08:54:41 +00:00
|
|
|
NickelConf.frontLightState.set(true)
|
2016-02-03 18:35:47 +00:00
|
|
|
|
|
|
|
fd = io.open(fn, "r")
|
2016-03-02 07:09:14 +00:00
|
|
|
assert.Equals([[
|
2016-02-03 18:35:47 +00:00
|
|
|
[PowerOptions]
|
|
|
|
foo=bar
|
|
|
|
FrontLightLevel=1
|
|
|
|
[OtherThing]
|
|
|
|
bar=baz
|
2016-03-02 07:09:14 +00:00
|
|
|
]], fd:read("*a"))
|
2016-02-03 18:35:47 +00:00
|
|
|
fd:close()
|
|
|
|
os.remove(fn)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it("should create config file", function()
|
2017-08-08 20:35:40 +00:00
|
|
|
local fd
|
2016-02-03 18:35:47 +00:00
|
|
|
local fn = "/tmp/abcfoobarbaz449"
|
|
|
|
assert.is_not.Equals(lfs.attributes(fn, "mode"), "file")
|
|
|
|
finally(function() os.remove(fn) end)
|
|
|
|
|
|
|
|
NickelConf._set_kobo_conf_path(fn)
|
|
|
|
NickelConf.frontLightLevel.set(15)
|
2016-02-25 08:54:41 +00:00
|
|
|
NickelConf.frontLightState.set(false)
|
2016-02-03 18:35:47 +00:00
|
|
|
|
|
|
|
fd = io.open(fn, "r")
|
|
|
|
assert.Equals([[
|
|
|
|
[PowerOptions]
|
|
|
|
FrontLightLevel=15
|
|
|
|
]],
|
|
|
|
fd:read("*a"))
|
|
|
|
fd:close()
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
end)
|