From 9f74d4f53396bebad214288810fa3de97153aea9 Mon Sep 17 00:00:00 2001 From: Wootak Jung Date: Fri, 17 May 2019 15:20:47 +0900 Subject: [PATCH] [Bluetooth][Non-ACR] Fix GattClient not destroyed issue Change-Id: I1381e78e38fdae50beb730d90ff631d5ac01012b --- .../testcase/BluetoothSetup.cs | 4 +- .../testcase/TSBluetoothLeDevice.cs | 109 ++++++++++++--------- .../TSGattConnectionStateChangedEventArgs.cs | 53 ++++------ 3 files changed, 86 insertions(+), 80 deletions(-) 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 89781f5..8821d44 100644 --- a/tct-suite-vs/Tizen.Bluetooth.Manual.Tests/testcase/BluetoothSetup.cs +++ b/tct-suite-vs/Tizen.Bluetooth.Manual.Tests/testcase/BluetoothSetup.cs @@ -223,7 +223,7 @@ namespace BluetoothNetworkUtils public static void AcceptStateChangedEventHandler(object sender, AcceptStateChangedEventArgs args) { - Log.Info(Globals.LogTag, "AcceptStateChangedCallback state: "+ args.State); + Log.Info(Globals.LogTag, "AcceptStateChangedCallback invoked!! Result: " + args.Result + ", State: " + args.State); Socket = args.Server; AcceptConnection = args.Connection; AcceptResult = args.Result; @@ -250,7 +250,7 @@ namespace BluetoothNetworkUtils public static void ConnectionStateChangedEventHandler(object sender, SocketConnectionStateChangedEventArgs args) { - Log.Info(Globals.LogTag, "ConnectionStateChanged callback in client "+ args.State); + Log.Info(Globals.LogTag, "ConnectionStateChanged invoked!! Result: " + args.Result + ", State: " + args.State); ClientState = args.State; ClientConnection = args.Connection; ClientResult = args.Result; 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 f25af97..3be19b4 100644 --- a/tct-suite-vs/Tizen.Bluetooth.Manual.Tests/testcase/TSBluetoothLeDevice.cs +++ b/tct-suite-vs/Tizen.Bluetooth.Manual.Tests/testcase/TSBluetoothLeDevice.cs @@ -14,13 +14,14 @@ namespace Tizen.Network.Bluetooth.Tests [Description("BluetoothLeDevice Tests")] public class BluetoothLeDeviceTests { - static BluetoothLeDevice leDevice = null; - static bool isBluetoothLeSupported = false; - static bool isBluetoothGattClientSupported = false; - static bool isGattConnected = false; + BluetoothLeDevice leDevice = null; + bool isBluetoothLeSupported = false; + bool isBluetoothGattClientSupported = false; + bool isGattConnected = false; + 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", out isBluetoothLeSupported); @@ -28,7 +29,7 @@ namespace Tizen.Network.Bluetooth.Tests } [TearDown] - public static void Destroy() + public void Destroy() { LogUtils.Write(LogUtils.DEBUG, LogUtils.INFO, "Postconditions for each TEST"); } @@ -44,7 +45,7 @@ namespace Tizen.Network.Bluetooth.Tests [Precondition(2, "Run GATT Server test case on another device")] [Step(1, "Tap the Run button")] [Postcondition(1, "NA")] - public static async Task AddressType_PROPERTY_READ_ONLY() + public async Task AddressType_PROPERTY_READ_ONLY() { try { @@ -100,7 +101,7 @@ namespace Tizen.Network.Bluetooth.Tests [Precondition(2, "Run GATT Server test case on another device")] [Step(1, "Tap the Run button")] [Postcondition(1, "NA")] - public static async Task AdvertsingDataInformation_PROPERTY_READ_ONLY() + public async Task AdvertsingDataInformation_PROPERTY_READ_ONLY() { try { @@ -155,7 +156,7 @@ namespace Tizen.Network.Bluetooth.Tests [Precondition(2, "Run GATT Server test case on another device")] [Step(1, "Tap the Run button")] [Postcondition(1, "NA")] - public static async Task Appearance_PROPERTY_READ_ONLY() + public async Task Appearance_PROPERTY_READ_ONLY() { try { @@ -223,7 +224,7 @@ namespace Tizen.Network.Bluetooth.Tests [Precondition(2, "Run GATT Server test case on another device")] [Step(1, "Tap the Run button")] [Postcondition(1, "NA")] - public static async Task DeviceName_PROPERTY_READ_ONLY() + public async Task DeviceName_PROPERTY_READ_ONLY() { try { @@ -288,7 +289,7 @@ namespace Tizen.Network.Bluetooth.Tests [Precondition(2, "Run GATT Server test case on another device")] [Step(1, "Tap the Run button")] [Postcondition(1, "NA")] - public static async Task ManufacturerData_PROPERTY_READ_ONLY() + public async Task ManufacturerData_PROPERTY_READ_ONLY() { try { @@ -355,7 +356,7 @@ namespace Tizen.Network.Bluetooth.Tests [Precondition(2, "Run GATT Server test case on another device")] [Step(1, "Tap the Run button")] [Postcondition(1, "NA")] - public static async Task RemoteAddress_PROPERTY_READ_ONLY() + public async Task RemoteAddress_PROPERTY_READ_ONLY() { try { @@ -410,7 +411,7 @@ namespace Tizen.Network.Bluetooth.Tests [Precondition(2, "Run GATT Server test case on another device")] [Step(1, "Tap the Run button")] [Postcondition(1, "NA")] - public static async Task Rssi_PROPERTY_READ_ONLY() + public async Task Rssi_PROPERTY_READ_ONLY() { try { @@ -465,7 +466,7 @@ namespace Tizen.Network.Bluetooth.Tests [Precondition(2, "Run GATT Server test case on another device")] [Step(1, "Tap the Run button")] [Postcondition(1, "NA")] - public static async Task ScanDataInformation_PROPERTY_READ_ONLY() + public async Task ScanDataInformation_PROPERTY_READ_ONLY() { try { @@ -526,7 +527,7 @@ namespace Tizen.Network.Bluetooth.Tests [Precondition(2, "Run GATT Server test case on another device")] [Step(1, "Tap the Run button")] [Postcondition(1, "NA")] - public static async Task ServiceSolictationUuid_PROPERTY_READ_ONLY() + public async Task ServiceSolictationUuid_PROPERTY_READ_ONLY() { try { @@ -594,7 +595,7 @@ namespace Tizen.Network.Bluetooth.Tests [Precondition(2, "Run GATT Server test case on another device")] [Step(1, "Tap the Run button")] [Postcondition(1, "NA")] - public static async Task ServiceUuid_PROPERTY_READ_ONLY() + public async Task ServiceUuid_PROPERTY_READ_ONLY() { try { @@ -662,7 +663,7 @@ namespace Tizen.Network.Bluetooth.Tests [Precondition(2, "Run GATT Server test case on another device")] [Step(1, "Tap the Run button")] [Postcondition(1, "NA")] - public static async Task TxPowerLevel_PROPERTY_READ_ONLY() + public async Task TxPowerLevel_PROPERTY_READ_ONLY() { try { @@ -729,7 +730,7 @@ namespace Tizen.Network.Bluetooth.Tests [Precondition(2, "Run GATT Server test case on another device")] [Step(1, "Tap the Run button")] [Postcondition(1, "NA")] - public static async Task GetServiceDataList_RETURN_LIST() + public async Task GetServiceDataList_RETURN_LIST() { try { @@ -796,7 +797,7 @@ namespace Tizen.Network.Bluetooth.Tests [Precondition(2, "Run GATT Server test case on another device")] [Step(1, "Tap the Run button")] [Postcondition(1, "NA")] - public static async Task PacketType_PROPERTY_READ_WRITE() + public async Task PacketType_PROPERTY_READ_WRITE() { try { @@ -858,12 +859,10 @@ 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. Try again.")] - public static async Task GattConnect_RETURN_VALUE() + public async Task GattConnect_RETURN_VALUE() { try { - BluetoothGattClient client = null; - /* We can't occupy the precondition, if GATT Client feature is not supported in Manual TC */ if (isBluetoothGattClientSupported == false) { @@ -881,22 +880,21 @@ namespace Tizen.Network.Bluetooth.Tests EventHandler LeDevice_GattConnectionStateChanged = null; LeDevice_GattConnectionStateChanged = (sender, e) => { + Log.Info(Globals.LogTag, "GattConnectionStateChanged invoked!! Result: " + e.Result + ", IsConnected: " + e.IsConnected); leDevice.GattConnectionStateChanged -= LeDevice_GattConnectionStateChanged; if (e.Result == 0 && e.IsConnected == true) { isGattConnected = true; - BluetoothHelper.DisplayPassLabel("GattConnect_RETURN_VALUE"); + ManualTest.Confirm(); } else { - BluetoothHelper.DisplayRetryLabel("GattConnect_RETURN_VALUE"); + ManualTest.ConfirmFail("GattConnect_RETURN_VALUE"); } }; client = leDevice.GattConnect(true); - leDevice.GattConnectionStateChanged += LeDevice_GattConnectionStateChanged; - await ManualTest.WaitForConfirm(); } catch (NotSupportedException) @@ -919,6 +917,16 @@ 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; + } + client?.Dispose(); + } } [Test] @@ -933,12 +941,10 @@ 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. Try again.")] - public static async Task GattDisconnect_RETURN_VALUE() + public async Task GattDisconnect_RETURN_VALUE() { try { - BluetoothGattClient client = null; - /* We can't occupy the precondition, if GATT Client feature is not supported in Manual TC */ if (isBluetoothGattClientSupported == false) { @@ -953,27 +959,29 @@ namespace Tizen.Network.Bluetooth.Tests Assert.IsNotNull(leDevice, "Precondition failed: Le device instance should not be null"); } - if (isGattConnected == false) - { - leDevice.GattConnect(true); - await Task.Delay(2000); - } - EventHandler LeDevice_GattConnectionStateChanged = null; LeDevice_GattConnectionStateChanged = (sender, e) => { - leDevice.GattConnectionStateChanged -= LeDevice_GattConnectionStateChanged; - if (e.Result == 0 && e.IsConnected == false) + Log.Info(Globals.LogTag, "GattConnectionStateChanged invoked!! Result: " + e.Result + ", IsConnected: " + e.IsConnected); + + if (e.Result == 0 && e.IsConnected == true) { + isGattConnected = true; + ManualTest.Confirm(); + } + else if (e.Result == 0 && e.IsConnected == false) + { + leDevice.GattConnectionStateChanged -= LeDevice_GattConnectionStateChanged; isGattConnected = false; - BluetoothHelper.DisplayPassLabel("GattDisconnect_RETURN_VALUE"); + ManualTest.Confirm(); } }; - leDevice.GattDisconnect(); - + client = leDevice.GattConnect(true); leDevice.GattConnectionStateChanged += LeDevice_GattConnectionStateChanged; + await ManualTest.WaitForConfirm(); + leDevice.GattDisconnect(); await ManualTest.WaitForConfirm(); } catch (NotSupportedException) @@ -996,6 +1004,16 @@ 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; + } + client?.Dispose(); + } } [Test] @@ -1010,12 +1028,10 @@ 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. Try again.")] - public static async Task GattConnectionStateChanged_CHECK_EVENT() + public async Task GattConnectionStateChanged_CHECK_EVENT() { try { - BluetoothGattClient client = null; - /* We can't occupy the precondition, if GATT Client is not supported in Manual TC */ if (isBluetoothGattClientSupported == false) { @@ -1033,11 +1049,13 @@ namespace Tizen.Network.Bluetooth.Tests EventHandler LeDevice_GattConnectionStateChanged = null; LeDevice_GattConnectionStateChanged = (sender, e) => { + Log.Info(Globals.LogTag, "GattConnectionStateChanged invoked!! Result: " + e.Result + ", IsConnected: " + e.IsConnected); + leDevice.GattConnectionStateChanged -= LeDevice_GattConnectionStateChanged; if (e.Result == 0) { isGattConnected = e.IsConnected; - BluetoothHelper.DisplayPassLabel("GattConnectionStateChanged_CHECK_EVENT"); + ManualTest.Confirm(); } }; @@ -1049,9 +1067,7 @@ namespace Tizen.Network.Bluetooth.Tests { client = leDevice.GattConnect(true); } - leDevice.GattConnectionStateChanged += LeDevice_GattConnectionStateChanged; - await ManualTest.WaitForConfirm(); } catch (NotSupportedException) @@ -1082,6 +1098,7 @@ namespace Tizen.Network.Bluetooth.Tests await Task.Delay(2000); isGattConnected = false; } + client?.Dispose(); } } diff --git a/tct-suite-vs/Tizen.Bluetooth.Manual.Tests/testcase/TSGattConnectionStateChangedEventArgs.cs b/tct-suite-vs/Tizen.Bluetooth.Manual.Tests/testcase/TSGattConnectionStateChangedEventArgs.cs index 3ec39ad..fdbea1e 100644 --- a/tct-suite-vs/Tizen.Bluetooth.Manual.Tests/testcase/TSGattConnectionStateChangedEventArgs.cs +++ b/tct-suite-vs/Tizen.Bluetooth.Manual.Tests/testcase/TSGattConnectionStateChangedEventArgs.cs @@ -12,19 +12,20 @@ namespace Tizen.Network.Bluetooth.Tests [Description("GattConnectionStateChangedEventArgs Tests")] public class GattConnectionStateChangedEventArgsTests { - static bool isBluetoothGattClientSupported = false; - static BluetoothLeDevice leDevice = null; - static bool isGattConnected = false; + bool isBluetoothGattClientSupported = false; + BluetoothLeDevice leDevice = null; + bool isGattConnected = false; + 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"); } @@ -40,12 +41,10 @@ namespace Tizen.Network.Bluetooth.Tests [Precondition(2, "Run BluetoothGattAttributeTests.ReadRequested_Characteristics_CHECK_EVENT test case on the server device.")] [Step(1, "Tap the Run button.")] [Postcondition(1, "If TC fails, turn off and turn on Bluetooth on both the devices. Try again.")] - public static async Task IsConnected_READ_ONLY() + public async Task IsConnected_READ_ONLY() { try { - BluetoothGattClient client = null; - /* We can't occupy the precondition, if BT GATT Client feature is not supported in Manual TC */ if (isBluetoothGattClientSupported == false) { @@ -63,8 +62,9 @@ namespace Tizen.Network.Bluetooth.Tests EventHandler LeDevice_GattConnectionStateChanged = null; LeDevice_GattConnectionStateChanged = (sender, e) => { - leDevice.GattConnectionStateChanged -= LeDevice_GattConnectionStateChanged; + Log.Info(Globals.LogTag, "GattConnectionStateChanged invoked!! Result: " + e.Result + ", IsConnected: " + e.IsConnected); + 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); @@ -73,17 +73,13 @@ namespace Tizen.Network.Bluetooth.Tests } 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"); + ManualTest.Confirm(); }; client = leDevice.GattConnect(true); - leDevice.GattConnectionStateChanged += LeDevice_GattConnectionStateChanged; - await ManualTest.WaitForConfirm(); } catch (NotSupportedException) @@ -114,6 +110,7 @@ namespace Tizen.Network.Bluetooth.Tests await Task.Delay(2000); isGattConnected = false; } + client?.Dispose(); } } @@ -129,12 +126,10 @@ 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 RemoteAddress_READ_ONLY() + public async Task RemoteAddress_READ_ONLY() { try { - BluetoothGattClient client = null; - /* We can't occupy the precondition, if BT GATT Client feature is not supported in Manual TC */ if (isBluetoothGattClientSupported == false) { @@ -152,8 +147,9 @@ namespace Tizen.Network.Bluetooth.Tests EventHandler LeDevice_GattConnectionStateChanged = null; LeDevice_GattConnectionStateChanged = (sender, e) => { - leDevice.GattConnectionStateChanged -= LeDevice_GattConnectionStateChanged; + Log.Info(Globals.LogTag, "GattConnectionStateChanged invoked!! Result: " + e.Result + ", IsConnected: " + e.IsConnected); + 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); @@ -162,17 +158,13 @@ namespace Tizen.Network.Bluetooth.Tests } 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"); + ManualTest.Confirm(); }; client = leDevice.GattConnect(true); - leDevice.GattConnectionStateChanged += LeDevice_GattConnectionStateChanged; - await ManualTest.WaitForConfirm(); } catch (NotSupportedException) @@ -203,6 +195,7 @@ namespace Tizen.Network.Bluetooth.Tests await Task.Delay(2000); isGattConnected = false; } + client?.Dispose(); } } @@ -218,12 +211,10 @@ 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 Result_READ_ONLY() + public async Task Result_READ_ONLY() { try { - BluetoothGattClient client = null; - /* We can't occupy the precondition, if BT GATT Client feature is not supported in Manual TC */ if (isBluetoothGattClientSupported == false) { @@ -241,8 +232,9 @@ namespace Tizen.Network.Bluetooth.Tests EventHandler LeDevice_GattConnectionStateChanged = null; LeDevice_GattConnectionStateChanged = (sender, e) => { - leDevice.GattConnectionStateChanged -= LeDevice_GattConnectionStateChanged; + Log.Info(Globals.LogTag, "GattConnectionStateChanged invoked!! Result: " + e.Result + ", IsConnected: " + e.IsConnected); + 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); @@ -251,16 +243,12 @@ namespace Tizen.Network.Bluetooth.Tests } isGattConnected = e.IsConnected; - Assert.IsInstanceOf(e.Result, "[TestCase][Result_READ_ONLY] Failed"); - - BluetoothHelper.DisplayPassLabel("Result_READ_ONLY"); + ManualTest.Confirm(); }; client = leDevice.GattConnect(true); - leDevice.GattConnectionStateChanged += LeDevice_GattConnectionStateChanged; - await ManualTest.WaitForConfirm(); } catch (NotSupportedException) @@ -291,6 +279,7 @@ namespace Tizen.Network.Bluetooth.Tests await Task.Delay(2000); isGattConnected = false; } + client?.Dispose(); } } } -- 2.7.4