Commit c219652d authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent b89415d7
...@@ -422,16 +422,15 @@ func newGhost(class string, oid Oid, jar *Connection) IPersistent { ...@@ -422,16 +422,15 @@ func newGhost(class string, oid Oid, jar *Connection) IPersistent {
} }
xobj := xpobj.Elem() // typ xobj := xpobj.Elem() // typ
base := xobj.FieldByName("Persistent").Addr().Interface().(*Persistent) pbase := xobj.FieldByName("Persistent").Addr().Interface().(*Persistent)
base.jar = jar pbase.jar = jar
base.oid = oid pbase.oid = oid
base.serial = 0 pbase.serial = 0
base.state = GHOST pbase.state = GHOST
obj := xpobj.Interface() obj := xpobj.Interface()
//base.instance = obj.(interface{IPersistent; Ghostable; Stateful}) pbase.instance = obj.(IPersistent)
base.instance = obj.(IPersistent) return pbase.instance
return base.instance
} }
// Broken objects are used to represent loaded ZODB objects with classes that // Broken objects are used to represent loaded ZODB objects with classes that
......
...@@ -56,23 +56,50 @@ func init() { ...@@ -56,23 +56,50 @@ func init() {
} }
func TestPersistent(t *testing.T) { func TestPersistent(t *testing.T) {
assert := require.New(t) checkObj := func(obj IPersistent, jar *Connection, oid Oid, serial Tid, state ObjectState, refcnt int32, loading *loadState) {
xbase := reflect.ValueOf(obj).Elem().FieldByName("Persistent")
pbase := xbase.Addr().Interface().(*Persistent)
badf := func(format string, argv ...interface{}) {
msg := fmt.Sprintf(format, argv...)
t.Fatalf("%#v: %s", obj, msg)
}
// XXX .zclass ?
if pbase.jar != jar {
badf("invalid jar")
}
if pbase.oid != oid {
badf("invalid oid: %s ; want %s", pbase.oid, oid)
}
if pbase.serial != serial {
badf("invalid serial: %s ; want %s", pbase.serial, serial)
}
if pbase.state != state {
badf("invalid state: %s ; want %s", pbase.state, state)
}
if pbase.refcnt != refcnt {
badf("invalid refcnt: %s ; want %s", pbase.refcnt, refcnt)
}
if pbase.instance != obj {
badf("base.instance != obj")
}
// XXX loading too?
}
xobj := newGhost("t.zodb.MyObject", 11, nil) xobj := newGhost("t.zodb.MyObject", 11, nil)
obj, ok := xobj.(*MyObject) obj, ok := xobj.(*MyObject)
if !ok { if !ok {
t.Fatalf("unknown -> %T; want Broken", xobj) t.Fatalf("unknown -> %T; want Broken", xobj)
} }
// XXX .zclass ? checkObj(obj, nil, 11, 0, GHOST, 0, nil)
assert.Equal(obj.jar, (*Connection)(nil))
assert.Equal(obj.oid, Oid(11))
assert.Equal(obj.serial, Tid(0)) // TODO activate - jar has to load, state changes
assert.Equal(obj.state, GHOST) // TODO activate again - refcnt++
assert.Equal(obj.refcnt, int32(0)) // TODO deactivate - refcnt--
assert.Equal(obj.instance, obj) // TODO deactivate - state dropped
assert.Equal(obj.loading, (*loadState)(nil))
} }
// XXX reenable // XXX reenable
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment