aboutsummaryrefslogtreecommitdiffstats
path: root/libtransport/src/test/test_interest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'libtransport/src/test/test_interest.cc')
-rw-r--r--libtransport/src/test/test_interest.cc96
1 files changed, 71 insertions, 25 deletions
diff --git a/libtransport/src/test/test_interest.cc b/libtransport/src/test/test_interest.cc
index 8853563b0..22dc01455 100644
--- a/libtransport/src/test/test_interest.cc
+++ b/libtransport/src/test/test_interest.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Copyright (c) 2021-2022 Cisco and/or its affiliates.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
@@ -30,7 +30,8 @@ namespace {
// The fixture for testing class Foo.
class InterestTest : public ::testing::Test {
protected:
- InterestTest() : name_("b001::123|321"), interest_() {
+ InterestTest()
+ : name_("b001::123|321"), interest_(HICN_PACKET_FORMAT_IPV6_TCP) {
// You can do set-up work for each test here.
}
@@ -63,15 +64,18 @@ class InterestTest : public ::testing::Test {
PAYLOAD};
};
-void testFormatConstructor(Packet::Format format = HF_UNSPEC) {
+void testFormatConstructor(
+ hicn_packet_format_t format = HICN_PACKET_FORMAT_NONE) {
try {
Interest interest(format, 0);
} catch (...) {
- FAIL() << "ERROR: Unexpected exception thrown for " << format;
+ char buf[MAXSZ_HICN_PACKET_FORMAT];
+ FAIL() << "ERROR: Unexpected exception thrown for " << buf;
}
}
-void testFormatConstructorException(Packet::Format format = HF_UNSPEC) {
+void testFormatConstructorException(
+ Packet::Format format = HICN_PACKET_FORMAT_NONE) {
try {
Interest interest(format, 0);
FAIL() << "We expected an exception here";
@@ -86,29 +90,29 @@ void testFormatConstructorException(Packet::Format format = HF_UNSPEC) {
TEST_F(InterestTest, ConstructorWithFormat) {
/**
- * Without arguments it should be format = HF_UNSPEC.
+ * Without arguments it should be format = HICN_PACKET_FORMAT_NONE.
* We expect a crash.
*/
- testFormatConstructor(Packet::Format::HF_INET_TCP);
- testFormatConstructor(Packet::Format::HF_INET6_TCP);
- testFormatConstructorException(Packet::Format::HF_INET_ICMP);
- testFormatConstructorException(Packet::Format::HF_INET6_ICMP);
- testFormatConstructor(Packet::Format::HF_INET_TCP_AH);
- testFormatConstructor(Packet::Format::HF_INET6_TCP_AH);
- testFormatConstructorException(Packet::Format::HF_INET_ICMP_AH);
- testFormatConstructorException(Packet::Format::HF_INET6_ICMP_AH);
+ testFormatConstructor(HICN_PACKET_FORMAT_IPV4_TCP);
+ testFormatConstructor(HICN_PACKET_FORMAT_IPV6_TCP);
+ testFormatConstructorException(HICN_PACKET_FORMAT_IPV4_ICMP);
+ testFormatConstructorException(HICN_PACKET_FORMAT_IPV6_ICMP);
+ testFormatConstructor(HICN_PACKET_FORMAT_IPV4_TCP_AH);
+ testFormatConstructor(HICN_PACKET_FORMAT_IPV6_TCP_AH);
+ testFormatConstructorException(HICN_PACKET_FORMAT_IPV4_ICMP_AH);
+ testFormatConstructorException(HICN_PACKET_FORMAT_IPV6_ICMP_AH);
}
TEST_F(InterestTest, ConstructorWithName) {
/**
- * Without arguments it should be format = HF_UNSPEC.
+ * Without arguments it should be format = HICN_PACKET_FORMAT_NONE.
* We expect a crash.
*/
Name n("b001::1|123");
try {
- Interest interest(n);
+ Interest interest(HICN_PACKET_FORMAT_IPV6_TCP, n);
} catch (...) {
FAIL() << "ERROR: Unexpected exception thrown";
}
@@ -116,8 +120,10 @@ TEST_F(InterestTest, ConstructorWithName) {
TEST_F(InterestTest, ConstructorWithBuffer) {
// Ensure buffer is interest
+#if 0
auto ret = Interest::isInterest(&buffer_[0]);
EXPECT_TRUE(ret);
+#endif
// Create interest from buffer
try {
@@ -175,28 +181,28 @@ TEST_F(InterestTest, SetGetLocator) {
// Get locator
auto l = interest.getLocator();
- ip_address_t address;
- ip_address_pton("b006::ab:cdab:cdef", &address);
- auto ret = !std::memcmp(&l, &address, sizeof(address));
+ hicn_ip_address_t address;
+ inet_pton(AF_INET6, "b006::ab:cdab:cdef", &address);
+ auto ret = !hicn_ip_address_cmp(&l, &address);
EXPECT_TRUE(ret);
// Set different locator
- ip_address_pton("2001::1234::4321::abcd::", &address);
+ inet_pton(AF_INET6, "2001::1234::4321::abcd::", &address);
// Set it on interest
interest.setLocator(address);
// Check it was set
l = interest.getLocator();
- ret = !std::memcmp(&l, &address, sizeof(address));
+ ret = !hicn_ip_address_cmp(&l, &address);
EXPECT_TRUE(ret);
}
TEST_F(InterestTest, SetGetLifetime) {
// Create interest from buffer
- Interest interest;
+ Interest interest(HICN_PACKET_FORMAT_IPV6_TCP);
const constexpr uint32_t lifetime = 10000;
// Set lifetime
@@ -211,7 +217,7 @@ TEST_F(InterestTest, SetGetLifetime) {
TEST_F(InterestTest, HasManifest) {
// Create interest from buffer
- Interest interest;
+ Interest interest(HICN_PACKET_FORMAT_IPV6_TCP);
// Let's expect anexception here
try {
@@ -232,7 +238,7 @@ TEST_F(InterestTest, HasManifest) {
TEST_F(InterestTest, AppendSuffixesEncodeAndIterate) {
// Create interest from buffer
- Interest interest;
+ Interest interest(HICN_PACKET_FORMAT_IPV6_TCP);
// Appenad some suffixes, with some duplicates
interest.appendSuffix(1);
@@ -250,13 +256,53 @@ TEST_F(InterestTest, AppendSuffixesEncodeAndIterate) {
interest.encodeSuffixes();
// Iterate over them. They should be in order and without repetitions
+
auto suffix = interest.firstSuffix();
auto n_suffixes = interest.numberOfSuffixes();
for (uint32_t i = 0; i < n_suffixes; i++) {
- EXPECT_EQ(*(suffix + i), (i + 1));
+ EXPECT_EQ(*(suffix + i), i);
}
}
+TEST_F(InterestTest, AppendSuffixesWithGaps) {
+ // Create interest from buffer
+ Interest interest(HICN_PACKET_FORMAT_IPV6_TCP);
+
+ // Appenad some suffixes, out of order and with gaps
+ interest.appendSuffix(6);
+ interest.appendSuffix(2);
+ interest.appendSuffix(5);
+ interest.appendSuffix(1);
+
+ // Encode them in wire format
+ interest.encodeSuffixes();
+ EXPECT_TRUE(interest.hasManifest());
+
+ // Check first suffix correctness
+ auto suffix = interest.firstSuffix();
+ EXPECT_NE(suffix, nullptr);
+ EXPECT_EQ(*suffix, 0U);
+
+ // Iterate over them. They should be in order and without repetitions
+ std::vector<uint32_t> expected = {interest.getName().getSuffix(), 1, 2, 5, 6};
+ EXPECT_EQ(interest.numberOfSuffixes(), expected.size());
+
+ for (uint32_t seq : expected) {
+ EXPECT_EQ(*suffix, seq);
+ suffix++;
+ }
+}
+
+TEST_F(InterestTest, InterestWithoutManifest) {
+ // Create interest without manifest
+ Interest interest(HICN_PACKET_FORMAT_IPV6_TCP);
+ auto suffix = interest.firstSuffix();
+
+ EXPECT_FALSE(interest.hasManifest());
+ EXPECT_EQ(interest.numberOfSuffixes(), 0U);
+ EXPECT_EQ(suffix, nullptr);
+}
+
} // namespace core
} // namespace transport