Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion test/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import re
import shlex
import shutil
import struct
import subprocess
import time
import zlib
Expand Down Expand Up @@ -70,8 +71,9 @@

from tools import ports, shared
from tools.feature_matrix import Feature
from tools.link import binary_encode
from tools.shared import EMCC, FILE_PACKAGER, PIPE
from tools.utils import WINDOWS, delete_dir
from tools.utils import WINDOWS, delete_dir, write_binary, write_file


def make_test_chunked_synchronous_xhr_server(support_byte_ranges, data, port):
Expand Down Expand Up @@ -5582,6 +5584,30 @@ def end_headers(self):
server.stop()
server.join()

# Tests encoding of all byte pairs for binary encoding in SINGLE_FILE mode.
@parameterized({
'': ('',),
'strict': ('"use strict";',),
})
def test_binary_encode(self, extra):
# Encode values 0 .. 65535 into test data
test_data = bytearray(struct.pack('<' + 'H' * 65536, *range(65536)))
write_binary('data.tmp', test_data)
binary_encoded = binary_encode('data.tmp')

write_file('test.html', '''<!DOCTYPE html><html><head><meta charset="utf-8"></head><body><script>
''' + extra + '\n' + read_file(path_from_root('src/binaryDecode.js')) + '''
var src = ''' + binary_encoded + ''';
var u16 = new Uint16Array(binaryDecode(src).buffer);
for(var i = 0; i < 65536; ++i)
if (u16[i] != i) throw i;
console.log('OK');
fetch('report_result?exit:0');
</script></body></html>
''')

self.run_browser('test.html', '/report_result?exit:0')


class emrun(RunnerCore):
def test_emrun_info(self):
Expand Down
9 changes: 7 additions & 2 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -15198,12 +15198,17 @@ def test_linkable_relocatable(self):
self.do_run_in_out_file_test('hello_world.c', cflags=['-Wno-deprecated', '-sLINKABLE', '-sRELOCATABLE'])

# Tests encoding of all byte pairs for binary encoding in SINGLE_FILE mode.
def test_binary_encode(self):
@parameterized({
'': ('',),
'strict': ('"use strict";',),
})
def test_binary_encode(self, extra):
# Encode values 0 .. 65535 into test data
test_data = bytearray(struct.pack('<' + 'H' * 65536, *range(65536)))
write_binary('data.tmp', test_data)
binary_encoded = binary_encode('data.tmp')
test_js = '''var u16 = new Uint16Array(binaryDecode(src).buffer);
test_js = extra + '''
var u16 = new Uint16Array(binaryDecode(src).buffer);
for(var i = 0; i < 65536; ++i)
if (u16[i] != i) throw i;
console.log('OK');'''
Expand Down
Loading