b722ebfc56e904efb084a83108056257648451ac
[test/tct/csharp/api.git] /
1 /*\r
2  *  Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved\r
3  *\r
4  *  Licensed under the Apache License, Version 2.0 (the "License");\r
5  *  you may not use this file except in compliance with the License.\r
6  *  You may obtain a copy of the License at\r
7  *\r
8  *      http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  *  Unless required by applicable law or agreed to in writing, software\r
11  *  distributed under the License is distributed on an "AS IS" BASIS,\r
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  *  See the License for the specific language governing permissions and\r
14  *  limitations under the License\r
15  */\r
16 \r
17 using NUnit.Framework;\r
18 using NUnit.Framework.TUnit;\r
19 using System;\r
20 using System.Collections.Generic;\r
21 using System.Threading;\r
22 using System.Threading.Tasks;\r
23 using Tizen;\r
24 \r
25 namespace Tizen.Applications.ComponentBased.Tests\r
26 {\r
27     [TestFixture]\r
28     [Description("Tizen.Applications.ComponentBased.ComponentManager Tests")]\r
29     public class ComponentManagerTests\r
30     {\r
31         private const string LogTag = "ComponentManager.Tests";\r
32         private IEnumerable<ComponentInfo> _listCompo;\r
33         private IEnumerable<ComponentRunningContext> _listCompoRun;\r
34         private const string AppId = "org.tizen.example.ComponentBasedSample2";\r
35         private const string CompoId = "org.example.bg-service-component";\r
36         private bool _flag;\r
37 \r
38         [SetUp]\r
39         public void Init()\r
40         {\r
41             Log.Debug(LogTag, "Preconditions for each TEST");\r
42             _flag = false;\r
43 \r
44             bool isRunning = ComponentManager.IsRunning(CompoId);\r
45             if (!isRunning)\r
46             {\r
47                 AppControl appControl = new AppControl();\r
48                 appControl.ApplicationId = AppId;\r
49                 appControl.ComponentId = CompoId;\r
50                 appControl.Operation = AppControlOperations.Default;\r
51                 AppControl.SendLaunchRequest(appControl);\r
52                 Thread.Sleep(5000);\r
53             }\r
54         }\r
55 \r
56         [TearDown]\r
57         public void Destroy()\r
58         {\r
59             Log.Debug(LogTag, "Postconditions for each TEST");\r
60         }\r
61 \r
62         [Test]\r
63         [Category("P1")]\r
64         [Description("Test: Get the information of all installed components asynchronously.")]\r
65         [Property("SPEC", "Tizen.Applications.ComponentBased.ComponentManager.GetInstalledComponentsAsync M")]\r
66         [Property("SPEC_URL", "-")]\r
67         [Property("CRITERIA", "MR")]\r
68         [Property("AUTHOR", "Hwankyu Jhun, h.jhun@samsung.com")]\r
69         public async Task GetInstalledComponentsAsync_GET_ALL_COMPO()\r
70         {\r
71             Log.Debug(LogTag, "START");\r
72             _listCompo = await ComponentManager.GetInstalledComponentsAsync();\r
73             Assert.IsNotEmpty(_listCompo, "The list of installed components should not be empty.");\r
74             foreach (ComponentInfo inst in _listCompo)\r
75             {\r
76                 if (string.Equals(inst.ComponentId, CompoId))\r
77                 {\r
78                     _flag = true;\r
79                     break;\r
80                 }\r
81             }\r
82             Assert.True(_flag, "Could not find the given component in list of installed components.");\r
83             Log.Debug(LogTag, "END");\r
84         }\r
85 \r
86         [Test]\r
87         [Category("P1")]\r
88         [Description("Test: Get the information of all running components asynchronously.")]\r
89         [Property("SPEC", "Tizen.Applications.ComponentBased.ComponentManager.GetRunningComponentsAsync M")]\r
90         [Property("SPEC_URL", "-")]\r
91         [Property("CRITERIA", "MR")]\r
92         [Property("AUTHOR", "Hwankyu Jhun, h.jhun@samsung.com")]\r
93         public async Task GetRunningComponentsAsync_All_RUNNING_COMPO()\r
94         {\r
95             Log.Debug(LogTag, "START");\r
96             _listCompoRun = await ComponentManager.GetRunningComponentsAsync();\r
97             Assert.IsNotEmpty(_listCompoRun, "The list of running components should not be empty.");\r
98             foreach (ComponentRunningContext context in _listCompoRun)\r
99             {\r
100                 if (string.Equals(context.ComponentId, CompoId))\r
101                 {\r
102                     _flag = true;\r
103                     break;\r
104                 }\r
105             }\r
106             Assert.True(_flag, "Could not find the given component in list of running components.");\r
107             Log.Debug(LogTag, "END");\r
108         }\r
109 \r
110         [Test]\r
111         [Category("P1")]\r
112         [Description("Test: Check whether the component is running or not.")]\r
113         [Property("SPEC", "Tizen.Applications.ComponentBased.ComponentManager.IsRunning M")]\r
114         [Property("SPEC_URL", "-")]\r
115         [Property("CRITERIA", "MR")]\r
116         [Property("AUTHOR", "Hwankyu Jhun, h.jhun@samsung.com")]\r
117         [Property("CONVPARAM", "string")]\r
118         public void IsRunning_RETURN_VALUE()\r
119         {\r
120             Log.Debug(LogTag, "START");\r
121             Assert.True(ComponentManager.IsRunning(CompoId), CompoId + " should be running");\r
122             Log.Debug(LogTag, "END");\r
123         }\r
124 \r
125         [Test]\r
126         [Category("P2")]\r
127         [Description("Test: Verify the component state with null argument.")]\r
128         [Property("SPEC", "Tizen.Applications.ComponentBased.ComponentManager.IsRunning M")]\r
129         [Property("SPEC_URL", "-")]\r
130         [Property("CRITERIA", "MEX")]\r
131         [Property("AUTHOR", "Hwankyu Jhun, h.jhun@samsung.com")]\r
132         [Property("CONVPARAM", "string")]\r
133         public void IsRunning_CHECK_ArgumentException()\r
134         {\r
135             Log.Debug(LogTag, "START");\r
136             try\r
137             {\r
138                 bool isRunning = ComponentManager.IsRunning(null);\r
139             }\r
140             catch (ArgumentException)\r
141             {\r
142                 Assert.Pass();\r
143             }\r
144             Log.Debug(LogTag, "END");\r
145         }\r
146 \r
147         [Test]\r
148         [Category("P1")]\r
149         [Description("Test: Terminate a running service component in the background.")]\r
150         [Property("SPEC", "Tizen.Applications.ComponentBased.ComponentManager.TerminateBackgroundComponent M")]\r
151         [Property("SPEC_URL", "-")]\r
152         [Property("CRITERIA", "MR")]\r
153         [Property("AUTHOR", "Hwankyu Jhun, h.jhun@samsung.com")]\r
154         public async Task TerminateBackgroundComponent_TERMINATE_BG_COMPO()\r
155         {\r
156             Log.Debug(LogTag, "START");\r
157             ComponentRunningContext context = null;\r
158 \r
159             try\r
160             {\r
161                 context = new ComponentRunningContext(CompoId);\r
162                 Assert.AreNotEqual(null, context, "context should not be null");\r
163                 Assert.IsInstanceOf<ComponentRunningContext>(context, "context should be ComponentRunningContext");\r
164             }\r
165             catch (Exception e)\r
166             {\r
167                 Assert.Fail("Failed to get running context. " + e.ToString());\r
168             }\r
169 \r
170             ComponentManager.TerminateBackgroundComponent(context);\r
171             await Task.Delay(5000);\r
172 \r
173             Assert.True(context.IsTerminated, CompoId + " should be terminated");\r
174             Log.Debug(LogTag, "END");\r
175         }\r
176 \r
177         [Test]\r
178         [Category("P2")]\r
179         [Description("Test: Terminate a running service component with null argument")]\r
180         [Property("SPEC", "Tizen.Applications.ComponentBased.ComponentManager.TerminateBackgroundComponent M")]\r
181         [Property("SPEC_URL", "-")]\r
182         [Property("CRITERIA", "MEX")]\r
183         [Property("AUTHOR", "Hwankyu Jhun, h.jhun@samsung.com")]\r
184         public void TerminateBackgroundComponent_CHECK_ArgumentException()\r
185         {\r
186             Log.Debug(LogTag, "START");\r
187             try\r
188             {\r
189                 ComponentManager.TerminateBackgroundComponent(null);\r
190             }\r
191             catch (ArgumentException)\r
192             {\r
193                 Assert.Pass();\r
194             }\r
195             Log.Debug(LogTag, "END");\r
196         }\r
197     }\r
198 }\r