From 983c65d39990a5058b3482ad10028bd7af0167ef Mon Sep 17 00:00:00 2001 From: David Date: Mon, 11 Apr 2016 23:44:02 -0400 Subject: [PATCH] Rewrote the Controller class in Swift (#216) * Enabled Defines Modules for swift code * Created bridge header, created swift Controller - Created Controller.swift - Created bridge header for use of objc in swift * Finished porting Controller files to swift * Added comments, created MoonlightUnitTest - Added comments for Controller.swift - Created MoonlightUnitTest for testing new class * Started writing tests for ControllerUnitTests - General formatting - Wrote helper functions - Wrote tests for first four properties * Finished writing Controller tests * Removed commented out lines --- Limelight/Input/Controller.h | 23 --- Limelight/Input/Controller.m | 15 -- Limelight/Input/Controller.swift | 26 +++ Limelight/Input/ControllerSupport.h | 5 +- Limelight/Input/ControllerSupport.m | 5 +- Limelight/Input/Moonlight-Bridging-Header.h | 4 + Limelight/Input/OnScreenControls.m | 5 +- Moonlight.xcodeproj/project.pbxproj | 161 ++++++++++++++- MoonlightUnitTests/Info.plist | 24 +++ .../Input/ControllerUnitTests.swift | 192 ++++++++++++++++++ .../MoonlightUnitTests-Bridging-Header.h | 4 + .../project.pbxproj | 2 + 12 files changed, 417 insertions(+), 49 deletions(-) delete mode 100644 Limelight/Input/Controller.h delete mode 100644 Limelight/Input/Controller.m create mode 100644 Limelight/Input/Controller.swift create mode 100644 Limelight/Input/Moonlight-Bridging-Header.h create mode 100644 MoonlightUnitTests/Info.plist create mode 100644 MoonlightUnitTests/Input/ControllerUnitTests.swift create mode 100644 MoonlightUnitTests/MoonlightUnitTests-Bridging-Header.h diff --git a/Limelight/Input/Controller.h b/Limelight/Input/Controller.h deleted file mode 100644 index 3cd38ec..0000000 --- a/Limelight/Input/Controller.h +++ /dev/null @@ -1,23 +0,0 @@ -// -// Controller.h -// Moonlight -// -// Created by Diego Waxemberg on 2/1/15. -// Copyright (c) 2015 Moonlight Stream. All rights reserved. -// - -#import - -@interface Controller : NSObject - -@property (nonatomic) int playerIndex; -@property (nonatomic) int lastButtonFlags; -@property (nonatomic) int emulatingButtonFlags; -@property (nonatomic) char lastLeftTrigger; -@property (nonatomic) char lastRightTrigger; -@property (nonatomic) short lastLeftStickX; -@property (nonatomic) short lastLeftStickY; -@property (nonatomic) short lastRightStickX; -@property (nonatomic) short lastRightStickY; - -@end diff --git a/Limelight/Input/Controller.m b/Limelight/Input/Controller.m deleted file mode 100644 index f566fed..0000000 --- a/Limelight/Input/Controller.m +++ /dev/null @@ -1,15 +0,0 @@ -// -// Controller.m -// Moonlight -// -// Created by Diego Waxemberg on 2/1/15. -// Copyright (c) 2015 Moonlight Stream. All rights reserved. -// - -#import "Controller.h" - -@implementation Controller -@synthesize playerIndex; -@synthesize lastButtonFlags, emulatingButtonFlags, lastLeftTrigger, lastRightTrigger; -@synthesize lastLeftStickX, lastLeftStickY, lastRightStickX, lastRightStickY; -@end diff --git a/Limelight/Input/Controller.swift b/Limelight/Input/Controller.swift new file mode 100644 index 0000000..9e3d86c --- /dev/null +++ b/Limelight/Input/Controller.swift @@ -0,0 +1,26 @@ +// +// Controller.swift +// Moonlight +// +// Created by David Aghassi on 4/11/16. +// Copyright © 2016 Moonlight Stream. All rights reserved. +// + +import Foundation + +@objc +/** + Defines a controller layout + */ +class Controller: NSObject { + // Swift requires initial properties + var playerIndex: CInt = 0 // Controller number (e.g. 1, 2 ,3 etc) + var lastButtonFlags: CInt = 0 + var emulatingButtonFlags: CInt = 0 + var lastLeftTrigger: CChar = 0 // Last left trigger pressed + var lastRightTrigger: CChar = 0 // Last right trigger pressed + var lastLeftStickX: CShort = 0 // Last X direction the left joystick went + var lastLeftStickY: CShort = 0 // Last Y direction the left joystick went + var lastRightStickX: CShort = 0 // Last X direction the right joystick went + var lastRightStickY: CShort = 0 // Last Y direction the right joystick went +} diff --git a/Limelight/Input/ControllerSupport.h b/Limelight/Input/ControllerSupport.h index 25cf939..1e94106 100644 --- a/Limelight/Input/ControllerSupport.h +++ b/Limelight/Input/ControllerSupport.h @@ -7,7 +7,10 @@ // #import -#import "Controller.h" + +// Swift +#import "Moonlight-Swift.h" +@class Controller; @class OnScreenControls; diff --git a/Limelight/Input/ControllerSupport.m b/Limelight/Input/ControllerSupport.m index a45c11e..7571052 100644 --- a/Limelight/Input/ControllerSupport.m +++ b/Limelight/Input/ControllerSupport.m @@ -8,9 +8,12 @@ #import "ControllerSupport.h" #import "OnScreenControls.h" -#import "Controller.h" #include "Limelight.h" +// Swift +#import "Moonlight-Swift.h" +@class Controller; + @import GameController; @implementation ControllerSupport { diff --git a/Limelight/Input/Moonlight-Bridging-Header.h b/Limelight/Input/Moonlight-Bridging-Header.h new file mode 100644 index 0000000..1b2cb5d --- /dev/null +++ b/Limelight/Input/Moonlight-Bridging-Header.h @@ -0,0 +1,4 @@ +// +// Use this file to import your target's public headers that you would like to expose to Swift. +// + diff --git a/Limelight/Input/OnScreenControls.m b/Limelight/Input/OnScreenControls.m index eb61e6b..bd38f1b 100644 --- a/Limelight/Input/OnScreenControls.m +++ b/Limelight/Input/OnScreenControls.m @@ -8,9 +8,12 @@ #import "OnScreenControls.h" #import "ControllerSupport.h" -#import "Controller.h" +//#import "Controller.h" #include "Limelight.h" +#import "Moonlight-Swift.h" +@class Controller; + #define UPDATE_BUTTON(x, y) (buttonFlags = \ (y) ? (buttonFlags | (x)) : (buttonFlags & ~(x))) diff --git a/Moonlight.xcodeproj/project.pbxproj b/Moonlight.xcodeproj/project.pbxproj index 8b70e7f..bd6c680 100644 --- a/Moonlight.xcodeproj/project.pbxproj +++ b/Moonlight.xcodeproj/project.pbxproj @@ -18,6 +18,8 @@ 9E5D60131A5A5A3900689918 /* Roboto-Medium.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 9E5D60001A5A5A3900689918 /* Roboto-Medium.ttf */; }; 9E5D60151A5A5A3900689918 /* Roboto-Regular.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 9E5D60021A5A5A3900689918 /* Roboto-Regular.ttf */; }; 9E5D60161A5A5A3900689918 /* Roboto-Thin.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 9E5D60031A5A5A3900689918 /* Roboto-Thin.ttf */; }; + D46A73AD1CBC7D090039F1EE /* ControllerUnitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D46A73AC1CBC7D090039F1EE /* ControllerUnitTests.swift */; }; + D4746EEC1CBC740C006FB401 /* Controller.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4746EEB1CBC740C006FB401 /* Controller.swift */; }; FB1D59971BBCCB6400F482CA /* ComputerScrollView.m in Sources */ = {isa = PBXBuildFile; fileRef = FB1D59961BBCCB6400F482CA /* ComputerScrollView.m */; }; FB1D599A1BBCCD7E00F482CA /* AppCollectionView.m in Sources */ = {isa = PBXBuildFile; fileRef = FB1D59991BBCCD7E00F482CA /* AppCollectionView.m */; }; FB290CF219B2C406004C83CF /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FB290CF119B2C406004C83CF /* Foundation.framework */; }; @@ -66,7 +68,6 @@ FB9AFD3A1A7E05CE00872C98 /* ServerInfoResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = FB9AFD391A7E05CE00872C98 /* ServerInfoResponse.m */; }; FB9AFD3D1A7E111600872C98 /* AppAssetResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = FB9AFD3C1A7E111600872C98 /* AppAssetResponse.m */; }; FB9AFD401A7E127D00872C98 /* AppListResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = FB9AFD3F1A7E127D00872C98 /* AppListResponse.m */; }; - FB9AFD431A7F0C6900872C98 /* Controller.m in Sources */ = {isa = PBXBuildFile; fileRef = FB9AFD421A7F0C6900872C98 /* Controller.m */; }; FBD1C8E21A8AD71400C6703C /* Logger.m in Sources */ = {isa = PBXBuildFile; fileRef = FBD1C8E11A8AD71400C6703C /* Logger.m */; }; FBD3494319FC9C04002D2A60 /* AppAssetManager.m in Sources */ = {isa = PBXBuildFile; fileRef = FBD3494219FC9C04002D2A60 /* AppAssetManager.m */; }; FBD3495019FF2174002D2A60 /* SettingsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = FBD3494F19FF2174002D2A60 /* SettingsViewController.m */; }; @@ -94,6 +95,13 @@ remoteGlobalIDString = FB290E2D19B37A4E004C83CF; remoteInfo = "moonlight-common"; }; + D46A73A51CBC7CB60039F1EE /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = FB290CE619B2C406004C83CF /* Project object */; + proxyType = 1; + remoteGlobalIDString = FB290CED19B2C406004C83CF; + remoteInfo = Moonlight; + }; /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ @@ -111,6 +119,12 @@ 9E5D60001A5A5A3900689918 /* Roboto-Medium.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Roboto-Medium.ttf"; sourceTree = ""; }; 9E5D60021A5A5A3900689918 /* Roboto-Regular.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Roboto-Regular.ttf"; sourceTree = ""; }; 9E5D60031A5A5A3900689918 /* Roboto-Thin.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Roboto-Thin.ttf"; sourceTree = ""; }; + D46A73A01CBC7CB60039F1EE /* MoonlightUnitTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MoonlightUnitTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + D46A73A41CBC7CB60039F1EE /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + D46A73AB1CBC7D080039F1EE /* MoonlightUnitTests-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "MoonlightUnitTests-Bridging-Header.h"; sourceTree = ""; }; + D46A73AC1CBC7D090039F1EE /* ControllerUnitTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ControllerUnitTests.swift; path = Input/ControllerUnitTests.swift; sourceTree = ""; }; + D4746EEA1CBC740C006FB401 /* Moonlight-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "Moonlight-Bridging-Header.h"; path = "Input/Moonlight-Bridging-Header.h"; sourceTree = ""; }; + D4746EEB1CBC740C006FB401 /* Controller.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Controller.swift; sourceTree = ""; }; FB1D59951BBCCB6400F482CA /* ComputerScrollView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ComputerScrollView.h; sourceTree = ""; }; FB1D59961BBCCB6400F482CA /* ComputerScrollView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ComputerScrollView.m; sourceTree = ""; }; FB1D59981BBCCD7E00F482CA /* AppCollectionView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppCollectionView.h; sourceTree = ""; }; @@ -274,8 +288,6 @@ FB9AFD3C1A7E111600872C98 /* AppAssetResponse.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppAssetResponse.m; sourceTree = ""; }; FB9AFD3E1A7E127D00872C98 /* AppListResponse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppListResponse.h; sourceTree = ""; }; FB9AFD3F1A7E127D00872C98 /* AppListResponse.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppListResponse.m; sourceTree = ""; }; - FB9AFD411A7F0C6900872C98 /* Controller.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Controller.h; sourceTree = ""; }; - FB9AFD421A7F0C6900872C98 /* Controller.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Controller.m; sourceTree = ""; }; FBB460391B50ACE400F3099C /* Moonlight v1.0.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Moonlight v1.0.xcdatamodel"; sourceTree = ""; }; FBD1C8E01A8AD69E00C6703C /* Logger.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Logger.h; sourceTree = ""; }; FBD1C8E11A8AD71400C6703C /* Logger.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Logger.m; sourceTree = ""; }; @@ -303,6 +315,13 @@ /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ + D46A739D1CBC7CB60039F1EE /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; FB290CEB19B2C406004C83CF /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; @@ -356,11 +375,30 @@ path = Roboto; sourceTree = ""; }; + D46A73A11CBC7CB60039F1EE /* MoonlightUnitTests */ = { + isa = PBXGroup; + children = ( + D46A73AB1CBC7D080039F1EE /* MoonlightUnitTests-Bridging-Header.h */, + D46A73AA1CBC7CEF0039F1EE /* Input */, + D46A73A41CBC7CB60039F1EE /* Info.plist */, + ); + path = MoonlightUnitTests; + sourceTree = ""; + }; + D46A73AA1CBC7CEF0039F1EE /* Input */ = { + isa = PBXGroup; + children = ( + D46A73AC1CBC7D090039F1EE /* ControllerUnitTests.swift */, + ); + name = Input; + sourceTree = ""; + }; FB290CE519B2C406004C83CF = { isa = PBXGroup; children = ( 98AB2E7F1CAD46830089BB98 /* moonlight-common.xcodeproj */, - FB290CF919B2C406004C83CF /* Limelight */, + FB290CF919B2C406004C83CF /* Moonlight */, + D46A73A11CBC7CB60039F1EE /* MoonlightUnitTests */, FB290CF019B2C406004C83CF /* Frameworks */, FB290CEF19B2C406004C83CF /* Products */, ); @@ -370,6 +408,7 @@ isa = PBXGroup; children = ( FB290CEE19B2C406004C83CF /* Moonlight.app */, + D46A73A01CBC7CB60039F1EE /* MoonlightUnitTests.xctest */, ); name = Products; sourceTree = ""; @@ -393,9 +432,10 @@ name = Frameworks; sourceTree = ""; }; - FB290CF919B2C406004C83CF /* Limelight */ = { + FB290CF919B2C406004C83CF /* Moonlight */ = { isa = PBXGroup; children = ( + D4746EEA1CBC740C006FB401 /* Moonlight-Bridging-Header.h */, 9E5D5FF61A5A5A3900689918 /* Font */, FB89460419F646E200339C8A /* Crypto */, FB89460919F646E200339C8A /* Input */, @@ -421,6 +461,7 @@ FB1D59981BBCCD7E00F482CA /* AppCollectionView.h */, FB1D59991BBCCD7E00F482CA /* AppCollectionView.m */, ); + name = Moonlight; path = Limelight; sourceTree = ""; }; @@ -453,8 +494,7 @@ children = ( FB89460A19F646E200339C8A /* ControllerSupport.h */, FB89460B19F646E200339C8A /* ControllerSupport.m */, - FB9AFD411A7F0C6900872C98 /* Controller.h */, - FB9AFD421A7F0C6900872C98 /* Controller.m */, + D4746EEB1CBC740C006FB401 /* Controller.swift */, FB89460C19F646E200339C8A /* StreamView.h */, FB89460D19F646E200339C8A /* StreamView.m */, FB4678EB1A50C40900377732 /* OnScreenControls.h */, @@ -750,6 +790,24 @@ /* End PBXGroup section */ /* Begin PBXNativeTarget section */ + D46A739F1CBC7CB60039F1EE /* MoonlightUnitTests */ = { + isa = PBXNativeTarget; + buildConfigurationList = D46A73A91CBC7CB60039F1EE /* Build configuration list for PBXNativeTarget "MoonlightUnitTests" */; + buildPhases = ( + D46A739C1CBC7CB60039F1EE /* Sources */, + D46A739D1CBC7CB60039F1EE /* Frameworks */, + D46A739E1CBC7CB60039F1EE /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + D46A73A61CBC7CB60039F1EE /* PBXTargetDependency */, + ); + name = MoonlightUnitTests; + productName = MoonlightUnitTests; + productReference = D46A73A01CBC7CB60039F1EE /* MoonlightUnitTests.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; FB290CED19B2C406004C83CF /* Moonlight */ = { isa = PBXNativeTarget; buildConfigurationList = FB290D2019B2C406004C83CF /* Build configuration list for PBXNativeTarget "Moonlight" */; @@ -774,9 +832,14 @@ FB290CE619B2C406004C83CF /* Project object */ = { isa = PBXProject; attributes = { + LastSwiftUpdateCheck = 0730; LastUpgradeCheck = 0700; ORGANIZATIONNAME = "Moonlight Stream"; TargetAttributes = { + D46A739F1CBC7CB60039F1EE = { + CreatedOnToolsVersion = 7.3; + TestTargetID = FB290CED19B2C406004C83CF; + }; FB290CED19B2C406004C83CF = { DevelopmentTeam = DM46QST4M7; }; @@ -801,6 +864,7 @@ projectRoot = ""; targets = ( FB290CED19B2C406004C83CF /* Moonlight */, + D46A739F1CBC7CB60039F1EE /* MoonlightUnitTests */, ); }; /* End PBXProject section */ @@ -816,6 +880,13 @@ /* End PBXReferenceProxy section */ /* Begin PBXResourcesBuildPhase section */ + D46A739E1CBC7CB60039F1EE /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; FB290CEC19B2C406004C83CF /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; @@ -838,6 +909,14 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ + D46A739C1CBC7CB60039F1EE /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + D46A73AD1CBC7D090039F1EE /* ControllerUnitTests.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; FB290CEA19B2C406004C83CF /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; @@ -877,12 +956,12 @@ FB9AFD371A7E02DB00872C98 /* HttpRequest.m in Sources */, FB4678ED1A50C40900377732 /* OnScreenControls.m in Sources */, FB290D0019B2C406004C83CF /* main.m in Sources */, - FB9AFD431A7F0C6900872C98 /* Controller.m in Sources */, FBD3494319FC9C04002D2A60 /* AppAssetManager.m in Sources */, FB6549561A57907E001C8F39 /* DiscoveryWorker.m in Sources */, FB89462A19F646E200339C8A /* ControllerSupport.m in Sources */, FB9AFD3D1A7E111600872C98 /* AppAssetResponse.m in Sources */, FBD349621A0089F6002D2A60 /* DataManager.m in Sources */, + D4746EEC1CBC740C006FB401 /* Controller.swift in Sources */, FBFCB3351B50B29400089F8A /* App.m in Sources */, FB4A23B81A9D3637004D2EF2 /* LoadingFrameViewController.m in Sources */, FB9AFD3A1A7E05CE00872C98 /* ServerInfoResponse.m in Sources */, @@ -898,6 +977,11 @@ name = "moonlight-common"; targetProxy = 98AB2E851CAD468B0089BB98 /* PBXContainerItemProxy */; }; + D46A73A61CBC7CB60039F1EE /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = FB290CED19B2C406004C83CF /* Moonlight */; + targetProxy = D46A73A51CBC7CB60039F1EE /* PBXContainerItemProxy */; + }; /* End PBXTargetDependency section */ /* Begin PBXVariantGroup section */ @@ -912,6 +996,51 @@ /* End PBXVariantGroup section */ /* Begin XCBuildConfiguration section */ + D46A73A71CBC7CB60039F1EE /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ENABLE_MODULES = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_NO_COMMON_BLOCKS = YES; + INFOPLIST_FILE = MoonlightUnitTests/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 9.3; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + MTL_ENABLE_DEBUG_INFO = YES; + PRODUCT_BUNDLE_IDENTIFIER = "com.moonlight-stream.MoonlightUnitTests"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "MoonlightUnitTests/MoonlightUnitTests-Bridging-Header.h"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Moonlight.app/Moonlight"; + }; + name = Debug; + }; + D46A73A81CBC7CB60039F1EE /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ENABLE_MODULES = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_NO_COMMON_BLOCKS = YES; + INFOPLIST_FILE = MoonlightUnitTests/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 9.3; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + MTL_ENABLE_DEBUG_INFO = NO; + PRODUCT_BUNDLE_IDENTIFIER = "com.moonlight-stream.MoonlightUnitTests"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "MoonlightUnitTests/MoonlightUnitTests-Bridging-Header.h"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Moonlight.app/Moonlight"; + }; + name = Release; + }; FB290D1E19B2C406004C83CF /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { @@ -992,6 +1121,7 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; ENABLE_BITCODE = NO; @@ -1005,6 +1135,7 @@ "$(PROJECT_DIR)/libs/**", ); INFOPLIST_FILE = "Limelight/Limelight-Info.plist"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; LIBRARY_SEARCH_PATHS = ( "$(inherited)", "$(PROJECT_DIR)/libs/opus/lib", @@ -1014,6 +1145,8 @@ PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE = ""; SKIP_INSTALL = NO; + SWIFT_OBJC_BRIDGING_HEADER = "Limelight/Input/Moonlight-Bridging-Header.h"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; WRAPPER_EXTENSION = app; }; name = Debug; @@ -1022,6 +1155,7 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; ENABLE_BITCODE = NO; @@ -1035,6 +1169,7 @@ "$(PROJECT_DIR)/libs/**", ); INFOPLIST_FILE = "Limelight/Limelight-Info.plist"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; LIBRARY_SEARCH_PATHS = ( "$(inherited)", "$(PROJECT_DIR)/libs/opus/lib", @@ -1044,6 +1179,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE = ""; SKIP_INSTALL = NO; + SWIFT_OBJC_BRIDGING_HEADER = "Limelight/Input/Moonlight-Bridging-Header.h"; WRAPPER_EXTENSION = app; }; name = Release; @@ -1051,6 +1187,15 @@ /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ + D46A73A91CBC7CB60039F1EE /* Build configuration list for PBXNativeTarget "MoonlightUnitTests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + D46A73A71CBC7CB60039F1EE /* Debug */, + D46A73A81CBC7CB60039F1EE /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; FB290CE919B2C406004C83CF /* Build configuration list for PBXProject "Moonlight" */ = { isa = XCConfigurationList; buildConfigurations = ( diff --git a/MoonlightUnitTests/Info.plist b/MoonlightUnitTests/Info.plist new file mode 100644 index 0000000..ba72822 --- /dev/null +++ b/MoonlightUnitTests/Info.plist @@ -0,0 +1,24 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + + diff --git a/MoonlightUnitTests/Input/ControllerUnitTests.swift b/MoonlightUnitTests/Input/ControllerUnitTests.swift new file mode 100644 index 0000000..5a2a788 --- /dev/null +++ b/MoonlightUnitTests/Input/ControllerUnitTests.swift @@ -0,0 +1,192 @@ +// +// ControllerUnitTests.swift +// Moonlight +// +// Created by David Aghassi on 4/11/16. +// Copyright © 2016 Moonlight Stream. All rights reserved. +// + +import XCTest +@testable import Moonlight + +/** + Tests the `Controller.swift` class + */ +class ControllerUnitTests: XCTestCase { + var controllerUnderTest: Controller! + + override func setUp() { + controllerUnderTest = Controller() + XCTAssertNotNil(controllerUnderTest, "controllerUnderTest is nil, and should not be for this test. See line \(#line) \n") + } + + override func tearDown() { + resetAllValues() + } + + + // MARK: Helper Methods + /** + Sets all the values of `controllerUnderTest` to `0` + */ + func resetAllValues() { + controllerUnderTest.emulatingButtonFlags = CInt(0) + controllerUnderTest.lastButtonFlags = CInt(0) + + controllerUnderTest.lastLeftStickX = CShort(0) + controllerUnderTest.lastLeftStickY = CShort(0) + controllerUnderTest.lastRightStickX = CShort(0) + controllerUnderTest.lastRightStickY = CShort(0) + + controllerUnderTest.lastLeftTrigger = CChar(0) + controllerUnderTest.lastRightTrigger = CChar(0) + } + + /** + Displays "*name* failed to set CInt correctly." Shows expected and actual, as well as failure line. + + - parameter name: The property being tested + - parameter expected: The expected value for the property + - parameter actual: The actual value for the property + + - returns: A string with the failure in it. Formatted to state actual, expected, and the failure line. + */ + func displayCIntFailure(name: String, expected: CInt, actual: CInt) -> String { + return "\(name) failed to set CInt correctly \n. Expected: \(expected)\n. Actual: \(actual) \n. See line \(#line) \n" + } + + /** + Displays "*name* failed to set CShort correctly." Shows expected and actual, as well as failure line. + + - parameter name: The property being tested + - parameter expected: The expected value for the property + - parameter actual: The actual value for the property + + - returns: A string with the failure in it. Formatted to state actual, expected, and the failure line. + */ + func displayCShortFailure(name: String, expected: CShort, actual: CShort) -> String { + return "\(name) failed to set CShort correctly \n. Expected: \(expected)\n. Actual: \(actual) \n. See line \(#line) \n" + } + + /** + Displays "*name* failed to set CCHar correctly." Shows expected and actual, as well as the failure line. + + - parameter name: The property being tested + - parameter expected: The expected value for the property + - parameter actual: The actual value for the property + + - returns: A string with the failure in it. Formatted to state actual, expected, and the failure line. + */ + func displayCCharFailure(name: String, expected: CChar, actual: CChar) -> String { + return "\(name) failed to set CChar correctly \n. Expected: \(expected)\n. Actual: \(actual) \n. See line \(#line) \n" + } + + + // MARK: Tests + /** + Asserts that the `emulatingButtonFlags` is of type `CInt` and can be set and gotten from properly + */ + func test_Assert_emulatingButtonFlags_Sets_To_CInt() { + // Assert type hasn't changed + XCTAssertTrue(controllerUnderTest.emulatingButtonFlags.dynamicType == CInt.self, "Expected emulatingButtonFlags to be of type CInt. See line \(#line) \n") + + // Assert value is assigned properly. + let expected = CInt(1) + controllerUnderTest.emulatingButtonFlags = expected + XCTAssertTrue(controllerUnderTest.emulatingButtonFlags == expected, displayCIntFailure("emulatingButtonFlags", expected: expected, actual: controllerUnderTest.emulatingButtonFlags)) + } + + /** + Asserts that the `lastButtonFlags` is of type `CInt` and can be set and gotten from properly + */ + func test_Assert_lastButtonFlags_Sets_To_CInt() { + // Assert type hasn't changed + XCTAssertTrue(controllerUnderTest.lastButtonFlags.dynamicType == CInt.self, "Expected lastButtonFlags to be of type CInt. See line \(#line) \n") + + // Assert value is assigned properly. + let expected = CInt(1) + controllerUnderTest.lastButtonFlags = expected + XCTAssertTrue(controllerUnderTest.lastButtonFlags == expected, displayCIntFailure("lastButtonFlags", expected: expected, actual: controllerUnderTest.lastButtonFlags)) + } + + /** + Asserts that the `lastLeftStickX` is of type `CShort` and can be set and gotten from properly + */ + func test_Assert_lastLeftStickX_Sets_To_CShort() { + // Assert type hasn't changed + XCTAssertTrue(controllerUnderTest.lastLeftStickX.dynamicType == CShort.self, "Expected lastLeftStickX to be of type CShort. See line \(#line) \n") + + // Assert value is assigned properly. + let expected = CShort(1) + controllerUnderTest.lastLeftStickX = expected + XCTAssertTrue(controllerUnderTest.lastLeftStickX == expected, displayCShortFailure("lastLeftStickX", expected: expected, actual: controllerUnderTest.lastLeftStickX)) + } + + /** + Asserts that lastLeftStickY` is of type `CShort` and can be set and gotten from properly + */ + func test_Assert_lastLeftStickY_Sets_To_CShort() { + // Assert type hasn't changed + XCTAssertTrue(controllerUnderTest.lastLeftStickY.dynamicType == CShort.self, "Expected lastLeftStickY to be of type CShort. See line \(#line) \n") + + // Assert value is assigned properly. + let expected = CShort(1) + controllerUnderTest.lastLeftStickY = expected + XCTAssertTrue(controllerUnderTest.lastLeftStickY == expected, displayCShortFailure("lastLeftStickY", expected: expected, actual: controllerUnderTest.lastLeftStickY)) + } + + /** + Asserts that the `lastRightStickX` is of type `CShort` and can be set and gotten from properly + */ + func test_Assert_lastRightStickX_SetsTo_CShort() { + // Assert type hasn't changed + XCTAssertTrue(controllerUnderTest.lastRightStickX.dynamicType == CShort.self, "Expected lastRightStickX to be of type CShort. See line \(#line) \n") + + // Assert value is assigned properly. + let expected = CShort(1) + controllerUnderTest.lastRightStickX = expected + XCTAssertTrue(controllerUnderTest.lastRightStickX == expected, displayCShortFailure("lastRightStickX", expected: expected, actual: controllerUnderTest.lastRightStickX)) + } + + /** + Asserts that the `lastRightStickY` is of type `CShort` and can be set and gotten from properly + */ + func test_Assert_lastRightStickY_Sets_To_CShort() { + // Assert type hasn't changed + XCTAssertTrue(controllerUnderTest.lastRightStickY.dynamicType == CShort.self, "Expected lastRightStickY to be of type CShort. See line \(#line) \n") + + // Assert value is assigned properly. + let expected = CShort(1) + controllerUnderTest.lastRightStickY = expected + XCTAssertTrue(controllerUnderTest.lastRightStickY == expected, displayCShortFailure("lastRightStickY", expected: expected, actual: controllerUnderTest.lastRightStickY)) + } + + /** + Asserts that the `lastLeftTrigger` is of type `CChar` and can be set and gotten from properly + */ + func test_Assert_lastLeftTrigger_Sets_To_CChar() { + // Assert type hasn't changed + XCTAssertTrue(controllerUnderTest.lastLeftTrigger.dynamicType == CChar.self, "Expected lastLeftTrigger to be of type CChar. See line \(#line) \n") + + // Assert value is assigned properly. + let expected = CChar(1) + controllerUnderTest.lastLeftTrigger = expected + XCTAssertTrue(controllerUnderTest.lastLeftTrigger == expected, displayCCharFailure("lastLeftTrigger", expected: expected, actual: controllerUnderTest.lastLeftTrigger)) + + } + + /** + Asserts that the `lastRightTrigger` is of type `CChar` and can be set and gotten from properly + */ + func test_Assert_lastRightTrigger_Sets_To_CChar() { + // Assert type hasn't changed + XCTAssertTrue(controllerUnderTest.lastRightTrigger.dynamicType == CChar.self, "Expected lastRightTrigger to be of type CChar. See line \(#line) \n") + + // Assert value is assigned properly. + let expected = CChar(1) + controllerUnderTest.lastRightTrigger = expected + XCTAssertTrue(controllerUnderTest.lastRightTrigger == expected, displayCCharFailure("lastRightTrigger", expected: expected, actual: controllerUnderTest.lastRightTrigger)) + + } + +} diff --git a/MoonlightUnitTests/MoonlightUnitTests-Bridging-Header.h b/MoonlightUnitTests/MoonlightUnitTests-Bridging-Header.h new file mode 100644 index 0000000..1b2cb5d --- /dev/null +++ b/MoonlightUnitTests/MoonlightUnitTests-Bridging-Header.h @@ -0,0 +1,4 @@ +// +// Use this file to import your target's public headers that you would like to expose to Swift. +// + diff --git a/moonlight-common/moonlight-common.xcodeproj/project.pbxproj b/moonlight-common/moonlight-common.xcodeproj/project.pbxproj index 63f3571..b58b29e 100644 --- a/moonlight-common/moonlight-common.xcodeproj/project.pbxproj +++ b/moonlight-common/moonlight-common.xcodeproj/project.pbxproj @@ -341,6 +341,7 @@ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = "Mac Developer"; COPY_PHASE_STRIP = NO; + DEFINES_MODULE = YES; ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; @@ -384,6 +385,7 @@ CODE_SIGN_IDENTITY = "3rd Party Mac Developer Application"; COPY_PHASE_STRIP = YES; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + DEFINES_MODULE = YES; ENABLE_NS_ASSERTIONS = NO; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_ENABLE_OBJC_EXCEPTIONS = YES;