| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2017 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2017 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include <utility> | 11 #include <utility> |
| 12 | 12 |
| 13 #include "webrtc/api/rtcerror.h" | 13 #include "webrtc/api/rtcerror.h" |
| 14 #include "webrtc/test/gtest.h" | 14 #include "webrtc/test/gtest.h" |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 const int kDefaultMoveOnlyIntValue = 0xbadf00d; | 18 const int kDefaultMoveOnlyIntValue = 0xbadf00d; |
| 19 | 19 |
| 20 // Class that has no copy constructor, ensuring that RTCErrorOr can | 20 // Class that has no copy constructor, ensuring that RTCErrorOr can |
| 21 struct MoveOnlyInt { | 21 struct MoveOnlyInt { |
| 22 MoveOnlyInt() {} | 22 MoveOnlyInt() {} |
| 23 explicit MoveOnlyInt(int value) : value(value) {} | 23 explicit MoveOnlyInt(int value) : value(value) {} |
| 24 MoveOnlyInt(const MoveOnlyInt& other) = delete; | 24 MoveOnlyInt(const MoveOnlyInt& other) = delete; |
| 25 MoveOnlyInt(MoveOnlyInt&& other) = default; | 25 MoveOnlyInt& operator=(const MoveOnlyInt& other) = delete; |
| 26 MoveOnlyInt& operator=(MoveOnlyInt&& other) = default; | 26 MoveOnlyInt(MoveOnlyInt&& other) : value(other.value) {} |
| 27 MoveOnlyInt& operator=(MoveOnlyInt&& other) { |
| 28 value = other.value; |
| 29 return *this; |
| 30 } |
| 27 | 31 |
| 28 int value = kDefaultMoveOnlyIntValue; | 32 int value = kDefaultMoveOnlyIntValue; |
| 29 }; | 33 }; |
| 30 | 34 |
| 31 // Same as above. Used to test conversion from RTCErrorOr<A> to RTCErrorOr<B> | 35 // Same as above. Used to test conversion from RTCErrorOr<A> to RTCErrorOr<B> |
| 32 // when A can be converted to B. | 36 // when A can be converted to B. |
| 33 struct MoveOnlyInt2 { | 37 struct MoveOnlyInt2 { |
| 34 MoveOnlyInt2() {} | 38 MoveOnlyInt2() {} |
| 35 explicit MoveOnlyInt2(int value) : value(value) {} | 39 explicit MoveOnlyInt2(int value) : value(value) {} |
| 36 MoveOnlyInt2(const MoveOnlyInt2& other) = delete; | 40 MoveOnlyInt2(const MoveOnlyInt2& other) = delete; |
| 37 MoveOnlyInt2(MoveOnlyInt2&& other) = default; | 41 MoveOnlyInt2& operator=(const MoveOnlyInt2& other) = delete; |
| 38 MoveOnlyInt2& operator=(MoveOnlyInt2&& other) = default; | 42 MoveOnlyInt2(MoveOnlyInt2&& other) : value(other.value) {} |
| 43 MoveOnlyInt2& operator=(MoveOnlyInt2&& other) { |
| 44 value = other.value; |
| 45 return *this; |
| 46 } |
| 39 | 47 |
| 40 explicit MoveOnlyInt2(MoveOnlyInt&& other) : value(other.value) {} | 48 explicit MoveOnlyInt2(MoveOnlyInt&& other) : value(other.value) {} |
| 41 MoveOnlyInt2& operator=(MoveOnlyInt&& other) { | 49 MoveOnlyInt2& operator=(MoveOnlyInt&& other) { |
| 42 value = other.value; | 50 value = other.value; |
| 43 return *this; | 51 return *this; |
| 44 } | 52 } |
| 45 | 53 |
| 46 int value = kDefaultMoveOnlyIntValue; | 54 int value = kDefaultMoveOnlyIntValue; |
| 47 }; | 55 }; |
| 48 | 56 |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 } | 240 } |
| 233 | 241 |
| 234 TEST(RTCErrorOrDeathTest, MoveErrorValue) { | 242 TEST(RTCErrorOrDeathTest, MoveErrorValue) { |
| 235 RTCErrorOr<int> error = RTCError(RTCErrorType::INTERNAL_ERROR); | 243 RTCErrorOr<int> error = RTCError(RTCErrorType::INTERNAL_ERROR); |
| 236 EXPECT_DEATH(error.MoveValue(), ""); | 244 EXPECT_DEATH(error.MoveValue(), ""); |
| 237 } | 245 } |
| 238 | 246 |
| 239 #endif // RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) | 247 #endif // RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) |
| 240 | 248 |
| 241 } // namespace webrtc | 249 } // namespace webrtc |
| OLD | NEW |