]>
Commit | Line | Data |
---|---|---|
453b82a3 DK |
1 | #include <config.h> |
2 | ||
ae2be086 | 3 | #include <apt-pkg/cmndline.h> |
453b82a3 | 4 | #include <apt-pkg/configuration.h> |
ae2be086 | 5 | |
f00832cc DK |
6 | #include <gtest/gtest.h> |
7 | ||
8 | class CLT: public CommandLine { | |
9 | public: | |
10 | std::string static AsString(const char * const * const argv, | |
11 | unsigned int const argc) { | |
12 | std::string const static conf = "Commandline::AsString"; | |
13 | _config->Clear(conf); | |
14 | SaveInConfig(argc, argv); | |
15 | return _config->Find(conf); | |
16 | } | |
17 | }; | |
18 | ||
19 | #define EXPECT_CMD(x, ...) { const char * const argv[] = { __VA_ARGS__ }; EXPECT_EQ(x, CLT::AsString(argv, sizeof(argv)/sizeof(argv[0]))); } | |
20 | ||
21 | TEST(CommandLineTest,SaveInConfig) | |
22 | { | |
23 | EXPECT_CMD("apt-get install -sf", | |
24 | "apt-get", "install", "-sf"); | |
25 | EXPECT_CMD("apt-cache -s apt -so Debug::test=Test", | |
26 | "apt-cache", "-s", "apt", "-so", "Debug::test=Test"); | |
27 | EXPECT_CMD("apt-cache -s apt -so Debug::test=\"Das ist ein Test\"", | |
28 | "apt-cache", "-s", "apt", "-so", "Debug::test=Das ist ein Test"); | |
29 | EXPECT_CMD("apt-cache -s apt --hallo test=1.0", | |
30 | "apt-cache", "-s", "apt", "--hallo", "test=1.0"); | |
31 | } | |
32 | TEST(CommandLineTest,Parsing) | |
ae2be086 DH |
33 | { |
34 | CommandLine::Args Args[] = { | |
35 | { 't', 0, "Test::Worked", 0 }, | |
36 | { 'z', "zero", "Test::Zero", 0 }, | |
37 | {0,0,0,0} | |
38 | }; | |
f00832cc DK |
39 | ::Configuration c; |
40 | CommandLine CmdL(Args, &c); | |
7a6d9076 | 41 | |
ae2be086 DH |
42 | char const * argv[] = { "test", "--zero", "-t" }; |
43 | CmdL.Parse(3 , argv); | |
f00832cc DK |
44 | EXPECT_TRUE(c.FindB("Test::Worked", false)); |
45 | EXPECT_TRUE(c.FindB("Test::Zero", false)); | |
ae2be086 | 46 | |
f00832cc DK |
47 | c.Clear("Test"); |
48 | EXPECT_FALSE(c.FindB("Test::Worked", false)); | |
49 | EXPECT_FALSE(c.FindB("Test::Zero", false)); | |
7a6d9076 | 50 | |
f00832cc DK |
51 | c.Set("Test::Zero", true); |
52 | EXPECT_TRUE(c.FindB("Test::Zero", false)); | |
7a6d9076 DK |
53 | |
54 | char const * argv2[] = { "test", "--no-zero", "-t" }; | |
55 | CmdL.Parse(3 , argv2); | |
f00832cc DK |
56 | EXPECT_TRUE(c.FindB("Test::Worked", false)); |
57 | EXPECT_FALSE(c.FindB("Test::Zero", false)); | |
ae2be086 | 58 | } |