Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cpp/src/arrow/engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ add_arrow_test(substrait_test
substrait/ext_test.cc
substrait/function_test.cc
substrait/serde_test.cc
substrait/protobuf_test_util.cc
EXTRA_LINK_LIBS
${ARROW_SUBSTRAIT_TEST_LINK_LIBS}
PREFIX
Expand Down
42 changes: 42 additions & 0 deletions cpp/src/arrow/engine/substrait/protobuf_test_util.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// 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
//
// 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 <gtest/gtest.h>

#include <google/protobuf/message_lite.h>

namespace arrow {
namespace engine {

// A global test "environment", to ensure that the Protobuf API is finalized after
// running unit tests by invoking google::protobuf::ShutdownProtobufLibrary.
// This will prevent leaks in valgrind tests because it will delete the global objects
// that were allocated by the Protocol Buffer library (see
// "protobuf::ShutdownProtobufLibrary" in
// https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.message_lite#ShutdownProtobufLibrary.details)

class ProtobufEnvironment : public ::testing::Environment {
public:
void SetUp() override { GOOGLE_PROTOBUF_VERIFY_VERSION; }
void TearDown() override { google::protobuf::ShutdownProtobufLibrary(); }
};

::testing::Environment* protobuf_env =
::testing::AddGlobalTestEnvironment(new ProtobufEnvironment);

} // namespace engine
} // namespace arrow