be0f8e87b3b23ea45634f2787fcc3717cab21f1a
[platform/upstream/libzypp.git] / tests / lib / WebServer.h
1
2 #ifndef ZYPP_TEST_WEBSERVER_H
3 #define ZYPP_TEST_WEBSERVER_H
4
5 #include "zypp/Url.h"
6 #include "zypp/Pathname.h"
7 #include "zypp/base/PtrTypes.h"
8
9 /**
10  *
11  * Starts a webserver to simulate remote transfers in
12  * testcases
13  * \author Duncan Mac-Vicar P. <dmacvicar@suse.de>
14  *
15  * \code
16  * #include "WebServer.h"
17  *
18  * BOOST_AUTO_TEST_CASE(Foo)
19  * {
20  *
21  *      WebServer web((Pathname(TESTS_SRC_DIR) + "/datadir").c_str() );
22  *      web.start();
23  *
24  *     MediaSetAccess media( Url("http://localhost:9099"), "/" );
25  *
26  *     // do something with the url
27  *
28  *
29  *     web.stop();
30  *
31  * \endcode
32  */
33 class WebServer
34 {
35  public:
36   /**
37    * creates a web server on \ref root and \port
38    */
39   WebServer(const zypp::Pathname &root, unsigned int port=10001);
40   ~WebServer();
41   /**
42    * Starts the webserver worker thread
43    */
44   void start();
45   /**
46    * Stops the worker thread
47    */
48   void stop();
49
50   /**
51    * returns the port we are listening to
52    */
53   int port() const;
54
55   /**
56    * returns the base url where the webserver is listening
57    */
58   zypp::Url url() const;
59
60   /**
61    * shows the log of last run
62    */
63   std::string log() const;
64
65   class Impl;
66 private:
67   /** Pointer to implementation */
68   zypp::RWCOW_pointer<Impl> _pimpl;
69 };
70
71 #endif