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 RTC_OBJC_TYPE(RTCEncodedImage) *encodedImage = 26 [[RTC_OBJC_TYPE(RTCEncodedImage) alloc] initWithNativeEncodedImage:encoded_image]; 27 28 XCTAssertEqual([encodedImage nativeEncodedImage].GetEncodedData(), encoded_data); 29} 30 31- (void)testInitWithNSData { 32 NSData *bufferData = [NSData data]; 33 RTC_OBJC_TYPE(RTCEncodedImage) *encodedImage = [[RTC_OBJC_TYPE(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 RTC_OBJC_TYPE(RTCEncodedImage) * encodedImage; 43 { 44 const auto encoded_data = webrtc::EncodedImageBuffer::Create(); 45 webrtc::EncodedImage encoded_image; 46 encoded_image.SetEncodedData(encoded_data); 47 encodedImage = 48 [[RTC_OBJC_TYPE(RTCEncodedImage) alloc] initWithNativeEncodedImage:encoded_image]; 49 } 50 webrtc::EncodedImage result_encoded_image = [encodedImage nativeEncodedImage]; 51 XCTAssertTrue(result_encoded_image.GetEncodedData() != nullptr); 52 XCTAssertTrue(result_encoded_image.GetEncodedData()->data() != nullptr); 53} 54 55@end 56