1/*
2 *  Copyright 2018 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 <CoreVideo/CoreVideo.h>
12#import <Foundation/Foundation.h>
13#import <GLKit/GLKit.h>
14#import <XCTest/XCTest.h>
15
16#import "base/RTCVideoFrame.h"
17#import "base/RTCVideoFrameBuffer.h"
18#import "components/renderer/opengl/RTCNV12TextureCache.h"
19#import "components/video_frame_buffer/RTCCVPixelBuffer.h"
20
21@interface RTCNV12TextureCacheTests : XCTestCase
22@end
23
24@implementation RTCNV12TextureCacheTests {
25  EAGLContext *_glContext;
26  RTCNV12TextureCache *_nv12TextureCache;
27}
28
29- (void)setUp {
30  [super setUp];
31  _glContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3];
32  if (!_glContext) {
33    _glContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
34  }
35  _nv12TextureCache = [[RTCNV12TextureCache alloc] initWithContext:_glContext];
36}
37
38- (void)tearDown {
39  _nv12TextureCache = nil;
40  _glContext = nil;
41  [super tearDown];
42}
43
44- (void)testNV12TextureCacheDoesNotCrashOnEmptyFrame {
45  CVPixelBufferRef nullPixelBuffer = NULL;
46  RTC_OBJC_TYPE(RTCCVPixelBuffer) *badFrameBuffer =
47      [[RTC_OBJC_TYPE(RTCCVPixelBuffer) alloc] initWithPixelBuffer:nullPixelBuffer];
48  RTC_OBJC_TYPE(RTCVideoFrame) *badFrame =
49      [[RTC_OBJC_TYPE(RTCVideoFrame) alloc] initWithBuffer:badFrameBuffer
50                                                  rotation:RTCVideoRotation_0
51                                               timeStampNs:0];
52  [_nv12TextureCache uploadFrameToTextures:badFrame];
53}
54
55@end
56