This is an automated email from the ASF dual-hosted git repository.
Fokko pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/avro.git
The following commit(s) were added to refs/heads/main by this push:
new a4972181af [c++] Include <memory> and <vector> in Layout.hh (#4076)
a4972181af is described below
commit a4972181af1b0c4582362cdeae57d0f853937f53
Author: Martin Kuntz Jacobsen <[email protected]>
AuthorDate: Mon Nov 9 17:50:06 2026 +0100
[c++] Include <memory> and <vector> in Layout.hh (#4076)
* [c++] Include <memory> and <vector> in Layout.hh
Layout.hh uses std::unique_ptr and std::vector but relies on other
headers to include them. Add the includes and a test that includes
Layout.hh first.
* [c++] Define init_unit_test_suite in LayoutTests
The test used BOOST_AUTO_TEST_CASE without BOOST_TEST_MODULE, so the
included Boost.Test runner had no init_unit_test_suite and linking
failed. Register the test case the same way the other C++ tests do,
and exercise CompoundLayout so the <memory>/<vector> uses are compiled.
---
lang/c++/CMakeLists.txt | 1 +
lang/c++/include/avro/Layout.hh | 2 ++
lang/c++/test/LayoutTests.cc | 43 +++++++++++++++++++++++++++++++++++++++++
3 files changed, 46 insertions(+)
diff --git a/lang/c++/CMakeLists.txt b/lang/c++/CMakeLists.txt
index a88bc77f09..ba4b7b7c62 100644
--- a/lang/c++/CMakeLists.txt
+++ b/lang/c++/CMakeLists.txt
@@ -216,6 +216,7 @@ if (AVRO_BUILD_TESTS)
endmacro (unittest)
unittest (buffertest)
+ unittest (LayoutTests)
unittest (unittest)
unittest (SchemaTests)
unittest (LargeSchemaTests)
diff --git a/lang/c++/include/avro/Layout.hh b/lang/c++/include/avro/Layout.hh
index cbc05df4a6..d5a25cb754 100644
--- a/lang/c++/include/avro/Layout.hh
+++ b/lang/c++/include/avro/Layout.hh
@@ -21,7 +21,9 @@
#include "Config.hh"
+#include <memory>
#include <stddef.h>
+#include <vector>
/// \file Layout.hh
///
diff --git a/lang/c++/test/LayoutTests.cc b/lang/c++/test/LayoutTests.cc
new file mode 100644
index 0000000000..76892d538e
--- /dev/null
+++ b/lang/c++/test/LayoutTests.cc
@@ -0,0 +1,43 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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
+ *
+ * https://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.
+ */
+
+// Layout.hh must be self-contained: include it before anything else.
+#include "Layout.hh"
+
+#include <boost/test/included/unit_test.hpp>
+
+namespace avro {
+
+void testCompoundLayout() {
+ CompoundLayout compound(8);
+ std::unique_ptr<Layout> child = std::make_unique<PrimitiveLayout>(16);
+ compound.add(child);
+ BOOST_CHECK_EQUAL(compound.offset(), 8U);
+ BOOST_CHECK_EQUAL(compound.at(0).offset(), 16U);
+}
+
+} // namespace avro
+
+boost::unit_test::test_suite *
+init_unit_test_suite(int /*argc*/, char * /*argv*/[]) {
+ using namespace boost::unit_test;
+
+ auto *ts = BOOST_TEST_SUITE("Avro C++ unit tests for Layout");
+ ts->add(BOOST_TEST_CASE(&avro::testCompoundLayout));
+ return ts;
+}