]> git.saurik.com Git - apt.git/blame - test/libapt/strutil_test.cc
add REAMDE.md
[apt.git] / test / libapt / strutil_test.cc
CommitLineData
453b82a3 1#include <config.h>
a513ace2 2#include <apt-pkg/strutl.h>
453b82a3
DK
3#include <string>
4#include <vector>
5
f00832cc 6#include <gtest/gtest.h>
a513ace2 7
f00832cc 8TEST(StrUtilTest,DeEscapeString)
a513ace2 9{
f00832cc
DK
10 // nothing special
11 EXPECT_EQ("", DeEscapeString(""));
12 EXPECT_EQ("foobar", DeEscapeString("foobar"));
a513ace2 13 // hex and octal
f00832cc
DK
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}
22TEST(StrUtilTest,StringSplitBasic)
23{
24 std::vector<std::string> result = StringSplit("", "");
25 EXPECT_EQ(result.size(), 0);
b9dc4706 26
f00832cc
DK
27 result = StringSplit("abc", "");
28 EXPECT_EQ(result.size(), 0);
00f4d9ff 29
f00832cc
DK
30 result = StringSplit("", "abc");
31 EXPECT_EQ(result.size(), 1);
00f4d9ff 32
f00832cc
DK
33 result = StringSplit("abc", "b");
34 ASSERT_EQ(result.size(), 2);
35 EXPECT_EQ(result[0], "a");
36 EXPECT_EQ(result[1], "c");
00f4d9ff 37
f00832cc
DK
38 result = StringSplit("abc", "abc");
39 ASSERT_EQ(result.size(), 2);
40 EXPECT_EQ(result[0], "");
41 EXPECT_EQ(result[1], "");
42}
43TEST(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);
85bf0019 49
2ddab3fb 50 result = StringSplit(input, "");
f00832cc
DK
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}
64TEST(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"));
a513ace2 72}