Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5849c5f0 authored by Myles Watson's avatar Myles Watson Committed by Chris Manton
Browse files

Add a new Iterator constructor for PDL

Bug: 319563845
Test: atest bluetooth_test_gd_unit
Flag: EXEMPT, no logical change (syntactic sugar for simplifying other code)
Change-Id: I879f6b4f893fad8b59b6cc86d03bbe6682baebb0
parent 646f5af5
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -32,6 +32,14 @@ Iterator<little_endian>::Iterator(const std::forward_list<View>& data, size_t of
  }
}

template <bool little_endian>
Iterator<little_endian>::Iterator(std::shared_ptr<std::vector<uint8_t>> data) {
  data_.emplace_front(data, 0, data->size());
  index_ = 0;
  begin_ = 0;
  end_ = data_.front().size();
}

template <bool little_endian>
Iterator<little_endian> Iterator<little_endian>::operator+(int offset) const {
  auto itr(*this);
+1 −0
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ template <bool little_endian>
class Iterator : public IteratorTraits {
 public:
  Iterator(const std::forward_list<View>& data, size_t offset);
  Iterator(std::shared_ptr<std::vector<uint8_t>> data);
  Iterator(const Iterator& itr) = default;
  virtual ~Iterator() = default;

+11 −0
Original line number Diff line number Diff line
@@ -17,10 +17,12 @@
#include "packet/packet_view.h"

#include <gtest/gtest.h>

#include <forward_list>
#include <memory>

#include "hci/address.h"
#include "packet/iterator.h"

using bluetooth::hci::Address;
using bluetooth::packet::PacketView;
@@ -399,6 +401,15 @@ TYPED_TEST(IteratorTest, subrangeTest) {
  ASSERT_EQ(*(subrange), this->packet->size() - 1);
}

TYPED_TEST(IteratorTest, constructor_from_shared_vector_test) {
  auto iterator = this->packet->begin();
  Iterator<kLittleEndian> another(std::make_shared<std::vector<uint8_t>>(count_all));
  ASSERT_EQ(iterator.NumBytesRemaining(), another.NumBytesRemaining());
  for (size_t i = 0; i < count_all.size(); i++) {
    ASSERT_EQ(iterator.template extract<uint8_t>(), another.extract<uint8_t>());
  }
}

using SubviewTestParam = std::pair<size_t, size_t>;
class SubviewBaseTest : public ::testing::TestWithParam<SubviewTestParam> {
 public: