2019-08-05 07:17:52 -07:00
|
|
|
#define CODE_ANALYSIS
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using System.Diagnostics.CodeAnalysis;
|
|
|
|
|
|
|
|
#if EFL_BETA
|
|
|
|
|
|
|
|
namespace TestSuite {
|
|
|
|
|
|
|
|
[SuppressMessage("Gendarme.Rules.Portability", "DoNotHardcodePathsRule")]
|
2019-11-04 09:40:18 -08:00
|
|
|
public static class TestModel {
|
2019-08-05 07:17:52 -07:00
|
|
|
|
2019-11-04 09:40:18 -08:00
|
|
|
private class VeggieViewModel
|
2019-08-05 07:17:52 -07:00
|
|
|
{
|
|
|
|
public string Name { get; set; }
|
|
|
|
public string Type { get; set; }
|
|
|
|
public string Image { get; set; }
|
|
|
|
}
|
|
|
|
|
|
|
|
private static Efl.UserModel<VeggieViewModel> CreateModel(Efl.Loop loop)
|
|
|
|
{
|
|
|
|
Efl.UserModel<VeggieViewModel> veggies = new Efl.UserModel<VeggieViewModel>(loop);
|
|
|
|
veggies.Add (new VeggieViewModel{ Name="Tomato", Type="Fruit", Image="tomato.png"});
|
|
|
|
veggies.Add (new VeggieViewModel{ Name="Romaine Lettuce", Type="Vegetable", Image="lettuce.png"});
|
|
|
|
veggies.Add (new VeggieViewModel{ Name="Zucchini", Type="Vegetable", Image="zucchini.png"});
|
|
|
|
|
|
|
|
return veggies;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void reflection_test ()
|
|
|
|
{
|
|
|
|
Efl.Loop loop = Efl.App.AppMain;
|
|
|
|
|
2019-11-14 09:26:16 -08:00
|
|
|
var model = CreateModel(loop);
|
|
|
|
model.Dispose();
|
2019-08-05 07:17:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
internal static async Task EasyModelExtractionAsync (Efl.Loop loop)
|
|
|
|
{
|
|
|
|
var veggies = CreateModel(loop);
|
|
|
|
|
|
|
|
var model = new Efl.GenericModel<VeggieViewModel>(veggies, loop);
|
|
|
|
Test.AssertEquals(3, (int)model.GetChildrenCount());
|
|
|
|
|
2019-10-25 07:22:35 -07:00
|
|
|
VeggieViewModel r2 = await model.GetAtAsync(1).ConfigureAwait(false);
|
2019-08-05 07:17:52 -07:00
|
|
|
Test.AssertEquals(r2.Name, "Romaine Lettuce");
|
|
|
|
|
2019-10-25 07:22:35 -07:00
|
|
|
VeggieViewModel r = await model.GetAtAsync(0).ConfigureAwait(false);
|
2019-08-05 07:17:52 -07:00
|
|
|
Test.AssertEquals(r.Name, "Tomato");
|
|
|
|
|
|
|
|
loop.End();
|
2019-11-14 09:26:16 -08:00
|
|
|
model.Dispose();
|
|
|
|
veggies.Dispose();
|
2019-08-05 07:17:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void easy_model_extraction ()
|
|
|
|
{
|
|
|
|
Efl.Loop loop = Efl.App.AppMain;
|
|
|
|
Task task = EasyModelExtractionAsync(loop);
|
|
|
|
|
|
|
|
loop.Begin();
|
|
|
|
|
|
|
|
task.Wait();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void factory_test ()
|
|
|
|
{
|
|
|
|
string propertyBound = null;
|
|
|
|
bool callbackCalled = false;
|
2019-09-24 13:06:29 -07:00
|
|
|
var parent = new Efl.Ui.Win(null);
|
|
|
|
parent.Visible = false;
|
|
|
|
var factory = new Efl.Ui.ItemFactory<Efl.Ui.Button>(parent);
|
2019-09-06 07:03:23 -07:00
|
|
|
factory.PropertyBoundEvent += (object sender, Efl.Ui.PropertyBindPropertyBoundEventArgs args) => {
|
2019-08-05 07:17:52 -07:00
|
|
|
propertyBound = args.arg;
|
|
|
|
callbackCalled = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
factory.Style().Bind("first name");
|
|
|
|
|
|
|
|
Test.Assert(callbackCalled, "Property bound callback must have been called.");
|
|
|
|
Test.AssertEquals(propertyBound, "style");
|
2019-11-14 09:26:16 -08:00
|
|
|
factory.Dispose();
|
|
|
|
parent.Dispose();
|
2019-08-05 07:17:52 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|