IoTClientApp does not reply for the launch request.
So some abnormal operations occur in TC senarios.
This patchset removes the callback for launch request,
and uses the common function to handle the client app.
Change-Id: I8bbea0443be510c5cffffd3dfce594fd650db9db
Signed-off-by: DoHyun Pyun <dh79.pyun@samsung.com>
IoTConnectivityServerManager.RegisterResource(lightResource);
Log.Info(LOGTAG, "LiteResourceTests OnPost launching Client");
- AppControlReplyCallback cb = (launchRequest, replyRequest, result) =>
- {
- if (result == AppControlReplyResult.Succeeded)
- {
- Log.Info(LOGTAG, "got reply from client app");
- _waitFlag = true;
- }
- };
- Log.Info(LOGTAG, "launhing client app in mode : init_lite_resource");
- AppControl appControl = new AppControl();
- appControl.ApplicationId = _clientAppId;
- appControl.ExtraData.Add("mode", "init_lite_resource");
- AppControl.SendLaunchRequest(appControl, cb);
- await waitFlag(10);
- /* TEST CODE */
+ await TestHelper.InitClientApp("init_lite_resource");
+
LightResourceFlags.OnPostReceivedFlag = false;
+
Log.Info(LOGTAG, "launhing client app in mode : post-lite");
- appControl.ExtraData.Add("mode", "post-lite");
- AppControl.SendLaunchRequest(appControl);
- await Task.Delay(5000);
+
+ /* TEST CODE */
+ await TestHelper.ExcuteClientApp("post-lite");
Assert.True(LightResourceFlags.OnPostReceivedFlag, "OnPost was not called");
public class RequestTests
{
internal const string LOGTAG = "IOT-TEST";
- private static bool _waitFlag;
private static bool _isRegistered = false;
private const string _attribute = "DOOR_ATTRIBUTE";
- private const string _clientAppId = "org.tizen.IoTClientApp";
- private static AppControl _appControl = null;
private static bool isSupported = false;
public static string datPath = "/opt/usr/home/owner/share/res/iotcon-test-svr-db-server.dat";
- public static async Task waitFlag(int seconds)
- {
- int count = 0;
- while(true) {
- Log.Info(LOGTAG, "Waiting.................................................." + count + "/" + seconds);
- await Task.Delay(1000);
- count++;
- if (_waitFlag)
- break;
- if (count == seconds)
- break;
- }
- }
-
[SetUp]
public static void Init()
{
Log.Info(LOGTAG, "RequestTests Init");
Information.TryGetValue("http://tizen.org/feature/iot.ocf", out isSupported);
- _waitFlag = false;
RequestData.OnGetReceivedFlag = false;
RequestData.OnPutReceivedFlag = false;
if (!_isRegistered && isSupported)
Log.Info(LOGTAG, "RequestTests Destroy");
}
- private static async Task LaunchClientApp()
- {
- if (!isSupported)
- throw new NotSupportedException("Not supported");
-
- AppControlReplyCallback cb = (launchRequest, replyRequest, result) =>
- {
- if (result == AppControlReplyResult.Succeeded)
- {
- Log.Info(LOGTAG, "got reply from client app");
- _waitFlag = true;
- }
- };
- Log.Info(LOGTAG, "launhing client app in mode : init_request");
- _appControl = new AppControl();
- _appControl.ApplicationId = _clientAppId;
- _appControl.ExtraData.Add("mode", "init_request");
- AppControl.SendLaunchRequest(_appControl, cb);
- await waitFlag(10);
- }
-
- private static async Task LaunchClientApp(string mode)
- {
- if (!isSupported)
- throw new NotSupportedException("Not supported");
-
- Log.Info(LOGTAG, "launhing client app in mode : " + mode);
- _appControl.ExtraData.Add("mode", mode);
- AppControl.SendLaunchRequest(_appControl);
- await Task.Delay(5000);
- }
-
[Test]
[Category("P1")]
[Description("Checks host address of the request")]
* 1. Connect the WiFI or 3g network.
* 2. Launch client app
*/
- if (_appControl == null)
- {
- await LaunchClientApp();
- Assert.IsTrue(_waitFlag == true, "ReplyCallback was not called");
- }
- await LaunchClientApp("get");
+ if (!isSupported)
+ throw new NotSupportedException("Not supported");
+
+ await TestHelper.InitClientApp("init_request");
/* TEST CODE */
+ await TestHelper.ExcuteClientApp("get");
+
Assert.True(RequestData.OnGetReceivedFlag, "OnGet was not called");
Assert.IsInstanceOf<string>(RequestData.Host, "Host should be of type string");
Assert.False(String.IsNullOrEmpty(RequestData.Host), "host address can not be null or empty");
* 1. Connect the WiFI or 3g network.
* 2. Launch client app
*/
- if (_appControl == null)
- {
- await LaunchClientApp();
- Assert.True(_waitFlag, "ReplyCallback was not called");
- }
- await LaunchClientApp("put");
+ if (!isSupported)
+ throw new NotSupportedException("Not supported");
+
+ await TestHelper.InitClientApp("init_request");
/* TEST CODE */
+ await TestHelper.ExcuteClientApp("put");
+
Assert.True(RequestData.OnPutReceivedFlag, "OnPut was not called");
Assert.IsInstanceOf<Representation>(RequestData.Repr, "Property should be of type Representation");
Assert.True(RequestData.Repr != null, "Representation can not be null");
* 1. Connect the WiFI or 3g network.
* 2. Launch client app
*/
- if (_appControl == null)
- {
- await LaunchClientApp();
- Assert.True(_waitFlag, "ReplyCallback was not called");
- }
- await LaunchClientApp("get");
+ if (!isSupported)
+ throw new NotSupportedException("Not supported");
+
+ await TestHelper.InitClientApp("init_request");
/* TEST CODE */
+ await TestHelper.ExcuteClientApp("get");
+
Assert.True(RequestData.OnGetReceivedFlag, "OnGet was not called");
Assert.IsInstanceOf<ResourceQuery>(RequestData.Query, "Property should be of type ResourceQuery");
Assert.True(RequestData.Query != null, "Query can not be null");
* 1. Connect the WiFI or 3g network.
* 2. Launch client app
*/
- if (_appControl == null)
- {
- await LaunchClientApp();
- Assert.True(_waitFlag, "ReplyCallback was not called");
- }
- await LaunchClientApp("put");
+ if (!isSupported)
+ throw new NotSupportedException("Not supported");
+
+ await TestHelper.InitClientApp("init_request");
/* TEST CODE */
+ await TestHelper.ExcuteClientApp("put");
+
Assert.True(RequestData.OnPutReceivedFlag, "OnPut was not called");
Assert.IsInstanceOf<ResourceOptions>(RequestData.Options, "Property should be of type ResourceOptions");
Assert.True(RequestData.Options != null, "Options can not be null");
internal const string LOGTAG = "IOT-TEST";
public static string datPath = "/opt/usr/home/owner/share/res/iotcon-test-svr-db-server.dat";
- private static bool _waitFlag;
private static bool _isRegistered = false;
private const string _attribute = "DOOR_ATTRIBUTE";
- private const string _clientAppId = "org.tizen.IoTClientApp";
- private static AppControl _appControl = null;
private static bool isSupported = false;
- public static async Task waitFlag(int seconds)
- {
- int count = 0;
- while(true) {
- Log.Info(LOGTAG, "Waiting.................................................." + count + "/" + seconds);
- await Task.Delay(1000);
- count++;
- if (_waitFlag)
- break;
- if (count == seconds)
- break;
- }
- }
-
[SetUp]
public static void Init()
{
Log.Info(LOGTAG, "ResourceTests Init");
Information.TryGetValue("http://tizen.org/feature/iot.ocf", out isSupported);
- _waitFlag = false;
Flags.OnGetReceivedFlag = false;
Flags.OnPostReceivedFlag = false;
Flags.OnPutReceivedFlag = false;
}
}
- private static async Task LaunchClientApp()
- {
- if (!isSupported)
- throw new NotSupportedException("Not supported");
-
- AppControlReplyCallback cb = (launchRequest, replyRequest, result) =>
- {
- if (result == AppControlReplyResult.Succeeded)
- {
- Log.Info(LOGTAG, "got reply from client app");
- _waitFlag = true;
- }
- };
- Log.Info(LOGTAG, "launching client app in mode : init_resource");
- _appControl = new AppControl();
- _appControl.ApplicationId = _clientAppId;
- _appControl.ExtraData.Add("mode", "init_resource");
- AppControl.SendLaunchRequest(_appControl, cb);
- await waitFlag(10);
- }
-
- private static async Task LaunchClientApp(string mode)
- {
- if (!isSupported)
- throw new NotSupportedException("Not supported");
-
- Log.Info(LOGTAG, "launching client app in mode : " + mode);
- _appControl.ExtraData.Add("mode", mode);
- AppControl.SendLaunchRequest(_appControl);
- await Task.Delay(5000);
- }
-
[Test]
[Category("P1")]
[Description("Checks if OnGet is called when a client invokes GetAsync.")]
* 1. Connect the WiFI or 3g network.
* 2. Launch client app
*/
- if (_appControl == null)
- {
- await LaunchClientApp();
- Assert.IsTrue(_waitFlag == true, "ReplyCallback was not called");
- }
+ if (!isSupported)
+ throw new NotSupportedException("Not supported");
+
+ await TestHelper.InitClientApp("init_resource");
/* TEST CODE */
- await LaunchClientApp("get");
+ await TestHelper.ExcuteClientApp("get");
Assert.True(Flags.OnGetReceivedFlag, "OnGet was not called");
}
catch (NotSupportedException)
* 1. Connect the WiFI or 3g network.
* 2. Launch client app
*/
- if (_appControl == null)
- {
- await LaunchClientApp();
- Assert.IsTrue(_waitFlag == true, "ReplyCallback was not called");
- }
+ if (!isSupported)
+ throw new NotSupportedException("Not supported");
+
+ await TestHelper.InitClientApp("init_resource");
/* TEST CODE */
- await LaunchClientApp("observe");
+ await TestHelper.ExcuteClientApp("observe");
Assert.True(Flags.OnObservingReceivedFlag, "OnObserving was not called");
}
catch (NotSupportedException)
* 1. Connect the WiFI or 3g network.
* 2. Launch client app
*/
- if (_appControl == null)
- {
- await LaunchClientApp();
- Assert.IsTrue(_waitFlag == true, "ReplyCallback was not called");
- }
+ if (!isSupported)
+ throw new NotSupportedException("Not supported");
+
+ await TestHelper.InitClientApp("init_resource");
/* TEST CODE */
- await LaunchClientApp("post");
+ await TestHelper.ExcuteClientApp("post");
Assert.True(Flags.OnPostReceivedFlag, "OnPost was not called");
}
catch (NotSupportedException)
* 1. Connect the WiFI or 3g network.
* 2. Launch client app
*/
- if (_appControl == null)
- {
- await LaunchClientApp();
- Assert.IsTrue(_waitFlag == true, "ReplyCallback was not called");
- }
+ if (!isSupported)
+ throw new NotSupportedException("Not supported");
+
+ await TestHelper.InitClientApp("init_resource");
/* TEST CODE */
- await LaunchClientApp("put");
+ await TestHelper.ExcuteClientApp("put");
Assert.True(Flags.OnPutReceivedFlag, "OnPut was not called");
}
catch (NotSupportedException)
* 1. Connect the WiFI or 3g network.
* 2. Launch client app
*/
- if (_appControl == null)
- {
- await LaunchClientApp();
- Assert.IsTrue(_waitFlag == true, "ReplyCallback was not called");
- }
+ if (!isSupported)
+ throw new NotSupportedException("Not supported");
+
+ await TestHelper.InitClientApp("init_resource");
/* TEST CODE */
- await LaunchClientApp("delete");
+ await TestHelper.ExcuteClientApp("delete");
Assert.True(Flags.OnDeleteReceivedFlag, "OnDelete was not called");
/* POST CONDITION */
--- /dev/null
+using System;
+using System.Collections.ObjectModel;
+using System.Linq;
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using NUnit.Framework;
+using Tizen.Applications;
+using Tizen.Network.IoTConnectivity;
+using Tizen.System;
+
+namespace Tizen.IoTConnectivityServer.Tests
+{
+ public static class TestHelper
+ {
+ private const string LOGTAG = "IOT-TEST";
+ private const string _clientAppId = "org.tizen.IoTClientApp";
+ private static AppControl _appControl = null;
+ public static string _launchMode = "init_resource";
+
+ internal static async Task InitClientApp(string mode)
+ {
+ Log.Info(LOGTAG, ">>>>>>>> called : " + mode);
+
+ if (_appControl != null && _launchMode.Equals(mode)) {
+ Log.Info(LOGTAG, "Client App already exist : " + mode);
+ return;
+ }
+
+ Log.Info(LOGTAG, "launching client app in mode : " + mode);
+
+ _launchMode = mode;
+
+ if (_appControl == null) {
+ _appControl = new AppControl();
+ _appControl.ApplicationId = _clientAppId;
+ }
+
+ _appControl.ExtraData.Add("mode", mode);
+ AppControl.SendLaunchRequest(_appControl);
+ await Task.Delay(5000);
+
+ Log.Info(LOGTAG, "<<<<<<<< ended : " + mode);
+ }
+
+ internal static async Task ExcuteClientApp(string mode)
+ {
+ Log.Info(LOGTAG, ">>>>>>>> called : " + mode);
+
+ if (_appControl == null) {
+ Log.Info(LOGTAG, "Client App is not ready");
+ return;
+ }
+
+ _appControl.ExtraData.Add("mode", mode);
+
+ AppControl.SendLaunchRequest(_appControl);
+ await Task.Delay(3000);
+
+ Log.Info(LOGTAG, "<<<<<<<< ended : " + mode);
+ }
+ }
+}