From: DoHyun Pyun Date: Tue, 7 Apr 2020 05:48:59 +0000 (+0900) Subject: [IoTConnectivityClient][Non-ACR] Fix TCT block issues X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9f52d2ab61da6a91daabcf5b4c9a912ae8cc4d95;p=test%2Ftct%2Fcsharp%2Fapi.git [IoTConnectivityClient][Non-ACR] Fix TCT block issues 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 --- diff --git a/tct-suite-vs/Tizen.IoTConnectivityServer.Tests/testcase/TSLiteResource.cs b/tct-suite-vs/Tizen.IoTConnectivityServer.Tests/testcase/TSLiteResource.cs index 439d1cf5c..800cdb2db 100755 --- a/tct-suite-vs/Tizen.IoTConnectivityServer.Tests/testcase/TSLiteResource.cs +++ b/tct-suite-vs/Tizen.IoTConnectivityServer.Tests/testcase/TSLiteResource.cs @@ -206,27 +206,15 @@ namespace Tizen.IoTConnectivityServer.Tests 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"); diff --git a/tct-suite-vs/Tizen.IoTConnectivityServer.Tests/testcase/TSRequest.cs b/tct-suite-vs/Tizen.IoTConnectivityServer.Tests/testcase/TSRequest.cs index 514be2872..c1b5eb640 100755 --- a/tct-suite-vs/Tizen.IoTConnectivityServer.Tests/testcase/TSRequest.cs +++ b/tct-suite-vs/Tizen.IoTConnectivityServer.Tests/testcase/TSRequest.cs @@ -136,34 +136,16 @@ namespace Tizen.IoTConnectivityServer.Tests 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) @@ -185,38 +167,6 @@ namespace Tizen.IoTConnectivityServer.Tests 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")] @@ -233,14 +183,14 @@ namespace Tizen.IoTConnectivityServer.Tests * 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(RequestData.Host, "Host should be of type string"); Assert.False(String.IsNullOrEmpty(RequestData.Host), "host address can not be null or empty"); @@ -272,14 +222,14 @@ namespace Tizen.IoTConnectivityServer.Tests * 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(RequestData.Repr, "Property should be of type Representation"); Assert.True(RequestData.Repr != null, "Representation can not be null"); @@ -311,14 +261,14 @@ namespace Tizen.IoTConnectivityServer.Tests * 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(RequestData.Query, "Property should be of type ResourceQuery"); Assert.True(RequestData.Query != null, "Query can not be null"); @@ -352,14 +302,14 @@ namespace Tizen.IoTConnectivityServer.Tests * 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(RequestData.Options, "Property should be of type ResourceOptions"); Assert.True(RequestData.Options != null, "Options can not be null"); diff --git a/tct-suite-vs/Tizen.IoTConnectivityServer.Tests/testcase/TSResource.cs b/tct-suite-vs/Tizen.IoTConnectivityServer.Tests/testcase/TSResource.cs old mode 100755 new mode 100644 index d8680b263..d16642be9 --- a/tct-suite-vs/Tizen.IoTConnectivityServer.Tests/testcase/TSResource.cs +++ b/tct-suite-vs/Tizen.IoTConnectivityServer.Tests/testcase/TSResource.cs @@ -136,33 +136,15 @@ namespace Tizen.IoTConnectivityServer.Tests 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; @@ -461,38 +443,6 @@ namespace Tizen.IoTConnectivityServer.Tests } } - 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.")] @@ -509,14 +459,13 @@ namespace Tizen.IoTConnectivityServer.Tests * 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) @@ -545,14 +494,13 @@ namespace Tizen.IoTConnectivityServer.Tests * 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) @@ -581,14 +529,13 @@ namespace Tizen.IoTConnectivityServer.Tests * 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) @@ -617,14 +564,13 @@ namespace Tizen.IoTConnectivityServer.Tests * 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) @@ -653,14 +599,13 @@ namespace Tizen.IoTConnectivityServer.Tests * 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 */ diff --git a/tct-suite-vs/Tizen.IoTConnectivityServer.Tests/testcase/support/TestHelper.cs b/tct-suite-vs/Tizen.IoTConnectivityServer.Tests/testcase/support/TestHelper.cs new file mode 100644 index 000000000..d27c9fc56 --- /dev/null +++ b/tct-suite-vs/Tizen.IoTConnectivityServer.Tests/testcase/support/TestHelper.cs @@ -0,0 +1,62 @@ +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); + } + } +}