Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[experimental] Test move-support for proto #5575

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
53 changes: 53 additions & 0 deletions onnx/test/cpp/proto_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright (c) ONNX Project Contributors

Check warning

Code scanning / lintrunner

CLANGFORMAT/format Warning

See https://clang.llvm.org/docs/ClangFormat.html.
Run lintrunner -a to apply this patch.

/*
* SPDX-License-Identifier: Apache-2.0
*/

#include "gtest/gtest.h"

Check warning on line 7 in onnx/test/cpp/proto_test.cc

View workflow job for this annotation

GitHub Actions / clang-tidy-review

clang-tidy

warning: 'gtest/gtest.h' file not found [clang-diagnostic-error] ```cpp #include "gtest/gtest.h" ^ ```
#include "onnx/onnx_pb.h"

using namespace ONNX_NAMESPACE;

Check warning on line 10 in onnx/test/cpp/proto_test.cc

View workflow job for this annotation

GitHub Actions / Optional Lint

[cpplint] reported by reviewdog 🐶 Do not use namespace using-directives. Use using-declarations instead. [build/namespaces] [5] Raw Output: onnx/test/cpp/proto_test.cc:10: Do not use namespace using-directives. Use using-declarations instead. [build/namespaces] [5]

namespace ONNX_NAMESPACE {
namespace Test {

using NodeList = google::protobuf::RepeatedPtrField<NodeProto>;

TEST(ProtoTest, Move) {
NodeList nodelist1;
NodeList nodelist2;

nodelist1.Add()->set_name("node1");
nodelist1.Add()->set_name("node2");

ASSERT_EQ(nodelist1.size(), 2);
ASSERT_EQ(nodelist2.size(), 0);

nodelist2 = std::move(nodelist1);

ASSERT_EQ(nodelist1.size(), 0);
ASSERT_EQ(nodelist2.size(), 2);

NodeProto node1;
NodeProto node2;

node1.mutable_input()->Add("input1");
node1.mutable_input()->Add("input2");

ASSERT_EQ(node1.input().size(), 2);
ASSERT_EQ(node2.input().size(), 0);

node2 = std::move(node1);

ASSERT_EQ(node1.input().size(), 0);
ASSERT_EQ(node2.input().size(), 2);

nodelist1.Add(std::move(node2));
ASSERT_EQ(nodelist1.size(), 1);
ASSERT_EQ(nodelist1.Get(0).input().size(), 2);
ASSERT_EQ(node2.input().size(), 0);
}

}

Check warning on line 52 in onnx/test/cpp/proto_test.cc

View workflow job for this annotation

GitHub Actions / Optional Lint

[cpplint] reported by reviewdog 🐶 Namespace should be terminated with "// namespace Test" [readability/namespace] [5] Raw Output: onnx/test/cpp/proto_test.cc:52: Namespace should be terminated with "// namespace Test" [readability/namespace] [5]
}

Check warning on line 53 in onnx/test/cpp/proto_test.cc

View workflow job for this annotation

GitHub Actions / Optional Lint

[cpplint] reported by reviewdog 🐶 Namespace should be terminated with "// namespace ONNX_NAMESPACE" [readability/namespace] [5] Raw Output: onnx/test/cpp/proto_test.cc:53: Namespace should be terminated with "// namespace ONNX_NAMESPACE" [readability/namespace] [5]