add sat::WhatProvides to look for Solvable providing a Capability. (somtimes segfaults).
[platform/upstream/libzypp.git] / tests / media / media3_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
6 #include <string>
7 #include <list>
8 #include <iostream>
9 #include <cstdlib>
10
11 #include <signal.h>
12
13 #include "mymediaverifier.h"
14
15 #include <boost/test/unit_test.hpp>
16
17 using boost::unit_test::test_suite;
18 using boost::unit_test::test_case;
19
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   bool eject_src = false;
46   bool close_src = false;
47   {
48       struct sigaction sa;
49       sigemptyset(&sa.sa_mask);
50       sa.sa_flags   = 0;
51       sa.sa_handler = goon;
52       sigaction(SIGINT,  &sa, NULL);
53       sa.sa_handler = quit;
54       sigaction(SIGTERM, &sa, NULL);
55
56 //       std::cerr << "ARGS=" << argc << std::endl;
57 //       for(int i=1; i < argc; i++)
58 //       {
59 //         if( std::string(argv[i]) == "-i")
60 //           do_step = true;
61 //         else
62 //         if( std::string(argv[i]) == "-e")
63 //           eject_src = true;
64 //         else
65 //         if( std::string(argv[i]) == "-c")
66 //           close_src = true;
67 //       }
68   }
69
70   MediaVerifierRef verifier(
71     new MyMediaVerifier(/* "SUSE-Linux-CORE-i386 9" */)
72   );
73   MediaManager     mm;
74   media::MediaId   src = 0;
75   media::MediaId   iso;
76   zypp::Url        src_url;
77   zypp::Url        iso_url;
78
79   src_url = "nfs://dist.suse.de/dist/install";
80
81   iso_url = "iso:/";
82   iso_url.setQueryParam("iso", "SUSE-10.1-Beta5/SUSE-Linux-10.1-beta5-i386-CD1.iso");
83   iso_url.setQueryParam("url", src_url.asString());
84
85 /*
86   iso_url = "iso:/";
87   iso_url.setQueryParam("iso", "/space/tmp/iso/SUSE-Linux-10.1-beta7-i386-CD1.iso");
88 */
89
90   try
91   {
92     if( eject_src || close_src)
93     {
94       ONE_STEP("SRC: open " + src_url.asString());
95       src = mm.open(src_url);
96
97       ONE_STEP("SRC: attach")
98       mm.attach(src);
99     }
100
101     ONE_STEP("ISO: open " + iso_url.asString());
102     iso = mm.open(iso_url);
103
104     ONE_STEP("ISO: add verifier")
105     mm.addVerifier(iso, verifier);
106
107     ONE_STEP("ISO: attach")
108     mm.attach(iso);
109
110     ONE_STEP("provideFile(/INDEX.gz)")
111     mm.provideFile(iso, Pathname("/INDEX.gz"));
112
113     if( eject_src)
114     {
115       try
116       {
117         ONE_STEP("SRC: release(eject=true)")
118         mm.release(src, true);
119       }
120       catch(const MediaException &e)
121       {
122         ZYPP_CAUGHT(e);
123         ERR << "ONE: HUH? Eject hasn't worked?!" << std::endl;
124       }
125     }
126     else
127     if( close_src)
128     {
129       try
130       {
131         ONE_STEP("SRC: close()")
132         mm.close(src);
133       }
134       catch(const MediaException &e)
135       {
136         ZYPP_CAUGHT(e);
137         ERR << "SRC: HUH? Close hasn't worked?!" << std::endl;
138       }
139     }
140
141     ONE_STEP("ISO: RELEASE")
142     mm.release(iso);
143
144     ONE_STEP("CLEANUP")
145   }
146   catch(const MediaException &e)
147   {
148     ERR << "Catched media exception..." << std::endl;
149     ZYPP_CAUGHT(e);
150   }
151   catch( ... )
152   {
153     // hmm...
154     ERR << "Catched *unknown* exception" << std::endl;
155   }
156 }
157
158 // vim: set ts=2 sts=2 sw=2 ai et: