From: DoHyun Pyun Date: Thu, 24 Jan 2019 09:15:22 +0000 (+0900) Subject: [Non-ACR][Bluetooth][Manual][Enable Bluetooth GATT Client TCs] X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F86%2F198386%2F5;p=test%2Ftct%2Fcsharp%2Fapi.git [Non-ACR][Bluetooth][Manual][Enable Bluetooth GATT Client TCs] Change-Id: I4c33b4d09875b65a8fc5a9510bb184340fe6910a Signed-off-by: DoHyun Pyun --- diff --git a/tct-suite-vs/Tizen.Bluetooth.Manual.Tests/testcase/BluetoothSetup.cs b/tct-suite-vs/Tizen.Bluetooth.Manual.Tests/testcase/BluetoothSetup.cs index 2e6298b07..1a0bbb3db 100644 --- a/tct-suite-vs/Tizen.Bluetooth.Manual.Tests/testcase/BluetoothSetup.cs +++ b/tct-suite-vs/Tizen.Bluetooth.Manual.Tests/testcase/BluetoothSetup.cs @@ -93,6 +93,7 @@ namespace BluetoothNetworkUtils public static BluetoothLeDevice leDevice = null; public static BluetoothGattClient client = null; public static bool StateChanged_flag = false; + public static bool GattClientConnected = false; public static void CreateServerSocketUtil() { @@ -621,7 +622,7 @@ namespace BluetoothNetworkUtils public static void scanResultEventHandler(object sender, AdapterLeScanResultChangedEventArgs e) { - if (!e.DeviceData.Equals(null)) + if (e.DeviceData != null) { if (remote_addr.Equals(default_remote_addr)) { @@ -648,10 +649,10 @@ namespace BluetoothNetworkUtils public static void scanDeviceResultEventHandler(object sender, AdapterLeScanResultChangedEventArgs e) { - if (!e.DeviceData.Equals(null)) + if (e.DeviceData != null) { BtLeScanDevice = e.DeviceData; - scanFlag = true; + scanFlag = true; } } @@ -832,17 +833,53 @@ namespace BluetoothNetworkUtils role = ""; } + public static void gatt_client_destroy() + { + if (client != null) + { + client.DestroyClient(); + client = null; + } + } + /* GATT Client */ public static void LeDevice_GattConnectionStateChanged(object sender, GattConnectionStateChangedEventArgs e) { - if (e.Result != (int)BluetoothError.None) - StateChanged_flag = false; - else if (!e.RemoteAddress.Equals(remote_addr)) - StateChanged_flag = false; - else if (e.IsConnected.Equals(false)) - StateChanged_flag = false; - else + if (e.Result == (int)BluetoothError.None) + { + if (!e.RemoteAddress.Equals(remote_addr)) + { + Log.Info(Globals.LogTag, "Not equal with BLE address, ignore it"); + return; + } + + GattClientConnected = e.IsConnected; StateChanged_flag = true; + + if (e.IsConnected.Equals(false)) + { + Log.Info(Globals.LogTag, "Client is disconnected"); + gatt_client_destroy(); + return; + } + + Log.Info(Globals.LogTag, "Client is connected"); + + return; + } + + StateChanged_flag = true; + + if (e.Result == (int)BluetoothError.AlreadyDone) + { + Log.Info(Globals.LogTag, "AlreadyDone"); + GattClientConnected = true; + return; + } + + Log.Info(Globals.LogTag, "Error: " + (BluetoothError)e.Result); + gatt_client_destroy(); + GattClientConnected = false; } public static async Task WaitStateChangedFlag() @@ -860,33 +897,64 @@ namespace BluetoothNetworkUtils } } - public static async Task gatt_client_init() + public static async Task gatt_client_init() { - role = "client"; - Assert.IsTrue(BluetoothAdapter.IsBluetoothEnabled, "PRECONDITION Failed: Bluetooth services should have beeen initialised"); + if (client != null && GattClientConnected == true) + return client; + + if (leDevice == null) + { + leDevice = await LeScanSetup(); + Assert.IsNotNull(leDevice, "Le device instance should not be null"); + leDevice.GattConnectionStateChanged += LeDevice_GattConnectionStateChanged; + } + + StateChanged_flag = false; - leDevice = await LeScanSetup(); - Assert.IsNotNull(leDevice, "Le device instance should not be null"); - leDevice.GattConnectionStateChanged += LeDevice_GattConnectionStateChanged; + try + { + client = leDevice.GattConnect(true); + await WaitStateChangedFlag(); + + StateChanged_flag = false; + } catch(Exception e) { + Log.Info(Globals.LogTag, "Exception in connect GATT" + e.Message); + + if (e.Message.Equals("Operation already done")) + GattClientConnected = true; + else + gatt_client_destroy(); + } - client = leDevice.GattConnect(false); - await WaitStateChangedFlag(); - Assert.IsNotNull(client, "Client instance should not be null"); - Assert.IsTrue(StateChanged_flag, "Either GattConnectionStateChanged callback is not invoked or GattConnection failed"); + return client; } - public static void gatt_client_exit() + public static async Task gatt_client_exit() { - if (!leDevice.Equals(null)) + StateChanged_flag = false; + GattClientConnected = false; + + try { - leDevice.GattConnectionStateChanged -= LeDevice_GattConnectionStateChanged; - leDevice.GattDisconnect(); - leDevice = null; - client.DestroyClient(); - client = null; + if (client != null) + { + client.DestroyClient(); + client = null; + } + + if (leDevice != null) + { + leDevice.GattDisconnect(); + await WaitStateChangedFlag(); + leDevice.GattConnectionStateChanged -= LeDevice_GattConnectionStateChanged; + leDevice = null; + } + + return true; + } catch(Exception e) { + Log.Info(Globals.LogTag, "Exception in destroying the gatt client" + e.Message); + return false; } - StateChanged_flag = false; - role = ""; } public static BluetoothOppClient GetBluetoothOppClientUtil() diff --git a/tct-suite-vs/Tizen.Bluetooth.Manual.Tests/testcase/TSBluetoothGattCharacteristic.cs b/tct-suite-vs/Tizen.Bluetooth.Manual.Tests/testcase/TSBluetoothGattCharacteristic.cs old mode 100755 new mode 100644 index 88c7c1913..05d208d63 --- a/tct-suite-vs/Tizen.Bluetooth.Manual.Tests/testcase/TSBluetoothGattCharacteristic.cs +++ b/tct-suite-vs/Tizen.Bluetooth.Manual.Tests/testcase/TSBluetoothGattCharacteristic.cs @@ -16,6 +16,9 @@ namespace Tizen.Network.Bluetooth.Tests { static bool isBluetoothGattServerSupported = false; static bool isBluetoothGattClientSupported = false; + static BluetoothGattClient client = null; + static string svcUuid = "181D"; + static string charUuid = "2A20"; [SetUp] public static void Init() @@ -34,11 +37,6 @@ namespace Tizen.Network.Bluetooth.Tests { BluetoothSetup.gatt_server_exit(); } - - if (BluetoothSetup.role.Equals("client")) - { - BluetoothSetup.gatt_client_exit(); - } } private static void Charc_NotificationStateChanged(object sender, NotificationStateChangedEventArg e) @@ -46,7 +44,7 @@ namespace Tizen.Network.Bluetooth.Tests ManualTest.Confirm(); } - //[Test] + [Test] [Category("P1")] [Description("Check whether NotificationStateChanged callback is getting invoked or not")] [Property("SPEC", "Tizen.Network.Bluetooth.BluetoothGattCharacteristic.NotificationStateChanged E")] @@ -79,7 +77,7 @@ namespace Tizen.Network.Bluetooth.Tests catch (TypeInitializationException e) { if (isBluetoothGattServerSupported == false && e.InnerException.GetType() == typeof(NotSupportedException)) - { + { BluetoothHelper.DisplayLabel("NotificationStateChanged_CHECK_EVENT"); await ManualTest.WaitForConfirm(); } @@ -90,12 +88,7 @@ namespace Tizen.Network.Bluetooth.Tests } } - private static void Charc_ValueChanged(object sender, ValueChangedEventArgs e) - { - ManualTest.Confirm(); - } - - //[Test] + [Test] [Category("P1")] [Description("Check whether ValueChanged callback is getting invoked or not")] [Property("SPEC", "Tizen.Network.Bluetooth.BluetoothGattCharacteristic.ValueChanged E")] @@ -105,24 +98,40 @@ namespace Tizen.Network.Bluetooth.Tests [Precondition(1, "Bluetooth should be turned on.")] [Precondition(2, "Run BluetoothGattServerTests.SendIndicationAsync_RETURN_VALUE test case on the server device.")] [Step(1, "Tap the Run button.")] - [Step(2, "TC should pass automatically.")] [Postcondition(1, "If TC fails, turn off and turn on Bluetooth on both the devices. Try again.")] public static async Task ValueChanged_CHECK_EVENT() { try { - await BluetoothSetup.gatt_client_init(); + /* We can't occupy the precondition, if GATT Client feature is not supported in Manual TC */ + if (isBluetoothGattClientSupported == false) + { + BluetoothHelper.DisplayLabel("ValueChanged_CHECK_EVENT"); + await ManualTest.WaitForConfirm(); + return; + } + + client = await BluetoothSetup.gatt_client_init(); + Assert.IsNotNull(client, "Precondition failed: client instance should not be null"); + + BluetoothGattService srv = BluetoothSetup.client.GetService(svcUuid); + BluetoothGattCharacteristic charc = srv.GetCharacteristic(charUuid); - BluetoothGattService srv = BluetoothSetup.client.GetService(BluetoothSetup.serviceUuid); - Assert.IsNotNull(srv, "srv should not be null"); + EventHandler Charc_ValueChanged = null; - BluetoothGattCharacteristic charc = srv.GetCharacteristic(BluetoothSetup.characteristicUuid); - Assert.IsNotNull(charc, "charc should not be null"); + Charc_ValueChanged = (sender, e) => { + Assert.IsNotNull(e.Value, "[TestCase][ValueChanged_CHECK_EVENT] Failed"); + Assert.IsInstanceOf(e.Value, "[TestCase][ValueChanged_CHECK_EVENT] Failed"); + + BluetoothHelper.DisplayPassLabel("ValueChanged_CHECK_EVENT"); + }; charc.ValueChanged += Charc_ValueChanged; + await ManualTest.WaitForConfirm(); + charc.ValueChanged -= Charc_ValueChanged; - } + } catch (NotSupportedException) { if (isBluetoothGattClientSupported == false) @@ -134,7 +143,7 @@ namespace Tizen.Network.Bluetooth.Tests catch (TypeInitializationException e) { if (isBluetoothGattClientSupported == false && e.InnerException.GetType() == typeof(NotSupportedException)) - { + { BluetoothHelper.DisplayLabel("ValueChanged_CHECK_EVENT"); await ManualTest.WaitForConfirm(); } @@ -143,6 +152,11 @@ namespace Tizen.Network.Bluetooth.Tests { Assert.True(false, "Exception occurs. Msg : " + ex.ToString()); } + finally + { + if (client != null) + await BluetoothSetup.gatt_client_exit(); + } } } } diff --git a/tct-suite-vs/Tizen.Bluetooth.Manual.Tests/testcase/TSBluetoothGattClient.cs b/tct-suite-vs/Tizen.Bluetooth.Manual.Tests/testcase/TSBluetoothGattClient.cs old mode 100755 new mode 100644 index a09fc5c6f..18c484439 --- a/tct-suite-vs/Tizen.Bluetooth.Manual.Tests/testcase/TSBluetoothGattClient.cs +++ b/tct-suite-vs/Tizen.Bluetooth.Manual.Tests/testcase/TSBluetoothGattClient.cs @@ -14,25 +14,29 @@ namespace Tizen.Network.Bluetooth.Tests [Description("BluetoothGattClient Tests")] public class BluetoothGattClientTests { - static string charc_value = "1234"; - static string desc_value = "1"; - static bool isBluetoothGattClientSupported = false; + string svcUuid = "181D"; + string charUuid = "2A20"; + string descUuid = "2901"; + string charc_value = "1234"; + string desc_value = "1"; + bool isBluetoothGattClientSupported = false; + BluetoothLeDevice leDevice = null; + BluetoothGattClient client = null; [SetUp] - public static void Init() + public void Init() { LogUtils.Write(LogUtils.DEBUG, LogUtils.INFO, "Preconditions for each TEST"); Information.TryGetValue("http://tizen.org/feature/network.bluetooth.le.gatt.client", out isBluetoothGattClientSupported); } [TearDown] - public static void Destroy() + public void Destroy() { LogUtils.Write(LogUtils.DEBUG, LogUtils.INFO, "Postconditions for each TEST"); - BluetoothSetup.gatt_client_exit(); } - //[Test] + [Test] [Category("P1")] [Description("Test RemoteAddress property of BluetoothGattClient")] [Property("SPEC", "Tizen.Network.Bluetooth.BluetoothGattClient.RemoteAddress A")] @@ -42,17 +46,25 @@ namespace Tizen.Network.Bluetooth.Tests [Precondition(1, "Bluetooth should be turned on.")] [Precondition(2, "Run BluetoothGattAttributeTests.ReadRequested_Characteristics_CHECK_EVENT test case on the server device.")] [Step(1, "Tap the Run button.")] - [Step(2, "TC should pass automatically.")] [Postcondition(1, "If TC fails, turn off and turn on Bluetooth on both the devices. Try again.")] - public static async Task RemoteAddress_PROPERTY_READ_ONLY() + public async Task RemoteAddress_PROPERTY_READ_ONLY() { try { - await BluetoothSetup.gatt_client_init(); - string address = BluetoothSetup.client.RemoteAddress; - Assert.IsNotNull(address, "RemoteAddress shold not be null"); - Assert.AreEqual(BluetoothSetup.remote_addr, address); - } + /* We can't occupy the precondition, if GATT Client feature is not supported in Manual TC */ + if (isBluetoothGattClientSupported == false) + { + BluetoothHelper.DisplayLabel("RemoteAddress_PROPERTY_READ_ONLY"); + await ManualTest.WaitForConfirm(); + return; + } + + client = await BluetoothSetup.gatt_client_init(); + Assert.IsNotNull(client, "Precondition failed: client instance should not be null"); + + Assert.IsNotNull(client.RemoteAddress, "RemoteAddress shold not be null"); + Assert.AreEqual(client.RemoteAddress, PreconditionUtils.GetBleAddress()); + } catch (NotSupportedException) { if (isBluetoothGattClientSupported == false) @@ -75,7 +87,7 @@ namespace Tizen.Network.Bluetooth.Tests } } - //[Test] + [Test] [Category("P1")] [Description("Test GetService method of BluetoothGattClient")] [Property("SPEC", "Tizen.Network.Bluetooth.BluetoothGattClient.GetService M")] @@ -85,19 +97,26 @@ namespace Tizen.Network.Bluetooth.Tests [Precondition(1, "Bluetooth should be turned on.")] [Precondition(2, "Run BluetoothGattAttributeTests.ReadRequested_Characteristics_CHECK_EVENT test case on the server device.")] [Step(1, "Tap the Run button.")] - [Step(2, "TC should pass automatically.")] [Postcondition(1, "If TC fails, turn off and turn on Bluetooth on both the devices. Try again.")] - public static async Task GetService_RETURN_VALUE() + public async Task GetService_RETURN_VALUE() { try { - await BluetoothSetup.gatt_client_init(); + /* We can't occupy the precondition, if GATT Client feature is not supported in Manual TC */ + if (isBluetoothGattClientSupported == false) + { + BluetoothHelper.DisplayLabel("RemoteAddress_PROPERTY_READ_ONLY"); + await ManualTest.WaitForConfirm(); + return; + } - string CUSTOM_UUID = "181D"; - BluetoothGattService srv = BluetoothSetup.client.GetService(CUSTOM_UUID); + client = await BluetoothSetup.gatt_client_init(); + Assert.IsNotNull(client, "Precondition failed: client instance should not be null"); + + BluetoothGattService srv = client.GetService(svcUuid); Assert.IsNotNull(srv, "Service returned should not be null"); - Assert.AreEqual(srv.Uuid, CUSTOM_UUID, "Fetched Service UUID is not matching"); - } + Assert.AreEqual(srv.Uuid, svcUuid, "Fetched Service UUID is not matching"); + } catch (NotSupportedException) { if (isBluetoothGattClientSupported == false) @@ -120,7 +139,7 @@ namespace Tizen.Network.Bluetooth.Tests } } - //[Test] + [Test] [Category("P1")] [Description("Test GetServices method of BluetoothGattClient")] [Property("SPEC", "Tizen.Network.Bluetooth.BluetoothGattClient.GetServices M")] @@ -130,18 +149,26 @@ namespace Tizen.Network.Bluetooth.Tests [Precondition(1, "Bluetooth should be turned on.")] [Precondition(2, "Run BluetoothGattAttributeTests.ReadRequested_Characteristics_CHECK_EVENT test case on the server device.")] [Step(1, "Tap the Run button.")] - [Step(2, "TC should pass automatically.")] [Postcondition(1, "If TC fails, turn off and turn on Bluetooth on both the devices. Try again.")] - public static async Task GetServices_RETURN_VALUE() + public async Task GetServices_RETURN_VALUE() { try { - await BluetoothSetup.gatt_client_init(); + /* We can't occupy the precondition, if GATT Client feature is not supported in Manual TC */ + if (isBluetoothGattClientSupported == false) + { + BluetoothHelper.DisplayLabel("RemoteAddress_PROPERTY_READ_ONLY"); + await ManualTest.WaitForConfirm(); + return; + } + + client = await BluetoothSetup.gatt_client_init(); + Assert.IsNotNull(client, "Precondition failed: client instance should not be null"); IEnumerable srv_list; - srv_list = BluetoothSetup.client.GetServices(); + srv_list = client.GetServices(); Assert.IsNotNull(srv_list, "Service list should not be null"); - } + } catch (NotSupportedException) { if (isBluetoothGattClientSupported == false) @@ -164,7 +191,7 @@ namespace Tizen.Network.Bluetooth.Tests } } - //[Test] + [Test] [Category("P1")] [Description("Test ReadValueAsync for BluetoothGattCharacteristic")] [Property("SPEC", "Tizen.Network.Bluetooth.BluetoothGattClient.ReadValueAsync M")] @@ -175,74 +202,33 @@ namespace Tizen.Network.Bluetooth.Tests [Precondition(1, "Bluetooth should be turned on.")] [Precondition(2, "Run BluetoothGattAttributeTests.ReadRequested_Characteristics_CHECK_EVENT test case on the server device.")] [Step(1, "Tap the Run button.")] - [Step(2, "TC should pass automatically.")] [Postcondition(1, "If TC fails, turn off and turn on Bluetooth on both the devices. Try again.")] - public static async Task ReadValueAsync_Characteristic_RETURN_VALUE() + public async Task ReadValueAsync_Characteristic_RETURN_VALUE() { try { - await BluetoothSetup.gatt_client_init(); - - BluetoothGattService srv = BluetoothSetup.client.GetService(BluetoothSetup.serviceUuid); - Assert.IsNotNull(srv, "srv should not be null"); - - BluetoothGattCharacteristic charc = srv.GetCharacteristic(BluetoothSetup.characteristicUuid); - Assert.IsNotNull(charc, "charc should not be null"); - - bool status = await BluetoothSetup.client.ReadValueAsync(charc); - Assert.IsTrue(status, "ReadValueAsync Status should be true"); - } - catch (NotSupportedException) - { + /* We can't occupy the precondition, if GATT Client feature is not supported in Manual TC */ if (isBluetoothGattClientSupported == false) { - BluetoothHelper.DisplayLabel("ReadValueAsync_Characteristic_RETURN_VALUE"); - await ManualTest.WaitForConfirm(); - } - } - catch (TypeInitializationException e) - { - if (isBluetoothGattClientSupported == false && e.InnerException.GetType() == typeof(NotSupportedException)) - { - BluetoothHelper.DisplayLabel("ReadValueAsync_Characteristic_RETURN_VALUE"); + BluetoothHelper.DisplayLabel("RemoteAddress_PROPERTY_READ_ONLY"); await ManualTest.WaitForConfirm(); + return; } - } - catch (Exception ex) - { - Assert.True(false, "Exception occurs. Msg : " + ex.ToString()); - } - } - //[Test] - [Category("P1")] - [Description("Test if ReadValueAsync throws InvalidOperationException")] - [Property("SPEC", "Tizen.Network.Bluetooth.BluetoothGattClient.ReadValueAsync M")] - [Property("SPEC_URL", "-")] - [Property("CRITERIA", "MEX")] - [Property("AUTHOR", "Gowtham Anandha Babu, gowtham.ab@samsung.com")] - [Property("COVPARAM", "BluetoothGattCharacteristic")] - [Precondition(1, "Bluetooth should be turned on.")] - [Precondition(2, "Run BluetoothGattAttributeTests.ReadRequested_Characteristics_CHECK_EVENT test case on the server device.")] - [Step(1, "Tap the Run button.")] - [Step(2, "TC should pass automatically.")] - [Postcondition(1, "If TC fails, turn off and turn on Bluetooth on both the devices. Try again.")] - public static async Task ReadValueAsync_CHECK_EXCEPTION() - { - try - { - await BluetoothSetup.gatt_client_init(); + client = await BluetoothSetup.gatt_client_init(); + Assert.IsNotNull(client, "Precondition failed: client instance should not be null"); - BluetoothGattCharacteristic charc_local = new BluetoothGattCharacteristic(BluetoothSetup.characteristicUuid, - BluetoothSetup.characteristicPermission, BluetoothSetup.characteristicProperties, BluetoothSetup.characteristicValue); + BluetoothGattService srv = client.GetService(svcUuid); + BluetoothGattCharacteristic charc = srv.GetCharacteristic(charUuid); - bool status = await BluetoothSetup.client.ReadValueAsync(charc_local); + bool status = await client.ReadValueAsync(charc); + Assert.IsTrue(status, "ReadValueAsync Status should be true"); } catch (NotSupportedException) { if (isBluetoothGattClientSupported == false) { - BluetoothHelper.DisplayLabel("ReadValueAsync_CHECK_EXCEPTION"); + BluetoothHelper.DisplayLabel("ReadValueAsync_Characteristic_RETURN_VALUE"); await ManualTest.WaitForConfirm(); } } @@ -250,7 +236,7 @@ namespace Tizen.Network.Bluetooth.Tests { if (isBluetoothGattClientSupported == false && e.InnerException.GetType() == typeof(NotSupportedException)) { - BluetoothHelper.DisplayLabel("ReadValueAsync_CHECK_EXCEPTION"); + BluetoothHelper.DisplayLabel("ReadValueAsync_Characteristic_RETURN_VALUE"); await ManualTest.WaitForConfirm(); } } @@ -260,7 +246,7 @@ namespace Tizen.Network.Bluetooth.Tests } } - //[Test] + [Test] [Category("P1")] [Description("Test ReadValueAsync method for BluetoothGattDescriptor")] [Property("SPEC", "Tizen.Network.Bluetooth.BluetoothGattClient.ReadValueAsync M")] @@ -271,26 +257,29 @@ namespace Tizen.Network.Bluetooth.Tests [Precondition(1, "Bluetooth should be turned on.")] [Precondition(2, "Run BluetoothGattAttributeTests.ReadRequested_Descriptor_CHECK_EVENT test case on the server device.")] [Step(1, "Tap the Run button.")] - [Step(2, "TC should pass automatically.")] [Postcondition(1, "If TC fails, turn off and turn on Bluetooth on both the devices. Try again.")] - public static async Task ReadValueAsync_Descriptor_RETURN_VALUE() + public async Task ReadValueAsync_Descriptor_RETURN_VALUE() { try { - await BluetoothSetup.gatt_client_init(); - - BluetoothGattService srv = BluetoothSetup.client.GetService(BluetoothSetup.serviceUuid); - Assert.IsNotNull(srv, "srv should not be null"); + /* We can't occupy the precondition, if GATT Client feature is not supported in Manual TC */ + if (isBluetoothGattClientSupported == false) + { + BluetoothHelper.DisplayLabel("RemoteAddress_PROPERTY_READ_ONLY"); + await ManualTest.WaitForConfirm(); + return; + } - BluetoothGattCharacteristic charc = srv.GetCharacteristic(BluetoothSetup.characteristicUuid); - Assert.IsNotNull(charc, "charc should not be null"); + client = await BluetoothSetup.gatt_client_init(); + Assert.IsNotNull(client, "Precondition failed: client instance should not be null"); - BluetoothGattDescriptor desc = charc.GetDescriptor(BluetoothSetup.descriptorUuid); - Assert.IsNotNull(desc, "desc should not be null"); + BluetoothGattService srv = client.GetService(svcUuid); + BluetoothGattCharacteristic charc = srv.GetCharacteristic(charUuid); + BluetoothGattDescriptor desc = charc.GetDescriptor(descUuid); - bool status = await BluetoothSetup.client.ReadValueAsync(desc); + bool status = await client.ReadValueAsync(desc); Assert.IsTrue(status, "ReadValueAsync Status should be true"); - } + } catch (NotSupportedException) { if (isBluetoothGattClientSupported == false) @@ -313,7 +302,7 @@ namespace Tizen.Network.Bluetooth.Tests } } - //[Test] + [Test] [Category("P1")] [Description("Test WriteValueAsync method for BluetoothGattCharacteristic")] [Property("SPEC", "Tizen.Network.Bluetooth.BluetoothGattClient.WriteValueAsync M")] @@ -326,26 +315,31 @@ namespace Tizen.Network.Bluetooth.Tests [Step(1, "Tap the Run button.")] [Step(2, "TC should pass automatically.")] [Postcondition(1, "If TC fails, turn off and turn on Bluetooth on both the devices. Try again.")] - public static async Task WriteValueAsync_Characteristic_RETURN_VALUE() + public async Task WriteValueAsync_Characteristic_RETURN_VALUE() { try { - await BluetoothSetup.gatt_client_init(); - - BluetoothGattService srv = BluetoothSetup.client.GetService(BluetoothSetup.serviceUuid); - Assert.IsNotNull(srv, "srv should not be null"); + /* We can't occupy the precondition, if GATT Client feature is not supported in Manual TC */ + if (isBluetoothGattClientSupported == false) + { + BluetoothHelper.DisplayLabel("RemoteAddress_PROPERTY_READ_ONLY"); + await ManualTest.WaitForConfirm(); + return; + } - BluetoothGattCharacteristic charc = srv.GetCharacteristic(BluetoothSetup.characteristicUuid); - Assert.IsNotNull(charc, "charc should not be null"); + client = await BluetoothSetup.gatt_client_init(); + Assert.IsNotNull(client, "Precondition failed: client instance should not be null"); + BluetoothGattService srv = BluetoothSetup.client.GetService(svcUuid); + BluetoothGattCharacteristic charc = srv.GetCharacteristic(charUuid); charc.SetValue(charc_value); - bool status = await BluetoothSetup.client.WriteValueAsync(charc); + bool status = await client.WriteValueAsync(charc); Assert.IsTrue(status, "WriteValueAsync Status should be true"); string value = charc.GetValue(0); Assert.AreEqual(charc_value, value); - } + } catch (NotSupportedException) { if (isBluetoothGattClientSupported == false) @@ -368,53 +362,7 @@ namespace Tizen.Network.Bluetooth.Tests } } - //[Test] - [Category("P1")] - [Description("Test if WriteValueAsync throws InvalidOperationException")] - [Property("SPEC", "Tizen.Network.Bluetooth.BluetoothGattClient.WriteValueAsync M")] - [Property("SPEC_URL", "-")] - [Property("CRITERIA", "MEX")] - [Property("AUTHOR", "Gowtham Anandha Babu, gowtham.ab@samsung.com")] - [Property("COVPARAM", "BluetoothGattCharacteristic")] - [Precondition(1, "Bluetooth should be turned on.")] - [Precondition(2, "Run BluetoothGattAttributeTests.WriteRequested_Characteristics_CHECK_EVENT test case on the server device.")] - [Step(1, "Tap the Run button.")] - [Step(2, "TC should pass automatically.")] - [Postcondition(1, "If TC fails, turn off and turn on Bluetooth on both the devices. Try again.")] - public static async Task WriteValueAsync_CHECK_EXCEPTION() - { - try - { - await BluetoothSetup.gatt_client_init(); - - BluetoothGattCharacteristic charc_local = new BluetoothGattCharacteristic(BluetoothSetup.characteristicUuid, - BluetoothSetup.characteristicPermission, BluetoothSetup.characteristicProperties, BluetoothSetup.characteristicValue); - - bool status = await BluetoothSetup.client.WriteValueAsync(charc_local); - } - catch (NotSupportedException) - { - if (isBluetoothGattClientSupported == false) - { - BluetoothHelper.DisplayLabel("WriteValueAsync_CHECK_EXCEPTION"); - await ManualTest.WaitForConfirm(); - } - } - catch (TypeInitializationException e) - { - if (isBluetoothGattClientSupported == false && e.InnerException.GetType() == typeof(NotSupportedException)) - { - BluetoothHelper.DisplayLabel("WriteValueAsync_CHECK_EXCEPTION"); - await ManualTest.WaitForConfirm(); - } - } - catch (Exception ex) - { - Assert.True(false, "Exception occurs. Msg : " + ex.ToString()); - } - } - - //[Test] + [Test] [Category("P1")] [Description("Test WriteValueAsync method for BluetoothGattDescriptor")] [Property("SPEC", "Tizen.Network.Bluetooth.BluetoothGattClient.WriteValueAsync M")] @@ -427,29 +375,33 @@ namespace Tizen.Network.Bluetooth.Tests [Step(1, "Tap the Run button.")] [Step(2, "TC should pass automatically.")] [Postcondition(1, "If TC fails, turn off and turn on Bluetooth on both the devices. Try again.")] - public static async Task WriteValueAsync_Descriptor_RETURN_VALUE() + public async Task WriteValueAsync_Descriptor_RETURN_VALUE() { try { - await BluetoothSetup.gatt_client_init(); - - BluetoothGattService srv = BluetoothSetup.client.GetService(BluetoothSetup.serviceUuid); - Assert.IsNotNull(srv, "srv should not be null"); + /* We can't occupy the precondition, if GATT Client feature is not supported in Manual TC */ + if (isBluetoothGattClientSupported == false) + { + BluetoothHelper.DisplayLabel("RemoteAddress_PROPERTY_READ_ONLY"); + await ManualTest.WaitForConfirm(); + return; + } - BluetoothGattCharacteristic charc = srv.GetCharacteristic(BluetoothSetup.characteristicUuid); - Assert.IsNotNull(charc, "charc should not be null"); + client = await BluetoothSetup.gatt_client_init(); + Assert.IsNotNull(client, "Precondition failed: client instance should not be null"); - BluetoothGattDescriptor desc = charc.GetDescriptor(BluetoothSetup.descriptorUuid); - Assert.IsNotNull(desc, "desc should not be null"); + BluetoothGattService srv = BluetoothSetup.client.GetService(svcUuid); + BluetoothGattCharacteristic charc = srv.GetCharacteristic(charUuid); + BluetoothGattDescriptor desc = charc.GetDescriptor(descUuid); desc.SetValue(desc_value); - bool status = await BluetoothSetup.client.WriteValueAsync(desc); + bool status = await client.WriteValueAsync(desc); Assert.IsTrue(status, "WriteValueAsync Status should be true"); string value = desc.GetValue(0); Assert.AreEqual(desc_value, value); - } + } catch (NotSupportedException) { if (isBluetoothGattClientSupported == false) @@ -472,7 +424,7 @@ namespace Tizen.Network.Bluetooth.Tests } } - //[Test] + [Test] [Category("P1")] [Description("Test DestroyClient method of BluetoothGattClient")] [Property("SPEC", "Tizen.Network.Bluetooth.BluetoothGattClient.DestroyClient M")] @@ -483,18 +435,24 @@ namespace Tizen.Network.Bluetooth.Tests [Step(1, "Tap the Run button.")] [Step(2, "TC should pass automatically.")] [Postcondition(1, "If TC fails, turn off and turn on Bluetooth on both the devices. Try again.")] - public static async Task DestroyClient_RETURN_VALUE() + public async Task DestroyClient_RETURN_VALUE() { try { - await BluetoothSetup.gatt_client_init(); - - Assert.IsNotNull(BluetoothSetup.client, "Gatt Client instance should not be null after init"); + /* We can't occupy the precondition, if GATT Client feature is not supported in Manual TC */ + if (isBluetoothGattClientSupported == false) + { + BluetoothHelper.DisplayLabel("RemoteAddress_PROPERTY_READ_ONLY"); + await ManualTest.WaitForConfirm(); + return; + } - BluetoothSetup.gatt_client_exit(); + client = await BluetoothSetup.gatt_client_init(); + Assert.IsNotNull(client, "Precondition failed: client instance should not be null"); - Assert.IsNull(BluetoothSetup.client, "Gatt Client instance should be null after exit"); - } + bool status = await BluetoothSetup.gatt_client_exit(); + Assert.IsTrue(status, "Status should be true"); + } catch (NotSupportedException) { if (isBluetoothGattClientSupported == false) diff --git a/tct-suite-vs/Tizen.Bluetooth.Manual.Tests/testcase/TSBluetoothLeDevice.cs b/tct-suite-vs/Tizen.Bluetooth.Manual.Tests/testcase/TSBluetoothLeDevice.cs index eec4ad5fd..2d6ae7547 100644 --- a/tct-suite-vs/Tizen.Bluetooth.Manual.Tests/testcase/TSBluetoothLeDevice.cs +++ b/tct-suite-vs/Tizen.Bluetooth.Manual.Tests/testcase/TSBluetoothLeDevice.cs @@ -16,6 +16,7 @@ namespace Tizen.Network.Bluetooth.Tests { static BluetoothLeDevice leDevice = null; static bool isBluetoothLeSupported = false; + static bool isBluetoothGattClientSupported = false; static bool isGattConnected = false; [SetUp] @@ -23,15 +24,13 @@ namespace Tizen.Network.Bluetooth.Tests { LogUtils.Write(LogUtils.DEBUG, LogUtils.INFO, "Preconditions for each TEST"); Information.TryGetValue("http://tizen.org/feature/network.bluetooth.le", out isBluetoothLeSupported); + Information.TryGetValue("http://tizen.org/feature/network.bluetooth.le.gatt.client", out isBluetoothGattClientSupported); } [TearDown] public static void Destroy() { LogUtils.Write(LogUtils.DEBUG, LogUtils.INFO, "Postconditions for each TEST"); - - if (BluetoothSetup.role != null && BluetoothSetup.role.Equals("client")) - BluetoothSetup.gatt_client_exit(); } [Test] @@ -865,8 +864,8 @@ namespace Tizen.Network.Bluetooth.Tests { BluetoothGattClient client = null; - /* We can't occupy the precondition, if BT LE feature is not supported in Manual TC */ - if (isBluetoothLeSupported == false) + /* We can't occupy the precondition, if GATT Client feature is not supported in Manual TC */ + if (isBluetoothGattClientSupported == false) { BluetoothHelper.DisplayLabel("GattConnect_RETURN_VALUE"); await ManualTest.WaitForConfirm(); @@ -894,7 +893,7 @@ namespace Tizen.Network.Bluetooth.Tests } }; - client = leDevice.GattConnect(false); + client = leDevice.GattConnect(true); leDevice.GattConnectionStateChanged += LeDevice_GattConnectionStateChanged; @@ -902,7 +901,7 @@ namespace Tizen.Network.Bluetooth.Tests } catch (NotSupportedException) { - if (isBluetoothLeSupported == false) + if (isBluetoothGattClientSupported == false) { BluetoothHelper.DisplayLabel("GattConnect_RETURN_VALUE"); await ManualTest.WaitForConfirm(); @@ -910,7 +909,7 @@ namespace Tizen.Network.Bluetooth.Tests } catch (TypeInitializationException e) { - if (isBluetoothLeSupported == false && e.InnerException.GetType() == typeof(NotSupportedException)) + if (isBluetoothGattClientSupported == false && e.InnerException.GetType() == typeof(NotSupportedException)) { BluetoothHelper.DisplayLabel("GattConnect_RETURN_VALUE"); await ManualTest.WaitForConfirm(); @@ -940,8 +939,8 @@ namespace Tizen.Network.Bluetooth.Tests { BluetoothGattClient client = null; - /* We can't occupy the precondition, if BT LE feature is not supported in Manual TC */ - if (isBluetoothLeSupported == false) + /* We can't occupy the precondition, if GATT Client feature is not supported in Manual TC */ + if (isBluetoothGattClientSupported == false) { BluetoothHelper.DisplayLabel("GattDisconnect_RETURN_VALUE"); await ManualTest.WaitForConfirm(); @@ -956,7 +955,7 @@ namespace Tizen.Network.Bluetooth.Tests if (isGattConnected == false) { - leDevice.GattConnect(false); + leDevice.GattConnect(true); await Task.Delay(2000); } @@ -979,7 +978,7 @@ namespace Tizen.Network.Bluetooth.Tests } catch (NotSupportedException) { - if (isBluetoothLeSupported == false) + if (isBluetoothGattClientSupported == false) { BluetoothHelper.DisplayLabel("GattDisconnect_RETURN_VALUE"); await ManualTest.WaitForConfirm(); @@ -987,7 +986,7 @@ namespace Tizen.Network.Bluetooth.Tests } catch (TypeInitializationException e) { - if (isBluetoothLeSupported == false && e.InnerException.GetType() == typeof(NotSupportedException)) + if (isBluetoothGattClientSupported == false && e.InnerException.GetType() == typeof(NotSupportedException)) { BluetoothHelper.DisplayLabel("GattDisconnect_RETURN_VALUE"); await ManualTest.WaitForConfirm(); @@ -1017,8 +1016,8 @@ namespace Tizen.Network.Bluetooth.Tests { BluetoothGattClient client = null; - /* We can't occupy the precondition, if BT LE feature is not supported in Manual TC */ - if (isBluetoothLeSupported == false) + /* We can't occupy the precondition, if GATT Client is not supported in Manual TC */ + if (isBluetoothGattClientSupported == false) { BluetoothHelper.DisplayLabel("GattConnectionStateChanged_CHECK_EVENT"); await ManualTest.WaitForConfirm(); @@ -1048,7 +1047,7 @@ namespace Tizen.Network.Bluetooth.Tests } else { - client = leDevice.GattConnect(false); + client = leDevice.GattConnect(true); } leDevice.GattConnectionStateChanged += LeDevice_GattConnectionStateChanged; @@ -1057,7 +1056,7 @@ namespace Tizen.Network.Bluetooth.Tests } catch (NotSupportedException) { - if (isBluetoothLeSupported == false) + if (isBluetoothGattClientSupported == false) { BluetoothHelper.DisplayLabel("GattConnectionStateChanged_CHECK_EVENT"); await ManualTest.WaitForConfirm(); @@ -1065,7 +1064,7 @@ namespace Tizen.Network.Bluetooth.Tests } catch (TypeInitializationException e) { - if (isBluetoothLeSupported == false && e.InnerException.GetType() == typeof(NotSupportedException)) + if (isBluetoothGattClientSupported == false && e.InnerException.GetType() == typeof(NotSupportedException)) { BluetoothHelper.DisplayLabel("GattConnectionStateChanged_CHECK_EVENT"); await ManualTest.WaitForConfirm(); diff --git a/tct-suite-vs/Tizen.Bluetooth.Manual.Tests/testcase/TSGattConnectionStateChangedEventArgs.cs b/tct-suite-vs/Tizen.Bluetooth.Manual.Tests/testcase/TSGattConnectionStateChangedEventArgs.cs old mode 100755 new mode 100644 index 8f056d7d1..3ec39adbf --- a/tct-suite-vs/Tizen.Bluetooth.Manual.Tests/testcase/TSGattConnectionStateChangedEventArgs.cs +++ b/tct-suite-vs/Tizen.Bluetooth.Manual.Tests/testcase/TSGattConnectionStateChangedEventArgs.cs @@ -13,6 +13,8 @@ namespace Tizen.Network.Bluetooth.Tests public class GattConnectionStateChangedEventArgsTests { static bool isBluetoothGattClientSupported = false; + static BluetoothLeDevice leDevice = null; + static bool isGattConnected = false; [SetUp] public static void Init() @@ -25,10 +27,9 @@ namespace Tizen.Network.Bluetooth.Tests public static void Destroy() { LogUtils.Write(LogUtils.DEBUG, LogUtils.INFO, "Postconditions for each TEST"); - BluetoothSetup.gatt_client_exit(); } - //[Test] + [Test] [Category("P1")] [Description("Test IsConnected parameter of GattConnectionStateChangedEventArgs")] [Property("SPEC", "Tizen.Network.Bluetooth.GattConnectionStateChangedEventArgs.IsConnected A")] @@ -38,14 +39,53 @@ namespace Tizen.Network.Bluetooth.Tests [Precondition(1, "Bluetooth should be turned on.")] [Precondition(2, "Run BluetoothGattAttributeTests.ReadRequested_Characteristics_CHECK_EVENT test case on the server device.")] [Step(1, "Tap the Run button.")] - [Step(2, "TC should pass automatically.")] [Postcondition(1, "If TC fails, turn off and turn on Bluetooth on both the devices. Try again.")] public static async Task IsConnected_READ_ONLY() { try { - await BluetoothSetup.gatt_client_init(); - } + BluetoothGattClient client = null; + + /* We can't occupy the precondition, if BT GATT Client feature is not supported in Manual TC */ + if (isBluetoothGattClientSupported == false) + { + BluetoothHelper.DisplayLabel("IsConnected_READ_ONLY"); + await ManualTest.WaitForConfirm(); + return; + } + + if (leDevice == null) + { + leDevice = await BluetoothSetup.LeScanSetup(); + Assert.IsNotNull(leDevice, "Precondition failed: Le device instance should not be null"); + } + + EventHandler LeDevice_GattConnectionStateChanged = null; + + LeDevice_GattConnectionStateChanged = (sender, e) => { + leDevice.GattConnectionStateChanged -= LeDevice_GattConnectionStateChanged; + + if (e.Result != (int)BluetoothError.None && e.Result != (int)BluetoothError.AlreadyDone) + { + Log.Info(Globals.LogTag, "Fail to connect " + (int)e.Result); + BluetoothHelper.DisplayRetryLabel("IsConnected_READ_ONLY"); + return; + } + + isGattConnected = e.IsConnected; + + Assert.IsInstanceOf(e.IsConnected, "[TestCase][IsConnected_READ_ONLY] Failed"); + Assert.IsTrue(e.IsConnected == true, "[TestCase][IsConnected_READ_ONLY] Failed"); + + BluetoothHelper.DisplayPassLabel("IsConnected_READ_ONLY"); + }; + + client = leDevice.GattConnect(true); + + leDevice.GattConnectionStateChanged += LeDevice_GattConnectionStateChanged; + + await ManualTest.WaitForConfirm(); + } catch (NotSupportedException) { if (isBluetoothGattClientSupported == false) @@ -57,7 +97,7 @@ namespace Tizen.Network.Bluetooth.Tests catch (TypeInitializationException e) { if (isBluetoothGattClientSupported == false && e.InnerException.GetType() == typeof(NotSupportedException)) - { + { BluetoothHelper.DisplayLabel("IsConnected_READ_ONLY"); await ManualTest.WaitForConfirm(); } @@ -66,9 +106,18 @@ namespace Tizen.Network.Bluetooth.Tests { Assert.True(false, "Exception occurs. Msg : " + ex.ToString()); } + finally + { + if (leDevice != null && isGattConnected == true) + { + leDevice.GattDisconnect(); + await Task.Delay(2000); + isGattConnected = false; + } + } } - //[Test] + [Test] [Category("P1")] [Description("Test RemoteAddress parameter of GattConnectionStateChangedEventArgs")] [Property("SPEC", "Tizen.Network.Bluetooth.GattConnectionStateChangedEventArgs.RemoteAddress A")] @@ -84,8 +133,48 @@ namespace Tizen.Network.Bluetooth.Tests { try { - await BluetoothSetup.gatt_client_init(); - } + BluetoothGattClient client = null; + + /* We can't occupy the precondition, if BT GATT Client feature is not supported in Manual TC */ + if (isBluetoothGattClientSupported == false) + { + BluetoothHelper.DisplayLabel("RemoteAddress_READ_ONLY"); + await ManualTest.WaitForConfirm(); + return; + } + + if (leDevice == null) + { + leDevice = await BluetoothSetup.LeScanSetup(); + Assert.IsNotNull(leDevice, "Precondition failed: Le device instance should not be null"); + } + + EventHandler LeDevice_GattConnectionStateChanged = null; + + LeDevice_GattConnectionStateChanged = (sender, e) => { + leDevice.GattConnectionStateChanged -= LeDevice_GattConnectionStateChanged; + + if (e.Result != (int)BluetoothError.None && e.Result != (int)BluetoothError.AlreadyDone) + { + Log.Info(Globals.LogTag, "Fail to connect " + (int)e.Result); + BluetoothHelper.DisplayRetryLabel("RemoteAddress_READ_ONLY"); + return; + } + + isGattConnected = e.IsConnected; + + Assert.IsInstanceOf(e.RemoteAddress, "[TestCase][RemoteAddress_READ_ONLY] Failed"); + Assert.True(String.Equals(e.RemoteAddress, PreconditionUtils.GetBleAddress()), "[TestCase][RemoteAddress_READ_ONLY] Failed"); + + BluetoothHelper.DisplayPassLabel("RemoteAddress_READ_ONLY"); + }; + + client = leDevice.GattConnect(true); + + leDevice.GattConnectionStateChanged += LeDevice_GattConnectionStateChanged; + + await ManualTest.WaitForConfirm(); + } catch (NotSupportedException) { if (isBluetoothGattClientSupported == false) @@ -97,7 +186,7 @@ namespace Tizen.Network.Bluetooth.Tests catch (TypeInitializationException e) { if (isBluetoothGattClientSupported == false && e.InnerException.GetType() == typeof(NotSupportedException)) - { + { BluetoothHelper.DisplayLabel("RemoteAddress_READ_ONLY"); await ManualTest.WaitForConfirm(); } @@ -106,9 +195,18 @@ namespace Tizen.Network.Bluetooth.Tests { Assert.True(false, "Exception occurs. Msg : " + ex.ToString()); } + finally + { + if (leDevice != null && isGattConnected == true) + { + leDevice.GattDisconnect(); + await Task.Delay(2000); + isGattConnected = false; + } + } } - //[Test] + [Test] [Category("P1")] [Description("Test Result parameter of GattConnectionStateChangedEventArgs")] [Property("SPEC", "Tizen.Network.Bluetooth.GattConnectionStateChangedEventArgs.Result A")] @@ -124,8 +222,47 @@ namespace Tizen.Network.Bluetooth.Tests { try { - await BluetoothSetup.gatt_client_init(); - } + BluetoothGattClient client = null; + + /* We can't occupy the precondition, if BT GATT Client feature is not supported in Manual TC */ + if (isBluetoothGattClientSupported == false) + { + BluetoothHelper.DisplayLabel("Result_READ_ONLY"); + await ManualTest.WaitForConfirm(); + return; + } + + if (leDevice == null) + { + leDevice = await BluetoothSetup.LeScanSetup(); + Assert.IsNotNull(leDevice, "Precondition failed: Le device instance should not be null"); + } + + EventHandler LeDevice_GattConnectionStateChanged = null; + + LeDevice_GattConnectionStateChanged = (sender, e) => { + leDevice.GattConnectionStateChanged -= LeDevice_GattConnectionStateChanged; + + if (e.Result != (int)BluetoothError.None && e.Result != (int)BluetoothError.AlreadyDone) + { + Log.Info(Globals.LogTag, "Fail to connect " + (int)e.Result); + BluetoothHelper.DisplayRetryLabel("Result_READ_ONLY"); + return; + } + + isGattConnected = e.IsConnected; + + Assert.IsInstanceOf(e.Result, "[TestCase][Result_READ_ONLY] Failed"); + + BluetoothHelper.DisplayPassLabel("Result_READ_ONLY"); + }; + + client = leDevice.GattConnect(true); + + leDevice.GattConnectionStateChanged += LeDevice_GattConnectionStateChanged; + + await ManualTest.WaitForConfirm(); + } catch (NotSupportedException) { if (isBluetoothGattClientSupported == false) @@ -137,7 +274,7 @@ namespace Tizen.Network.Bluetooth.Tests catch (TypeInitializationException e) { if (isBluetoothGattClientSupported == false && e.InnerException.GetType() == typeof(NotSupportedException)) - { + { BluetoothHelper.DisplayLabel("Result_READ_ONLY"); await ManualTest.WaitForConfirm(); } @@ -146,6 +283,15 @@ namespace Tizen.Network.Bluetooth.Tests { Assert.True(false, "Exception occurs. Msg : " + ex.ToString()); } + finally + { + if (leDevice != null && isGattConnected == true) + { + leDevice.GattDisconnect(); + await Task.Delay(2000); + isGattConnected = false; + } + } } } } diff --git a/tct-suite-vs/Tizen.Bluetooth.Manual.Tests/testcase/TSValueChangedEventArgs.cs b/tct-suite-vs/Tizen.Bluetooth.Manual.Tests/testcase/TSValueChangedEventArgs.cs old mode 100755 new mode 100644 index 22538bdd1..c4390f3f4 --- a/tct-suite-vs/Tizen.Bluetooth.Manual.Tests/testcase/TSValueChangedEventArgs.cs +++ b/tct-suite-vs/Tizen.Bluetooth.Manual.Tests/testcase/TSValueChangedEventArgs.cs @@ -14,50 +14,25 @@ namespace Tizen.Network.Bluetooth.Tests [Description("ValueChangedEventArgs Tests")] public class ValueChangedEventArgsTests { - static bool ValueChanged_flag = false; - static bool isBluetoothLeSupported = false; - static bool isBluetoothGattClientSupported = false; - static string val = null; - + bool isBluetoothGattClientSupported = false; + BluetoothGattClient client = null; + string svcUuid = "181D"; + string charUuid = "2A20"; [SetUp] - public static void Init() + public void Init() { LogUtils.Write(LogUtils.DEBUG, LogUtils.INFO, "Preconditions for each TEST"); - Information.TryGetValue("http://tizen.org/feature/network.bluetooth.le", out isBluetoothLeSupported); Information.TryGetValue("http://tizen.org/feature/network.bluetooth.le.gatt.client", out isBluetoothGattClientSupported); } [TearDown] - public static void Destroy() + public void Destroy() { LogUtils.Write(LogUtils.DEBUG, LogUtils.INFO, "Postconditions for each TEST"); - BluetoothSetup.gatt_client_exit(); - } - - public static async Task WaitCharcValueChanged() - { - int count = 0; - while (true) - { - Log.Info(Globals.LogTag, "WaitCharcValueChanged"); - await Task.Delay(3000); - count++; - if (ValueChanged_flag) - break; - if (count == 15) - break; - } } - private static void Charc_ValueChanged(object sender, ValueChangedEventArgs e) - { - ValueChanged_flag = true; - Assert.IsInstanceOf(e.Value, "Value param is not a byte[] type"); - Assert.AreNotEqual(val, e.Value.ToString()); - } - - //[Test] + [Test] [Category("P1")] [Description("Check Value parameter of ValueChangedEventArgs")] [Property("SPEC", "Tizen.Network.Bluetooth.ValueChangedEventArgs.Value A")] @@ -67,41 +42,53 @@ namespace Tizen.Network.Bluetooth.Tests [Precondition(1, "Bluetooth should be turned on.")] [Precondition(2, "Run BluetoothGattServerTests.SendIndicationAsync_RETURN_VALUE test case on the server device.")] [Step(1, "Tap the Run button.")] - [Step(2, "TC should pass automatically.")] [Postcondition(1, "If TC fails, turn off and turn on Bluetooth on both the devices. Try again.")] - public static async Task Value_READ_ONLY() + public async Task Value_READ_ONLY() { try { - await BluetoothSetup.gatt_client_init(); + /* We can't occupy the precondition, if GATT Client feature is not supported in Manual TC */ + if (isBluetoothGattClientSupported == false) + { + BluetoothHelper.DisplayLabel("Value_READ_ONLY"); + await ManualTest.WaitForConfirm(); + return; + } + + client = await BluetoothSetup.gatt_client_init(); + Assert.IsNotNull(client, "Precondition failed: client instance should not be null"); - BluetoothGattService srv = BluetoothSetup.client.GetService(BluetoothSetup.serviceUuid); - Assert.IsNotNull(srv, "srv should not be null"); + BluetoothGattService srv = BluetoothSetup.client.GetService(svcUuid); + BluetoothGattCharacteristic charc = srv.GetCharacteristic(charUuid); - BluetoothGattCharacteristic charc = srv.GetCharacteristic(BluetoothSetup.characteristicUuid); - Assert.IsNotNull(charc, "charc should not be null"); + EventHandler Charc_ValueChanged = null; - val = charc.GetValue(0); + Charc_ValueChanged = (sender, e) => { + Assert.IsNotNull(e.Value, "[TestCase][Value_READ_ONLY] Failed"); + Assert.IsInstanceOf(e.Value, "[TestCase][Value_READ_ONLY] Failed"); + + BluetoothHelper.DisplayPassLabel("Value_READ_ONLY"); + }; charc.ValueChanged += Charc_ValueChanged; - await WaitCharcValueChanged(); - Assert.IsTrue(ValueChanged_flag, "ValueChanged callback is not invoked"); + + await ManualTest.WaitForConfirm(); + charc.ValueChanged -= Charc_ValueChanged; - ValueChanged_flag = false; - } + } catch (NotSupportedException) { if (isBluetoothGattClientSupported == false) { - BluetoothHelper.DisplayLabel("Value_READ_ONLY"); + BluetoothHelper.DisplayLabel("ValueChanged_CHECK_EVENT"); await ManualTest.WaitForConfirm(); } } catch (TypeInitializationException e) { if (isBluetoothGattClientSupported == false && e.InnerException.GetType() == typeof(NotSupportedException)) - { - BluetoothHelper.DisplayLabel("Value_READ_ONLY"); + { + BluetoothHelper.DisplayLabel("ValueChanged_CHECK_EVENT"); await ManualTest.WaitForConfirm(); } } @@ -109,6 +96,11 @@ namespace Tizen.Network.Bluetooth.Tests { Assert.True(false, "Exception occurs. Msg : " + ex.ToString()); } + finally + { + if (client != null) + await BluetoothSetup.gatt_client_exit(); + } } } }