Adding gtest framework.
authorBrian Aker <brian@gaz>
Tue, 29 Jun 2010 22:04:05 +0000 (15:04 -0700)
committerBrian Aker <brian@gaz>
Tue, 29 Jun 2010 22:04:05 +0000 (15:04 -0700)
.bzrignore
Makefile.am
configure.ac
libmemcached/common.h
m4/pandora_warnings.m4
tests/include.am
unittests/include.am [new file with mode: 0644]
unittests/main.cc [new file with mode: 0644]
unittests/strings.cc [new file with mode: 0644]

index e28af860bad8ee84ce4753e5f9900b3dec5a3ace..ea78c2ef1c78cf4f788d1d4cf0a44097ea267005 100644 (file)
@@ -181,3 +181,4 @@ tests/testapp
 tests/testhashkit
 tests/testplus
 tests/testudp
+unittests/unittests
index d2acebaa4658258582dd8e4b712c90d91b5223f1..38f87c5e76f02c643bba3927fb707831afb4ec89 100644 (file)
@@ -12,6 +12,7 @@ noinst_LTLIBRARIES =
 noinst_PROGRAMS =
 include_HEADERS =
 nobase_include_HEADERS =
+check_PROGRAMS = 
 EXTRA_HEADERS =
 BUILT_SOURCES=
 EXTRA_DIST= \
@@ -37,10 +38,13 @@ test-docs:
 include libmemcached/include.am
 include clients/include.am
 include libhashkit/include.am
+include unittests/include.am
 include tests/include.am
 include example/include.am
 include support/include.am
 
+TESTS += ${check_PROGRAMS}
+
 check-local: test-no-outputdiff
 
 
index 2e0a5a93eb8d6fdd21cdef86fe51cd34b6f40bb6..0db997591b1b3ce2731459b6edabb36b6f03ae46 100644 (file)
@@ -36,6 +36,7 @@ AC_SEARCH_LIBS(gethostbyname, nsl)
 
 AC_CHECK_FUNCS([getline])
 
+PANDORA_HAVE_LIBGTEST
 PANDORA_HAVE_LIBEVENT
 PANDORA_REQUIRE_PTHREAD
 PANDORA_CXX_DEMANGLE
index bfbc9220950569b45fddc320d22cb4b503b3b402..b45bf80791ac83de883cbbd239145dcabfefee20 100644 (file)
@@ -79,7 +79,7 @@ struct memcached_continuum_item_st
 typedef enum {
   MEM_NOT= -1,
   MEM_FALSE= false,
-  MEM_TRUE= true,
+  MEM_TRUE= true
 } memcached_ternary_t;
 
 
