| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "na64util/uri.hh" | ||
| 2 | |||
| 3 | #include <gtest/gtest.h> | ||
| 4 | |||
| 5 | namespace na64dp { | ||
| 6 | namespace test { | ||
| 7 | |||
| 8 | 8 | TEST(URI, EncodeMathesDecodeSimple) { | |
| 9 |
1/1✓ Branch 1 taken 1 times.
|
2 | const std::string sample = " s`oom''\"e %123+17=150 #/#!$ h),),]" |
| 10 |
1/1✓ Branch 1 taken 1 times.
|
2 | , encoded = util::URI::encode(sample) |
| 11 |
1/1✓ Branch 1 taken 1 times.
|
2 | , decoded = util::URI::decode(encoded) |
| 12 | ; | ||
| 13 |
2/3✓ Branch 3 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
|
2 | EXPECT_STREQ(sample.c_str(), decoded.c_str()); |
| 14 | 2 | } | |
| 15 | |||
| 16 | 8 | TEST(URI, CorrectlyParsesFullURI) { | |
| 17 | const std::string sample | ||
| 18 |
1/1✓ Branch 1 taken 1 times.
|
2 | = "https://john.doe@www.example.com:123/forum/questions/?tag=networking&order=newest#top"; |
| 19 |
1/1✓ Branch 1 taken 1 times.
|
2 | util::URI uri(sample); |
| 20 | |||
| 21 |
2/3✓ Branch 3 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
|
2 | EXPECT_STREQ(uri.scheme().c_str(), "https"); |
| 22 |
2/3✓ Branch 3 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
|
2 | EXPECT_STREQ(uri.userinfo().c_str(), "john.doe"); |
| 23 |
2/3✓ Branch 3 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
|
2 | EXPECT_STREQ(uri.host().c_str(), "www.example.com"); |
| 24 |
2/3✓ Branch 3 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
|
2 | EXPECT_STREQ(uri.port().c_str(), "123"); |
| 25 |
2/3✓ Branch 3 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
|
2 | EXPECT_STREQ(uri.path().c_str(), "/forum/questions/"); |
| 26 | //EXPECT_STREQ(uri.query().c_str(), "tag=networking&order=newest"); | ||
| 27 |
2/2✓ Branch 2 taken 1 times.
✓ Branch 5 taken 1 times.
|
4 | auto it1 = uri.query().find("tag"); |
| 28 |
3/5✓ Branch 3 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
✓ Branch 21 taken 1 times.
✗ Branch 22 not taken.
|
2 | ASSERT_NE(it1, uri.query().end()); |
| 29 |
2/3✓ Branch 3 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
|
2 | EXPECT_STREQ(it1->second.c_str(), "networking"); |
| 30 |
2/2✓ Branch 2 taken 1 times.
✓ Branch 5 taken 1 times.
|
4 | auto it2 = uri.query().find("order"); |
| 31 |
3/5✓ Branch 3 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
✓ Branch 21 taken 1 times.
✗ Branch 22 not taken.
|
2 | ASSERT_NE(it2, uri.query().end()); |
| 32 |
2/3✓ Branch 3 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
|
2 | EXPECT_STREQ(it2->second.c_str(), "newest"); |
| 33 |
2/3✓ Branch 3 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
|
2 | EXPECT_STREQ(uri.fragment().c_str(), "top"); |
| 34 | |||
| 35 |
3/4✓ Branch 1 taken 1 times.
✓ Branch 5 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
|
2 | EXPECT_STREQ(uri.authority().c_str(), "john.doe@www.example.com:123"); |
| 36 | |||
| 37 | //EXPECT_STREQ(sample.c_str(), uri.to_str().c_str()); // TODO: query string may differ (unordered map) | ||
| 38 | 2 | } | |
| 39 | |||
| 40 | 8 | TEST(URI, CorrectlyHandlesSimplePath) { | |
| 41 | const std::string sample | ||
| 42 |
1/1✓ Branch 1 taken 1 times.
|
2 | = "/foo/bar/../one\\ two/.././/"; |
| 43 |
1/1✓ Branch 1 taken 1 times.
|
2 | util::URI uri(sample); |
| 44 | |||
| 45 |
1/2✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
|
2 | EXPECT_TRUE(uri.scheme().empty()); |
| 46 |
1/2✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
|
2 | EXPECT_TRUE(uri.userinfo().empty()); |
| 47 |
1/2✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
|
2 | EXPECT_TRUE(uri.host().empty()); |
| 48 |
1/2✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
|
2 | EXPECT_TRUE(uri.port().empty()); |
| 49 |
2/3✓ Branch 4 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
|
2 | EXPECT_STREQ(uri.path().c_str(), sample.c_str()); |
| 50 |
1/2✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
|
2 | EXPECT_TRUE(uri.query().empty()); |
| 51 |
1/2✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
|
2 | EXPECT_TRUE(uri.fragment().empty()); |
| 52 | |||
| 53 |
2/3✓ Branch 1 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
|
2 | EXPECT_TRUE(uri.authority().empty()); |
| 54 | |||
| 55 |
3/4✓ Branch 1 taken 1 times.
✓ Branch 6 taken 1 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 times.
|
2 | EXPECT_STREQ(sample.c_str(), uri.to_str().c_str()); |
| 56 | 2 | } | |
| 57 | |||
| 58 | } | ||
| 59 | } | ||
| 60 | |||
| 61 |