Skip to content

Commit

Permalink
Added Interstitital Tag Builder tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rmigneco committed Nov 1, 2024
1 parent cc7dfd3 commit 373888d
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 0 deletions.
8 changes: 8 additions & 0 deletions mamba.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@
E65FB24A2CD524BF00BF6F56 /* InterstitialTagBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = E65FB2492CD524BF00BF6F56 /* InterstitialTagBuilder.swift */; };
E65FB24B2CD524BF00BF6F56 /* InterstitialTagBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = E65FB2492CD524BF00BF6F56 /* InterstitialTagBuilder.swift */; };
E65FB24C2CD524BF00BF6F56 /* InterstitialTagBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = E65FB2492CD524BF00BF6F56 /* InterstitialTagBuilder.swift */; };
E65FB24E2CD526DD00BF6F56 /* InterstitialTagBuilderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E65FB24D2CD526DD00BF6F56 /* InterstitialTagBuilderTests.swift */; };
E65FB24F2CD526DD00BF6F56 /* InterstitialTagBuilderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E65FB24D2CD526DD00BF6F56 /* InterstitialTagBuilderTests.swift */; };
E65FB2502CD526DD00BF6F56 /* InterstitialTagBuilderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E65FB24D2CD526DD00BF6F56 /* InterstitialTagBuilderTests.swift */; };
EC03B63D1E5CC55800BF1F97 /* RapidParserMasterParseArray.c in Sources */ = {isa = PBXBuildFile; fileRef = EC03B63B1E5CC55800BF1F97 /* RapidParserMasterParseArray.c */; };
EC03B63E1E5CC55800BF1F97 /* RapidParserMasterParseArray.c in Sources */ = {isa = PBXBuildFile; fileRef = EC03B63B1E5CC55800BF1F97 /* RapidParserMasterParseArray.c */; };
EC03B63F1E5CC55800BF1F97 /* RapidParserMasterParseArray.h in Headers */ = {isa = PBXBuildFile; fileRef = EC03B63C1E5CC55800BF1F97 /* RapidParserMasterParseArray.h */; };
Expand Down Expand Up @@ -682,6 +685,7 @@
E65FB2412CD51E4200BF6F56 /* InterstitialValueTypes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InterstitialValueTypes.swift; sourceTree = "<group>"; };
E65FB2452CD5241D00BF6F56 /* InterstitialValueTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InterstitialValueTests.swift; sourceTree = "<group>"; };
E65FB2492CD524BF00BF6F56 /* InterstitialTagBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InterstitialTagBuilder.swift; sourceTree = "<group>"; };
E65FB24D2CD526DD00BF6F56 /* InterstitialTagBuilderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InterstitialTagBuilderTests.swift; sourceTree = "<group>"; };
EC03B62D1E5CC54900BF1F97 /* PrototypeRapidParseArray.include */ = {isa = PBXFileReference; lastKnownFileType = text; path = PrototypeRapidParseArray.include; sourceTree = "<group>"; };
EC03B62E1E5CC54900BF1F97 /* RapidParser_LookingForEForEXTINFState_ParseArray.include */ = {isa = PBXFileReference; lastKnownFileType = text; path = RapidParser_LookingForEForEXTINFState_ParseArray.include; sourceTree = "<group>"; };
EC03B62F1E5CC54900BF1F97 /* RapidParser_LookingForEForEXTState_ParseArray.include */ = {isa = PBXFileReference; lastKnownFileType = text; path = RapidParser_LookingForEForEXTState_ParseArray.include; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1337,6 +1341,7 @@
EC073F5F1FE08F7500689228 /* String+Helio.swift */,
EC7492A61DD29F7000AF4E20 /* URLSchemeChangeTests.swift */,
EC9BCAA21D749D8B0032BEBE /* Value Types */,
E65FB24D2CD526DD00BF6F56 /* InterstitialTagBuilderTests.swift */,
);
path = "Util Tests";
sourceTree = "<group>";
Expand Down Expand Up @@ -1927,6 +1932,7 @@
EC7492761DD29EC800AF4E20 /* EXT_X_KEYTagParserTests.swift in Sources */,
883290561EA172170064588B /* MambaStringRefExtensionTests.swift in Sources */,
ECDE185122387257008566BB /* VariantPlaylistMediaSpanTests.swift in Sources */,
E65FB2502CD526DD00BF6F56 /* InterstitialTagBuilderTests.swift in Sources */,
EC7492A91DD29F7000AF4E20 /* MambaUtilTests.swift in Sources */,
EC7492741DD29EC800AF4E20 /* EXT_X_I_FRAME_STREAM_INFTagParserTests.swift in Sources */,
ECFBD90E1E5CCC2200379FC2 /* MambaStringRefTests.m in Sources */,
Expand Down Expand Up @@ -2107,6 +2113,7 @@
EC7492291DD29E4A00AF4E20 /* FixtureLoader.swift in Sources */,
F7CFF27F1F392009009F4C82 /* CMTimeMakeFromStringTests.swift in Sources */,
ECDE185222387257008566BB /* VariantPlaylistMediaSpanTests.swift in Sources */,
E65FB24F2CD526DD00BF6F56 /* InterstitialTagBuilderTests.swift in Sources */,
EC7492771DD29EC800AF4E20 /* EXT_X_KEYTagParserTests.swift in Sources */,
EC7492AA1DD29F7000AF4E20 /* MambaUtilTests.swift in Sources */,
ECFBD90F1E5CCC2200379FC2 /* MambaStringRefTests.m in Sources */,
Expand Down Expand Up @@ -2287,6 +2294,7 @@
ECE253F0209A50B500D388CE /* EXT_X_I_FRAME_STREAM_INFTagParserTests.swift in Sources */,
ECDE185322387257008566BB /* VariantPlaylistMediaSpanTests.swift in Sources */,
ECE25405209A50B500D388CE /* CodecArrayTests.swift in Sources */,
E65FB24E2CD526DD00BF6F56 /* InterstitialTagBuilderTests.swift in Sources */,
ECE253EA209A50A100D388CE /* MambaStringRefTests.m in Sources */,
ECE253F7209A50B500D388CE /* StringArrayParserTests.swift in Sources */,
ECE25401209A50B500D388CE /* MambaUtilTests.swift in Sources */,
Expand Down
113 changes: 113 additions & 0 deletions mambaTests/Util Tests/InterstitialTagBuilderTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
//
// InterstitialTagBuilderTests.swift
// mambaTests
//
// Created by Migneco, Ray on 10/23/24.
// Copyright © 2024 Comcast Corporation.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License. All rights reserved.
//

