using NUnit.Framework;
using NUnit.Framework.TUnit;
-using ElmSharp;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
[TestFixture]
[Description("Testing Tizen.Applications.WidgetBase class")]
public class WidgetBaseTests {
- private Tizen.Applications.WidgetControl _widgetControl;
- private string _widgetId = "org.tizen.WidgetAppInstChecker";
- private Window _window;
- private Background _background;
- private RemoteView _remoteView;
- private bool _created;
-
- private void LaunchWidget()
- {
- if (_window == null)
- {
- _window = new Window(Application.Current.ApplicationInfo.ApplicationId);
- _window.Show();
- _background = new Background(_window)
- {
- AlignmentX = -1,
- AlignmentY = -1,
- WeightX = 1,
- WeightY = 1,
- Color = Color.Black
- };
- _background.Show();
- _window.AddResizeObject(_background);
-
- RemoteViewFactory.Init(_window);
- _remoteView = RemoteViewFactory.Create(_window, _widgetId, "", 0, true, true, true);
- _remoteView.Layout.Resize(712, 712);
- _remoteView.Layout.Show();
- }
- }
-
- private void ShutdownWidget()
- {
- _window = null;
- _background = null;
- _remoteView = null;
- _created = false;
- }
-
- private void OnCreated(object sender, Tizen.Applications.WidgetLifecycleEventArgs args)
- {
- _created = true;
- }
-
[SetUp]
public void Init()
{
Assert.NotNull(bWidget, "Should not return NULL");
Assert.IsInstanceOf<WidgetBase>(bWidget, "Should return WidgetBase instance.");
}
-
- [Test]
- [Category("P1")]
- [Description("Create a widget with default value")]
- [Property("SPEC", "Tizen.Applications.WidgetBase.Id A")]
- [Property("SPEC_URL", "-")]
- [Property("CRITERIA", "PRO")]
- [Property("AUTHOR", "Junghoon Park, jh9216.park@samsung.com")]
- public async Task Id_PROPERTY_GET()
- {
- /* PRECONDITION
- * */
- ShutdownWidget();
- _widgetControl = new Tizen.Applications.WidgetControl(_widgetId);
- _widgetControl.Created += OnCreated;
- LaunchWidget();
- await Task.Delay(4000);
- Assert.True(_created);
- string content = _remoteView.Content;
- Assert.NotNull(content);
-
- /* TEST CODE */
- Bundle b = Bundle.Decode(content);
- b.TryGetItem("InstID", out string val);
- Assert.NotNull(val);\r
-\r
- string[] vs = val.Split(":");
- Assert.AreEqual(vs[1], _widgetId);
-
- /* POSTCONDITION
- * */
- b.Dispose();
- ShutdownWidget();
- _widgetControl.Created -= OnCreated;
- _widgetControl.Dispose();
- _widgetControl = null;
- }
}
}