diff --git a/BCL.csproj b/BCL.csproj
index 6c7602639..fb71a4763 100644
--- a/BCL.csproj
+++ b/BCL.csproj
@@ -138,7 +138,7 @@
-
+
diff --git a/Tests/image-tests.ts b/Tests/image-source-tests.ts
similarity index 54%
rename from Tests/image-tests.ts
rename to Tests/image-source-tests.ts
index 9e178a4b5..816d553b3 100644
--- a/Tests/image-tests.ts
+++ b/Tests/image-source-tests.ts
@@ -1,10 +1,32 @@
-import imageSource = require("image-source/image-source");
+//
+// # Image source
+// Using the image source requires the image-source module.
+// ``` JavaScript
+//var imageSource = require("image-source");
+// ```
+// The pre-required `imageSource` module is used throughout the following code snippets.
+// we also use fs module defined as follows:
+// ``` JavaScript
+//var fs = require("file-system");
+// ```
+// ## Loading and saving images
+//
+
+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 = imageSource.fromResource(getTestImageName());
+ //
+ // ### Load image using resource name
+ // this similar to loading Bitmap from `R.drawable.logo` on Android or calling `[UIImage imageNamed@"logo"]` on iOS
+ // TODO: replace getTestImageName() with "logo"
+ // ``` JavaScript
+ var img = imageSource.fromResource("logo");
+ // ```
+ //
TKUnit.assert(img.height > 0, "image.fromResource failed");
}
@@ -12,14 +34,25 @@ export var testFromUrl = function () {
var completed;
var result: imageSource.ImageSource;
+ //
+ // ### Load image from URL
+ // ``` JavaScript
imageSource.fromUrl("http://www.google.com/images/errors/logo_sm_2.png")
.then(function (res: imageSource.ImageSource) {
+ //console.log("Image successfully loaded");
+ //
completed = true;
result = res;
+ //
})
.fail(function (error) {
+ //console.log("Error loading image: " + error);
+ //
completed = true;
- });
+ //
+ });
+ // ```
+ //
var isReady = function () {
return completed;
@@ -31,21 +64,29 @@ export var testFromUrl = function () {
}
export var testSaveToFile = function () {
- var img = imageSource.fromResource(getTestImageName());
+ //
+ // ### Save image source to PNG or JPG file
+ // ``` JavaScript
+ var img = imageSource.fromResource("logo");
var folder = fs.knownFolders.documents();
var path = fs.path.join(folder.path, "Test.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");
}
export var testFromFile = function () {
+ //
+ // ### Load image from a local file
+ // ``` JavaScript
var folder = fs.knownFolders.documents();
var path = fs.path.join(folder.path, "Test.png");
-
var img = imageSource.fromFile(path);
-
+ // ```
+ //
+
TKUnit.assert(img.height > 0, "image.fromResource failed");
// remove the image from the file system
@@ -55,22 +96,10 @@ export var testFromFile = function () {
}
export var testNativeFields = function () {
- var img = imageSource.fromResource(getTestImageName());
+ var img = imageSource.fromResource("logo");
if (app.android) {
TKUnit.assert(img.android != null, "Image.android not updated.");
} else if (app.ios) {
TKUnit.assert(img.ios != null, "Image.ios not updated.");
}
}
-
-var getTestImageName = function (): string {
- if (app.ios) {
- // TODO: This expects
- return "logo";
- }
- if (app.android) {
- return "ic_launcher";
- }
-
- return "";
-}
\ No newline at end of file
diff --git a/Tests/local-settings-tests.ts b/Tests/local-settings-tests.ts
index 5185c87ac..3622efa21 100644
--- a/Tests/local-settings-tests.ts
+++ b/Tests/local-settings-tests.ts
@@ -47,7 +47,9 @@ export var testString = function () {
export var testNumber = function () {
//
- // ### Set and get numeric value. We use toFixed() here in order to avoid number based errors
+ // ### Set and get numeric value.
+ // We use `toFixed()` here in order to avoid floating point errors - ex: `54.321` becoming `54.320999999537`.
+ // Beware the result of `toFixed()` is a string not a number therefore you cannot use `===` or `!==` when comparing with a number.
// ``` JavaScript
LocalSettings.setNumber("numberKey", 54.321);
var value = LocalSettings.getNumber("numberKey").toFixed(3);
diff --git a/Tests/testRunner.ts b/Tests/testRunner.ts
index 9f93ac5ac..90d7dd0c6 100644
--- a/Tests/testRunner.ts
+++ b/Tests/testRunner.ts
@@ -6,7 +6,7 @@ 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");
+allTests["IMAGE SOURCE"] = require("Tests/image-source-tests");
allTests["TIMER"] = require("Tests/timer-tests");
export var runAll = function (moduleName?: string) {