diff options
Diffstat (limited to 'src/test')
37 files changed, 816 insertions, 395 deletions
diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index 9e008c86..fa0bcf9b 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: Allen Winter <winter@kde.org> +# SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0 + include_directories( ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/src @@ -20,6 +23,7 @@ set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}) set(TEST_DATADIR "\"${CMAKE_SOURCE_DIR}/test-data\"") add_definitions(-DTEST_DATADIR=${TEST_DATADIR} -DTEST_ZONEDIR="${CMAKE_SOURCE_DIR}/zoneinfo") +# Set properties for the test macro(setprops _name) if(UNIX) set_tests_properties(${_name} PROPERTIES @@ -61,7 +65,9 @@ macro(buildme _name _srcs) target_link_libraries(${_name} ical_cxx icalss_cxx) endif() - target_link_libraries(${_name} ${CMAKE_THREAD_LIBS_INIT}) + if(DEFINED CMAKE_THREAD_LIBS_INIT) + target_link_libraries(${_name} ${CMAKE_THREAD_LIBS_INIT}) + endif() if(ICU_FOUND) target_link_libraries(${_name} ${ICU_LIBRARIES}) endif() @@ -70,6 +76,7 @@ macro(buildme _name _srcs) endif() endmacro() +# Build the test and add the test, making sure the test properties are set macro(testme _name _srcs) buildme(${_name} "${_srcs}") add_test(NAME ${_name} COMMAND ${_name}) @@ -96,6 +103,8 @@ set(regression_SRCS regression-utils.c regression-recur.c regression-storage.c + test-malloc.c + test-malloc.h ) if(WITH_CXX_BINDINGS) list(APPEND regression_SRCS regression-cxx.cpp) @@ -108,10 +117,10 @@ set(parser_SRCS icaltestparser.c) buildme(parser "${parser_SRCS}") file(GLOB TEST_FILES ${CMAKE_SOURCE_DIR}/test-data/*.ics) -foreach(TEST_FILE ${TEST_FILES}) - get_filename_component(TEST_NAME ${TEST_FILE} NAME_WE) - add_test(NAME parser-${TEST_NAME} COMMAND parser ${TEST_FILE}) - setprops(parser-${TEST_NAME}) +foreach(test_file ${TEST_FILES}) + get_filename_component(test_name ${test_file} NAME_WE) + add_test(NAME parser-${test_name} COMMAND parser ${test_file}) + setprops(parser-${test_name}) endforeach() ########### next target ############### @@ -177,7 +186,8 @@ if(NOT ${CMAKE_VERSION} VERSION_LESS 3.14) set(CMAKE_COMPARE_FILES_IGNORE_EOL TRUE) endif() if(NOT WIN32 OR CMAKE_COMPARE_FILES_IGNORE_EOL) - if(NOT CYGWIN AND NOT USE_32BIT_TIME_T) #ignore_eol doesn't work on Cygwin. tests for years greater than 2037 will fail + #ignore_eol doesn't work on Cygwin. testing years greater than 2037 will fail + if(NOT CYGWIN AND NOT USE_32BIT_TIME_T) set(icalrecurtest_SRCS icalrecur_test.c) add_executable(icalrecurtest ${icalrecurtest_SRCS}) target_link_libraries(icalrecurtest ical icalss icalvcal) diff --git a/src/test/builtin_timezones.c b/src/test/builtin_timezones.c index 3ceb462d..334b683a 100644 --- a/src/test/builtin_timezones.c +++ b/src/test/builtin_timezones.c @@ -2,18 +2,10 @@ FILE: builtin_timezones.c CREATOR: Milan Crha 26 November 2014 - (C) COPYRIGHT 2014 Milan Crha <mcrha@redhat.com> + SPDX-FileCopyrightText: 2014 Milan Crha <mcrha@redhat.com> - This library is free software; you can redistribute it and/or modify - it under the terms of either: + SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0 - The LGPL as published by the Free Software Foundation, version - 2.1, available at: https://www.gnu.org/licenses/lgpl-2.1.html - - Or: - - The Mozilla Public License Version 2.0. You may obtain a copy of - the License at https://www.mozilla.org/MPL/ ======================================================================*/ #ifdef HAVE_CONFIG_H diff --git a/src/test/copycluster.c b/src/test/copycluster.c index 282d0fc4..05961252 100644 --- a/src/test/copycluster.c +++ b/src/test/copycluster.c @@ -2,18 +2,9 @@ FILE: copycluster.c CREATOR: eric 15 January 2000 - (C) COPYRIGHT 2000 Eric Busboom <eric@civicknowledge.com> + SPDX-FileCopyrightText: 2000 Eric Busboom <eric@civicknowledge.com> - This library is free software; you can redistribute it and/or modify - it under the terms of either: - - The LGPL as published by the Free Software Foundation, version - 2.1, available at: https://www.gnu.org/licenses/lgpl-2.1.html - - Or: - - The Mozilla Public License Version 2.0. You may obtain a copy of - the License at https://www.mozilla.org/MPL/ + SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0 The Original Code is eric. The Initial Developer of the Original Code is Eric Busboom diff --git a/src/test/icalattach-leak.c b/src/test/icalattach-leak.c index d91aa398..3740742c 100644 --- a/src/test/icalattach-leak.c +++ b/src/test/icalattach-leak.c @@ -1,18 +1,9 @@ /*====================================================================== FILE: icalattach-leak.c - Copyright (C) 2019 Red Hat, Inc. <www.redhat.com> + SPDX-FileCopyrightText: 2019 Red Hat, Inc. <www.redhat.com> - This library is free software; you can redistribute it and/or modify - it under the terms of either: - - The LGPL as published by the Free Software Foundation, version - 2.1, available at: https://www.gnu.org/licenses/lgpl-2.1.html - - Or: - - The Mozilla Public License Version 2.0. You may obtain a copy of - the License at https://www.mozilla.org/MPL/ + SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0 The Initial Developer of the Original Code is Milan Crha ======================================================================*/ @@ -23,9 +14,7 @@ #include <stdio.h> -#define LIBICAL_GLIB_UNSTABLE_API #include "libical-glib/libical-glib.h" -#undef LIBICAL_GLIB_UNSTABLE_API static GSList *get_attachments(ICalComponent *comp) { diff --git a/src/test/icalrecur_test.c b/src/test/icalrecur_test.c index 3b1f0ceb..a236848d 100644 --- a/src/test/icalrecur_test.c +++ b/src/test/icalrecur_test.c @@ -2,18 +2,10 @@ FILE: icalrecur_test.c CREATOR: Ken Murchison 26 September 2014 - (C) COPYRIGHT 2000 Eric Busboom <eric@civicknowledge.com> + SPDX-FileCopyrightText: 2000 Eric Busboom <eric@civicknowledge.com> - This library is free software; you can redistribute it and/or modify - it under the terms of either: + SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0 - The LGPL as published by the Free Software Foundation, version - 2.1, available at: https://www.gnu.org/licenses/lgpl-2.1.html - - Or: - - The Mozilla Public License Version 2.0. You may obtain a copy of - the License at https://www.mozilla.org/MPL/ ======================================================================*/ /* @@ -670,7 +662,7 @@ int main(int argc, char *argv[]) } icalrecur_iterator_free(ritr); - free(rrule.rscale); + icalmemory_free_buffer(rrule.rscale); } fclose(fp); diff --git a/src/test/icaltestparser.c b/src/test/icaltestparser.c index c301a74f..c3a27abf 100644 --- a/src/test/icaltestparser.c +++ b/src/test/icaltestparser.c @@ -2,18 +2,9 @@ FILE: icaltestparser.c CREATOR: eric 20 June 1999 - (C) COPYRIGHT 1999 The Software Studio <eric@civicknowledge.com> + SPDX-FileCopyrightText: 1999 The Software Studio <eric@civicknowledge.com> - This library is free software; you can redistribute it and/or modify - it under the terms of either: - - The LGPL as published by the Free Software Foundation, version - 2.1, available at: https://www.gnu.org/licenses/lgpl-2.1.html - - Or: - - The Mozilla Public License Version 2.0. You may obtain a copy of - the License at https://www.mozilla.org/MPL/ + SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0 The original author is Eric Busboom ======================================================================*/ diff --git a/src/test/icaltm_test.c b/src/test/icaltm_test.c index 141d49e4..b3ccad34 100644 --- a/src/test/icaltm_test.c +++ b/src/test/icaltm_test.c @@ -1,18 +1,9 @@ /*====================================================================== FILE: icaltm_test.c - Copyright (C) 2017 Red Hat, Inc. <www.redhat.com> + SPDX-FileCopyrightText: 2017 Red Hat, Inc. <www.redhat.com> - This library is free software; you can redistribute it and/or modify - it under the terms of either: - - The LGPL as published by the Free Software Foundation, version - 2.1, available at: https://www.gnu.org/licenses/lgpl-2.1.html - - Or: - - The Mozilla Public License Version 2.0. You may obtain a copy of - the License at https://www.mozilla.org/MPL/ + SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0 The Initial Developer of the Original Code is Milan Crha ======================================================================*/ diff --git a/src/test/libical-glib/CMakeLists.txt b/src/test/libical-glib/CMakeLists.txt index 4d239dba..2f88b115 100644 --- a/src/test/libical-glib/CMakeLists.txt +++ b/src/test/libical-glib/CMakeLists.txt @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: Milan Crha <mcrha@redhat.com> +# SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0 + find_program(PYTHON3 python3) set_package_properties(PYTHON3 PROPERTIES TYPE REQUIRED PURPOSE "Required by the libical build system.") add_feature_info("libical-glib testing" PYTHON3 "python3 is required to run the regression tests") @@ -19,9 +22,22 @@ list(APPEND TEST_FILES ) if(PYTHON3) + set(GI_TYPELIB_PATH_STR "${CMAKE_BINARY_DIR}/src/libical-glib") + if(DEFINED GI_TYPELIB_PATH) + if($ENV{GI_TYPELIB_PATH}) + set(GI_TYPELIB_PATH_STR "${GI_TYPELIB_PATH_STR}:$ENV{GI_TYPELIB_PATH}") + endif() + endif() + set(LD_LIBRARY_PATH_STR "${LIBRARY_OUTPUT_PATH}") + if(DEFINED LD_LIBRARY_PATH) + if($ENV{LD_LIBRARY_PATH}) + set(LD_LIBRARY_PATH_STR "${LD_LIBRARY_PATH_STR}:$ENV{LD_LIBRARY_PATH}") + endif() + endif() + list(APPEND test_env - "GI_TYPELIB_PATH=${CMAKE_BINARY_DIR}/src/libical-glib;$ENV{GI_TYPELIB_PATH}" - "LD_LIBRARY_PATH=${LIBRARY_OUTPUT_PATH};$ENV{LD_LIBRARY_PATH}" + "GI_TYPELIB_PATH=${GI_TYPELIB_PATH_STR}" + "LD_LIBRARY_PATH=${LD_LIBRARY_PATH_STR}" "ZONEINFO_DIRECTORY=${CMAKE_SOURCE_DIR}/zoneinfo" ) diff --git a/src/test/libical-glib/array.py b/src/test/libical-glib/array.py index 77d9550a..da3b26b2 100755..100644 --- a/src/test/libical-glib/array.py +++ b/src/test/libical-glib/array.py @@ -3,18 +3,12 @@ ############################################################################### # -# Copyright (C) 2015 William Yu <williamyu@gnome.org> +# SPDX-FileCopyrightText: 2015 William Yu <williamyu@gnome.org> # -# This library is free software; you can redistribute it and/or modify -# it under the terms of either: +# SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0 # -# The LGPL as published by the Free Software Foundation, version -# 2.1, available at: https://www.gnu.org/licenses/lgpl-2.1.txt # -# Or: # -# The Mozilla Public License Version 2.0. You may obtain a copy of -# the License at https://www.mozilla.org/MPL/ # ############################################################################### diff --git a/src/test/libical-glib/attach.py b/src/test/libical-glib/attach.py index 4a5492ac..7bcb5583 100755..100644 --- a/src/test/libical-glib/attach.py +++ b/src/test/libical-glib/attach.py @@ -3,18 +3,12 @@ ############################################################################### # -# Copyright (C) 2015 William Yu <williamyu@gnome.org> +# SPDX-FileCopyrightText: 2015 William Yu <williamyu@gnome.org> # -# This library is free software; you can redistribute it and/or modify -# it under the terms of either: +# SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0 # -# The LGPL as published by the Free Software Foundation, version -# 2.1, available at: https://www.gnu.org/licenses/lgpl-2.1.txt # -# Or: # -# The Mozilla Public License Version 2.0. You may obtain a copy of -# the License at https://www.mozilla.org/MPL/ # ############################################################################### diff --git a/src/test/libical-glib/component.py b/src/test/libical-glib/component.py index cbdb097e..13d6b104 100755..100644 --- a/src/test/libical-glib/component.py +++ b/src/test/libical-glib/component.py @@ -3,18 +3,12 @@ ############################################################################### # -# Copyright (C) 2015 William Yu <williamyu@gnome.org> +# SPDX-FileCopyrightText: 2015 William Yu <williamyu@gnome.org> # -# This library is free software; you can redistribute it and/or modify -# it under the terms of either: +# SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0 # -# The LGPL as published by the Free Software Foundation, version -# 2.1, available at: https://www.gnu.org/licenses/lgpl-2.1.txt # -# Or: # -# The Mozilla Public License Version 2.0. You may obtain a copy of -# the License at https://www.mozilla.org/MPL/ # ############################################################################### @@ -183,25 +177,21 @@ def main(): #Traverse with external API. iter = parent.begin_component(ICalGLib.ComponentKind.VEVENT_COMPONENT); child_component = iter.deref(); - child_component.set_owner(parent); for i in range(0, count): prefix = "test" index = i+2; assert(child_component.get_summary() == prefix + str(index)); if (i != count-1): child_component = iter.next(); - child_component.set_owner(parent); iter = parent.end_component(ICalGLib.ComponentKind.VEVENT_COMPONENT); child_component = iter.prior(); - child_component.set_owner(parent); for i in range(0, count): prefix = "test" index = count + 1 - i; assert(child_component.get_summary() == prefix + str(index)); if (i != count - 1): child_component = iter.prior(); - child_component.set_owner(parent); #Traverse and remove with external API. iter = parent.begin_component(ICalGLib.ComponentKind.VEVENT_COMPONENT); diff --git a/src/test/libical-glib/comprehensive.py b/src/test/libical-glib/comprehensive.py index 94fdfb6f..4f3fe629 100755..100644 --- a/src/test/libical-glib/comprehensive.py +++ b/src/test/libical-glib/comprehensive.py @@ -3,18 +3,12 @@ ############################################################################### # -# Copyright (C) 2015 William Yu <williamyu@gnome.org> +# SPDX-FileCopyrightText: 2015 William Yu <williamyu@gnome.org> # -# This library is free software; you can redistribute it and/or modify -# it under the terms of either: +# SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0 # -# The LGPL as published by the Free Software Foundation, version -# 2.1, available at: https://www.gnu.org/licenses/lgpl-2.1.txt # -# Or: # -# The Mozilla Public License Version 2.0. You may obtain a copy of -# the License at https://www.mozilla.org/MPL/ # ############################################################################### diff --git a/src/test/libical-glib/duration.py b/src/test/libical-glib/duration.py index 114970ad..b6a1ac78 100755..100644 --- a/src/test/libical-glib/duration.py +++ b/src/test/libical-glib/duration.py @@ -3,18 +3,12 @@ ############################################################################### # -# Copyright (C) 2015 William Yu <williamyu@gnome.org> +# SPDX-FileCopyrightText: 2015 William Yu <williamyu@gnome.org> # -# This library is free software; you can redistribute it and/or modify -# it under the terms of either: +# SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0 # -# The LGPL as published by the Free Software Foundation, version -# 2.1, available at: https://www.gnu.org/licenses/lgpl-2.1.txt # -# Or: # -# The Mozilla Public License Version 2.0. You may obtain a copy of -# the License at https://www.mozilla.org/MPL/ # ############################################################################### diff --git a/src/test/libical-glib/error.py b/src/test/libical-glib/error.py index e501a984..e64de32a 100755..100644 --- a/src/test/libical-glib/error.py +++ b/src/test/libical-glib/error.py @@ -3,18 +3,12 @@ ############################################################################### # -# Copyright (C) 2015 William Yu <williamyu@gnome.org> +# SPDX-FileCopyrightText: 2015 William Yu <williamyu@gnome.org> # -# This library is free software; you can redistribute it and/or modify -# it under the terms of either: +# SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0 # -# The LGPL as published by the Free Software Foundation, version -# 2.1, available at: https://www.gnu.org/licenses/lgpl-2.1.txt # -# Or: # -# The Mozilla Public License Version 2.0. You may obtain a copy of -# the License at https://www.mozilla.org/MPL/ # ############################################################################### diff --git a/src/test/libical-glib/misc.py b/src/test/libical-glib/misc.py index d10648b8..2cb59d44 100755..100644 --- a/src/test/libical-glib/misc.py +++ b/src/test/libical-glib/misc.py @@ -3,18 +3,12 @@ ############################################################################### # -# Copyright (C) 2019 Red Hat Inc. <www.redhat.com> +# SPDX-FileCopyrightText: 2019 Red Hat Inc. <www.redhat.com> # -# This library is free software; you can redistribute it and/or modify -# it under the terms of either: +# SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0 # -# The LGPL as published by the Free Software Foundation, version -# 2.1, available at: https://www.gnu.org/licenses/lgpl-2.1.txt # -# Or: # -# The Mozilla Public License Version 2.0. You may obtain a copy of -# the License at https://www.mozilla.org/MPL/ # ############################################################################### diff --git a/src/test/libical-glib/parameter.py b/src/test/libical-glib/parameter.py index 5a0c6230..33cea40a 100755..100644 --- a/src/test/libical-glib/parameter.py +++ b/src/test/libical-glib/parameter.py @@ -3,18 +3,12 @@ ############################################################################### # -# Copyright (C) 2015 William Yu <williamyu@gnome.org> +# SPDX-FileCopyrightText: 2015 William Yu <williamyu@gnome.org> # -# This library is free software; you can redistribute it and/or modify -# it under the terms of either: +# SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0 # -# The LGPL as published by the Free Software Foundation, version -# 2.1, available at: https://www.gnu.org/licenses/lgpl-2.1.txt # -# Or: # -# The Mozilla Public License Version 2.0. You may obtain a copy of -# the License at https://www.mozilla.org/MPL/ # ############################################################################### diff --git a/src/test/libical-glib/period.py b/src/test/libical-glib/period.py index bcc49706..1791a34d 100755..100644 --- a/src/test/libical-glib/period.py +++ b/src/test/libical-glib/period.py @@ -3,18 +3,12 @@ ############################################################################### # -# Copyright (C) 2015 William Yu <williamyu@gnome.org> +# SPDX-FileCopyrightText: 2015 William Yu <williamyu@gnome.org> # -# This library is free software; you can redistribute it and/or modify -# it under the terms of either: +# SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0 # -# The LGPL as published by the Free Software Foundation, version -# 2.1, available at: https://www.gnu.org/licenses/lgpl-2.1.txt # -# Or: # -# The Mozilla Public License Version 2.0. You may obtain a copy of -# the License at https://www.mozilla.org/MPL/ # ############################################################################### diff --git a/src/test/libical-glib/property.py b/src/test/libical-glib/property.py index 23de9b5d..ee78467e 100755..100644 --- a/src/test/libical-glib/property.py +++ b/src/test/libical-glib/property.py @@ -3,18 +3,12 @@ ############################################################################### # -# Copyright (C) 2015 William Yu <williamyu@gnome.org> +# SPDX-FileCopyrightText: 2015 William Yu <williamyu@gnome.org> # -# This library is free software; you can redistribute it and/or modify -# it under the terms of either: +# SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0 # -# The LGPL as published by the Free Software Foundation, version -# 2.1, available at: https://www.gnu.org/licenses/lgpl-2.1.txt # -# Or: # -# The Mozilla Public License Version 2.0. You may obtain a copy of -# the License at https://www.mozilla.org/MPL/ # ############################################################################### diff --git a/src/test/libical-glib/recurrence.py b/src/test/libical-glib/recurrence.py index c136224b..d00910ff 100755..100644 --- a/src/test/libical-glib/recurrence.py +++ b/src/test/libical-glib/recurrence.py @@ -3,18 +3,12 @@ ############################################################################### # -# Copyright (C) 2015 William Yu <williamyu@gnome.org> +# SPDX-FileCopyrightText: 2015 William Yu <williamyu@gnome.org> # -# This library is free software; you can redistribute it and/or modify -# it under the terms of either: +# SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0 # -# The LGPL as published by the Free Software Foundation, version -# 2.1, available at: https://www.gnu.org/licenses/lgpl-2.1.txt # -# Or: # -# The Mozilla Public License Version 2.0. You may obtain a copy of -# the License at https://www.mozilla.org/MPL/ # ############################################################################### diff --git a/src/test/libical-glib/timezone.py b/src/test/libical-glib/timezone.py index ec027a1b..88fb6b01 100755..100644 --- a/src/test/libical-glib/timezone.py +++ b/src/test/libical-glib/timezone.py @@ -3,18 +3,12 @@ ############################################################################### # -# Copyright (C) 2015 William Yu <williamyu@gnome.org> +# SPDX-FileCopyrightText: 2015 William Yu <williamyu@gnome.org> # -# This library is free software; you can redistribute it and/or modify -# it under the terms of either: +# SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0 # -# The LGPL as published by the Free Software Foundation, version -# 2.1, available at: https://www.gnu.org/licenses/lgpl-2.1.txt # -# Or: # -# The Mozilla Public License Version 2.0. You may obtain a copy of -# the License at https://www.mozilla.org/MPL/ # ############################################################################### diff --git a/src/test/libical-glib/value.py b/src/test/libical-glib/value.py index 7be64644..0cebbb7b 100755..100644 --- a/src/test/libical-glib/value.py +++ b/src/test/libical-glib/value.py @@ -3,18 +3,12 @@ ############################################################################### # -# Copyright (C) 2015 William Yu <williamyu@gnome.org> +# SPDX-FileCopyrightText: 2015 William Yu <williamyu@gnome.org> # -# This library is free software; you can redistribute it and/or modify -# it under the terms of either: +# SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0 # -# The LGPL as published by the Free Software Foundation, version -# 2.1, available at: https://www.gnu.org/licenses/lgpl-2.1.txt # -# Or: # -# The Mozilla Public License Version 2.0. You may obtain a copy of -# the License at https://www.mozilla.org/MPL/ # ############################################################################### diff --git a/src/test/process.c b/src/test/process.c index db609b27..f2816154 100644 --- a/src/test/process.c +++ b/src/test/process.c @@ -2,18 +2,10 @@ FILE: process.c CREATOR: eric 11 February 2000 - (C) COPYRIGHT 2000 Eric Busboom <eric@civicknowledge.com> + SPDX-FileCopyrightText: 2000 Eric Busboom <eric@civicknowledge.com> - This library is free software; you can redistribute it and/or modify - it under the terms of either: + SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0 - The LGPL as published by the Free Software Foundation, version - 2.1, available at: https://www.gnu.org/licenses/lgpl-2.1.html - - Or: - - The Mozilla Public License Version 2.0. You may obtain a copy of - the License at https://www.mozilla.org/MPL/ ======================================================================*/ #ifdef HAVE_CONFIG_H diff --git a/src/test/recur.c b/src/test/recur.c index 01552802..014ede09 100644 --- a/src/test/recur.c +++ b/src/test/recur.c @@ -2,7 +2,7 @@ FILE: recur.c CREATOR: ebusboom 8jun00 - (C) COPYRIGHT 1999 Eric Busboom <eric@civicknowledge.com> + SPDX-FileCopyrightText: 1999 Eric Busboom <eric@civicknowledge.com> DESCRIPTION: @@ -10,16 +10,8 @@ ./recur ../../test-data/recur.txt - This library is free software; you can redistribute it and/or modify - it under the terms of either: + SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0 - The LGPL as published by the Free Software Foundation, version - 2.1, available at: https://www.gnu.org/licenses/lgpl-2.1.html - - Or: - - The Mozilla Public License Version 2.0. You may obtain a copy of - the License at https://www.mozilla.org/MPL/ ======================================================================*/ #ifdef HAVE_CONFIG_H @@ -45,8 +37,8 @@ static void recur_callback(icalcomponent *comp, struct icaltime_span *span, void { _unused(comp); _unused(data); - printf("cb: %s", ctime(&span->start)); - printf(" %s\n", ctime(&span->end)); + printf("cb: %s", icalctime(&span->start)); + printf(" %s\n", icalctime(&span->end)); } int main(int argc, char *argv[]) @@ -57,7 +49,7 @@ int main(int argc, char *argv[]) icalproperty *desc, *dtstart, *rrule; struct icalrecurrencetype recur; icalrecur_iterator *ritr; - time_t tt; + icaltime_t tt; const char *file; icalerror_set_error_state(ICAL_PARSE_ERROR, ICAL_ERROR_NONFATAL); @@ -114,7 +106,7 @@ int main(int argc, char *argv[]) tt = icaltime_as_timet(start); - printf("#### %s\n", ctime(&tt)); + printf("#### %s\n", icalctime(&tt)); icalrecur_iterator_free(ritr); @@ -123,7 +115,7 @@ int main(int argc, char *argv[]) !icaltime_is_null_time(next); next = icalrecur_iterator_next(ritr)) { tt = icaltime_as_timet(next); - printf(" %s", ctime(&tt)); + printf(" %s", icalctime(&tt)); } icalrecur_iterator_free(ritr); diff --git a/src/test/regression-classify.c b/src/test/regression-classify.c index 7e5d4aa7..a5f3af0c 100644 --- a/src/test/regression-classify.c +++ b/src/test/regression-classify.c @@ -1,18 +1,10 @@ /*====================================================================== FILE: regression-classify.c - Copyright (C) 2002 Paul Lindner <lindner@users.sf.net> + SPDX-FileCopyrightText: 2002 Paul Lindner <lindner@users.sf.net> - This library is free software; you can redistribute it and/or modify - it under the terms of either: + SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0 - The LGPL as published by the Free Software Foundation, version - 2.1, available at: https://www.gnu.org/licenses/lgpl-2.1.html - - Or: - - The Mozilla Public License Version 2.0. You may obtain a copy of - the License at https://www.mozilla.org/MPL/ ======================================================================*/ #ifdef HAVE_CONFIG_H diff --git a/src/test/regression-component.c b/src/test/regression-component.c index 3e147e9e..388c53a4 100644 --- a/src/test/regression-component.c +++ b/src/test/regression-component.c @@ -1,18 +1,9 @@ /*====================================================================== FILE: regression-component.c - (C) COPYRIGHT 1999 Eric Busboom <eric@civicknowledge.com> + SPDX-FileCopyrightText: 1999 Eric Busboom <eric@civicknowledge.com> - This library is free software; you can redistribute it and/or modify - it under the terms of either: - - The LGPL as published by the Free Software Foundation, version - 2.1, available at: https://www.gnu.org/licenses/lgpl-2.1.html - - Or: - - The Mozilla Public License Version 2.0. You may obtain a copy of - the License at https://www.mozilla.org/MPL/ + SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0 The original author is Eric Busboom ======================================================================*/ @@ -310,9 +301,9 @@ static void print_span(int c, struct icaltime_span span) */ void test_icalcomponent_get_span() { - time_t tm1 = 973378800; /*Sat Nov 4 23:00:00 UTC 2000, + icaltime_t tm1 = 973378800; /*Sat Nov 4 23:00:00 UTC 2000, Sat Nov 4 15:00:00 PST 2000 */ - time_t tm2 = 973382400; /*Sat Nov 5 00:00:00 UTC 2000 + icaltime_t tm2 = 973382400; /*Sat Nov 5 00:00:00 UTC 2000 Sat Nov 4 16:00:00 PST 2000 */ struct icaldurationtype dur; struct icaltime_span span; @@ -321,7 +312,7 @@ void test_icalcomponent_get_span() int tnum = 0; /** test 0 - * Direct assigning time_t means they will be interpreted as UTC + * Direct assigning icaltime_t means they will be interpreted as UTC */ span.start = tm1; span.end = tm2; @@ -448,7 +439,7 @@ void test_icalcomponent_get_span() if (VERBOSE) print_span(tnum++, span); - int_is("null span", (int)span.start, 0); + int_is("start == end", (int)span.start, (int)span.end); icalcomponent_free(c); /** test 7 diff --git a/src/test/regression-cxx.cpp b/src/test/regression-cxx.cpp index 6bb33b3a..dbe3ae49 100644 --- a/src/test/regression-cxx.cpp +++ b/src/test/regression-cxx.cpp @@ -1,16 +1,8 @@ /** - (C) COPYRIGHT 2001, Critical Path + SPDX-FileCopyrightText: 2001, Critical Path - This library is free software; you can redistribute it and/or modify - it under the terms of either: + SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0 - The LGPL as published by the Free Software Foundation, version - 2.1, available at: https://www.gnu.org/licenses/lgpl-2.1.html - - Or: - - The Mozilla Public License Version 2.0. You may obtain a copy of - the License at https://www.mozilla.org/MPL/ */ #ifdef HAVE_CONFIG_H diff --git a/src/test/regression-recur.c b/src/test/regression-recur.c index e11112e6..dee65679 100644 --- a/src/test/regression-recur.c +++ b/src/test/regression-recur.c @@ -2,20 +2,12 @@ FILE: regression-recur.c CREATOR: ebusboom 8jun00 - (C) COPYRIGHT 1999 Eric Busboom <eric@civicknowledge.com> + SPDX-FileCopyrightText: 1999 Eric Busboom <eric@civicknowledge.com> DESCRIPTION: - This library is free software; you can redistribute it and/or modify - it under the terms of either: + SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0 - The LGPL as published by the Free Software Foundation, version - 2.1, available at: https://www.gnu.org/licenses/lgpl-2.1.html - - Or: - - The Mozilla Public License Version 2.0. You may obtain a copy of - the License at https://www.mozilla.org/MPL/ ======================================================================*/ #ifdef HAVE_CONFIG_H @@ -69,8 +61,8 @@ static void recur_callback(icalcomponent *comp, struct icaltime_span *span, void _unused(comp); if (VERBOSE) { - printf("recur: %s", ctime(&span->start)); - printf(" %s", ctime(&span->end)); + printf("recur: %s", icalctime(&span->start)); + printf(" %s", icalctime(&span->end)); } *num_recurs = *num_recurs + 1; } @@ -83,7 +75,7 @@ void test_recur_file() icalproperty *desc, *dtstart, *rrule; struct icalrecurrencetype recur; icalrecur_iterator *ritr; - time_t tt; + icaltime_t tt; const char *file; int num_recurs_found = 0; icalfileset_options options = { O_RDONLY, 0644, 0, NULL }; @@ -147,7 +139,7 @@ void test_recur_file() tt = icaltime_as_timet(start); if (VERBOSE) - printf("#### %s\n", ctime(&tt)); + printf("#### %s\n", icalctime(&tt)); icalrecur_iterator_free(ritr); @@ -157,7 +149,7 @@ void test_recur_file() next = icalrecur_iterator_next(ritr)) { tt = icaltime_as_timet(next); if (VERBOSE) - printf(" %s", ctime(&tt)); + printf(" %s", icalctime(&tt)); } icalrecur_iterator_free(ritr); diff --git a/src/test/regression-storage.c b/src/test/regression-storage.c index f8cd11e1..b3c1f98d 100644 --- a/src/test/regression-storage.c +++ b/src/test/regression-storage.c @@ -2,20 +2,11 @@ FILE: regression-storage.c CREATOR: eric 03 April 1999 - (C) COPYRIGHT 1999 Eric Busboom <eric@civicknowledge.com> + SPDX-FileCopyrightText: 1999 Eric Busboom <eric@civicknowledge.com> DESCRIPTION: - This library is free software; you can redistribute it and/or modify - it under the terms of either: - - The LGPL as published by the Free Software Foundation, version - 2.1, available at: https://www.gnu.org/licenses/lgpl-2.1.html - - Or: - - The Mozilla Public License Version 2.0. You may obtain a copy of - the License at https://www.mozilla.org/MPL/ + SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0 The original author is Eric Busboom The original code is usecases.c diff --git a/src/test/regression-utils.c b/src/test/regression-utils.c index 431cef85..3536f0ad 100644 --- a/src/test/regression-utils.c +++ b/src/test/regression-utils.c @@ -1,18 +1,9 @@ /*====================================================================== FILE: regression-utils.c - (C) COPYRIGHT 1999 Eric Busboom <eric@civicknowledge.com> + SPDX-FileCopyrightText: 1999 Eric Busboom <eric@civicknowledge.com> - This library is free software; you can redistribute it and/or modify - it under the terms of either: - - The LGPL as published by the Free Software Foundation, version - 2.1, available at: https://www.gnu.org/licenses/lgpl-2.1.html - - Or: - - The Mozilla Public License Version 2.0. You may obtain a copy of - the License at https://www.mozilla.org/MPL/ + SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0 The original author is Eric Busboom ======================================================================*/ @@ -23,6 +14,9 @@ #include "libical/ical.h" +#include "test-malloc.h" +#include "regression.h" + #include <stdlib.h> int QUIET = 0; @@ -30,12 +24,12 @@ int VERBOSE = 1; static char ictt_str[1024]; -const char *ical_timet_string(const time_t t) +const char *ical_timet_string(const icaltime_t t) { struct tm tmp, stm; memset(&tmp, 0, sizeof(tmp)); - if (gmtime_r(&t, &tmp)) { + if (icalgmtime_r(&t, &tmp)) { stm = tmp; } else { memset(&stm, 0, sizeof(stm)); @@ -68,10 +62,10 @@ const char *ictt_as_string(struct icaltimetype t) char *icaltime_as_ctime(struct icaltimetype t) { - time_t tt; + icaltime_t tt; tt = icaltime_as_timet(t); - snprintf(ictt_str, sizeof(ictt_str), "%s", ctime(&tt)); + snprintf(ictt_str, sizeof(ictt_str), "%s", icalctime(&tt)); return ictt_str; } @@ -93,7 +87,7 @@ void die_on_errors_set(int val) die_on_errors = val; } -void _ok(const char *test_name, int success, char *file, int linenum, const char *test) +void _ok(const char *test_name, int success, const char *file, int linenum, const char *test) { testnumber++; @@ -114,7 +108,7 @@ void _ok(const char *test_name, int success, char *file, int linenum, const char } } -void _is(const char *test_name, const char *str1, const char *str2, char *file, int linenum) +void _is(const char *test_name, const char *str1, const char *str2, const char *file, int linenum) { int diff; @@ -135,7 +129,7 @@ void _is(const char *test_name, const char *str1, const char *str2, char *file, } } -void _int_is(char *test_name, int i1, int i2, char *file, int linenum) +void _int_is(const char *test_name, int i1, int i2, const char *file, int linenum) { _ok(test_name, (i1 == i2), file, linenum, ""); @@ -196,7 +190,6 @@ int test_end(void) printf("%s%d/%d ", prefix, this_set, failed_tests[i].test); } printf("\n"); - } else { printf("\n All Tests Successful.\n"); } @@ -204,6 +197,24 @@ int test_end(void) return failed; } +/** + * Bring all memory that is allocated as side effect into a stable state, so we can calculate + * stable memory allocation statistics. + */ +static void cleanup_nondeterministic_memory() { + + // icalerrno_return() allocates a buffer on it's first use per thread. Let's allocate it + // now, so it doesn't disturb our test statistics. + icalerrno_return(); + + // Built-in timezones are cached by libical. By freeing them, they don't influence our statistics. + icaltimezone_free_builtin_timezones(); + + // Memory that was added to the ring buffer is not required to be freed by the caller, so + // we free it here to keep our statistics clean. + icalmemory_free_ring(); +} + void test_run(const char *test_name, void (*test_fcn) (void), int do_test, int headeronly) { static int test_set = 1; @@ -212,7 +223,29 @@ void test_run(const char *test_name, void (*test_fcn) (void), int do_test, int h test_header(test_name, test_set); if (!headeronly && (do_test == 0 || do_test == test_set)) { + + struct testmalloc_statistics mem_statistics; + + // Clean up cached and other kind of non-deterministic memory. + cleanup_nondeterministic_memory(); + + // Now that we are in a stable state, reset the memory statistics and start counting. + testmalloc_reset(); + + // Run the test. (*test_fcn) (); + + // Before getting the statistics, clean up any non-deterministic memory again, so it + // doesn't influence the statistics. + cleanup_nondeterministic_memory(); + + // Now we should get clean statistics. + testmalloc_get_statistics(&mem_statistics); + + ok("no memory leaked", + (mem_statistics.mem_allocated_current == 0) && + (mem_statistics.blocks_allocated == 0)); + if (!QUIET) printf("\n"); } diff --git a/src/test/regression.c b/src/test/regression.c index 2b94dc1c..da3ba9af 100644 --- a/src/test/regression.c +++ b/src/test/regression.c @@ -2,18 +2,9 @@ FILE: regression.c CREATOR: eric 03 April 1999 - (C) COPYRIGHT 1999 Eric Busboom <eric@civicknowledge.com> + SPDX-FileCopyrightText: 1999 Eric Busboom <eric@civicknowledge.com> - This library is free software; you can redistribute it and/or modify - it under the terms of either: - - The LGPL as published by the Free Software Foundation, version - 2.1, available at: https://www.gnu.org/licenses/lgpl-2.1.html - - Or: - - The Mozilla Public License Version 2.0. You may obtain a copy of - the License at https://www.mozilla.org/MPL/ + SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0 The original author is Eric Busboom The original code is regression.c @@ -27,6 +18,7 @@ #include "regression.h" #include "libical/astime.h" +#include "test-malloc.h" #include "libical/ical.h" #include "libicalss/icalss.h" #include "libicalvcal/icalvcal.h" @@ -806,7 +798,7 @@ void test_memory() ok("final buffer size == 806", (bufsize == 806)); - free(f); + icalmemory_free_buffer(f); bufsize = 4; @@ -895,7 +887,7 @@ void test_memory() if (VERBOSE) printf("Char-by-Char buffer: %s\n", f); - free(f); + icalmemory_free_buffer(f); for (i = 0; i < 100; i++) { f = icalmemory_tmp_buffer(bufsize); @@ -1145,7 +1137,15 @@ void test_restriction() icalproperty_vanew_dtend(atime, icalparameter_new_tzid("America/New_York"), (void *)0), - icalproperty_new_location("1CP Conference Room 4350"), (void *)0), (void *)0); + icalproperty_new_location("1CP Conference Room 4350"), + icalcomponent_vanew(ICAL_VALARM_COMPONENT, + icalproperty_new_action(ICAL_ACTION_EMAIL), + icalproperty_new_repeat(0), + icalcomponent_vanew(ICAL_VLOCATION_COMPONENT, + (void *)0), + (void *)0), + (void *)0), + (void *)0); valid = icalrestriction_check(comp); @@ -1217,17 +1217,17 @@ void print_occur(struct icalrecurrencetype recur, struct icaltimetype start) struct icaltimetype next; icalrecur_iterator *ritr; - time_t tt = icaltime_as_timet(start); + icaltime_t tt = icaltime_as_timet(start); printf("#### %s\n", icalrecurrencetype_as_string(&recur)); - printf("#### %s\n", ctime(&tt)); + printf("#### %s\n", icalctime(&tt)); ritr = icalrecur_iterator_new(recur, start); for (next = icalrecur_iterator_next(ritr); !icaltime_is_null_time(next); next = icalrecur_iterator_next(ritr)) { tt = icaltime_as_timet(next); - printf(" %s", ctime(&tt)); + printf(" %s", icalctime(&tt)); } icalrecur_iterator_free(ritr); @@ -1237,7 +1237,7 @@ void test_recur() { struct icalrecurrencetype rt; struct icaltimetype start; - time_t array[25]; + icaltime_t array[25]; int i; rt = icalrecurrencetype_from_string( @@ -1258,7 +1258,7 @@ void test_recur() for (i = 0; i < 25 && array[i] != 0; i++) { if (VERBOSE) { - printf(" %s", ctime(&(array[i]))); + printf(" %s", icalctime(&(array[i]))); } } /* test_increment();*/ @@ -1350,19 +1350,19 @@ void test_recur_encode_by_month() void test_expand_recurrence() { - time_t arr[10]; - time_t now = 931057385; + icaltime_t arr[10]; + icaltime_t now = 931057385; int i, numfound = 0; icalrecur_expand_recurrence("FREQ=MONTHLY;BYDAY=MO,WE", now, 5, arr); if (VERBOSE) - printf("Start %s", ctime(&now)); + printf("Start %s", icalctime(&now)); for (i = 0; i < 5; i++) { numfound++; if (VERBOSE) - printf("i=%d %s\n", i, ctime(&arr[i])); + printf("i=%d %s\n", i, icalctime(&arr[i])); } int_is("Get an array of 5 items", numfound, 5); } @@ -1391,7 +1391,7 @@ void icalrecurrencetype_test() struct icalrecurrencetype r = icalvalue_get_recur(v); struct icaltimetype t = icaltime_from_timet_with_zone(time(0), 0, NULL); struct icaltimetype next; - time_t tt; + icaltime_t tt; struct icalrecur_iterator_impl *itr = (struct icalrecur_iterator_impl *)icalrecur_iterator_new(r, t); @@ -1401,7 +1401,7 @@ void icalrecurrencetype_test() next = icalrecur_iterator_next(itr); tt = icaltime_as_timet(next); - printf("%s", ctime(&tt)); + printf("%s", icalctime(&tt)); } while (!icaltime_is_null_time(next)); @@ -1767,8 +1767,8 @@ void do_test_time(const char *zone) { struct icaltimetype ictt, icttutc, icttzone, icttdayl, icttla, icttny, icttphoenix, icttlocal, icttnorm; - time_t tt, tt2, tt_p200; - time_t offset_tz; + icaltime_t tt, tt2, tt_p200; + icaltime_t offset_tz; icalvalue *v; short day_of_week, start_day_of_week, day_of_year; icaltimezone *azone, *utczone; @@ -1781,7 +1781,7 @@ void do_test_time(const char *zone) /* Test new API */ if (VERBOSE) { - printf("\n---> From time_t \n"); + printf("\n---> From icaltime_t \n"); } tt = 1025127869; /* stick with a constant... Wed, 26 Jun 2002 21:44:29 GMT */ @@ -1791,7 +1791,7 @@ void do_test_time(const char *zone) } ictt = icaltime_from_timet_with_zone(tt, 0, NULL); - str_is("Floating time from time_t", ictt_as_string(ictt), "2002-06-26 21:44:29 (floating)"); + str_is("Floating time from icaltime_t", ictt_as_string(ictt), "2002-06-26 21:44:29 (floating)"); ictt = icaltime_from_timet_with_zone(tt, 0, azone); #if ADD_TESTS_REQUIRING_INVESTIGATION @@ -1869,7 +1869,7 @@ void do_test_time(const char *zone) tt = icaltime_as_timet(ictt); - ok("test icaltime -> time_t for 20001103T183030Z", (tt == 973276230)); + ok("test icaltime -> icaltime_t for 20001103T183030Z", (tt == 973276230)); /* Fri Nov 3 10:30:30 PST 2000 in PST Fri Nov 3 18:30:30 PST 2000 in UTC */ @@ -1894,7 +1894,7 @@ void do_test_time(const char *zone) /** add test case here.. **/ if (VERBOSE) { - printf("\n As time_t \n"); + printf("\n As icaltime_t \n"); } tt2 = icaltime_as_timet(ictt); @@ -1914,7 +1914,7 @@ void do_test_time(const char *zone) printf("20001103T183030 : %s\n", ictt_as_string(icttlocal)); } - offset_tz = (time_t) (-icaltimezone_get_utc_offset_of_utc_time(azone, &ictt, 0)); + offset_tz = (icaltime_t) (-icaltimezone_get_utc_offset_of_utc_time(azone, &ictt, 0)); if (VERBOSE) printf("offset_tz : %ld\n", (long)offset_tz); @@ -2012,7 +2012,7 @@ void do_test_time(const char *zone) icaltimezone_get_builtin_timezone("America/Phoenix")); if (VERBOSE) { - printf("Orig (ctime): %s\n", ical_timet_string(tt)); + printf("Orig (icalctime): %s\n", ical_timet_string(tt)); printf("Orig (ical) : %s\n", ictt_as_string(ictt)); printf("UTC : %s\n", ictt_as_string(icttutc)); printf("Los Angeles : %s\n", ictt_as_string(icttla)); @@ -2025,7 +2025,7 @@ void do_test_time(const char *zone) if (VERBOSE) { printf("\n Daylight Savings \n"); - printf("Orig (ctime): %s\n", ical_timet_string(tt)); + printf("Orig (icalctime): %s\n", ical_timet_string(tt)); printf("Orig (ical) : %s\n", ictt_as_string(ictt)); printf("NY : %s\n", ictt_as_string(icttny)); } @@ -2053,7 +2053,7 @@ void do_test_time(const char *zone) icaltimezone_get_builtin_timezone("America/Los_Angeles")); if (VERBOSE) { - printf("\nOrig (ctime): %s\n", ical_timet_string(tt)); + printf("\nOrig (icalctime): %s\n", ical_timet_string(tt)); printf("Orig (ical) : %s\n", ictt_as_string(ictt)); printf("LA : %s\n", ictt_as_string(icttla)); } @@ -2270,12 +2270,12 @@ void test_overlaps() { icalcomponent *cset, *c; icalset *set; - time_t tm1 = 973378800; /*Sat Nov 4 23:00:00 UTC 2000, + icaltime_t tm1 = 973378800; /*Sat Nov 4 23:00:00 UTC 2000, Sat Nov 4 15:00:00 PST 2000 */ - time_t tm2 = 973382400; /*Sat Nov 5 00:00:00 UTC 2000 + icaltime_t tm2 = 973382400; /*Sat Nov 5 00:00:00 UTC 2000 Sat Nov 4 16:00:00 PST 2000 */ - time_t hh = 1800; /* one half hour */ + icaltime_t hh = 1800; /* one half hour */ icalfileset_options options = { O_RDONLY, 0644, 0, NULL }; set = icalset_new(ICAL_FILE_SET, TEST_DATADIR "/overlaps.ics", &options); @@ -2722,16 +2722,14 @@ void test_recur_parser() rt = icalrecurrencetype_from_string(str); icalerror_restore("MALFORMEDDATA", es); ok(str, rt.freq == ICAL_NO_RECURRENCE); - free(v); + icalmemory_free_buffer(v); } - static int test_juldat_caldat_instance(long year, int month, int day) { struct icaltimetype t; struct ut_instant originalInstant; - memset(&t, 0, sizeof(t)); t.year = year; t.month = month; @@ -2808,7 +2806,6 @@ void test_juldat_caldat() { ok("juldat and caldat return the expected values for random input values", failed == 0); } - char *ical_strstr(const char *haystack, const char *needle) { return strstr(haystack, needle); @@ -2872,7 +2869,7 @@ void test_doy() stm.tm_year = tt1.year - 1900; stm.tm_isdst = -1; - (void)mktime(&stm); + (void)icalmktime(&stm); doy = icaltime_day_of_year(tt1); @@ -4252,6 +4249,8 @@ void test_vcal(void) if (comp) { icalcomponent_free(comp); } + + cleanVObject(vcal); } } @@ -4378,6 +4377,50 @@ void test_comma_in_quoted_value(void) icalcomponent_free(c); } +void test_geo_props(void) +{ + int estate; + icalcomponent *c; + icalproperty *p; + + c = icalparser_parse_string("BEGIN:VEVENT\n" "GEO:49.42612;7.75473\n" "END:VEVENT\n"); + ok("icalparser_parse_string()", (c != NULL)); + if (!c) { + exit(EXIT_FAILURE); + } + if (VERBOSE) + printf("%s", icalcomponent_as_ical_string(c)); + p = icalcomponent_get_first_property(c, ICAL_GEO_PROPERTY); + str_is("icalproperty_get_value_as_string() works", + icalproperty_get_value_as_string(p), "49.42612;7.75473"); + icalcomponent_free(c); + + c = icalparser_parse_string("BEGIN:VEVENT\n" "GEO:-0;+0\n" "END:VEVENT\n"); + ok("icalparser_parse_string()", (c != NULL)); + if (!c) { + exit(EXIT_FAILURE); + } + if (VERBOSE) + printf("%s", icalcomponent_as_ical_string(c)); + p = icalcomponent_get_first_property(c, ICAL_GEO_PROPERTY); + str_is("icalproperty_get_value_as_string() works", + icalproperty_get_value_as_string(p), "-0;+0"); + icalcomponent_free(c); + + estate = icalerror_get_errors_are_fatal(); + icalerror_set_errors_are_fatal(0); + c = icalparser_parse_string("BEGIN:VEVENT\n" "GEO:-0a;+0\n" "END:VEVENT\n"); + if (!c) { + exit(EXIT_FAILURE); + } + if (VERBOSE) + printf("%s", icalcomponent_as_ical_string(c)); + p = icalcomponent_get_first_property(c, ICAL_GEO_PROPERTY); + ok("expected fail icalcomponent_get_first_property()", (p == NULL)); + icalcomponent_free(c); + icalerror_set_errors_are_fatal(estate); +} + void test_zoneinfo_stuff(void) { #if defined(HAVE_SETENV) @@ -4621,7 +4664,7 @@ void test_timezone_from_builtin(void) icaltimezone *zone; struct icaltimetype dtstart, dtend, due; char *strcomp, *tzidprefix, *prevslash = NULL, *prevprevslash = NULL, *p; - int len; + size_t len; zone = icaltimezone_get_builtin_timezone("America/New_York"); tzidprefix = strdup(icaltimezone_get_tzid (zone)); @@ -4662,7 +4705,7 @@ void test_timezone_from_builtin(void) comp = icaltimezone_get_component(zone); strcomp = icalcomponent_as_ical_string_r(comp); comp = icalcomponent_new_from_string(strcomp); - free(strcomp); + icalmemory_free_buffer(strcomp); ok("VTIMEZONE icalcomponent_new_from_string()", (comp != NULL)); @@ -4877,6 +4920,308 @@ static void test_builtin_compat_tzid (void) icaltimezone_free_builtin_timezones(); } +static void test_vcc_vcard_parse(void) +{ + /* Two VCARD-s, because some arches can parse the first and some the second. */ + const char *vcard1 = + "BEGIN:VCARD\r\n" + "VERSION:3.0\r\n" + "NOTE:\r\n" + "FN:Xxxx\r\n" + "N:;Xxxx;;;\r\n" + "END:VCARD"; + const char *vcard2 = + "BEGIN:VCARD\r\n" + "VERSION:3.0\r\n" + "X-XXX-ORIGINAL-VCARD:\r\n" + "X-XXX-KIND:XX_XXXXXXXX\r\n" + "NOTE:\r\n" + "X-XXXXXXXXX-FILE-AS:Xxxxxx\r\n" + "FN:Xxxxxx\r\n" + "N:;Xxxxxx;;;\r\n" + "X-XXX-XXXXXXXXX:\r\n" + "END:VCARD"; + const char *vcalendar = + "BEGIN:VCALENDAR\r\n" + "BEGIN:VEVENT\r\n" + "UID:123\r\n" + "SUMMARY:Summary\r\n" + "DTSTAMP:20210803T063522Z\r\n" + "DTSTART;VALUE=DATE:20210902\r\n" + "END:VEVENT\r\n" + "END:VCALENDAR\r\n"; + const char *vcalendar_broken = + "BEGIN:VCALENDAR\r\n" + "BEGIN:VTIMEZONE\r\n" + "TZID:tz/id\r\n" + "BEGIN:STANDARD\r\n" + "TZNAME:PMT\r\n" + "TZOFFSETFROM:+005744\r\n" + "TZOFFSETTO:+005744\r\n" + "DTSTART:18500101T000000\r\n" + "END:STANDARD\r\n" + "BEGIN:STANDARD\r\n" + "TZNAME:CET\r\n" + "TZOFFSETFROM:+005744\r\n" + "TZOFFSETTO:+0100\r\n" + "DTSTART:18911001T000000\r\n" + "END:STANDARD\r\n" + "BEGIN:DAYLIGHT\r\n" + "TZNAME:CEST\r\n" + "TZOFFSETFROM:+0100\r\n" + "TZOFFSETTO:+0200\r\n" + "DTSTART:19160430T230000\r\n" + "END:DAYLIGHT\r\n" + "END:VTIMEZONE\r\n" + "BEGIN:VEVENT\r\n" + "UID:321\r\n" + "SUMMARY:Summary\r\n" + "DTSTAMP:20210803T063522Z\r\n" + "DTSTART;VALUE=DATE:20210902\r\n" + "END:VEVENT\r\n" + "BEGIN:VEVENT\r\n" + "UID:123\r\n" + "DTSTAMP:20210803T063522Z\r\n" + "DTSTART;VALUE=DATE:20210902\r\n" + "BEGIN:VALARM\r\n" + "ACTION:DISPLAY\r\n" + "TRIGGER:-PT15M\r\n" + "END:VALARM\r\n" + "DESCRIPTION:aaa \r\n" + "\r\n" + " aaa\\naaa 1\\n \r\n" + "SUMMARY:Summary\r\n" + "END:VEVENT\r\n" + "END:VCALENDAR\r\n"; + VObject *vcal; + + vcal = Parse_MIME(vcard1, (unsigned long)strlen(vcard1)); + if(vcal) { + icalcomponent *icalcomp; + + icalcomp = icalvcal_convert(vcal); + ok("vCard1 is not iCalendar", (icalcomp == NULL)); + if(icalcomp) + icalcomponent_free(icalcomp); + + cleanVObject (vcal); + } else { + ok("vCard1 cannot be parsed", (vcal == NULL)); + } + + vcal = Parse_MIME(vcard2, (unsigned long)strlen(vcard2)); + if(vcal) { + icalcomponent *icalcomp; + + icalcomp = icalvcal_convert(vcal); + ok("vCard2 is not iCalendar", (icalcomp == NULL)); + if(icalcomp) + icalcomponent_free(icalcomp); + + cleanVObject(vcal); + } else { + ok("vCard2 cannot be parsed", (vcal == NULL)); + } + + vcal = Parse_MIME(vcalendar, (unsigned long)strlen(vcalendar)); + ok("vCalendar can be parsed", (vcal != NULL)); + if(vcal) { + icalcomponent *icalcomp; + + icalcomp = icalvcal_convert(vcal); + ok("vCalendar can be converted", (icalcomp != NULL)); + if(icalcomp) { + icalcomponent *child; + + ok("vCalendar is VCALENDAR", (icalcomponent_isa(icalcomp) == ICAL_VCALENDAR_COMPONENT)); + ok("vCalendar has one child", (icalcomponent_count_components(icalcomp, ICAL_ANY_COMPONENT) == 1)); + child = icalcomponent_get_inner(icalcomp); + ok("vCalendar has inner comp", (child != NULL && child != icalcomp)); + ok("vCalendar child is VEVENT", (icalcomponent_isa(child) == ICAL_VEVENT_COMPONENT)); + ok("vCalendar child UID matches", (strcmp(icalcomponent_get_uid(child), "123") == 0)); + ok("vCalendar child SUMMARY matches", (strcmp(icalcomponent_get_summary(child), "Summary") == 0)); + icalcomponent_free(icalcomp); + } + + cleanVObject(vcal); + } + + vcal = Parse_MIME(vcalendar_broken, (unsigned long)strlen(vcalendar_broken)); + ok("vCalendar-broken cannot be parsed", (vcal == NULL)); +} + +static void test_implicit_dtend_duration(void) +{ + const struct icaltimetype start1 = icaltime_from_string("20220108"); + icalcomponent* c = icalcomponent_vanew( + ICAL_VCALENDAR_COMPONENT, + icalcomponent_vanew( + ICAL_VEVENT_COMPONENT, + icalproperty_vanew_dtstart(start1, 0), + 0), + 0); + struct icaldurationtype d = icalcomponent_get_duration(c); + struct icaltimetype end = icalcomponent_get_dtend(c), + start = icaltime_from_string("20220108T101010Z"); + if (VERBOSE) { + printf("%s\n", icaldurationtype_as_ical_string(d)); + } + str_is("icaldurationtype_as_ical_string(d)", "P1D", icaldurationtype_as_ical_string(d)); + + if (VERBOSE) { + printf("%s\n", icaltime_as_ical_string(end)); + } + str_is("icaltime_as_ical_string(end)", "20220109", icaltime_as_ical_string(end)); + + icalcomponent_set_dtstart(c, start); + d = icalcomponent_get_duration(c); + end = icalcomponent_get_dtend(c); + if (VERBOSE) { + printf("%s\n", icaldurationtype_as_ical_string(d)); + } + int_is("icaldurationtype_as_int(d)", 0, icaldurationtype_as_int(d)); + + if (VERBOSE) { + printf("%s\n", icaltime_as_ical_string(end)); + } + int_is("icaltime_compare(start, end)", 0, icaltime_compare(start, end)); + icalcomponent_free(c); + + c = icalcomponent_vanew( + ICAL_VCALENDAR_COMPONENT, + icalcomponent_vanew( + ICAL_VTODO_COMPONENT, + icalproperty_vanew_dtstart(start1, 0), + 0), + 0); + icalcomponent_set_due(c, icaltime_from_string("20220109")); + d = icalcomponent_get_duration(c); + end = icalcomponent_get_dtend(c); + if (VERBOSE) { + printf("%s\n", icaldurationtype_as_ical_string(d)); + } + str_is("P1D", "P1D", icaldurationtype_as_ical_string(d)); + + if (VERBOSE) { + printf("%i\n", icaltime_is_null_time(end)); + } + int_is("icaltime_is_null_time(end)", 1, icaltime_is_null_time(end)); + icalcomponent_free(c); +} + +static void +test_icalvalue_resets_timezone_on_set(void) +{ + const char *strcomp = + "BEGIN:VCALENDAR\r\n" + "BEGIN:VTIMEZONE\r\n" + "TZID:my_zone\r\n" + "BEGIN:STANDARD\r\n" + "TZNAME:my_zone\r\n" + "DTSTART:19160429T230000\r\n" + "TZOFFSETFROM:+0100\r\n" + "TZOFFSETTO:+0200\r\n" + "RRULE:FREQ=YEARLY;UNTIL=19160430T220000Z;BYDAY=-1SU;BYMONTH=4\r\n" + "END:STANDARD\r\n" + "END:VTIMEZONE\r\n" + "BEGIN:VEVENT\r\n" + "UID:0\r\n" + "DTSTART;TZID=my_zone:20180101T010000\r\n" + "DTEND:20180202T020000Z\r\n" + "DUE:20180302T030000\r\n" + "END:VEVENT\r\n" + "END:VCALENDAR\r\n"; + icalcomponent *comp, *clone, *inner; + icaltimetype comp_dtstart, comp_dtend, comp_due; + icaltimetype clone_dtstart, clone_dtend, clone_due; + const char *orig_str, *clone_str; + int estate; + + estate = icalerror_get_errors_are_fatal(); + icalerror_set_errors_are_fatal(0); + + /* First try without calling 'set' */ + comp = icalcomponent_new_from_string(strcomp); + ok("1st - vCalendar can be parsed", (comp != NULL)); + inner = icalcomponent_get_inner(comp); + ok("1st - inner exists", (inner != NULL)); + orig_str = icalcomponent_as_ical_string(inner); + comp_dtstart = icalcomponent_get_dtstart(inner); + comp_dtend = icalcomponent_get_dtend(inner); + comp_due = icalcomponent_get_due(inner); + ok("1st - comp dtstart is non-UTC zone", (comp_dtstart.zone != NULL && comp_dtstart.zone != icaltimezone_get_utc_timezone())); + ok("1st - comp dtend is UTC zone", (comp_dtend.zone == icaltimezone_get_utc_timezone())); + ok("1st - comp due is floating", (comp_due.zone == NULL)); + clone = icalcomponent_new_clone(inner); + icalcomponent_free(comp); + /* note the comp_dtstart.zone points to a freed memory now (it was freed with the 'comp') */ + clone_dtstart = icalcomponent_get_dtstart(clone); + clone_dtend = icalcomponent_get_dtend(clone); + clone_due = icalcomponent_get_due(clone); + ok("1st - clone dtstart is null zone", (clone_dtstart.zone == NULL)); + ok("1st - clone dtend is UTC zone", (clone_dtend.zone == icaltimezone_get_utc_timezone())); + ok("1st - clone due is floating", (clone_due.zone == NULL)); + clone_str = icalcomponent_as_ical_string(clone); + ok("1st - clone and orig components match", (strcmp(orig_str, clone_str) == 0)); + icalcomponent_free(clone); + + /* Second try with calling 'set' */ + comp = icalcomponent_new_from_string(strcomp); + inner = icalcomponent_get_inner(comp); + orig_str = icalcomponent_as_ical_string(inner); + comp_dtstart = icalcomponent_get_dtstart(inner); + comp_dtend = icalcomponent_get_dtend(inner); + comp_due = icalcomponent_get_due(inner); + ok("2nd - comp dtstart is non-UTC zone", (comp_dtstart.zone != NULL && comp_dtstart.zone != icaltimezone_get_utc_timezone())); + ok("2nd - comp dtend is UTC zone", (comp_dtend.zone == icaltimezone_get_utc_timezone())); + ok("2nd - comp due is floating", (comp_due.zone == NULL)); + icalcomponent_set_dtstart(inner, comp_dtstart); + icalcomponent_set_dtend(inner, comp_dtend); + icalcomponent_set_due(inner, comp_due); + comp_dtstart = icalcomponent_get_dtstart(inner); + comp_dtend = icalcomponent_get_dtend(inner); + comp_due = icalcomponent_get_due(inner); + ok("2nd - comp dtstart is non-UTC zone", (comp_dtstart.zone != NULL && comp_dtstart.zone != icaltimezone_get_utc_timezone())); + ok("2nd - comp dtend is UTC zone after set", (comp_dtend.zone == icaltimezone_get_utc_timezone())); + ok("2nd - comp due is floating after set", (comp_due.zone == NULL)); + clone = icalcomponent_new_clone(inner); + icalcomponent_free(comp); + /* note the comp_dtstart.zone points to a freed memory now (it was freed with the 'comp') */ + clone_dtstart = icalcomponent_get_dtstart(clone); + clone_dtend = icalcomponent_get_dtend(clone); + clone_due = icalcomponent_get_due(clone); + ok("2nd - clone dtstart is null zone", (clone_dtstart.zone == NULL)); + ok("2nd - clone dtend is UTC zone", (clone_dtend.zone == icaltimezone_get_utc_timezone())); + ok("2nd - clone due is floating", (clone_due.zone == NULL)); + clone_str = icalcomponent_as_ical_string(clone); + ok("2nd - clone and orig components match", (strcmp(orig_str, clone_str) == 0)); + icalcomponent_free(clone); + + icalerror_set_errors_are_fatal(estate); + icalerror_clear_errno(); +} + +static void test_remove_tzid_from_due(void) +{ + icalproperty *due = icalproperty_vanew_due(icaltime_from_string("20220120T120000"), 0); + icalcomponent *c; + + icalproperty_add_parameter(due, icalparameter_new_tzid("America/New_York")); + + c = icalcomponent_vanew( + ICAL_VCALENDAR_COMPONENT, + icalcomponent_vanew( + ICAL_VTODO_COMPONENT, + due, + 0), + 0); + + icalcomponent_set_due(c, icaltime_from_string("20220120")); + str_is("icalproperty_as_ical_string()", "DUE;VALUE=DATE:20220120\r\n", icalproperty_as_ical_string(icalcomponent_get_first_property(icalcomponent_get_inner(c), ICAL_DUE_PROPERTY))); + + icalcomponent_free(c); +} + int main(int argc, char *argv[]) { #if !defined(HAVE_UNISTD_H) @@ -4892,6 +5237,17 @@ int main(int argc, char *argv[]) int do_header = 0; int failed_count = 0; +#if !defined(MEMORY_CONSISTENCY) + // With MEMORY_CONSISTENCY we are building the entire library using the + // test_* functions; therefore, no need to set them here again. + + // We specify special versions of malloc et al. that perform some extra verifications. + // Most notably they ensure, that memory allocated with icalmemory_new_buffer() is freed + // using icalmemory_free() rather than using free() directly and vice versa. Failing to + // do so would cause the test to fail with assertions or access violations. + icalmemory_set_mem_alloc_funcs(&test_malloc, &test_realloc, &test_free); +#endif + set_zone_directory(TEST_ZONEDIR); icaltimezone_set_tzid_prefix(TESTS_TZID_PREFIX); @@ -5021,6 +5377,11 @@ int main(int argc, char *argv[]) test_run("Test icalcomponent_normalize", test_icalcomponent_normalize, do_test, do_header); test_run("Test builtin compat TZID", test_builtin_compat_tzid, do_test, do_header); + test_run("Test VCC vCard parse", test_vcc_vcard_parse, do_test, do_header); + test_run("Test implicit DTEND and DURATION for VEVENT and VTODO", test_implicit_dtend_duration, do_test, do_header); + test_run("Test icalvalue resets timezone on set", test_icalvalue_resets_timezone_on_set, do_test, do_header); + test_run("Test removing TZID from DUE with icalcomponent_set_due", test_remove_tzid_from_due, do_test, do_header); + test_run("Test geo precision", test_geo_props, do_test, do_header); /** OPTIONAL TESTS go here... **/ diff --git a/src/test/regression.h b/src/test/regression.h index 9c5aab88..55531793 100644 --- a/src/test/regression.h +++ b/src/test/regression.h @@ -2,18 +2,10 @@ FILE: regression.c CREATOR: eric 03 April 1999 - (C) COPYRIGHT 1999 Eric Busboom <eric@civicknowledge.com> + SPDX-FileCopyrightText: 1999 Eric Busboom <eric@civicknowledge.com> - This library is free software; you can redistribute it and/or modify - it under the terms of either: + SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0 - The LGPL as published by the Free Software Foundation, version - 2.1, available at: https://www.gnu.org/licenses/lgpl-2.1.html - - Or: - - The Mozilla Public License Version 2.0. You may obtain a copy of - the License at https://www.mozilla.org/MPL/ ======================================================================*/ #ifndef TEST_REGRESSION_H #define TEST_REGRESSION_H @@ -52,7 +44,7 @@ extern "C" void test_bdbset(void); /* regression-utils.c */ - const char *ical_timet_string(const time_t t); + const char *ical_timet_string(const icaltime_t t); const char *ictt_as_string(struct icaltimetype t); char *icaltime_as_ctime(struct icaltimetype t); diff --git a/src/test/stow.c b/src/test/stow.c index 0b98126e..00b07d11 100644 --- a/src/test/stow.c +++ b/src/test/stow.c @@ -2,18 +2,9 @@ FILE: stow.c CREATOR: eric 29 April 2000 - (C) COPYRIGHT 2000 Eric Busboom <eric@civicknowledge.com> + SPDX-FileCopyrightText: 2000 Eric Busboom <eric@civicknowledge.com> - This library is free software; you can redistribute it and/or modify - it under the terms of either: - - The LGPL as published by the Free Software Foundation, version - 2.1, available at: https://www.gnu.org/licenses/lgpl-2.1.html - - Or: - - The Mozilla Public License Version 2.0. You may obtain a copy of - the License at https://www.mozilla.org/MPL/ + SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0 The Initial Developer of the Original Code is Eric Busboom ======================================================================*/ diff --git a/src/test/test-malloc.c b/src/test/test-malloc.c new file mode 100644 index 00000000..d9c46995 --- /dev/null +++ b/src/test/test-malloc.c @@ -0,0 +1,178 @@ +/*====================================================================== +FILE: test-malloc.c + +SPDX-FileCopyrightText: 2018-2022, Markus Minichmayr <markus@tapkey.com> + + SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0 + +======================================================================*/ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include "test-malloc.h" +#include "icalerror.h" +#if !defined(MEMORY_CONSISTENCY) +#include "regression.h" +#endif + +#include <stdlib.h> +#include <string.h> + +struct testmalloc_statistics global_testmalloc_statistics; +static int global_testmalloc_remaining_attempts = -1; + +#define TESTMALLOC_MAGIC_NO 0x1234abcd +struct testmalloc_hdr { + uint32_t magic_no; + size_t size; +}; + +struct testmalloc_hdrlayout { + struct testmalloc_hdr hdr; + int data; +}; + +#define TESTMALLOC_HDR_SIZE ((size_t) &((struct testmalloc_hdrlayout*) 0)->data) + +void *test_malloc(size_t size) { + + void *block; + struct testmalloc_hdr *hdr; + + global_testmalloc_statistics.malloc_cnt++; + if (global_testmalloc_remaining_attempts == 0) { + global_testmalloc_statistics.malloc_failed_cnt++; + return NULL; + } + + block = malloc(size + TESTMALLOC_HDR_SIZE); + if (block == NULL) { + global_testmalloc_statistics.malloc_failed_cnt++; + return NULL; + } + + hdr = (struct testmalloc_hdr *)block; + hdr->magic_no = TESTMALLOC_MAGIC_NO; + hdr->size = size; + + global_testmalloc_statistics.mem_allocated_current += size; + if (global_testmalloc_statistics.mem_allocated_current > global_testmalloc_statistics.mem_allocated_max) { + global_testmalloc_statistics.mem_allocated_max = global_testmalloc_statistics.mem_allocated_current; + } + + global_testmalloc_statistics.blocks_allocated++; + + if (global_testmalloc_remaining_attempts > 0) { + global_testmalloc_remaining_attempts--; + } + + return (void*) &((struct testmalloc_hdrlayout *) hdr)->data; +} + +void *test_realloc(void *p, size_t size) { + + struct testmalloc_hdr *hdr; + size_t old_size; + + global_testmalloc_statistics.realloc_cnt++; + if (global_testmalloc_remaining_attempts == 0) { + global_testmalloc_statistics.realloc_failed_cnt++; + return NULL; + } + + if (p == NULL) { + global_testmalloc_statistics.realloc_failed_cnt++; + return NULL; + } + + hdr = (struct testmalloc_hdr *) (((uint8_t *) p) - TESTMALLOC_HDR_SIZE); + if (hdr->magic_no != TESTMALLOC_MAGIC_NO) { + global_testmalloc_statistics.realloc_failed_cnt++; + return NULL; + } + + old_size = hdr->size; + hdr->magic_no = 0; + + // cppcheck-suppress memleakOnRealloc; the mem block p passed to this function stays valid. + hdr = (struct testmalloc_hdr *)realloc(hdr, size + TESTMALLOC_HDR_SIZE); + if (hdr == NULL) { + global_testmalloc_statistics.realloc_failed_cnt++; + return NULL; + } + + hdr->magic_no = TESTMALLOC_MAGIC_NO; + hdr->size = size; + + global_testmalloc_statistics.mem_allocated_current += size - old_size; + if (global_testmalloc_statistics.mem_allocated_current > global_testmalloc_statistics.mem_allocated_max) { + global_testmalloc_statistics.mem_allocated_max = global_testmalloc_statistics.mem_allocated_current; + } + + if (global_testmalloc_remaining_attempts > 0) { + global_testmalloc_remaining_attempts--; + } + + return (void *) &((struct testmalloc_hdrlayout *)hdr)->data; +} + +void test_free(void *p) { + + struct testmalloc_hdr *hdr; + size_t old_size; + + if (p == NULL) { + return; + } + + global_testmalloc_statistics.free_cnt++; + + hdr = (struct testmalloc_hdr *) (((uint8_t *) p) - TESTMALLOC_HDR_SIZE); + + // The main objective of this check is to ensure, that only memory, that has been allocated via icalmemory is freed + // via icalmemory_free(). A side objective is to make sure, the block of memory hasn't been corrupted. + if (hdr->magic_no != TESTMALLOC_MAGIC_NO) { + + // If we end up here, then probably either of the following happened: + // * The calling code tries to free a block of memory via icalmemory_free() that has been allocated outside of + // icalmemory, e.g. via malloc(). + // * The header in front of the memory block being freed has been corrupted. + +#if !defined(MEMORY_CONSISTENCY) + ok("freed memory was allocated via icalmemory and has not been corrupted", + hdr->magic_no == TESTMALLOC_MAGIC_NO); +#endif + icalerror_assert(hdr->magic_no == TESTMALLOC_MAGIC_NO, + "freed memory was allocated via icalmemory and has been corrupted"); + global_testmalloc_statistics.free_failed_cnt++; + return; + } + + old_size = hdr->size; + hdr->magic_no = 0; + + free(hdr); + + global_testmalloc_statistics.mem_allocated_current -= old_size; + global_testmalloc_statistics.blocks_allocated--; +} + +void testmalloc_reset() { + memset(&global_testmalloc_statistics, 0, sizeof(global_testmalloc_statistics)); + global_testmalloc_remaining_attempts = -1; +} + +/** Sets the maximum number of malloc or realloc attemts that will succeed. If +* the number is negative, no limit will be applied. */ +void testmalloc_set_max_successful_allocs(int n) { + global_testmalloc_remaining_attempts = n; +} + +void testmalloc_get_statistics(struct testmalloc_statistics *statistics) { + + if (statistics) { + *statistics = global_testmalloc_statistics; + } +} diff --git a/src/test/test-malloc.h b/src/test/test-malloc.h new file mode 100644 index 00000000..04858bae --- /dev/null +++ b/src/test/test-malloc.h @@ -0,0 +1,61 @@ +/*====================================================================== +FILE: test-malloc.h + +SPDX-FileCopyrightText: 2018-2022, Markus Minichmayr <markus@tapkey.com> + + SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0 + +======================================================================*/ + +#ifndef TESTMALLOC_H +#define TESTMALLOC_H + +#include <stdint.h> + +#include "libical_ical_export.h" + +struct testmalloc_statistics { + int malloc_cnt; + int realloc_cnt; + int free_cnt; + + int malloc_failed_cnt; + int realloc_failed_cnt; + int free_failed_cnt; + + size_t mem_allocated_max; + size_t mem_allocated_current; + int blocks_allocated; +}; + +/** Allocates the specified amount of memory and returns a pointer to the allocated memory. + * Memory allocated using this function must be freed using test_free(). + * The number of allocations that can be made using this function can be limited via + * testmalloc_set_max_successful_allocs(). + */ +LIBICAL_ICAL_EXPORT void *test_malloc(size_t size); + +/** Resizes the specified buffer. + * Can only be used with memory that has previously been allocated using test_malloc(). + */ +LIBICAL_ICAL_EXPORT void *test_realloc(void *p, size_t size); + +/** Frees a block of memory that has previously been allocated via the test_malloc() function. Specifying memory that + * has not been allocated via test_malloc() causes an assertion. + */ +LIBICAL_ICAL_EXPORT void test_free(void *p); + +/** Resets the memory management statistics and sets the number of successful + * allocations limit to infinite. + */ +LIBICAL_ICAL_EXPORT void testmalloc_reset(); + +/** Sets the maximum number of malloc or realloc attemts that will succeed. If + * the number is negative, no limit will be applied. + */ +LIBICAL_ICAL_EXPORT void testmalloc_set_max_successful_allocs(int n); + +/** Gets current memory allocation statistics. */ +LIBICAL_ICAL_EXPORT void testmalloc_get_statistics(struct testmalloc_statistics *statistics); + +#endif /* !TESTMALLOC_H */ diff --git a/src/test/testmime.c b/src/test/testmime.c index e0c53ea9..df904868 100644 --- a/src/test/testmime.c +++ b/src/test/testmime.c @@ -2,18 +2,9 @@ FILE: CREATOR: eric 25 June 2000 - (C) COPYRIGHT 2000, Eric Busboom <eric@civicknowledge.com> + SPDX-FileCopyrightText: 2000, Eric Busboom <eric@civicknowledge.com> - This library is free software; you can redistribute it and/or modify - it under the terms of either: - - The LGPL as published by the Free Software Foundation, version - 2.1, available at: https://www.gnu.org/licenses/lgpl-2.1.html - - Or: - - The Mozilla Public License Version 2.0. You may obtain a copy of - the License at https://www.mozilla.org/MPL/ + SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0 The Initial Developer of the Original Code is Eric Busboom ======================================================================*/ diff --git a/src/test/testvcal.c b/src/test/testvcal.c index 96650f44..f38df8a8 100644 --- a/src/test/testvcal.c +++ b/src/test/testvcal.c @@ -2,18 +2,9 @@ FILE: testvcal.c CREATOR: eric 26 May 2000 - (C) COPYRIGHT 2000 Eric Busboom <eric@civicknowledge.com> + SPDX-FileCopyrightText: 2000 Eric Busboom <eric@civicknowledge.com> - This library is free software; you can redistribute it and/or modify - it under the terms of either: - - The LGPL as published by the Free Software Foundation, version - 2.1, available at: https://www.gnu.org/licenses/lgpl-2.1.html - - Or: - - The Mozilla Public License Version 2.0. You may obtain a copy of - the License at https://www.mozilla.org/MPL/ + SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0 The Original Code is eric. The Initial Developer of the Original Code is Eric Busboom diff --git a/src/test/timezones.c b/src/test/timezones.c index 935e912d..0285e3b5 100644 --- a/src/test/timezones.c +++ b/src/test/timezones.c @@ -1,18 +1,9 @@ /* ====================================================================== - (C) COPYRIGHT 2008, Eric Busboom <eric@civicknowledge.com> + SPDX-FileCopyrightText: 2008, Eric Busboom <eric@civicknowledge.com> - This library is free software; you can redistribute it and/or modify - it under the terms of either: - - The LGPL as published by the Free Software Foundation, version - 2.1, available at: https://www.gnu.org/licenses/lgpl-2.1.html - - Or: - - The Mozilla Public License Version 2.0. You may obtain a copy of - the License at https://www.mozilla.org/MPL/ + SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0 ======================================================================*/ @@ -39,9 +30,9 @@ int main() int verbose = 0; int day; - time_t start_time; + icaltime_t start_time; struct tm start_tm; - time_t curr_time; + icaltime_t curr_time; struct tm curr_tm; struct icaltimetype curr_tt; int failed = 0; @@ -82,19 +73,19 @@ int main() * determine current local time and date: always use midday in * the current zone and first day of first month in the year */ - start_time = time(NULL); - (void)localtime_r(&start_time, &start_tm); + start_time = icaltime(NULL); + (void)icallocaltime_r(&start_time, &start_tm); start_tm.tm_hour = 12; start_tm.tm_min = 0; start_tm.tm_sec = 0; start_tm.tm_mday = 1; start_tm.tm_mon = 0; - start_time = mktime(&start_tm); + start_time = icalmktime(&start_tm); /* check time conversion for the next 365 days */ for (day = 0, curr_time = start_time; day < 365; day++, curr_time += 24 * 60 * 60) { /* determine date/time with glibc */ - localtime_r(&curr_time, &curr_tm); + icallocaltime_r(&curr_time, &curr_tm); /* determine date/time with libical */ curr_tt = icaltime_from_timet_with_zone(curr_time, 0, utc_zone); curr_tt.zone = utc_zone; /* workaround: icaltime_from_timet_with_zone() @@ -114,7 +105,7 @@ int main() if (verbose || curr_failed != failed) { struct tm utc_tm; - if (!gmtime_r(&curr_time, &utc_tm)) + if (!icalgmtime_r(&curr_time, &utc_tm)) memset(&utc_tm, 0, sizeof(utc_tm)); printf( |