[NUI] Make PrimaryCursorPosition property public
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Tests / Tizen.NUI.Devel.Tests / testcase / public / BaseComponents / TSTextEditorEvent.cs
1 using global::System;
2 using NUnit.Framework;
3 using NUnit.Framework.TUnit;
4 using Tizen.NUI.Components;
5 using Tizen.NUI.BaseComponents;
6 using System.Collections.Generic;
7 using System.Threading.Tasks;
8
9 namespace Tizen.NUI.Devel.Tests
10 {
11     using tlog = Tizen.Log;
12
13     [TestFixture]
14     [Description("public/BaseComponents/TextEditorEvent")]
15     public class PublicTextEditorEventTest
16     {
17         private const string tag = "NUITEST";
18         private bool selectionStartedFlag = false;
19
20         [SetUp]
21         public void Init()
22         {
23             tlog.Info(tag, "Init() is called!");
24         }
25
26         [TearDown]
27         public void Destroy()
28         {
29             tlog.Info(tag, "Destroy() is called!");
30         }
31
32         [Test]
33         [Category("P1")]
34         [Description("TextEditorEvent TextChanged.")]
35         [Property("SPEC", "Tizen.NUI.TextEditorEvent.TextChanged A")]
36         [Property("SPEC_URL", "-")]
37         [Property("CRITERIA", "PRW")]
38         [Property("AUTHOR", "guowei.wang@samsung.com")]
39         public void TextEditorEventEvents()
40         {
41             tlog.Debug(tag, $"TextEditorEventEvents START");
42
43             var testingTarget = new TextEditor(true);
44             Assert.IsNotNull(testingTarget, "Can't create success object TextEditor");
45             Assert.IsInstanceOf<TextEditor>(testingTarget, "Should be an instance of TextEditor type.");
46
47             testingTarget.TextChanged += OnTextChanged;
48             testingTarget.TextChanged -= OnTextChanged;
49
50             testingTarget.MaxLengthReached += OnMaxLengthReached;
51             testingTarget.MaxLengthReached -= OnMaxLengthReached;
52
53             testingTarget.AnchorClicked += OnAnchorClicked;
54             testingTarget.AnchorClicked -= OnAnchorClicked;
55
56             testingTarget.SelectionStarted += OnSelectionStarted;
57             testingTarget.SelectionStarted -= OnSelectionStarted;
58                         
59             testingTarget.Dispose();
60             tlog.Debug(tag, $"TextEditorEventEvents END (OK)");
61         }
62
63         [Test]
64         [Category("P1")]
65         [Description("TextEditorEvent SelectionStarted.")]
66         [Property("SPEC", "Tizen.NUI.TextEditor.SelectionStarted A")]
67         [Property("SPEC_URL", "-")]
68         [Property("CRITERIA", "PRW")]
69         [Property("AUTHOR", "a.ghujeh@samsung.com")]
70         async public Task TextEditorSelectionStarted()
71         {
72             tlog.Debug(tag, $"SelectionStarted START");
73
74             var testingTarget = new TextEditor()
75             {
76                 Text = "texteditor",
77             };
78
79             Window.Instance.GetDefaultLayer().Add(testingTarget);
80
81             Assert.IsNotNull(testingTarget, "Can't create success object TextEditor");
82             Assert.IsInstanceOf<TextEditor>(testingTarget, "Should be an instance of TextEditor type.");
83
84             try
85             {
86                 testingTarget.SelectionStarted += OnSelectionStarted;
87
88                 testingTarget.SelectWholeText();
89                 await Task.Delay(500);
90
91                 testingTarget.SelectionStarted -= OnSelectionStarted;
92             }
93             catch (Exception e)
94             {
95                 tlog.Info(tag, e.Message.ToString());
96                 Assert.Fail("Caught Exception : Failed!");
97             }
98
99             testingTarget.Dispose();
100
101             if(selectionStartedFlag == true)
102                 tlog.Debug(tag, $"SelectionStarted END (OK)");
103             else
104                 Assert.Fail("SelectionStarted : Failed!");
105         }
106
107         private void OnAnchorClicked(object sender, AnchorClickedEventArgs e)
108         {
109         }
110
111         private void OnMaxLengthReached(object sender, TextEditor.MaxLengthReachedEventArgs e)
112         {
113         }
114
115         private void OnTextChanged(object sender, TextEditor.TextChangedEventArgs e)
116         {
117         }
118         
119         private void OnSelectionStarted(object sender, EventArgs e) 
120         {
121             selectionStartedFlag = true;
122         }
123     }
124 }