1 : // Copyright 2014 Google Inc. All Rights Reserved.
2 : //
3 : // Licensed under the Apache License, Version 2.0 (the "License");
4 : // you may not use this file except in compliance with the License.
5 : // You may obtain a copy of the License at
6 : //
7 : // http://www.apache.org/licenses/LICENSE-2.0
8 : //
9 : // Unless required by applicable law or agreed to in writing, software
10 : // distributed under the License is distributed on an "AS IS" BASIS,
11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : // See the License for the specific language governing permissions and
13 : // limitations under the License.
14 :
15 : #ifndef SYZYGY_KASKO_TESTING_TEST_SERVER_H_
16 : #define SYZYGY_KASKO_TESTING_TEST_SERVER_H_
17 :
18 : #include <stdint.h>
19 :
20 : #include "base/macros.h"
21 : #include "base/files/scoped_temp_dir.h"
22 : #include "base/process/process.h"
23 : #include "base/win/scoped_handle.h"
24 :
25 m : namespace kasko {
26 m : namespace testing {
27 :
28 : // Launches and terminates an external web server implemented in Python.
29 m : class TestServer {
30 m : public:
31 m : TestServer();
32 m : ~TestServer();
33 :
34 : // Start the test server and block until it's ready. Returns true on success.
35 m : bool Start();
36 :
37 : // Returns the port that the server is listening on.
38 m : uint16_t port() { return port_; }
39 :
40 : // Returns the directory that the test server writes uploaded files to.
41 m : base::FilePath incoming_directory() { return incoming_directory_.path(); }
42 :
43 m : private:
44 m : base::ScopedTempDir incoming_directory_;
45 : // Python process running the test server.
46 m : base::Process process_;
47 :
48 : // The TCP port that the Python process is listening on.
49 m : uint16_t port_;
50 :
51 m : DISALLOW_COPY_AND_ASSIGN(TestServer);
52 m : };
53 :
54 m : } // namespace testing
55 m : } // namespace kasko
56 :
57 : #endif // SYZYGY_KASKO_TESTING_TEST_SERVER_H_
|