-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboxing_test.cpp
More file actions
168 lines (143 loc) · 4.58 KB
/
Copy pathboxing_test.cpp
File metadata and controls
168 lines (143 loc) · 4.58 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
Copyright (C) 2015-present The DotCpp Authors.
This file is part of .C++, a native C++ implementation of
popular .NET class library APIs developed to facilitate
code reuse between C# and C++.
http://github.com/dotcpp/dotcpp (source)
http://dotcpp.org (documentation)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include <dot/test/implement.hpp>
#include <approvals/ApprovalTests.hpp>
#include <approvals/Catch.hpp>
#include <dot/system/object.hpp>
#include <dot/system/string.hpp>
#include <dot/system/nullable.hpp>
#include <dot/system/collections/generic/list.hpp>
#include <dot/noda_time/local_time.hpp>
#include <dot/noda_time/local_date.hpp>
#include <dot/noda_time/local_date_time.hpp>
#include <dot/system/type.hpp>
namespace dot
{
TEST_CASE("Smoke")
{
{
// Boxing list of double
list<double> obj = make_list<double>();
obj->add(1.);
obj->add(2.);
obj->add(3.);
object boxed = obj;
list<double> unboxed = (list<double>)boxed;
int i = 0;
for (object item : unboxed)
{
REQUIRE((double)item == ++i);
}
}
{
// Boxing bool
bool x = false;
object boxed = x;
REQUIRE((bool)boxed == false);
boxed = true;
REQUIRE((bool)boxed == true);
}
{
// Boxing nullableBool
nullable<bool> x;
object boxed = x;
REQUIRE(((nullable<bool>)boxed).has_value() == false);
nullable<bool> y = true;
boxed = y;
REQUIRE((bool)boxed == true);
}
{
// Boxing double
double x = 1.0;
object boxed = x;
REQUIRE((double)boxed == 1.0);
boxed = 2.0;
REQUIRE((double)boxed == 2.0);
}
{
// Boxing nullableDouble
nullable<double> x;
object boxed = x;
REQUIRE(((nullable<double>)boxed).has_value() == false);
nullable<double> y = 2.0;
boxed = y;
REQUIRE((double)boxed == 2.0);
}
{
// Boxing int
int x = 1;
object boxed = x;
REQUIRE((int)boxed == 1);
boxed = 2;
REQUIRE((int)boxed == 2);
}
{
// Boxing nullableInt
nullable<int> x;
object boxed = x;
REQUIRE(((nullable<int>)boxed).has_value() == false);
nullable<int> y = 2;
boxed = y;
REQUIRE((int)boxed == 2);
}
{
// Boxing int64_t
int64_t x = 1;
object boxed = x;
REQUIRE((int64_t)boxed == 1);
boxed = (int64_t)2;
REQUIRE((int64_t)boxed == 2);
}
{
// Boxing nullableLong
nullable<int64_t> x;
object boxed = x;
REQUIRE(((nullable<int64_t>)boxed).has_value() == false);
nullable<int64_t> y = (int64_t)2;
boxed = y;
REQUIRE((int64_t)boxed == 2);
}
{
// Boxing local_time
local_time time(12, 0);
local_time time2(12, 0);
object boxed = time;
CHECK_NOTHROW((local_time) boxed);
REQUIRE((local_time) boxed == time);
REQUIRE((local_time) boxed == time2);
}
{
// Boxing local_date
local_date date(2005, 1, 1);
local_date date2(2005, 1, 1);
object boxed = date;
CHECK_NOTHROW((local_date) boxed);
REQUIRE((local_date) boxed == date);
REQUIRE((local_date) boxed == date2);
}
{
// Boxing local_date_time
local_date_time date(2005, 1, 1, 12, 0);
local_date_time date2(2005, 1, 1, 12, 0);
object boxed = date;
CHECK_NOTHROW((local_date_time) boxed);
REQUIRE((local_date_time) boxed == date);
REQUIRE((local_date_time) boxed == date2);
}
}
}