Location: PHPKode > projects > HessianPHP > HessianPHP/unit_test/csharp.php
<?php

include_once('../dist/HessianClient.php');
include_once 'DisplayFilter.php';

function debugVar($var){
	echo '<pre>';
	var_dump($var);
	echo '</pre>';
}

function getmicrotime() 
{ 
    list($usec, $sec) = explode(" ", microtime()); 
    return ((float)$usec + (float)$sec); 
} 

class ParamObject{
	var $test = 'Hola hessian';
	var $stringVar = 'vaca';
	var $hashVar;
}

$url = 'http://localhost:81/HESSIAN/HesC/HessianService.hessian';

$options = array(
'out_stream_file'=>'out_net.bin',
'in_stream_file'=>'in_net.bin',
'dump_mode'=>'append',
'dump_detail'=>'advanced',
'methods'=>'testStringToBoolean
,testConcatString
,testStringToLong
,testStringToDouble
,testStringToShort
,testStringToInt
,testStringToFloat
,testStringToByte
,testIntToString
,testDoubleToString
,testBoolToString
,testCharToString
,testIntArrToString
,testStringArrToInt
,testDoubleArrToString
,testStringArrToDouble
,testHashMap
,testHashMapParam
,testParamObject
,testSendParamObject
,testReceiveParamObject
,testArrayListParam
,testArrayList
,testList
,testStringToDate
,testDateToString',
'filters'=>
	array(
		'display'=>new SimpleDisplayFilter(),
	)
);

// es necesario mapear el tipo si se quiere que sea correcto, TODO cambiar a algo mas generico como que coja lo ultimo del nombre
Hessian::mapRemoteType('hessiancsharp.test.ParamObject','ParamObject');

Hessian::errorReporting(HESSIAN_SILENT);
Hessian::addFilter(new LogFilter());
Hessian::addFilter(new StreamDumpFilter());
$start_time = getmicrotime();
$proxy = &new HessianClient($url, $options );

/* NOTES:
 - Double and float from string: PHP and Java use '.' for decimal separator while .net only worked using ','
 - Array functions: seems to work with mixed content in the array
 - HashMaps: .net seems to switch the order of the keys in the map
 - Date: Internal .net handling is done different from Java and PHP, the timestamps just don't match
		 Needs to do more testing with GMT differences, day light saving and more time issues
*/

debugVar( $proxy->testConcatString("hello"," hessianphp") );
debugVar( $proxy->testStringToLong('5124567855432488') );
debugVar( $proxy->testStringToBoolean('true') );  // fails with other values, works only with 'true' and 'false'
debugVar( $proxy->testStringToDouble('545,54') ); // Different format for .net
debugVar( $proxy->testStringToShort('17') );
debugVar( $proxy->testStringToInt('17') );
debugVar( $proxy->testStringToFloat('0,333333') ); // Different format for .net
debugVar( $proxy->testStringToByte("01") ); // Just works with integers and returns integers
debugVar( $proxy->testIntToString(83) );
debugVar( $proxy->testDoubleToString(123.4) );
debugVar( $proxy->testBoolToString(true) );
debugVar( $proxy->testCharToString(65) ); // the ascii code of the char

debugVar( $proxy->testIntArrToString(array(1,2,3,4)) ); 
debugVar( $proxy->testStringArrToInt(array('1',2,'3',4)) ); // only integers or mixed strings/integers
debugVar( $proxy->testDoubleArrToString(array(0.1,0.2,0.3,5.4)) ); 
debugVar( $proxy->testStringArrToDouble(array(0.1,'0,2',0.3,'5,4')) ); // same as above
debugVar( $proxy->testHashMap(array('A','B','C'), array(1,2,3)) ); // switches order of indexes
debugVar( $proxy->testHashMapParam(array('A' => 1,'B'=>2,'C'=>3)) ); // same as above

debugVar( $proxy->testParamObject(null) );
debugVar( $proxy->testParamObject(new ParamObject()) );
debugVar( $proxy->testSendParamObject(new ParamObject()) );

debugVar( $proxy->testReceiveParamObject('burr') );

debugVar( $proxy->testArrayListParam(array(1,2,3,4,5)) ); // as arraylist
debugVar( $proxy->testArrayList(array(1,'2',3,4.5,5)) ); // doesn't seem to care what I send in the array
debugVar( $proxy->testList(array(1,'2')) ); // as IList (.net) / List (Java)
debugVar( $proxy->testList(array()) ); // as IList (.net) / List (Java)

$ts = $proxy->testStringToDate('2005-12-27 20:30:15');
debugVar( $ts ); // Datetime object

debugVar( $proxy->testDateToString(new DateTime('1998-05-08 02:51:31')) ); // .NET: Returns incorrect information

echo ('<hr>Done in: '.(getmicrotime()-$start_time).' seconds');

echo '<hr><b>LogFilter dump</b>';
debugVar( LogFilter::getMessages() );

if(Hessian::error()){
	$error = Hessian::error();
	echo '<h2>ERROR</h2>';
	debugVar( $error->message);
	echo '<pre>';
	echo $error->__toString();
	echo '</pre>';
	if($error->stream)
		echo $error->stream;
}

?>
Return current item: HessianPHP