From: Brian Aker Date: Tue, 29 Jun 2010 22:04:05 +0000 (-0700) Subject: Adding gtest framework. X-Git-Tag: 0.41~5 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=49a02c953ab03f71b819e7a5f68ef7a0e5857544;p=m6w6%2Flibmemcached Adding gtest framework. --- 49a02c953ab03f71b819e7a5f68ef7a0e5857544 diff --cc .bzrignore index e28af860,e28af860..ea78c2ef --- a/.bzrignore +++ b/.bzrignore @@@ -181,3 -181,3 +181,4 @@@ tests/testap tests/testhashkit tests/testplus tests/testudp ++unittests/unittests diff --cc Makefile.am index d2acebaa,d855c8f4..38f87c5e --- a/Makefile.am +++ b/Makefile.am @@@ -37,6 -38,6 +38,7 @@@ 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 diff --cc libmemcached/common.h index bfbc9220,bfbc9220..b45bf807 --- a/libmemcached/common.h +++ b/libmemcached/common.h @@@ -79,7 -79,7 +79,7 @@@ struct memcached_continuum_item_s typedef enum { MEM_NOT= -1, MEM_FALSE= false, -- MEM_TRUE= true, ++ MEM_TRUE= true } memcached_ternary_t; diff --cc m4/pandora_warnings.m4 index 1731870d,1731870d..9ee365a0 --- a/m4/pandora_warnings.m4 +++ b/m4/pandora_warnings.m4 @@@ -145,7 -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++" ],[ diff --cc tests/include.am index f3b767ca,21450f6d..3631a81e --- a/tests/include.am +++ b/tests/include.am @@@ -89,7 -99,7 +89,7 @@@ tests_memplus_CXXFLAGS = $(AM_CXXFLAGS 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 --cc unittests/include.am index 00000000,00000000..fc67e937 new file mode 100644 --- /dev/null +++ b/unittests/include.am @@@ -1,0 -1,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 --cc unittests/main.cc index 00000000,00000000..7e575c30 new file mode 100644 --- /dev/null +++ b/unittests/main.cc @@@ -1,0 -1,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 ++ ++ ++int main(int argc, char **argv) ++{ ++ ::testing::InitGoogleTest(&argc, argv); ++ return RUN_ALL_TESTS(); ++} diff --cc unittests/strings.cc index 00000000,00000000..8728926b new file mode 100644 --- /dev/null +++ b/unittests/strings.cc @@@ -1,0 -1,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 ++ ++#include ++ ++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); ++}