Blender V4.3
scoped_ptr_test.cc
Go to the documentation of this file.
1// Copyright (c) 2009 libmv authors.
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to
5// deal in the Software without restriction, including without limitation the
6// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7// sell copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19// IN THE SOFTWARE.
20
22#include "testing/testing.h"
23
24namespace libmv {
25namespace {
26
27struct FreeMe {
28 FreeMe(int* freed) : freed(freed) {}
29 ~FreeMe() { (*freed)++; }
30 int* freed;
31};
32
33TEST(ScopedPtr, NullDoesNothing) {
34 scoped_ptr<FreeMe> x(NULL);
35 // Does nothing.
36}
37
38TEST(ScopedPtr, FreesWhenOutOfScope) {
39 int frees = 0;
40 {
41 scoped_ptr<FreeMe> scoped(new FreeMe(&frees));
42 EXPECT_EQ(0, frees);
43 }
44 EXPECT_EQ(1, frees);
45}
46
47TEST(ScopedPtr, Operators) {
48 int tag = 123;
49 scoped_ptr<FreeMe> scoped(new FreeMe(&tag));
50 EXPECT_EQ(123, *(scoped->freed));
51 EXPECT_EQ(123, *((*scoped).freed));
52}
53
54TEST(ScopedPtr, Reset) {
55 int frees = 0;
56 scoped_ptr<FreeMe> scoped(new FreeMe(&frees));
57 EXPECT_EQ(0, frees);
58 scoped.reset(new FreeMe(&frees));
59 EXPECT_EQ(1, frees);
60}
61
62TEST(ScopedPtr, ReleaseAndGet) {
63 int frees = 0;
64 FreeMe* allocated = new FreeMe(&frees);
65 FreeMe* released = NULL;
66 {
67 scoped_ptr<FreeMe> scoped(allocated);
68 EXPECT_EQ(0, frees);
69 EXPECT_EQ(allocated, scoped.get());
70 released = scoped.release();
71 EXPECT_EQ(0, frees);
72 EXPECT_EQ(released, allocated);
73 }
74 EXPECT_EQ(0, frees);
75 delete released;
76}
77
78} // namespace
79} // namespace libmv
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
#define NULL
TEST(PolynomialCameraIntrinsics2, ApplyOnFocalCenter)
int * freed