From 373888d69bf31a27d9c55a1b46577c58ffa7dcfa Mon Sep 17 00:00:00 2001 From: Ray Migneco Date: Fri, 1 Nov 2024 11:12:25 -0400 Subject: [PATCH] Added Interstitital Tag Builder tests --- mamba.xcodeproj/project.pbxproj | 8 ++ .../InterstitialTagBuilderTests.swift | 113 ++++++++++++++++++ 2 files changed, 121 insertions(+) create mode 100644 mambaTests/Util Tests/InterstitialTagBuilderTests.swift diff --git a/mamba.xcodeproj/project.pbxproj b/mamba.xcodeproj/project.pbxproj index ba2d471..044576c 100644 --- a/mamba.xcodeproj/project.pbxproj +++ b/mamba.xcodeproj/project.pbxproj @@ -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 */; }; @@ -682,6 +685,7 @@ E65FB2412CD51E4200BF6F56 /* InterstitialValueTypes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InterstitialValueTypes.swift; sourceTree = ""; }; E65FB2452CD5241D00BF6F56 /* InterstitialValueTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InterstitialValueTests.swift; sourceTree = ""; }; E65FB2492CD524BF00BF6F56 /* InterstitialTagBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InterstitialTagBuilder.swift; sourceTree = ""; }; + E65FB24D2CD526DD00BF6F56 /* InterstitialTagBuilderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InterstitialTagBuilderTests.swift; sourceTree = ""; }; EC03B62D1E5CC54900BF1F97 /* PrototypeRapidParseArray.include */ = {isa = PBXFileReference; lastKnownFileType = text; path = PrototypeRapidParseArray.include; sourceTree = ""; }; EC03B62E1E5CC54900BF1F97 /* RapidParser_LookingForEForEXTINFState_ParseArray.include */ = {isa = PBXFileReference; lastKnownFileType = text; path = RapidParser_LookingForEForEXTINFState_ParseArray.include; sourceTree = ""; }; EC03B62F1E5CC54900BF1F97 /* RapidParser_LookingForEForEXTState_ParseArray.include */ = {isa = PBXFileReference; lastKnownFileType = text; path = RapidParser_LookingForEForEXTState_ParseArray.include; sourceTree = ""; }; @@ -1337,6 +1341,7 @@ EC073F5F1FE08F7500689228 /* String+Helio.swift */, EC7492A61DD29F7000AF4E20 /* URLSchemeChangeTests.swift */, EC9BCAA21D749D8B0032BEBE /* Value Types */, + E65FB24D2CD526DD00BF6F56 /* InterstitialTagBuilderTests.swift */, ); path = "Util Tests"; sourceTree = ""; @@ -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 */, @@ -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 */, @@ -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 */, diff --git a/mambaTests/Util Tests/InterstitialTagBuilderTests.swift b/mambaTests/Util Tests/InterstitialTagBuilderTests.swift new file mode 100644 index 0000000..d8d9671 --- /dev/null +++ b/mambaTests/Util Tests/InterstitialTagBuilderTests.swift @@ -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(forValueIdentifier: PantosValue.id), id) + XCTAssertEqual(tag.value(forValueIdentifier: PantosValue.assetUri), assetUri) + XCTAssertNil(tag.value(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(forValueIdentifier: PantosValue.assetList), assetListUri) + XCTAssertNil(tag.value(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(forValueIdentifier: PantosValue.duration), duration) + XCTAssertEqual(tag.value(forValueIdentifier: PantosValue.plannedDuration), plannedDuration) + XCTAssertEqual(tag.value(forValueIdentifier: PantosValue.snap), alignment) + XCTAssertEqual(tag.value(forValueIdentifier: PantosValue.restrict), restrictions) + XCTAssertEqual(tag.value(forValueIdentifier: PantosValue.playoutLimit), playoutLimit) + XCTAssertEqual(tag.value(forValueIdentifier: PantosValue.resumeOffset), resumeOffset) + XCTAssertEqual(tag.value(forValueIdentifier: PantosValue.timelineStyle), timelineStyle) + XCTAssertEqual(tag.value(forValueIdentifier: PantosValue.timelineOccupies), timelineOccupation) + XCTAssertEqual(tag.value(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 + } + +}