From 574b88d7ef29c5a33eaf963c96a12df1c3c4260c Mon Sep 17 00:00:00 2001 From: Hai Shang Date: Mon, 10 Apr 2023 10:39:53 -0700 Subject: [PATCH] add unit test for NP v0 advertisement parsing PiperOrigin-RevId: 523153029 --- .../implementation/advertisement_decoder_test.cc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/presence/implementation/advertisement_decoder_test.cc b/presence/implementation/advertisement_decoder_test.cc index c667503d..8a6d6c49 100644 --- a/presence/implementation/advertisement_decoder_test.cc +++ b/presence/implementation/advertisement_decoder_test.cc @@ -242,6 +242,22 @@ TEST(AdvertisementDecoder, DecodeBaseNpWithTxActionField) { DataElement(DataElement(ActionBit::kNearbyShareAction)))); } +TEST(AdvertisementDecoder, DecodeBaseNpV0PublicIdentityWithTxAndActionField) { + AdvertisementDecoder decoder(GetScanRequest()); + + auto result = decoder.DecodeAdvertisement( + // v0 public identity, power and action, action value 8 for active unlock. + absl::HexStringToBytes("000336FF0080")); + + EXPECT_OK(result); + EXPECT_THAT(result->data_elements, + UnorderedElementsAre( + DataElement(DataElement::kPublicIdentityFieldType, ""), + DataElement(DataElement::kTxPowerFieldType, + absl::HexStringToBytes("ff")), + DataElement(DataElement(ActionBit::kActiveUnlockAction)))); +} + TEST(AdvertisementDecoder, ScanForEncryptedIdentityIgnoresPublicIdentityAdvertisement) { AdvertisementDecoder decoder(