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()
{
public static void scanResultEventHandler(object sender, AdapterLeScanResultChangedEventArgs e)
{
- if (!e.DeviceData.Equals(null))
+ if (e.DeviceData != null)
{
if (remote_addr.Equals(default_remote_addr))
{
public static void scanDeviceResultEventHandler(object sender, AdapterLeScanResultChangedEventArgs e)
{
- if (!e.DeviceData.Equals(null))
+ if (e.DeviceData != null)
{
BtLeScanDevice = e.DeviceData;
- scanFlag = true;
+ scanFlag = true;
}
}
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()
}
}
- public static async Task gatt_client_init()
+ public static async Task<BluetoothGattClient> 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<bool> 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()
{
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()
{
BluetoothSetup.gatt_server_exit();
}
-
- if (BluetoothSetup.role.Equals("client"))
- {
- BluetoothSetup.gatt_client_exit();
- }
}
private static void Charc_NotificationStateChanged(object sender, NotificationStateChangedEventArg e)
ManualTest.Confirm();
}
- //[Test]
+ [Test]
[Category("P1")]
[Description("Check whether NotificationStateChanged callback is getting invoked or not")]
[Property("SPEC", "Tizen.Network.Bluetooth.BluetoothGattCharacteristic.NotificationStateChanged E")]
catch (TypeInitializationException e)
{
if (isBluetoothGattServerSupported == false && e.InnerException.GetType() == typeof(NotSupportedException))
- {
+ {
BluetoothHelper.DisplayLabel("NotificationStateChanged_CHECK_EVENT");
await ManualTest.WaitForConfirm();
}
}
}
- 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")]
[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<ValueChangedEventArgs> 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<byte[]>(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)
catch (TypeInitializationException e)
{
if (isBluetoothGattClientSupported == false && e.InnerException.GetType() == typeof(NotSupportedException))
- {
+ {
BluetoothHelper.DisplayLabel("ValueChanged_CHECK_EVENT");
await ManualTest.WaitForConfirm();
}
{
Assert.True(false, "Exception occurs. Msg : " + ex.ToString());
}
+ finally
+ {
+ if (client != null)
+ await BluetoothSetup.gatt_client_exit();
+ }
}
}
}
[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")]
[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)
}
}
- //[Test]
+ [Test]
[Category("P1")]
[Description("Test GetService method of BluetoothGattClient")]
[Property("SPEC", "Tizen.Network.Bluetooth.BluetoothGattClient.GetService M")]
[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)
}
}
- //[Test]
+ [Test]
[Category("P1")]
[Description("Test GetServices method of BluetoothGattClient")]
[Property("SPEC", "Tizen.Network.Bluetooth.BluetoothGattClient.GetServices M")]
[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<BluetoothGattService> 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)
}
}
- //[Test]
+ [Test]
[Category("P1")]
[Description("Test ReadValueAsync for BluetoothGattCharacteristic")]
[Property("SPEC", "Tizen.Network.Bluetooth.BluetoothGattClient.ReadValueAsync M")]
[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();
}
}
{
if (isBluetoothGattClientSupported == false && e.InnerException.GetType() == typeof(NotSupportedException))
{
- BluetoothHelper.DisplayLabel("ReadValueAsync_CHECK_EXCEPTION");
+ BluetoothHelper.DisplayLabel("ReadValueAsync_Characteristic_RETURN_VALUE");
await ManualTest.WaitForConfirm();
}
}
}
}
- //[Test]
+ [Test]
[Category("P1")]
[Description("Test ReadValueAsync method for BluetoothGattDescriptor")]
[Property("SPEC", "Tizen.Network.Bluetooth.BluetoothGattClient.ReadValueAsync M")]
[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)
}
}
- //[Test]
+ [Test]
[Category("P1")]
[Description("Test WriteValueAsync method for BluetoothGattCharacteristic")]
[Property("SPEC", "Tizen.Network.Bluetooth.BluetoothGattClient.WriteValueAsync M")]
[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)
}
}
- //[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")]
[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)
}
}
- //[Test]
+ [Test]
[Category("P1")]
[Description("Test DestroyClient method of BluetoothGattClient")]
[Property("SPEC", "Tizen.Network.Bluetooth.BluetoothGattClient.DestroyClient M")]
[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)
{
static BluetoothLeDevice leDevice = null;
static bool isBluetoothLeSupported = false;
+ static bool isBluetoothGattClientSupported = false;
static bool isGattConnected = false;
[SetUp]
{
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]
{
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();
}
};
- client = leDevice.GattConnect(false);
+ client = leDevice.GattConnect(true);
leDevice.GattConnectionStateChanged += LeDevice_GattConnectionStateChanged;
}
catch (NotSupportedException)
{
- if (isBluetoothLeSupported == false)
+ if (isBluetoothGattClientSupported == false)
{
BluetoothHelper.DisplayLabel("GattConnect_RETURN_VALUE");
await ManualTest.WaitForConfirm();
}
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();
{
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();
if (isGattConnected == false)
{
- leDevice.GattConnect(false);
+ leDevice.GattConnect(true);
await Task.Delay(2000);
}
}
catch (NotSupportedException)
{
- if (isBluetoothLeSupported == false)
+ if (isBluetoothGattClientSupported == false)
{
BluetoothHelper.DisplayLabel("GattDisconnect_RETURN_VALUE");
await ManualTest.WaitForConfirm();
}
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();
{
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();
}
else
{
- client = leDevice.GattConnect(false);
+ client = leDevice.GattConnect(true);
}
leDevice.GattConnectionStateChanged += LeDevice_GattConnectionStateChanged;
}
catch (NotSupportedException)
{
- if (isBluetoothLeSupported == false)
+ if (isBluetoothGattClientSupported == false)
{
BluetoothHelper.DisplayLabel("GattConnectionStateChanged_CHECK_EVENT");
await ManualTest.WaitForConfirm();
}
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();
public class GattConnectionStateChangedEventArgsTests
{
static bool isBluetoothGattClientSupported = false;
+ static BluetoothLeDevice leDevice = null;
+ static bool isGattConnected = false;
[SetUp]
public static void Init()
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")]
[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<GattConnectionStateChangedEventArgs> 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<bool>(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)
catch (TypeInitializationException e)
{
if (isBluetoothGattClientSupported == false && e.InnerException.GetType() == typeof(NotSupportedException))
- {
+ {
BluetoothHelper.DisplayLabel("IsConnected_READ_ONLY");
await ManualTest.WaitForConfirm();
}
{
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")]
{
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<GattConnectionStateChangedEventArgs> 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<string>(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)
catch (TypeInitializationException e)
{
if (isBluetoothGattClientSupported == false && e.InnerException.GetType() == typeof(NotSupportedException))
- {
+ {
BluetoothHelper.DisplayLabel("RemoteAddress_READ_ONLY");
await ManualTest.WaitForConfirm();
}
{
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")]
{
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<GattConnectionStateChangedEventArgs> 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<int>(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)
catch (TypeInitializationException e)
{
if (isBluetoothGattClientSupported == false && e.InnerException.GetType() == typeof(NotSupportedException))
- {
+ {
BluetoothHelper.DisplayLabel("Result_READ_ONLY");
await ManualTest.WaitForConfirm();
}
{
Assert.True(false, "Exception occurs. Msg : " + ex.ToString());
}
+ finally
+ {
+ if (leDevice != null && isGattConnected == true)
+ {
+ leDevice.GattDisconnect();
+ await Task.Delay(2000);
+ isGattConnected = false;
+ }
+ }
}
}
}
[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<byte[]>(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")]
[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<ValueChangedEventArgs> Charc_ValueChanged = null;
- val = charc.GetValue(0);
+ Charc_ValueChanged = (sender, e) => {
+ Assert.IsNotNull(e.Value, "[TestCase][Value_READ_ONLY] Failed");
+ Assert.IsInstanceOf<byte[]>(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();
}
}
{
Assert.True(false, "Exception occurs. Msg : " + ex.ToString());
}
+ finally
+ {
+ if (client != null)
+ await BluetoothSetup.gatt_client_exit();
+ }
}
}
}