-
Notifications
You must be signed in to change notification settings - Fork 0
/
convention.t.cpp
61 lines (49 loc) · 2.08 KB
/
convention.t.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "ndnph/packet/convention.hpp"
#include "ndnph/packet/name.hpp"
#include "test-common.hpp"
namespace ndnph {
namespace {
TEST(Convention, ImplicitDigest)
{
StaticRegion<1024> region;
Name name(region, { 0x08, 0x01, 0x41, 0x01, 0x00 });
EXPECT_FALSE(name[0].is<convention::ImplicitDigest>());
EXPECT_FALSE(name[1].is<convention::ImplicitDigest>());
std::vector<uint8_t> value(NDNPH_SHA256_LEN);
std::fill(value.begin(), value.end(), 0xA0);
name = name.append(region, convention::ImplicitDigest(), value.data());
EXPECT_EQ(test::toString(name[-1]), "1=%A0%A0%A0%A0%A0%A0%A0%A0%A0%A0%A0%A0%A0%A0%A0%A0"
"%A0%A0%A0%A0%A0%A0%A0%A0%A0%A0%A0%A0%A0%A0%A0%A0");
EXPECT_TRUE(name[-1].is<convention::ImplicitDigest>());
const uint8_t* digest = name[-1].as<convention::ImplicitDigest>();
ASSERT_THAT(digest, g::NotNull());
EXPECT_THAT(std::vector<uint8_t>(digest, digest + NDNPH_SHA256_LEN), g::ElementsAreArray(value));
}
TEST(Convention, Keyword)
{
StaticRegion<1024> region;
Name name(region, { 0x08, 0x01, 0x41, 0x20, 0x00 });
EXPECT_FALSE(name[0].is<convention::Keyword>());
EXPECT_TRUE(name[1].is<convention::Keyword>());
name = name.append(region, convention::Keyword(), "hello", convention::Keyword(), "world");
EXPECT_EQ(test::toString(name[-2]), "32=hello");
EXPECT_TRUE(name[-2].is<convention::Keyword>());
EXPECT_EQ(test::toString(name[-1]), "32=world");
EXPECT_TRUE(name[-1].is<convention::Keyword>());
const char* keyword = name[-2].as<convention::Keyword>(region);
EXPECT_EQ(keyword, std::string("hello"));
}
TEST(Convention, Segment)
{
StaticRegion<1024> region;
Name name(region, { 0x08, 0x01, 0x41, TT::SegmentNameComponent, 0x00 });
EXPECT_FALSE(name[0].is<convention::Segment>());
EXPECT_FALSE(name[1].is<convention::Segment>());
name = name.append(region, convention::Segment(), 700);
EXPECT_EQ(test::toString(name[-1]), "50=%02%BC");
EXPECT_TRUE(name[-1].is<convention::Segment>());
uint64_t segment = name[-1].as<convention::Segment>();
EXPECT_EQ(segment, 700);
}
} // namespace
} // namespace ndnph