aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/hello_world.js92
-rw-r--r--tests/sockets/test_getprotobyname.c87
-rw-r--r--tests/test_other.py14
-rw-r--r--tests/test_sockets.py3
4 files changed, 104 insertions, 92 deletions
diff --git a/tests/hello_world.js b/tests/hello_world.js
deleted file mode 100644
index 01082eb4..00000000
--- a/tests/hello_world.js
+++ /dev/null
@@ -1,92 +0,0 @@
-// *** Environment setup code ***
-var arguments_ = [];
-
-var ENVIRONMENT_IS_NODE = typeof process === 'object';
-var ENVIRONMENT_IS_WEB = typeof window === 'object';
-var ENVIRONMENT_IS_WORKER = typeof importScripts === 'function';
-var ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE && !ENVIRONMENT_IS_WORKER;
-
-if (ENVIRONMENT_IS_NODE) {
- // Expose functionality in the same simple way that the shells work
- // Note that we pollute the global namespace here, otherwise we break in node
- print = function(x) {
- process['stdout'].write(x + '\n');
- };
- printErr = function(x) {
- process['stderr'].write(x + '\n');
- };
-
- var nodeFS = require('fs');
-
- read = function(filename) {
- var ret = nodeFS['readFileSync'](filename).toString();
- if (!ret && filename[0] != '/') {
- filename = __dirname.split('/').slice(0, -1).join('/') + '/src/' + filename;
- ret = nodeFS['readFileSync'](filename).toString();
- }
- return ret;
- };
-
- load = function(f) {
- globalEval(read(f));
- };
-
- arguments_ = process['argv'].slice(2);
-
-} else if (ENVIRONMENT_IS_SHELL) {
- // Polyfill over SpiderMonkey/V8 differences
- if (!this['read']) {
- this['read'] = function(f) { snarf(f) };
- }
-
- if (typeof scriptArgs != 'undefined') {
- arguments_ = scriptArgs;
- } else if (typeof arguments != 'undefined') {
- arguments_ = arguments;
- }
-
-} else if (ENVIRONMENT_IS_WEB) {
- this['print'] = printErr = function(x) {
- console.log(x);
- };
-
- this['read'] = function(url) {
- var xhr = new XMLHttpRequest();
- xhr.open('GET', url, false);
- xhr.send(null);
- return xhr.responseText;
- };
-
- if (this['arguments']) {
- arguments_ = arguments;
- }
-} else if (ENVIRONMENT_IS_WORKER) {
- // We can do very little here...
-
- this['load'] = importScripts;
-
-} else {
- throw 'Unknown runtime environment. Where are we?';
-}
-
-function globalEval(x) {
- eval.call(null, x);
-}
-
-if (typeof load == 'undefined' && typeof read != 'undefined') {
- this['load'] = function(f) {
- globalEval(read(f));
- };
-}
-
-if (typeof printErr === 'undefined') {
- this['printErr'] = function(){};
-}
-
-if (typeof print === 'undefined') {
- this['print'] = printErr;
-}
-// *** Environment setup code ***
-
-print('hello, world!');
-
diff --git a/tests/sockets/test_getprotobyname.c b/tests/sockets/test_getprotobyname.c
new file mode 100644
index 00000000..571a287e
--- /dev/null
+++ b/tests/sockets/test_getprotobyname.c
@@ -0,0 +1,87 @@
+#include <assert.h>
+#include <errno.h>
+#include <netdb.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+void checkEntryByValue(char* name, int port, char** aliasArray) {
+ struct protoent* entry;
+ char** aliases;
+
+ // Perform a protocol look up by name
+ entry = getprotobyname(name);
+ assert(entry != NULL);
+
+ // Check results
+ assert(strcmp(name, entry->p_name) == 0);
+ assert(port == entry->p_proto);
+
+ aliases = entry->p_aliases;
+ for (int i = 0; aliases[i] != NULL; i++) {
+ assert(strcmp(aliases[i], aliasArray[i]) == 0);
+ }
+
+ // Perform a protocol look up by number
+ entry = getprotobynumber(port);
+ assert(entry != NULL);
+
+ // Check results
+ assert(strcmp(name, entry->p_name) == 0);
+ assert(port == entry->p_proto);
+
+ aliases = entry->p_aliases;
+ for (int i = 0; aliases[i] != NULL; i++) {
+ assert(strcmp(aliases[i], aliasArray[i]) == 0);
+ }
+}
+
+void checkEntryDatabase() {
+ struct protoent* entry;
+
+ // Don't call setprotoent() initially as getprotoent() should open the "database" if necessary.
+ entry = getprotoent();
+ assert(entry != NULL);
+ assert(strcmp("tcp", entry->p_name) == 0);
+
+ entry = getprotoent();
+ assert(entry != NULL);
+ assert(strcmp("udp", entry->p_name) == 0);
+
+ // Check that setprotoent() correctly sets the next entry to the first entry
+ setprotoent(1);
+
+ entry = getprotoent();
+ assert(entry != NULL);
+ assert(strcmp("tcp", entry->p_name) == 0);
+
+ entry = getprotoent();
+ assert(entry != NULL);
+ assert(strcmp("udp", entry->p_name) == 0);
+
+ // If we do a getprotoent() that goes past the end of the 'database' check that it returns NULL.
+ entry = getprotoent();
+ assert(entry == NULL);
+}
+
+int main() {
+ // First check getprotobyname() and getprotobynumber()
+ char* aliases[] = {"TCP"};
+ checkEntryByValue("tcp", 6, aliases);
+
+ aliases[0] = "UDP";
+ checkEntryByValue("udp", 17, aliases);
+
+ // Check that the doomsday protocol hasn't been implemented :-) ......
+ assert(getprotobyname("doomsday") == NULL);
+
+ // Now check setprotoent() and getprotoent()
+ checkEntryDatabase();
+
+ endprotoent();
+
+ puts("success");
+
+ return EXIT_SUCCESS;
+}
+
diff --git a/tests/test_other.py b/tests/test_other.py
index 5100db72..b10ae13b 100644
--- a/tests/test_other.py
+++ b/tests/test_other.py
@@ -2136,3 +2136,17 @@ int main()
assert 'test.o' in head, 'Invalid dependency target'
assert 'test.cpp' in tail and 'test.hpp' in tail, 'Invalid dependencies generated'
+ def test_quoted_js_lib_key(self):
+ open('lib.js', 'w').write(r'''
+mergeInto(LibraryManager.library, {
+ __internal_data:{
+ '<' : 0,
+ 'white space' : 1
+ },
+ printf__deps: ['__internal_data', 'fprintf']
+});
+''')
+
+ Popen([PYTHON, EMCC, path_from_root('tests', 'hello_world.cpp'), '--js-library', 'lib.js']).communicate()
+ self.assertContained('hello, world!', run_js(os.path.join(self.get_dir(), 'a.out.js')))
+
diff --git a/tests/test_sockets.py b/tests/test_sockets.py
index 1229aa70..f9dcbc68 100644
--- a/tests/test_sockets.py
+++ b/tests/test_sockets.py
@@ -228,6 +228,9 @@ class sockets(BrowserCore):
def test_gethostbyname(self):
self.do_run(open(path_from_root('tests', 'sockets', 'test_gethostbyname.c')).read(), 'success')
+ def test_getprotobyname(self):
+ self.do_run(open(path_from_root('tests', 'sockets', 'test_getprotobyname.c')).read(), 'success')
+
def test_sockets_echo(self):
sockets_include = '-I'+path_from_root('tests', 'sockets')