[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [flashproxy/js] Add the beginning of a unit test program for flashproxy.js.
commit 41750ae520ce1f9994dc74800605d6e92d085361
Author: David Fifield <david@xxxxxxxxxxxxxxx>
Date: Mon Mar 12 09:57:32 2012 -0700
Add the beginning of a unit test program for flashproxy.js.
I run this using Rhino, which is "apt-get install rhino" on Debian.
---
Makefile | 5 ++-
flashproxy-test.js | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++
flashproxy.js | 5 ++
3 files changed, 115 insertions(+), 1 deletions(-)
diff --git a/Makefile b/Makefile
index 7f6e02e..0fb0c79 100644
--- a/Makefile
+++ b/Makefile
@@ -19,4 +19,7 @@ install:
clean:
rm -f $(TARGETS)
-.PHONY: all clean
+test:
+ ./flashproxy-test.js
+
+.PHONY: all clean test
diff --git a/flashproxy-test.js b/flashproxy-test.js
new file mode 100755
index 0000000..21ae756
--- /dev/null
+++ b/flashproxy-test.js
@@ -0,0 +1,106 @@
+#!/usr/bin/js
+
+/* To run this test program, install the Rhino JavaScript interpreter
+ (apt-get install rhino). */
+
+var num_tests = 0;
+var num_failed = 0;
+
+load("flashproxy.js");
+
+function objects_equal(a, b)
+{
+ if (typeof a != typeof b)
+ return false;
+ if (typeof a != "object")
+ return a == b;
+
+ for (var k in a) {
+ if (!objects_equal(a[k], b[k]))
+ return false;
+ }
+ for (var k in b) {
+ if (!objects_equal(a[k], b[k]))
+ return false;
+ }
+
+ return true;
+}
+
+function quote(s)
+{
+ return "\"" + s.replace(/([\\\"])/, "\\$1") + "\"";
+}
+
+function maybe_quote(s)
+{
+ if (/[\\\"]/.test(s))
+ return quote(s);
+ else
+ return s;
+}
+
+function repr(x)
+{
+ if (typeof x === null) {
+ return "null";
+ } else if (typeof x == "undefined") {
+ return "undefined";
+ } else if (typeof x == "object") {
+ var elems = [];
+ for (var k in x)
+ elems.push(maybe_quote(k) + ": " + repr(x[k]));
+ return "{ " + elems.join(", ") + " }";
+ } else if (typeof x == "string") {
+ return quote(x);
+ } else {
+ return x.toString();
+ }
+}
+
+function pass(test)
+{
+ num_tests++;
+ print("PASS " + repr(test));
+}
+
+function fail(test, expected, actual)
+{
+ num_tests++;
+ num_failed++;
+ print("FAIL " + repr(test) + " expected: " + repr(expected) + " actual: " + repr(actual));
+}
+
+function test_parse_query_string()
+{
+ var TESTS = [
+ { qs: "",
+ expected: { } },
+ { qs: "a=b",
+ expected: { a: "b" } },
+ { qs: "a=b=c",
+ expected: { a: "b=c" } },
+ { qs: "a=b&c=d",
+ expected: { a: "b", c: "d" } },
+ { qs: "client=&relay=1.2.3.4%3A9001",
+ expected: { client: "", relay: "1.2.3.4:9001" } },
+ ];
+
+ for (var i = 0; i < TESTS.length; i++) {
+ var test = TESTS[i];
+ var actual;
+
+ actual = parse_query_string(test.qs);
+ if (objects_equal(actual, test.expected))
+ pass(test.qs);
+ else
+ fail(test.qs, test.expected, actual);
+ }
+}
+
+test_parse_query_string();
+
+if (num_failed == 0)
+ quit(0);
+else
+ quit(1);
diff --git a/flashproxy.js b/flashproxy.js
index 7bab9e9..e4c7319 100644
--- a/flashproxy.js
+++ b/flashproxy.js
@@ -3,6 +3,11 @@ var DEFAULT_FACILITATOR_ADDR = {
port: 9002
};
+function parse_query_string(qs)
+{
+ return {};
+}
+
function format_addr(addr)
{
return addr.host + ":" + addr.port;
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits