Skip to content

Commit

Permalink
Removed tester application. Implementing unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
philiphardy committed Jun 12, 2016
1 parent a4f3c8d commit c027286
Show file tree
Hide file tree
Showing 10 changed files with 220 additions and 451 deletions.
132 changes: 106 additions & 26 deletions ID3Edit.xcodeproj/project.pbxproj
Expand Up @@ -12,15 +12,18 @@
4A1804331C3DF496000E1FF2 /* Errors.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A1804321C3DF496000E1FF2 /* Errors.swift */; };
4A36BFC51C422AF000E34BBD /* TagParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A36BFC41C422AF000E34BBD /* TagParser.swift */; };
4A36BFCA1C4317F100E34BBD /* ID3Tag.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A36BFC91C4317F100E34BBD /* ID3Tag.swift */; };
4A39575D1D0E07B60064BF7C /* Toolbox.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A39575C1D0E07B60064BF7C /* Toolbox.swift */; };
4A3957661D0E0C400064BF7C /* ID3EditTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A3957651D0E0C400064BF7C /* ID3EditTests.swift */; };
4A3957681D0E0C400064BF7C /* ID3Edit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4A1804001C3DED53000E1FF2 /* ID3Edit.framework */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
4A2988BB1C41A838001DF149 /* PBXContainerItemProxy */ = {
4A3957691D0E0C400064BF7C /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 4A2988B71C41A837001DF149 /* ID3EditTester.xcodeproj */;
proxyType = 2;
remoteGlobalIDString = 4A2988A71C41A837001DF149;
remoteInfo = ID3EditTester;
containerPortal = 4A1803F71C3DED52000E1FF2 /* Project object */;
proxyType = 1;
remoteGlobalIDString = 4A1803FF1C3DED52000E1FF2;
remoteInfo = ID3Edit;
};
/* End PBXContainerItemProxy section */

Expand All @@ -30,9 +33,12 @@
4A1804051C3DED53000E1FF2 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
4A18040B1C3DEEC4000E1FF2 /* MP3File.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MP3File.swift; sourceTree = "<group>"; };
4A1804321C3DF496000E1FF2 /* Errors.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Errors.swift; sourceTree = "<group>"; };
4A2988B71C41A837001DF149 /* ID3EditTester.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = ID3EditTester.xcodeproj; path = ID3EditTester/ID3EditTester.xcodeproj; sourceTree = "<group>"; };
4A36BFC41C422AF000E34BBD /* TagParser.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TagParser.swift; sourceTree = "<group>"; };
4A36BFC91C4317F100E34BBD /* ID3Tag.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ID3Tag.swift; sourceTree = "<group>"; };
4A39575C1D0E07B60064BF7C /* Toolbox.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Toolbox.swift; sourceTree = "<group>"; };
4A3957631D0E0C400064BF7C /* ID3EditTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ID3EditTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
4A3957651D0E0C400064BF7C /* ID3EditTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ID3EditTests.swift; sourceTree = "<group>"; };
4A3957671D0E0C400064BF7C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -43,14 +49,22 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
4A3957601D0E0C400064BF7C /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
4A3957681D0E0C400064BF7C /* ID3Edit.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
4A1803F61C3DED52000E1FF2 = {
isa = PBXGroup;
children = (
4A2988B71C41A837001DF149 /* ID3EditTester.xcodeproj */,
4A1804021C3DED53000E1FF2 /* ID3Edit */,
4A3957641D0E0C400064BF7C /* ID3EditTests */,
4A1804011C3DED53000E1FF2 /* Products */,
);
sourceTree = "<group>";
Expand All @@ -59,6 +73,7 @@
isa = PBXGroup;
children = (
4A1804001C3DED53000E1FF2 /* ID3Edit.framework */,
4A3957631D0E0C400064BF7C /* ID3EditTests.xctest */,
);
name = Products;
sourceTree = "<group>";
Expand All @@ -71,17 +86,19 @@
4A1804051C3DED53000E1FF2 /* Info.plist */,
4A18040B1C3DEEC4000E1FF2 /* MP3File.swift */,
4A36BFC91C4317F100E34BBD /* ID3Tag.swift */,
4A39575C1D0E07B60064BF7C /* Toolbox.swift */,
4A1804321C3DF496000E1FF2 /* Errors.swift */,
);
path = ID3Edit;
sourceTree = "<group>";
};
4A2988B81C41A837001DF149 /* Products */ = {
4A3957641D0E0C400064BF7C /* ID3EditTests */ = {
isa = PBXGroup;
children = (
4A2988BC1C41A838001DF149 /* ID3EditTester.app */,
4A3957651D0E0C400064BF7C /* ID3EditTests.swift */,
4A3957671D0E0C400064BF7C /* Info.plist */,
);
name = Products;
path = ID3EditTests;
sourceTree = "<group>";
};
/* End PBXGroup section */
Expand Down Expand Up @@ -116,19 +133,41 @@
productReference = 4A1804001C3DED53000E1FF2 /* ID3Edit.framework */;
productType = "com.apple.product-type.framework";
};
4A3957621D0E0C400064BF7C /* ID3EditTests */ = {
isa = PBXNativeTarget;
buildConfigurationList = 4A39576B1D0E0C400064BF7C /* Build configuration list for PBXNativeTarget "ID3EditTests" */;
buildPhases = (
4A39575F1D0E0C400064BF7C /* Sources */,
4A3957601D0E0C400064BF7C /* Frameworks */,
4A3957611D0E0C400064BF7C /* Resources */,
);
buildRules = (
);
dependencies = (
4A39576A1D0E0C400064BF7C /* PBXTargetDependency */,
);
name = ID3EditTests;
productName = ID3EditTests;
productReference = 4A3957631D0E0C400064BF7C /* ID3EditTests.xctest */;
productType = "com.apple.product-type.bundle.unit-test";
};
/* End PBXNativeTarget section */

