Skip to content

Commit

Permalink
New clif/testing/python:vector_unique_ptr_member_test
Browse files Browse the repository at this point in the history
BEGIN_PUBLIC

New clif/testing/python:vector_unique_ptr_member_test

END_PUBLIC

Follow-on to:

* pybind/pybind11#4630  —  Introduce `pybind11::detail::is_move_constructible`

* cl/526123390  —  Generate is_move_constructible<T>: std::false_type to tell pybind11 that T is not movable.

Originally reduced from:

```
blaze build //waymo/planner/evaluation/metrics/time_to_encroachment/encroachment_utils/python:potential_collision_severity_calculator_clif
```

Manually tested with `_GEN_PYBIND11 = True` in devtools/clif/python/clif_build_rule.bzl:

* http://sponge2/200da41a-fdd0-4e0e-a3e7-8fd00294b84d

PiperOrigin-RevId: 526133273
  • Loading branch information
rwgk authored and wangxf123456 committed May 18, 2023
1 parent e6ff775 commit b66e837
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
20 changes: 20 additions & 0 deletions clif/testing/python/vector_unique_ptr_member.clif
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2023 Google LLC
#
# 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.

from "clif/testing/vector_unique_ptr_member.h":
namespace `clif_testing_vector_unique_ptr_member`:
class VectorOwner:
@classmethod
def Create(cls, num_elems: int) -> VectorOwner
def data_size(self) -> int
30 changes: 30 additions & 0 deletions clif/testing/python/vector_unique_ptr_member_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright 2023 Google LLC
#
# 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.

from absl.testing import absltest
from absl.testing import parameterized

from clif.testing.python import vector_unique_ptr_member


class VectorUniquePtrMemberTest(parameterized.TestCase):

@parameterized.parameters(range(3))
def testCreate(self, num_elems):
vo = vector_unique_ptr_member.VectorOwner.Create(num_elems)
assert vo.data_size() == num_elems


if __name__ == '__main__':
absltest.main()
44 changes: 44 additions & 0 deletions clif/testing/vector_unique_ptr_member.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2023 Google LLC
*
* 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.
*/
#ifndef CLIF_TESTING_VECTOR_UNIQUE_PTR_MEMBER_H_
#define CLIF_TESTING_VECTOR_UNIQUE_PTR_MEMBER_H_

#include <memory>
#include <vector>

namespace clif_testing_vector_unique_ptr_member {

struct DataType {};

// Reduced from a use case in the wild.
struct VectorOwner {
static std::unique_ptr<VectorOwner> Create(std::size_t num_elems) {
return std::unique_ptr<VectorOwner>(
new VectorOwner(std::vector<std::unique_ptr<DataType>>(num_elems)));
}

std::size_t data_size() const { return data_.size(); }

private:
explicit VectorOwner(std::vector<std::unique_ptr<DataType>> data)
: data_(std::move(data)) {}

const std::vector<std::unique_ptr<DataType>> data_;
};

} // namespace clif_testing_vector_unique_ptr_member

#endif // CLIF_TESTING_VECTOR_UNIQUE_PTR_MEMBER_H_

0 comments on commit b66e837

Please sign in to comment.