|
| 1 | +// |
| 2 | +// InterstitialTagBuilderTests.swift |
| 3 | +// mambaTests |
| 4 | +// |
| 5 | +// Created by Migneco, Ray on 10/23/24. |
| 6 | +// Copyright © 2024 Comcast Corporation. |
| 7 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +// you may not use this file except in compliance with the License. |
| 9 | +// You may obtain a copy of the License at |
| 10 | +// |
| 11 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +// |
| 13 | +// Unless required by applicable law or agreed to in writing, software |
| 14 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +// See the License for the specific language governing permissions and |
| 17 | +// limitations under the License. All rights reserved. |
| 18 | +// |
| 19 | + |
| 20 | +import XCTest |
| 21 | + |
| 22 | +@testable import mamba |
| 23 | + |
| 24 | + |
| 25 | +final class InterstitialTagBuilderTests: XCTestCase { |
| 26 | + |
| 27 | + func testTagBuilder() { |
| 28 | + |
| 29 | + let startDate = Date() |
| 30 | + let id: String = "12345" |
| 31 | + let assetUri: String = "http://not.a.real.uri" |
| 32 | + let assetListUri: String = "http://not.a.real.list" |
| 33 | + |
| 34 | + let validator = EXT_X_DATERANGETagValidator() |
| 35 | + |
| 36 | + // test URI |
| 37 | + var tagBuilder = InterstitialTagBuilder(id: id, |
| 38 | + startDate: startDate, |
| 39 | + assetUri: assetUri) |
| 40 | + |
| 41 | + var tag = decorateAndTest(tagBuilder) |
| 42 | + |
| 43 | + XCTAssertEqual(tag.value(forValueIdentifier: PantosValue.startDate), String.DateFormatter.iso8601MS.string(from: startDate)) |
| 44 | + XCTAssertEqual(tag.value<String>(forValueIdentifier: PantosValue.id), id) |
| 45 | + XCTAssertEqual(tag.value<String>(forValueIdentifier: PantosValue.assetUri), assetUri) |
| 46 | + XCTAssertNil(tag.value<String>(forValueIdentifier: PantosValue.assetList)) |
| 47 | + |
| 48 | + XCTAssertNil(validator.validate(tag: tag)) |
| 49 | + |
| 50 | + // test asset list |
| 51 | + tagBuilder = InterstitialTagBuilder(id: id, |
| 52 | + startDate: startDate, |
| 53 | + assetList: assetListUri) |
| 54 | + |
| 55 | + tag = decorateAndTest(tagBuilder) |
| 56 | + |
| 57 | + XCTAssertEqual(tag.value<String>(forValueIdentifier: PantosValue.assetList), assetListUri) |
| 58 | + XCTAssertNil(tag.value<String>(forValueIdentifier: PantosValue.assetUri)) |
| 59 | + |
| 60 | + XCTAssertNil(validator.validate(tag: tag)) |
| 61 | + } |
| 62 | + |
| 63 | + func decorateAndTest(_ tagBuilder: InterstitialTagBuilder) -> PlaylistTag { |
| 64 | + |
| 65 | + let duration: Double = 10.0 |
| 66 | + let plannedDuration: Double = 10.0 |
| 67 | + let alignment = HLSInterstitialAlignment(values: [.in, .out]) |
| 68 | + let restrictions = HLSInterstitialSeekRestrictions(restrictions: [.skip, .jump]) |
| 69 | + let playoutLimit: Double = 30.0 |
| 70 | + let resumeOffset: Double = 5.0 |
| 71 | + let timelineStyle = HLSInterstitialTimelineStyle.highlight |
| 72 | + let timelineOccupation = HLSInterstitialTimelineOccupation.point |
| 73 | + let contentVariation = false |
| 74 | + let clientAttributes: [String: LosslessStringConvertible] = ["X-COM-BEACON-URI": "http://not.a.real.beacon", |
| 75 | + "X-COM-AD-PROVIDER-ID": 100] |
| 76 | + |
| 77 | + let tag = tagBuilder |
| 78 | + .withDuration(duration) |
| 79 | + .withPlannedDuration(plannedDuration) |
| 80 | + .withAlignment(alignment) |
| 81 | + .withRestrictions(restrictions) |
| 82 | + .withPlayoutLimit(playoutLimit) |
| 83 | + .withResumeOffset(resumeOffset) |
| 84 | + .withTimelineStyle(timelineStyle) |
| 85 | + .withTimelineOccupation(timelineOccupation) |
| 86 | + .withContentVariation(contentVariation) |
| 87 | + .withClientAttributes(clientAttributes) |
| 88 | + .buildTag() |
| 89 | + |
| 90 | + XCTAssertEqual(tag.value<Double>(forValueIdentifier: PantosValue.duration), duration) |
| 91 | + XCTAssertEqual(tag.value<Double>(forValueIdentifier: PantosValue.plannedDuration), plannedDuration) |
| 92 | + XCTAssertEqual(tag.value<HLSInterstitialAlignment>(forValueIdentifier: PantosValue.snap), alignment) |
| 93 | + XCTAssertEqual(tag.value<HLSInterstitialSeekRestrictions>(forValueIdentifier: PantosValue.restrict), restrictions) |
| 94 | + XCTAssertEqual(tag.value<Double>(forValueIdentifier: PantosValue.playoutLimit), playoutLimit) |
| 95 | + XCTAssertEqual(tag.value<Double>(forValueIdentifier: PantosValue.resumeOffset), resumeOffset) |
| 96 | + XCTAssertEqual(tag.value<HLSInterstitialTimelineStyle>(forValueIdentifier: PantosValue.timelineStyle), timelineStyle) |
| 97 | + XCTAssertEqual(tag.value<HLSInterstitialTimelineOccupation>(forValueIdentifier: PantosValue.timelineOccupies), timelineOccupation) |
| 98 | + XCTAssertEqual(tag.value<Bool>(forValueIdentifier: PantosValue.contentMayVary), contentVariation) |
| 99 | + |
| 100 | + // check client attributes |
| 101 | + for (k, v) in clientAttributes { |
| 102 | + guard let val = tag.value(forKey: k) else { |
| 103 | + XCTFail("Expected to find value for key \(k)") |
| 104 | + continue |
| 105 | + } |
| 106 | + |
| 107 | + XCTAssertEqual(val, v.description) |
| 108 | + } |
| 109 | + |
| 110 | + return tag |
| 111 | + } |
| 112 | + |
| 113 | +} |
0 commit comments