diff --git a/clif/testing/python/vector_unique_ptr_member.clif b/clif/testing/python/vector_unique_ptr_member.clif new file mode 100644 index 00000000..20c6adec --- /dev/null +++ b/clif/testing/python/vector_unique_ptr_member.clif @@ -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 diff --git a/clif/testing/python/vector_unique_ptr_member_test.py b/clif/testing/python/vector_unique_ptr_member_test.py new file mode 100644 index 00000000..8dca3cfb --- /dev/null +++ b/clif/testing/python/vector_unique_ptr_member_test.py @@ -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() diff --git a/clif/testing/vector_unique_ptr_member.h b/clif/testing/vector_unique_ptr_member.h new file mode 100644 index 00000000..ee27a518 --- /dev/null +++ b/clif/testing/vector_unique_ptr_member.h @@ -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 +#include + +namespace clif_testing_vector_unique_ptr_member { + +struct DataType {}; + +// Reduced from a use case in the wild. +struct VectorOwner { + static std::unique_ptr Create(std::size_t num_elems) { + return std::unique_ptr( + new VectorOwner(std::vector>(num_elems))); + } + + std::size_t data_size() const { return data_.size(); } + + private: + explicit VectorOwner(std::vector> data) + : data_(std::move(data)) {} + + const std::vector> data_; +}; + +} // namespace clif_testing_vector_unique_ptr_member + +#endif // CLIF_TESTING_VECTOR_UNIQUE_PTR_MEMBER_H_