aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorCui Yan <yanx.cui@intel.com>2016-12-08 08:20:12 +0800
committerJimmy Huang <jimmy.huang@linux.intel.com>2016-12-07 16:20:12 -0800
commitb36da6d1636237a12247cf253b8d57e6c0e3399f (patch)
tree496f3a3a436b43c14cf8fd095cad5ad9304f09ae /modules
parent7f1fd812a8241490b379f9f6a534387993e2db15 (diff)
[tests] Add tests for UART APIs (#507)
Diffstat (limited to 'modules')
-rw-r--r--modules/Assert.js74
1 files changed, 74 insertions, 0 deletions
diff --git a/modules/Assert.js b/modules/Assert.js
new file mode 100644
index 0000000..945d67f
--- /dev/null
+++ b/modules/Assert.js
@@ -0,0 +1,74 @@
+// Copyright (c) 2016, Intel Corporation.
+
+// JavaScript library for the tests case
+
+function Assert() {
+
+ // API object
+ var assert = {};
+
+ assert.total = 0;
+ assert.pass = 0;
+
+ assert.true = function (actual, description) {
+ if (typeof actual !== "boolean" ||
+ typeof description !== "string") {
+ console.log("AssertionError: invalid input type given");
+ throw new Error();
+ return;
+ }
+
+ this.total++;
+
+ var label = "\033[1m\033[31mFAIL\033[0m";
+ if (actual === true) {
+ this.pass++;
+ label = "\033[1m\033[32mPASS\033[0m";
+ }
+
+ console.log(label + " - " + description);
+ }
+
+ assert.equal = function (argA, argB, description) {
+ if (typeof argA !== "object" ||
+ typeof argA === "undefined" ||
+ typeof argB !== "object" ||
+ typeof argB === "undefined" ||
+ typeof description !== "string") {
+ console.log("AssertionError: invalid input type given");
+ throw new Error();
+ return;
+ }
+
+ this.true(argA === argB, description);
+ }
+
+ assert.throws = function (description, func) {
+ if (typeof description !== "string" ||
+ typeof func !== "function") {
+ console.log("AssertionError: invalid input type given");
+ throw new Error();
+ return;
+ }
+
+ var booleanValue = false;
+
+ try {
+ func();
+ }
+ catch (err) {
+ booleanValue = true;
+ }
+
+ this.true(booleanValue, description);
+ }
+
+ assert.result = function () {
+ console.log("TOTAL: " + this.pass + " of "
+ + this.total + " passed");
+ }
+
+ return assert;
+};
+
+module.exports.Assert = new Assert();