index 1731870d6f94fc28b17548305660724194103220..9ee365a023537af1539f10a425170aa3c9f76ca9 100644 (file)
@@ -145,7 +145,7 @@ uint16_t x= htons(80);
       m4_if(PW_LESS_WARNINGS,[no],[
         BASE_WARNINGS_FULL="-Wformat=2 ${W_CONVERSION} -Wstrict-aliasing"
         CC_WARNINGS_FULL="-Wswitch-default -Wswitch-enum -Wwrite-strings"
-        CXX_WARNINGS_FULL="-Weffc++ -Wold-style-cast"
+        CXX_WARNINGS_FULL="-Wold-style-cast"
         NO_OLD_STYLE_CAST="-Wno-old-style-cast"
         NO_EFF_CXX="-Wno-effc++"
       ],[
index f3b767cafc97972ff4b4e780431fc53eec507089..3631a81e25713fc083b4b2d24ff9f2b33a3ab866 100644 (file)
@@ -89,7 +89,7 @@ tests_memplus_CXXFLAGS = $(AM_CXXFLAGS) $(NO_EFF_CXX)
 tests_memplus_DEPENDENCIES = tests/libtest.la tests/libserver.la libmemcached/libmemcached.la
 tests_memplus_LDADD = $(tests_memplus_DEPENDENCIES)
 
-test: test-docs test-mem test-hash memcapable
+test: unittests-run test-docs test-mem test-hash memcapable
        echo "Tests completed"
 
 test-x: test-docs test-plus test-mem test-hash memcapable test-memcat test-memcp test-memrm test-memerror test-memdump test-memflush test-memstat
diff --git a/unittests/include.am b/unittests/include.am
new file mode 100644 (file)
index 0000000..fc67e93
--- /dev/null
@@ -0,0 +1,23 @@
+# vim:ft=automake
+# included from Top Level Makefile.am
+# All paths should be given relative to the root
+
+if HAVE_LIBGTEST
+UNITTEST_PROGRAM= unittests/unittests
+
+noinst_PROGRAMS += $(UNITTEST_PROGRAM)
+
+unittests_unittests_SOURCES= \
+                            unittests/strings.cc \
+                            unittests/main.cc
+unittests_unittests_LDADD= \
+                          tests/libserver.la \
+                          libmemcached/libmemcachedinternal.la \
+                          ${TESTS_LDADDS} ${LTLIBGTEST}
+endif
+
+# Shorthand
+unit: unittests-run
+
+unittests-run: $(UNITTEST_PROGRAM)
+       $(UNITTEST_PROGRAM)
diff --git a/unittests/main.cc b/unittests/main.cc
new file mode 100644 (file)
index 0000000..7e575c3
--- /dev/null
@@ -0,0 +1,21 @@
+/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
+ *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ *
+ *  Copyright (C) 2010 Monty Taylor
+ *
+ *  All rights reserved.
+ *
+ *  Use and distribution licensed under the BSD license.  See
+ *  the COPYING file in the parent directory for full text.
+ */
+
+#include "config.h"
+
+#include <gtest/gtest.h>
+
+
+int main(int argc, char **argv)
+{
+  ::testing::InitGoogleTest(&argc, argv);
+  return RUN_ALL_TESTS();
+}
diff --git a/unittests/strings.cc b/unittests/strings.cc
new file mode 100644 (file)
index 0000000..8728926
--- /dev/null
@@ -0,0 +1,131 @@
+/* libMemcached
+ * Copyright (C) 2010 Brian Aker
+ * All rights reserved.
+ *
+ * Use and distribution licensed under the BSD license.  See
+ * the COPYING file in the parent directory for full text.
+ */
+
+#include "config.h"
+
+#include <gtest/gtest.h>
+
+#include <libmemcached/common.h>
+
+TEST(memcached_string_st, memcached_create_static)
+{
+  memcached_string_st string;
+  memcached_string_st *string_ptr;
+
+  memcached_st *memc= memcached_create(NULL);
+  string_ptr= memcached_string_create(memc, &string, 0);
+  ASSERT_TRUE(string.options.is_initialized);
+  ASSERT_TRUE(string_ptr);
+
+  /* The following two better be the same! */
+  ASSERT_FALSE(memcached_is_allocated(string_ptr));
+  ASSERT_FALSE(memcached_is_allocated(&string));
+  EXPECT_EQ(&string, string_ptr);
+
+  ASSERT_TRUE(string.options.is_initialized);
+  ASSERT_TRUE(memcached_is_initialized(&string));
+  memcached_string_free(&string);
+  ASSERT_FALSE(memcached_is_initialized(&string));
+
+  memcached_free(memc);
+}
+
+TEST(memcached_string_st, memcached_create_null)
+{
+  memcached_string_st *string;
+  memcached_st *memc= memcached_create(NULL);
+
+  string= memcached_string_create(memc, NULL, 0);
+  ASSERT_TRUE(string);
+  ASSERT_TRUE(memcached_is_allocated(string));
+  ASSERT_TRUE(memcached_is_initialized(string));
+  memcached_string_free(string);
+
+  memcached_free(memc);
+}
+
+TEST(memcached_string_st, string_alloc_with_size)
+{
+  memcached_string_st *string;
+  memcached_st *memc= memcached_create(NULL);
+
+  string= memcached_string_create(memc, NULL, 1024);
+  ASSERT_TRUE(string);
+  ASSERT_TRUE(memcached_is_allocated(string));
+  ASSERT_TRUE(memcached_is_initialized(string));
+  memcached_string_free(string);
+
+  memcached_free(memc);
+}
+
+TEST(memcached_string_st, string_alloc_with_size_toobig)
+{
+  memcached_st *memc= memcached_create(NULL);
+  memcached_string_st *string;
+
+  string= memcached_string_create(memc, NULL, SIZE_MAX);
+  ASSERT_FALSE(string);
+
+  memcached_free(memc);
+}
+
+TEST(memcached_string_st, string_alloc_append)
+{
+  char buffer[SMALL_STRING_LEN];
+  memcached_string_st *string;
+
+  memcached_st *memc= memcached_create(NULL);
+
+  /* Ring the bell! */
+  memset(buffer, 6, SMALL_STRING_LEN);
+
+  string= memcached_string_create(memc, NULL, 100);
+  ASSERT_TRUE(string);
+  ASSERT_TRUE(memcached_is_allocated(string));
+  ASSERT_TRUE(memcached_is_initialized(string));
+
+  for (uint32_t x= 0; x < 1024; x++)
+  {
+    memcached_return_t rc;
+    rc= memcached_string_append(string, buffer, SMALL_STRING_LEN);
+    EXPECT_EQ(rc, MEMCACHED_SUCCESS);
+  }
+  ASSERT_TRUE(memcached_is_allocated(string));
+  memcached_string_free(string);
+
+  memcached_free(memc);
+}
+
+TEST(memcached_string_st, string_alloc_append_toobig)
+{
+  memcached_return_t rc;
+  char buffer[SMALL_STRING_LEN];
+  memcached_string_st *string;
+
+  memcached_st *memc= memcached_create(NULL);
+
+  /* Ring the bell! */
+  memset(buffer, 6, SMALL_STRING_LEN);
+
+  string= memcached_string_create(memc, NULL, 100);
+  ASSERT_TRUE(string);
+  ASSERT_TRUE(memcached_is_allocated(string));
+  ASSERT_TRUE(memcached_is_initialized(string));
+
+  for (uint32_t x= 0; x < 1024; x++)
+  {
+    rc= memcached_string_append(string, buffer, SMALL_STRING_LEN);
+    EXPECT_EQ(rc, MEMCACHED_SUCCESS);
+  }
+  rc= memcached_string_append(string, buffer, SIZE_MAX);
+  EXPECT_EQ(rc, MEMCACHED_MEMORY_ALLOCATION_FAILURE);
+  ASSERT_TRUE(memcached_is_allocated(string));
+  memcached_string_free(string);
+
+  memcached_free(memc);
+}