| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 9f8d24a commit 8b4a9b3
10 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,7 +7,7 @@ | |||
| 7 | 7 | 4. tests should use TKUnit.assert(condition, message) to mark error. If no assert fails test is successful | |
| 8 | 8 | 5. (if exists) at the end of each test tearDown() module function is called | |
| 9 | 9 | 6. (if exists) at the end of module test tearDownModule() module function is called | |
| 10 | - | ||
| 10 | + | ||
| 11 | 11 | */ | |
| 12 | 12 | ||
| 13 | 13 | import * as Application from "tns-core-modules/application"; | |
@@ -317,6 +317,12 @@ export function assertAreClose(actual: number, expected: number, delta: number, | |||
| 317 | 317 | } | |
| 318 | 318 | } | |
| 319 | 319 | ||
| 320 | + export function assertMatches(actual: string, expected: RegExp, message?: string) { | ||
| 321 | + if (expected.test(actual) !== true) { | ||
| 322 | + throw new Error(`"${actual}" doesn't match "${expected}". ${message}`); | ||
| 323 | + } | ||
| 324 | + } | ||
| 325 | + | ||
| 320 | 326 | export function arrayAssert(actual: Array<any>, expected: Array<any>, message?: string) { | |
| 321 | 327 | if (actual.length !== expected.length) { | |
| 322 | 328 | throw new Error(message + " Actual array length: " + actual.length + " Expected array length: " + expected.length); | |
@@ -330,6 +336,11 @@ export function arrayAssert(actual: Array<any>, expected: Array<any>, message?: | |||
| 330 | 336 | } | |
| 331 | 337 | ||
| 332 | 338 | export function assertThrows(testFunc: () => void, assertMessage?: string, expectedMessage?: string) { | |
| 339 | + const re = expectedMessage ? new RegExp(`^${expectedMessage}$`) : null; | ||
| 340 | + return assertThrowsRegExp(testFunc, assertMessage, re); | ||
| 341 | + } | ||
| 342 | + | ||
| 343 | + export function assertThrowsRegExp(testFunc: () => void, assertMessage?: string, expectedMessage?: RegExp) { | ||
| 333 | 344 | let actualError: Error; | |
| 334 | 345 | try { | |
| 335 | 346 | testFunc(); | |
@@ -341,8 +352,8 @@ export function assertThrows(testFunc: () => void, assertMessage?: string, expec | |||
| 341 | 352 | throw new Error("Missing expected exception. " + assertMessage); | |
| 342 | 353 | } | |
| 343 | 354 | ||
| 344 | - if (expectedMessage && actualError.message !== expectedMessage) { | ||
| 345 | - throw new Error("Got unwanted exception. Actual error: " + actualError.message + " Expected error: " + expectedMessage); | ||
| 355 | + if (expectedMessage && !expectedMessage.test(actualError.message)) { | ||
| 356 | + throw new Error("Got unwanted exception. Actual error: " + actualError.message + " Expected to match: " + expectedMessage); | ||
| 346 | 357 | } | |
| 347 | 358 | } | |
| 348 | 359 | ||
@@ -455,4 +466,4 @@ function doModalAndroid(quitLoop: () => boolean, timeoutSec: number, shouldThrow | |||
| 455 | 466 | quit = true; | |
| 456 | 467 | } | |
| 457 | 468 | } | |
| 458 | - } | ||
| 469 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -264,6 +264,9 @@ allTests["RESET-ROOT-VIEW"] = resetRootViewTests; | |||
| 264 | 264 | import * as rootViewTests from "./ui/root-view/root-view-tests"; | |
| 265 | 265 | allTests["ROOT-VIEW"] = rootViewTests; | |
| 266 | 266 | ||
| 267 | + import * as utilsTests from "./utils/utils-tests"; | ||
| 268 | + allTests["UTILS"] = utilsTests; | ||
| 269 | + | ||
| 267 | 270 | const testsSuitesWithLongDelay = { | |
| 268 | 271 | HTTP: 15 * 1000, | |
| 269 | 272 | } | |
@@ -504,4 +507,4 @@ class TestInfo implements TKUnit.TestInfoEntry { | |||
| 504 | 507 | this.testTimeout = testTimeout; | |
| 505 | 508 | this.duration = duration; | |
| 506 | 509 | } | |
| 507 | - } | ||
| 510 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,44 @@ | |||
| 1 | + import * as TKUnit from "../TKUnit"; | ||
| 2 | + import * as utils from "tns-core-modules/utils/utils"; | ||
| 3 | + import { isIOS } from "tns-core-modules/platform"; | ||
| 4 | + | ||
| 5 | + export function test_GC_isDefined() { | ||
| 6 | + TKUnit.assertNotEqual(utils.GC, undefined, "Method utils.GC() should be defined!"); | ||
| 7 | + }; | ||
| 8 | + | ||
| 9 | + export function test_releaseNativeObject_isDefined() { | ||
| 10 | + TKUnit.assertNotEqual(utils.releaseNativeObject, undefined, "Method utils.releaseNativeObject() should be defined!"); | ||
| 11 | + }; | ||
| 12 | + | ||
| 13 | + export function test_releaseNativeObject_canBeCalledWithNativeObject() { | ||
| 14 | + if (isIOS) { | ||
| 15 | + test_releaseNativeObject_canBeCalledWithNativeObject_iOS(); | ||
| 16 | + } else { | ||
| 17 | + test_releaseNativeObject_canBeCalledWithNativeObject_Android(); | ||
| 18 | + } | ||
| 19 | + }; | ||
| 20 | + | ||
| 21 | + function test_releaseNativeObject_canBeCalledWithNativeObject_iOS() { | ||
| 22 | + let deallocated = false; | ||
| 23 | + const obj = new ((<any>NSObject).extend({ | ||
| 24 | + dealloc: function () { | ||
| 25 | + deallocated = true; | ||
| 26 | + } | ||
| 27 | + })); | ||
| 28 | + TKUnit.assertMatches(obj.description, /NSObject/, "Object description should match!") | ||
| 29 | + | ||
| 30 | + utils.releaseNativeObject(obj); | ||
| 31 | + | ||
| 32 | + // Need to sleep to make the delayed release get executed | ||
| 33 | + NSThread.sleepForTimeInterval(0); | ||
| 34 | + TKUnit.assertTrue(deallocated, "NativeObject must have been deallocated!"); | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + function test_releaseNativeObject_canBeCalledWithNativeObject_Android() { | ||
| 38 | + const obj = new java.lang.Object(); | ||
| 39 | + TKUnit.assertMatches(obj.toString(), /java.lang.Object/, "Object description should match!") | ||
| 40 | + | ||
| 41 | + utils.releaseNativeObject(obj); | ||
| 42 | + | ||
| 43 | + TKUnit.assertThrowsRegExp(obj.toString.bind(obj), "Should throw an error!", /Failed calling toString on a java\/lang\/Object instance/); | ||
| 44 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -206,6 +206,10 @@ export function GC() { | |||
| 206 | 206 | gc(); | |
| 207 | 207 | } | |
| 208 | 208 | ||
| 209 | + export function releaseNativeObject(object: java.lang.Object) { | ||
| 210 | + __releaseNativeCounterpart(object); | ||
| 211 | + } | ||
| 212 | + | ||
| 209 | 213 | export function openUrl(location: string): boolean { | |
| 210 | 214 | const context = ad.getApplicationContext(); | |
| 211 | 215 | try { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -191,7 +191,7 @@ export module ios { | |||
| 191 | 191 | */ | |
| 192 | 192 | export function getter<T>(_this: any, propertyValue: T | {(): T}): T; | |
| 193 | 193 | ||
| 194 | - // Common properties between UILabel, UITextView and UITextField | ||
| 194 | + // Common properties between UILabel, UITextView and UITextField | ||
| 195 | 195 | export interface TextUIView { | |
| 196 | 196 | font: any; | |
| 197 | 197 | textAlignment: number; | |
@@ -261,6 +261,12 @@ export module ios { | |||
| 261 | 261 | */ | |
| 262 | 262 | export function GC(); | |
| 263 | 263 | ||
| 264 | + /** | ||
| 265 | + * Releases the reference to the wrapped native object | ||
| 266 | + * @param object The Java/Objective-C object to release. | ||
| 267 | + */ | ||
| 268 | + export function releaseNativeObject(object: any /*java.lang.Object | NSObject*/); | ||
| 269 | + | ||
| 264 | 270 | /** | |
| 265 | 271 | * Returns true if the specified path points to a resource or local file. | |
| 266 | 272 | * @param path The path. | |
@@ -281,13 +287,13 @@ export function openUrl(url: string): boolean | |||
| 281 | 287 | ||
| 282 | 288 | /** | |
| 283 | 289 | * Escapes special regex symbols (., *, ^, $ and so on) in string in order to create a valid regex from it. | |
| 284 | - * @param source The original value. | ||
| 290 | + * @param source The original value. | ||
| 285 | 291 | */ | |
| 286 | 292 | export function escapeRegexSymbols(source: string): string | |
| 287 | 293 | ||
| 288 | 294 | /** | |
| 289 | 295 | * Converts string value to number or boolean. | |
| 290 | - * @param value The original value. | ||
| 296 | + * @param value The original value. | ||
| 291 | 297 | */ | |
| 292 | 298 | export function convertString(value: any): any | |
| 293 | 299 | ||
@@ -308,4 +314,4 @@ export function hasDuplicates(arr: Array<any>): boolean; | |||
| 308 | 314 | * Removes duplicate elements from array. | |
| 309 | 315 | * @param arr - The array. | |
| 310 | 316 | */ | |
| 311 | - export function eliminateDuplicates(arr: Array<any>): Array<any>; | ||
| 317 | + export function eliminateDuplicates(arr: Array<any>): Array<any>; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -105,7 +105,7 @@ export module ios { | |||
| 105 | 105 | // Strip part after tns_modules to obtain app root | |
| 106 | 106 | appPath = currentDir.substring(0, tnsModulesIndex); | |
| 107 | 107 | } | |
| 108 | - | ||
| 108 | + | ||
| 109 | 109 | return appPath; | |
| 110 | 110 | } | |
| 111 | 111 | ||
@@ -140,6 +140,10 @@ export function GC() { | |||
| 140 | 140 | __collect(); | |
| 141 | 141 | } | |
| 142 | 142 | ||
| 143 | + export function releaseNativeObject(object: NSObject) { | ||
| 144 | + __releaseNativeCounterpart(object); | ||
| 145 | + } | ||
| 146 | + | ||
| 143 | 147 | export function openUrl(location: string): boolean { | |
| 144 | 148 | try { | |
| 145 | 149 | var url = NSURL.URLWithString(location.trim()); | |
@@ -175,4 +179,4 @@ class UIDocumentInteractionControllerDelegateImpl extends NSObject implements UI | |||
| 175 | 179 | } | |
| 176 | 180 | } | |
| 177 | 181 | ||
| 178 | - mainScreenScale = ios.getter(UIScreen, UIScreen.mainScreen).scale; | ||
| 182 | + mainScreenScale = ios.getter(UIScreen, UIScreen.mainScreen).scale; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,10 +3,16 @@ | |||
| 3 | 3 | declare function float(num: number): any; | |
| 4 | 4 | declare function long(num: number): any; | |
| 5 | 5 | ||
| 6 | + /** | ||
| 7 | + * Triggers garbage collection in JavaScript | ||
| 8 | + */ | ||
| 6 | 9 | declare var gc: () => void; | |
| 7 | 10 | ||
| 8 | - declare function float(num: number): any; | ||
| 9 | - declare function long(num: number): any; | ||
| 11 | + /** | ||
| 12 | + * Releases the reference to the wrapped native object | ||
| 13 | + * @param object The Java object to release. | ||
| 14 | + */ | ||
| 15 | + declare function __releaseNativeCounterpart(object: java.lang.Object): void; | ||
| 10 | 16 | ||
| 11 | 17 | interface ArrayConstructor { | |
| 12 | 18 | create(type: any, count: number): any; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,4 @@ | |||
| 1 | - /// <reference path="interop.d.ts" /> | ||
| 1 | + /// <reference path="runtime.d.ts" /> | ||
| 2 | 2 | /// <reference path="objc-x86_64/objc!ARKit.d.ts" /> | |
| 3 | 3 | /// <reference path="objc-x86_64/objc!AVFoundation.d.ts" /> | |
| 4 | 4 | /// <reference path="objc-x86_64/objc!AVKit.d.ts" /> | |
@@ -126,4 +126,3 @@ | |||
| 126 | 126 | /// <reference path="objc-x86_64/objc!os_object.d.ts" /> | |
| 127 | 127 | /// <reference path="objc-x86_64/objc!simd.d.ts" /> | |
| 128 | 128 | /// <reference path="objc-x86_64/objc!zlib.d.ts" /> | |
| 129 | - declare function __collect(): void; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,17 @@ | |||
| 1 | + /// <reference path="interop.d.ts" /> | ||
| 2 | + | ||
| 3 | + /** | ||
| 4 | + * Triggers garbage collection in JavaScript | ||
| 5 | + */ | ||
| 6 | + declare function __collect(): void; | ||
| 7 | + | ||
| 8 | + /** | ||
| 9 | + * Releases the reference to the wrapped native object | ||
| 10 | + * @param object The Objective-C object to release. | ||
| 11 | + */ | ||
| 12 | + declare function __releaseNativeCounterpart(object: NSObject): void; | ||
| 13 | + | ||
| 14 | + /** | ||
| 15 | + * Gets accurate system timestamp in ms. | ||
| 16 | + */ | ||
| 17 | + declare function __time(): Number; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -42,11 +42,11 @@ mv ios-typings-prj/typings/x86_64/* ios/objc-x86_64/ | |||
| 42 | 42 | ||
| 43 | 43 | echo "Emitting (ios/ios.d.ts)..." | |
| 44 | 44 | pushd ios | |
| 45 | - echo '/// <reference path="interop.d.ts" />' > ios.d.ts | ||
| 45 | + | ||
| 46 | + echo '/// <reference path="runtime.d.ts" />' > ios.d.ts | ||
| 46 | 47 | ||
| 47 | 48 | for i in `ls objc-x86_64/*.d.ts`; do | |
| 48 | 49 | echo "/// <reference path=\"$i\" />" >> ios.d.ts | |
| 49 | 50 | done | |
| 50 | 51 | ||
| 51 | - echo 'declare function __collect(): void;' >> ios.d.ts | ||
| 52 | 52 | popd | |
| Back | FazBrowse Home | New Git URL |
0 commit comments