1 /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /*
3  *     Copyright 2010-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_UNIT_TESTS_H
18 #define TESTS_MOCK_UNIT_TESTS_H 1
19 
20 #include "config.h"
21 #include <gtest/gtest.h>
22 #include <libcouchbase/couchbase.h>
23 #include "mock-environment.h"
24 
25 class HandleWrap;
26 
27 #define SKIP_IF_MOCK()                                                                                                 \
28     if (!getenv(LCB_TEST_REALCLUSTER_ENV)) {                                                                           \
29         MockEnvironment::printSkipMessage(__FILE__, __LINE__, "needs real cluster");                                   \
30         return;                                                                                                        \
31     }
32 
33 #define SKIP_UNLESS_MOCK()                                                                                             \
34     if (getenv(LCB_TEST_REALCLUSTER_ENV)) {                                                                            \
35         MockEnvironment::printSkipMessage(__FILE__, __LINE__, "needs mock cluster");                                   \
36         return;                                                                                                        \
37     }
38 
39 #define ASSERT_ERRISA(err, et) \
40         ASSERT_EQ(et, (int)lcb_get_errtype(err) & (int)et)
41 
42 class MockUnitTest : public ::testing::Test
43 {
44 protected:
45     virtual void SetUp();
46     virtual void createConnection(lcb_t &instance);
47     virtual void createConnection(HandleWrap &handle);
48     virtual void createConnection(HandleWrap &handle, lcb_t &instance);
49     virtual lcb_error_t tryCreateConnection(HandleWrap &hw,
50         lcb_t &instance, lcb_create_st &crparams);
51 
52     // A mock "Transaction"
53     void doMockTxn(MockCommand &cmd) {
54         MockEnvironment::getInstance()->sendCommand(cmd);
55         MockResponse tmp;
56         MockEnvironment::getInstance()->getResponse(tmp);
57         ASSERT_TRUE(tmp.isOk());
58     }
59 };
60 
61 #endif
62