Fixed Capabilites iterator exposing prereq marker.
[platform/upstream/libzypp.git] / tests / zypp / Capabilities_test.cc
1 // Capabilities.cc
2 //
3 // tests for Capabilities
4 //
5 #include <iostream>
6 #include <string>
7
8 // Boost.Test
9 #include <boost/test/floating_point_comparison.hpp>
10 #include <boost/test/auto_unit_test.hpp>
11
12 #include "zypp/Capability.h"
13 #include "zypp/Capabilities.h"
14
15 using boost::unit_test::test_suite;
16 using boost::unit_test::test_case;
17 using boost::test_tools::close_at_tolerance;
18
19 using namespace std;
20 using namespace zypp;
21
22 BOOST_AUTO_TEST_CASE(capabilities_test)
23 {
24 //     Resolvable::Kind kind = ResTraits<zypp::Package>::kind;
25 //     CapFactory factory;
26 //
27 //     Edition edition ("1.0", "42");
28 //     Capability cap = factory.parse ( kind, "foo", "=", "1.0-42");
29 //     BOOST_CHECK_EQUAL( cap.asString(), "foo == 1.0-42" );
30 //     BOOST_CHECK_EQUAL( cap.index(), "foo");
31 //     BOOST_CHECK_EQUAL( cap.op(), Rel::EQ);
32 //     BOOST_CHECK_EQUAL( cap.edition(), edition);
33 //
34 //     Capability cap2 = factory.parse ( kind, "foo", Rel::EQ, edition);
35 //     BOOST_CHECK_EQUAL( cap2.index(), cap.index());
36 //     BOOST_CHECK_EQUAL( cap2.op(), cap.op());
37 //     BOOST_CHECK_EQUAL( cap2.edition(), cap.edition());
38 //
39 //     Capability cap3 = factory.parse ( kind, "foo = 1.0-42");
40 //     BOOST_CHECK_EQUAL( cap3.index(), cap.index());
41 //     BOOST_CHECK_EQUAL( cap3.op(), cap.op());
42 //     BOOST_CHECK_EQUAL( cap3.edition(), cap.edition());
43 //
44 //     Capability cap6 = factory.parse ( kind, "kdelibs* > 1.5");
45 //     BOOST_CHECK_EQUAL( cap6.index(), "kdelibs*");
46 //     BOOST_CHECK_EQUAL( cap6.op(), Rel::GT);
47 //     BOOST_CHECK_EQUAL( cap6.edition(), Edition("1.5"));
48 //
49 //
50 //     string bash = "/bin/bash";
51 //     Capability cap4 = factory.parse ( kind, bash);
52 //     BOOST_CHECK_EQUAL(cap4.index(), bash);
53 //     BOOST_CHECK_EQUAL(cap4.op(), Rel::NONE);
54 //     BOOST_CHECK_EQUAL(cap4.edition(), Edition::noedition);
55 //
56 //     string hal = "hal(smp)";
57 //     Capability cap5 = factory.parse ( kind, hal);
58 //     BOOST_CHECK_EQUAL(cap5.index(), "hal()");
59 //     BOOST_CHECK_EQUAL(cap5.op(), Rel::NONE);
60 //     BOOST_CHECK_EQUAL(cap5.edition(), Edition::noedition);
61
62   Capability c0( 0 ); // id 0
63   Capability c1( 1 ); // id 1
64   Capability cD;      // default constructed empty
65   Capability cE( "" );// empty
66
67   BOOST_CHECK_EQUAL( c0.id(), 0 );
68   BOOST_CHECK_EQUAL( c1.id(), 1 );
69   BOOST_CHECK_EQUAL( Capability().id(), 1 );   // default constructed empty
70   BOOST_CHECK_EQUAL( Capability("").id(), 1 ); // empty
71
72   BOOST_CHECK_EQUAL( c0.asString(), "" );
73   BOOST_CHECK_EQUAL( c1.asString(), "" );
74
75   BOOST_CHECK_EQUAL( c0.empty(), true );
76   BOOST_CHECK_EQUAL( c1.empty(), true );
77
78   BOOST_CHECK_EQUAL( c0.detail().kind(), CapDetail::NOCAP );
79   BOOST_CHECK_EQUAL( c1.detail().kind(), CapDetail::NOCAP );
80
81   BOOST_CHECK_EQUAL( ( c0 == c1 ), false );
82   BOOST_CHECK_EQUAL( Capability::matches( c0, c1 ), CapMatch::yes );
83
84
85   Capability r( "req" );
86   Capability p( "prereq" );
87
88   sat::detail::IdType caps[10];
89   caps[0] = r.id();
90   caps[1] = sat::detail::solvablePrereqMarker;
91   caps[2] = p.id();
92   caps[3] = 0;
93
94   // Capabilities with and without prereq (skip marker in ++)
95   Capabilities c( caps );
96   cout << c << endl;
97   BOOST_CHECK_EQUAL( c.size(), 2 );
98   Capabilities::const_iterator it( c.begin() );
99   BOOST_CHECK_EQUAL( *it, r );
100   BOOST_CHECK_EQUAL( it.tagged(), false );
101   ++it;
102   BOOST_CHECK_EQUAL( *it, p );
103   BOOST_CHECK_EQUAL( it.tagged(), true );
104
105   // Capabilities with prereq only (skip marker in ctor)
106   c = Capabilities( caps+1 );
107   cout << c << endl;
108   BOOST_CHECK_EQUAL( c.size(), 1 );
109   it = c.begin();
110   BOOST_CHECK_EQUAL( *it, p );
111   BOOST_CHECK_EQUAL( it.tagged(), true );
112
113 }
114