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/win/scoped_handle.h"
23 :
24 : namespace kasko {
25 : namespace testing {
26 :
27 : // Launches and terminates an external web server implemented in Python.
28 : class TestServer {
29 : public:
30 : TestServer();
31 : ~TestServer();
32 :
33 : // Start the test server and block until it's ready. Returns true on success.
34 : bool Start();
35 :
36 : // Returns the port that the server is listening on.
37 E : uint16_t port() { return port_; }
38 :
39 : // Returns the directory that the test server writes uploaded files to.
40 E : base::FilePath incoming_directory() { return incoming_directory_.path(); }
41 :
42 : private:
43 : base::ScopedTempDir incoming_directory_;
44 : // Handle of the Python process running the test server.
45 : base::win::ScopedHandle process_handle_;
46 :
47 : // The TCP port that the Python process is listening on.
48 : uint16_t port_;
49 :
50 : DISALLOW_COPY_AND_ASSIGN(TestServer);
51 : };
52 :
53 : } // namespace testing
54 : } // namespace kasko
55 :
56 : #endif // SYZYGY_KASKO_TESTING_TEST_SERVER_H_
|