• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2015 Microsoft Corporation. All rights reserved.
4 //
5 // This code is licensed under the MIT License (MIT).
6 //
7 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
8 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
9 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
10 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
11 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
12 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
13 // THE SOFTWARE.
14 //
15 ///////////////////////////////////////////////////////////////////////////////
16 
17 #include <UnitTest++/UnitTest++.h>
18 #include <gsl/multi_span>
19 #include <vector>
20 
21 using namespace std;
22 using namespace gsl;;
23 
24 namespace
25 {
use(std::ptrdiff_t &)26     void use(std::ptrdiff_t&) {}
27 }
28 
SUITE(bounds_test)29 SUITE(bounds_test)
30 {
31 	TEST(basic_bounds)
32 	{
33 		for (auto point : static_bounds<dynamic_range, 3, 4 > { 2 })
34 		{
35 			for (decltype(point)::size_type j = 0;
36 			     j < static_cast<decltype(point)::size_type>(decltype(point)::rank);
37 			     j++)
38 			{
39 				use(j);
40 				use(point[j]);
41 			}
42 		}
43 	}
44 
45 	TEST(bounds_basic)
46 	{
47 		static_bounds<3, 4, 5> b;
48 		auto a = b.slice();
49 		(void)a;
50 		static_bounds<4, dynamic_range, 2> x{ 4 };
51 		x.slice().slice();
52 	}
53 
54 	TEST (arrayview_iterator)
55 	{
56 		static_bounds<4, dynamic_range, 2> bounds{ 3 };
57 
58 		auto itr = bounds.begin();
59 		(void)itr;
60 #ifdef CONFIRM_COMPILATION_ERRORS
61 		multi_span<int, 4, dynamic_range, 2> av(nullptr, bounds);
62 
63 		auto itr2 = av.cbegin();
64 
65 		for (auto& v : av) {
66 			v = 4;
67 		}
68 		fill(av.begin(), av.end(), 0);
69 #endif
70 	}
71 
72 	TEST (bounds_convertible)
73 	{
74 		static_bounds<7, 4, 2> b1;
75 		static_bounds<7, dynamic_range, 2> b2 = b1;
76 		(void)b2;
77 #ifdef CONFIRM_COMPILATION_ERRORS
78 		static_bounds<7, dynamic_range, 1> b4 = b2;
79 #endif
80 
81 		static_bounds<dynamic_range, dynamic_range, dynamic_range> b3 = b1;
82 		static_bounds<7, 4, 2> b4 = b3;
83 		(void)b4;
84 
85 		static_bounds<dynamic_range> b11;
86 
87 		static_bounds<dynamic_range> b5;
88 		static_bounds<34> b6;
89 
90 		b5 = static_bounds<20>();
91 		CHECK_THROW(b6 = b5, fail_fast);
92 		b5 = static_bounds<34>();
93 		b6 = b5;
94 
95 		CHECK(b5 == b6);
96 		CHECK(b5.size() == b6.size());
97 	}
98 }
99 
main(int,const char * [])100 int main(int, const char *[])
101 {
102 	return UnitTest::RunAllTests();
103 }
104