Sha256: 37f718674af780ef12c08a2ef13ccb82d54b2687775b95cc42cfd21e3c85265c

Contents?: true

Size: 1.65 KB

Versions: 35

Compression:

Stored size: 1.65 KB

Contents

#include "config.h"
#include <gtest/gtest.h>
#include <libcouchbase/couchbase.h>
#include "logging.h"
#include "internal.h"
#include <list>

using namespace std;

class Logger : public ::testing::Test
{
};


struct MyLogprocs : lcb_logprocs {
    set<string> messages;
};

extern "C" {
static void fallback_logger(lcb_logprocs *procs, unsigned int,
                            const char *, int, const char *,
                            int, const char *fmt, va_list ap)
{
    char buf[2048];
    vsprintf(buf, fmt, ap);
    EXPECT_FALSE(procs == NULL);
    MyLogprocs *myprocs = static_cast<MyLogprocs *>(procs);
    myprocs->messages.insert(buf);
}
}

TEST_F(Logger, testLogger)
{
    lcb_t instance;
    lcb_error_t err;

    lcb_create(&instance, NULL);
    MyLogprocs procs;
    lcb_logprocs *ptrprocs = static_cast<lcb_logprocs *>(&procs);
    ptrprocs->version = 0;
    memset(ptrprocs, 0, sizeof(*ptrprocs));

    err = lcb_cntl(instance, LCB_CNTL_SET, LCB_CNTL_LOGGER, ptrprocs);
    ASSERT_EQ(LCB_SUCCESS, err);

    procs.v.v0.callback = fallback_logger;

    LCB_LOG_BASIC(instance->getSettings(), "foo");
    LCB_LOG_BASIC(instance->getSettings(), "bar");
    LCB_LOG_BASIC(instance->getSettings(), "baz");

    set<string>& msgs = procs.messages;
    ASSERT_FALSE(msgs.find("foo") == msgs.end());
    ASSERT_FALSE(msgs.find("bar") == msgs.end());
    ASSERT_FALSE(msgs.find("baz") == msgs.end());
    msgs.clear();

    // Try without a logger
    err = lcb_cntl(instance, LCB_CNTL_SET, LCB_CNTL_LOGGER, NULL);
    ASSERT_EQ(LCB_SUCCESS, err);
    LCB_LOG_BASIC(instance->getSettings(), "this should not appear");
    ASSERT_TRUE(msgs.empty());

    lcb_destroy(instance);
}

Version data entries

35 entries across 35 versions & 2 rubygems

Version Path
mt-libcouchbase-1.4.03 ext/libcouchbase/tests/basic/t_logger.cc
mt-libcouchbase-1.4.02 ext/libcouchbase/tests/basic/t_logger.cc
mt-libcouchbase-1.4.01 ext/libcouchbase/tests/basic/t_logger.cc
mt-libcouchbase-1.4.0 ext/libcouchbase/tests/basic/t_logger.cc
libcouchbase-1.3.2 ext/libcouchbase/tests/basic/t_logger.cc
libcouchbase-1.3.0 ext/libcouchbase/tests/basic/t_logger.cc
libcouchbase-1.2.8 ext/libcouchbase/tests/basic/t_logger.cc
libcouchbase-1.2.7 ext/libcouchbase/tests/basic/t_logger.cc
libcouchbase-1.2.6 ext/libcouchbase/tests/basic/t_logger.cc
libcouchbase-1.2.5 ext/libcouchbase/tests/basic/t_logger.cc
libcouchbase-1.2.4 ext/libcouchbase/tests/basic/t_logger.cc
libcouchbase-1.2.3 ext/libcouchbase/tests/basic/t_logger.cc
libcouchbase-1.2.2 ext/libcouchbase/tests/basic/t_logger.cc
libcouchbase-1.2.1 ext/libcouchbase/tests/basic/t_logger.cc
libcouchbase-1.2.0 ext/libcouchbase/tests/basic/t_logger.cc
libcouchbase-1.1.1 ext/libcouchbase/tests/basic/t_logger.cc
libcouchbase-1.1.0 ext/libcouchbase/tests/basic/t_logger.cc
libcouchbase-1.0.4 ext/libcouchbase/tests/basic/t_logger.cc
libcouchbase-1.0.3 ext/libcouchbase/tests/basic/t_logger.cc
libcouchbase-1.0.2 ext/libcouchbase/tests/basic/t_logger.cc