Commit 522a88cd for libheif
commit 522a88cdf3665f19539d754bdc9473d78604ab15
Author: Dirk Farin <dirk.farin@gmail.com>
Date: Mon Oct 26 09:20:27 2026 +0100
tests: move internal-API text test into text_internal
The memory budget test added in ea751a33 uses internal classes
(TextItem, TotalMemoryTracker, global_security_limits), which are not
exported with WITH_REDUCED_VISIBILITY=ON. This broke linking the tests
in default Release builds. Move it into its own test that is only built
when internal symbols are visible.
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 6a785e5d..37874f2c 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -149,6 +149,9 @@ add_libheif_test(sequence_nonvisual_sample_entry)
add_libheif_test(sequence_no_decoder_output)
add_libheif_test(tai)
add_libheif_test(text)
+if (NOT WITH_REDUCED_VISIBILITY)
+ add_libheif_test(text_internal)
+endif()
add_libheif_test(cxx_wrapper)
add_libheif_test(component_descriptions)
add_libheif_test(ffmpeg_decode_bitdepth)
diff --git a/tests/text.cc b/tests/text.cc
index ffd2e448..edebbff1 100644
--- a/tests/text.cc
+++ b/tests/text.cc
@@ -29,12 +29,9 @@
#include "libheif/heif.h"
#include "test-config.h"
#include "test_utils.h"
-#include "security_limits.h"
-#include "text.h"
#include <cstddef>
#include <cstdint>
#include <cstring>
-#include <utility>
#include <libheif/heif_items.h>
#include <libheif/heif_library.h>
@@ -53,30 +50,6 @@ TEST_CASE("no text") {
heif_context_free(context);
}
-
-TEST_CASE("retained text data remains charged to the memory budget") {
- heif_security_limits limits = global_security_limits;
- limits.max_total_memory = 48;
- TotalMemoryTracker tracker(&limits);
-
- TextItem second;
- std::vector<uint8_t> second_data(32, 'b');
- {
- TextItem first;
- std::vector<uint8_t> first_data(32, 'a');
- REQUIRE_FALSE(first.parse(std::move(first_data), &limits));
- auto first_text = first.get_item_text();
- REQUIRE(first_text);
- REQUIRE(*first_text == std::string(32, 'a'));
-
- Error err = second.parse(std::move(second_data), &limits);
- REQUIRE(err.error_code == heif_error_Memory_allocation_error);
- REQUIRE(err.sub_error_code == heif_suberror_Security_limit_exceeded);
- }
-
- REQUIRE_FALSE(second.parse(std::move(second_data), &limits));
-}
-
TEST_CASE("create text item") {
// skip test if we do not have the uncompressed codec
if (!heif_have_decoder_for_format(heif_compression_uncompressed)) {
diff --git a/tests/text_internal.cc b/tests/text_internal.cc
new file mode 100644
index 00000000..9375aa1e
--- /dev/null
+++ b/tests/text_internal.cc
@@ -0,0 +1,57 @@
+/*
+ libheif unit tests for text items (internal API)
+
+ MIT License
+
+ Copyright (c) 2026 Dirk Farin <dirk.farin@gmail.com>
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in all
+ copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ SOFTWARE.
+*/
+
+#include "catch_amalgamated.hpp"
+#include "security_limits.h"
+#include "text.h"
+#include <cstdint>
+#include <string>
+#include <utility>
+#include <vector>
+
+
+TEST_CASE("retained text data remains charged to the memory budget") {
+ heif_security_limits limits = global_security_limits;
+ limits.max_total_memory = 48;
+ TotalMemoryTracker tracker(&limits);
+
+ TextItem second;
+ std::vector<uint8_t> second_data(32, 'b');
+ {
+ TextItem first;
+ std::vector<uint8_t> first_data(32, 'a');
+ REQUIRE_FALSE(first.parse(std::move(first_data), &limits));
+ auto first_text = first.get_item_text();
+ REQUIRE(first_text);
+ REQUIRE(*first_text == std::string(32, 'a'));
+
+ Error err = second.parse(std::move(second_data), &limits);
+ REQUIRE(err.error_code == heif_error_Memory_allocation_error);
+ REQUIRE(err.sub_error_code == heif_suberror_Security_limit_exceeded);
+ }
+
+ REQUIRE_FALSE(second.parse(std::move(second_data), &limits));
+}