mirror of
https://github.com/espressif/openthread.git
synced 2026-08-13 22:27:47 +00:00
[channel-mask] update Mac::ChannelMask::ToString() (#6375)
This commit contains a small fix in `Mac::ChannelMask::ToString()`
string output (e.g, return `{ 11-26 }` instead of `{ 11-26}`). This
commit also updates the unit test to follow naming style and verify
the `ToString()` behavior.
This commit is contained in:
@@ -128,7 +128,7 @@ ChannelMask::InfoString ChannelMask::ToString(void) const
|
||||
}
|
||||
}
|
||||
|
||||
IgnoreError(string.Append("}"));
|
||||
IgnoreError(string.Append(" }"));
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
@@ -331,39 +331,48 @@ void VerifyChannelMaskContent(const Mac::ChannelMask &aMask, uint8_t *aChannels,
|
||||
|
||||
void TestMacChannelMask(void)
|
||||
{
|
||||
uint8_t all_channels[] = {11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26};
|
||||
uint8_t channels1[] = {11, 14, 15, 16, 17, 20, 21, 22, 24, 25};
|
||||
uint8_t channels2[] = {14, 21, 26};
|
||||
uint8_t channels3[] = {14, 21};
|
||||
uint8_t channles4[] = {20};
|
||||
uint8_t allChannels[] = {11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26};
|
||||
uint8_t channels1[] = {11, 14, 15, 16, 17, 20, 21, 22, 24, 25};
|
||||
uint8_t channels2[] = {14, 21, 26};
|
||||
uint8_t channels3[] = {14, 21};
|
||||
uint8_t channles4[] = {20};
|
||||
|
||||
static const char kEmptyMaskString[] = "{ }";
|
||||
static const char kAllChannelsString[] = "{ 11-26 }";
|
||||
static const char kChannels1String[] = "{ 11, 14-17, 20-22, 24, 25 }";
|
||||
static const char kChannels2String[] = "{ 14, 21, 26 }";
|
||||
static const char kChannels3String[] = "{ 14, 21 }";
|
||||
static const char kChannels4String[] = "{ 20 }";
|
||||
|
||||
Mac::ChannelMask mask1;
|
||||
Mac::ChannelMask mask2(Radio::kSupportedChannels);
|
||||
|
||||
printf("Testing Mac::ChannelMask\n");
|
||||
|
||||
VerifyOrQuit(mask1.IsEmpty(), "ChannelMask.IsEmpty failed");
|
||||
VerifyOrQuit(mask1.IsEmpty(), "ChannelMask::IsEmpty failed");
|
||||
printf("empty = %s\n", mask1.ToString().AsCString());
|
||||
VerifyOrQuit(strcmp(mask1.ToString().AsCString(), kEmptyMaskString) == 0, "ChannelMask::ToString() failed");
|
||||
|
||||
VerifyOrQuit(!mask2.IsEmpty(), "ChannelMask.IsEmpty failed");
|
||||
VerifyOrQuit(mask2.GetMask() == Radio::kSupportedChannels, "ChannelMask.GetMask() failed");
|
||||
printf("all_channels = %s\n", mask2.ToString().AsCString());
|
||||
VerifyOrQuit(!mask2.IsEmpty(), "ChannelMask::IsEmpty failed");
|
||||
VerifyOrQuit(mask2.GetMask() == Radio::kSupportedChannels, "ChannelMask::GetMask() failed");
|
||||
printf("allChannels = %s\n", mask2.ToString().AsCString());
|
||||
VerifyOrQuit(strcmp(mask2.ToString().AsCString(), kAllChannelsString) == 0, "ChannelMask::ToString() failed");
|
||||
|
||||
mask1.SetMask(Radio::kSupportedChannels);
|
||||
VerifyOrQuit(!mask1.IsEmpty(), "ChannelMask.IsEmpty failed");
|
||||
VerifyOrQuit(mask1.GetMask() == Radio::kSupportedChannels, "ChannelMask.GetMask() failed");
|
||||
VerifyOrQuit(!mask1.IsEmpty(), "ChannelMask::IsEmpty failed");
|
||||
VerifyOrQuit(mask1.GetMask() == Radio::kSupportedChannels, "ChannelMask::GetMask() failed");
|
||||
|
||||
VerifyChannelMaskContent(mask1, all_channels, sizeof(all_channels));
|
||||
VerifyChannelMaskContent(mask1, allChannels, sizeof(allChannels));
|
||||
|
||||
// Test ChannelMask::RemoveChannel()
|
||||
for (uint8_t index = 0; index < sizeof(all_channels) - 1; index++)
|
||||
for (uint8_t index = 0; index < sizeof(allChannels) - 1; index++)
|
||||
{
|
||||
mask1.RemoveChannel(all_channels[index]);
|
||||
VerifyChannelMaskContent(mask1, &all_channels[index + 1], sizeof(all_channels) - 1 - index);
|
||||
mask1.RemoveChannel(allChannels[index]);
|
||||
VerifyChannelMaskContent(mask1, &allChannels[index + 1], sizeof(allChannels) - 1 - index);
|
||||
}
|
||||
|
||||
mask1.Clear();
|
||||
VerifyOrQuit(mask1.IsEmpty(), "ChannelMask.IsEmpty failed");
|
||||
VerifyOrQuit(mask1.IsEmpty(), "ChannelMask::IsEmpty failed");
|
||||
VerifyChannelMaskContent(mask1, nullptr, 0);
|
||||
|
||||
for (uint8_t channel : channels1)
|
||||
@@ -372,8 +381,9 @@ void TestMacChannelMask(void)
|
||||
}
|
||||
|
||||
printf("channels1 = %s\n", mask1.ToString().AsCString());
|
||||
VerifyOrQuit(strcmp(mask1.ToString().AsCString(), kChannels1String) == 0, "ChannelMask::ToString() failed");
|
||||
|
||||
VerifyOrQuit(!mask1.IsEmpty(), "ChannelMask.IsEmpty failed");
|
||||
VerifyOrQuit(!mask1.IsEmpty(), "ChannelMask::IsEmpty failed");
|
||||
VerifyChannelMaskContent(mask1, channels1, sizeof(channels1));
|
||||
|
||||
mask2.Clear();
|
||||
@@ -384,29 +394,33 @@ void TestMacChannelMask(void)
|
||||
}
|
||||
|
||||
printf("channels2 = %s\n", mask2.ToString().AsCString());
|
||||
VerifyOrQuit(strcmp(mask2.ToString().AsCString(), kChannels2String) == 0, "ChannelMask::ToString() failed");
|
||||
|
||||
VerifyOrQuit(!mask2.IsEmpty(), "ChannelMask.IsEmpty failed");
|
||||
VerifyOrQuit(!mask2.IsEmpty(), "ChannelMask::IsEmpty failed");
|
||||
VerifyChannelMaskContent(mask2, channels2, sizeof(channels2));
|
||||
|
||||
mask1.Intersect(mask2);
|
||||
VerifyChannelMaskContent(mask1, channels3, sizeof(channels3));
|
||||
printf("channels3 = %s\n", mask1.ToString().AsCString());
|
||||
VerifyOrQuit(strcmp(mask1.ToString().AsCString(), kChannels3String) == 0, "ChannelMask::ToString() failed");
|
||||
|
||||
mask2.Clear();
|
||||
mask2.AddChannel(channles4[0]);
|
||||
VerifyChannelMaskContent(mask2, channles4, sizeof(channles4));
|
||||
|
||||
printf("channels4 = %s\n", mask2.ToString().AsCString());
|
||||
VerifyOrQuit(strcmp(mask2.ToString().AsCString(), kChannels4String) == 0, "ChannelMask::ToString() failed");
|
||||
|
||||
mask1.Clear();
|
||||
mask2.Clear();
|
||||
VerifyOrQuit(mask1 == mask2, "ChannelMask.operator== failed");
|
||||
VerifyOrQuit(mask1 == mask2, "ChannelMask::operator== failed");
|
||||
|
||||
mask1.SetMask(Radio::kSupportedChannels);
|
||||
mask2.SetMask(Radio::kSupportedChannels);
|
||||
VerifyOrQuit(mask1 == mask2, "ChannelMask.operator== failed");
|
||||
VerifyOrQuit(mask1 == mask2, "ChannelMask::operator== failed");
|
||||
|
||||
mask1.Clear();
|
||||
VerifyOrQuit(mask1 != mask2, "ChannelMask.operator== failed");
|
||||
VerifyOrQuit(mask1 != mask2, "ChannelMask::operator== failed");
|
||||
}
|
||||
|
||||
void TestMacFrameApi(void)
|
||||
|
||||
Reference in New Issue
Block a user