From d0363b118e75436ddd2be2ddcb63608bd43f46aa Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Tue, 24 Nov 2020 21:37:09 +0900 Subject: [PATCH] Add tests for curl_util (#1481) --- .gitignore | 1 + src/Makefile.am | 21 +++++++++- src/curl_util.h | 2 + src/test_curl_util.cpp | 90 ++++++++++++++++++++++++++++++++++++++++++ src/test_util.h | 2 + 5 files changed, 114 insertions(+), 2 deletions(-) create mode 100644 src/test_curl_util.cpp diff --git a/.gitignore b/.gitignore index dcd7761..b85e24b 100644 --- a/.gitignore +++ b/.gitignore @@ -73,6 +73,7 @@ missing *.trs default_commit_hash src/s3fs +src/test_curl_util src/test_string_util test/s3proxy-* diff --git a/src/Makefile.am b/src/Makefile.am index 4e30965..c9c6c80 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -63,11 +63,28 @@ endif s3fs_LDADD = $(DEPS_LIBS) -noinst_PROGRAMS = test_string_util +noinst_PROGRAMS = \ + test_curl_util \ + test_string_util + +test_curl_util_SOURCES = common_auth.cpp curl_util.cpp string_util.cpp test_curl_util.cpp s3fs_global.cpp s3fs_logger.cpp +if USE_SSL_OPENSSL + test_curl_util_SOURCES += openssl_auth.cpp +endif +if USE_SSL_GNUTLS + test_curl_util_SOURCES += gnutls_auth.cpp +endif +if USE_SSL_NSS + test_curl_util_SOURCES += nss_auth.cpp +endif + +test_curl_util_LDADD = $(DEPS_LIBS) test_string_util_SOURCES = string_util.cpp test_string_util.cpp s3fs_logger.cpp -TESTS = test_string_util +TESTS = \ + test_curl_util \ + test_string_util clang-tidy: clang-tidy $(s3fs_SOURCES) -- $(DEPS_CFLAGS) $(CPPFLAGS) diff --git a/src/curl_util.h b/src/curl_util.h index b9fcb73..76d13d3 100644 --- a/src/curl_util.h +++ b/src/curl_util.h @@ -23,6 +23,8 @@ #include +struct sse_type_t; + //---------------------------------------------- // Functions //---------------------------------------------- diff --git a/src/test_curl_util.cpp b/src/test_curl_util.cpp new file mode 100644 index 0000000..ca14724 --- /dev/null +++ b/src/test_curl_util.cpp @@ -0,0 +1,90 @@ +/* + * s3fs - FUSE-based file system backed by Amazon S3 + * + * Copyright(C) 2020 Andrew Gaul + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include +#include + +#include "curl_util.h" +#include "test_util.h" + +#define ASSERT_IS_SORTED(x) assert_is_sorted((x), __FILE__, __LINE__) + +void assert_is_sorted(struct curl_slist* list, const char *file, int line) +{ + for(; list != NULL && list->next != NULL; list = list->next){ + std::string key1 = list->data; + key1.erase(key1.find(':')); + std::string key2 = list->data; + key2.erase(key2.find(':')); + std::cerr << "key1: " << key1 << " key2: " << key2 << std::endl; + + if(strcasecmp(key1.c_str(), key2.c_str()) > 0){ + std::cerr << "not sorted: " << key1 << " " << key2 << " at " << file << ":" << line << std::endl; + std::exit(1); + } + } +} + +size_t curl_slist_length(const struct curl_slist* list) +{ + size_t len = 0; + for(; list != NULL; list = list->next){ + ++len; + } + return len; +} + +void test_sort_insert() +{ + struct curl_slist* list = NULL; + ASSERT_IS_SORTED(list); + // add to head + list = curl_slist_sort_insert(list, "2", "val"); + ASSERT_IS_SORTED(list); + // add to tail + list = curl_slist_sort_insert(list, "4", "val"); + ASSERT_IS_SORTED(list); + // add in between + list = curl_slist_sort_insert(list, "3", "val"); + ASSERT_IS_SORTED(list); + // add to head + list = curl_slist_sort_insert(list, "1", "val"); + ASSERT_IS_SORTED(list); + // replace head + list = curl_slist_sort_insert(list, "1", "val2"); + ASSERT_IS_SORTED(list); + ASSERT_EQUALS(static_cast(4), curl_slist_length(list)); + ASSERT_STREQUALS("1: val2", list->data); +} + +int main(int argc, char *argv[]) +{ + test_sort_insert(); + return 0; +} + +/* +* Local variables: +* tab-width: 4 +* c-basic-offset: 4 +* End: +* vim600: expandtab sw=4 ts=4 fdm=marker +* vim<600: expandtab sw=4 ts=4 +*/ diff --git a/src/test_util.h b/src/test_util.h index 2692668..c7d270a 100644 --- a/src/test_util.h +++ b/src/test_util.h @@ -25,6 +25,8 @@ #include #include +#include "string_util.h" + template void assert_equals(const T &x, const T &y, const char *file, int line) { if (x != y) {