1
1
#![ cfg_attr( windows, feature( abi_vectorcall) ) ]
2
2
extern crate ext_php_rs;
3
3
4
+ #[ cfg( feature = "embed" ) ]
5
+ use std:: ffi:: c_char;
4
6
#[ cfg( feature = "embed" ) ]
5
7
use ext_php_rs:: builders:: SapiBuilder ;
6
8
#[ cfg( feature = "embed" ) ]
@@ -14,10 +16,29 @@ use ext_php_rs::prelude::*;
14
16
#[ cfg( feature = "embed" ) ]
15
17
use ext_php_rs:: zend:: try_catch;
16
18
19
+ #[ cfg( feature = "embed" ) ]
20
+ static mut LAST_OUTPUT : String = String :: new ( ) ;
21
+
22
+ #[ cfg( feature = "embed" ) ]
23
+ extern "C" fn output_tester ( str : * const c_char , str_length : usize ) -> usize {
24
+ let char = unsafe { std:: slice:: from_raw_parts ( str as * const u8 , str_length) } ;
25
+ let string = String :: from_utf8_lossy ( char) ;
26
+
27
+ println ! ( "{}" , string) ;
28
+
29
+ unsafe {
30
+ LAST_OUTPUT = string. to_string ( ) ;
31
+ } ;
32
+
33
+ str_length
34
+ }
35
+
17
36
#[ test]
18
37
#[ cfg( feature = "embed" ) ]
19
38
fn test_sapi ( ) {
20
- let builder = SapiBuilder :: new ( "test" , "Test" ) ;
39
+ let mut builder = SapiBuilder :: new ( "test" , "Test" ) ;
40
+ builder = builder. ub_write_function ( output_tester) ;
41
+
21
42
let sapi = builder. build ( ) . unwrap ( ) . into_raw ( ) ;
22
43
let module = get_module ( ) ;
23
44
@@ -50,6 +71,10 @@ fn test_sapi() {
50
71
let string = zval. string ( ) . unwrap ( ) ;
51
72
52
73
assert_eq ! ( string. to_string( ) , "Hello, foo!" ) ;
74
+
75
+ let result = Embed :: eval ( "var_dump($foo);" ) ;
76
+
77
+ assert ! ( result. is_ok( ) ) ;
53
78
} ,
54
79
true ,
55
80
) ;
@@ -58,6 +83,10 @@ fn test_sapi() {
58
83
php_request_shutdown ( std:: ptr:: null_mut ( ) ) ;
59
84
}
60
85
86
+ unsafe {
87
+ assert_eq ! ( LAST_OUTPUT , "string(11) \" Hello, foo!\" \n " ) ;
88
+ }
89
+
61
90
unsafe {
62
91
php_module_shutdown ( ) ;
63
92
}
0 commit comments