add sat::WhatProvides to look for Solvable providing a Capability. (somtimes segfaults).
[platform/upstream/libzypp.git] / tests / media / media4_test.cc
1 #include <zypp/media/MediaManager.h>
2 #include <zypp/base/String.h>
3 #include <zypp/base/Logger.h>
4 #include <zypp/Pathname.h>
5 #include <zypp/PathInfo.h>
6 #include <zypp/TmpPath.h>
7 #include <zypp/ExternalProgram.h>
8
9 #include <string>
10 #include <list>
11 #include <iostream>
12 #include <cstdlib>
13
14 #include <signal.h>
15 #include <stdlib.h>
16 #include <boost/test/unit_test.hpp>
17
18 using boost::unit_test::test_suite;
19 using boost::unit_test::test_case;
20 using namespace zypp;
21 using namespace zypp::media;
22
23 bool       do_step = false;
24 int        do_quit = 0;
25
26 void quit(int)
27 {
28     do_quit = 1;
29 }
30
31 void goon(int)
32 {
33 }
34
35 #define ONE_STEP(MSG) \
36 do { \
37   DBG << "======================================" << std::endl; \
38   DBG << "==>> " << MSG << std::endl; \
39   DBG << "======================================" << std::endl; \
40   if( do_step) { pause(); if( do_quit) exit(0); } \
41 } while(0);
42
43 BOOST_AUTO_TEST_CASE(strange_test)
44 {
45   {
46       struct sigaction sa;
47       sigemptyset(&sa.sa_mask);
48       sa.sa_flags   = 0;
49       sa.sa_handler = goon;
50       sigaction(SIGINT,  &sa, NULL);
51       sa.sa_handler = quit;
52       sigaction(SIGTERM, &sa, NULL);
53
54 //       if( argc > 1 && std::string(argv[1]) == "-i")
55 //         do_step = true;
56   }
57
58   MediaManager     mm;
59   media::MediaId   id;
60   zypp::Url        url;
61   Pathname         dir("./suse/setup/descr");
62
63   url = "cd:/";
64
65   try
66   {
67     ONE_STEP("open " + url.asString());
68     id = mm.open(url);
69
70     ONE_STEP("attach")
71     mm.attach(id);
72
73     ONE_STEP("provideDirTree(" + dir.asString() + ")");
74     mm.provideDirTree(id, Pathname(dir));
75
76     ONE_STEP("Create a temporary dir");
77     zypp::filesystem::TmpDir temp;
78
79     ONE_STEP("Create a copy of " + dir.asString());
80     zypp::filesystem::copy_dir(mm.localPath(id, dir), temp.path());
81
82     std::string cmd("/bin/ls -lR ");
83                 cmd += temp.path().asString();
84
85     ONE_STEP("Check the directory copy")
86     system( cmd.c_str());
87
88     ONE_STEP("CLEANUP")
89   }
90   catch(const MediaException &e)
91   {
92     ZYPP_CAUGHT(e);
93   }
94   catch( ... )
95   {
96     // hmm...
97     ERR << "Catched *unknown* exception" << std::endl;
98   }
99 }
100
101 // vim: set ts=2 sts=2 sw=2 ai et: