Brian Silverman | a6f7ce0 | 2018-07-07 15:04:00 -0700 | [diff] [blame^] | 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 <catch/catch.hpp> // for AssertionHandler, StringRef, CHECK, TEST_... |
| 18 | |
| 19 | #include <gsl/pointers> // for owner |
| 20 | |
| 21 | using namespace gsl; |
| 22 | |
| 23 | void f(int* i) { *i += 1; } |
| 24 | |
| 25 | TEST_CASE("basic_test") |
| 26 | { |
| 27 | owner<int*> p = new int(120); |
| 28 | CHECK(*p == 120); |
| 29 | f(p); |
| 30 | CHECK(*p == 121); |
| 31 | delete p; |
| 32 | } |
| 33 | |
| 34 | TEST_CASE("check_pointer_constraint") |
| 35 | { |
| 36 | #ifdef CONFIRM_COMPILATION_ERRORS |
| 37 | { |
| 38 | owner<int> integerTest = 10; |
| 39 | owner<std::shared_ptr<int>> sharedPtrTest(new int(10)); |
| 40 | } |
| 41 | #endif |
| 42 | } |