/* Begin PBXProject section */
4A1803F71C3DED52000E1FF2 /* Project object */ = {
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0730;
LastUpgradeCheck = 0720;
ORGANIZATIONNAME = "Hardy Creations";
TargetAttributes = {
4A1803FF1C3DED52000E1FF2 = {
CreatedOnToolsVersion = 7.2;
DevelopmentTeam = 45V2XP9N28;
};
4A3957621D0E0C400064BF7C = {
CreatedOnToolsVersion = 7.3.1;
};
};
};
buildConfigurationList = 4A1803FA1C3DED52000E1FF2 /* Build configuration list for PBXProject "ID3Edit" */;
Expand All @@ -141,29 +180,14 @@
mainGroup = 4A1803F61C3DED52000E1FF2;
productRefGroup = 4A1804011C3DED53000E1FF2 /* Products */;
projectDirPath = "";
projectReferences = (
{
ProductGroup = 4A2988B81C41A837001DF149 /* Products */;
ProjectRef = 4A2988B71C41A837001DF149 /* ID3EditTester.xcodeproj */;
},
);
projectRoot = "";
targets = (
4A1803FF1C3DED52000E1FF2 /* ID3Edit */,
4A3957621D0E0C400064BF7C /* ID3EditTests */,
);
};
/* End PBXProject section */

/* Begin PBXReferenceProxy section */
4A2988BC1C41A838001DF149 /* ID3EditTester.app */ = {
isa = PBXReferenceProxy;
fileType = wrapper.application;
path = ID3EditTester.app;
remoteRef = 4A2988BB1C41A838001DF149 /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
/* End PBXReferenceProxy section */

/* Begin PBXResourcesBuildPhase section */
4A1803FE1C3DED52000E1FF2 /* Resources */ = {
isa = PBXResourcesBuildPhase;
Expand All @@ -172,22 +196,46 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
4A3957611D0E0C400064BF7C /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
4A1803FB1C3DED52000E1FF2 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
4A39575D1D0E07B60064BF7C /* Toolbox.swift in Sources */,
4A1804331C3DF496000E1FF2 /* Errors.swift in Sources */,
4A18040C1C3DEEC4000E1FF2 /* MP3File.swift in Sources */,
4A36BFC51C422AF000E34BBD /* TagParser.swift in Sources */,
4A36BFCA1C4317F100E34BBD /* ID3Tag.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
4A39575F1D0E0C400064BF7C /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
4A3957661D0E0C400064BF7C /* ID3EditTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */

/* Begin PBXTargetDependency section */
4A39576A1D0E0C400064BF7C /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = 4A1803FF1C3DED52000E1FF2 /* ID3Edit */;
targetProxy = 4A3957691D0E0C400064BF7C /* PBXContainerItemProxy */;
};
/* End PBXTargetDependency section */

/* Begin XCBuildConfiguration section */
4A1804061C3DED53000E1FF2 /* Debug */ = {
isa = XCBuildConfiguration;
Expand Down Expand Up @@ -314,6 +362,30 @@
};
name = Release;
};
4A39576C1D0E0C400064BF7C /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ANALYZER_NONNULL = YES;
COMBINE_HIDPI_IMAGES = YES;
INFOPLIST_FILE = ID3EditTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.hardycreations.ID3EditTests;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Debug;
};
4A39576D1D0E0C400064BF7C /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ANALYZER_NONNULL = YES;
COMBINE_HIDPI_IMAGES = YES;
INFOPLIST_FILE = ID3EditTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.hardycreations.ID3EditTests;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
};
/* End XCBuildConfiguration section */

