15 |
# file for more details. |
# file for more details. |
16 |
# |
# |
17 |
|
|
|
""" |
|
|
A variant of saving.test, for saving with gzz.storm code |
|
|
instead of saving with gzz.mediaserver code. |
|
|
|
|
|
XXX Stores the spans in a Mediaserver and |
|
|
the versions in a StormPool currently... |
|
|
because gzz.media doesn't work with Storm yet |
|
|
""" |
|
|
|
|
18 |
import gzz, java |
import gzz, java |
19 |
|
|
20 |
from gzz import * |
FilerGroup = gzz.storm.util.SimpleStormFiler.Group |
|
from gzz.impl import * |
|
|
from gzz.media import * |
|
|
from gzz.media.impl import Enfilade1DImpl, PageImageScroll |
|
|
from gzz.slices import SliceVersion |
|
|
from gzz.slices.YAMLVersionFormatter import * |
|
|
from gzz.storm.impl import * |
|
|
from gzz.storm.util import StormFiler |
|
|
from gzz.util import * |
|
|
|
|
|
from java.io import * |
|
|
from java.util import * |
|
|
|
|
|
from test.tools import tools |
|
|
|
|
|
serv = gzz.mediaserver.SimpleMediaserver(gzz.mediaserver.storage.TransientStorer()) |
|
|
pool = TransientPool(java.util.Collections.singleton(DefaultPointerIndexType.type)) |
|
|
enfMaker = Enfilade1DImpl.Enfilade1DImplMaker() |
|
|
filers = StormFiler.Group(SliceVersion.EMPTY_VERSION, pool, |
|
|
YAMLVersionFormat(serv, enfMaker)) |
|
|
filer = filers.getFiler("FOO") |
|
|
space = ModularSpace(*tools.spaceArgList()) |
|
|
|
|
|
def load(): |
|
|
ver = filer.load() |
|
|
print ver |
|
|
return ModularSpace(ver, *tools.spaceArgList()) |
|
|
|
|
|
def save(space): |
|
|
filers.saveAll(space.getSlicer().exportAll()) |
|
|
|
|
|
|
|
|
def testSaveLoad(): |
|
|
"""Test space saving and re-loading""" |
|
|
a,b,c = space.N(), space.N(), space.N() |
|
|
a.connect(space.getDim(b), c) |
|
|
a.setText("foo") |
|
|
|
|
|
ids = pool.getIds() |
|
|
save(space) |
|
|
print ids, pool.getIds() |
|
|
assert ids != pool.getIds() |
|
|
|
|
|
ids = pool.getIds() |
|
|
save(space) |
|
|
print ids, pool.getIds() |
|
|
assert ids == pool.getIds() |
|
|
|
|
|
s2 = load() |
|
|
|
|
|
ids = pool.getIds() |
|
|
save(s2) |
|
|
print ids, pool.getIds() |
|
|
assert ids == pool.getIds() |
|
|
|
|
|
a2, b2, c2 = [s2.getCell(cell.getId()) for cell in (a,b,c)] |
|
|
assert a2.s(s2.getDim(b2)) == c2 |
|
|
assert a2.t() == "foo" |
|
|
|
|
|
a2.insertText(2, "bing") |
|
|
c2.setText("bar") |
|
|
a2.insert(s2.getDim(b2), 1, b2) |
|
|
|
|
|
ids = pool.getIds() |
|
|
save(s2) |
|
|
print ids, pool.getIds() |
|
|
assert ids != pool.getIds() |
|
|
s3 = load() |
|
|
|
|
|
a3, b3, c3 = [s3.getCell(cell.getId()) for cell in (a,b,c)] |
|
|
assert a3.s(s3.getDim(b3)) == b3 |
|
|
assert b3.s(s3.getDim(b3)) == c3 |
|
|
assert a3.t() == "fobingo" |
|
|
assert c3.t() == "bar" |
|
|
|
|
|
ids = pool.getIds() |
|
|
save(s3) |
|
|
print ids, pool.getIds() |
|
|
assert ids == pool.getIds() |
|
|
|
|
|
|
|
|
def testJoinSpans(): |
|
|
"""Test that adjacent spans are joined when saving""" |
|
|
|
|
|
c = space.N() |
|
|
|
|
|
c.insertText(0, "f") |
|
|
c.insertText(1, "oo") |
|
|
c.insertText(3, "bar") |
|
|
c.insertText(3, ""); # empty spans must be removed, too |
|
|
|
|
|
assert c.t() == "foobar" |
|
|
assert space.getCellTexter().getEnfilade(c, None).getList().size() == 4 |
|
|
|
|
|
v = space.getSlicer().export(space.getSlicer().getSlice0()) |
|
|
enf = v.contents.get(c.getId()) |
|
|
assert enf.makeString() == "foobar" |
|
|
assert enf.getList().size() == 1 |
|
21 |
|
|
22 |
|
execfile('lava/test/gzz/impl/storm_saving.meta') |
|
def testSavePageSpans(): |
|
|
""" |
|
|
Test saving and re-loading page spans. |
|
|
|
|
|
Exploits an implementation detail of PageImageScroll: it doesn't look |
|
|
at the actual block, just at the mstmpimg version of it. So we can |
|
|
create an empty block with content type application/pdf and expect the |
|
|
test to work. |
|
|
""" |
|
|
|
|
|
# Create dummy pageimage scroll |
|
|
id = serv.addDatum("", "application/pdf") |
|
|
|
|
|
c = space.N() |
|
|
empty = space.getCellTexter().getEnfilade(c, None) |
|
|
scr = ScrollBlockManager.getScrollBlock(serv, id) |
|
|
scr.forcelengthKLUDGE(17); |
|
|
|
|
|
space.getCellTexter().setEnfilade(c, empty.plus(scr.getCurrent()).plus( |
|
|
scr.getCurrent().subArea(5,9,7,7,23,23))) |
|
|
|
|
|
save(space) |
|
|
s2 = load() |
|
|
|
|
|
c2 = s2.getCell(c.getId()) |
|
|
|
|
|
print s2.getCellTexter().getEnfilade(c2, None) |
|
|
print space.getCellTexter().getEnfilade(c, None) |
|
|
|
|
|
assert s2.getCellTexter().getEnfilade(c2, None) == \ |
|
|
space.getCellTexter().getEnfilade(c, None) |
|
|
|
|
|
save(s2) |
|
|
s3 = load() |
|