提交 36d8f694 authored 作者: José Luis Millán's avatar José Luis Millán

SeqManager: enable setting an offset to the output value

上级 d7b65168
......@@ -38,6 +38,7 @@ namespace RTC
public:
void Sync(T input);
void Drop(T input);
void Offset(T offset);
bool Input(const T input, T& output);
T GetMaxInput() const;
T GetMaxOutput() const;
......
......@@ -64,6 +64,12 @@ namespace RTC
this->dropped.insert(input);
}
template<typename T>
void SeqManager<T>::Offset(T offset)
{
this->base += offset;
}
template<typename T>
bool SeqManager<T>::Input(const T input, T& output)
{
......
......@@ -7,8 +7,9 @@ using namespace RTC;
struct TestSeqManagerInput
{
TestSeqManagerInput(uint16_t input, uint16_t output, bool sync = false, bool drop = false)
: input(input), output(output), sync(sync), drop(drop)
TestSeqManagerInput(
uint16_t input, uint16_t output, bool sync = false, bool drop = false, uint16_t offset = 0)
: input(input), output(output), sync(sync), drop(drop), offset(offset)
{
}
......@@ -16,6 +17,7 @@ struct TestSeqManagerInput
uint16_t output{ 0 };
bool sync{ false };
bool drop{ false };
uint16_t offset{ 0 };
};
void validate(RTC::SeqManager<uint16_t>& seqManager, std::vector<TestSeqManagerInput>& inputs)
......@@ -25,6 +27,9 @@ void validate(RTC::SeqManager<uint16_t>& seqManager, std::vector<TestSeqManagerI
if (element.sync)
seqManager.Sync(element.input);
if (element.offset)
seqManager.Offset(element.offset);
if (element.drop)
{
seqManager.Drop(element.input);
......@@ -257,4 +262,24 @@ SCENARIO("RTC::SeqManager", "[rtc]")
RTC::SeqManager<uint16_t> seqManager;
validate(seqManager, inputs);
}
SECTION("receive ordered numbers, sync, no drop, increase input")
{
// clang-format off
std::vector<TestSeqManagerInput> inputs =
{
{ 0, 0, false, false },
{ 1, 1, false, false },
{ 2, 2, false, false },
{ 80, 23, true, false, 20 },
{ 81, 24, false, false },
{ 82, 25, false, false },
{ 83, 26, false, false },
{ 84, 27, false, false }
};
// clang-format on
RTC::SeqManager<uint16_t> seqManager;
validate(seqManager, inputs);
}
}
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论