Sha256: 4915413f754a11537905d303eeec3e149d80f62b406cec4212c39713edbe1467
Contents?: true
Size: 1.57 KB
Versions: 3
Compression:
Stored size: 1.57 KB
Contents
require File.dirname(__FILE__) + '/spec_helper.rb' def get_refcnt(pobject) raise 'Cannot work with a nil object' if pobject.nil? if pobject.kind_of? Rupy::RubyPyProxy pobject = pobject.pObject.pointer elsif pobject.kind_of? Rupy::PyObject pobject = pobject.pointer end struct = Rupy::Python::PyObjectStruct.new pobject struct[:ob_refcnt] end include TestConstants describe 'Reference Counting' do before :all do Rupy.start @sys = Rupy.import 'sys' @sys.path.append './spec/python_helpers' @objects = Rupy.import 'objects' end after :all do Rupy.stop end it "should be one for a new object" do pyObj = @objects.RubyPythonMockObject.new get_refcnt(pyObj).should == 1 end it "should increase when a new reference is passed into Ruby" do pyObj = @objects.RubyPythonMockObject refcnt = get_refcnt(pyObj) pyObj2 = @objects.RubyPythonMockObject get_refcnt(pyObj).should == (refcnt + 1) end describe Rupy::PyObject do describe "#xIncref" do it "should increase the reference count" do pyObj = @objects.RubyPythonMockObject.new refcnt = get_refcnt(pyObj) pyObj.pObject.xIncref get_refcnt(pyObj).should == refcnt + 1 end end describe "#xDecref" do it "should decrease the reference count" do pyObj = @objects.RubyPythonMockObject.new pyObj.pObject.xIncref refcnt = get_refcnt(pyObj) pointer = pyObj.pObject.pointer pyObj.pObject.xDecref get_refcnt(pointer).should == refcnt - 1 end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
rupy-0.4.2 | spec/refcnt_spec.rb |
rupy-0.4.1 | spec/refcnt_spec.rb |
rupy-0.4.0 | ./spec/refcnt_spec.rb |