From: Michael Wallner Date: Fri, 23 Oct 2020 11:05:27 +0000 (+0200) Subject: start using a .clang-format code style X-Git-Tag: 1.1.0-beta1~182 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=fb3710011600c04359d26615be7a92df1742a3e9;p=m6w6%2Flibmemcached start using a .clang-format code style --- diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..b86de6c1 --- /dev/null +++ b/.clang-format @@ -0,0 +1,128 @@ +AccessModifierOffset: -2 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: false +#AlignConsecutiveBitFields: false (in v11) +AlignConsecutiveDeclarations: false +AlignConsecutiveMacros: true +AlignEscapedNewlines: DontAlign +# AlignOperands: AlignAfterOperator (in v11) +AlignOperands: false +AlignTrailingComments: true +AllowAllArgumentsOnNextLine: true +AllowAllConstructorInitializersOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: Never +AllowShortCaseLabelsOnASingleLine: true +#AllowShortEnumsOnASingleLine: true (in v11) +AllowShortFunctionsOnASingleLine: Inline +AllowShortIfStatementsOnASingleLine: Never +AllowShortLambdasOnASingleLine: All +AllowShortLoopsOnASingleLine: true +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: Yes +BinPackArguments: true +BinPackParameters: true +#BitFieldColonSpacing: None (in v12) +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: MultiLine + AfterEnum: false + AfterExternBlock: false + AfterFunction: false + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + BeforeCatch: false + BeforeElse: false +# BeforeLambdaBody: false (in v11) +# BeforeWhile: false (in v11) + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyNamespace: true + SplitEmptyRecord: true +BreakBeforeBinaryOperators: NonAssignment +BreakBeforeBraces: Custom +BreakBeforeInheritanceComma: true +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: BeforeComma +BreakConstructorInitializersBeforeComma: true +BreakInheritanceList: BeforeComma +BreakStringLiterals: true +ColumnLimit: 100 +#CommentPragmas: '^ ...' +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 0 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DeriveLineEnding: true +DerivePointerAlignment: false +DisableFormat: false +#ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: true +ForEachMacros: + - foreach + - BOOST_FOREACH +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^"lib(hashkit|(memcached(|protocol|util)))(-.*)?/' + Priority: 3 + - Regex: '^(<|")test/)' + Priority: 2 + - Regex: '.*' + Priority: 1 +IncludeIsMainSourceRegex: '' +IndentCaseLabels: false +IndentGotoLabels: false +#IndentExternBlock: false (in v11) +IndentPPDirectives: AfterHash +IndentWidth: 2 +IndentWrappedFunctionNames: false +#InsertTrailingCommas: Wrapped (in v11) +KeepEmptyLinesAtTheStartOfBlocks: false +Language: Cpp +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +#PenaltyBreakAssignment: 2 +#PenaltyBreakBeforeFirstCallParameter: 19 +#PenaltyBreakComment: 300 +#PenaltyBreakFirstLessLess: 120 +#PenaltyBreakString: 1000 +#PenaltyBreakTemplateDeclaration: 10 +#PenaltyExcessCharacter: 1000000 +#PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Right +ReflowComments: true +SortIncludes: false +SortUsingDeclarations: true +SpaceAfterCStyleCast: true +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: false +#SpaceAroundPointerQualifiers: Both (in v12) +SpaceBeforeAssignmentOperators: true +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true +SpaceBeforeSquareBrackets: false +SpaceInEmptyBlock: false +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInConditionalStatement: false +SpacesInContainerLiterals: false +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Latest +#StatementMacros: +# - +TabWidth: 2 +UseCRLF: false +UseTab: Never diff --git a/LICENSE.HEADER b/LICENSE.HEADER new file mode 100644 index 00000000..734fa5b9 --- /dev/null +++ b/LICENSE.HEADER @@ -0,0 +1,14 @@ +/* + +--------------------------------------------------------------------+ + | libmemcached - C/C++ Client Library for memcached | + +--------------------------------------------------------------------+ + | Redistribution and use in source and binary forms, with or without | + | modification, are permitted under the terms of the BSD license. | + | You should have received a copy of the license in a bundled file | + | named LICENSE; in case you did not receive a copy you can review | + | the terms online at: https://opensource.org/licenses/BSD-3-Clause | + +--------------------------------------------------------------------+ + | Copyright (c) 2006-2014 Brian Aker https://datadifferential.com/ | + | Copyright (c) 2020 Michael Wallner | + +--------------------------------------------------------------------+ +*/ diff --git a/scripts/fix-license-header.sh b/scripts/fix-license-header.sh new file mode 100755 index 00000000..6ab70cde --- /dev/null +++ b/scripts/fix-license-header.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +PROGRAM_NAME=$(basename $0) +CWD=$(dirname $0) +FILES=() +INPLACE=false + +help() { + echo $2 + echo "Usage:" + echo " $PROGRAM_NAME [-hi] [--help|--inplace] ..." + echo + exit $1 +} + +while test $# -gt 0; do + case $1 in + -h|--help) help ;; + -i|--inplace) INPLACE=true ;; + *) + test -f $1 || help 1 "$1 does not exist.\n" + FILES+=($1) + ;; + esac + + shift +done + +test "${#FILES[@]}" -eq 0 && help 1 + +for FILE in "${FILES[@]}"; do + if $INPLACE; then + TEMP=$(mktemp $FILE.XXXXXXXX) + exec 1>$TEMP + fi + cat $CWD/../LICENSE.HEADER + echo + awk < $FILE ' + BEGIN { hash_seen = 0 } + /^#/ { hash_seen = 1 } + { if (hash_seen) print } + ' + if $INPLACE; then + mv $TEMP $FILE + fi +done diff --git a/src/libmemcached/get.cc b/src/libmemcached/get.cc index 57e2ae72..d0d3f687 100644 --- a/src/libmemcached/get.cc +++ b/src/libmemcached/get.cc @@ -1,5 +1,5 @@ /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: - * + * * Libmemcached library * * Copyright (C) 2011-2013 Data Differential, http://datadifferential.com/ @@ -37,9 +37,6 @@ #include "libmemcached/common.h" -/* - What happens if no servers exist? -*/ char *memcached_get(memcached_st *ptr, const char *key, size_t key_length, size_t *value_length, @@ -80,7 +77,7 @@ char *memcached_get_by_key(memcached_st *shell, /* Request the key */ *error= __mget_by_key_real(ptr, group_key, group_key_length, - (const char * const *)&key, &key_length, + (const char * const *)&key, &key_length, 1, false); if (ptr) { @@ -97,7 +94,7 @@ char *memcached_get_by_key(memcached_st *shell, } } - if (value_length) + if (value_length) { *value_length= 0; } diff --git a/test/fixtures/callbacks.hpp b/test/fixtures/callbacks.hpp index 52bab4c7..5e01c4b4 100644 --- a/test/fixtures/callbacks.hpp +++ b/test/fixtures/callbacks.hpp @@ -1,25 +1,45 @@ +/* + +--------------------------------------------------------------------+ + | libmemcached - C/C++ Client Library for memcached | + +--------------------------------------------------------------------+ + | Redistribution and use in source and binary forms, with or without | + | modification, are permitted under the terms of the BSD license. | + | You should have received a copy of the license in a bundled file | + | named LICENSE; in case you did not receive a copy you can review | + | the terms online at: https://opensource.org/licenses/BSD-3-Clause | + +--------------------------------------------------------------------+ + | Copyright (c) 2006-2014 Brian Aker https://datadifferential.com/ | + | Copyright (c) 2020 Michael Wallner | + +--------------------------------------------------------------------+ +*/ + #include "test/lib/common.hpp" #include "libmemcached/common.h" #include "libmemcachedutil/common.h" -static inline memcached_return_t ping_callback(const memcached_st *, const memcached_instance_st *instance, void *) { +static inline memcached_return_t ping_callback(const memcached_st *, + const memcached_instance_st *instance, void *) { memcached_return_t rc; - REQUIRE(libmemcached_util_ping(memcached_server_name(instance), memcached_server_port(instance), &rc)); + REQUIRE(libmemcached_util_ping(memcached_server_name(instance), memcached_server_port(instance), + &rc)); REQUIRE(rc == MEMCACHED_SUCCESS); return MEMCACHED_SUCCESS; } -static inline memcached_return_t ping2_callback(const memcached_st *, const memcached_instance_st *instance, void *) { +static inline memcached_return_t ping2_callback(const memcached_st *, + const memcached_instance_st *instance, void *) { memcached_return_t rc; - REQUIRE(libmemcached_util_ping2(memcached_server_name(instance), memcached_server_port(instance), "memcached", "memcached", &rc)); + REQUIRE(libmemcached_util_ping2(memcached_server_name(instance), memcached_server_port(instance), + "memcached", "memcached", &rc)); REQUIRE(rc == MEMCACHED_SUCCESS); return MEMCACHED_SUCCESS; } -static inline memcached_return_t callback_counter(const memcached_st *, memcached_result_st *, void *context) { - auto *counter= reinterpret_cast(context); +static inline memcached_return_t callback_counter(const memcached_st *, memcached_result_st *, + void *context) { + auto *counter = reinterpret_cast(context); *counter = *counter + 1; return MEMCACHED_SUCCESS; @@ -29,7 +49,8 @@ static inline memcached_return_t delete_trigger(memcached_st *, const char *, si return MEMCACHED_SUCCESS; } -static inline memcached_return_t read_through_trigger(memcached_st *, char *, size_t, memcached_result_st *result) { +static inline memcached_return_t read_through_trigger(memcached_st *, char *, size_t, + memcached_result_st *result) { return memcached_result_set_value(result, S("updated by read through trigger")); } @@ -41,7 +62,8 @@ static inline memcached_return_t cleanup_callback(memcached_st *) { return MEMCACHED_SUCCESS; } -static inline memcached_return_t server_sort_callback(const memcached_st *, const memcached_instance_st *server, void *context) { +static inline memcached_return_t +server_sort_callback(const memcached_st *, const memcached_instance_st *server, void *context) { if (context) { auto bigger = reinterpret_cast(context); REQUIRE(*bigger <= memcached_server_port(server)); @@ -49,4 +71,3 @@ static inline memcached_return_t server_sort_callback(const memcached_st *, cons } return MEMCACHED_SUCCESS; } - diff --git a/test/fixtures/hashes.hpp b/test/fixtures/hashes.hpp index 2c62c824..001bf6d4 100644 --- a/test/fixtures/hashes.hpp +++ b/test/fixtures/hashes.hpp @@ -1,141 +1,113 @@ +/* + +--------------------------------------------------------------------+ + | libmemcached - C/C++ Client Library for memcached | + +--------------------------------------------------------------------+ + | Redistribution and use in source and binary forms, with or without | + | modification, are permitted under the terms of the BSD license. | + | You should have received a copy of the license in a bundled file | + | named LICENSE; in case you did not receive a copy you can review | + | the terms online at: https://opensource.org/licenses/BSD-3-Clause | + +--------------------------------------------------------------------+ + | Copyright (c) 2006-2014 Brian Aker https://datadifferential.com/ | + | Copyright (c) 2020 Michael Wallner | + +--------------------------------------------------------------------+ +*/ + #pragma once #include "mem_config.h" static const char *input[] = { - "apple", - "beat", - "carrot", - "daikon", - "eggplant", - "flower", - "green", - "hide", - "ick", - "jack", - "kick", - "lime", - "mushrooms", - "nectarine", - "orange", - "peach", - "quant", - "ripen", - "strawberry", - "tang", - "up", - "volumne", - "when", - "yellow", - "zip", - "The quick brown fox jumps over the lazy dog", + "apple", "beat", + "carrot", "daikon", + "eggplant", "flower", + "green", "hide", + "ick", "jack", + "kick", "lime", + "mushrooms", "nectarine", + "orange", "peach", + "quant", "ripen", + "strawberry", "tang", + "up", "volumne", + "when", "yellow", + "zip", "The quick brown fox jumps over the lazy dog", }; -static const uint32_t output[][sizeof(input)/sizeof(*input)] = { +static const uint32_t output[][sizeof(input) / sizeof(*input)] = { // one_at_a_time - { 2297466611U, 3902465932U, 469785835U, 1937308741U, - 261917617U, 3785641677U, 1439605128U, 1649152283U, - 1493851484U, 1246520657U, 2221159044U, 1973511823U, - 384136800U, 214358653U, 2379473940U, 4269788650U, - 2864377005U, 2638630052U, 427683330U, 990491717U, - 1747111141U, 792127364U, 2599214128U, 2553037199U, - 2509838425U, 1369346549U }, + {2297466611U, 3902465932U, 469785835U, 1937308741U, 261917617U, 3785641677U, 1439605128U, + 1649152283U, 1493851484U, 1246520657U, 2221159044U, 1973511823U, 384136800U, 214358653U, + 2379473940U, 4269788650U, 2864377005U, 2638630052U, 427683330U, 990491717U, 1747111141U, + 792127364U, 2599214128U, 2553037199U, 2509838425U, 1369346549U}, // md5 - { 3195025439U, 2556848621U, 3724893440U, 3332385401U, - 245758794U, 2550894432U, 121710495U, 3053817768U, - 1250994555U, 1862072655U, 2631955953U, 2951528551U, - 1451250070U, 2820856945U, 2060845566U, 3646985608U, - 2138080750U, 217675895U, 2230934345U, 1234361223U, - 3968582726U, 2455685270U, 1293568479U, 199067604U, - 2042482093U, 2642219166U }, + {3195025439U, 2556848621U, 3724893440U, 3332385401U, 245758794U, 2550894432U, 121710495U, + 3053817768U, 1250994555U, 1862072655U, 2631955953U, 2951528551U, 1451250070U, 2820856945U, + 2060845566U, 3646985608U, 2138080750U, 217675895U, 2230934345U, 1234361223U, 3968582726U, + 2455685270U, 1293568479U, 199067604U, 2042482093U, 2642219166U}, // crc - { 10542U, 22009U, 14526U, 19510U, 19432U, 10199U, 20634U, - 9369U, 11511U, 10362U, 7893U, 31289U, 11313U, 9354U, - 7621U, 30628U, 15218U, 25967U, 2695U, 9380U, - 17300U, 28156U, 9192U, 20484U, 16925U, 16719U }, + {10542U, 22009U, 14526U, 19510U, 19432U, 10199U, 20634U, 9369U, 11511U, + 10362U, 7893U, 31289U, 11313U, 9354U, 7621U, 30628U, 15218U, 25967U, + 2695U, 9380U, 17300U, 28156U, 9192U, 20484U, 16925U, 16719U}, // fnv1_64 - { 473199127U, 4148981457U, 3971873300U, 3257986707U, - 1722477987U, 2991193800U, 4147007314U, 3633179701U, - 1805162104U, 3503289120U, 3395702895U, 3325073042U, - 2345265314U, 3340346032U, 2722964135U, 1173398992U, - 2815549194U, 2562818319U, 224996066U, 2680194749U, - 3035305390U, 246890365U, 2395624193U, 4145193337U, - 1801941682U, 2112060110U }, + {473199127U, 4148981457U, 3971873300U, 3257986707U, 1722477987U, 2991193800U, 4147007314U, + 3633179701U, 1805162104U, 3503289120U, 3395702895U, 3325073042U, 2345265314U, 3340346032U, + 2722964135U, 1173398992U, 2815549194U, 2562818319U, 224996066U, 2680194749U, 3035305390U, + 246890365U, 2395624193U, 4145193337U, 1801941682U, 2112060110U}, // fnv1a_64 - { 1488911807U, 2500855813U, 1510099634U, 1390325195U, - 3647689787U, 3241528582U, 1669328060U, 2604311949U, - 734810122U, 1516407546U, 560948863U, 1767346780U, - 561034892U, 4156330026U, 3716417003U, 3475297030U, - 1518272172U, 227211583U, 3938128828U, 126112909U, - 3043416448U, 3131561933U, 1328739897U, 2455664041U, - 2272238452U, 3890508048U }, + {1488911807U, 2500855813U, 1510099634U, 1390325195U, 3647689787U, 3241528582U, 1669328060U, + 2604311949U, 734810122U, 1516407546U, 560948863U, 1767346780U, 561034892U, 4156330026U, + 3716417003U, 3475297030U, 1518272172U, 227211583U, 3938128828U, 126112909U, 3043416448U, + 3131561933U, 1328739897U, 2455664041U, 2272238452U, 3890508048U}, // fnv1_32 - { 67176023U, 1190179409U, 2043204404U, 3221866419U, - 2567703427U, 3787535528U, 4147287986U, 3500475733U, - 344481048U, 3865235296U, 2181839183U, 119581266U, - 510234242U, 4248244304U, 1362796839U, 103389328U, - 1449620010U, 182962511U, 3554262370U, 3206747549U, - 1551306158U, 4127558461U, 1889140833U, 2774173721U, - 1180552018U, 3922226286U }, + {67176023U, 1190179409U, 2043204404U, 3221866419U, 2567703427U, 3787535528U, 4147287986U, + 3500475733U, 344481048U, 3865235296U, 2181839183U, 119581266U, 510234242U, 4248244304U, + 1362796839U, 103389328U, 1449620010U, 182962511U, 3554262370U, 3206747549U, 1551306158U, + 4127558461U, 1889140833U, 2774173721U, 1180552018U, 3922226286U}, // fnv1a_32 - { 280767167U, 2421315013U, 3072375666U, 855001899U, - 459261019U, 3521085446U, 18738364U, 1625305005U, - 2162232970U, 777243802U, 3323728671U, 132336572U, - 3654473228U, 260679466U, 1169454059U, 2698319462U, - 1062177260U, 235516991U, 2218399068U, 405302637U, - 1128467232U, 3579622413U, 2138539289U, 96429129U, - 2877453236U, 76545936U }, + {280767167U, 2421315013U, 3072375666U, 855001899U, 459261019U, 3521085446U, 18738364U, + 1625305005U, 2162232970U, 777243802U, 3323728671U, 132336572U, 3654473228U, 260679466U, + 1169454059U, 2698319462U, 1062177260U, 235516991U, 2218399068U, 405302637U, 1128467232U, + 3579622413U, 2138539289U, 96429129U, 2877453236U, 76545936U}, - // hsieh +// hsieh #ifdef HAVE_HSIEH_HASH - { 3738850110U, 3636226060U, 3821074029U, 3489929160U, 3485772682U, 80540287U, - 1805464076U, 1895033657U, 409795758U, 979934958U, 3634096985U, 1284445480U, - 2265380744U, 707972988U, 353823508U, 1549198350U, 1327930172U, 9304163U, - 4220749037U, 2493964934U, 2777873870U, 2057831732U, 1510213931U, 2027828987U, - 3395453351U, 471461527U }, + {3738850110U, 3636226060U, 3821074029U, 3489929160U, 3485772682U, 80540287U, 1805464076U, + 1895033657U, 409795758U, 979934958U, 3634096985U, 1284445480U, 2265380744U, 707972988U, + 353823508U, 1549198350U, 1327930172U, 9304163U, 4220749037U, 2493964934U, 2777873870U, + 2057831732U, 1510213931U, 2027828987U, 3395453351U, 471461527U}, #else - { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, + {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, #endif - // murmur +// murmur #ifdef HAVE_MURMUR_HASH - { 4142305122U, 734504955U, 3802834688U, 4076891445U, - 387802650U, 560515427U, 3274673488U, 3150339524U, - 1527441970U, 2728642900U, 3613992239U, 2938419259U, - 2321988328U, 1145154116U, 4038540960U, 2224541613U, - 264013145U, 3995512858U, 2400956718U, 2346666219U, - 926327338U, 442757446U, 1770805201U, 560483147U, - 3902279934U, 818385189U }, + {4142305122U, 734504955U, 3802834688U, 4076891445U, 387802650U, 560515427U, 3274673488U, + 3150339524U, 1527441970U, 2728642900U, 3613992239U, 2938419259U, 2321988328U, 1145154116U, + 4038540960U, 2224541613U, 264013145U, 3995512858U, 2400956718U, 2346666219U, 926327338U, + 442757446U, 1770805201U, 560483147U, 3902279934U, 818385189U}, #else - { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, + {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, #endif // jenkins - { 1442444624U, 4253821186U, 1885058256U, 2120131735U, - 3261968576U, 3515188778U, 4232909173U, 4288625128U, - 1812047395U, 3689182164U, 2502979932U, 1214050606U, - 2415988847U, 1494268927U, 1025545760U, 3920481083U, - 4153263658U, 3824871822U, 3072759809U, 798622255U, - 3065432577U, 1453328165U, 2691550971U, 3408888387U, - 2629893356U, 314054204U }, + {1442444624U, 4253821186U, 1885058256U, 2120131735U, 3261968576U, 3515188778U, 4232909173U, + 4288625128U, 1812047395U, 3689182164U, 2502979932U, 1214050606U, 2415988847U, 1494268927U, + 1025545760U, 3920481083U, 4153263658U, 3824871822U, 3072759809U, 798622255U, 3065432577U, + 1453328165U, 2691550971U, 3408888387U, 2629893356U, 314054204U}, - // murmur3 +// murmur3 #ifdef HAVE_MURMUR_HASH - { 1120212521U, 1448785489U, 4186307405U, 2686268514U, - 444808887U, 221750260U, 3074673162U, 1946933257U, - 2826416675U, 2430719166U, 3200429559U, 297894347U, - 732888124U, 4050076964U, 3298336176U, 1336207361U, - 810553576U, 3748182674U, 3860119212U, 3439537197U, - 3044240981U, 1464271804U, 3896193724U, 2915115798U, - 1702843840U, 2603515018U }, + {1120212521U, 1448785489U, 4186307405U, 2686268514U, 444808887U, 221750260U, 3074673162U, + 1946933257U, 2826416675U, 2430719166U, 3200429559U, 297894347U, 732888124U, 4050076964U, + 3298336176U, 1336207361U, 810553576U, 3748182674U, 3860119212U, 3439537197U, 3044240981U, + 1464271804U, 3896193724U, 2915115798U, 1702843840U, 2603515018U}, #else - { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, + {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, #endif }; - diff --git a/test/fixtures/ketama.hpp b/test/fixtures/ketama.hpp index 36c56851..33c77335 100644 --- a/test/fixtures/ketama.hpp +++ b/test/fixtures/ketama.hpp @@ -1,217 +1,230 @@ +/* + +--------------------------------------------------------------------+ + | libmemcached - C/C++ Client Library for memcached | + +--------------------------------------------------------------------+ + | Redistribution and use in source and binary forms, with or without | + | modification, are permitted under the terms of the BSD license. | + | You should have received a copy of the license in a bundled file | + | named LICENSE; in case you did not receive a copy you can review | + | the terms online at: https://opensource.org/licenses/BSD-3-Clause | + +--------------------------------------------------------------------+ + | Copyright (c) 2006-2014 Brian Aker https://datadifferential.com/ | + | Copyright (c) 2020 Michael Wallner | + +--------------------------------------------------------------------+ +*/ + #pragma once static struct { - const char *key; - unsigned long hash1; - unsigned long hash2; - const char *server; -} ketama_test_cases[99]= { - { "SVa_]_V41)", 443691461UL, 445379617UL, "10.0.1.7" }, - { "*/Z;?V(.\\8", 1422915503UL, 1428303028UL, "10.0.1.1" }, - { "30C1*Z*S/_", 1473165754UL, 1480075959UL, "10.0.1.2" }, - { "ERR:EC58G>", 2148406511UL, 2168579133UL, "10.0.1.7" }, - { "1I=cTMNTKF", 2882686667UL, 2885206587UL, "10.0.1.5" }, - { "]VG<`I*Z8)", 1103544263UL, 1104827657UL, "10.0.1.5" }, - { "UUTC`-V159", 3716288206UL, 3727224240UL, "10.0.1.5" }, - { "@7RU6C6T+Z", 3862737685UL, 3871917949UL, "10.0.1.5" }, - { "/XLN0@+36;", 1623269830UL, 1627683651UL, "10.0.1.1" }, - { "4(`X;\\V.^c", 373546328UL, 383925769UL, "10.0.1.1" }, - { "726bW=9*a4", 4213440020UL, 4213950705UL, "10.0.1.7" }, - { "\\`)32", 536016577UL, 539988520UL, "10.0.1.7" }, - { "U))Fb-(`,.", 4128682289UL, 4136854163UL, "10.0.1.7" }, - { "R-08RNTaRT", 3718170086UL, 3727224240UL, "10.0.1.5" }, - { "(LHcO203I3", 1007779411UL, 1014643570UL, "10.0.1.5" }, - { "=256P+;Qc8", 3976201210UL, 3976304873UL, "10.0.1.5" }, - { "OI5XZ_BBT(", 2155922164UL, 2168579133UL, "10.0.1.7" }, - { "2TLRL/UL;:", 1086800909UL, 1095659802UL, "10.0.1.7" }, - { "WHD\\O1`ZRW", 3087923411UL, 3095471560UL, "10.0.1.5" }, - { ".=54)_c;=T", 2497691631UL, 2502731301UL, "10.0.1.1" }, - { ";GE`)FT\\4", 580747448UL, 581063326UL, "10.0.1.2" }, - { "HZAU*;P*N]", 2564670474UL, 2565697267UL, "10.0.1.7" }, - { "NZ@ZE=O84_", 533335275UL, 539988520UL, "10.0.1.7" }, - { "6,cEI`F_P>", 3972869246UL, 3974773167UL, "10.0.1.6" }, - { "c,5AQ/T5)6", 2835605783UL, 2847870057UL, "10.0.1.8" }, - { ".O,>>BT)RX", 3857978174UL, 3871917949UL, "10.0.1.5" }, - { "XY\\X::LX50", 1749241099UL, 1752196488UL, "10.0.1.6" }, - { "+550F^/.01", 3781824099UL, 3783248219UL, "10.0.1.6" }, - { "<.X9E2S5+9", 3232479481UL, 3234387706UL, "10.0.1.7" }, - { "]\\.UH8_0a1", 2419699252UL, 2423002920UL, "10.0.1.4" }, - { "8(6=(T0/Z0", 728266737UL, 729026070UL, "10.0.1.7" }, - { "8*6a;Sc*X+", 4223431086UL, 4230156966UL, "10.0.1.2" }, - { "J5/", 2776949824UL, 2784182515UL, "10.0.1.7" }, - { "[>RZHG97Q9", 71954686UL, 72034069UL, "10.0.1.6" }, - { "J3/G[)9<^Z", 2799896459UL, 2805183696UL, "10.0.1.7" }, - { "N-)88>[O`,", 50404102UL, 51792557UL, "10.0.1.5" }, - { "NP:=FR\\OaA", 3837333776UL, 3837792034UL, "10.0.1.7" }, - { "`@L+W;a,O[", 1512157148UL, 1522285852UL, "10.0.1.6" }, - { "W2`P:-+1T[", 2945171975UL, 2946196424UL, "10.0.1.5" }, - { "-6G7K^YDIN", 3168617340UL, 3170513015UL, "10.0.1.7" }, - { "U>*>9ZI6V5", 668514946UL, 674097631UL, "10.0.1.6" }, - { ".I?^6Ic9RK", 938419020UL, 942832691UL, "10.0.1.6" }, - { "0OZH^9BKM[", 3682518606UL, 3686781297UL, "10.0.1.8" }, - { "5?50UGZ:ML", 868610882UL, 869425986UL, "10.0.1.5" }, - { "?K2NF@3=IU", 381218851UL, 383925769UL, "10.0.1.1" }, - { "YI@G-2X?UB", 3688706179UL, 3693197681UL, "10.0.1.5" }, - { "7cY", 2590140172UL, 2598117636UL, "10.0.1.7" }, - { "\\[a\\^=V_M0", 689410119UL, 698690782UL, "10.0.1.6" }, - { "7;RM+8J9YC", 1530175299UL, 1531107082UL, "10.0.1.7" }, - { "4*=.SPR[AV", 3928582722UL, 3928853792UL, "10.0.1.1" }, - { "-2F+^88P4U", 3023552752UL, 3025823613UL, "10.0.1.7" }, - { "X;-F`(N?9D", 570465234UL, 572485994UL, "10.0.1.7" }, - { "R=F_D-K2a]", 1287750228UL, 1290935562UL, "10.0.1.7" }, - { "X*+2aaC.EG", 3200948713UL, 3201088518UL, "10.0.1.5" }, - { "[1ZXONX2]a", 4108881567UL, 4109865744UL, "10.0.1.4" }, - { "FL;\\GWacaV", 458449508UL, 467374054UL, "10.0.1.4" }, - { "\\MQ_XNT7L-", 1259349383UL, 1259509450UL, "10.0.1.7" }, - { "VD6D0]ba_\\", 3842502950UL, 3842588691UL, "10.0.1.1" }, + const char *key; + unsigned long hash1; + unsigned long hash2; + const char *server; +} ketama_test_cases[99] = { + {"SVa_]_V41)", 443691461UL, 445379617UL, "10.0.1.7"}, + {"*/Z;?V(.\\8", 1422915503UL, 1428303028UL, "10.0.1.1"}, + {"30C1*Z*S/_", 1473165754UL, 1480075959UL, "10.0.1.2"}, + {"ERR:EC58G>", 2148406511UL, 2168579133UL, "10.0.1.7"}, + {"1I=cTMNTKF", 2882686667UL, 2885206587UL, "10.0.1.5"}, + {"]VG<`I*Z8)", 1103544263UL, 1104827657UL, "10.0.1.5"}, + {"UUTC`-V159", 3716288206UL, 3727224240UL, "10.0.1.5"}, + {"@7RU6C6T+Z", 3862737685UL, 3871917949UL, "10.0.1.5"}, + {"/XLN0@+36;", 1623269830UL, 1627683651UL, "10.0.1.1"}, + {"4(`X;\\V.^c", 373546328UL, 383925769UL, "10.0.1.1"}, + {"726bW=9*a4", 4213440020UL, 4213950705UL, "10.0.1.7"}, + {"\\`)32", 536016577UL, 539988520UL, "10.0.1.7"}, + {"U))Fb-(`,.", 4128682289UL, 4136854163UL, "10.0.1.7"}, + {"R-08RNTaRT", 3718170086UL, 3727224240UL, "10.0.1.5"}, + {"(LHcO203I3", 1007779411UL, 1014643570UL, "10.0.1.5"}, + {"=256P+;Qc8", 3976201210UL, 3976304873UL, "10.0.1.5"}, + {"OI5XZ_BBT(", 2155922164UL, 2168579133UL, "10.0.1.7"}, + {"2TLRL/UL;:", 1086800909UL, 1095659802UL, "10.0.1.7"}, + {"WHD\\O1`ZRW", 3087923411UL, 3095471560UL, "10.0.1.5"}, + {".=54)_c;=T", 2497691631UL, 2502731301UL, "10.0.1.1"}, + {";GE`)FT\\4", 580747448UL, 581063326UL, "10.0.1.2"}, + {"HZAU*;P*N]", 2564670474UL, 2565697267UL, "10.0.1.7"}, + {"NZ@ZE=O84_", 533335275UL, 539988520UL, "10.0.1.7"}, + {"6,cEI`F_P>", 3972869246UL, 3974773167UL, "10.0.1.6"}, + {"c,5AQ/T5)6", 2835605783UL, 2847870057UL, "10.0.1.8"}, + {".O,>>BT)RX", 3857978174UL, 3871917949UL, "10.0.1.5"}, + {"XY\\X::LX50", 1749241099UL, 1752196488UL, "10.0.1.6"}, + {"+550F^/.01", 3781824099UL, 3783248219UL, "10.0.1.6"}, + {"<.X9E2S5+9", 3232479481UL, 3234387706UL, "10.0.1.7"}, + {"]\\.UH8_0a1", 2419699252UL, 2423002920UL, "10.0.1.4"}, + {"8(6=(T0/Z0", 728266737UL, 729026070UL, "10.0.1.7"}, + {"8*6a;Sc*X+", 4223431086UL, 4230156966UL, "10.0.1.2"}, + {"J5/", 2776949824UL, 2784182515UL, "10.0.1.7"}, + {"[>RZHG97Q9", 71954686UL, 72034069UL, "10.0.1.6"}, + {"J3/G[)9<^Z", 2799896459UL, 2805183696UL, "10.0.1.7"}, + {"N-)88>[O`,", 50404102UL, 51792557UL, "10.0.1.5"}, + {"NP:=FR\\OaA", 3837333776UL, 3837792034UL, "10.0.1.7"}, + {"`@L+W;a,O[", 1512157148UL, 1522285852UL, "10.0.1.6"}, + {"W2`P:-+1T[", 2945171975UL, 2946196424UL, "10.0.1.5"}, + {"-6G7K^YDIN", 3168617340UL, 3170513015UL, "10.0.1.7"}, + {"U>*>9ZI6V5", 668514946UL, 674097631UL, "10.0.1.6"}, + {".I?^6Ic9RK", 938419020UL, 942832691UL, "10.0.1.6"}, + {"0OZH^9BKM[", 3682518606UL, 3686781297UL, "10.0.1.8"}, + {"5?50UGZ:ML", 868610882UL, 869425986UL, "10.0.1.5"}, + {"?K2NF@3=IU", 381218851UL, 383925769UL, "10.0.1.1"}, + {"YI@G-2X?UB", 3688706179UL, 3693197681UL, "10.0.1.5"}, + {"7cY", 2590140172UL, 2598117636UL, "10.0.1.7"}, + {"\\[a\\^=V_M0", 689410119UL, 698690782UL, "10.0.1.6"}, + {"7;RM+8J9YC", 1530175299UL, 1531107082UL, "10.0.1.7"}, + {"4*=.SPR[AV", 3928582722UL, 3928853792UL, "10.0.1.1"}, + {"-2F+^88P4U", 3023552752UL, 3025823613UL, "10.0.1.7"}, + {"X;-F`(N?9D", 570465234UL, 572485994UL, "10.0.1.7"}, + {"R=F_D-K2a]", 1287750228UL, 1290935562UL, "10.0.1.7"}, + {"X*+2aaC.EG", 3200948713UL, 3201088518UL, "10.0.1.5"}, + {"[1ZXONX2]a", 4108881567UL, 4109865744UL, "10.0.1.4"}, + {"FL;\\GWacaV", 458449508UL, 467374054UL, "10.0.1.4"}, + {"\\MQ_XNT7L-", 1259349383UL, 1259509450UL, "10.0.1.7"}, + {"VD6D0]ba_\\", 3842502950UL, 3842588691UL, "10.0.1.1"}, }; - static struct { const char *key; unsigned long hash1; unsigned long hash2; const char *server; -} ketama_test_cases_spy[99]= { - { "SVa_]_V41)", 443691461UL, 445379617UL, "10.0.1.2" }, - { "*/Z;?V(.\\8", 1422915503UL, 1428303028UL, "10.0.1.4" }, - { "30C1*Z*S/_", 1473165754UL, 1480075959UL, "10.0.1.2" }, - { "ERR:EC58G>", 2148406511UL, 2168579133UL, "10.0.1.7" }, - { "1I=cTMNTKF", 2882686667UL, 2885206587UL, "10.0.1.4" }, - { "]VG<`I*Z8)", 1103544263UL, 1104827657UL, "10.0.1.5" }, - { "UUTC`-V159", 3716288206UL, 3727224240UL, "10.0.1.7" }, - { "@7RU6C6T+Z", 3862737685UL, 3871917949UL, "10.0.1.6" }, - { "/XLN0@+36;", 1623269830UL, 1627683651UL, "10.0.1.7" }, - { "4(`X;\\V.^c", 373546328UL, 383925769UL, "10.0.1.6" }, - { "726bW=9*a4", 4213440020UL, 4213950705UL, "10.0.1.3" }, - { "\\`)32", 536016577UL, 539988520UL, "10.0.1.7" }, - { "U))Fb-(`,.", 4128682289UL, 4136854163UL, "10.0.1.7" }, - { "R-08RNTaRT", 3718170086UL, 3727224240UL, "10.0.1.5" }, - { "(LHcO203I3", 1007779411UL, 1014643570UL, "10.0.1.1" }, - { "=256P+;Qc8", 3976201210UL, 3976304873UL, "10.0.1.3" }, - { "OI5XZ_BBT(", 2155922164UL, 2168579133UL, "10.0.1.5" }, - { "2TLRL/UL;:", 1086800909UL, 1095659802UL, "10.0.1.2" }, - { "WHD\\O1`ZRW", 3087923411UL, 3095471560UL, "10.0.1.1" }, - { ".=54)_c;=T", 2497691631UL, 2502731301UL, "10.0.1.6" }, - { ";GE`)FT\\4", 580747448UL, 581063326UL, "10.0.1.5" }, - { "HZAU*;P*N]", 2564670474UL, 2565697267UL, "10.0.1.1" }, - { "NZ@ZE=O84_", 533335275UL, 539988520UL, "10.0.1.7" }, - { "6,cEI`F_P>", 3972869246UL, 3974773167UL, "10.0.1.3" }, - { "c,5AQ/T5)6", 2835605783UL, 2847870057UL, "10.0.1.7" }, - { ".O,>>BT)RX", 3857978174UL, 3871917949UL, "10.0.1.7" }, - { "XY\\X::LX50", 1749241099UL, 1752196488UL, "10.0.1.7" }, - { "+550F^/.01", 3781824099UL, 3783248219UL, "10.0.1.2" }, - { "<.X9E2S5+9", 3232479481UL, 3234387706UL, "10.0.1.7" }, - { "]\\.UH8_0a1", 2419699252UL, 2423002920UL, "10.0.1.6" }, - { "8(6=(T0/Z0", 728266737UL, 729026070UL, "10.0.1.6" }, - { "8*6a;Sc*X+", 4223431086UL, 4230156966UL, "10.0.1.5" }, - { "J5/", 2776949824UL, 2784182515UL, "10.0.1.6" }, - { "[>RZHG97Q9", 71954686UL, 72034069UL, "10.0.1.4" }, - { "J3/G[)9<^Z", 2799896459UL, 2805183696UL, "10.0.1.6" }, - { "N-)88>[O`,", 50404102UL, 51792557UL, "10.0.1.2" }, - { "NP:=FR\\OaA", 3837333776UL, 3837792034UL, "10.0.1.7" }, - { "`@L+W;a,O[", 1512157148UL, 1522285852UL, "10.0.1.5" }, - { "W2`P:-+1T[", 2945171975UL, 2946196424UL, "10.0.1.7" }, - { "-6G7K^YDIN", 3168617340UL, 3170513015UL, "10.0.1.5" }, - { "U>*>9ZI6V5", 668514946UL, 674097631UL, "10.0.1.5" }, - { ".I?^6Ic9RK", 938419020UL, 942832691UL, "10.0.1.6" }, - { "0OZH^9BKM[", 3682518606UL, 3686781297UL, "10.0.1.2" }, - { "5?50UGZ:ML", 868610882UL, 869425986UL, "10.0.1.6" }, - { "?K2NF@3=IU", 381218851UL, 383925769UL, "10.0.1.6" }, - { "YI@G-2X?UB", 3688706179UL, 3693197681UL, "10.0.1.6" }, - { "7cY", 2590140172UL, 2598117636UL, "10.0.1.5" }, - { "\\[a\\^=V_M0", 689410119UL, 698690782UL, "10.0.1.7" }, - { "7;RM+8J9YC", 1530175299UL, 1531107082UL, "10.0.1.7" }, - { "4*=.SPR[AV", 3928582722UL, 3928853792UL, "10.0.1.3" }, - { "-2F+^88P4U", 3023552752UL, 3025823613UL, "10.0.1.7" }, - { "X;-F`(N?9D", 570465234UL, 572485994UL, "10.0.1.5" }, - { "R=F_D-K2a]", 1287750228UL, 1290935562UL, "10.0.1.1" }, - { "X*+2aaC.EG", 3200948713UL, 3201088518UL, "10.0.1.3" }, - { "[1ZXONX2]a", 4108881567UL, 4109865744UL, "10.0.1.7" }, - { "FL;\\GWacaV", 458449508UL, 467374054UL, "10.0.1.7" }, - { "\\MQ_XNT7L-", 1259349383UL, 1259509450UL, "10.0.1.5" }, - { "VD6D0]ba_\\", 3842502950UL, 3842588691UL, "10.0.1.7" }, +} ketama_test_cases_spy[99] = { + {"SVa_]_V41)", 443691461UL, 445379617UL, "10.0.1.2"}, + {"*/Z;?V(.\\8", 1422915503UL, 1428303028UL, "10.0.1.4"}, + {"30C1*Z*S/_", 1473165754UL, 1480075959UL, "10.0.1.2"}, + {"ERR:EC58G>", 2148406511UL, 2168579133UL, "10.0.1.7"}, + {"1I=cTMNTKF", 2882686667UL, 2885206587UL, "10.0.1.4"}, + {"]VG<`I*Z8)", 1103544263UL, 1104827657UL, "10.0.1.5"}, + {"UUTC`-V159", 3716288206UL, 3727224240UL, "10.0.1.7"}, + {"@7RU6C6T+Z", 3862737685UL, 3871917949UL, "10.0.1.6"}, + {"/XLN0@+36;", 1623269830UL, 1627683651UL, "10.0.1.7"}, + {"4(`X;\\V.^c", 373546328UL, 383925769UL, "10.0.1.6"}, + {"726bW=9*a4", 4213440020UL, 4213950705UL, "10.0.1.3"}, + {"\\`)32", 536016577UL, 539988520UL, "10.0.1.7"}, + {"U))Fb-(`,.", 4128682289UL, 4136854163UL, "10.0.1.7"}, + {"R-08RNTaRT", 3718170086UL, 3727224240UL, "10.0.1.5"}, + {"(LHcO203I3", 1007779411UL, 1014643570UL, "10.0.1.1"}, + {"=256P+;Qc8", 3976201210UL, 3976304873UL, "10.0.1.3"}, + {"OI5XZ_BBT(", 2155922164UL, 2168579133UL, "10.0.1.5"}, + {"2TLRL/UL;:", 1086800909UL, 1095659802UL, "10.0.1.2"}, + {"WHD\\O1`ZRW", 3087923411UL, 3095471560UL, "10.0.1.1"}, + {".=54)_c;=T", 2497691631UL, 2502731301UL, "10.0.1.6"}, + {";GE`)FT\\4", 580747448UL, 581063326UL, "10.0.1.5"}, + {"HZAU*;P*N]", 2564670474UL, 2565697267UL, "10.0.1.1"}, + {"NZ@ZE=O84_", 533335275UL, 539988520UL, "10.0.1.7"}, + {"6,cEI`F_P>", 3972869246UL, 3974773167UL, "10.0.1.3"}, + {"c,5AQ/T5)6", 2835605783UL, 2847870057UL, "10.0.1.7"}, + {".O,>>BT)RX", 3857978174UL, 3871917949UL, "10.0.1.7"}, + {"XY\\X::LX50", 1749241099UL, 1752196488UL, "10.0.1.7"}, + {"+550F^/.01", 3781824099UL, 3783248219UL, "10.0.1.2"}, + {"<.X9E2S5+9", 3232479481UL, 3234387706UL, "10.0.1.7"}, + {"]\\.UH8_0a1", 2419699252UL, 2423002920UL, "10.0.1.6"}, + {"8(6=(T0/Z0", 728266737UL, 729026070UL, "10.0.1.6"}, + {"8*6a;Sc*X+", 4223431086UL, 4230156966UL, "10.0.1.5"}, + {"J5/", 2776949824UL, 2784182515UL, "10.0.1.6"}, + {"[>RZHG97Q9", 71954686UL, 72034069UL, "10.0.1.4"}, + {"J3/G[)9<^Z", 2799896459UL, 2805183696UL, "10.0.1.6"}, + {"N-)88>[O`,", 50404102UL, 51792557UL, "10.0.1.2"}, + {"NP:=FR\\OaA", 3837333776UL, 3837792034UL, "10.0.1.7"}, + {"`@L+W;a,O[", 1512157148UL, 1522285852UL, "10.0.1.5"}, + {"W2`P:-+1T[", 2945171975UL, 2946196424UL, "10.0.1.7"}, + {"-6G7K^YDIN", 3168617340UL, 3170513015UL, "10.0.1.5"}, + {"U>*>9ZI6V5", 668514946UL, 674097631UL, "10.0.1.5"}, + {".I?^6Ic9RK", 938419020UL, 942832691UL, "10.0.1.6"}, + {"0OZH^9BKM[", 3682518606UL, 3686781297UL, "10.0.1.2"}, + {"5?50UGZ:ML", 868610882UL, 869425986UL, "10.0.1.6"}, + {"?K2NF@3=IU", 381218851UL, 383925769UL, "10.0.1.6"}, + {"YI@G-2X?UB", 3688706179UL, 3693197681UL, "10.0.1.6"}, + {"7cY", 2590140172UL, 2598117636UL, "10.0.1.5"}, + {"\\[a\\^=V_M0", 689410119UL, 698690782UL, "10.0.1.7"}, + {"7;RM+8J9YC", 1530175299UL, 1531107082UL, "10.0.1.7"}, + {"4*=.SPR[AV", 3928582722UL, 3928853792UL, "10.0.1.3"}, + {"-2F+^88P4U", 3023552752UL, 3025823613UL, "10.0.1.7"}, + {"X;-F`(N?9D", 570465234UL, 572485994UL, "10.0.1.5"}, + {"R=F_D-K2a]", 1287750228UL, 1290935562UL, "10.0.1.1"}, + {"X*+2aaC.EG", 3200948713UL, 3201088518UL, "10.0.1.3"}, + {"[1ZXONX2]a", 4108881567UL, 4109865744UL, "10.0.1.7"}, + {"FL;\\GWacaV", 458449508UL, 467374054UL, "10.0.1.7"}, + {"\\MQ_XNT7L-", 1259349383UL, 1259509450UL, "10.0.1.5"}, + {"VD6D0]ba_\\", 3842502950UL, 3842588691UL, "10.0.1.7"}, }; - diff --git a/test/fixtures/parser.hpp b/test/fixtures/parser.hpp index 2c72302d..349e3986 100644 --- a/test/fixtures/parser.hpp +++ b/test/fixtures/parser.hpp @@ -1,3 +1,18 @@ +/* + +--------------------------------------------------------------------+ + | libmemcached - C/C++ Client Library for memcached | + +--------------------------------------------------------------------+ + | Redistribution and use in source and binary forms, with or without | + | modification, are permitted under the terms of the BSD license. | + | You should have received a copy of the license in a bundled file | + | named LICENSE; in case you did not receive a copy you can review | + | the terms online at: https://opensource.org/licenses/BSD-3-Clause | + +--------------------------------------------------------------------+ + | Copyright (c) 2006-2014 Brian Aker https://datadifferential.com/ | + | Copyright (c) 2020 Michael Wallner | + +--------------------------------------------------------------------+ +*/ + #pragma once #include @@ -12,14 +27,9 @@ struct c_string { c_string(const char *s, size_t l) noexcept : c_str{s} - , size{l} - {} - bool operator ==(const c_string &cs) const noexcept { - return !strcmp(c_str, cs.c_str); - } - bool operator ==(const char *p) const noexcept { - return !strcmp(c_str, p); - } + , size{l} {} + bool operator==(const c_string &cs) const noexcept { return !strcmp(c_str, cs.c_str); } + bool operator==(const char *p) const noexcept { return !strcmp(c_str, p); } }; static c_string null_c_string{nullptr, 0}; @@ -33,23 +43,19 @@ struct test_case { test_case(c_string o, c_string r) noexcept : option{o} - , result{r} - {} + , result{r} {} test_case(const char *os, size_t ol, const char *rs, size_t rl) noexcept : option{os, ol} - , result{c_string{rs, rl}} - {} + , result{c_string{rs, rl}} {} test_case(const char *os, size_t ol, memcached_behavior_t b, uint64_t v) noexcept - : option{os, ol} - , result{setting_t{b, v}} - {} + : option{os, ol} + , result{setting_t{b, v}} {} test_case(const char *os, size_t ol, memcached_flag_t f, uint64_t v) noexcept - : option{os, ol} - , result{setting_t{f, v}} - {} + : option{os, ol} + , result{setting_t{f, v}} {} }; -#define test_count(tca) (sizeof(tca)/sizeof(tca[0])) +#define test_count(tca) (sizeof(tca) / sizeof(tca[0])) struct test_group { using check_func = function; @@ -62,36 +68,35 @@ struct test_group { : name{name_} , check{move(check_)} , tests{tests_} - , ntests{ntests_} - {} + , ntests{ntests_} {} }; static test_case host_string_tests[] = { - {S("--server=localhost"), S("localhost")}, - {S("--server=10.0.2.1"), S("10.0.2.1")}, - {S("--server=example.com"), S("example.com")}, - {S("--server=localhost:30"), S("localhost")}, - {S("--server=10.0.2.1:20"), S("10.0.2.1")}, - {S("--server=example.com:1024"), S("example.com")}, - {S("--server=10.0.2.1:30/?40"), S("10.0.2.1")}, - {S("--server=example.com:1024/?30"), S("example.com")}, - {S("--server=10.0.2.1/?20"), S("10.0.2.1")}, - {S("--server=example.com/?10"), S("example.com")}, + {S("--server=localhost"), S("localhost")}, + {S("--server=10.0.2.1"), S("10.0.2.1")}, + {S("--server=example.com"), S("example.com")}, + {S("--server=localhost:30"), S("localhost")}, + {S("--server=10.0.2.1:20"), S("10.0.2.1")}, + {S("--server=example.com:1024"), S("example.com")}, + {S("--server=10.0.2.1:30/?40"), S("10.0.2.1")}, + {S("--server=example.com:1024/?30"), S("example.com")}, + {S("--server=10.0.2.1/?20"), S("10.0.2.1")}, + {S("--server=example.com/?10"), S("example.com")}, }; static test_group test_host_strings{ - "host strings", - [](memcached_st *memc, const test_case::result_t &result) { - auto instance = memcached_server_instance_by_position(memc, 0); - REQUIRE(instance); - REQUIRE(get(result) == memcached_server_name(instance)); - }, - host_string_tests, - test_count(host_string_tests) -}; + "host strings", + [](memcached_st *memc, const test_case::result_t &result) { + auto instance = memcached_server_instance_by_position(memc, 0); + REQUIRE(instance); + REQUIRE(get(result) == memcached_server_name(instance)); + }, + host_string_tests, test_count(host_string_tests)}; static test_case bad_host_string_tests[] = { - {{S("-servers=localhost:11221,localhost:11222,localhost:11223,localhost:11224,localhost:11225")}, null_c_string}, + {{S("-servers=localhost:11221,localhost:11222,localhost:11223,localhost:11224,localhost:" + "11225")}, + null_c_string}, {{S("-- servers=a.example.com:81,localhost:82,b.example.com")}, null_c_string}, {{S("--servers=localhost:+80")}, null_c_string}, // all of the following should not fail IMO @@ -101,13 +106,9 @@ static test_case bad_host_string_tests[] = { }; static test_group test_bad_host_strings{ - "bad host strings", - [](memcached_st *memc, const test_case::result_t &) { - REQUIRE_FALSE(memc); - }, - bad_host_string_tests, - test_count(bad_host_string_tests) -}; + "bad host strings", + [](memcached_st *memc, const test_case::result_t &) { REQUIRE_FALSE(memc); }, + bad_host_string_tests, test_count(bad_host_string_tests)}; static test_case behavior_tests[] = { {S("--CONNECT-TIMEOUT=456"), MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT, 456}, @@ -133,10 +134,14 @@ static test_case behavior_tests[] = { {S("--TCP-KEEPIDLE"), MEMCACHED_BEHAVIOR_TCP_KEEPIDLE, 1}, {S("--USE-UDP"), MEMCACHED_BEHAVIOR_USE_UDP, 1}, {S("--VERIFY-KEY"), MEMCACHED_BEHAVIOR_VERIFY_KEY, 1}, - {S("--DISTRIBUTION=consistent"), MEMCACHED_BEHAVIOR_DISTRIBUTION, MEMCACHED_DISTRIBUTION_CONSISTENT}, - {S("--DISTRIBUTION=consistent,CRC"), MEMCACHED_BEHAVIOR_DISTRIBUTION, MEMCACHED_DISTRIBUTION_CONSISTENT}, - {S("--DISTRIBUTION=consistent,MD5"), MEMCACHED_BEHAVIOR_DISTRIBUTION, MEMCACHED_DISTRIBUTION_CONSISTENT}, - {S("--DISTRIBUTION=consistent,JENKINS"), MEMCACHED_BEHAVIOR_KETAMA_HASH, MEMCACHED_HASH_JENKINS}, + {S("--DISTRIBUTION=consistent"), MEMCACHED_BEHAVIOR_DISTRIBUTION, + MEMCACHED_DISTRIBUTION_CONSISTENT}, + {S("--DISTRIBUTION=consistent,CRC"), MEMCACHED_BEHAVIOR_DISTRIBUTION, + MEMCACHED_DISTRIBUTION_CONSISTENT}, + {S("--DISTRIBUTION=consistent,MD5"), MEMCACHED_BEHAVIOR_DISTRIBUTION, + MEMCACHED_DISTRIBUTION_CONSISTENT}, + {S("--DISTRIBUTION=consistent,JENKINS"), MEMCACHED_BEHAVIOR_KETAMA_HASH, + MEMCACHED_HASH_JENKINS}, {S("--DISTRIBUTION=random"), MEMCACHED_BEHAVIOR_DISTRIBUTION, MEMCACHED_DISTRIBUTION_RANDOM}, {S("--DISTRIBUTION=modula"), MEMCACHED_BEHAVIOR_DISTRIBUTION, MEMCACHED_DISTRIBUTION_MODULA}, {S("--HASH=CRC"), MEMCACHED_BEHAVIOR_HASH, MEMCACHED_HASH_CRC}, @@ -148,16 +153,14 @@ static test_case behavior_tests[] = { }; static test_group test_behaviors{ - "behaviors", - [](memcached_st *memc, const test_case::result_t &result) { - auto setting = get(result); - REQUIRE(memc); - REQUIRE(setting.second == - memcached_behavior_get(memc, get(setting.first))); - }, - behavior_tests, - test_count(behavior_tests) -}; + "behaviors", + [](memcached_st *memc, const test_case::result_t &result) { + auto setting = get(result); + REQUIRE(memc); + REQUIRE(setting.second + == memcached_behavior_get(memc, get(setting.first))); + }, + behavior_tests, test_count(behavior_tests)}; static test_case flag_tests[] = { {S("--FETCH-VERSION"), MEMCACHED_FLAG_IS_FETCHING_VERSION, 1}, @@ -165,32 +168,28 @@ static test_case flag_tests[] = { }; static test_group test_flags{ - "flags", - [](memcached_st *memc, const test_case::result_t &result) { - auto setting = get(result); - REQUIRE(memc); - REQUIRE(setting.second == memcached_flag(*memc, get(setting.first))); - }, - flag_tests, - test_count(flag_tests) -}; + "flags", + [](memcached_st *memc, const test_case::result_t &result) { + auto setting = get(result); + REQUIRE(memc); + REQUIRE(setting.second == memcached_flag(*memc, get(setting.first))); + }, + flag_tests, test_count(flag_tests)}; static test_case namespace_tests[] = { {S("--NAMESPACE=foo"), S("foo")}, {S("--NAMESPACE=\"foo\""), S("foo")}, - {S("--NAMESPACE=\"The quick brown fox jumps over the lazy dog\""), S("The quick brown fox jumps over the lazy dog")}, + {S("--NAMESPACE=\"The quick brown fox jumps over the lazy dog\""), + S("The quick brown fox jumps over the lazy dog")}, }; -static test_group test_namespace{ - "namespace", - [](memcached_st *memc, const test_case::result_t &result) { - auto ns = get(result); - REQUIRE(memc); - REQUIRE(ns == memcached_get_namespace(*memc)); - }, - namespace_tests, - test_count(namespace_tests) -}; +static test_group test_namespace{"namespace", + [](memcached_st *memc, const test_case::result_t &result) { + auto ns = get(result); + REQUIRE(memc); + REQUIRE(ns == memcached_get_namespace(*memc)); + }, + namespace_tests, test_count(namespace_tests)}; static test_group tests[] = { test_host_strings, diff --git a/test/lib/Cluster.hpp b/test/lib/Cluster.hpp index 1bbc9d22..c6c0cb92 100644 --- a/test/lib/Cluster.hpp +++ b/test/lib/Cluster.hpp @@ -1,3 +1,18 @@ +/* + +--------------------------------------------------------------------+ + | libmemcached - C/C++ Client Library for memcached | + +--------------------------------------------------------------------+ + | Redistribution and use in source and binary forms, with or without | + | modification, are permitted under the terms of the BSD license. | + | You should have received a copy of the license in a bundled file | + | named LICENSE; in case you did not receive a copy you can review | + | the terms online at: https://opensource.org/licenses/BSD-3-Clause | + +--------------------------------------------------------------------+ + | Copyright (c) 2006-2014 Brian Aker https://datadifferential.com/ | + | Copyright (c) 2020 Michael Wallner | + +--------------------------------------------------------------------+ +*/ + #pragma once #include "common.hpp" @@ -5,20 +20,18 @@ class Cluster { public: - explicit - Cluster(Server serv, uint16_t cnt = 0); + explicit Cluster(Server serv, uint16_t cnt = 0); ~Cluster(); Cluster(const Cluster &c) = delete; - Cluster &operator = (const Cluster &c) = delete; + Cluster &operator=(const Cluster &c) = delete; Cluster(Cluster &&c) - : proto{} - { + : proto{} { *this = move(c); }; - Cluster &operator = (Cluster &&c) { + Cluster &operator=(Cluster &&c) { count = exchange(c.count, 0); proto = exchange(c.proto, Server{}); cluster = exchange(c.cluster, {}); diff --git a/test/lib/Connection.hpp b/test/lib/Connection.hpp index 8571759e..380116e6 100644 --- a/test/lib/Connection.hpp +++ b/test/lib/Connection.hpp @@ -1,3 +1,18 @@ +/* + +--------------------------------------------------------------------+ + | libmemcached - C/C++ Client Library for memcached | + +--------------------------------------------------------------------+ + | Redistribution and use in source and binary forms, with or without | + | modification, are permitted under the terms of the BSD license. | + | You should have received a copy of the license in a bundled file | + | named LICENSE; in case you did not receive a copy you can review | + | the terms online at: https://opensource.org/licenses/BSD-3-Clause | + +--------------------------------------------------------------------+ + | Copyright (c) 2006-2014 Brian Aker https://datadifferential.com/ | + | Copyright (c) 2020 Michael Wallner | + +--------------------------------------------------------------------+ +*/ + #pragma once #include "common.hpp" @@ -14,10 +29,10 @@ public: void swap(Connection &conn); Connection(const Connection &conn); - Connection &operator = (const Connection &conn); + Connection &operator=(const Connection &conn); - Connection(Connection &&conn) noexcept ; - Connection &operator = (Connection &&conn) noexcept ; + Connection(Connection &&conn) noexcept; + Connection &operator=(Connection &&conn) noexcept; int getError(); int getLastError(); diff --git a/test/lib/ForkAndExec.hpp b/test/lib/ForkAndExec.hpp index ad7b4151..66d93f8e 100644 --- a/test/lib/ForkAndExec.hpp +++ b/test/lib/ForkAndExec.hpp @@ -1,3 +1,18 @@ +/* + +--------------------------------------------------------------------+ + | libmemcached - C/C++ Client Library for memcached | + +--------------------------------------------------------------------+ + | Redistribution and use in source and binary forms, with or without | + | modification, are permitted under the terms of the BSD license. | + | You should have received a copy of the license in a bundled file | + | named LICENSE; in case you did not receive a copy you can review | + | the terms online at: https://opensource.org/licenses/BSD-3-Clause | + +--------------------------------------------------------------------+ + | Copyright (c) 2006-2014 Brian Aker https://datadifferential.com/ | + | Copyright (c) 2020 Michael Wallner | + +--------------------------------------------------------------------+ +*/ + #pragma once #include "common.hpp" @@ -10,13 +25,12 @@ public: ~ForkAndExec(); ForkAndExec(const ForkAndExec &) = delete; - ForkAndExec &operator = (const ForkAndExec &) = delete; + ForkAndExec &operator=(const ForkAndExec &) = delete; ForkAndExec(ForkAndExec &&) = default; - ForkAndExec &operator = (ForkAndExec &&) = default; + ForkAndExec &operator=(ForkAndExec &&) = default; - [[nodiscard]] - int createPipe(); - pid_t operator () (); + [[nodiscard]] int createPipe(); + pid_t operator()(); private: int ready[2], pipes[2]; diff --git a/test/lib/MemcachedCluster.hpp b/test/lib/MemcachedCluster.hpp index 0a4dcb6b..202d878d 100644 --- a/test/lib/MemcachedCluster.hpp +++ b/test/lib/MemcachedCluster.hpp @@ -1,10 +1,24 @@ +/* + +--------------------------------------------------------------------+ + | libmemcached - C/C++ Client Library for memcached | + +--------------------------------------------------------------------+ + | Redistribution and use in source and binary forms, with or without | + | modification, are permitted under the terms of the BSD license. | + | You should have received a copy of the license in a bundled file | + | named LICENSE; in case you did not receive a copy you can review | + | the terms online at: https://opensource.org/licenses/BSD-3-Clause | + +--------------------------------------------------------------------+ + | Copyright (c) 2006-2014 Brian Aker https://datadifferential.com/ | + | Copyright (c) 2020 Michael Wallner | + +--------------------------------------------------------------------+ +*/ + #pragma once #include "common.hpp" #include "Cluster.hpp" #include "ReturnMatcher.hpp" - class MemcachedCluster { public: using behavior_t = pair; diff --git a/test/lib/Retry.hpp b/test/lib/Retry.hpp index 04c0466d..dba843ba 100644 --- a/test/lib/Retry.hpp +++ b/test/lib/Retry.hpp @@ -1,19 +1,32 @@ +/* + +--------------------------------------------------------------------+ + | libmemcached - C/C++ Client Library for memcached | + +--------------------------------------------------------------------+ + | Redistribution and use in source and binary forms, with or without | + | modification, are permitted under the terms of the BSD license. | + | You should have received a copy of the license in a bundled file | + | named LICENSE; in case you did not receive a copy you can review | + | the terms online at: https://opensource.org/licenses/BSD-3-Clause | + +--------------------------------------------------------------------+ + | Copyright (c) 2006-2014 Brian Aker https://datadifferential.com/ | + | Copyright (c) 2020 Michael Wallner | + +--------------------------------------------------------------------+ +*/ + #pragma once #include "common.hpp" class Retry { public: - using predicate = function; explicit Retry(predicate pred_, unsigned max_ = 10, chrono::milliseconds sleep_for_ = 100ms); - bool operator () (); + bool operator()(); private: unsigned max; chrono::milliseconds sleep_for; predicate pred; }; - diff --git a/test/lib/ReturnMatcher.hpp b/test/lib/ReturnMatcher.hpp index 48c9ca28..5de5b3b2 100644 --- a/test/lib/ReturnMatcher.hpp +++ b/test/lib/ReturnMatcher.hpp @@ -1,22 +1,37 @@ +/* + +--------------------------------------------------------------------+ + | libmemcached - C/C++ Client Library for memcached | + +--------------------------------------------------------------------+ + | Redistribution and use in source and binary forms, with or without | + | modification, are permitted under the terms of the BSD license. | + | You should have received a copy of the license in a bundled file | + | named LICENSE; in case you did not receive a copy you can review | + | the terms online at: https://opensource.org/licenses/BSD-3-Clause | + +--------------------------------------------------------------------+ + | Copyright (c) 2006-2014 Brian Aker https://datadifferential.com/ | + | Copyright (c) 2020 Michael Wallner | + +--------------------------------------------------------------------+ +*/ + #pragma once #include "test/lib/common.hpp" class ReturnMatcher : public Catch::MatcherBase { public: - explicit ReturnMatcher(const memcached_st *memc_, memcached_return_t expected_ = MEMCACHED_SUCCESS) - : memc{memc_} - , expected{expected_} - {} + explicit ReturnMatcher(const memcached_st *memc_, + memcached_return_t expected_ = MEMCACHED_SUCCESS) + : memc{memc_} + , expected{expected_} {} ReturnMatcher(const ReturnMatcher &) = default; ReturnMatcher(ReturnMatcher &&rm); - ReturnMatcher &operator = (ReturnMatcher &&rm); + ReturnMatcher &operator=(ReturnMatcher &&rm); bool match(const memcached_return_t &arg) const override; ReturnMatcher success(); - ReturnMatcher operator () (memcached_return_t expected_); + ReturnMatcher operator()(memcached_return_t expected_); protected: string describe() const override; @@ -29,6 +44,6 @@ private: class LoneReturnMatcher { public: ReturnMatcher returns; - explicit LoneReturnMatcher(const memcached_st *memc) : returns{memc} - {} + explicit LoneReturnMatcher(const memcached_st *memc) + : returns{memc} {} }; diff --git a/test/lib/Server.hpp b/test/lib/Server.hpp index f37c79a5..5e263267 100644 --- a/test/lib/Server.hpp +++ b/test/lib/Server.hpp @@ -1,3 +1,18 @@ +/* + +--------------------------------------------------------------------+ + | libmemcached - C/C++ Client Library for memcached | + +--------------------------------------------------------------------+ + | Redistribution and use in source and binary forms, with or without | + | modification, are permitted under the terms of the BSD license. | + | You should have received a copy of the license in a bundled file | + | named LICENSE; in case you did not receive a copy you can review | + | the terms online at: https://opensource.org/licenses/BSD-3-Clause | + +--------------------------------------------------------------------+ + | Copyright (c) 2006-2014 Brian Aker https://datadifferential.com/ | + | Copyright (c) 2020 Michael Wallner | + +--------------------------------------------------------------------+ +*/ + #pragma once #include "common.hpp" @@ -7,7 +22,6 @@ class Server { public: - friend class Cluster; using arg_func_t = function; @@ -15,18 +29,15 @@ public: using arg_pair_t = pair; using argv_t = vector>; - explicit - Server(string binary_ = "false", argv_t args_ = {}); + explicit Server(string binary_ = "false", argv_t args_ = {}); ~Server(); Server(const Server &s); - Server &operator = (const Server &s); + Server &operator=(const Server &s); - Server(Server &&s) { - *this = move(s); - }; - Server &operator = (Server &&s) { + Server(Server &&s) { *this = move(s); }; + Server &operator=(Server &&s) { binary = exchange(s.binary, "false"); args = exchange(s.args, {}); pid = exchange(s.pid, 0); @@ -49,9 +60,7 @@ public: int pipe; ChildProc(pid_t pid_, int pipe_) : pid{pid_} - , pipe{pipe_} - { - } + , pipe{pipe_} {} }; optional start(); bool stop(); @@ -65,7 +74,6 @@ public: bool tryWait(); string &drain(); - private: string binary; argv_t args; @@ -77,12 +85,11 @@ private: socket_or_port_t socket_or_port = 11211; string output; - [[nodiscard]] - vector createArgv(); + [[nodiscard]] vector createArgv(); optional handleArg(vector &arr, const string &arg, const arg_func_t &next_arg); }; -inline ostream &operator << (ostream &out, const socket_or_port_t sop) { +inline ostream &operator<<(ostream &out, const socket_or_port_t sop) { if (holds_alternative(sop)) { out << get(sop); } else { @@ -91,7 +98,8 @@ inline ostream &operator << (ostream &out, const socket_or_port_t sop) { return out; } -inline ostream &operator << (ostream &out, const Server &server) { - out << "Server{binary=" << server.getBinary() << ",pid=" << server.getPid() << ",conn=" << server.getSocketOrPort() << "}"; +inline ostream &operator<<(ostream &out, const Server &server) { + out << "Server{binary=" << server.getBinary() << ",pid=" << server.getPid() + << ",conn=" << server.getSocketOrPort() << "}"; return out; } diff --git a/test/lib/Shell.hpp b/test/lib/Shell.hpp index d61f8ceb..a1496bb5 100644 --- a/test/lib/Shell.hpp +++ b/test/lib/Shell.hpp @@ -1,3 +1,18 @@ +/* + +--------------------------------------------------------------------+ + | libmemcached - C/C++ Client Library for memcached | + +--------------------------------------------------------------------+ + | Redistribution and use in source and binary forms, with or without | + | modification, are permitted under the terms of the BSD license. | + | You should have received a copy of the license in a bundled file | + | named LICENSE; in case you did not receive a copy you can review | + | the terms online at: https://opensource.org/licenses/BSD-3-Clause | + +--------------------------------------------------------------------+ + | Copyright (c) 2006-2014 Brian Aker https://datadifferential.com/ | + | Copyright (c) 2020 Michael Wallner | + +--------------------------------------------------------------------+ +*/ + #pragma once #include "test/lib/common.hpp" @@ -8,6 +23,7 @@ public: explicit Shell(const string &prefix, bool redirect_stderr = true); bool run(const string &command, string &output); bool run(const string &command); + private: string prefix; bool redirect; diff --git a/test/lib/common.hpp b/test/lib/common.hpp index b5ef3525..a76a1ca8 100644 --- a/test/lib/common.hpp +++ b/test/lib/common.hpp @@ -1,3 +1,18 @@ +/* + +--------------------------------------------------------------------+ + | libmemcached - C/C++ Client Library for memcached | + +--------------------------------------------------------------------+ + | Redistribution and use in source and binary forms, with or without | + | modification, are permitted under the terms of the BSD license. | + | You should have received a copy of the license in a bundled file | + | named LICENSE; in case you did not receive a copy you can review | + | the terms online at: https://opensource.org/licenses/BSD-3-Clause | + +--------------------------------------------------------------------+ + | Copyright (c) 2006-2014 Brian Aker https://datadifferential.com/ | + | Copyright (c) 2020 Michael Wallner | + +--------------------------------------------------------------------+ +*/ + #pragma once #include @@ -23,22 +38,25 @@ using socket_or_port_t = variant; /** * Useful macros for testing */ -#define S(s) (s),strlen(s) +#define S(s) (s), strlen(s) #define DECLARE_STREQUAL static auto strequal = equal_to(); #define LOOPED_SECTION(tests) \ for (auto &[name, test] : tests) DYNAMIC_SECTION("test " << name) -#define REQUIRE_SUCCESS(rc) do { \ - INFO("expected: SUCCESS"); \ +#define REQUIRE_SUCCESS(rc) \ + do { \ + INFO("expected: SUCCESS"); \ REQUIRE_THAT(rc, test.returns.success()); \ - } while(0) -#define REQUIRE_RC(rc, call) do { \ + } while (0) +#define REQUIRE_RC(rc, call) \ + do { \ INFO("expected: " << memcached_strerror(nullptr, rc)); \ - REQUIRE_THAT(call, test.returns(rc)); \ - } while(0) + REQUIRE_THAT(call, test.returns(rc)); \ + } while (0) const char *getenv_else(const char *var, const char *defval); -inline memcached_return_t fetch_all_results(memcached_st *memc, unsigned int &keys_returned, memcached_return_t &rc) { +inline memcached_return_t fetch_all_results(memcached_st *memc, unsigned int &keys_returned, + memcached_return_t &rc) { keys_returned = 0; memcached_result_st *result = nullptr; @@ -62,22 +80,19 @@ inline memcached_return_t fetch_all_results(memcached_st *memc, unsigned int &ke class Tempfile { public: explicit Tempfile(const char templ_[] = "memc.test.XXXXXX") { - *copy(S(templ_)+templ_, fn) = '\0'; + *copy(S(templ_) + templ_, fn) = '\0'; fd = mkstemp(fn); } ~Tempfile() { close(fd); unlink(fn); } - int getFd() const { - return fd; - } - const char *getFn() const { - return fn; - } + int getFd() const { return fd; } + const char *getFn() const { return fn; } bool put(const char *buf, size_t len) const { - return static_cast(len) == write(fd, buf, len); + return static_cast(len) == write(fd, buf, len); } + private: char fn[80]; int fd; @@ -87,32 +102,21 @@ class MemcachedPtr { public: memcached_st *memc; - explicit - MemcachedPtr(memcached_st *memc_) { - memc = memc_; - } + explicit MemcachedPtr(memcached_st *memc_) { memc = memc_; } MemcachedPtr() - : MemcachedPtr(memcached_create(nullptr)) - {} - ~MemcachedPtr() { - memcached_free(memc); - } - memcached_st *operator * () const { - return memc; - } - auto operator ->() const{ - return memc; - } + : MemcachedPtr(memcached_create(nullptr)) {} + ~MemcachedPtr() { memcached_free(memc); } + memcached_st *operator*() const { return memc; } + auto operator->() const { return memc; } }; template class Malloced { T *ptr; + public: - explicit - Malloced(T *ptr_) - : ptr{ptr_} - {} + explicit Malloced(T *ptr_) + : ptr{ptr_} {} Malloced &operator=(T *ptr_) { if (ptr) free(ptr); @@ -120,13 +124,9 @@ public: return *this; } ~Malloced() { - if(ptr) + if (ptr) free(ptr); } - auto operator *() { - return ptr; - } - auto operator ->() { - return ptr; - } + auto operator*() { return ptr; } + auto operator->() { return ptr; } }; diff --git a/test/lib/env.hpp b/test/lib/env.hpp index 105fef5d..6bc4da66 100644 --- a/test/lib/env.hpp +++ b/test/lib/env.hpp @@ -1,3 +1,18 @@ +/* + +--------------------------------------------------------------------+ + | libmemcached - C/C++ Client Library for memcached | + +--------------------------------------------------------------------+ + | Redistribution and use in source and binary forms, with or without | + | modification, are permitted under the terms of the BSD license. | + | You should have received a copy of the license in a bundled file | + | named LICENSE; in case you did not receive a copy you can review | + | the terms online at: https://opensource.org/licenses/BSD-3-Clause | + +--------------------------------------------------------------------+ + | Copyright (c) 2006-2014 Brian Aker https://datadifferential.com/ | + | Copyright (c) 2020 Michael Wallner | + +--------------------------------------------------------------------+ +*/ + #pragma once #include "mem_config.h" @@ -5,14 +20,15 @@ #include #if HAVE_SETENV -# define SET_ENV_EX(n, k, v, overwrite) setenv(k, v, (overwrite)) +# define SET_ENV_EX(n, k, v, overwrite) setenv(k, v, (overwrite)) #else // !HAVE_SETENV -# define SET_ENV_EX(n, k, v, overwrite) do { \ - static char n ## _env[] = k "=" v; \ - if ((overwrite) || !getenv(k)) { \ - putenv(n ## _env); \ - } \ -} while(false) +# define SET_ENV_EX(n, k, v, overwrite) \ + do { \ + static char n##_env[] = k "=" v; \ + if ((overwrite) || !getenv(k)) { \ + putenv(n##_env); \ + } \ + } while (false) #endif #define SET_ENV(symbolic_name, literal_env_var, literal_env_val) \ diff --git a/test/lib/random.hpp b/test/lib/random.hpp index 1984e89c..1d7f7a6f 100644 --- a/test/lib/random.hpp +++ b/test/lib/random.hpp @@ -1,3 +1,18 @@ +/* + +--------------------------------------------------------------------+ + | libmemcached - C/C++ Client Library for memcached | + +--------------------------------------------------------------------+ + | Redistribution and use in source and binary forms, with or without | + | modification, are permitted under the terms of the BSD license. | + | You should have received a copy of the license in a bundled file | + | named LICENSE; in case you did not receive a copy you can review | + | the terms online at: https://opensource.org/licenses/BSD-3-Clause | + +--------------------------------------------------------------------+ + | Copyright (c) 2006-2014 Brian Aker https://datadifferential.com/ | + | Copyright (c) 2020 Michael Wallner | + +--------------------------------------------------------------------+ +*/ + #pragma once #include @@ -32,10 +47,10 @@ char random_binary(); string random_binary_string(size_t len); char random_ascii(char min = '!', char max = '~'); string random_ascii_string(size_t len, char min = '!', char max = '~'); -kv_pair random_ascii_pair(size_t minlen = 1<<2, size_t maxlen = 1<<10); +kv_pair random_ascii_pair(size_t minlen = 1 << 2, size_t maxlen = 1 << 10); -template