import XCTest

@testable import mamba


final class InterstitialTagBuilderTests: XCTestCase {

func testTagBuilder() {

let startDate = Date()
let id: String = "12345"
let assetUri: String = "http://not.a.real.uri"
let assetListUri: String = "http://not.a.real.list"

let validator = EXT_X_DATERANGETagValidator()

// test URI
var tagBuilder = InterstitialTagBuilder(id: id,
startDate: startDate,
assetUri: assetUri)

var tag = decorateAndTest(tagBuilder)

XCTAssertEqual(tag.value(forValueIdentifier: PantosValue.startDate), String.DateFormatter.iso8601MS.string(from: startDate))
XCTAssertEqual(tag.value<String>(forValueIdentifier: PantosValue.id), id)
XCTAssertEqual(tag.value<String>(forValueIdentifier: PantosValue.assetUri), assetUri)
XCTAssertNil(tag.value<String>(forValueIdentifier: PantosValue.assetList))

XCTAssertNil(validator.validate(tag: tag))

// test asset list
tagBuilder = InterstitialTagBuilder(id: id,
startDate: startDate,
assetList: assetListUri)

tag = decorateAndTest(tagBuilder)

XCTAssertEqual(tag.value<String>(forValueIdentifier: PantosValue.assetList), assetListUri)
XCTAssertNil(tag.value<String>(forValueIdentifier: PantosValue.assetUri))

XCTAssertNil(validator.validate(tag: tag))
}

func decorateAndTest(_ tagBuilder: InterstitialTagBuilder) -> PlaylistTag {

let duration: Double = 10.0
let plannedDuration: Double = 10.0
let alignment = HLSInterstitialAlignment(values: [.in, .out])
let restrictions = HLSInterstitialSeekRestrictions(restrictions: [.skip, .jump])
let playoutLimit: Double = 30.0
let resumeOffset: Double = 5.0
let timelineStyle = HLSInterstitialTimelineStyle.highlight
let timelineOccupation = HLSInterstitialTimelineOccupation.point
let contentVariation = false
let clientAttributes: [String: LosslessStringConvertible] = ["X-COM-BEACON-URI": "http://not.a.real.beacon",
"X-COM-AD-PROVIDER-ID": 100]

let tag = tagBuilder
.withDuration(duration)
.withPlannedDuration(plannedDuration)
.withAlignment(alignment)
.withRestrictions(restrictions)
.withPlayoutLimit(playoutLimit)
.withResumeOffset(resumeOffset)
.withTimelineStyle(timelineStyle)
.withTimelineOccupation(timelineOccupation)
.withContentVariation(contentVariation)
.withClientAttributes(clientAttributes)
.buildTag()

XCTAssertEqual(tag.value<Double>(forValueIdentifier: PantosValue.duration), duration)
XCTAssertEqual(tag.value<Double>(forValueIdentifier: PantosValue.plannedDuration), plannedDuration)
XCTAssertEqual(tag.value<HLSInterstitialAlignment>(forValueIdentifier: PantosValue.snap), alignment)
XCTAssertEqual(tag.value<HLSInterstitialSeekRestrictions>(forValueIdentifier: PantosValue.restrict), restrictions)
XCTAssertEqual(tag.value<Double>(forValueIdentifier: PantosValue.playoutLimit), playoutLimit)
XCTAssertEqual(tag.value<Double>(forValueIdentifier: PantosValue.resumeOffset), resumeOffset)
XCTAssertEqual(tag.value<HLSInterstitialTimelineStyle>(forValueIdentifier: PantosValue.timelineStyle), timelineStyle)
XCTAssertEqual(tag.value<HLSInterstitialTimelineOccupation>(forValueIdentifier: PantosValue.timelineOccupies), timelineOccupation)
XCTAssertEqual(tag.value<Bool>(forValueIdentifier: PantosValue.contentMayVary), contentVariation)

// check client attributes
for (k, v) in clientAttributes {
guard let val = tag.value(forKey: k) else {
XCTFail("Expected to find value for key \(k)")
continue
}

XCTAssertEqual(val, v.description)
}

return tag
}

}

0 comments on commit 373888d

Please sign in to comment.