1 /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /*
3  *     Copyright 2010-2020 Couchbase, Inc.
4  *
5  *   Licensed under the Apache License, Version 2.0 (the "License");
6  *   you may not use this file except in compliance with the License.
7  *   You may obtain a copy of the License at
8  *
9  *       http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *   Unless required by applicable law or agreed to in writing, software
12  *   distributed under the License is distributed on an "AS IS" BASIS,
13  *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *   See the License for the specific language governing permissions and
15  *   limitations under the License.
16  */
17 #ifndef LIBCOUCHBASE_TEST_SERVER_H
18 #define LIBCOUCHBASE_TEST_SERVER_H 1
19 #define LCB_TEST_REALCLUSTER_ENV "LCB_TEST_CLUSTER_CONF"
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 #ifdef _WIN32
26 #define in_port_t USHORT
27 #ifndef usleep
28 #define usleep(us) Sleep((us) / 1000)
29 #endif
30 #ifndef sleep
31 #define sleep(s) Sleep((s)*1000)
32 #endif
33 
34 #include <winsock2.h>
35 #else
36 #define closesocket close
37 #include <sys/types.h>
38 #include <sys/socket.h>
39 #include <arpa/inet.h>
40 #endif
41 #include <libcouchbase/couchbase.h>
42 #include "procutil.h"
43 
44 struct test_server_info {
45     child_process_t process;
46     char *http;
47     char *bucket;
48     char *username;
49     char *password;
50     in_port_t port;
51     struct sockaddr_storage storage;
52     int sock;
53     int client;
54     int is_mock;
55 };
56 
57 const void *start_test_server(char **cmdline);
58 const char *get_mock_http_server(const void *);
59 void get_mock_std_creds(const void *handle, const char **userp, const char **passp);
60 int is_using_real_cluster(void);
61 
62 void shutdown_mock_server(const void *);
63 
64 struct lcb_io_opt_st *get_test_io_opts(void);
65 void setup_test_timeout_handler(void);
66 
67 #ifdef __cplusplus
68 }
69 #endif
70 
71 #endif
72