aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2010-10-10 15:11:25 +0200
committerMarcel Holtmann <marcel@holtmann.org>2010-10-10 15:11:25 +0200
commit9bb104f244c58247a56d2bd64d43b126ac9485ba (patch)
tree05f3d9ee8b8a1da5d47f2d0314459fce1b368941
parent15fa201e647c1f7d504a0987d89551cd5d25f61c (diff)
downloadpacrunner-9bb104f244c58247a56d2bd64d43b126ac9485ba.tar.gz
Add unit test for example PAC script testing
-rw-r--r--unit/test-mozjs.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/unit/test-mozjs.c b/unit/test-mozjs.c
index b2d9f9a..220bd7e 100644
--- a/unit/test-mozjs.c
+++ b/unit/test-mozjs.c
@@ -48,6 +48,18 @@ void pacrunner_debug(const char *format, ...)
" return \"DIRECT\";" \
"}\n"
+#define EXAMPLE_PAC \
+ "function FindProxyForURL(url, host)\n" \
+ "{\n" \
+ " var me = myIpAddress();\n" \
+ " var resolved_ip = dnsResolve(host);\n" \
+ " if (me == \"127.0.0.1\") { return \"DIRECT\"; }\n" \
+ " if (host == \"127.0.0.1\") { return \"DIRECT\"; }\n" \
+ " if (host == \"localhost\") { return \"DIRECT\"; }\n" \
+ " if (isPlainHostName(host)) { return \"DIRECT\"; }\n" \
+ " return \"PROXY proxy.example.com\";\n" \
+ "}\n"
+
static void test_single_init(void)
{
g_assert(__pacrunner_mozjs_init() == 0);
@@ -147,6 +159,25 @@ static void test_massive_execute_with_direct_pac(void)
__pacrunner_mozjs_cleanup();
}
+static void test_multiple_execute_with_example_pac(void)
+{
+ const char *result;
+ int i;
+
+ __pacrunner_mozjs_init();
+
+ g_assert(__pacrunner_mozjs_set(NULL, EXAMPLE_PAC) == 0);
+
+ for (i = 0; i < MULTIPLE_COUNT; i++) {
+ result = __pacrunner_mozjs_execute(EXAMPLE_URL, EXAMPLE_HOST);
+ g_test_message("result %d: %s\n", i, result);
+ }
+
+ __pacrunner_mozjs_clear();
+
+ __pacrunner_mozjs_cleanup();
+}
+
int main(int argc, char **argv)
{
g_test_init(&argc, &argv, NULL);
@@ -163,6 +194,8 @@ int main(int argc, char **argv)
test_multiple_execute_with_direct_pac);
g_test_add_func("/mozjs/massive-execute-with-direct-pac",
test_massive_execute_with_direct_pac);
+ g_test_add_func("/mozjs/multiple-execute-with-example-pac",
+ test_multiple_execute_with_example_pac);
return g_test_run();
}