aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/cases/redundantswitch_fastcomp.ll28
-rw-r--r--tests/cases/redundantswitch_fastcomp.txt2
-rw-r--r--tests/core/test_sscanf_hex.in24
-rw-r--r--tests/core/test_sscanf_hex.out3
-rw-r--r--tests/embind/embind.test.js15
-rw-r--r--tests/embind/embind_test.cpp5
-rw-r--r--tests/test_core.py3
-rw-r--r--tests/test_other.py5
8 files changed, 81 insertions, 4 deletions
diff --git a/tests/cases/redundantswitch_fastcomp.ll b/tests/cases/redundantswitch_fastcomp.ll
new file mode 100644
index 00000000..5b797ac8
--- /dev/null
+++ b/tests/cases/redundantswitch_fastcomp.ll
@@ -0,0 +1,28 @@
+target datalayout = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-p:32:32:32-v128:32:128-n32-S128"
+target triple = "asmjs-unknown-emscripten"
+
+@.str = private constant [18 x i8] c"hello, world: %d\0A\00", align 1
+
+declare i32 @printf(i8*, ...)
+
+define linkonce_odr i32 @main() align 2 {
+entry:
+ %temp32 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([18 x i8]* @.str, i32 0, i32 0), i32 5)
+ switch i32 %temp32, label %mid1 [
+ i32 1000, label %mid1
+ i32 1001, label %mid2
+ i32 2000, label %finish
+ ]
+
+mid1:
+ br label %finish
+
+mid2:
+ br label %finish
+
+finish: ; preds = %555
+ %last = phi i32 [0, %entry], [1, %mid1], [2, %mid2]
+ %a333c = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([18 x i8]* @.str, i32 0, i32 0), i32 %last)
+ ret i32 0
+}
+
diff --git a/tests/cases/redundantswitch_fastcomp.txt b/tests/cases/redundantswitch_fastcomp.txt
new file mode 100644
index 00000000..72084b0c
--- /dev/null
+++ b/tests/cases/redundantswitch_fastcomp.txt
@@ -0,0 +1,2 @@
+hello, world: 5
+hello, world: 1
diff --git a/tests/core/test_sscanf_hex.in b/tests/core/test_sscanf_hex.in
index d8175e82..a05eb890 100644
--- a/tests/core/test_sscanf_hex.in
+++ b/tests/core/test_sscanf_hex.in
@@ -1,7 +1,27 @@
-#include "stdio.h"
+#include <stdio.h>
+#include <string>
+#include <cstdlib>
-int main() {
+int main()
+{
unsigned int a, b;
sscanf("0x12AB 12AB", "%x %x", &a, &b);
printf("%d %d\n", a, b);
+
+ std::string hexstr("0102037F00FF");
+ const char * cstr = hexstr.c_str();
+ int len = hexstr.length() / 2;
+ char * tmp_data = new char[len];
+ for(int i = 0; i < len; i++)
+ {
+ sscanf(cstr, "%2hhx", &tmp_data[i]);
+ cstr += 2 * sizeof(char);
+ }
+
+ for (int j = 0; j < len; j++)
+ printf("%i, ", tmp_data[j]);
+ printf("\n");
+ delete[] tmp_data;
}
+
+
diff --git a/tests/core/test_sscanf_hex.out b/tests/core/test_sscanf_hex.out
index ac855044..6e7f66aa 100644
--- a/tests/core/test_sscanf_hex.out
+++ b/tests/core/test_sscanf_hex.out
@@ -1 +1,2 @@
-4779 4779 \ No newline at end of file
+4779 4779
+1, 2, 3, 127, 0, -1,
diff --git a/tests/embind/embind.test.js b/tests/embind/embind.test.js
index 6bba4de0..3ded811a 100644
--- a/tests/embind/embind.test.js
+++ b/tests/embind/embind.test.js
@@ -442,6 +442,21 @@ module({
var e = cm.emval_test_take_and_return_std_string((new Int8Array([65, 66, 67, 68])).buffer);
assert.equal('ABCD', e);
});
+
+ test("can pass Uint8Array to std::basic_string<unsigned char>", function() {
+ var e = cm.emval_test_take_and_return_std_basic_string_unsigned_char(new Uint8Array([65, 66, 67, 68]));
+ assert.equal('ABCD', e);
+ });
+
+ test("can pass Int8Array to std::basic_string<unsigned char>", function() {
+ var e = cm.emval_test_take_and_return_std_basic_string_unsigned_char(new Int8Array([65, 66, 67, 68]));
+ assert.equal('ABCD', e);
+ });
+
+ test("can pass ArrayBuffer to std::basic_string<unsigned char>", function() {
+ var e = cm.emval_test_take_and_return_std_basic_string_unsigned_char((new Int8Array([65, 66, 67, 68])).buffer);
+ assert.equal('ABCD', e);
+ });
test("non-ascii wstrings", function() {
var expected = String.fromCharCode(10) +
diff --git a/tests/embind/embind_test.cpp b/tests/embind/embind_test.cpp
index 1b835751..5a83903a 100644
--- a/tests/embind/embind_test.cpp
+++ b/tests/embind/embind_test.cpp
@@ -109,6 +109,10 @@ std::string emval_test_take_and_return_std_string_const_ref(const std::string& s
return str;
}
+std::basic_string<unsigned char> emval_test_take_and_return_std_basic_string_unsigned_char(std::basic_string<unsigned char> str) {
+ return str;
+}
+
std::wstring take_and_return_std_wstring(std::wstring str) {
return str;
}
@@ -1446,6 +1450,7 @@ EMSCRIPTEN_BINDINGS(tests) {
//function("emval_test_take_and_return_const_char_star", &emval_test_take_and_return_const_char_star);
function("emval_test_take_and_return_std_string", &emval_test_take_and_return_std_string);
function("emval_test_take_and_return_std_string_const_ref", &emval_test_take_and_return_std_string_const_ref);
+ function("emval_test_take_and_return_std_basic_string_unsigned_char", &emval_test_take_and_return_std_basic_string_unsigned_char);
function("take_and_return_std_wstring", &take_and_return_std_wstring);
//function("emval_test_take_and_return_CustomStruct", &emval_test_take_and_return_CustomStruct);
diff --git a/tests/test_core.py b/tests/test_core.py
index c9784ec9..cf2730d0 100644
--- a/tests/test_core.py
+++ b/tests/test_core.py
@@ -3905,6 +3905,8 @@ Pass: 0.000012 0.000012''')
self.do_run_from_file(src, output)
def test_sscanf_hex(self):
+ if Settings.USE_TYPED_ARRAYS != 2: return self.skip('requires ta2')
+
test_path = path_from_root('tests', 'core', 'test_sscanf_hex')
src, output = (test_path + s for s in ('.in', '.out'))
@@ -5662,7 +5664,6 @@ def process(filename):
def test_embind_2(self):
if self.emcc_args is None: return self.skip('requires emcc')
- if self.run_name == 'asm2f': return self.skip('embind/asm.js not compatible with PRECISE_F32 because it changes signature strings')
if self.run_name == 'slow2asm': return self.skip('embind/asm.js requires fastcomp')
Building.COMPILER_TEST_OPTS += ['--bind', '--post-js', 'post.js']
open('post.js', 'w').write('''
diff --git a/tests/test_other.py b/tests/test_other.py
index 0721bb35..4560ac6e 100644
--- a/tests/test_other.py
+++ b/tests/test_other.py
@@ -2380,6 +2380,11 @@ int main() {
err = Popen([PYTHON, EMCC, 'src.cpp', '-include', 'header.h', '-Xclang', '-print-stats'], stderr=PIPE).communicate()
assert '*** PCH/Modules Loaded:\nModule: header.h.gch' not in err[1], err[1]
+ # with specified target via -o
+ try_delete('header.h.gch')
+ Popen([PYTHON, EMCC, '-xc++-header', 'header.h', '-o', 'my.gch']).communicate()
+ assert os.path.exists('my.gch')
+
def test_warn_unaligned(self):
if os.environ.get('EMCC_FAST_COMPILER') == '0': return self.skip('need fastcomp')
open('src.cpp', 'w').write(r'''