From 03dccbe61356f7d3059de981e3bac1d4f005ec47 Mon Sep 17 00:00:00 2001 From: cacaodev Date: Fri, 30 Jun 2017 12:26:15 +0200 Subject: [PATCH] Add a manual test for the previous fixes. The tests must be run independently because animations are launched at the end of the current run loop. --- AppKit/CoreAnimation/CPAnimationContext.j | 1 - .../CPAnimationContextTest/AppController.j | 172 +++++++++++++++ .../Manual/CPAnimationContextTest/Info.plist | 12 ++ Tests/Manual/CPAnimationContextTest/Jakefile | 184 ++++++++++++++++ .../CPAnimationContextTest/index-debug.html | 204 ++++++++++++++++++ .../Manual/CPAnimationContextTest/index.html | 166 ++++++++++++++ Tests/Manual/CPAnimationContextTest/main.j | 18 ++ .../CPCollectionViewNibTest/AppController.j | 4 +- 8 files changed, 758 insertions(+), 3 deletions(-) create mode 100644 Tests/Manual/CPAnimationContextTest/AppController.j create mode 100644 Tests/Manual/CPAnimationContextTest/Info.plist create mode 100644 Tests/Manual/CPAnimationContextTest/Jakefile create mode 100644 Tests/Manual/CPAnimationContextTest/index-debug.html create mode 100644 Tests/Manual/CPAnimationContextTest/index.html create mode 100644 Tests/Manual/CPAnimationContextTest/main.j diff --git a/AppKit/CoreAnimation/CPAnimationContext.j b/AppKit/CoreAnimation/CPAnimationContext.j index 0bf7b07b7..4a2225e00 100644 --- a/AppKit/CoreAnimation/CPAnimationContext.j +++ b/AppKit/CoreAnimation/CPAnimationContext.j @@ -261,7 +261,6 @@ var _CPAnimationContextStack = nil, } // start timers - while(k--) { #if (DEBUG) diff --git a/Tests/Manual/CPAnimationContextTest/AppController.j b/Tests/Manual/CPAnimationContextTest/AppController.j new file mode 100644 index 000000000..ffae47f58 --- /dev/null +++ b/Tests/Manual/CPAnimationContextTest/AppController.j @@ -0,0 +1,172 @@ +/* + * AppController.j + * CPAnimationContextTest + * + * Created by You on June 28, 2017. + * Copyright 2017, Your Company All rights reserved. + */ + +@import +@import + +#define UIAssert(a) [self markTest:_cmd didPass:a]; + +@implementation AppController : CPObject +{ + CPWindow theWindow; +} + +- (void)applicationDidFinishLaunching:(CPNotification)aNotification +{ + theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask]; + var contentView = [theWindow contentView]; + + [theWindow orderFront:self]; + + [self setup]; + // Uncomment the following line to turn on the standard menu bar. + //[CPMenu setMenuBarVisible:YES]; +} + +- (void)setup +{ + var methods = class_copyMethodList([self class]); + var testMethodCount = 0; + [methods enumerateObjectsUsingBlock:function(meth, _) + { + var method_name = method_getName(meth); + if ([method_name hasPrefix:@"test"]) + { + var runButton = [[CPButton alloc] initWithFrame:CGRectMake(10,10 + 35*testMethodCount,0,32)]; + [runButton setTitle:unCamelCase(method_name)]; + [runButton setTarget:self]; + [runButton setAction:CPSelectorFromString(method_name)]; + [[theWindow contentView] addSubview:runButton]; + [runButton sizeToFit]; + + var label = [[CPTextField alloc] initWithFrame:CGRectMake(CGRectGetMaxX([runButton frame]) + 10, 10 + 35*testMethodCount,200,32)]; + [label setIdentifier:method_name]; + [label setFont:[CPFont systemFontOfSize:16]]; + [label setStringValue:@"………"]; + [[theWindow contentView] addSubview:label]; + testMethodCount++; + } + }]; +} + +- (void)markTest:(CPString)testSelector didPass:(BOOL)passed +{ + [[[theWindow contentView] subviews] enumerateObjectsUsingBlock:function(aView, idx, stop) + { + if ([aView identifier] == testSelector) + { + [aView setTextColor:passed ? [CPColor greenColor]: [CPColor redColor]]; + [aView setStringValue:(passed ? @"Passed" : "Failed")]; + } + }]; +} + +/* + =================== + ====== TESTS ====== + =================== +*/ + +- (void)testCompletionHandlerWithoutAnimator +{ + var completions = @[]; + + var ctx = [CPAnimationContext currentContext]; + [ctx setDuration:0.1]; + [ctx setCompletionHandler:function() + { + [completions addObject:@"done"]; + UIAssert([completions isEqualToArray:@["done"]]); + }]; +} + +- (void)testCompletionHandlerWithoutAnimatorWithGrouping +{ + var completions = @[]; + + [CPAnimationContext beginGrouping]; + + var ctx = [CPAnimationContext currentContext]; + [ctx setDuration:0.1]; + [ctx setCompletionHandler:function() + { + [completions addObject:@"done"]; + UIAssert([completions isEqualToArray:@["done"]]); + }]; + + [CPAnimationContext endGrouping]; +} + +- (void)testCompletionHandlerAnimatorMethodNotAnimating:(id)sender +{ + var completions = @[]; + + [CPAnimationContext beginGrouping]; + + var ctx = [CPAnimationContext currentContext]; + [ctx setDuration:0.1]; + [ctx setCompletionHandler:function() + { + [completions addObject:@"done"]; + UIAssert([completions isEqualToArray:@["done"]]); + }]; + + [[sender animator] setObjectValue:0]; + + [CPAnimationContext endGrouping]; +} + +- (void)testCompletionHandlerViewNotMoving:(id)sender +{ + var completions = @[]; + + [CPAnimationContext beginGrouping]; + + var ctx = [CPAnimationContext currentContext]; + [ctx setDuration:0.1]; + [ctx setCompletionHandler:function() + { + [completions addObject:@"done"]; + UIAssert([completions isEqualToArray:@["done"]]); + }]; + + [[sender animator] setFrame:[sender frame]]; + + [CPAnimationContext endGrouping]; +} + +- (void)testSetCompletionHandler:(id)sender +{ + var completions = @[]; + + var ctx = [CPAnimationContext currentContext]; + [ctx setDuration:0.1]; + [ctx setCompletionHandler:function() + { + CPLog.debug("We should never be here"); + UIAssert(NO); + }]; + + [ctx setCompletionHandler:function() + { + [completions addObject:@"done"]; + UIAssert([completions isEqualToArray:@["done"]]); + }]; + + [[sender animator] setFrame:[sender frame]]; +} + +@end + +var unCamelCase = function(aString) +{ + // insert a space before all caps + return aString.replace(/([A-Z])/g, ' $1') + // uppercase the first character + .replace(/^./, function(str){ return str.toUpperCase(); }); +}; diff --git a/Tests/Manual/CPAnimationContextTest/Info.plist b/Tests/Manual/CPAnimationContextTest/Info.plist new file mode 100644 index 000000000..2a5c58ae5 --- /dev/null +++ b/Tests/Manual/CPAnimationContextTest/Info.plist @@ -0,0 +1,12 @@ + + + + + CPApplicationDelegateClass + AppController + CPBundleName + CPAnimationContextTest + CPPrincipalClass + CPApplication + + diff --git a/Tests/Manual/CPAnimationContextTest/Jakefile b/Tests/Manual/CPAnimationContextTest/Jakefile new file mode 100644 index 000000000..c3db5628c --- /dev/null +++ b/Tests/Manual/CPAnimationContextTest/Jakefile @@ -0,0 +1,184 @@ +/* + * Jakefile + * CPAnimationContextTest + * + * Created by You on June 28, 2017. + * Copyright 2017, Your Company All rights reserved. + */ + +var ENV = require("system").env, + FILE = require("file"), + JAKE = require("jake"), + task = JAKE.task, + FileList = JAKE.FileList, + app = require("cappuccino/jake").app, + configuration = ENV["CONFIG"] || ENV["CONFIGURATION"] || ENV["c"] || "Debug", + OS = require("os"), + projectName = "CPAnimationContextTest"; + +app (projectName, function(task) +{ + ENV["OBJJ_INCLUDE_PATHS"] = "Frameworks"; + + if (configuration === "Debug") + ENV["OBJJ_INCLUDE_PATHS"] = FILE.join(ENV["OBJJ_INCLUDE_PATHS"], configuration); + + task.setBuildIntermediatesPath(FILE.join("Build", "CPAnimationContextTest.build", configuration)); + task.setBuildPath(FILE.join("Build", configuration)); + + task.setProductName("CPAnimationContextTest"); + task.setIdentifier("com.yourcompany.CPAnimationContextTest"); + task.setVersion("1.0"); + task.setAuthor("Your Company"); + task.setEmail("feedback @nospam@ yourcompany.com"); + task.setSummary("CPAnimationContextTest"); + task.setSources(new FileList("**/*.j").exclude(FILE.join("Build", "**")).exclude(FILE.join("Frameworks", "Source", "**"))); + task.setResources(new FileList("Resources/**")); + task.setIndexFilePath("index.html"); + task.setInfoPlistPath("Info.plist"); + + if (configuration === "Debug") + task.setCompilerFlags("-DDEBUG -g"); + else + task.setCompilerFlags("-O2"); +}); + +task ("default", [projectName], function() +{ + printResults(configuration); +}); + +task ("build", ["default"], function() +{ + updateApplicationSize(); +}); + +task ("debug", function() +{ + configuration = ENV["CONFIGURATION"] = "Debug"; + JAKE.subjake(["."], "build", ENV); +}); + +task ("release", function() +{ + configuration = ENV["CONFIGURATION"] = "Release"; + JAKE.subjake(["."], "build", ENV); +}); + +task ("run", ["debug"], function() +{ + OS.system(["open", FILE.join("Build", "Debug", projectName, "index.html")]); +}); + +task ("run-release", ["release"], function() +{ + OS.system(["open", FILE.join("Build", "Release", projectName, "index.html")]); +}); + +task ("deploy", ["release"], function() +{ + FILE.mkdirs(FILE.join("Build", "Deployment", projectName)); + OS.system(["press", "-f", FILE.join("Build", "Release", projectName), FILE.join("Build", "Deployment", projectName)]); + printResults("Deployment") +}); + +task ("desktop", ["release"], function() +{ + FILE.mkdirs(FILE.join("Build", "Desktop", projectName)); + require("cappuccino/nativehost").buildNativeHost(FILE.join("Build", "Release", projectName), FILE.join("Build", "Desktop", projectName, "CPAnimationContextTest.app")); + printResults("Desktop") +}); + +task ("run-desktop", ["desktop"], function() +{ + OS.system([FILE.join("Build", "Desktop", projectName, "CPAnimationContextTest.app", "Contents", "MacOS", "NativeHost"), "-i"]); +}); + +function printResults(configuration) +{ + print("----------------------------"); + print(configuration+" app built at path: "+FILE.join("Build", configuration, projectName)); + print("----------------------------"); +} + +function updateApplicationSize() +{ + print("Calculating application file sizes..."); + + var contents = FILE.read(FILE.join("Build", configuration, projectName, "Info.plist"), { charset:"UTF-8" }), + format = CFPropertyList.sniffedFormatOfString(contents), + plist = CFPropertyList.propertyListFromString(contents), + totalBytes = {executable:0, data:0, mhtml:0}; + + // Get the size of all framework executables and sprite data + var frameworksDir = "Frameworks"; + + if (configuration === "Debug") + frameworksDir = FILE.join(frameworksDir, "Debug"); + + var frameworks = FILE.list(frameworksDir); + + frameworks.forEach(function(framework) + { + if (framework !== "Source") + addBundleFileSizes(FILE.join(frameworksDir, framework), totalBytes); + }); + + // Read in the default theme name, and attempt to get its size + var themeName = plist.valueForKey("CPDefaultTheme") || "Aristo2", + themePath = nil; + + if (themeName === "Aristo" || themeName === "Aristo2") + themePath = FILE.join(frameworksDir, "AppKit", "Resources", themeName + ".blend"); + else + themePath = FILE.join("Frameworks", "Resources", themeName + ".blend"); + + if (FILE.isDirectory(themePath)) + addBundleFileSizes(themePath, totalBytes); + + // Add sizes for the app + addBundleFileSizes(FILE.join("Build", configuration, projectName), totalBytes); + + print("Executables: " + totalBytes.executable + ", sprite data: " + totalBytes.data + ", total: " + (totalBytes.executable + totalBytes.data)); + + var dict = new CFMutableDictionary(); + + dict.setValueForKey("executable", totalBytes.executable); + dict.setValueForKey("data", totalBytes.data); + dict.setValueForKey("mhtml", totalBytes.mhtml); + + plist.setValueForKey("CPApplicationSize", dict); + + FILE.write(FILE.join("Build", configuration, projectName, "Info.plist"), CFPropertyList.stringFromPropertyList(plist, format), { charset:"UTF-8" }); +} + +function addBundleFileSizes(bundlePath, totalBytes) +{ + var bundleName = FILE.basename(bundlePath), + environment = bundleName === "Foundation" ? "Objj" : "Browser", + bundlePath = FILE.join(bundlePath, environment + ".environment"); + + if (FILE.isDirectory(bundlePath)) + { + var filename = bundleName + ".sj", + filePath = new FILE.Path(FILE.join(bundlePath, filename)); + + if (filePath.exists()) + totalBytes.executable += filePath.size(); + + filePath = new FILE.Path(FILE.join(bundlePath, "dataURLs.txt")); + + if (filePath.exists()) + totalBytes.data += filePath.size(); + + filePath = new FILE.Path(FILE.join(bundlePath, "MHTMLData.txt")); + + if (filePath.exists()) + totalBytes.mhtml += filePath.size(); + + filePath = new FILE.Path(FILE.join(bundlePath, "MHTMLPaths.txt")); + + if (filePath.exists()) + totalBytes.mhtml += filePath.size(); + } +} diff --git a/Tests/Manual/CPAnimationContextTest/index-debug.html b/Tests/Manual/CPAnimationContextTest/index-debug.html new file mode 100644 index 000000000..504b47db3 --- /dev/null +++ b/Tests/Manual/CPAnimationContextTest/index-debug.html @@ -0,0 +1,204 @@ + + + + + + + + + + + + + + + + + + CPAnimationContextTest + + + + + + + + + + + + + + +
+
+
+ +
+
+ +
+ + diff --git a/Tests/Manual/CPAnimationContextTest/index.html b/Tests/Manual/CPAnimationContextTest/index.html new file mode 100644 index 000000000..a9ab78274 --- /dev/null +++ b/Tests/Manual/CPAnimationContextTest/index.html @@ -0,0 +1,166 @@ + + + + + + + + + + + + + + + + + + CPAnimationContextTest + + + + + + + + + + + + +
+
+
+ +
+
+ +
+ + diff --git a/Tests/Manual/CPAnimationContextTest/main.j b/Tests/Manual/CPAnimationContextTest/main.j new file mode 100644 index 000000000..fad2ca5ac --- /dev/null +++ b/Tests/Manual/CPAnimationContextTest/main.j @@ -0,0 +1,18 @@ +/* + * AppController.j + * CPAnimationContextTest + * + * Created by You on June 28, 2017. + * Copyright 2017, Your Company All rights reserved. + */ + +@import +@import + +@import "AppController.j" + + +function main(args, namedArgs) +{ + CPApplicationMain(args, namedArgs); +} diff --git a/Tests/Manual/CPCollectionViewNibTest/AppController.j b/Tests/Manual/CPCollectionViewNibTest/AppController.j index 6f26dd5b9..4b1e79e00 100644 --- a/Tests/Manual/CPCollectionViewNibTest/AppController.j +++ b/Tests/Manual/CPCollectionViewNibTest/AppController.j @@ -7,7 +7,6 @@ */ @import -//@import "CPCollectionView.j" CPLogRegister(CPLogConsole); @@ -42,7 +41,8 @@ CPLogRegister(CPLogConsole); [collectionView registerForDraggedTypes:[@"DragType"]]; [emptyCollectionView registerForDraggedTypes:[@"DragType"]]; - //[theWindow setFullPlatformWindow:YES]; + + [collectionView setBackgroundColors:@[[CPColor redColor], [CPColor greenColor]]]; } - (IBAction)setPrototypeItem:(id)sender