check_PROGRAMS = \
src/tests/test_ptrs_list_foreach_pos \
+ src/tests/test_ptrs_list_map \
src/tests/test_compression_common \
src/tests/test_fastlz_neg \
src/tests/fuzz_logprint \
src_tests_test_ptrs_list_neg_CFLAGS = $(check_CFLAGS)
src_tests_test_ptrs_list_neg_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=free,--wrap=calloc
+src_tests_test_ptrs_list_map_SOURCES = src/tests/test_ptrs_list_map.c src/shared/ptrs_list.c
+src_tests_test_ptrs_list_map_CFLAGS = $(check_CFLAGS)
+src_tests_test_ptrs_list_map_LDFLAGS = $(AM_LDFLAGS)
+
src_tests_test_common_SOURCES = src/tests/test_common.c src/shared/logcommon.c src/shared/buffer_traits.c src/shared/logconfig.c src/shared/parsers.c src/shared/backend_androidlogger.c
src_tests_test_common_CFLAGS = $(check_CFLAGS)
src_tests_test_common_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=sendmsg,--wrap=recvmsg,--wrap=writev,--wrap=read,--wrap=poll,--wrap=fcntl,--wrap=fcntl64,--wrap=malloc,--wrap=calloc,--wrap=connect,--wrap=socket,--wrap=open,--wrap=open64,--wrap=ioctl
--- /dev/null
+/* Copyright (c) 2023, Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License. */
+
+#include <ptrs_list.h>
+
+#include <assert.h>
+#include <stddef.h>
+#include <stdint.h>
+
+static void sum_list(void *element, void *userdata)
+{
+ *((int *) userdata) += (intptr_t) element;
+}
+
+static elem_value map_to_square(elem_value value, void *_)
+{
+ intptr_t v = (intptr_t) value;
+ intptr_t v2 = v * v;
+ return (elem_value) v2;
+}
+
+int main()
+{
+ // Make a simple list: 1-2-3
+ list_head L = NULL;
+ for (int i = 1; i <= 3; ++i)
+ list_add(&L, (void *) ((intptr_t) i));
+
+ // Run some basic checks as a reference point for later.
+ int sum = 0;
+ list_foreach(L, &sum, sum_list);
+ assert(sum == 1+2+3);
+
+ // Map it to squares, i.e. 1-4-9
+ list_head M = list_map(L, NULL, map_to_square, NULL);
+ sum = 0;
+ list_foreach(M, &sum, sum_list);
+ assert(sum == 1+4+9);
+
+ // Iterate manually to make sure the list is linked 1-4-9 and not 9-4-1
+ list_head Li = L;
+ list_head Mi = M;
+ while (Li && Mi) {
+ intptr_t x = (intptr_t) list_at(Li);
+ assert((intptr_t) list_at(Mi) == x * x);
+
+ list_next(&Li);
+ list_next(&Mi);
+ }
+ assert(!Li && !Mi);
+
+ list_clear(&L);
+ list_clear(&M);
+
+ return 0;
+}
+