2 * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
\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
8 * http://www.apache.org/licenses/LICENSE-2.0
\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
17 using NUnit.Framework;
\r
18 using NUnit.Framework.TUnit;
\r
20 using System.Collections.Generic;
\r
21 using System.Threading;
\r
22 using System.Threading.Tasks;
\r
25 namespace Tizen.Applications.ComponentBased.Tests
\r
28 [Description("Tizen.Applications.ComponentBased.ComponentManager Tests")]
\r
29 public class ComponentManagerTests
\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
41 Log.Debug(LogTag, "Preconditions for each TEST");
\r
44 bool isRunning = ComponentManager.IsRunning(CompoId);
\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
57 public void Destroy()
\r
59 Log.Debug(LogTag, "Postconditions for each TEST");
\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
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
76 if (string.Equals(inst.ComponentId, CompoId))
\r
82 Assert.True(_flag, "Could not find the given component in list of installed components.");
\r
83 Log.Debug(LogTag, "END");
\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
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
100 if (string.Equals(context.ComponentId, CompoId))
\r
106 Assert.True(_flag, "Could not find the given component in list of running components.");
\r
107 Log.Debug(LogTag, "END");
\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
120 Log.Debug(LogTag, "START");
\r
121 Assert.True(ComponentManager.IsRunning(CompoId), CompoId + " should be running");
\r
122 Log.Debug(LogTag, "END");
\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
135 Log.Debug(LogTag, "START");
\r
138 bool isRunning = ComponentManager.IsRunning(null);
\r
140 catch (ArgumentException)
\r
144 Log.Debug(LogTag, "END");
\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
156 Log.Debug(LogTag, "START");
\r
157 ComponentRunningContext context = null;
\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
165 catch (Exception e)
\r
167 Assert.Fail("Failed to get running context. " + e.ToString());
\r
170 ComponentManager.TerminateBackgroundComponent(context);
\r
171 await Task.Delay(5000);
\r
173 Assert.True(context.IsTerminated, CompoId + " should be terminated");
\r
174 Log.Debug(LogTag, "END");
\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
186 Log.Debug(LogTag, "START");
\r
189 ComponentManager.TerminateBackgroundComponent(null);
\r
191 catch (ArgumentException)
\r
195 Log.Debug(LogTag, "END");
\r