]> git.saurik.com Git - apt.git/blob - test/libapt/commandline_test.cc
Merge remote-tracking branch 'donkult/debian/sid' into debian/experimental
[apt.git] / test / libapt / commandline_test.cc
1 #include <config.h>
2
3 #include <apt-pkg/cmndline.h>
4 #include <apt-pkg/configuration.h>
5
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)
33 {
34 CommandLine::Args Args[] = {
35 { 't', 0, "Test::Worked", 0 },
36 { 'z', "zero", "Test::Zero", 0 },
37 {0,0,0,0}
38 };
39 ::Configuration c;
40 CommandLine CmdL(Args, &c);
41
42 char const * argv[] = { "test", "--zero", "-t" };
43 CmdL.Parse(3 , argv);
44 EXPECT_TRUE(c.FindB("Test::Worked", false));
45 EXPECT_TRUE(c.FindB("Test::Zero", false));
46
47 c.Clear("Test");
48 EXPECT_FALSE(c.FindB("Test::Worked", false));
49 EXPECT_FALSE(c.FindB("Test::Zero", false));
50
51 c.Set("Test::Zero", true);
52 EXPECT_TRUE(c.FindB("Test::Zero", false));
53
54 char const * argv2[] = { "test", "--no-zero", "-t" };
55 CmdL.Parse(3 , argv2);
56 EXPECT_TRUE(c.FindB("Test::Worked", false));
57 EXPECT_FALSE(c.FindB("Test::Zero", false));
58 }