In tests, GATT Attributes are added incrementally:
device_ = SimulateLowEnergyDevice(3);
device_->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED),
GetConnectErrorCallback(Call::NOT_EXPECTED));
SimulateGattConnection(device_);
base::RunLoop().RunUntilIdle();
SimulateGattServicesDiscovered(device_, std::vector<std::string>({kTestUUIDGenericAccess}));
service_ = device_->GetGattServices()[0];
SimulateGattCharacteristic(service_, kTestUUIDDeviceName, 0);
characteristic_ = service_->GetCharacteristics()[0];
SimulateGattDescriptor(characteristic_,
kTestUUIDCharacteristicUserDescription);
descriptor1_ = characteristic_->GetDescriptors()[0];
But that's not how discovery actually works in the platform APIs. In the platform APIs discovery is done all at once i.e. once the "Services Discovered" signal arrives all attributes are present.
This pattern is forcing us to perform extra operations that don't actually occur in real devices[1][2]. This causes an increase in the complexity of our testing framework and also makes our tests less accurate.
Tests should define all GATT Attributes upfront and call SimulateGattServicesDiscovered once all desired GATT Attributes are in place. A test would look like this:
SimulateGattService(...);
SimulateGattCharacteristic(...);
SimulateGattDescriptor(...);
SimulateGattDiscoveryComplete();
[1] https://cs.chromium.org/chromium/src/device/bluetooth/test/bluetooth_test_win.cc?type=cs&q=SimulateGattCharacteristic&sq=package:chromium&l=274
[2] https://cs.chromium.org/chromium/src/device/bluetooth/test/bluetooth_test_mac.mm?type=cs&q=SimulateGattCharacteristic&sq=package:chromium&l=335
Comment 1 by jlebel@chromium.org
, Apr 21 2017