csharp: Disposing IDisposable objects.

Summary: ref T8423

Reviewers: lauromoura, felipealmeida, YOhoho

Reviewed By: lauromoura

Subscribers: cedric, #reviewers, #committers

Tags: #efl

Maniphest Tasks: T8423

Differential Revision: https://phab.enlightenment.org/D10644
This commit is contained in:
Bruno da Silva Belo 2019-11-14 14:26:16 -03:00 committed by Lauro Moura
parent 37b55172b0
commit cd113d7aae
19 changed files with 482 additions and 18 deletions

View File

@ -29,7 +29,10 @@ internal class ModelHelper
var properties = typeof(T).GetProperties();
foreach (var prop in properties)
{
child.SetProperty(prop.Name, ValueFromProperty(o, prop));
using (var tmp = ValueFromProperty(o, prop))
{
child.SetProperty(prop.Name, tmp);
}
}
}

View File

@ -31,6 +31,7 @@ class TestIntDirections
t.IntOut(original, out received);
Test.AssertEquals(-original, received);
t.Dispose();
}
/*

File diff suppressed because it is too large Load Diff

View File

@ -28,6 +28,7 @@ class TestEo
var testing = new Dummy.TestObject();
var o1 = testing.ReturnNullObject();
Test.Assert(o1 == null);
testing.Dispose();
}
//
@ -42,6 +43,7 @@ class TestEo
var o2 = o1.ReturnObject();
Test.Assert(o2.NativeHandle != IntPtr.Zero);
Test.Assert(o2.NativeHandle == o1.NativeHandle);
testing.Dispose();
}
/* Commented out as adding the event listener seems to prevent it from being GC'd.
public static void destructor_really_frees()
@ -121,12 +123,12 @@ class TestEoInherit
{
Efl.Object loop = new MyObject();
Test.Assert(loop.NativeHandle != System.IntPtr.Zero);
loop.Dispose();
}
private static WeakReference CreateCollectableInherited()
{
var obj = new MyObject();
return new WeakReference(obj);
return new WeakReference(new MyObject());
}
public static void inherited_collected()
@ -147,6 +149,7 @@ class TestEoNames
string name = "Dummy";
obj.SetName(name);
Test.AssertEquals(name, obj.GetName());
obj.Dispose();
}
}
@ -161,6 +164,8 @@ class TestEoParent
var parent_retrieved = child.GetParent() as Dummy.TestObject;
Test.AssertEquals(parent, parent_retrieved);
child.Dispose();
parent.Dispose();
}
public static void parent_inherited_class()
@ -172,6 +177,8 @@ class TestEoParent
Dummy.Numberwrapper parent_retrieved = child.GetParent() as Dummy.Numberwrapper;
Test.AssertEquals(parent, parent_retrieved);
child.Dispose();
parent.Dispose();
}
private class Derived : Dummy.TestObject
@ -190,6 +197,8 @@ class TestEoParent
var parent_from_cast = child.GetParent() as Derived;
Test.AssertEquals(parent, parent_from_cast);
child.Dispose();
parent.Dispose();
}
}
@ -222,7 +231,7 @@ class TestTypedefs
Test.AssertEquals((Dummy.MyInt)ret, input);
Test.AssertEquals(receiver, input);
obj.Dispose();
}
}
@ -262,6 +271,8 @@ class TestEoAccessors
{
Test.AssertEquals(pair.Item1, pair.Item2);
}
lst.Dispose();
obj.Dispose();
}
}
@ -282,6 +293,7 @@ class TestEoFinalize
{
Inherit inherit = new Inherit();
Test.Assert(inherit.finalizeCalled);
inherit.Dispose();
}
}
@ -315,8 +327,11 @@ class TestEoMultipleChildClasses
SecondChild obj2 = new SecondChild();
Test.AssertEquals(2, obj2.receivedValue);
obj.Dispose();
obj = new FirstChild();
Test.AssertEquals(1, obj.receivedValue);
obj2.Dispose();
obj.Dispose();
}
}
@ -329,12 +344,14 @@ class TestCsharpProperties
obj.Name = name;
Test.AssertEquals(name, obj.Name);
obj.Dispose();
}
public static void test_getter_only()
{
var obj = new Dummy.TestObject();
Test.Assert(!obj.Invalidating);
obj.Dispose();
}
public static void test_setter_only()
@ -344,6 +361,7 @@ class TestCsharpProperties
obj.SetterOnly = val;
Test.AssertEquals(val, obj.GetSetterOnly());
obj.Dispose();
}
public static void test_class_property()
@ -359,6 +377,7 @@ class TestCsharpProperties
Dummy.ITestIface iface = new Dummy.TestObject();
iface.IfaceProp = val;
Test.AssertEquals(val, iface.IfaceProp);
iface.Dispose();
}
public static void test_csharp_multi_valued_prop()
@ -367,6 +386,7 @@ class TestCsharpProperties
obj.MultiValuedProp = (1, 2);
var ret = obj.MultiValuedProp;
Test.AssertEquals(ret, (1, 2));
obj.Dispose();
}
}
@ -386,6 +406,7 @@ class TestEoGrandChildrenFinalize
{
Child obj = new Child();
Test.AssertEquals(42, obj.receivedValue);
obj.Dispose();
}
public sealed class GrandChild : Dummy.Child
@ -409,6 +430,7 @@ class TestEoGrandChildrenFinalize
{
GrandChild obj = new GrandChild();
Test.AssertEquals(-42, obj.receivedValue);
obj.Dispose();
}
}
@ -429,7 +451,7 @@ class TestConstructors
var obj = new Dummy.Child(null, a, b, iface_prop);
#endif
Test.AssertEquals(iface_prop, obj.IfaceProp);
obj.Dispose();
#if EFL_BETA
obj = new Dummy.Child(parent: null, ifaceProp : iface_prop, doubleParamsA : a, doubleParamsB : b,
obligatoryBetaCtor : beta,
@ -443,6 +465,7 @@ class TestConstructors
Test.Assert(obj.ObligatoryBetaCtorWasCalled);
Test.Assert(obj.OptionalBetaCtorWasCalled);
#endif
obj.Dispose();
}
public static void test_optional_constructor()
@ -457,6 +480,7 @@ class TestConstructors
var obj = new Dummy.Child(null, a, b);
#endif
Test.Assert(!obj.GetIfaceWasSet());
obj.Dispose();
}
}
@ -470,6 +494,7 @@ class TestInterfaceConcrete
iface.IfaceProp = 1970;
Test.AssertEquals(iface.IfaceProp, 1970);
obj.Dispose();
}
}
@ -482,6 +507,7 @@ class TestProvider
Dummy.Numberwrapper provider = obj.FindProvider(typeof(Dummy.Numberwrapper)) as Dummy.Numberwrapper;
Test.AssertEquals(provider.GetType(), typeof(Dummy.Numberwrapper));
Test.AssertEquals(provider.GetNumber(), 1999);
obj.Dispose();
}
private class ProviderHolder : Dummy.TestObject
@ -526,7 +552,7 @@ class TestProvider
provider = obj.CallFindProviderForIface();
Test.AssertNotNull(provider, msg : "Provider of ITestIFace must not be null");
Test.AssertEquals(provider.Name, obj.ProviderName, "Provider name does not match expected");
obj.Dispose();
}
}
@ -542,6 +568,7 @@ class TestObjectDeletion
part.Del();
Test.AssertNull(obj.OnePart);
obj.Dispose();
}
}
@ -564,12 +591,14 @@ class TestProtectedInterfaceMembers
{
var obj = new Dummy.TestObject();
Test.AssertEquals(obj.CallMethodProtected(42), -42);
obj.Dispose();
}
public static void test_protected_interface_in_inherited_class_called_from_c()
{
var obj = new MyObject();
Test.AssertEquals(obj.CallMethodProtected(42), 42 * 42);
obj.Dispose();
}
public static void test_interface_skipped_protected()
@ -640,6 +669,7 @@ class TestHiddenClasses
var hidden = obj.HiddenObject;
Test.AssertEquals(hidden.Name, "hidden_object");
obj.Dispose();
}
}

View File

@ -72,6 +72,7 @@ class TestEoPromises
loop.Iterate();
Test.Assert(callbackCalled, "Future callback must have been called.");
Test.AssertEquals(receivedValue, sentValue);
obj.Dispose();
}
public static void test_object_promise_cancel()
@ -97,6 +98,7 @@ class TestEoPromises
loop.Iterate();
Test.Assert(callbackCalled, "Future callback must have been called.");
Test.AssertEquals(receivedError, sentError);
obj.Dispose();
}
}
@ -144,6 +146,7 @@ class TestEoAsyncMethods
int receivedValue;
v.Get(out receivedValue);
Test.AssertEquals(receivedValue, sentValue);
obj.Dispose();
}
public static void test_async_cancel()
@ -173,6 +176,8 @@ class TestEoAsyncMethods
}
Test.Assert(raised, "AggregateException must have been raised.");
cancelSrc.Dispose();
obj.Dispose();
}
public static void test_async_reject()
@ -205,6 +210,7 @@ class TestEoAsyncMethods
}
Test.Assert(raised, "AggregateException must have been raised.");
obj.Dispose();
}
}
}

View File

@ -53,6 +53,7 @@ class TestEolianError
var obj = new Overrider();
Test.AssertRaises<Efl.EflException>(obj.CallChildrenRaiseError);
obj.Dispose();
}
// return eina_error
@ -70,6 +71,7 @@ class TestEolianError
error = obj.ReturnsError();
Test.AssertEquals(expected, error);
obj.Dispose();
}
class ReturnOverride : Dummy.TestObject {
@ -97,6 +99,7 @@ class TestEolianError
error = obj.ReturnsError();
Test.AssertEquals(new Eina.Error(expected * 2), error);
obj.Dispose();
}
// events
@ -114,11 +117,13 @@ class TestEolianError
// An event whose managed delegate generates an exception
// must set an eina_error so it can be reported back to
// the managed code
var obj = new Dummy.TestObject();
var obj = new Dummy.TestObject();
Listener listener = new Listener();
obj.EvtWithIntEvent += listener.callback;
Test.AssertRaises<Efl.EflException>(() => { obj.EmitEventWithInt(2); });
Test.AssertRaises<Efl.EflException>(() =>
{ obj.EmitEventWithInt(2); });
obj.Dispose();
}
}
}

View File

@ -36,6 +36,7 @@ class TestEoEvents
Eina.Value v = new Eina.Value(Eina.ValueType.Int32);
v.Set(0);
loop.Quit(v);
v.Dispose();
}
protected void another_callback(object sender, EventArgs e) { }
@ -70,6 +71,7 @@ class TestEoEvents
obj.EmitEventWithString("Some args");
Test.AssertEquals("Some args", received_string);
obj.Dispose();
}
public static void event_with_int_payload()
@ -84,6 +86,7 @@ class TestEoEvents
obj.EmitEventWithInt(-1984);
Test.AssertEquals(-1984, received_int);
obj.Dispose();
}
public static void event_with_bool_payload()
@ -102,6 +105,7 @@ class TestEoEvents
obj.EmitEventWithBool(false);
Test.AssertEquals(false, received_bool);
obj.Dispose();
}
public static void event_with_uint_payload()
@ -115,6 +119,7 @@ class TestEoEvents
obj.EmitEventWithUint(0xbeef);
Test.AssertEquals<uint>(0xbeef, received_uint);
obj.Dispose();
}
public static void event_with_float_payload()
@ -128,6 +133,7 @@ class TestEoEvents
obj.EmitEventWithFloat(3.14f);
Test.AssertAlmostEquals(3.14f, received_float);
obj.Dispose();
}
public static void event_with_double_payload()
@ -142,6 +148,7 @@ class TestEoEvents
obj.EmitEventWithDouble(reference);
Test.AssertAlmostEquals(reference, received_double);
obj.Dispose();
}
public static void event_with_object_payload()
@ -158,6 +165,8 @@ class TestEoEvents
obj.EmitEventWithObj(sent_obj);
Test.AssertEquals(sent_obj, received_obj);
sent_obj.Dispose();
obj.Dispose();
}
public static void event_with_error_payload()
@ -174,6 +183,7 @@ class TestEoEvents
obj.EmitEventWithError(sent_error);
Test.AssertEquals(sent_error, received_error);
obj.Dispose();
}
public static void event_with_struct_payload()
@ -191,6 +201,7 @@ class TestEoEvents
obj.EmitEventWithStruct(sent_struct);
Test.AssertEquals(sent_struct.Fstring, received_struct.Fstring);
obj.Dispose();
}
#if EFL_BETA
@ -208,6 +219,7 @@ class TestEoEvents
obj.EmitEventWithStructComplex(sent_struct);
Test.AssertEquals(sent_struct.Fobj, received_struct.Fobj);
obj.Dispose();
}
#endif
@ -230,7 +242,12 @@ class TestEoEvents
Test.AssertEquals(sent.Length, received.Length);
var pairs = sent.Zip(received, (string sentItem, string receivedItem) => new { Sent = sentItem, Received = receivedItem } );
foreach (var pair in pairs)
{
Test.AssertEquals(pair.Sent, pair.Received);
}
sent.Dispose();
received.Dispose();
obj.Dispose();
}
}
@ -253,6 +270,7 @@ class TestEventAddRemove
obj.EvtWithIntEvent -= evtCb;
obj.EmitEventWithInt(42);
Test.Assert(!called);
obj.Dispose();
}
}
@ -270,6 +288,7 @@ class TestInterfaceEvents
obj.NonconflictedEvent += cb;
obj.EmitNonconflicted();
Test.Assert(called);
obj.Dispose();
}
}
@ -290,7 +309,7 @@ class TestEventNaming
obj.EmitEventWithUnder();
Test.Assert(test_called);
obj.Dispose();
}
}
@ -342,6 +361,7 @@ class TestEventWithDeadWrappers
Test.CollectAndIterate();
Test.AssertNull(wref.Target);
manager.Dispose();
}
}

View File

@ -41,6 +41,9 @@ class TestFunctionPointerMarshalling
Test.Assert(called, "Callback was not called");
Test.AssertEquals(reference, buf.Steal());
v.Dispose();
buf.Dispose();
obj.Dispose();
}
}
}

View File

@ -53,6 +53,7 @@ class TestFunctionPointers
Test.Assert(called, "call_callback must call a callback");
Test.AssertEquals(42 * 2, x);
obj.Dispose();
}
public static void set_callback_with_lambda()
@ -71,6 +72,7 @@ class TestFunctionPointers
Test.Assert(called, "call_callback must call a callback");
Test.AssertEquals(37 + 4, x);
obj.Dispose();
}
public static void replace_callback()
@ -96,6 +98,7 @@ class TestFunctionPointers
x = obj.CallCallback(42);
Test.Assert(new_called, "call_callback must call a callback");
Test.AssertEquals(42 * 42, x);
obj.Dispose();
}
class NoOverride : Dummy.TestObject {
@ -112,6 +115,7 @@ class TestFunctionPointers
Test.Assert(called, "call_callback must call a callback");
Test.AssertEquals(42 * 3, x);
obj.Dispose();
}
class WithOverride : Dummy.TestObject {
@ -151,6 +155,7 @@ class TestFunctionPointers
Test.Assert(called, "call_callback must call a callback");
Test.AssertEquals(42 * 3, x);
obj.Dispose();
}
// These are needed due to issues calling methods on obj from the GC thread (where the
@ -202,7 +207,7 @@ class TestFunctionPointers
Test.Assert(called, "call_callback must call a callback");
Test.AssertEquals(42 * 2, x);
obj.Dispose();
}
}

View File

@ -21,6 +21,7 @@ class TestHash
Test.AssertEquals(hash.Count, 2);
Test.Assert(!hash.DelByValue(200));
hash.Dispose();
}
public static void test_del_value_string()
@ -39,6 +40,7 @@ class TestHash
Test.AssertEquals(hash.Count, 2);
Test.Assert(!hash.DelByValue("Elementary"));
hash.Dispose();
}
public static void test_del_key()
@ -50,6 +52,7 @@ class TestHash
hash.DelByKey(1);
Test.AssertEquals(hash.Count, 2);
hash.Dispose();
}
}
} // namespace TestSuite

View File

@ -49,7 +49,7 @@ class TestInheritance
return "Hello World";
}
}
internal class Inherit3Parent : Dummy.TestObject
{
public bool disposed = false;
@ -95,6 +95,7 @@ class TestInheritance
var obj = new Inherit1();
int i = Dummy.InheritHelper.ReceiveDummyAndCallIntOut(obj);
Test.AssertEquals (50, i);
obj.Dispose();
}
public static void test_inherit_from_iface()
@ -104,6 +105,7 @@ class TestInheritance
Test.AssertEquals (50, i);
string s = Dummy.InheritHelper.ReceiveDummyAndCallInStringshare(obj);
Test.AssertEquals ("Hello World", s);
obj.Dispose();
}
private static void CreateAndCheckInheritedObjects(out WeakReference parentWRef, out WeakReference childWRef)
@ -127,8 +129,8 @@ class TestInheritance
Test.AssertEquals(false, parent.disposed);
Test.AssertEquals(false, parent.childDisposed);
parent = null;
child = null;
child.Dispose();
parent.Dispose();
}
public static void test_inherit_lifetime()

View File

@ -32,7 +32,8 @@ public static class TestModel {
{
Efl.Loop loop = Efl.App.AppMain;
CreateModel(loop);
var model = CreateModel(loop);
model.Dispose();
}
internal static async Task EasyModelExtractionAsync (Efl.Loop loop)
@ -49,6 +50,8 @@ public static class TestModel {
Test.AssertEquals(r.Name, "Tomato");
loop.End();
model.Dispose();
veggies.Dispose();
}
public static void easy_model_extraction ()
@ -77,6 +80,8 @@ public static class TestModel {
Test.Assert(callbackCalled, "Property bound callback must have been called.");
Test.AssertEquals(propertyBound, "style");
factory.Dispose();
parent.Dispose();
}
}

View File

@ -31,6 +31,7 @@ public static class TestParts
{
var t = new Dummy.PartHolder();
do_part_test(t);
t.Dispose();
}
private class Child : Dummy.PartHolder
@ -41,6 +42,7 @@ public static class TestParts
public static void inherited_part_test() {
var t = new Child();
do_part_test(t);
t.Dispose();
}
private static void do_part_test(Dummy.PartHolder t)
@ -66,6 +68,8 @@ public static class TestMVVMParts
var error = bindablePart.Markup().Bind("name");
Test.AssertEquals(error, Eina.Error.NO_ERROR);
factory.Dispose();
parent.Dispose();
}
public static void mvvm_factory_properties()
@ -78,6 +82,9 @@ public static class TestMVVMParts
var error = factory.IconPart().BindFactory(iconFactory);
Test.AssertEquals(error, Eina.Error.NO_ERROR);
iconFactory.Dispose();
factory.Dispose();
parent.Dispose();
}
}
@ -92,6 +99,7 @@ public static class TestNamedParts
Test.AssertEquals("part_one", p1.GetName());
Test.Assert(p2 is Dummy.TestObject);
Test.AssertEquals("part_two", p2.GetName());
obj.Dispose();
}
}

View File

@ -30,6 +30,7 @@ class TestPromises
Test.Assert(cleanCalled, "Promise clean callback should have been called.");
Test.AssertRaises<ObjectDisposedException>(() => { promise.Resolve(null); });
Test.AssertRaises<ObjectDisposedException>(future.Cancel);
promise.Dispose();
}
public static void test_simple_resolve()
@ -55,6 +56,8 @@ class TestPromises
Test.Assert(callbackCalled, "Future callback should have been called.");
Test.AssertEquals(received_value, reference_value);
reference_value.Dispose();
promise.Dispose();
}
public static void test_simple_with_object()
@ -74,12 +77,16 @@ class TestPromises
Eina.Value referenceValue = new Eina.Value(Eina.ValueType.Array, Eina.ValueType.Int32);
referenceValue.Append(32);
promise.Resolve(new Eina.Value(referenceValue));
var tmp = new Eina.Value(referenceValue);
promise.Resolve(tmp);
loop.Iterate();
Test.Assert(callbackCalled, "Future callback should have been called.");
Test.AssertEquals(receivedValue, referenceValue);
tmp.Dispose();
referenceValue.Dispose();
promise.Dispose();
}
public static void test_simple_reject()
@ -106,6 +113,7 @@ class TestPromises
Test.AssertRaises<ObjectDisposedException>(() => { promise.Resolve(null); });
Test.AssertRaises<ObjectDisposedException>(future.Cancel);
promise.Dispose();
}
public static void test_simple_future_cancel()
@ -128,6 +136,7 @@ class TestPromises
Test.Assert(promiseCallbackCalled, "Promise cancel callback should have been called.");
Test.Assert(callbackCalled, "Future callback should have been called.");
Test.AssertEquals(received_error, Eina.Error.ECANCELED);
promise.Dispose();
}
@ -172,6 +181,8 @@ class TestPromises
Test.AssertRaises<ObjectDisposedException>(() => { promise.Resolve(null); });
Test.AssertRaises<ObjectDisposedException>(future.Cancel);
reference_value.Dispose();
promise.Dispose();
}
public static void test_then_chain_array()
@ -217,6 +228,8 @@ class TestPromises
Test.AssertRaises<ObjectDisposedException>(() => { promise.Resolve(null); });
Test.AssertRaises<ObjectDisposedException>(future.Cancel);
reference_value.Dispose();
promise.Dispose();
}
public static void test_cancel_after_resolve()
@ -244,6 +257,7 @@ class TestPromises
Test.AssertRaises<ObjectDisposedException>(() => { promise.Resolve(null); });
Test.AssertRaises<ObjectDisposedException>(future.Cancel);
promise.Dispose();
}
public static void test_constructor_with_callback()
@ -270,6 +284,9 @@ class TestPromises
Test.Assert(callbackCalled, "Future callback should have been called.");
Test.AssertEquals(received_value, reference_value);
promise.Dispose();
loop.Dispose();
reference_value.Dispose();
}
public static void test_reject_on_disposal()

View File

@ -29,6 +29,7 @@ class TestStrBuf
Test.AssertEquals("Here's Jonnny!".Length, buf.Length);
Test.AssertEquals("Here's Johnny!", buf.Steal());
buf.Dispose();
}
public static void test_tostring()
@ -39,6 +40,7 @@ class TestStrBuf
buf.Append("World!");
Test.AssertEquals("Hello World!", buf.ToString());
buf.Dispose();
}
public static void test_eolian()
@ -50,6 +52,8 @@ class TestStrBuf
obj.AppendToStrbuf(buf, " to buf");
Test.AssertEquals("Appended to buf", buf.Steal());
buf.Dispose();
obj.Dispose();
}
private class Appender : Dummy.TestObject
@ -79,6 +83,8 @@ class TestStrBuf
Test.Assert(obj.called);
Test.AssertEquals("Is this virtual?", buf.Steal());
buf.Dispose();
obj.Dispose();
}
}
} // namespace TestSuite

View File

@ -28,6 +28,7 @@ class TestStrings
String sent = "in_string";
String returned = obj.InString(sent);
Test.AssertEquals(sent, returned);
obj.Dispose();
}
System.GC.Collect();
}
@ -41,6 +42,7 @@ class TestStrings
String sent = "in_own_string";
String returned = obj.InOwnString(sent);
Test.AssertEquals(sent, returned);
obj.Dispose();
}
System.GC.Collect();
}
@ -51,6 +53,7 @@ class TestStrings
{
var obj = new Dummy.TestObject();
Test.AssertEquals("string", obj.ReturnString());
obj.Dispose();
}
System.GC.Collect();
}
@ -61,6 +64,7 @@ class TestStrings
{
var obj = new Dummy.TestObject();
Test.AssertEquals("own_string", obj.ReturnOwnString());
obj.Dispose();
}
System.GC.Collect();
}
@ -73,6 +77,7 @@ class TestStrings
var obj = new Dummy.TestObject();
obj.OutString(out str);
Test.AssertEquals("out_string", str);
obj.Dispose();
}
System.GC.Collect();
}
@ -86,6 +91,7 @@ class TestStrings
obj.OutOwnString(out str);
Test.AssertEquals(str.ToString(CultureInfo.CurrentCulture),
"out_own_string");
obj.Dispose();
}
System.GC.Collect();
}
@ -143,6 +149,7 @@ class TestStrings
Test.AssertEquals(sent, obj.received_in);
/* } */
System.GC.Collect();
obj.Dispose();
}
/* The managed wrapper should take ownership of the in parameter */
@ -155,6 +162,7 @@ class TestStrings
Test.AssertEquals(sent, obj.received_in_own);
/* } */
System.GC.Collect();
obj.Dispose();
}
/* The managed wrapper still owns the returned C string. We need to cache it until
@ -165,6 +173,7 @@ class TestStrings
/* for (int i = 0; i < 10000; i ++) // Uncomment this to check for memory leaks. */
Test.AssertEquals("inherited", obj.CallReturnString());
System.GC.Collect();
obj.Dispose();
}
/* The managed wrapper must surrender the ownership to the C after the virtual call. */
@ -174,6 +183,7 @@ class TestStrings
/* for (int i = 0; i < 10000; i ++) // Uncomment this to check for memory leaks. */
Test.AssertEquals("own_inherited", obj.CallReturnOwnString());
System.GC.Collect();
obj.Dispose();
}
/* The managed wrapper still owns the C string after the call. Like return without own, we may
@ -184,6 +194,7 @@ class TestStrings
/* for (int i = 0; i < 10000; i ++) // Uncomment this to check for memory leaks. */
Test.AssertEquals("out_inherited", obj.CallOutString());
System.GC.Collect();
obj.Dispose();
}
/* The managed wrapper gives C the ownership of the filled out parameter */
@ -193,6 +204,7 @@ class TestStrings
/* for (int i = 0; i < 10000; i ++) // Uncomment this to check for memory leaks. */
Test.AssertEquals("out_own_inherited", obj.CallOutOwnString());
System.GC.Collect();
obj.Dispose();
}
}
@ -206,6 +218,7 @@ class TestStringshare
String sent = "in_stringshare";
String returned = obj.InStringshare(sent);
Test.AssertEquals(sent, returned);
obj.Dispose();
}
System.GC.Collect();
}
@ -217,6 +230,7 @@ class TestStringshare
String sent = "in_own_stringshare";
String returned = obj.InOwnStringshare(sent);
Test.AssertEquals(sent, returned);
obj.Dispose();
}
System.GC.Collect();
}
@ -226,6 +240,7 @@ class TestStringshare
{
var obj = new Dummy.TestObject();
Test.AssertEquals("stringshare", obj.ReturnStringshare());
obj.Dispose();
}
System.GC.Collect();
}
@ -235,6 +250,7 @@ class TestStringshare
{
var obj = new Dummy.TestObject();
Test.AssertEquals("own_stringshare", obj.ReturnOwnStringshare());
obj.Dispose();
}
System.GC.Collect();
}
@ -246,6 +262,7 @@ class TestStringshare
var obj = new Dummy.TestObject();
obj.OutStringshare(out str);
Test.AssertEquals("out_stringshare", str);
obj.Dispose();
}
System.GC.Collect();
}
@ -258,6 +275,7 @@ class TestStringshare
obj.OutOwnStringshare(out str);
Test.AssertEquals(str.ToString(CultureInfo.CurrentCulture),
"out_own_stringshare");
obj.Dispose();
}
System.GC.Collect();
}
@ -310,6 +328,7 @@ class TestStringshare
String sent = "in_inherited";
obj.CallInStringshare(sent);
Test.AssertEquals(sent, obj.received_in);
obj.Dispose();
}
public static void in_own_stringshare_from_virtual()
@ -318,6 +337,7 @@ class TestStringshare
String sent = "in_own_inherited";
obj.CallInOwnStringshare(sent);
Test.AssertEquals(sent, obj.received_in_own);
obj.Dispose();
}
public static void return_stringshare_from_virtual()
@ -325,6 +345,7 @@ class TestStringshare
var obj = new StringshareReturner();
// for (int i = 0; i < 1000000; i ++) // Uncomment this to check for memory leaks.
Test.AssertEquals("inherited", obj.CallReturnStringshare());
obj.Dispose();
}
public static void return_own_stringshare_from_virtual()
@ -332,6 +353,7 @@ class TestStringshare
var obj = new StringshareReturner();
// for (int i = 0; i < 1000000; i ++) // Uncomment this to check for memory leaks.
Test.AssertEquals("own_inherited", obj.CallReturnOwnStringshare());
obj.Dispose();
}
public static void out_stringshare_from_virtual()
@ -339,6 +361,7 @@ class TestStringshare
var obj = new StringshareReturner();
// for (int i = 0; i < 1000000; i ++) // Uncomment this to check for memory leaks.
Test.AssertEquals("out_inherited", obj.CallOutStringshare());
obj.Dispose();
}
public static void out_own_stringshare_from_virtual()
@ -346,6 +369,7 @@ class TestStringshare
var obj = new StringshareReturner();
// for (int i = 0; i < 1000000; i ++) // Uncomment this to check for memory leaks.
Test.AssertEquals("out_own_inherited", obj.CallOutOwnStringshare());
obj.Dispose();
}
}

