X-Git-Url: https://gerrit.akraino.org/r/gitweb?a=blobdiff_plain;f=src%2Ftype3_AndroidCloud%2Fanbox-master%2Ftests%2Fanbox%2Fcommon%2Fscope_ptr_tests.cpp;fp=src%2Ftype3_AndroidCloud%2Fanbox-master%2Ftests%2Fanbox%2Fcommon%2Fscope_ptr_tests.cpp;h=25e300c8c7c39010d7baa8967d793374666e4b7b;hb=e26c1ec581be598521517829adba8c8dd23a768f;hp=0000000000000000000000000000000000000000;hpb=6699c1aea74eeb0eb400e6299079f0c7576f716f;p=iec.git diff --git a/src/type3_AndroidCloud/anbox-master/tests/anbox/common/scope_ptr_tests.cpp b/src/type3_AndroidCloud/anbox-master/tests/anbox/common/scope_ptr_tests.cpp new file mode 100644 index 0000000..25e300c --- /dev/null +++ b/src/type3_AndroidCloud/anbox-master/tests/anbox/common/scope_ptr_tests.cpp @@ -0,0 +1,65 @@ +// Copyright (C) 2016 The Android Open Source Project +// +// 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. + +#include "anbox/common/scope_ptr.h" + +#include + +#include +#include + +namespace anbox { +namespace common { + +TEST(ScopedPtr, FuncDelete_conversions) { + // This test makes sure the code compiles, it doesn't do any runtime checks. + auto lambda = [](int i) { return i; }; + FuncDelete lambdaFd(lambda); + // unary + converts a captureless lambda into a raw function pointer + FuncDelete funcFd1(+lambda); + + // copy ctor + FuncDelete funcFd2(funcFd1); + // assignment operator + funcFd2 = funcFd1; + // move operator + funcFd2 = std::move(funcFd1); + + // conversion ctor + FuncDelete funcFd3(lambdaFd); + // conversion move ctor + FuncDelete funcFd4(std::move(lambdaFd)); + // conversion assignment + funcFd3 = lambdaFd; + // conversion move + funcFd3 = std::move(lambdaFd); +} + +TEST(ScopedPtr, makeCustomScopedPtr_fromLambda) { + auto freeAsLambda = [](void* ptr) { free(ptr); }; + + auto ptr1 = makeCustomScopedPtr(malloc(1), freeAsLambda); + + ScopedPtr> ptr2 = + makeCustomScopedPtr(malloc(1), freeAsLambda); + + ScopedPtr> ptr3 = + makeCustomScopedPtr(malloc(1), +freeAsLambda); + + static_assert(!std::is_same::value, + "Custom ScopedPtr<> from a lambda expression type may not " + "be the same as with a function pointer"); +} +} // namespace common +} // namespace anbox