</ItemGroup>
<ItemGroup>
- <PackageReference Include="Tizen.NET" Version="9.0.0.15923">
+ <PackageReference Include="Tizen.NET" Version="9.0.0.16089">
<ExcludeAssets>Runtime</ExcludeAssets>
</PackageReference>
</ItemGroup>
+++ /dev/null
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-using Tizen.Applications.ComponentBased;
-
-namespace ServicePort
-{
- public sealed class Port : ComponentPort
- {
- public Port(string name) : base(name)
- {
- Log.Info("Port(): " + PortName);
- }
-
- protected override void OnRequestEvent(string sender, object request)
- {
- Log.Info("OnRequestEvent() sender: " + sender);
- if (request.GetType() == typeof(Request))
- {
- var req = (Request)request;
- Log.Info("Command: " + req.Command + " Sequence: " + req.Sequence + " Message: " + req.Message);
-
- if (req.Command == "OnRequestEvent_CHECK")
- {
- Service.SendMessage(0);
- }
- }
- else if (request.GetType() == typeof(Response))
- {
- var res = (Response)request;
- Log.Info("Command: " + res.Command + " Sequence: " + res.Sequence + " Result: " + res.Result);
- }
- }
-
- protected override object OnSyncRequestEvent(string sender, object request)
- {
- Log.Info("OnSyncRequestEvent() sender: " + sender);
- Response res;
- if (request.GetType() == typeof(Request))
- {
- var req = (Request)request;
- Log.Info("Command: " + req.Command + " Sequence: " + req.Sequence + " Message: " + req.Message);
-
- if (req.Command == "OnSyncRequestEvent_CHECK")
- {
- Service.SendMessage(0);
- }
-
- res = new Response(req.Command, req.Sequence, 0);
- }
- else
- {
- Log.Error("Invalid request");
- res = new Response("Unknown", -1, -1);
- }
-
- return res;
- }
- }
-
-}
*/
using System;
-using System.Threading;
using Tizen.Applications;
+using Tizen.Applications.ComponentBased;
using Tizen.Applications.ComponentBased.Common;
using Tizen.Applications.Messages;
{
public class Service : ServiceComponent
{
- private Thread _thread;
- private Port _port;
- private Port _dummyPort;
- private Thread _dummyThread;
+ private ComponentTask _task;
+ private ComponentTask _dummyTask;
private int _sequence = 0;
private static string _command = string.Empty;
private static string _caller = string.Empty;
private static string _remotePortName = string.Empty;
private static MessagePort _messagePort;
- private void ThreadMethod()
+ private void OnMessageRecevied(object sender, MessageReceivedEventArgs args)
{
- Log.Info("ThreadMethod()");
- _port.WaitForEvent();
+ Log.Info("");
}
- private void DummyThreadMethod()
+ private void OnRequestReceived(object sender, RequestEventArgs args)
{
- Log.Info("DummyThreadMethod()");
- _dummyPort.WaitForEvent();
- }
+ Log.Info("OnRequestReceived() Sender: " + args.Sender);
+ var request = args.Request;
+ if (request.GetType() == typeof(Request))
+ {
+ var req = (Request)request;
+ Log.Info("Command: " + req.Command + " Sequence: " + req.Sequence + " Message: " + req.Message);
- private void OnMessageRecevied(object sender, MessageReceivedEventArgs args)
- {
- Log.Info("");
+ if (req.Command == "RequestReceived_CHECK" ||
+ req.Command == "Sender_GET" ||
+ req.Command == "Request_GET")
+ {
+ SendMessage(0);
+ }
+
+ if (args.IsReplyRequested)
+ {
+ args.Reply = new Response(req.Command, req.Sequence, 0);
+ if (req.Command == "IsReplyRequested_CHECK")
+ {
+ SendMessage(0);
+ }
+ else if (req.Command == "Reply_SET_AND_GET")
+ {
+ var reply = (Response)args.Reply;
+ SendMessage(reply.Result);
+ }
+ }
+ }
+ else if (request.GetType() == typeof(Response))
+ {
+ var res = (Response)request;
+ Log.Info("Command: " + res.Command + " Sequence: " + res.Sequence + " Result: " + res.Result);
+ }
+ else
+ {
+ Log.Warn("Invalid request");
+ if (args.IsReplyRequested)
+ {
+ args.Reply = new Response("Unknown", -1, -1);
+ }
+ }
}
public override bool OnCreate()
{
Log.Info("OnCreate()");
- _port = new Port("ServicePort");
- _port.AddPrivilege("http://tizen.org/privilege/appmanager.launch");
- _thread = new Thread(new ThreadStart(ThreadMethod));
- _thread.Start();
+ _task = new ComponentTask(new ComponentPort("ServicePort"));
+ _task.Port.AddPrivilege("http://tizen.org/privilege/appmanager.launch");
+ _task.Port.RequestReceived += OnRequestReceived;
+ _task.Start();
- _dummyPort = new Port("DummyPort");
- _dummyPort.AddPrivilege("http://tizen.org/privilege/datasharing");
- _dummyThread = new Thread(new ThreadStart(DummyThreadMethod));
- _dummyThread.Start();
+ _dummyTask = new ComponentTask(new ComponentPort("DummyPort"));
+ _dummyTask.Port.AddPrivilege("http://tizen.org/privilege/datasharing");
+ _dummyTask.Start();
_messagePort = new MessagePort("ServicePort", false);
_messagePort.MessageReceived += OnMessageRecevied;
Log.Info("END");
}
- private void HandleCommand()
+ private async void HandleCommand()
{
Log.Info("START");
if (_command == "Send_CHECK_WITHOUT_EXCEPTION")
try
{
var request = new Request(_command, _sequence++, _caller);
- _port.Send(_port.PortName, 5000, request);
+ _task.Port.Send(_task.Port.PortName, 5000, request);
SendMessage(0);
}
catch
SendMessage(-1);
}
}
- else if (_command == "SendSync_CHECK_WITHOUT_EXCEPTION")
+ else if (_command == "SendAndReceive_CHECK_WITHOUT_EXCEPTION")
{
try
{
var request = new Request(_command, _sequence++, _caller);
- var response = (Response)_port.SendSync(_port.PortName, 5000, request);
+ var response = (Response)_task.Port.SendAndReceive(_task.Port.PortName, 5000, request);
SendMessage(0);
}
catch
SendMessage(-1);
}
}
- else if (_command == "OnSyncRequestEvent_CHECK")
+ else if (_command == "SendAndReceiveAsync_CHECK_WITHOUT_EXCEPTION")
{
try
{
var request = new Request(_command, _sequence++, _caller);
- var response = (Response)_port.SendSync(_port.PortName, 5000, request);
+ await _task.Port.SendAndReceiveAsync(_task.Port.PortName, 5000, request);
+ SendMessage(0);
}
catch
{
SendMessage(-1);
}
}
- else if (_command == "OnRequestEvent_CHECK")
+ else if (_command == "RequestReceived_CHECK")
{
try
{
var request = new Request(_command, _sequence++, _caller);
- _port.Send(_port.PortName, 5000, request);
+ var response = (Response)_task.Port.SendAndReceive(_task.Port.PortName, 5000, request);
}
catch
{
try
{
var request = new Request(_command, _sequence++, _caller);
- _port.Send(_dummyPort.PortName, 5000, request);
+ _task.Port.Send(_dummyTask.Port.PortName, 5000, request);
SendMessage(-1);
}
catch (UnauthorizedAccessException)
SendMessage(0);
}
}
- else if (_command == "SendSync_CHECK_WITH_UNAUTHORIZEDACCESSEXCEPTION")
+ else if (_command == "Send_WITH_EMPTYSTRING_AND_CHECK_ARGUMENTEXCEPTION")
+ {
+ try
+ {
+ var request = new Request(_command, _sequence++, _caller);
+ _task.Port.Send("", 5000, request);
+ SendMessage(-1);
+ }
+ catch (ArgumentException)
+ {
+ Log.Error("Failed to send request");
+ SendMessage(0);
+ }
+ }
+ else if (_command == "SendAndReceive_CHECK_WITH_UNAUTHORIZEDACCESSEXCEPTION")
+ {
+ try
+ {
+ var request = new Request(_command, _sequence++, _caller);
+ var response = (Response)_task.Port.SendAndReceive(_dummyTask.Port.PortName, 5000, request);
+ SendMessage(-1);
+ }
+ catch (UnauthorizedAccessException)
+ {
+ Log.Error("Failed to send request");
+ SendMessage(0);
+ }
+ }
+ else if (_command == "SendAndReceive_WITH_EMPTYSTRING_AND_CHECK_ARGUMENTEXCEPTION")
+ {
+ try
+ {
+ var request = new Request(_command, _sequence++, _caller);
+ var response = (Response)_task.Port.SendAndReceive("", 5000, request);
+ SendMessage(-1);
+ }
+ catch (ArgumentException)
+ {
+ Log.Error("Failed to send request");
+ SendMessage(0);
+ }
+ }
+ else if (_command == "SendAndReceiveAsync_CHECK_WITH_UNAUTHORIZEDACCESSEXCEPTION")
{
try
{
var request = new Request(_command, _sequence++, _caller);
- var response = (Response)_port.SendSync(_dummyPort.PortName, 5000, request);
+ await _task.Port.SendAndReceiveAsync(_dummyTask.Port.PortName, 5000, request);
SendMessage(-1);
}
catch (UnauthorizedAccessException)
SendMessage(0);
}
}
+ else if (_command == "SendAndReceiveAsync_WITH_EMPTYSTRING_AND_CHECK_ARGUMENTEXCEPTION")
+ {
+ try
+ {
+ var request = new Request(_command, _sequence++, _caller);
+ await _task.Port.SendAndReceiveAsync("", 5000, request);
+ SendMessage(-1);
+ }
+ catch (ArgumentException)
+ {
+ Log.Error("Failed to send request");
+ SendMessage(0);
+ }
+ }
+ else if (_command == "Sender_GET" || _command == "Request_GET")
+ {
+ try
+ {
+ var request = new Request(_command, _sequence++, _caller);
+ _task.Port.Send(_task.Port.PortName, 5000, request);
+ }
+ catch
+ {
+ Log.Error("Failed to send request");
+ SendMessage(-1);
+ }
+ }
+ else if (_command == "IsReplyRequested_CHECK" || _command == "Reply_SET_AND_GET")
+ {
+ try
+ {
+ var request = new Request(_command, _sequence++, _caller);
+ var response = (Response)_task.Port.SendAndReceive(_task.Port.PortName, 5000, request);
+ }
+ catch
+ {
+ Log.Error("Failed to send request");
+ SendMessage(-1);
+ }
+ }
Log.Info("END");
}
{
Log.Info("OnDestroy()");
base.OnDestroy();
- _port.Cancel();
- _thread.Join();
- _dummyPort.Cancel();
- _dummyThread.Join();
+ if (_dummyTask != null)
+ {
+ _dummyTask.Stop();
+ _dummyTask.Port?.Dispose();
+ _dummyTask = null;
+ }
+
+ if (_task != null)
+ {
+ _task.Stop();
+ if (_task.Port != null)
+ {
+ _task.Port.RequestReceived -= OnRequestReceived;
+ _task.Port.Dispose();
+ }
+ _task = null;
+ }
+
+ if (_messagePort != null)
+ {
+ _messagePort.StopListening();
+ _messagePort.MessageReceived -= OnMessageRecevied;
+ _messagePort.Dispose();
+ _messagePort = null;
+ }
}
}
}
<Import Project="..\Common\dependencies.props" />
<ItemGroup>
- <PackageReference Include="Tizen.NET" Version="$(TizenNETVersion)">
+ <PackageReference Include="Tizen.NET" Version="9.0.0.16089">
<ExcludeAssets>Runtime</ExcludeAssets>
</PackageReference>
<PackageReference Include="Tizen.NET.Sdk" Version="$(TizenNETSdkVersion)" />
using System.Threading;
using System.Threading.Tasks;
using System.Timers;
-using Tizen.Applications;
using Tizen.Applications.Messages;
using Timer = System.Timers.Timer;
-namespace Tizen.Applications.ComponentBased.Tests {
+namespace Tizen.Applications.ComponentBased.Tests
+{
[TestFixture]
[Description("Tizen.Applications.ComponentBased.ComponentPort Tests")]
{
private const string LogTag = "ComponentPort.Tests";
private MessagePort _messagePort;
- private TestPort _port;
+ private ComponentPort _port;
private Timer _timer;
private Thread _thread;
private uint _count;
private int _receivedResult;
private bool _received;
- public class TestPort : ComponentPort
- {
- public TestPort(string portName) : base(portName)
- {
- }
-
- protected override void OnRequestEvent(string sender, object request)
- {
- }
-
- protected override object OnSyncRequestEvent(string sender, object request)
- {
- return null;
- }
- }
-
void OnMessageReceived(object sender, MessageReceivedEventArgs e)
{
Log.Info(LogTag, "START sender: " + sender);
_receivedResult = -1;
_received = false;
- _port = new TestPort("Test");
+ _port = new ComponentPort("Test");
_count = 0;
}
_port?.Dispose();
_port = null;
- _messagePort?.StopListening();
- _messagePort?.Dispose();
- _messagePort = null;
+ if (_messagePort != null)
+ {
+ _messagePort.MessageReceived -= OnMessageReceived;
+ _messagePort.StopListening();
+ _messagePort.Dispose();
+ _messagePort = null;
+ }
}
private void SendLaunchRequest(string command)
public void ComponentPort_INIT()
{
Log.Info(LogTag, "START");
- var testPort = new TestPort("Test2");
+ var testPort = new ComponentPort("Test2");
Assert.IsInstanceOf<ComponentPort>(testPort, "Should be an instance of ComponentPort");
Assert.IsNotNull(testPort, "testPort should not be null");
testPort?.Dispose();
public void ComponentPort_INIT_WITH_NULL_AND_CHECK_ARGUMENTEXCEPTION()
{
Log.Info(LogTag, "START");
- try\r
- {\r
- var testPort = new TestPort(null);\r
- Assert.Fail("Should throw ArgumentException");\r
+ try
+ {
+ var testPort = new ComponentPort(null);
+ Assert.Fail("Should throw ArgumentException");
}
catch (ArgumentException)
- {\r
- Assert.Pass("ArgumentException: Pass");\r
+ {
+ Assert.Pass("ArgumentException: Pass");
}
Log.Info(LogTag, "END");
}
public void ComponentPort_INIT_WITH_EMPTYSTRING_AND_CHECK_ARGUMENTEXCEPTION()
{
Log.Info(LogTag, "START");
- try\r
- {\r
- var testPort = new TestPort("");\r
- Assert.Fail("Should throw ArgumentException");\r
+ try
+ {
+ var testPort = new ComponentPort("");
+ Assert.Fail("Should throw ArgumentException");
}
catch (ArgumentException)
- {\r
- Assert.Pass("ArgumentException: Pass");\r
+ {
+ Assert.Pass("ArgumentException: Pass");
}
Log.Info(LogTag, "END");
}
public void ComponentPort_INIT_AND_CHECK_IOEXCEPTION()
{
Log.Info(LogTag, "START");
- try\r
- {\r
- var testPort = new TestPort("Test");\r
- Assert.Fail("Should throw IOException");\r
+ try
+ {
+ var testPort = new ComponentPort("Test");
+ Assert.Fail("Should throw IOException");
+ }
+ catch (global::System.IO.IOException)
+ {
+ Assert.Pass("IOException: Pass");
}
- catch (global::System.IO.IOException)\r
- {\r
- Assert.Pass("IOException: Pass");\r
- }\r
Log.Info(LogTag, "END");
}
public void AddPrivilege_CHECK_WITH_EMPTYSTRING_AND_CHECK_ARGUMENTEXCEPTION()
{
Log.Info(LogTag, "START");
- try\r
- {\r
+ try
+ {
_port.AddPrivilege("");
- Assert.Fail("Should throw ArgumentException");\r
+ Assert.Fail("Should throw ArgumentException");
}
catch (ArgumentException)
- {\r
+ {
Log.Error(LogTag, "ArgumentException occurs");
- Assert.Pass("ArgumentException: Pass");\r
+ Assert.Pass("ArgumentException: Pass");
}
Log.Info(LogTag, "END");
}
+ [Test]
+ [Category("P1")]
+ [Description("Test : Wait for port")]
+ [Property("SPEC", "Tizen.Applications.ComponentBased.ComponentPort.WaitForPort M")]
+ [Property("SPEC_URL", "-")]
+ [Property("CRITERIA", "MR")]
+ [Property("AUTHOR", "Hwankyu Jhun, h.jhun@samsung.com")]
+ public async Task WaitForPort_CHECK()
+ {
+ Log.Info(LogTag, "START");
+ /// If the target port is not ready, WaitForPort() will not be finished until the port is ready.
+ await ComponentPort.WaitForPort("Test");
+ Assert.Pass("Test Port exists");
+ Log.Info(LogTag, "END");
+ }
+
private void Timeout(object sender, ElapsedEventArgs args)
{
_count++;
}
[Test]
+ [Category("P2")]
+ [Description("Test : Send a request asynchronously")]
+ [Property("SPEC", "Tizen.Applications.ComponentBased.ComponentPort.Send M")]
+ [Property("SPEC_URL", "-")]
+ [Property("CRITERIA", "MEX")]
+ [Property("AUTHOR", "Hwankyu Jhun, h.jhun@samsung.com")]
+ public async Task Send_WITH_EMPTYSTRING_AND_CHECK_ARGUMENTEXCEPTION()
+ {
+ Log.Info(LogTag, "START");
+ _thread = new Thread(() => SetTimer(new ElapsedEventHandler(CheckReceivedMessage)));
+ _thread.Start();
+
+ SendLaunchRequest("Send_WITH_EMPTYSTRING_AND_CHECK_ARGUMENTEXCEPTION");
+ await Task.Delay(4000);
+
+ _timer.Stop();
+ _thread.Join();
+
+ Assert.AreEqual(_receivedCommand, "Send_WITH_EMPTYSTRING_AND_CHECK_ARGUMENTEXCEPTION", "Recevied Command should be 'Send_WITH_EMPTYSTRING_AND_CHECK_ARGUMENTEXCEPTION'");
+ Assert.AreEqual(_receivedResult, 0, "Recevied Result should be '0'");
+ Log.Info(LogTag, "END");
+ }
+
+ [Test]
[Category("P1")]
- [Description("Test : Send a request synchronously")]
- [Property("SPEC", "Tizen.Applications.ComponentBased.ComponentPort.SendSync M")]
+ [Description("Test : Send a request and receive a response synchronously")]
+ [Property("SPEC", "Tizen.Applications.ComponentBased.ComponentPort.SendAndReceive M")]
[Property("SPEC_URL", "-")]
[Property("CRITERIA", "MR")]
[Property("AUTHOR", "Hwankyu Jhun, h.jhun@samsung.com")]
- public async Task SendSync_CHECK_WITHOUT_EXCEPTION()
+ public async Task SendAndReceive_CHECK_WITHOUT_EXCEPTION()
{
Log.Info(LogTag, "START");
_thread = new Thread(() => SetTimer(new ElapsedEventHandler(CheckReceivedMessage)));
_thread.Start();
- SendLaunchRequest("SendSync_CHECK_WITHOUT_EXCEPTION");
+ SendLaunchRequest("SendAndReceive_CHECK_WITHOUT_EXCEPTION");
await Task.Delay(8000);
_timer.Stop();
_thread.Join();
- Assert.AreEqual(_receivedCommand, "SendSync_CHECK_WITHOUT_EXCEPTION", "Recevied Command should be 'SendSync_CHECK_WITHOUT_EXCEPTION'");
+ Assert.AreEqual(_receivedCommand, "SendAndReceive_CHECK_WITHOUT_EXCEPTION", "Recevied Command should be 'SendAndReceive_CHECK_WITHOUT_EXCEPTION'");
Assert.AreEqual(_receivedResult, 0, "Recevied Result should be '0'");
Log.Info(LogTag, "END");
}
[Test]
[Category("P1")]
- [Description("Test : Send a request synchronously")]
- [Property("SPEC", "Tizen.Applications.ComponentBased.ComponentPort.SendSync M")]
+ [Description("Test : Send a request and receive a response synchronously")]
+ [Property("SPEC", "Tizen.Applications.ComponentBased.ComponentPort.SendAndReceive M")]
[Property("SPEC_URL", "-")]
[Property("CRITERIA", "MEX")]
[Property("AUTHOR", "Hwankyu Jhun, h.jhun@samsung.com")]
- public void SendSync_CHECK_WITH_ARUMENTEXCEPTION()
+ public void SendAndReceive_CHECK_WITH_ARUMENTEXCEPTION()
{
Log.Info(LogTag, "START");
try
{
- var res = _port.SendSync("ServicePort", 5000, null);
- Assert.Fail();
+ var res = _port.SendAndReceive("ServicePort", 5000, null);
+ Assert.Fail("DO NOT COME HERE");
}
catch (ArgumentException)
{
- Assert.Pass();
+ Assert.Pass("ArgumentException: Pass");
}
Log.Info(LogTag, "END");
}
[Test]
[Category("P2")]
- [Description("Test : Send a request synchronously")]
- [Property("SPEC", "Tizen.Applications.ComponentBased.ComponentPort.SendSync M")]
+ [Description("Test : Send a request and receive a response synchronously")]
+ [Property("SPEC", "Tizen.Applications.ComponentBased.ComponentPort.SendAndReceive M")]
+ [Property("SPEC_URL", "-")]
+ [Property("CRITERIA", "MEX")]
+ [Property("AUTHOR", "Hwankyu Jhun, h.jhun@samsung.com")]
+ public async Task SendAndReceive_CHECK_WITH_UNAUTHORIZEDACCESSEXCEPTION()
+ {
+ Log.Info(LogTag, "START");
+ _thread = new Thread(() => SetTimer(new ElapsedEventHandler(CheckReceivedMessage)));
+ _thread.Start();
+
+ SendLaunchRequest("SendAndReceive_CHECK_WITH_UNAUTHORIZEDACCESSEXCEPTION");
+ await Task.Delay(4000);
+
+ _timer.Stop();
+ _thread.Join();
+
+ Assert.AreEqual(_receivedCommand, "SendAndReceive_CHECK_WITH_UNAUTHORIZEDACCESSEXCEPTION", "Recevied Command should be 'SendAndReceive_CHECK_WITH_UNAUTHORIZEDACCESSEXCEPTION'");
+ Assert.AreEqual(_receivedResult, 0, "Recevied Result should be '0'");
+ Log.Info(LogTag, "END");
+ }
+
+ [Test]
+ [Category("P2")]
+ [Description("Test : Send a request and receive a response synchronously")]
+ [Property("SPEC", "Tizen.Applications.ComponentBased.ComponentPort.SendAndReceive M")]
[Property("SPEC_URL", "-")]
[Property("CRITERIA", "MEX")]
[Property("AUTHOR", "Hwankyu Jhun, h.jhun@samsung.com")]
- public async Task SendSync_CHECK_WITH_UNAUTHORIZEDACCESSEXCEPTION()
+ public async Task SendAndReceive_WITH_EMPTYSTRING_AND_CHECK_ARGUMENTEXCEPTION()
{
Log.Info(LogTag, "START");
_thread = new Thread(() => SetTimer(new ElapsedEventHandler(CheckReceivedMessage)));
_thread.Start();
- SendLaunchRequest("SendSync_CHECK_WITH_UNAUTHORIZEDACCESSEXCEPTION");
+ SendLaunchRequest("SendAndReceive_WITH_EMPTYSTRING_AND_CHECK_ARGUMENTEXCEPTION");
await Task.Delay(4000);
_timer.Stop();
_thread.Join();
- Assert.AreEqual(_receivedCommand, "SendSync_CHECK_WITH_UNAUTHORIZEDACCESSEXCEPTION", "Recevied Command should be 'SendSync_CHECK_WITH_UNAUTHORIZEDACCESSEXCEPTION'");
+ Assert.AreEqual(_receivedCommand, "SendAndReceive_WITH_EMPTYSTRING_AND_CHECK_ARGUMENTEXCEPTION", "Recevied Command should be 'SendAndReceive_WITH_EMPTYSTRING_AND_CHECK_ARGUMENTEXCEPTION'");
Assert.AreEqual(_receivedResult, 0, "Recevied Result should be '0'");
Log.Info(LogTag, "END");
}
[Test]
[Category("P1")]
- [Description("Test : OnSyncRequestEvent")]
- [Property("SPEC", "Tizen.Applications.ComponentBased.ComponentPort.OnSyncRequestEvent E")]
+ [Description("Test : Send a request and receive a response asynchronously")]
+ [Property("SPEC", "Tizen.Applications.ComponentBased.ComponentPort.SendAndReceiveAsync M")]
[Property("SPEC_URL", "-")]
- [Property("CRITERIA", "EVL")]
+ [Property("CRITERIA", "MR")]
+ [Property("AUTHOR", "Hwankyu Jhun, h.jhun@samsung.com")]
+ public async Task SendAndReceiveAsync_CHECK_WITHOUT_EXCEPTION()
+ {
+ Log.Info(LogTag, "START");
+ _thread = new Thread(() => SetTimer(new ElapsedEventHandler(CheckReceivedMessage)));
+ _thread.Start();
+
+ SendLaunchRequest("SendAndReceiveAsync_CHECK_WITHOUT_EXCEPTION");
+ await Task.Delay(8000);
+
+ _timer.Stop();
+ _thread.Join();
+
+ Assert.AreEqual(_receivedCommand, "SendAndReceiveAsync_CHECK_WITHOUT_EXCEPTION", "Recevied Command should be 'SendAndReceiveAsync_CHECK_WITHOUT_EXCEPTION'");
+ Assert.AreEqual(_receivedResult, 0, "Recevied Result should be '0'");
+ Log.Info(LogTag, "END");
+ }
+
+ [Test]
+ [Category("P1")]
+ [Description("Test : Send a request and receive a response asynchronously")]
+ [Property("SPEC", "Tizen.Applications.ComponentBased.ComponentPort.SendAndReceiveAsync M")]
+ [Property("SPEC_URL", "-")]
+ [Property("CRITERIA", "MEX")]
+ [Property("AUTHOR", "Hwankyu Jhun, h.jhun@samsung.com")]
+ public async Task SendAndReceiveAsync_CHECK_WITH_ARUMENTEXCEPTION()
+ {
+ Log.Info(LogTag, "START");
+ try
+ {
+ var result = await _port.SendAndReceiveAsync(null, 0, null);
+ Assert.Fail("DO NOT COME HERE");
+ }
+ catch (ArgumentException)
+ {
+ Assert.Pass("ArgumentException: Pass");
+ }
+ Log.Info(LogTag, "END");
+ }
+
+ [Test]
+ [Category("P2")]
+ [Description("Test : Send a request and receive a response asynchronously")]
+ [Property("SPEC", "Tizen.Applications.ComponentBased.ComponentPort.SendAndReceiveAsync M")]
+ [Property("SPEC_URL", "-")]
+ [Property("CRITERIA", "MEX")]
+ [Property("AUTHOR", "Hwankyu Jhun, h.jhun@samsung.com")]
+ public async Task SendAndReceiveAsync_CHECK_WITH_UNAUTHORIZEDACCESSEXCEPTION()
+ {
+ Log.Info(LogTag, "START");
+ _thread = new Thread(() => SetTimer(new ElapsedEventHandler(CheckReceivedMessage)));
+ _thread.Start();
+
+ SendLaunchRequest("SendAndReceiveAsync_CHECK_WITH_UNAUTHORIZEDACCESSEXCEPTION");
+ await Task.Delay(4000);
+
+ _timer.Stop();
+ _thread.Join();
+
+ Assert.AreEqual(_receivedCommand, "SendAndReceiveAsync_CHECK_WITH_UNAUTHORIZEDACCESSEXCEPTION", "Recevied Command should be 'SendAndReceiveAsync_CHECK_WITH_UNAUTHORIZEDACCESSEXCEPTION'");
+ Assert.AreEqual(_receivedResult, 0, "Recevied Result should be '0'");
+ Log.Info(LogTag, "END");
+ }
+
+ [Test]
+ [Category("P2")]
+ [Description("Test : Send a request and receive a response asynchronously")]
+ [Property("SPEC", "Tizen.Applications.ComponentBased.ComponentPort.SendAndReceiveAsync M")]
+ [Property("SPEC_URL", "-")]
+ [Property("CRITERIA", "MEX")]
[Property("AUTHOR", "Hwankyu Jhun, h.jhun@samsung.com")]
- public async Task OnSyncRequestEvent_CHECK()
+ public async Task SendAndReceiveAsync_WITH_EMPTYSTRING_AND_CHECK_ARGUMENTEXCEPTION()
{
Log.Info(LogTag, "START");
_thread = new Thread(() => SetTimer(new ElapsedEventHandler(CheckReceivedMessage)));
_thread.Start();
- SendLaunchRequest("OnSyncRequestEvent_CHECK");
+ SendLaunchRequest("SendAndReceiveAsync_WITH_EMPTYSTRING_AND_CHECK_ARGUMENTEXCEPTION");
await Task.Delay(4000);
_timer.Stop();
_thread.Join();
- Assert.AreEqual(_receivedCommand, "OnSyncRequestEvent_CHECK", "Recevied Command should be 'OnSyncRequestEvent_CHECK'");
+ Assert.AreEqual(_receivedCommand, "SendAndReceiveAsync_WITH_EMPTYSTRING_AND_CHECK_ARGUMENTEXCEPTION", "Recevied Command should be 'SendAndReceiveAsync_WITH_EMPTYSTRING_AND_CHECK_ARGUMENTEXCEPTION'");
Assert.AreEqual(_receivedResult, 0, "Recevied Result should be '0'");
Log.Info(LogTag, "END");
}
[Test]
[Category("P1")]
- [Description("Test : OnRequestEvent")]
- [Property("SPEC", "Tizen.Applications.ComponentBased.ComponentPort.OnRequestEvent E")]
+ [Description("Test : RequestReceived event handler")]
+ [Property("SPEC", "Tizen.Applications.ComponentBased.ComponentPort.RequestReceived E")]
[Property("SPEC_URL", "-")]
[Property("CRITERIA", "EVL")]
[Property("AUTHOR", "Hwankyu Jhun, h.jhun@samsung.com")]
- public async Task OnRequestEvent_CHECK()
+ public async Task RequestReceived_CHECK()
{
Log.Info(LogTag, "START");
_thread = new Thread(() => SetTimer(new ElapsedEventHandler(CheckReceivedMessage)));
_thread.Start();
- SendLaunchRequest("OnRequestEvent_CHECK");
+ SendLaunchRequest("RequestReceived_CHECK");
await Task.Delay(4000);
_timer.Stop();
_thread.Join();
- Assert.AreEqual(_receivedCommand, "OnRequestEvent_CHECK", "Recevied Command should be 'OnRequestEvent_CHECK'");
+ Assert.AreEqual(_receivedCommand, "RequestReceived_CHECK", "Recevied Command should be 'RequestReceived_CHECK'");
Assert.AreEqual(_receivedResult, 0, "Recevied Result should be '0'");
Log.Info(LogTag, "END");
}
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+using NUnit.Framework;
+using System.Threading.Tasks;
+using Tizen.Applications;
+using Tizen.Applications.ComponentBased;
+
+namespace Tizen.Applications.ComponentBased.Tests
+{
+ [TestFixture]
+ [Description("Tizen.Applications.ComponentBased.ComponentTask Tests")]
+ public class ComponentTaskTests
+ {
+ private static string LogTag = "ComponentPort.Tests";
+ private ComponentTask _task;
+ private ComponentPort _port;
+
+ private void OnRequestReceived(object sender, RequestEventArgs args)
+ {
+ }
+
+ [SetUp]
+ public void Init()
+ {
+ Log.Info(LogTag, "Preconditions for each TEST");
+ _port = new ComponentPort("TestTask");
+ _port.RequestReceived += OnRequestReceived;
+ _task = new ComponentTask(_port);
+ }
+
+ [TearDown]
+ public void Destroy()
+ {
+ Log.Info(LogTag, "Postconditions for each TEST");
+ if (_task != null)
+ {
+ if (_task.IsRunning)
+ _task.Stop();
+
+ _task = null;
+ }
+
+ if (_port != null)
+ {
+ _port.RequestReceived -= OnRequestReceived;
+ _port.Dispose();
+ _port = null;
+ }
+ }
+
+ [Test]
+ [Category("P1")]
+ [Description("Test : ComponentTask method initialization")]
+ [Property("SPEC", "Tizen.Applications.ComponentBased.ComponentTask.ComponentTask C")]
+ [Property("SPEC_URL", "-")]
+ [Property("CRITERIA", "CONSTR")]
+ [Property("AUTHOR", "Hwankyu Jhun, h.jhun@samsung.com")]
+ public void ComponentTask_INIT()
+ {
+ Log.Info(LogTag, "START");
+ var testTask = new ComponentTask(new ComponentPort("Task"));
+ Assert.IsInstanceOf<ComponentTask>(testTask, "Should be an instance of ComponentTask");
+ Assert.IsNotNull(testTask, "testPort should not be null");
+ Log.Info(LogTag, "END");
+ }
+
+ [Test]
+ [Category("P1")]
+ [Description("Test : Starts the task.")]
+ [Property("SPEC", "Tizen.Applications.ComponentBased.ComponentTask.Start M")]
+ [Property("SPEC_URL", "-")]
+ [Property("CRITERIA", "MR")]
+ [Property("AUTHOR", "Hwankyu Jhun, h.jhun@samsung.com")]
+ public async Task Start_CHECK_RUNNING()
+ {
+ Log.Info(LogTag, "START");
+ _task.Start();
+ // To wait until the main loop is running properly, the delay is needed.
+ await Task.Delay(1000);
+
+ Assert.AreEqual(true, _task.IsRunning, "task should be running");
+ Log.Info(LogTag, "END");
+ }
+
+ [Test]
+ [Category("P1")]
+ [Description("Test : Stops the task.")]
+ [Property("SPEC", "Tizen.Applications.ComponentBased.ComponentTask.Stop M")]
+ [Property("SPEC_URL", "-")]
+ [Property("CRITERIA", "MR")]
+ [Property("AUTHOR", "Hwankyu Jhun, h.jhun@samsung.com")]
+ public async Task Stop_CHECK_RUNNING()
+ {
+ Log.Info(LogTag, "START");
+ _task.Start();
+ // To wait until the main loop is running properly, the delay is needed.
+ await Task.Delay(1000);
+
+ _task.Stop();
+ Assert.AreEqual(false, _task.IsRunning, "task should not be running");
+ Log.Info(LogTag, "END");
+ }
+
+ [Test]
+ [Category("P1")]
+ [Description("Test : property IsRunning of ComponentTask")]
+ [Property("SPEC", "Tizen.Applications.ComponentBased.ComponentTask.IsRunning A")]
+ [Property("SPEC_URL", "-")]
+ [Property("CRITERIA", "PRO")]
+ [Property("AUTHOR", "Hwankyu Jhun, h.jhun@samsung.com")]
+ public async Task IsRunning_CHECK()
+ {
+ Log.Info(LogTag, "START");
+ _task.Start();
+ // To wait until the main loop is running properly, the delay is needed.
+ await Task.Delay(1000);
+ Assert.AreEqual(true, _task.IsRunning, "The task should be running");
+
+ _task.Stop();
+ Assert.AreEqual(false, _task.IsRunning, "The task should not be running") ;
+ Log.Info(LogTag, "END");
+ }
+
+ [Test]
+ [Category("P1")]
+ [Description("Test : property Port of ComponentTask")]
+ [Property("SPEC", "Tizen.Applications.ComponentBased.ComponentTask.Port A")]
+ [Property("SPEC_URL", "-")]
+ [Property("CRITERIA", "PRO")]
+ [Property("AUTHOR", "Hwankyu Jhun, h.jhun@samsung.com")]
+ public void Port_GET()
+ {
+ Log.Info(LogTag, "START");
+ var port = _task.Port;
+ Assert.IsInstanceOf<ComponentPort>(port, "Should be an instance of ComponentPort");
+ Assert.IsNotNull(port, "testPort should not be null");
+ Assert.AreEqual(port, _port, "Should be equal to port");
+ Log.Info(LogTag, "END");
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+using NUnit.Framework;
+using System;
+using System.Threading;
+using System.Threading.Tasks;
+using System.Timers;
+using Timer = System.Timers.Timer;
+using Tizen.Applications.Messages;
+
+namespace Tizen.Applications.ComponentBased.Tests
+{
+
+ [TestFixture]
+ [Description("Tizen.Applications.ComponentBased.RequestEventArgs Tests")]
+ public class RequestEventArgsTests
+ {
+ private const string LogTag = "ComponentPort.Tests";
+ private MessagePort _messagePort;
+ private string _receivedCommand;
+ private int _receivedResult;
+ private bool _received;
+ private Timer _timer;
+ private Thread _thread;
+
+ void OnMessageReceived(object sender, MessageReceivedEventArgs e)
+ {
+ Log.Info(LogTag, "START sender: " + sender);
+ try
+ {
+ _receivedCommand = e.Message.GetItem<string>("command");
+ _receivedResult = int.Parse(e.Message.GetItem<string>("result"));
+ Log.Info(LogTag, "Command: " + _receivedCommand + " Result: " + _receivedResult);
+ _received = true;
+ }
+ catch (ArgumentException)
+ {
+ Log.Error(LogTag, "ArgumentException occurs");
+ }
+ catch (InvalidOperationException)
+ {
+ Log.Error(LogTag, "InvalidOperationException occurs");
+ }
+ Log.Info(LogTag, "END");
+ }
+
+ [SetUp]
+ public void Init()
+ {
+ Log.Info(LogTag, "Preconditions for each TEST");
+ SendLaunchRequest("wakeup");
+
+ _messagePort = new MessagePort("ComponentPort.Tests", false);
+ _messagePort.MessageReceived += OnMessageReceived;
+ _messagePort.Listen();
+
+ _receivedCommand = string.Empty;
+ _receivedResult = -1;
+ _received = false;
+ }
+
+ [TearDown]
+ public void Destroy()
+ {
+ Log.Info(LogTag, "Postconditions for each TEST");
+ _timer = null;
+ _thread = null;
+
+ if (_messagePort != null)
+ {
+ _messagePort.MessageReceived -= OnMessageReceived;
+ _messagePort.StopListening();
+ _messagePort.Dispose();
+ _messagePort = null;
+ }
+ }
+
+ private void SendLaunchRequest(string command)
+ {
+ Log.Info(LogTag, "START command: " + command);
+ AppControl appControl = new AppControl();
+ appControl.ApplicationId = "org.tizen.example.ComponentPortTest";
+ appControl.ComponentId = "Service";
+ appControl.ExtraData.Add("command", command);
+ appControl.ExtraData.Add("caller", Application.Current.ApplicationInfo.ApplicationId);
+ appControl.ExtraData.Add("message-port", "ComponentPort.Tests");
+ try
+ {
+ AppControl.SendLaunchRequest(appControl);
+ }
+ catch (ArgumentNullException)
+ {
+ Log.Error(LogTag, "ArgumentNullException occurs");
+ }
+ catch (InvalidOperationException)
+ {
+ Log.Error(LogTag, "InvalidOperationException occurs");
+ }
+ catch (TimeoutException)
+ {
+ Log.Error(LogTag, "TimeoutException occurs");
+ }
+ Log.Info(LogTag, "END");
+ }
+
+ private void SetTimer(ElapsedEventHandler handler)
+ {
+ Log.Info(LogTag, "SetTimer()");
+ _timer = new Timer(5 * 100);
+ _timer.Elapsed += handler;
+ _timer.Start();
+ }
+
+ private void CheckReceivedMessage(object sender, ElapsedEventArgs args)
+ {
+ Log.Info(LogTag, "START");
+ if (_received)
+ {
+ Log.Info(LogTag, "MessageReceived");
+ _timer.Stop();
+ }
+ Log.Info(LogTag, "END");
+ }
+
+ [Test]
+ [Category("P1")]
+ [Description("Test : property Sender of RequestEventArgs")]
+ [Property("SPEC", "Tizen.Applications.ComponentBased.RequestEventArgs.Sender A")]
+ [Property("SPEC_URL", "-")]
+ [Property("CRITERIA", "PRO")]
+ [Property("AUTHOR", "Hwankyu Jhun, h.jhun@samsung.com")]
+ public async Task Sender_GET()
+ {
+ Log.Info(LogTag, "START");
+ _thread = new Thread(() => SetTimer(new ElapsedEventHandler(CheckReceivedMessage)));
+ _thread.Start();
+
+ SendLaunchRequest("Sender_GET");
+ await Task.Delay(4000);
+
+ _timer.Stop();
+ _thread.Join();
+
+ Assert.AreEqual(_receivedCommand, "Sender_GET", "Recevied Command should be 'Sender_GET'");
+ Assert.AreEqual(_receivedResult, 0, "Recevied Result should be '0'");
+ Log.Info(LogTag, "END");
+ }
+
+ [Test]
+ [Category("P1")]
+ [Description("Test : property Request of RequestEventArgs")]
+ [Property("SPEC", "Tizen.Applications.ComponentBased.RequestEventArgs.Request A")]
+ [Property("SPEC_URL", "-")]
+ [Property("CRITERIA", "PRO")]
+ [Property("AUTHOR", "Hwankyu Jhun, h.jhun@samsung.com")]
+ public async Task Request_GET()
+ {
+ Log.Info(LogTag, "START");
+ _thread = new Thread(() => SetTimer(new ElapsedEventHandler(CheckReceivedMessage)));
+ _thread.Start();
+
+ SendLaunchRequest("Request_GET");
+ await Task.Delay(4000);
+
+ _timer.Stop();
+ _thread.Join();
+
+ Assert.AreEqual(_receivedCommand, "Request_GET", "Recevied Command should be 'Request_GET'");
+ Assert.AreEqual(_receivedResult, 0, "Recevied Result should be '0'");
+ Log.Info(LogTag, "END");
+ }
+
+ [Test]
+ [Category("P1")]
+ [Description("Test : property IsReplyRequested of RequestEventArgs")]
+ [Property("SPEC", "Tizen.Applications.ComponentBased.RequestEventArgs.IsReplyRequested A")]
+ [Property("SPEC_URL", "-")]
+ [Property("CRITERIA", "PRO")]
+ [Property("AUTHOR", "Hwankyu Jhun, h.jhun@samsung.com")]
+ public async Task IsReplyRequested_CHECK()
+ {
+ Log.Info(LogTag, "START");
+ _thread = new Thread(() => SetTimer(new ElapsedEventHandler(CheckReceivedMessage)));
+ _thread.Start();
+
+ SendLaunchRequest("IsReplyRequested_CHECK");
+ await Task.Delay(4000);
+
+ _timer.Stop();
+ _thread.Join();
+
+ Assert.AreEqual(_receivedCommand, "IsReplyRequested_CHECK", "Recevied Command should be 'IsReplyRequested_CHECK'");
+ Assert.AreEqual(_receivedResult, 0, "Recevied Result should be '0'");
+ Log.Info(LogTag, "END");
+ }
+
+ [Test]
+ [Category("P1")]
+ [Description("Test : property Reply of RequestEventArgs")]
+ [Property("SPEC", "Tizen.Applications.ComponentBased.RequestEventArgs.Reply A")]
+ [Property("SPEC_URL", "-")]
+ [Property("CRITERIA", "PRW")]
+ [Property("AUTHOR", "Hwankyu Jhun, h.jhun@samsung.com")]
+ public async Task Reply_SET_AND_GET()
+ {
+ Log.Info(LogTag, "START");
+ _thread = new Thread(() => SetTimer(new ElapsedEventHandler(CheckReceivedMessage)));
+ _thread.Start();
+
+ SendLaunchRequest("Reply_SET_AND_GET");
+ await Task.Delay(4000);
+
+ _timer.Stop();
+ _thread.Join();
+
+ Assert.AreEqual(_receivedCommand, "Reply_SET_AND_GET", "Recevied Command should be 'Reply_SET_AND_GET'");
+ Assert.AreEqual(_receivedResult, 0, "Recevied Result should be '0'");
+ Log.Info(LogTag, "END");
+ }
+ }
+}