Imported Upstream version 17.22.1
[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 #include <boost/test/unit_test.hpp>
18
19 using boost::unit_test::test_suite;
20 using boost::unit_test::test_case;
21 using namespace zypp;
22 using namespace zypp::media;
23
24 bool       do_step = false;
25 int        do_quit = 0;
26
27 void quit(int)
28 {
29     do_quit = 1;
30 }
31
32 void goon(int)
33 {
34 }
35
36 #define ONE_STEP(MSG) \
37 do { \
38   DBG << "======================================" << std::endl; \
39   DBG << "==>> " << MSG << std::endl; \
40   DBG << "======================================" << std::endl; \
41   if( do_step) { pause(); if( do_quit) exit(0); } \
42 } while(0);
43
44 BOOST_AUTO_TEST_CASE(strange_test)
45 {
46   {
47       struct sigaction sa;
48       sigemptyset(&sa.sa_mask);
49       sa.sa_flags   = 0;
50       sa.sa_handler = goon;
51       sigaction(SIGINT,  &sa, NULL);
52       sa.sa_handler = quit;
53       sigaction(SIGTERM, &sa, NULL);
54
55 //       if( argc > 1 && std::string(argv[1]) == "-i")
56 //         do_step = true;
57   }
58
59   MediaManager     mm;
60   media::MediaId   id;
61   zypp::Url        url;
62   Pathname         dir("./suse/setup/descr");
63
64   url = "cd:/";
65
66   try
67   {
68     ONE_STEP("open " + url.asString());
69     id = mm.open(url);
70
71     ONE_STEP("attach")
72     mm.attach(id);
73
74     ONE_STEP("provideDirTree(" + dir.asString() + ")");
75     mm.provideDirTree(id, Pathname(dir));
76
77     ONE_STEP("Create a temporary dir");
78     zypp::filesystem::TmpDir temp;
79
80     ONE_STEP("Create a copy of " + dir.asString());
81     zypp::filesystem::copy_dir(mm.localPath(id, dir), temp.path());
82
83     std::string cmd("/bin/ls -lR ");
84                 cmd += temp.path().asString();
85
86     ONE_STEP("Check the directory copy")
87     system( cmd.c_str());
88
89     ONE_STEP("CLEANUP")
90   }
91   catch(const MediaException &e)
92   {
93     ZYPP_CAUGHT(e);
94   }
95   catch( ... )
96   {
97     // hmm...
98     ERR << "Catched *unknown* exception" << std::endl;
99   }
100 }
101
102 // vim: set ts=2 sts=2 sw=2 ai et: