aboutsummaryrefslogtreecommitdiff
path: root/Examples/test-suite/tcl/cpp11_rvalue_reference_move_runme.tcl
blob: 7bd51f2a27b8dddd417f2767b2bb0b4d36351291 (plain)
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

if [ catch { load ./cpp11_rvalue_reference_move[info sharedlibextension] Cpp11_rvalue_reference_move} err_msg ] {
	puts stderr "Could not load shared object:\n$err_msg"
}


# Function containing rvalue reference parameter
Counter_reset_counts
MovableCopyable mo 222
Counter_check_counts 1  0  0  0  0  0
MovableCopyable_movein mo
Counter_check_counts 1  0  0  1  0  2
if {![MovableCopyable_is_nullptr mo]} {
  error "is_nullptr failed to throw"
}
mo -delete
Counter_check_counts 1  0  0  1  0  2

# Move constructor test
Counter_reset_counts
MovableCopyable mo 222
Counter_check_counts 1  0  0  0  0  0
MovableCopyable mo_moved mo
Counter_check_counts 1  0  0  1  0  1
if {![MovableCopyable_is_nullptr mo]} {
  error "is_nullptr failed to throw"
}
mo -delete
Counter_check_counts 1  0  0  1  0  1
mo_moved -delete
Counter_check_counts 1  0  0  1  0  2

# Move assignment operator test
Counter_reset_counts
MovableCopyable mo111 111
MovableCopyable mo222 222
Counter_check_counts 2  0  0  0  0  0
mo111 MoveAssign mo222
Counter_check_counts 2  0  0  0  1  1
if {![MovableCopyable_is_nullptr mo222]} {
  error "is_nullptr failed to throw"
}
mo222 -delete
Counter_check_counts 2  0  0  0  1  1
mo111 -delete
Counter_check_counts 2  0  0  0  1  2

# null check
Counter_reset_counts
set exception_thrown 0
if [ catch {
  MovableCopyable_movein "NULL"
} e ] {
  if {[string first "invalid null reference" $e] == -1} {
    error "incorrect exception message: $e"
  }
  set exception_thrown 1
}
if {!$exception_thrown} {
  error "Should have thrown null error"
}
Counter_check_counts 0  0  0  0  0  0

# output
Counter_reset_counts
set mc [MovableCopyable_moveout 1234]
Counter_check_counts  2  0  0  0  1  1
MovableCopyable_check_numbers_match $mc 1234

set exception_thrown 0
if [ catch {
  MovableCopyable_movein $mc
} e ] {
  if {[string first "cannot release ownership as memory is not owned" $e] == -1} {
    error "incorrect exception message: $e"
  }
  set exception_thrown 1
}
if {!$exception_thrown} {
  error "Should have thrown 'Cannot release ownership as memory is not owned' error"
}
Counter_check_counts  2  0  0  0  1  1