Kári Tristan Helgason | ecbdbf6 | 2020-02-20 07:34:45 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2020 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #import "api/peerconnection/RTCEncodedImage+Private.h" |
| 12 | |
| 13 | #import <XCTest/XCTest.h> |
| 14 | |
| 15 | @interface RTCEncodedImageTests : XCTestCase |
| 16 | @end |
| 17 | |
| 18 | @implementation RTCEncodedImageTests |
| 19 | |
| 20 | - (void)testInitializedWithNativeEncodedImage { |
| 21 | const auto encoded_data = webrtc::EncodedImageBuffer::Create(); |
| 22 | webrtc::EncodedImage encoded_image; |
| 23 | encoded_image.SetEncodedData(encoded_data); |
| 24 | |
| 25 | RTCEncodedImage *encodedImage = |
| 26 | [[RTCEncodedImage alloc] initWithNativeEncodedImage:encoded_image]; |
| 27 | |
| 28 | XCTAssertEqual([encodedImage nativeEncodedImage].GetEncodedData(), encoded_data); |
| 29 | } |
| 30 | |
| 31 | - (void)testInitWithNSData { |
| 32 | NSData *bufferData = [NSData data]; |
| 33 | RTCEncodedImage *encodedImage = [[RTCEncodedImage alloc] init]; |
| 34 | encodedImage.buffer = bufferData; |
| 35 | |
| 36 | webrtc::EncodedImage result_encoded_image = [encodedImage nativeEncodedImage]; |
| 37 | XCTAssertTrue(result_encoded_image.GetEncodedData() != nullptr); |
| 38 | XCTAssertEqual(result_encoded_image.GetEncodedData()->data(), bufferData.bytes); |
| 39 | } |
| 40 | |
| 41 | - (void)testRetainsNativeEncodedImage { |
| 42 | RTCEncodedImage *encodedImage; |
| 43 | { |
| 44 | const auto encoded_data = webrtc::EncodedImageBuffer::Create(); |
| 45 | webrtc::EncodedImage encoded_image; |
| 46 | encoded_image.SetEncodedData(encoded_data); |
| 47 | encodedImage = [[RTCEncodedImage alloc] initWithNativeEncodedImage:encoded_image]; |
| 48 | } |
| 49 | webrtc::EncodedImage result_encoded_image = [encodedImage nativeEncodedImage]; |
| 50 | XCTAssertTrue(result_encoded_image.GetEncodedData() != nullptr); |
| 51 | XCTAssertTrue(result_encoded_image.GetEncodedData()->data() != nullptr); |
| 52 | } |
| 53 | |
| 54 | @end |