File: Search_104_test.cc

package info (click to toggle)
zypper 1.14.95-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 28,564 kB
  • sloc: cpp: 27,591; sh: 718; perl: 133; xml: 109; python: 39; makefile: 14
file content (69 lines) | stat: -rw-r--r-- 2,469 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <tests/lib/TestSetup.h>
#include "commands/search/search.h"
#include "commands/query.h"

using namespace zypp;

extern ZYpp::Ptr God;
static TestSetup test( TestSetup::initLater );
struct TestInit {
  TestInit() {
    test = TestSetup( Arch_x86_64 );
    zypp::base::LogControl::instance().logfile( "./zypper_test.log" );
    try
    {
      God = zypp::getZYpp();
    }
    catch ( const ZYppFactoryException & excpt_r )
    {
      ZYPP_CAUGHT (excpt_r);
      cerr <<
        "Could not access the package manager engine."
        " This usually happens when you have another application (like YaST)"
        " using it at the same time. Close the other applications and try again.";
    }
    catch ( const Exception & excpt_r)
    {
      ZYPP_CAUGHT (excpt_r);
      cerr << excpt_r.msg() << endl;
    }

    test.loadRepo(TESTS_SRC_DIR "/data/openSUSE-11.1", "main");

  }
  ~TestInit() { test.reset(); }
};
BOOST_GLOBAL_FIXTURE( TestInit );

void runSearch( ZypperBaseCommand & cmd, const std::vector<std::string> & positionalArgs, int exitInfoExpect, int exitInfoPre = 0 )
{
  Zypper::instance().clearExitInfoCode();  // The only way to reset! setExitInfoCode remembers the fist code set.
  if ( exitInfoPre )
    Zypper::instance().setExitInfoCode( exitInfoPre );
  cmd.setPositionalArguments( positionalArgs );
  int res = cmd.run( Zypper::instance() );
  BOOST_CHECK_EQUAL( res, 0 );
  BOOST_CHECK_EQUAL( Zypper::instance().exitCode(), 0 );
  BOOST_CHECK_EQUAL( Zypper::instance().exitInfoCode(), exitInfoExpect );
}
void runBasiccSearchTest( ZypperBaseCommand && cmd )
{
  Zypper & zypper { Zypper::instance() };
  zypper.configNoConst().ignore_unknown = false;
  runSearch( cmd, { "nomatch" },           104 );
  runSearch( cmd, { "nomatch", "zypper" }, 0 );         // 104 only if the complete search is empty
  runSearch( cmd, { "nomatch" },           106, 106 );  // a previously set exitinfoCode overrules any other
  runSearch( cmd, { "nomatch", "zypper" }, 106, 106 );
  zypper.configNoConst().ignore_unknown = true;         // --ignore-unknown turns 104 into 0
  runSearch( cmd, { "nomatch" },           0 );
  runSearch( cmd, { "nomatch", "zypper" }, 0 );
  runSearch( cmd, { "nomatch" },           106, 106 );
  runSearch( cmd, { "nomatch", "zypper" }, 106, 106 );
}

BOOST_AUTO_TEST_CASE( basic )
{
  // search/info should behave similar
  runBasiccSearchTest( SearchCmd({ "search" }) );
  runBasiccSearchTest( InfoCmd({ "info" }) );
}