View File

@ -62,6 +62,7 @@ internal class TestStructs
var t = new Dummy.TestObject();
bool r = t.StructSimpleIn(simple);
Test.Assert(r, "Function returned false");
t.Dispose();
}
/*
@ -95,6 +96,7 @@ internal class TestStructs
bool r = t.StructSimpleOut(out simple);
Test.Assert(r, "Function returned false");
checkStructSimple(simple);
t.Dispose();
}
/*
@ -122,6 +124,7 @@ internal class TestStructs
var t = new Dummy.TestObject();
var simple = t.StructSimpleReturn();
checkStructSimple(simple);
t.Dispose();
}
/*
@ -236,6 +239,7 @@ internal class TestStructs
t.CallStructSimpleIn(simple);
Test.Assert(t.called);
Test.AssertEquals(simple.Fstring, t.received.Fstring);
t.Dispose();
}
/*
@ -269,6 +273,7 @@ internal class TestStructs
t.CallStructSimpleOut(out simple);
Test.Assert(t.called, "override was not called");
Test.AssertEquals("Virtual Struct Out", simple.Fstring);
t.Dispose();
}
/*
@ -297,6 +302,7 @@ internal class TestStructs
Dummy.StructSimple simple = t.CallStructSimpleReturn();
Test.Assert(t.called, "override was not called");
Test.AssertEquals("Virtual Struct Return", simple.Fstring);
t.Dispose();
}
/*
@ -325,6 +331,7 @@ internal class TestStructs
var t = new Dummy.TestObject();
bool r = t.StructComplexIn(complex);
Test.Assert(r, "Function returned false");
t.Dispose();
}
// public static void complex_ptr_in()
@ -342,6 +349,7 @@ internal class TestStructs
bool r = t.StructComplexOut(out complex);
Test.Assert(r, "Function returned false");
checkStructComplex(complex);
t.Dispose();
}
// public static void complex_ptr_out()
@ -357,6 +365,7 @@ internal class TestStructs
var t = new Dummy.TestObject();
var complex = t.StructComplexReturn();
checkStructComplex(complex);
t.Dispose();
}
#endif
// public static void complex_ptr_return()

View File

@ -172,6 +172,8 @@ public static class TestEinaValue {
Efl.Object target;
Test.Assert(v.Get(out target));
Test.AssertEquals(target, obj);
target.Dispose();
obj.Dispose();
}
}
@ -329,6 +331,8 @@ public static class TestEinaValue {
Efl.Object received = null;
Test.Assert(a.Get(out received));
Test.AssertEquals(expected, received);
received.Dispose();
expected.Dispose();
}
}
@ -364,6 +368,7 @@ public static class TestEinaValue {
Test.Assert(a.Reset());
Test.Assert(a.Set(expected));
actual.Dispose();
}
}
public static void TestValueOptionalLists()
@ -395,6 +400,7 @@ public static class TestEinaValue {
Eina.Value actual = null;
Test.Assert(a.Get(out actual));
Test.AssertEquals(expected, actual);
actual.Dispose();
}
}
@ -865,6 +871,9 @@ public static class TestEinaValue {
Test.AssertEquals((Efl.Object)array[0], c);
Test.AssertEquals((Efl.Object)array[1], b);
c.Dispose();
b.Dispose();
a.Dispose();
}
}
@ -1027,6 +1036,7 @@ public static class TestEinaValue {
int rec_val;
Test.Assert(v2.Get(out rec_val));
Test.AssertEquals(raw_val, rec_val);
v2.Dispose();
}
// FIXME Add remaining list tests
@ -1123,6 +1133,7 @@ public static class TestValueFromObject
Test.Assert(v.Set(newObj));
prop.SetValue(source, v.Unwrap());
Test.AssertEquals(prop.GetValue(source), newObj);
newObj.Dispose();
}
}
@ -1163,14 +1174,18 @@ public static class TestValueFromObject
Test.AssertEquals(toCheck[0], 100);
Test.AssertEquals(toCheck[1], 200);
Test.AssertEquals(toCheck[2], 300);
v.Dispose();
}
public static void TestObjectContainerFromToObject()
{
var initialBag = new Eina.Array<Efl.Object>();
initialBag.Push(new Dummy.TestObject());
initialBag.Push(new Dummy.TestObject());
initialBag.Push(new Dummy.TestObject());
var tmp1 = new Dummy.TestObject();
var tmp2 = new Dummy.TestObject();
var tmp3 = new Dummy.TestObject();
initialBag.Push(tmp1);
initialBag.Push(tmp2);
initialBag.Push(tmp3);
var source = new ComplexHolder { BagOfObjects = initialBag };
var prop = source.GetType().GetProperty("BagOfObjects");
@ -1199,6 +1214,10 @@ public static class TestValueFromObject
Test.AssertEquals(toCheck[0], first);
Test.AssertEquals(toCheck[1], second);
Test.AssertEquals(toCheck[2], third);
tmp3.Dispose();
tmp2.Dispose();
tmp1.Dispose();
v.Dispose();
}
}
#pragma warning restore 1591

View File

@ -38,6 +38,7 @@ public static class TestEinaValueEolian {
Test.AssertEquals(v, v_received);
v_received.Dispose();
}
obj.Dispose();
}
public static void TestEolianEinaValueInOwn()
@ -58,6 +59,7 @@ public static class TestEinaValueEolian {
obj.ClearValue();
}
obj.Dispose();
}
public static void TestEolianEinaValueOut()
@ -73,7 +75,9 @@ public static class TestEinaValueEolian {
Test.AssertEquals(v, v_out);
Test.AssertEquals(Eina.Ownership.Unmanaged, v_out.Ownership);
v_out.Dispose();
}
obj.Dispose();
}
public static void TestEolianEinaValueOutOwn()
@ -89,7 +93,9 @@ public static class TestEinaValueEolian {
Test.AssertEquals(v, v_out);
Test.AssertEquals(Eina.Ownership.Managed, v_out.Ownership);
v_out.Dispose();
}
obj.Dispose();
}
public static void TestEolianEinaValueOutByValue()
@ -105,7 +111,9 @@ public static class TestEinaValueEolian {
Test.AssertEquals(v, v_out);
Test.AssertEquals(Eina.Ownership.Managed, v_out.Ownership);
v_out.Dispose();
}
obj.Dispose();
}
private class ValueHandler : Dummy.TestObject
@ -130,6 +138,7 @@ public static class TestEinaValueEolian {
obj.CallSetValue(val);
Test.AssertEquals(val, obj.value);
}
obj.Dispose();
}
public static void TestEolianEinaValueImplicitOperators()
@ -141,6 +150,7 @@ public static class TestEinaValueEolian {
var expected = new Eina.Value(1999);
var received = new Eina.Value(Eina.ValueType.String);
received.Dispose();
obj.OutValue(out received);
Test.AssertEquals(expected, received);
Test.AssertEquals(Eina.ValueType.Int32, received.GetValueType());
@ -148,6 +158,7 @@ public static class TestEinaValueEolian {
int i = received;
Test.AssertEquals(i, 1999);
expected.Dispose();
expected = new Eina.Value("Hallo");
obj.SetValue("Hallo");
@ -159,9 +170,11 @@ public static class TestEinaValueEolian {
Test.AssertEquals(s, "Hallo");
// Casting
expected.Dispose();
expected = new Eina.Value((double)15);
obj.SetValue((double)15);
received.Dispose();
obj.OutValue(out received);
Test.AssertEquals(expected, received);
Test.AssertEquals(Eina.ValueType.Double, received.GetValueType());
@ -169,11 +182,16 @@ public static class TestEinaValueEolian {
// Check for 0
// This is a special value, since C# can silently convert it to an enum
// leading to collisions with Eina.ValueType
expected.Dispose();
expected = new Eina.Value(0);
obj.SetValue(0);
received.Dispose();
obj.OutValue(out received);
Test.AssertEquals(expected, received);
Test.AssertEquals(Eina.ValueType.Int32, received.GetValueType());
expected.Dispose();
received.Dispose();
obj.Dispose();
}
// ValueType in eolian context is beta, so not allowed.
@ -188,6 +206,7 @@ public static class TestEinaValueEolian {
{
Test.AssertEquals(type, obj.MirrorValueType(type));
}
obj.Dispose();
}
#endif
}