public SetGlobalObject ( string objname, object value ) : void | ||
objname | string | |
value | object | |
Результат | void |
public void ExecuteRedefinedNew() { Machine machine = new Machine(); IClass cls = this.CompileClass( "Rectangle", new string[] { "x", "y" }, new string[] { "initialize x := 10. y := 20" }, new string[] { "new ^self basicNew initialize" }); machine.SetGlobalObject("Rectangle", cls); Block block = this.compiler.CompileBlock("^Rectangle new"); Assert.IsNotNull(block); object obj = block.Execute(machine, null); Assert.IsNotNull(obj); Assert.IsInstanceOfType(obj, typeof(IObject)); Assert.AreEqual(cls, ((IObject)obj).Behavior); IObject iobj = (IObject)obj; Assert.AreEqual(2, iobj.Behavior.NoInstanceVariables); Assert.AreEqual(10, iobj[0]); Assert.AreEqual(20, iobj[1]); }
public void ExecuteBasicInstVarAtPut() { Machine machine = new Machine(); IClass cls = this.CompileClass( "Rectangle", new string[] { "x", "y" }, new string[] { "x ^x", "x: newX x := newX", "y ^y", "y: newY y := newY" }); IObject iobj = (IObject)cls.NewObject(); machine.SetGlobalObject("aRectangle", iobj); Block block = this.compiler.CompileBlock("aRectangle basicInstVarAt: 1 put: 200"); Assert.IsNotNull(block); block.Execute(machine, null); Assert.AreEqual(200, iobj[0]); Assert.IsNull(iobj[1]); }
public void ExecuteNew() { Machine machine = new Machine(); IClass cls = this.CompileClass( "Rectangle", new string[] { "x", "y" }, null); cls.DefineClassMethod(new BehaviorDoesNotUnderstandMethod(machine, cls)); machine.SetGlobalObject("Rectangle", cls); Block block = this.compiler.CompileBlock("^Rectangle new"); Assert.IsNotNull(block); object obj = block.Execute(machine, null); Assert.IsNotNull(obj); Assert.IsInstanceOfType(obj, typeof(IObject)); Assert.AreEqual(cls, ((IObject)obj).Behavior); }
public void ExecuteBasicInstAt() { Machine machine = new Machine(); IClass cls = CompileClass( "Rectangle", new string[] { "x", "y" }, new string[] { "x ^x", "x: newX x := newX", "y ^y", "y: newY y := newY" }); IObject iobj = (IObject)cls.NewObject(); machine.SetGlobalObject("aRectangle", iobj); iobj[0] = 100; Parser compiler = new Parser("^aRectangle basicInstVarAt: 1"); Block block = compiler.CompileBlock(); Assert.IsNotNull(block); object result = block.Execute(machine, null); Assert.AreEqual(100, result); }
public void ExecuteBasicInstSizeInRectangle() { Machine machine = new Machine(); IClass cls = this.CompileClass( "Rectangle", new string[] { "x", "y" }, new string[] { "x ^x", "x: newX x := newX", "y ^y", "y: newY y := newY" }); machine.SetGlobalObject("aRectangle", cls.NewObject()); Block block = this.compiler.CompileBlock("^aRectangle basicInstSize"); Assert.IsNotNull(block); object result = block.Execute(machine, null); Assert.AreEqual(2, result); }
public void ExecuteBasicNew() { Machine machine = new Machine(); IClass cls = CompileClass( "Rectangle", new string[] { "x", "y" }, null); machine.SetGlobalObject("Rectangle", cls); Parser compiler = new Parser("^Rectangle basicNew"); Block block = compiler.CompileBlock(); Assert.IsNotNull(block); object obj = block.Execute(machine, null); Assert.IsNotNull(obj); Assert.IsInstanceOfType(obj, typeof(IObject)); Assert.AreEqual(cls, ((IObject)obj).Behavior); }
public void GetGlobalNames() { Machine machine = new Machine(); machine.SetGlobalObject("One", 1); var names = machine.GetGlobalNames(); Assert.IsNotNull(names); Assert.IsTrue(names.Contains("One")); Assert.IsTrue(names.Contains("UndefinedObject")); }
public void SetGlobalVariable() { Machine machine = new Machine(); machine.SetGlobalObject("One", 1); Assert.AreEqual(1, machine.GetGlobalObject("One")); }
public void SerializeAndDeserializeCompositeObject() { Machine machine = new Machine(true); BaseClass cls = new BaseClass("MyClass", machine); BaseObject bso1 = new BaseObject(cls, new object[] { 1, 2, 3 }); BaseObject bso2 = new BaseObject(cls, new object[] { 2, 3, 4 }); BaseObject bso3 = new BaseObject(cls, new object[] { 4, 5, 6 }); BaseObject bo = new BaseObject(cls, new object[] { bso1, bso2, bso3, bso2 }); bso3[2] = bo; BinaryFormatter formatter = new BinaryFormatter(); BaseObject bo2; Machine machine2; BaseClass cls2; using (MemoryStream stream = new MemoryStream()) { formatter.Serialize(stream, bo); stream.Seek(0, SeekOrigin.Begin); machine2 = new Machine(true); Assert.AreSame(Machine.Current, machine2); cls2 = new BaseClass("MyClass", machine2); machine2.SetGlobalObject("MyClass", cls2); bo2 = (BaseObject)formatter.Deserialize(stream); } Assert.IsNotNull(bo2[0]); Assert.IsNotNull(bo2[1]); Assert.IsNotNull(bo2[2]); Assert.IsNotNull(bo2[3]); Assert.AreEqual(bo2[1], bo2[3]); Assert.IsNotNull(bo2.Behavior); Assert.AreSame(cls2, bo2.Behavior); Assert.IsInstanceOfType(bo2[0], typeof(BaseObject)); Assert.IsInstanceOfType(bo2[1], typeof(BaseObject)); Assert.IsInstanceOfType(bo2[2], typeof(BaseObject)); Assert.IsInstanceOfType(bo2[3], typeof(BaseObject)); BaseObject bso32 = (BaseObject)bo2[2]; Assert.AreSame(cls2, bso32.Behavior); Assert.AreSame(bo2, bso32[2]); Assert.AreEqual(cls, bo.Behavior); }
public void SerializeAndDeserializeSimpleObject() { Machine machine = new Machine(); BaseClass cls = new BaseClass("MyClass", machine); BaseObject bo = new BaseObject(cls, new object[] { 1, 2, 3 }); BinaryFormatter formatter = new BinaryFormatter(); BaseObject bo2; Machine machine2; BaseClass cls2; using (MemoryStream stream = new MemoryStream()) { formatter.Serialize(stream, bo); stream.Seek(0, SeekOrigin.Begin); machine2 = new Machine(true); Assert.AreSame(Machine.Current, machine2); cls2 = new BaseClass("MyClass", machine2); machine2.SetGlobalObject("MyClass", cls2); bo2 = (BaseObject)formatter.Deserialize(stream); } Assert.AreEqual(1, bo2[0]); Assert.AreEqual(2, bo2[1]); Assert.AreEqual(3, bo2[2]); Assert.IsNotNull(bo2.Behavior); Assert.AreSame(cls2, bo2.Behavior); Assert.AreEqual(cls, bo.Behavior); }