From: anthony Date: Thu, 29 Mar 2012 04:59:34 +0000 (+0000) Subject: Test for the script-token module X-Git-Tag: 7.0.1-0~5949 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=39befa7094a46dc14d224ebb47a27ecae2eec560;p=imagemagick Test for the script-token module --- diff --git a/MagickWand/tests/script-token-test-data.txt b/MagickWand/tests/script-token-test-data.txt new file mode 100644 index 000000000..4769b317e --- /dev/null +++ b/MagickWand/tests/script-token-test-data.txt @@ -0,0 +1,42 @@ +# +# Comments should be ignored +# +-option key # end of line comment ++reset imbedded#hash # <- not a comment, thought this is + +This\ is' a 'single" token" + +And\\\ \''even '\'\""more \""complex + +"Backslash chars \n are returned as is" +'regardless \n of quoting' + +'Single quote escapes' +\' "'" + +"Double quote escapes" +\" '"' "\"" + +Back\ slash\ escapes +\\ '\' "\\" # NOTE that backslash in single quotes are literial! + +'Space Character Escapes' +\ ' ' " " + +'Empty Tokens, using quotes' +'' "" + +"Unicode charcaters are handled" +"° ' ² ³ ` ´" +"µ ¶ ⨀ ⨁ ⨂" +测试用的汉字 + +Lines__\ +__Continuation + +'quoted_newlines__ +__are_part_of_token' + +"Last Token before EOF" + + diff --git a/MagickWand/tests/script-token-test-results.txt b/MagickWand/tests/script-token-test-results.txt new file mode 100644 index 000000000..8c5c57053 --- /dev/null +++ b/MagickWand/tests/script-token-test-results.txt @@ -0,0 +1,53 @@ +l=4, c=1, stat=0, len=64, token="-option" +l=4, c=9, stat=0, len=64, token="key" +l=5, c=1, stat=0, len=64, token="+reset" +l=5, c=10, stat=0, len=64, token="imbedded#hash" +l=7, c=1, stat=0, len=64, token="This is a single token" +l=9, c=1, stat=0, len=64, token="And\ 'even '"more "complex" +l=11, c=1, stat=0, len=64, token="Backslash chars \n are returned as is" +l=12, c=1, stat=0, len=64, token="regardless \n of quoting" +l=14, c=1, stat=0, len=64, token="Single quote escapes" +l=15, c=2, stat=0, len=64, token="'" +l=15, c=4, stat=0, len=64, token="'" +l=17, c=1, stat=0, len=64, token="Double quote escapes" +l=18, c=2, stat=0, len=64, token=""" +l=18, c=4, stat=0, len=64, token=""" +l=18, c=8, stat=0, len=64, token=""" +l=20, c=1, stat=0, len=64, token="Back slash escapes" +l=21, c=2, stat=0, len=64, token="\" +l=21, c=4, stat=0, len=64, token="\" +l=21, c=9, stat=0, len=64, token="\" +l=23, c=1, stat=0, len=64, token="Space Character Escapes" +l=24, c=2, stat=0, len=64, token=" " +l=24, c=4, stat=0, len=64, token=" " +l=24, c=9, stat=0, len=64, token=" " +l=26, c=1, stat=0, len=64, token="Empty Tokens, using quotes" +l=27, c=1, stat=0, len=64, token="" +l=27, c=6, stat=0, len=64, token="" +l=29, c=1, stat=0, len=64, token="Unicode charcaters are handled" +l=30, c=1, stat=0, len=64, token="° ' ² ³ ` ´" +l=31, c=1, stat=0, len=64, token="µ ¶ ⨀ ⨁ ⨂" +l=32, c=1, stat=0, len=64, token="测试用的汉字" +l=34, c=1, stat=0, len=64, token="Lines____Continuation" +l=37, c=1, stat=0, len=64, token="quoted_newlines__ +__are_part_of_token" +l=40, c=1, stat=0, len=64, token="Last Token before EOF" +EOF Found + +l=1, c=1, stat=0, len=64, token="Next token bad quotes" +Bad Quotes l=1, c=25 token="unfinished quotes ->" + +l=1, c=1, stat=0, len=64, token="Binary input follows" +Binary Char at l=2, c=4 + +l=1, c=1, stat=0, len=64, token="Very BIG Token Tests" +l=2, c=1, stat=0, len=256, token="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa..." +l=3, c=1, stat=0, len=1024, token="bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb..." +l=4, c=1, stat=0, len=4096, token="cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc..." +l=5, c=1, stat=0, len=8192, token="dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd..." +l=6, c=1, stat=0, len=12288, token="eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee..." +l=7, c=1, stat=0, len=16384, token="ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff..." +l=8, c=1, stat=0, len=8392704, token="eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee..." +l=9, c=1, stat=0, len=8392704, token="and all is well!" +EOF Found + diff --git a/MagickWand/tests/script-token-test.c b/MagickWand/tests/script-token-test.c new file mode 100644 index 000000000..e1c3249f7 --- /dev/null +++ b/MagickWand/tests/script-token-test.c @@ -0,0 +1,140 @@ +/* +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % +% % +% SSS CCC RRRR III PPPP TTTTT TTTTT OOO K K EEEE N N % +% S C R R I P P T T O O K K E NN N % +% SSS C RRRR I PPPP T T O O KK EEE N N N % +% S C R R I P T T O O K K E N NN % +% SSSS CCC R RR III P T T OOO K K EEEE N N % +% % +% TTTTT EEEEE SSSSS TTTTT % +% T E SS T % +% T EEE SSS T % +% T E SS T % +% T EEEEE SSSSS T % +% % +% Perform "Magick" on Images via the Command Line Interface % +% % +% Dragon Computing % +% Anthony Thyssen % +% January 2012 % +% % +% % +% Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization % +% dedicated to making software imaging solutions freely available. % +% % +% You may not use this file except in compliance with the License. You may % +% obtain a copy of the License at % +% % +% http://www.imagemagick.org/script/license.php % +% % +% Unless required by applicable law or agreed to in writing, software % +% distributed under the License is distributed on an "AS IS" BASIS, % +% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % +% See the License for the specific language governing permissions and % +% limitations under the License. % +% % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% Test the raw tokanization of the ScriptToken Subroutines +% +% This actually uses very little of the magic core functions +% and in fact creates a completely stand-alone program by substituting +% required MagickCore with direct system equivelents. +% +% Build +% cc script-token-test.c -o script-token-test +% +% For testing see script-token-test.sh +% +*/ + +/* System Replacement for MagickWand includes */ +#include +#include +#include +#include +#include + +/* Defines to replace MagickWand / MagickCore defintions */ +#define MaxTextExtent 4096 +#define MagickFalse 0 +#define MagickTrue 1 +#define MagickBooleanType int + +#define AcquireMagickMemory(s) malloc(s) +#define RelinquishMagickMemory(p) (free(p),NULL) +#define ResizeMagickMemory(p,s) realloc(p,s) +#define ResetMagickMemory(p,b,s) memset(p,b,s) +#define StringToLong(s) strtol(s,(char **) NULL,10) +#define LocaleCompare(p,q) strcasecmp(p,q) +#define LocaleNCompare(p,q,l) strncasecmp(p,q,l) +#define WandSignature 0xabacadabUL +#define WandExport + +/* Include the actual code for ScriptToken functions */ +#define SCRIPT_TOKEN_TESTING 1 /* Prevent MagickWand Includes */ +#include "../script-token.h" +#include "../script-token.c" + +/* Test program to report what tokens it finds in given input file/stream */ + +int main(int argc, char *argv[]) +{ + ScriptTokenInfo + *token_info; + + token_info = AcquireScriptTokenInfo( (argc>1) ? argv[1] : "-" ); + if (token_info == (ScriptTokenInfo *) NULL) { + printf("Script Open Failure : %s\n", strerror(errno)); + return(1); + } + + while (1) { + if( GetScriptToken(token_info) == MagickFalse ) + break; + + if( strlen(token_info->token) > INITAL_TOKEN_LENGTH-1 ) { + token_info->token[INITAL_TOKEN_LENGTH-4] = '.'; + token_info->token[INITAL_TOKEN_LENGTH-3] = '.'; + token_info->token[INITAL_TOKEN_LENGTH-2] = '.'; + token_info->token[INITAL_TOKEN_LENGTH-1] = '\0'; + } + printf("l=%d, c=%d, stat=%d, len=%d, token=\"%s\"\n", + token_info->token_line, token_info->token_column, + token_info->status, token_info->length, token_info->token); + } + + switch( token_info->status ) { + case TokenStatusOK: + break; + case TokenStatusEOF: + printf("EOF Found\n"); + break; + case TokenStatusBadQuotes: + /* Ensure last token has a sane length for error report */ + if( strlen(token_info->token) > INITAL_TOKEN_LENGTH-1 ) { + token_info->token[INITAL_TOKEN_LENGTH-4] = '.'; + token_info->token[INITAL_TOKEN_LENGTH-3] = '.'; + token_info->token[INITAL_TOKEN_LENGTH-2] = '.'; + token_info->token[INITAL_TOKEN_LENGTH-1] = '\0'; + } + printf("Bad Quotes l=%d, c=%d token=\"%s\"\n", + token_info->token_line,token_info->token_column, token_info->token); + break; + case TokenStatusMemoryFailed: /* token is invalid */ + printf("Out of Memory l=%d, c=%d\n", + token_info->token_line,token_info->token_column); + break; + case TokenStatusBinary: /* token is invalid */ + printf("Binary Char at l=%d, c=%d\n", + token_info->curr_line,token_info->curr_column); + break; + } + + /* Clean up */ + token_info = DestroyScriptTokenInfo(token_info); + + return(0); +} diff --git a/MagickWand/tests/script-token-test.sh b/MagickWand/tests/script-token-test.sh new file mode 100755 index 000000000..4e44c2d91 --- /dev/null +++ b/MagickWand/tests/script-token-test.sh @@ -0,0 +1,29 @@ +#!/bin/sh +# +# Basic testing of ScriptToken parser. +# +# script-token-test.sh | diff - script-token-test-results.txt +# +./script-token-test script-token-test-data.txt +echo "" + +echo -n "\"Next token bad quotes\" \"unfinished quotes ->" |\ + ./script-token-test +echo "" + +perl -e 'print "\"Binary input follows\"\n", "abc\006xyz\n"' |\ + ./script-token-test +echo "" + +( echo '"Very BIG Token Tests"' + dd if=/dev/zero bs=80 count=1 2>/dev/null | tr '\0' 'a'; echo "" + dd if=/dev/zero bs=500 count=1 2>/dev/null | tr '\0' 'b'; echo "" + dd if=/dev/zero bs=4000 count=1 2>/dev/null | tr '\0' 'c'; echo "" + dd if=/dev/zero bs=5000 count=1 2>/dev/null | tr '\0' 'd'; echo "" + dd if=/dev/zero bs=10k count=1 2>/dev/null | tr '\0' 'e'; echo "" + dd if=/dev/zero bs=13k count=1 2>/dev/null | tr '\0' 'f'; echo "" + dd if=/dev/zero bs=8k count=1024 2>/dev/null | tr '\0' 'e'; echo "" + echo '"and all is well!"' +) | ./script-token-test +echo "" +