forked from derickr/quickhash
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added QuickHash::loadFromString().
SVN Rev: 531
- Loading branch information
Showing
4 changed files
with
177 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
--TEST-- | ||
Test for failure conditions for loadFromString. | ||
--INI-- | ||
extension=quickhash.so | ||
xdebug.default_enable=0 | ||
--FILE-- | ||
<?php | ||
echo "\nWrong params: \n"; | ||
try | ||
{ | ||
$hash = QuickHashIntSet::loadFromString(); | ||
} | ||
catch( Exception $e ) | ||
{ | ||
echo $e->getMessage(), "\n"; | ||
} | ||
|
||
try | ||
{ | ||
$hash = QuickHashIntSet::loadFromString( 1024, 2, 'stuff' ); | ||
} | ||
catch( Exception $e ) | ||
{ | ||
echo $e->getMessage(), "\n"; | ||
} | ||
|
||
try | ||
{ | ||
$hash = QuickHashIntSet::loadFromString( 1024, 'stuff' ); | ||
} | ||
catch( Exception $e ) | ||
{ | ||
echo $e->getMessage(), "\n"; | ||
} | ||
|
||
try | ||
{ | ||
$hash = QuickHashIntSet::loadFromString( new StdClass ); | ||
} | ||
catch( Exception $e ) | ||
{ | ||
echo $e->getMessage(), "\n"; | ||
} | ||
|
||
echo "\nWrong size: \n"; | ||
try | ||
{ | ||
$contents = file_get_contents( dirname( __FILE__ ) . "/broken-file.set" ); | ||
$hash = QuickHashIntSet::loadFromString( $contents ); | ||
} | ||
catch( Exception $e ) | ||
{ | ||
echo $e->getMessage(), "\n"; | ||
} | ||
?> | ||
--EXPECT-- | ||
|
||
Wrong params: | ||
QuickHashIntSet::loadFromString() expects at least 1 parameter, 0 given | ||
QuickHashIntSet::loadFromString() expects at most 2 parameters, 3 given | ||
QuickHashIntSet::loadFromString() expects parameter 2 to be long, string given | ||
QuickHashIntSet::loadFromString() expects parameter 1 to be string, object given | ||
|
||
Wrong size: | ||
QuickHashIntSet::loadFromString(): String is in the wrong format (not a multiple of 4 bytes) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
--TEST-- | ||
Basic test for reading sets from strings. | ||
--INI-- | ||
extension=quickhash.so | ||
xdebug.default_enable=0 | ||
--FILE-- | ||
<?php | ||
$file = dirname( __FILE__ ) . "/simple.set"; | ||
$contents = file_get_contents( $file ); | ||
$hash = QuickHashIntSet::loadFromString( $contents, QuickHashIntSet::DO_NOT_USE_ZEND_ALLOC ); | ||
foreach( range( 0, 0x1f ) as $key ) | ||
{ | ||
printf( "Key %3d (%2x) is %s\n", $key, $key, $hash->exists( $key ) ? 'set' : 'unset' ); | ||
} | ||
?> | ||
--EXPECT-- | ||
Key 0 ( 0) is unset | ||
Key 1 ( 1) is set | ||
Key 2 ( 2) is set | ||
Key 3 ( 3) is set | ||
Key 4 ( 4) is unset | ||
Key 5 ( 5) is set | ||
Key 6 ( 6) is unset | ||
Key 7 ( 7) is set | ||
Key 8 ( 8) is unset | ||
Key 9 ( 9) is unset | ||
Key 10 ( a) is unset | ||
Key 11 ( b) is set | ||
Key 12 ( c) is unset | ||
Key 13 ( d) is set | ||
Key 14 ( e) is unset | ||
Key 15 ( f) is unset | ||
Key 16 (10) is unset | ||
Key 17 (11) is set | ||
Key 18 (12) is unset | ||
Key 19 (13) is set | ||
Key 20 (14) is unset | ||
Key 21 (15) is unset | ||
Key 22 (16) is unset | ||
Key 23 (17) is set | ||
Key 24 (18) is unset | ||
Key 25 (19) is unset | ||
Key 26 (1a) is unset | ||
Key 27 (1b) is set | ||
Key 28 (1c) is unset | ||
Key 29 (1d) is set | ||
Key 30 (1e) is unset | ||
Key 31 (1f) is set |