forked from gsl-lite/gsl-lite
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathowner.t.cpp
More file actions
66 lines (54 loc) · 1.74 KB
/
owner.t.cpp
File metadata and controls
66 lines (54 loc) · 1.74 KB
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
//
// gsl-lite is based on GSL: Guideline Support Library.
// For more information see https://github.com/martinmoene/gsl-lite
//
// Copyright (c) 2015 Martin Moene
// Copyright (c) 2015 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.h"
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;
#else
EXPECT( !!"owner<> alias template is not available." );
#endif
}
CASE( "Owner(): Allows its use as the (pointer) type it stands for" )
{
#if gsl_FEATURE_HAVE_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