/* Begin XCConfigurationList section */
Expand All @@ -335,6 +407,14 @@
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
4A39576B1D0E0C400064BF7C /* Build configuration list for PBXNativeTarget "ID3EditTests" */ = {
isa = XCConfigurationList;
buildConfigurations = (
4A39576C1D0E0C400064BF7C /* Debug */,
4A39576D1D0E0C400064BF7C /* Release */,
);
defaultConfigurationIsVisible = 0;
};
/* End XCConfigurationList section */
};
rootObject = 4A1803F71C3DED52000E1FF2 /* Project object */;
Expand Down
47 changes: 15 additions & 32 deletions ID3Edit/ID3Tag.swift
Expand Up @@ -192,7 +192,8 @@ internal class ID3Tag
}

// Add the size to the byte array
var size = toByteArray(UInt32(cont.count))
var int = UInt32(cont.count)
var size = Toolbox.toByteArray(&int)
size.removeFirst()

// Create the frame
Expand All @@ -212,11 +213,12 @@ internal class ID3Tag

let content = [Byte](getLyrics().utf8)

var size = toByteArray(UInt32(content.count + encoding.count))
size.removeFirst()
var size = UInt32(content.count + encoding.count)
var sizeArr = Toolbox.toByteArray(&size)
sizeArr.removeFirst()

// Form the header
bytes.appendContentsOf(size)
bytes.appendContentsOf(sizeArr)
bytes.appendContentsOf(encoding)
bytes.appendContentsOf(content)

Expand All @@ -229,8 +231,8 @@ internal class ID3Tag
var bytes: [Byte] = FRAMES.HEADER

// Add the size to the byte array
let formattedSize = UInt32(calcSize(contentSize))
bytes.appendContentsOf(toByteArray(formattedSize))
var formattedSize = UInt32(calcSize(contentSize))
bytes.appendContentsOf(Toolbox.toByteArray(&formattedSize))

// Return the completed tag header
return bytes
Expand All @@ -242,10 +244,11 @@ internal class ID3Tag
var bytes: [Byte] = FRAMES.ARTWORK

// Calculate size
var size = toByteArray(UInt32(artwork.art!.length + 6))
size.removeFirst()
var size = UInt32(artwork.art!.length + 6)
var sizeArr = Toolbox.toByteArray(&size)
sizeArr.removeFirst()

bytes.appendContentsOf(size)
bytes.appendContentsOf(sizeArr)

// Append encoding
if artwork.isPNG!
Expand All @@ -265,16 +268,14 @@ internal class ID3Tag
return bytes
}

// MARK: - Helper Methods



// MARK: - Helper Methods
private func calcSize(size: Int) -> Int
{
// Holds the size of the tag
var newSize = 0

for var i = 0; i < 4; i++
for i in 0 ..< 4
{
// Get the bytes from size
let shift = i * 8
Expand All @@ -285,7 +286,7 @@ internal class ID3Tag
var byte = (size & mask) >> shift

var oMask: Byte = 0x80
for var j = 0; j < i; j++
for _ in 0 ..< i
{
// Create the overflow mask
oMask = oMask >> 1
Expand All @@ -310,22 +311,4 @@ internal class ID3Tag
{
return category != ""
}

private func toByteArray<T>(var num: T) -> [Byte]
{
// Get pointer to number
let ptr = withUnsafePointer(&num) {
UnsafePointer<Byte>($0)
}

// The array to store the bytes
var bytes: [Byte] = []

for var i = sizeof(T) - 1; i >= 0; i--
{
bytes.append(ptr[i])
}

return bytes
}
}
6 changes: 3 additions & 3 deletions ID3Edit/TagParser.swift
Expand Up @@ -45,7 +45,7 @@ internal class TagParser

var isPresent = true

for var i = 0; i < 3; i++
for i in 0 ..< 3
{
isPresent = isPresent && (bytes[i] == header[i])
}
Expand Down Expand Up @@ -178,7 +178,7 @@ internal class TagParser
var size = ID3Tag.FRAME_OFFSET
var shift = 2 * BYTE

for var i = 0; i < 3; i++
for i in 0 ..< 3
{
size += Int(frameSizeBytes[i]) << shift
shift -= BYTE
Expand All @@ -196,7 +196,7 @@ internal class TagParser
var size = 0
var shift = 21

for var i = 0; i < 4; i++
for i in 0 ..< 4
{
size += Int(ptr[i]) << shift
shift -= 7
Expand Down

0 comments on commit c027286

Please sign in to comment.