Skip to content
Newer
Older
100644 126 lines (109 sloc) 3.64 KB
69a4ea3 @trondn Split up mock-unit-test.h
trondn authored Sep 10, 2012
1 /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /*
3 * Copyright 2012 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 TESTS_MOCK_ENVIRONMENT_H
18 #define TESTS_MOCK_ENVIRONMENT_H 1
19
20 #include "config.h"
21 #include <gtest/gtest.h>
22 #include <libcouchbase/couchbase.h>
23 #include "serverparams.h"
24
25 class MockEnvironment : public ::testing::Environment
26 {
27 public:
9feee92 @mnunberg Determine cluster version
mnunberg authored Sep 9, 2012
28 enum ServerVersion {
29 VERSION_UNKNOWN = 0,
30 VERSION_10 = 1,
31 VERSION_20 = 2
32 };
33
69a4ea3 @trondn Split up mock-unit-test.h
trondn authored Sep 10, 2012
34 virtual void SetUp();
35 virtual void TearDown();
36
959a7c2 @avsej Reformat code
avsej authored Sep 26, 2012
37 static MockEnvironment *getInstance(void);
325d6f4 @trondn Refactor MockEnvironment to singleton
trondn authored Sep 10, 2012
38
3df652b @trondn The mockenv should provide createConnection
trondn authored Sep 10, 2012
39 /**
40 * Make a connect structure you may utilize to connect to
41 * the backend we're running the tests towards.
42 *
43 * @param crst the create structure to fill in
44 * @param io the io ops to use (pass NULL if you don't have a
45 * special io ops you want to use
46 */
47 void makeConnectParams(lcb_create_st &crst, lcb_io_opt_t io) {
48 serverParams.makeConnectParams(crst, io);
69a4ea3 @trondn Split up mock-unit-test.h
trondn authored Sep 10, 2012
49 }
50
3df652b @trondn The mockenv should provide createConnection
trondn authored Sep 10, 2012
51 /**
52 * Get the number of nodes used in the backend
53 */
325d6f4 @trondn Refactor MockEnvironment to singleton
trondn authored Sep 10, 2012
54 int getNumNodes(void) const {
55 return numNodes;
56 }
69a4ea3 @trondn Split up mock-unit-test.h
trondn authored Sep 10, 2012
57
3df652b @trondn The mockenv should provide createConnection
trondn authored Sep 10, 2012
58 /**
59 * Are we currently using a real cluster as the backend, or
60 * are we using the mock server.
61 *
62 * You should try your very best to avoid using this variable, and
63 * rather extend the mock server to support the requested feature.
64 */
325d6f4 @trondn Refactor MockEnvironment to singleton
trondn authored Sep 10, 2012
65 bool isRealCluster(void) const {
66 return realCluster;
67 }
68
3df652b @trondn The mockenv should provide createConnection
trondn authored Sep 10, 2012
69 /**
70 * Create a connection to the mock/real server.
71 *
72 * The instance will be initialized with the the connect parameters
73 * to either the mock or a real server (just like makeConnectParams),
74 * and call lcb_create. The io instance will be stored in the instance
75 * cookie so you may grab it from there.
76 *
77 * You should call lcb_destroy on the instance when you're done
78 * using it.
79 *
80 * @param instance the instane to create
81 */
82 void createConnection(lcb_t &instance);
69a4ea3 @trondn Split up mock-unit-test.h
trondn authored Sep 10, 2012
83
9feee92 @mnunberg Determine cluster version
mnunberg authored Sep 9, 2012
84 ServerVersion getServerVersion(void) const {
85 return serverVersion;
86 }
87
88 void setServerVersion(ServerVersion ver) {
89 serverVersion = ver;
90 }
91
69a4ea3 @trondn Split up mock-unit-test.h
trondn authored Sep 10, 2012
92 protected:
3df652b @trondn The mockenv should provide createConnection
trondn authored Sep 10, 2012
93 /**
94 * Protected destructor to make it to a singleton
95 */
325d6f4 @trondn Refactor MockEnvironment to singleton
trondn authored Sep 10, 2012
96 MockEnvironment();
3df652b @trondn The mockenv should provide createConnection
trondn authored Sep 10, 2012
97 /**
98 * Handle to the one and only instance of the mock environment
99 */
325d6f4 @trondn Refactor MockEnvironment to singleton
trondn authored Sep 10, 2012
100 static MockEnvironment *instance;
101
102 void bootstrapRealCluster();
103 const struct test_server_info *mock;
104 ServerParams serverParams;
105 int numNodes;
106 bool realCluster;
9feee92 @mnunberg Determine cluster version
mnunberg authored Sep 9, 2012
107 ServerVersion serverVersion;
325d6f4 @trondn Refactor MockEnvironment to singleton
trondn authored Sep 10, 2012
108 const char *http;
69a4ea3 @trondn Split up mock-unit-test.h
trondn authored Sep 10, 2012
109 };
110
9feee92 @mnunberg Determine cluster version
mnunberg authored Sep 9, 2012
111 #define LCB_TEST_REQUIRE_CLUSTER_VERSION(v) \
112 if (!MockEnvironment::getInstance()->isRealCluster()) { \
113 std::cerr << "Skipping " << __FILE__ << ":" << std::dec << __LINE__; \
114 std::cerr << " (need real cluster) " << std::endl; \
115 return; \
116 } \
6040ca7 @mnunberg Test lock and unlock commands
mnunberg authored Sep 9, 2012
117 if (MockEnvironment::getInstance()->getServerVersion() < v) { \
9feee92 @mnunberg Determine cluster version
mnunberg authored Sep 9, 2012
118 std::cerr << "Skipping " << __FILE__ << ":" << std::dec << __LINE__; \
119 std::cerr << " (test needs higher cluster version)" << std::endl; \
120 return; \
121 }
122
123
124
69a4ea3 @trondn Split up mock-unit-test.h
trondn authored Sep 10, 2012
125 #endif
Something went wrong with that request. Please try again.