forked from gsl-lite/gsl-lite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathowner.t.cpp
90 lines (75 loc) · 2.4 KB
/
owner.t.cpp
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//
// gsl-lite is based on GSL: Guidelines Support Library.
// For more information see https://github.com/gsl-lite/gsl-lite
//
// Copyright (c) 2015-2019 Martin Moene
// Copyright (c) 2019-2021 Moritz Beutel
// Copyright (c) 2015-2018 Microsoft Corporation. All rights reserved.
//
// This code is licensed under the MIT License (MIT).
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#include "gsl-lite.t.hpp"
using namespace gsl;
CASE( "owner<>: Disallows construction from a non-pointer type (define gsl_CONFIG_CONFIRMS_COMPILATION_ERRORS)" )
{
#if gsl_CONFIG( CONFIRMS_COMPILATION_ERRORS )
# if gsl_HAVE( TYPE_TRAITS )
owner<int> p = gsl_nullptr;
# else
EXPECT( !!"owner<> alias template restricted to pointer type is not available." );
# endif
#endif
}
CASE( "owner<>: Allows its use as the (pointer) type it stands for" )
{
#if gsl_HAVE( OWNER_TEMPLATE )
struct F { static void incr( int * i ) { *i += 1; } };
owner<int*> p = new int( 120 );
EXPECT( (p != NULL) );
EXPECT( p != nullptr_void() );
# if gsl_HAVE( NULLPTR )
EXPECT( p != nullptr );
# endif
EXPECT( *p == 120 );
F::incr( p );
EXPECT( *p == 121 );
delete p;
#if gsl_FEATURE( GSL_LITE_NAMESPACE )
// Also try to consume `owner<>` from the `gsl_lite` namespace
gsl_lite::owner<int*> p2 = new int( 120 );
EXPECT( ( p2 != NULL ) );
EXPECT( *p2 == 120 );
F::incr( p2 );
EXPECT( *p2 == 121 );
delete p2;
#endif
#else
EXPECT( !!"owner<> alias template is not available." );
#endif
}
CASE( "Owner(): Allows its use as the (pointer) type it stands for" )
{
#if gsl_FEATURE( OWNER_MACRO )
struct F { static void incr( int * i ) { *i += 1; } };
Owner(int*) p = new int( 120 );
EXPECT( (p != NULL) );
EXPECT( p != nullptr_void() );
# if gsl_HAVE( NULLPTR )
EXPECT( p != nullptr );
# endif
EXPECT( *p == 120 );
F::incr( p );
EXPECT( *p == 121 );
delete p;
#else
EXPECT( !!"Owner() macro is not available." );
#endif
}
// end of file