From c946c24ae23a6af8d624e6cfba17d41d4b473aab Mon Sep 17 00:00:00 2001 From: atanasovg Date: Thu, 15 May 2014 16:13:33 +0300 Subject: [PATCH] Renamed image module to image-source. Extended the testRunner to accept module name to run. --- BCL.csproj | 20 +++++------ Tests/http-tests.ts | 2 +- Tests/image-tests.ts | 18 +++++----- Tests/testRunner.ts | 26 ++++++++------ file-system/index.ts | 2 +- http/http-request.android.ts | 2 +- http/http-request.d.ts | 4 +-- http/http-request.ios.ts | 2 +- http/http.ts | 6 ++-- {image => image-source}/Readme.md | 4 +-- .../image-source-native.android.ts | 0 .../image-source-native.d.ts | 0 .../image-source-native.ios.ts | 0 .../image-source.d.ts | 22 ++++++------ .../image.ts => image-source/image-source.ts | 34 +++++++++---------- image-source/index.ts | 2 ++ image/index.ts | 2 -- 17 files changed, 75 insertions(+), 71 deletions(-) rename {image => image-source}/Readme.md (57%) rename image/image-native.android.ts => image-source/image-source-native.android.ts (100%) rename image/image-native.d.ts => image-source/image-source-native.d.ts (100%) rename image/image-native.ios.ts => image-source/image-source-native.ios.ts (100%) rename image/image.d.ts => image-source/image-source.d.ts (73%) rename image/image.ts => image-source/image-source.ts (69%) create mode 100644 image-source/index.ts delete mode 100644 image/index.ts diff --git a/BCL.csproj b/BCL.csproj index 988af8b4f..4eb71cf05 100644 --- a/BCL.csproj +++ b/BCL.csproj @@ -110,18 +110,18 @@ - - image-native.d.ts + + image-source-native.d.ts - - image-native.d.ts + + image-source-native.d.ts - - image.d.ts + + + + image-source.d.ts - - - + location.d.ts @@ -188,7 +188,7 @@ http-request.d.ts - + diff --git a/Tests/http-tests.ts b/Tests/http-tests.ts index 638d089c9..957b23923 100644 --- a/Tests/http-tests.ts +++ b/Tests/http-tests.ts @@ -121,7 +121,7 @@ export var test_getImage = function () { // TKUnit.waitUntilReady(isReady, 3); - TKUnit.assert(result instanceof require("image").Image, "Result from getImage() should be valid Image object!"); + TKUnit.assert(result instanceof require("image-source").ImageSource, "Result from getImage() should be valid ImageSource object!"); }; export var test_getImage_fail = function () { diff --git a/Tests/image-tests.ts b/Tests/image-tests.ts index 70437d6b4..b3f4941c3 100644 --- a/Tests/image-tests.ts +++ b/Tests/image-tests.ts @@ -1,19 +1,19 @@ -import image = require("image/image"); +import imageSource = require("image-source/image-source"); import app = require("application/application"); import fs = require("file-system/file-system"); import TKUnit = require("Tests/TKUnit"); export var testFromResource = function () { - var img = image.fromResource(getTestImageName()); + var img = imageSource.fromResource(getTestImageName()); TKUnit.assert(img.height > 0, "image.fromResource failed"); } export var testFromUrl = function () { var completed; - var result: image.Image; + var result: imageSource.ImageSource; - image.fromUrl("http://www.google.com/images/errors/logo_sm_2.png") - .then(function (res: image.Image) { + imageSource.fromUrl("http://www.google.com/images/errors/logo_sm_2.png") + .then(function (res: imageSource.ImageSource) { completed = true; result = res; }) @@ -31,11 +31,11 @@ export var testFromUrl = function () { } export var testSaveToFile = function () { - var img = image.fromResource(getTestImageName()); + var img = imageSource.fromResource(getTestImageName()); var folder = fs.knownFolders.documents(); var path = fs.path.join(folder.path, "Test.png"); - var saved = img.saveToFile(path, image.ImageFormat.PNG); + var saved = img.saveToFile(path, imageSource.ImageFormat.PNG); TKUnit.assert(saved, "Image not saved to file"); TKUnit.assert(fs.File.exists(path), "Image not saved to file"); } @@ -44,7 +44,7 @@ export var testFromFile = function () { var folder = fs.knownFolders.documents(); var path = fs.path.join(folder.path, "Test.png"); - var img = image.fromFile(path); + var img = imageSource.fromFile(path); TKUnit.assert(img.height > 0, "image.fromResource failed"); @@ -55,7 +55,7 @@ export var testFromFile = function () { } export var testNativeFields = function () { - var img = image.fromResource(getTestImageName()); + var img = imageSource.fromResource(getTestImageName()); if (app.android) { TKUnit.assert(img.android != null, "Image.android not updated."); } else if (app.ios) { diff --git a/Tests/testRunner.ts b/Tests/testRunner.ts index 02e7002ac..fa360024d 100644 --- a/Tests/testRunner.ts +++ b/Tests/testRunner.ts @@ -1,14 +1,18 @@ var TKUnit = require("Tests/TKUnit"); -var fsTests = require("Tests/file-system-tests"); -var httpTests = require("Tests/http-tests"); -var locationTests = require("Tests/location-tests"); -var localSettingsTests = require("Tests/local-settings-tests"); -var imageTests = require("Tests/image-tests"); -export var runAll = function () { - TKUnit.runTestModule(imageTests, "IMAGE"); - TKUnit.runTestModule(fsTests, "FILE SYSTEM"); - TKUnit.runTestModule(httpTests, "HTTP"); - TKUnit.runTestModule(locationTests, "LOCATION"); - TKUnit.runTestModule(localSettingsTests, "LOCAL SETTINGS"); +var allTests = {}; +allTests["FILE SYSTEM"] = require("Tests/file-system-tests"); +allTests["HTTP"] = require("Tests/http-tests"); +allTests["LOCATION"] = require("Tests/location-tests"); +allTests["LOCAL SETTINGS"] = require("Tests/local-settings-tests"); +allTests["IMAGE SOURCE"] = require("Tests/image-tests"); + +export var runAll = function (moduleName?: string) { + for (var name in allTests) { + if(moduleName && (moduleName.toLowerCase() !== name.toLowerCase())) { + continue; + } + + TKUnit.runTestModule(allTests[name], name); + } } diff --git a/file-system/index.ts b/file-system/index.ts index bf898499f..af5098c9b 100644 --- a/file-system/index.ts +++ b/file-system/index.ts @@ -1,2 +1,2 @@ declare var module, require; -module.exports = require("file-system/file_system"); \ No newline at end of file +module.exports = require("file-system/file-system"); \ No newline at end of file diff --git a/http/http-request.android.ts b/http/http-request.android.ts index d2b6f6425..1be15e2bc 100644 --- a/http/http-request.android.ts +++ b/http/http-request.android.ts @@ -25,7 +25,7 @@ export function request(options: http.HttpRequestOptions): promises.Promise { return null }, toJSON: () => { return null }, - toImage: () => { return require("image").fromNativeBitmap(data); } + toImage: () => { return require("image-source").fromNativeSource(data); } }, statusCode: 0, headers: {} diff --git a/http/http-request.d.ts b/http/http-request.d.ts index 8fc95e612..ab7233df9 100644 --- a/http/http-request.d.ts +++ b/http/http-request.d.ts @@ -1,7 +1,7 @@ /** * The http client interface. */ -import image_module = require("image/image"); +import image_module = require("image-source/image-source"); import promises = require("promises/promises"); export declare function request(options: HttpRequestOptions): promises.Promise; @@ -24,5 +24,5 @@ export interface HttpContent { raw: any; toString: () => string; toJSON: () => any; - toImage: () => image_module.Image; + toImage: () => image_module.ImageSource; } \ No newline at end of file diff --git a/http/http-request.ios.ts b/http/http-request.ios.ts index 4337178e3..1cc6bef16 100644 --- a/http/http-request.ios.ts +++ b/http/http-request.ios.ts @@ -54,7 +54,7 @@ export function request(options: http.HttpRequestOptions): promises.Promise { return NSDataToString(data); }, toJSON: () => { return JSON.parse(NSDataToString(data)); }, - toImage: () => { return require("image").fromData(data); } + toImage: () => { return require("image-source").fromData(data); } }, statusCode: response.statusCode(), headers: headers diff --git a/http/http.ts b/http/http.ts index 7fcd04cb3..5a8ec7b15 100644 --- a/http/http.ts +++ b/http/http.ts @@ -1,4 +1,4 @@ -import image_module = require("image/image"); +import image_module = require("image-source/image-source"); import promises = require("promises/promises"); import http = require("http/http-request"); @@ -37,8 +37,8 @@ export function getJSON(url: string): promises.Promise { /** * Gets image from url. */ -export function getImage(url: string): promises.Promise { - var d = promises.defer(); +export function getImage(url: string): promises.Promise { + var d = promises.defer(); http.request({ url: url, method: "GET" }) .then(r => d.resolve(r.content.toImage())) diff --git a/image/Readme.md b/image-source/Readme.md similarity index 57% rename from image/Readme.md rename to image-source/Readme.md index 731f0254c..c8c08b361 100644 --- a/image/Readme.md +++ b/image-source/Readme.md @@ -1,6 +1,6 @@ The way we get local path here is different for now. Maybe we should get it from FS module in the future samples. Sample code Android: ``` -var Image = require("image").Image; -var baseImage = Image.imageFromResource('foxie'); +var ImageSource = require("image-source").ImageSource; +var source = ImageSource.imageFromResource('foxie'); ``` diff --git a/image/image-native.android.ts b/image-source/image-source-native.android.ts similarity index 100% rename from image/image-native.android.ts rename to image-source/image-source-native.android.ts diff --git a/image/image-native.d.ts b/image-source/image-source-native.d.ts similarity index 100% rename from image/image-native.d.ts rename to image-source/image-source-native.d.ts diff --git a/image/image-native.ios.ts b/image-source/image-source-native.ios.ts similarity index 100% rename from image/image-native.ios.ts rename to image-source/image-source-native.ios.ts diff --git a/image/image.d.ts b/image-source/image-source.d.ts similarity index 73% rename from image/image.d.ts rename to image-source/image-source.d.ts index b1477ff1a..04d6d3095 100644 --- a/image/image.d.ts +++ b/image-source/image-source.d.ts @@ -9,9 +9,9 @@ export declare enum ImageFormat { } /** -* Encapsulates the common abstraction behind a platform specific image object. +* Encapsulates the common abstraction behind a platform specific object (typically a Bitmap) that is used as a source for images. */ -export declare class Image { +export declare class ImageSource { /** * Gets the height of this instance. This is a read-only property. */ @@ -48,10 +48,10 @@ export declare class Image { loadFromData(data: any): boolean; /** - * Sets the provided native bitmap object. + * Sets the provided native source object (typically a Bitmap). * This will update either the android or ios properties, depending on the target os. */ - setNativeBitmap(source: any): boolean; + setNativeSource(source: any): boolean; /** * Saves this instance to the specified file, using the provided image format and quality. @@ -62,25 +62,25 @@ export declare class Image { /** * Creates a new Image instance and loads it from the specified resource name. */ -export declare function fromResource(name: string): Image; +export declare function fromResource(name: string): ImageSource; /** * Creates a new Image instance and loads it from the specified file. */ -export declare function fromFile(path: string): Image; +export declare function fromFile(path: string): ImageSource; /** * Creates a new Image instance and loads it from the specified resource name. */ -export declare function fromData(data: any): Image; +export declare function fromData(data: any): ImageSource; /** -* Creates a new Image instance and sets the provided native bitmap object. -* The native bitmap object will update either the android or ios properties, depending on the target os. +* Creates a new Image instance and sets the provided native source object (typically a Bitmap). +* The native source object will update either the android or ios properties, depending on the target os. */ -export declare function fromNativeBitmap(source: any): Image; +export declare function fromNativeSource(source: any): ImageSource; /** * Downloads the image from the provided Url and creates a new Image instance from it. */ -export declare function fromUrl(url: string): promises.Promise; \ No newline at end of file +export declare function fromUrl(url: string): promises.Promise; \ No newline at end of file diff --git a/image/image.ts b/image-source/image-source.ts similarity index 69% rename from image/image.ts rename to image-source/image-source.ts index 8893bf2ff..4340c7438 100644 --- a/image/image.ts +++ b/image-source/image-source.ts @@ -1,5 +1,5 @@ import app = require("application/application"); -import impl = require("image/image-native"); +import native = require("image-source/image-source-native"); import promises = require("promises/promises"); import http = require("http/http"); @@ -8,7 +8,7 @@ export enum ImageFormat { JPEG, } -export class Image { +export class ImageSource { public android: android.graphics.Bitmap; public ios: UIKit.UIImage; @@ -17,30 +17,30 @@ export class Image { } public loadFromResource(name: string): boolean { - var nativeInstance = impl.fromResource(name); + var nativeInstance = native.fromResource(name); this.setNativeInstance(nativeInstance); return nativeInstance != null; } public loadFromFile(path: string): boolean { - var nativeInstance = impl.fromFile(path); + var nativeInstance = native.fromFile(path); this.setNativeInstance(nativeInstance); return (nativeInstance != null); } public loadFromData(data: any): boolean { - var nativeInstance = impl.fromData(data); + var nativeInstance = native.fromData(data); this.setNativeInstance(nativeInstance); return (nativeInstance != null); } - public setNativeBitmap(source: any): boolean { + public setNativeSource(source: any): boolean { this.setNativeInstance(source); return source != null; } public saveToFile(path: string, format: ImageFormat, quality?: number): boolean { - return impl.saveToFile(this.getNativeInstance(), path, format, quality); + return native.saveToFile(this.getNativeInstance(), path, format, quality); } get height(): number { @@ -85,26 +85,26 @@ export class Image { } } -export function fromResource(name: string): Image { - var image = new Image(); +export function fromResource(name: string): ImageSource { + var image = new ImageSource(); return image.loadFromResource(name) ? image : null; } -export function fromFile(path: string): Image { - var image = new Image(); +export function fromFile(path: string): ImageSource { + var image = new ImageSource(); return image.loadFromFile(path) ? image : null; } -export function fromData(data: any): Image { - var image = new Image(); +export function fromData(data: any): ImageSource { + var image = new ImageSource(); return image.loadFromData(data) ? image : null; } -export function fromNativeBitmap(source: any): Image { - var image = new Image(); - return image.setNativeBitmap(source) ? image : null; +export function fromNativeSource(source: any): ImageSource { + var image = new ImageSource(); + return image.setNativeSource(source) ? image : null; } -export function fromUrl(url: string): promises.Promise { +export function fromUrl(url: string): promises.Promise { return http.getImage(url); } \ No newline at end of file diff --git a/image-source/index.ts b/image-source/index.ts new file mode 100644 index 000000000..d987e3edd --- /dev/null +++ b/image-source/index.ts @@ -0,0 +1,2 @@ +declare var module, require; +module.exports = require("image-source/image-source"); \ No newline at end of file diff --git a/image/index.ts b/image/index.ts deleted file mode 100644 index 8c7abb23f..000000000 --- a/image/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -declare var module, require; -module.exports = require("image/image"); \ No newline at end of file