blob: d5cca8b6ed24068fa9aa9e6e3937916764fc3e7b (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vespa/vespalib/util/weakref.h>
#include <vespa/vespalib/testkit/testapp.h>
using vespalib::WeakRef;
class Test : public vespalib::TestApp
{
public:
int getFive() { return 5; }
void testSimple();
int Main() override;
};
void
Test::testSimple()
{
WeakRef<Test>::Owner owner(this);
WeakRef<Test> ref(owner);
{
WeakRef<Test>::Usage use(ref);
ASSERT_TRUE(use.valid());
EXPECT_TRUE(use->getFive() == 5);
}
owner.clear();
{
WeakRef<Test>::Usage use(ref);
EXPECT_TRUE(!use.valid());
}
}
int
Test::Main()
{
TEST_INIT("weakref_test");
testSimple();
TEST_DONE();
}
TEST_APPHOOK(Test)
|