[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);
}
[TearDown]
- public static void Destroy()
+ public void Destroy()
{
LogUtils.Write(LogUtils.DEBUG, LogUtils.INFO, "Postconditions for each TEST");
}
[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
{
[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
{
[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
{
[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
{
[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
{
[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
{
[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
{
[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
{
[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
{
[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
{
[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
{
[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
{
[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
{
[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)
{
EventHandler<GattConnectionStateChangedEventArgs> 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)
{
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]
[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)
{
Assert.IsNotNull(leDevice, "Precondition failed: Le device instance should not be null");
}
- if (isGattConnected == false)
- {
- leDevice.GattConnect(true);
- await Task.Delay(2000);
- }
-
EventHandler<GattConnectionStateChangedEventArgs> 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)
{
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]
[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)
{
EventHandler<GattConnectionStateChangedEventArgs> 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();
}
};
{
client = leDevice.GattConnect(true);
}
-
leDevice.GattConnectionStateChanged += LeDevice_GattConnectionStateChanged;
-
await ManualTest.WaitForConfirm();
}
catch (NotSupportedException)
await Task.Delay(2000);
isGattConnected = false;
}
+ client?.Dispose();
}
}
[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");
}
[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)
{
EventHandler<GattConnectionStateChangedEventArgs> 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);
}
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");
+ ManualTest.Confirm();
};
client = leDevice.GattConnect(true);
-
leDevice.GattConnectionStateChanged += LeDevice_GattConnectionStateChanged;
-
await ManualTest.WaitForConfirm();
}
catch (NotSupportedException)
await Task.Delay(2000);
isGattConnected = false;
}
+ client?.Dispose();
}
}
[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)
{
EventHandler<GattConnectionStateChangedEventArgs> 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);
}
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");
+ ManualTest.Confirm();
};
client = leDevice.GattConnect(true);
-
leDevice.GattConnectionStateChanged += LeDevice_GattConnectionStateChanged;
-
await ManualTest.WaitForConfirm();
}
catch (NotSupportedException)
await Task.Delay(2000);
isGattConnected = false;
}
+ client?.Dispose();
}
}
[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)
{
EventHandler<GattConnectionStateChangedEventArgs> 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);
}
isGattConnected = e.IsConnected;
-
Assert.IsInstanceOf<int>(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)
await Task.Delay(2000);
isGattConnected = false;
}
+ client?.Dispose();
}
}
}