|
| 1 | +package com.smartdevicelink.test.streaming.video; |
| 2 | + |
| 3 | +import com.smartdevicelink.AndroidTestCase2; |
| 4 | +import com.smartdevicelink.proxy.rpc.ImageResolution; |
| 5 | +import com.smartdevicelink.proxy.rpc.VideoStreamingCapability; |
| 6 | +import com.smartdevicelink.proxy.rpc.VideoStreamingFormat; |
| 7 | +import com.smartdevicelink.proxy.rpc.enums.VideoStreamingCodec; |
| 8 | +import com.smartdevicelink.proxy.rpc.enums.VideoStreamingProtocol; |
| 9 | +import com.smartdevicelink.streaming.video.VideoStreamingParameters; |
| 10 | +import java.util.Collections; |
| 11 | + |
| 12 | + |
| 13 | +public class VideoStreamingParametersTest extends AndroidTestCase2 { |
| 14 | + |
| 15 | + private VideoStreamingParameters params; |
| 16 | + private VideoStreamingCapability capability; |
| 17 | + private ImageResolution preferredResolution; |
| 18 | + |
| 19 | + public void setUp() { |
| 20 | + params = new VideoStreamingParameters(); |
| 21 | + capability = new VideoStreamingCapability(); |
| 22 | + } |
| 23 | + |
| 24 | + public void testUpdateNullScale() { |
| 25 | + preferredResolution = new ImageResolution(800, 354); |
| 26 | + |
| 27 | + capability.setScale(null); |
| 28 | + capability.setPreferredResolution(preferredResolution); |
| 29 | + |
| 30 | + params.update(capability); |
| 31 | + |
| 32 | + int width = params.getResolution().getResolutionWidth(); |
| 33 | + int height = params.getResolution().getResolutionHeight(); |
| 34 | + |
| 35 | + assertEquals(800, width); |
| 36 | + assertEquals(354, height); |
| 37 | + } |
| 38 | + |
| 39 | + public void testUpdateScale_1_Resolution_800_354() { |
| 40 | + preferredResolution = new ImageResolution(800, 354); |
| 41 | + |
| 42 | + capability.setScale(1.0); |
| 43 | + capability.setPreferredResolution(preferredResolution); |
| 44 | + |
| 45 | + params.update(capability); |
| 46 | + |
| 47 | + int width = params.getResolution().getResolutionWidth(); |
| 48 | + int height = params.getResolution().getResolutionHeight(); |
| 49 | + |
| 50 | + assertEquals(800, width); |
| 51 | + assertEquals(354, height); |
| 52 | + } |
| 53 | + |
| 54 | + public void testUpdateScale_1_25_Resolution_1280_569() { |
| 55 | + preferredResolution = new ImageResolution(1280, 569); |
| 56 | + |
| 57 | + capability.setScale(1.25); |
| 58 | + capability.setPreferredResolution(preferredResolution); |
| 59 | + |
| 60 | + params.update(capability); |
| 61 | + |
| 62 | + int width = params.getResolution().getResolutionWidth(); |
| 63 | + int height = params.getResolution().getResolutionHeight(); |
| 64 | + |
| 65 | + assertEquals(1024, width); |
| 66 | + assertEquals(456, height); |
| 67 | + } |
| 68 | + |
| 69 | + public void testUpdateScale_1_5_Resolution_1280_569() { |
| 70 | + preferredResolution = new ImageResolution(1280, 569); |
| 71 | + |
| 72 | + capability.setScale(1.5); |
| 73 | + capability.setPreferredResolution(preferredResolution); |
| 74 | + |
| 75 | + params.update(capability); |
| 76 | + |
| 77 | + int width = params.getResolution().getResolutionWidth(); |
| 78 | + int height = params.getResolution().getResolutionHeight(); |
| 79 | + |
| 80 | + assertEquals(854, width); |
| 81 | + assertEquals(380, height); |
| 82 | + } |
| 83 | + |
| 84 | + public void testUpdateCapabilityFormat(){ |
| 85 | + VideoStreamingCapability capability = new VideoStreamingCapability(); |
| 86 | + capability.setMaxBitrate(10000); |
| 87 | + capability.setPreferredResolution( new ImageResolution(800,600)); |
| 88 | + capability.setIsHapticSpatialDataSupported(false); |
| 89 | + |
| 90 | + VideoStreamingFormat format = new VideoStreamingFormat(VideoStreamingProtocol.RAW, VideoStreamingCodec.H264); |
| 91 | + capability.setSupportedFormats(Collections.singletonList(format)); |
| 92 | + |
| 93 | + VideoStreamingParameters params = new VideoStreamingParameters(); |
| 94 | + params.setFormat(null); |
| 95 | + |
| 96 | + assertNull(params.getFormat()); |
| 97 | + |
| 98 | + params.update(capability); |
| 99 | + |
| 100 | + assertEquals(params.getFormat(), format); |
| 101 | + |
| 102 | + format = new VideoStreamingFormat(VideoStreamingProtocol.RTP, VideoStreamingCodec.H264); |
| 103 | + capability.setSupportedFormats(Collections.singletonList(format)); |
| 104 | + params.update(capability); |
| 105 | + assertEquals(params.getFormat(), format); |
| 106 | + |
| 107 | + format = new VideoStreamingFormat(VideoStreamingProtocol.RTP, VideoStreamingCodec.H265); |
| 108 | + capability.setSupportedFormats(Collections.singletonList(format)); |
| 109 | + params.update(capability); |
| 110 | + assertFalse(params.getFormat().equals(format)); |
| 111 | + |
| 112 | + format = new VideoStreamingFormat(VideoStreamingProtocol.RAW, VideoStreamingCodec.VP8); |
| 113 | + capability.setSupportedFormats(Collections.singletonList(format)); |
| 114 | + params.update(capability); |
| 115 | + assertFalse(params.getFormat().equals(format)); |
| 116 | + |
| 117 | + } |
| 118 | +} |
0 commit comments