]> git.saurik.com Git - apt.git/blame - test/libapt/parsedepends_test.cc
merged from lp:~donkult/apt/sid
[apt.git] / test / libapt / parsedepends_test.cc
CommitLineData
41c81fd8
DK
1#include <apt-pkg/deblistparser.h>
2#include <apt-pkg/configuration.h>
3
4#include "assert.h"
5
6int main(int argc,char *argv[]) {
7 string Package;
8 string Version;
9 unsigned int Op = 5;
10 unsigned int Null = 0;
11 bool StripMultiArch = true;
12 bool ParseArchFlags = false;
13 _config->Set("APT::Architecture","dsk");
14
15 const char* Depends =
16 "debhelper:any (>= 5.0), "
17 "libdb-dev:any, "
18 "gettext:native (<= 0.12), "
19 "libcurl4-gnutls-dev:native | libcurl3-gnutls-dev (>> 7.15.5), "
20 "debiandoc-sgml, "
21 "apt (>= 0.7.25), "
22 "not-for-me [ !dsk ], "
23 "only-for-me [ dsk ], "
24 "overlord-dev:any (= 7.15.3~) | overlord-dev:native (>> 7.15.5), "
25 ;
26
27 unsigned short runner = 0;
28test:
29// std::clog << (StripMultiArch ? "NO-Multi" : "Multi") << " " << (ParseArchFlags ? "Flags" : "NO-Flags") << std::endl;
30
31 // Stripping MultiArch is currently the default setting to not confuse
32 // non-MultiArch capable users of the library with "strange" extensions.
33 const char* Start = Depends;
34 const char* End = Depends + strlen(Depends);
35
36 Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch);
37 if (StripMultiArch == true)
38 equals("debhelper", Package);
39 else
40 equals("debhelper:any", Package);
41 equals("5.0", Version);
42 equals(Null | pkgCache::Dep::GreaterEq, Op);
43
44 Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch);
45 if (StripMultiArch == true)
46 equals("libdb-dev", Package);
47 else
48 equals("libdb-dev:any", Package);
49 equals("", Version);
50 equals(Null | pkgCache::Dep::NoOp, Op);
51
52 Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch);
53 if (StripMultiArch == true)
54 equals("gettext", Package);
55 else
56 equals("gettext:native", Package);
57 equals("0.12", Version);
58 equals(Null | pkgCache::Dep::LessEq, Op);
59
60 Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch);
61 if (StripMultiArch == true)
62 equals("libcurl4-gnutls-dev", Package);
63 else
64 equals("libcurl4-gnutls-dev:native", Package);
65 equals("", Version);
66 equals(Null | pkgCache::Dep::Or, Op);
67
68 Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch);
69 equals("libcurl3-gnutls-dev", Package);
70 equals("7.15.5", Version);
71 equals(Null | pkgCache::Dep::Greater, Op);
72
73 Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch);
74 equals("debiandoc-sgml", Package);
75 equals("", Version);
76 equals(Null | pkgCache::Dep::NoOp, Op);
77
78 Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch);
79 equals("apt", Package);
80 equals("0.7.25", Version);
81 equals(Null | pkgCache::Dep::GreaterEq, Op);
82
83 if (ParseArchFlags == true) {
84 Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch);
85 equals("", Package); // not-for-me
86 } else {
87 equals(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch));
88 Start = strstr(Start, ",");
89 Start++;
90 }
91
92 if (ParseArchFlags == true) {
93 Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch);
94 equals("only-for-me", Package);
95 equals("", Version);
96 equals(Null | pkgCache::Dep::NoOp, Op);
97 } else {
98 equals(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch));
99 Start = strstr(Start, ",");
100 Start++;
101 }
102
103 Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch);
104 if (StripMultiArch == true)
105 equals("overlord-dev", Package);
106 else
107 equals("overlord-dev:any", Package);
108 equals("7.15.3~", Version);
109 equals(Null | pkgCache::Dep::Equals | pkgCache::Dep::Or, Op);
110
111 Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch);
112 if (StripMultiArch == true)
113 equals("overlord-dev", Package);
114 else
115 equals("overlord-dev:native", Package);
116 equals("7.15.5", Version);
117 equals(Null | pkgCache::Dep::Greater, Op);
118
119 if (StripMultiArch == false)
120 ParseArchFlags = true;
121 StripMultiArch = !StripMultiArch;
122
123 runner++;
124 if (runner < 4)
125 goto test; // this is the prove: tests are really evil ;)
126
127 return 0;
128}