[Cppunit-cvs] cppunit2/test/json_test .cvsignore,NONE,1.1 cleantests.py,NONE,1.1 generate_expected.p
Brought to you by:
blep
Update of /cvsroot/cppunit/cppunit2/test/json_test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4107/test/json_test Added Files: .cvsignore cleantests.py generate_expected.py runjsontests.py test_array_01.expected test_array_01.json test_array_02.expected test_array_02.json test_array_03.expected test_array_03.json test_array_04.expected test_array_04.json test_array_05.expected test_array_05.json test_array_06.expected test_array_06.json test_basic_01.expected test_basic_01.json test_basic_02.expected test_basic_02.json test_basic_03.expected test_basic_03.json test_basic_04.expected test_basic_04.json test_basic_05.expected test_basic_05.json test_basic_06.expected test_basic_06.json test_basic_07.expected test_basic_07.json test_basic_08.expected test_basic_08.json test_basic_09.expected test_basic_09.json test_complex_01.expected test_complex_01.json test_integer_01.expected test_integer_01.json test_integer_02.expected test_integer_02.json test_integer_03.expected test_integer_03.json test_integer_04.expected test_integer_04.json test_integer_05.expected test_integer_05.json test_object_01.expected test_object_01.json test_object_02.expected test_object_02.json test_object_03.expected test_object_03.json test_preserve_comment_01.expected test_preserve_comment_01.json test_real_01.expected test_real_01.json test_real_02.expected test_real_02.json test_real_03.expected test_real_03.json test_real_04.expected test_real_04.json test_real_05.expected test_real_05.json test_real_06.expected test_real_06.json test_real_07.expected test_real_07.json Log Message: * added end to end json tests --- NEW FILE: test_preserve_comment_01.expected --- .={} .first=1 .second=2 --- NEW FILE: test_basic_09.expected --- .=null --- NEW FILE: test_basic_07.expected --- .=false --- NEW FILE: test_array_05.expected --- .=[] .[0]=1 .[1]=2 .[2]=3 .[3]=4 .[4]=5 .[5]=6 .[6]=7 .[7]=8 .[8]=9 .[9]=10 .[10]=11 .[11]=12 .[12]=13 .[13]=14 .[14]=15 .[15]=16 .[16]=17 .[17]=18 .[18]=19 .[19]=20 .[20]=21 .[21]=22 .[22]=23 .[23]=24 .[24]=25 .[25]=26 .[26]=27 .[27]=28 .[28]=29 .[29]=30 .[30]=31 .[31]=32 .[32]=33 .[33]=34 .[34]=35 .[35]=36 .[36]=37 .[37]=38 .[38]=39 .[39]=40 .[40]=41 .[41]=42 .[42]=43 .[43]=44 .[44]=45 .[45]=46 .[46]=47 .[47]=48 .[48]=49 .[49]=50 .[50]=51 .[51]=52 .[52]=53 .[53]=54 .[54]=55 .[55]=56 .[56]=57 .[57]=58 .[58]=59 .[59]=60 .[60]=61 .[61]=62 .[62]=63 .[63]=64 .[64]=65 .[65]=66 .[66]=67 .[67]=68 .[68]=69 .[69]=70 .[70]=71 .[71]=72 .[72]=73 .[73]=74 .[74]=75 .[75]=76 .[76]=77 .[77]=78 .[78]=79 .[79]=80 .[80]=81 .[81]=82 .[82]=83 .[83]=84 .[84]=85 .[85]=86 .[86]=87 .[87]=88 .[88]=89 .[89]=90 .[90]=91 .[91]=92 .[92]=93 .[93]=94 .[94]=95 .[95]=96 .[96]=97 .[97]=98 .[98]=99 --- NEW FILE: test_basic_02.expected --- .=-123456789 --- NEW FILE: test_array_01.expected --- .=[] --- NEW FILE: test_real_04.expected --- .=1.2345678 --- NEW FILE: test_preserve_comment_01.json --- /* A comment at the beginning of the file. */ { "first" : 1, // comment after 'first' on the same line /* Comment before 'second' */ "second" : 2 } /* A comment at the end of the file. */ --- NEW FILE: test_basic_08.json --- // C++ style comment null --- NEW FILE: test_real_02.json --- // -2^32 => out of signed integer range, switch to double -4294967295 --- NEW FILE: generate_expected.py --- import glob import os.path for path in glob.glob( '*.json' ): text = file(path,'rt').read() target = os.path.splitext(path)[0] + '.expected' if os.path.exists( target ): print 'skipping:', target else: print 'creating:', target file(target,'wt').write(text) --- NEW FILE: test_object_01.expected --- .={} --- NEW FILE: test_array_05.json --- [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99] --- NEW FILE: test_integer_03.json --- // Max unsigned integer 4294967295 --- NEW FILE: test_integer_04.expected --- .=0 --- NEW FILE: test_integer_01.json --- // Max signed integer 2147483647 --- NEW FILE: test_real_01.expected --- .=8589934592 --- NEW FILE: cleantests.py --- # removes all files created during testing import glob import os paths = [] for pattern in [ '*.actual', '*.actual-rewrite', '*.rewrite', '*.process-output' ]: paths += glob.glob( pattern ) for path in paths: os.unlink( path ) --- NEW FILE: test_array_06.expected --- .=[] .[0]="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" .[1]="bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" .[2]="ccccccccccccccccccccccc" .[3]="dddddddddddddddddddddddddddddddddddddddddddddddddddd" --- NEW FILE: test_real_05.json --- // 1234567.8 0.12345678e7 --- NEW FILE: test_basic_03.json --- 1.2345678 --- NEW FILE: runjsontests.py --- import sys import os import os.path import glob if len(sys.argv) != 2: print "Usage: %s jsontest-executable-path" % sys.argv[0] sys.exit( 1 ) jsontest_executable_path = os.path.normpath( os.path.abspath( sys.argv[1] ) ) def compareOutputs( expected, actual, message ): expected = expected.strip().replace('\r','').split('\n') actual = actual.strip().replace('\r','').split('\n') diff_line = 0 max_line_to_compare = min( len(expected), len(actual) ) for index in xrange(0,max_line_to_compare): if expected[index].strip() != actual[index].strip(): diff_line = index + 1 break if diff_line == 0 and len(expected) != len(actual): diff_line = max_line_to_compare+1 if diff_line == 0: return None def safeGetLine( lines, index ): index += -1 if index >= len(lines): return '' return lines[index].strip() return """ Difference in %s at line %d: Expected: '%s' Actual: '%s' """ % (message, diff_line, safeGetLine(expected,diff_line), safeGetLine(actual,diff_line) ) def safeReadFile( path ): try: return file( base_path + '.actual', 'rt' ).read() except: return "" tests = glob.glob( '*.json' ) failed_tests = [] for input_path in tests: print 'TESTING:', input_path, pipe = os.popen( "%s %s" % (jsontest_executable_path, input_path) ) process_output = pipe.read() status = pipe.close() base_path = os.path.splitext(input_path)[0] actual_output = safeReadFile( base_path + '.actual' ) actual_rewrite_output = safeReadFile( base_path + '.actual-rewrite' ) file(base_path + '.process-output','wt').write( process_output ) if status: print 'parsing failed' failed_tests.append( (input_path, 'Parsing failed:\n' + process_output) ) else: expected_output_path = os.path.splitext(input_path)[0] + '.expected' expected_output = file( expected_output_path, 'rt' ).read() detail = ( compareOutputs( expected_output, actual_output, 'input' ) or compareOutputs( expected_output, actual_rewrite_output, 'rewrite' ) ) if detail: print 'FAILED' failed_tests.append( (input_path, detail) ) else: print 'OK' if failed_tests: print print 'Failure details:' for failed_test in failed_tests: print '* Test', failed_test[0] print failed_test[1] print print 'Test results: %d passed, %d failed.' % (len(tests)-len(failed_tests), len(failed_tests) ) sys.exit(1) else: print 'All %d tests passed.' % len(tests) sys.exit(0) --- NEW FILE: test_object_01.json --- {} --- NEW FILE: test_integer_02.json --- // Min signed integer -2147483648 --- NEW FILE: test_object_02.expected --- .={} .count=1234 --- NEW FILE: test_real_04.json --- // 1.2345678 12345678e-7 --- NEW FILE: test_integer_05.expected --- .=1 --- NEW FILE: test_real_01.json --- // 2^33 => out of integer range, switch to double 8589934592 --- NEW FILE: test_real_05.expected --- .=1234567.8 --- NEW FILE: test_basic_09.json --- /* C style comment */ null --- NEW FILE: test_basic_06.expected --- .=true --- NEW FILE: test_array_01.json --- [] --- NEW FILE: test_real_06.expected --- .=-1.2345678 --- NEW FILE: .cvsignore --- *.actual *.actual-rewrite *.rewrite *.process-output *.pyc json.py --- NEW FILE: test_basic_05.expected --- .=null --- NEW FILE: test_object_03.json --- { "count" : 1234, "name" : "test", "attribute" : "random" } --- NEW FILE: test_basic_06.json --- true --- NEW FILE: test_object_03.expected --- .={} .attribute="random" .count=1234 .name="test" --- NEW FILE: test_real_07.expected --- .=-1234567.8 --- NEW FILE: test_integer_03.expected --- .=4294967295 --- NEW FILE: test_real_03.json --- // -2^32 => out of signed integer range, switch to double -4294967295 --- NEW FILE: test_array_06.json --- [ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "ccccccccccccccccccccccc", "dddddddddddddddddddddddddddddddddddddddddddddddddddd" ] --- NEW FILE: test_real_06.json --- // -1.2345678 -12345678e-7 --- NEW FILE: test_integer_01.expected --- .=2147483647 --- NEW FILE: test_complex_01.expected --- .={} .attribute=[] .attribute[0]="random" .attribute[1]="short" .attribute[2]="bold" .attribute[3]=12 .attribute[4]={} .attribute[4].height=7 .attribute[4].width=64 .count=1234 .name={} .name.aka="T.E.S.T." .name.id=123987 .test={} .test.1={} .test.1.2={} .test.1.2.3={} .test.1.2.3.coord=[] .test.1.2.3.coord[0]=1 .test.1.2.3.coord[1]=2 --- NEW FILE: test_integer_04.json --- // Min unsigned integer 0 --- NEW FILE: test_array_04.expected --- .=[] .[0]=1 .[1]="abc" .[2]=12.3 .[3]=-4 --- NEW FILE: test_basic_07.json --- false --- NEW FILE: test_basic_03.expected --- .=1.2345678 --- NEW FILE: test_array_03.json --- [ 1, 2 , 3,4,5] --- NEW FILE: test_object_02.json --- { "count" : 1234 } --- NEW FILE: test_complex_01.json --- { "count" : 1234, "name" : { "aka" : "T.E.S.T.", "id" : 123987 }, "attribute" : [ "random", "short", "bold", 12, { "height" : 7, "width" : 64 } ], "test": { "1" : { "2" : { "3" : { "coord" : [ 1,2] } } } } } --- NEW FILE: test_real_03.expected --- .=-4294967295 --- NEW FILE: test_array_04.json --- [1, "abc" , 12.3, -4] --- NEW FILE: test_array_02.json --- [1] --- NEW FILE: test_basic_08.expected --- .=null --- NEW FILE: test_basic_04.json --- "abcdef" --- NEW FILE: test_array_02.expected --- .=[] .[0]=1 --- NEW FILE: test_basic_04.expected --- .="abcdef" --- NEW FILE: test_basic_01.expected --- .=123456789 --- NEW FILE: test_basic_02.json --- -0123456789 --- NEW FILE: test_integer_05.json --- 1 --- NEW FILE: test_basic_01.json --- 0123456789 --- NEW FILE: test_real_02.expected --- .=-4294967295 --- NEW FILE: test_real_07.json --- // -1234567.8 -0.12345678e7 --- NEW FILE: test_basic_05.json --- null --- NEW FILE: test_array_03.expected --- .=[] .[0]=1 .[1]=2 .[2]=3 .[3]=4 .[4]=5 --- NEW FILE: test_integer_02.expected --- .=-2147483648 |