]>
Commit | Line | Data |
---|---|---|
1 | #include <config.h> | |
2 | #include <apt-pkg/strutl.h> | |
3 | #include <string> | |
4 | #include <vector> | |
5 | ||
6 | #include <gtest/gtest.h> | |
7 | ||
8 | TEST(StrUtilTest,DeEscapeString) | |
9 | { | |
10 | // nothing special | |
11 | EXPECT_EQ("", DeEscapeString("")); | |
12 | EXPECT_EQ("foobar", DeEscapeString("foobar")); | |
13 | // hex and octal | |
14 | EXPECT_EQ("foo bar\nbaz", DeEscapeString("foo\\040bar\\x0abaz")); | |
15 | EXPECT_EQ("foo ", DeEscapeString("foo\\040")); | |
16 | EXPECT_EQ("\nbaz", DeEscapeString("\\x0abaz")); | |
17 | EXPECT_EQ("/media/Ubuntu 11.04 amd64", DeEscapeString("/media/Ubuntu\\04011.04\\040amd64")); | |
18 | // double slashes | |
19 | EXPECT_EQ("foo\\ x", DeEscapeString("foo\\\\ x")); | |
20 | EXPECT_EQ("\\foo\\", DeEscapeString("\\\\foo\\\\")); | |
21 | } | |
22 | TEST(StrUtilTest,StringSplitBasic) | |
23 | { | |
24 | std::vector<std::string> result = StringSplit("", ""); | |
25 | EXPECT_EQ(result.size(), 0); | |
26 | ||
27 | result = StringSplit("abc", ""); | |
28 | EXPECT_EQ(result.size(), 0); | |
29 | ||
30 | result = StringSplit("", "abc"); | |
31 | EXPECT_EQ(result.size(), 1); | |
32 | ||
33 | result = StringSplit("abc", "b"); | |
34 | ASSERT_EQ(result.size(), 2); | |
35 | EXPECT_EQ(result[0], "a"); | |
36 | EXPECT_EQ(result[1], "c"); | |
37 | ||
38 | result = StringSplit("abc", "abc"); | |
39 | ASSERT_EQ(result.size(), 2); | |
40 | EXPECT_EQ(result[0], ""); | |
41 | EXPECT_EQ(result[1], ""); | |
42 | } | |
43 | TEST(StrUtilTest,StringSplitDpkgStatus) | |
44 | { | |
45 | std::string const input = "status: libnet1:amd64: unpacked"; | |
46 | std::vector<std::string> result = StringSplit(input, "xxx"); | |
47 | ASSERT_EQ(result.size(), 1); | |
48 | EXPECT_EQ(result[0], input); | |
49 | ||
50 | result = StringSplit(input, ""); | |
51 | EXPECT_EQ(result.size(), 0); | |
52 | ||
53 | result = StringSplit(input, ": "); | |
54 | ASSERT_EQ(result.size(), 3); | |
55 | EXPECT_EQ(result[0], "status"); | |
56 | EXPECT_EQ(result[1], "libnet1:amd64"); | |
57 | EXPECT_EQ(result[2], "unpacked"); | |
58 | ||
59 | result = StringSplit("x:y:z", ":", 2); | |
60 | ASSERT_EQ(result.size(), 2); | |
61 | EXPECT_EQ(result[0], "x"); | |
62 | EXPECT_EQ(result[1], "y:z"); | |
63 | } | |
64 | TEST(StrUtilTest,EndsWith) | |
65 | { | |
66 | using APT::String::Endswith; | |
67 | EXPECT_TRUE(Endswith("abcd", "d")); | |
68 | EXPECT_TRUE(Endswith("abcd", "cd")); | |
69 | EXPECT_TRUE(Endswith("abcd", "abcd")); | |
70 | EXPECT_FALSE(Endswith("abcd", "x")); | |
71 | EXPECT_FALSE(Endswith("abcd", "abcndefg")); | |
72 | } |