Add DateTimeSelectorTC2 and NaviframeTest3
[platform/core/csapi/tizenfx.git] / test / ElmSharp.Test / TC / NaviframeTest3.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 using System;
18 using System.Linq;
19
20 namespace ElmSharp.Test
21 {
22     public class NaviframeTest3 : TestCaseBase
23     {
24         public override string TestName => "NaviframeTest3";
25         public override string TestDescription => "Naviframe test";
26
27         Naviframe _navi;
28         int _sequence = 0;
29
30         public override void Run(Window window)
31         {
32             Conformant conformant = new Conformant(window);
33             conformant.Show();
34
35             Naviframe navi = new Naviframe(window)
36             {
37                 PreserveContentOnPop = true,
38                 DefaultBackButtonEnabled = true
39             };
40             _navi = navi;
41
42             navi.Popped += (s, e) =>
43             {
44                 Console.WriteLine("----- Naviframe was popped {0:x} ", (int)(IntPtr)e.Content);
45             };
46
47             NaviItem item = navi.Push(CreatePage(window), "0 Page");
48             item.SetPartContent("title_left_btn", new Button(window) { Text = "LEFT" , Style = "naviframe/title_left"} );
49             item.SetPartContent("title_right_btn", new Button(window) { Text = "RIGHT", Style = "naviframe/title_right" });
50             navi.Show();
51             conformant.SetContent(navi);
52         }
53
54         EvasObject CreatePage(Window parent)
55         {
56             Box box = new Box(parent);
57             box.Show();
58
59             Label label = new Label(parent) {
60                 Text = string.Format("{0} Page", _sequence++),
61                 WeightX = 1,
62                 AlignmentX = -1,
63             };
64             Button push = new Button(parent) {
65                 Text = "Push",
66                 WeightX = 1,
67                 AlignmentX = -1,
68             };
69             Button pop = new Button(parent) {
70                 Text = "pop",
71                 WeightX = 1,
72                 AlignmentX = -1,
73             };
74             Button insertBeforeTop = new Button(parent) {
75                 Text = "insertBeforeTop",
76                 WeightX = 1,
77                 AlignmentX = -1,
78             };
79             Button insertAfterTop = new Button(parent) {
80                 Text = "insertAfterTop",
81                 WeightX = 1,
82                 AlignmentX = -1,
83             };
84
85             Button removeTop = new Button(parent)
86             {
87                 Text = "removeTop",
88                 WeightX = 1,
89                 AlignmentX = -1,
90             };
91
92             Button barChange = new Button(parent)
93             {
94                 Text = "TitleBarColor Change",
95                 WeightX = 1,
96                 AlignmentX = -1,
97             };
98
99             Button barColorDefault = new Button(parent)
100             {
101                 Text = "TitleBarColor - Default",
102                 WeightX = 1,
103                 AlignmentX = -1,
104             };
105
106             label.Show();
107             push.Show();
108             pop.Show();
109             insertBeforeTop.Show();
110             insertAfterTop.Show();
111             removeTop.Show();
112             barChange.Show();
113             barColorDefault.Show();
114
115             push.Clicked += (s, e) =>
116             {
117                 _navi.Push(CreatePage(parent), string.Format("{0} Page", _sequence-1));
118             };
119
120             pop.Clicked += (s, e) =>
121             {
122                 var item = _navi.NavigationStack.LastOrDefault();
123                 int nativePointer = (int)(IntPtr)(item.Content);
124                 Console.WriteLine("----- Before Call _navi.Pop() {0:x} ", nativePointer);
125                 _navi.Pop();
126                 Console.WriteLine("----- After Call _navi.Pop() {0:x} ", nativePointer);
127             };
128
129             insertBeforeTop.Clicked += (s, e) =>
130             {
131                 _navi.InsertBefore(_navi.NavigationStack.LastOrDefault(), CreatePage(parent), string.Format("{0} Page", _sequence - 1));
132             };
133
134             insertAfterTop.Clicked += (s, e) =>
135             {
136                 _navi.InsertAfter(_navi.NavigationStack.LastOrDefault(), CreatePage(parent), string.Format("{0} Page", _sequence - 1));
137             };
138             removeTop.Clicked += (s, e) =>
139             {
140                 var item = _navi.NavigationStack.LastOrDefault();
141                 int nativePointer = (int)(IntPtr)(item.Content);
142                 Console.WriteLine("----- Before Call NaviItem.Delete() {0:x} ", nativePointer);
143                 item.Delete();
144                 Console.WriteLine("----- After Call NaviItem.Delete() {0:x} ", nativePointer);
145             };
146
147             Random rand = new Random(DateTime.Now.Millisecond);
148             barChange.Clicked += (s, e) =>
149             {
150                 int currentIndex = _navi.NavigationStack.Count - 1;
151                 if (currentIndex >= 0)
152                 {
153                     _navi.NavigationStack[currentIndex].TitleBarBackgroundColor = Color.FromHex(string.Format("#{0:X8}", rand.Next()));
154                 }
155             };
156
157             barColorDefault.Clicked += (s, e) =>
158             {
159                 int currentIndex = _navi.NavigationStack.Count - 1;
160                 if (currentIndex >= 0)
161                 {
162                     _navi.NavigationStack[currentIndex].TitleBarBackgroundColor = Color.Default;
163                 }
164             };
165
166             box.PackEnd(label);
167             box.PackEnd(push);
168             box.PackEnd(pop);
169             box.PackEnd(insertBeforeTop);
170             box.PackEnd(insertAfterTop);
171             box.PackEnd(removeTop);
172             box.PackEnd(barChange);
173             box.PackEnd(barColorDefault);
174
175             return box;
176         }
177     }
178 }