fork/slippc
git clone https://git.julia.blue/fork/slippc
b79f91c
0.8.0
1#include "tests.h" 2 3// file containing test replays 4static const std::string TESTDIR = "test-replays" ; 5// normal replays 6static const std::string STANDARDDIR = "standard" ; 7// replays that cannot compress 8static const std::string CORRUPTDIR = "corrupt" ; 9// replays that were compressed with old versions of compressor 10static const std::string BACKCOMPATDIR = "zlp-compat-1" ; 11 12// known file 1 13static const std::string TSLPFILE = "3-9-0-singles-irl-summit12.slp.xz" ; 14// known file 2 15static const std::string TCMPFILE = "3-7-0-singles-net.slp.xz" ; 16// temporary slp file 17static const std::string TZLPFILE = "zlptest.zlp" ; 18// temporary zlp file 19static const std::string TUNZLPFILE = "zlptest.slp" ; 20 21static const std::string tmpzlp = (PATH (TESTDIR ) /PATH (TZLPFILE )).string (); 22static const std::string tmpunzlp = (PATH (TESTDIR ) /PATH (TUNZLPFILE )).string (); 23 24typedef std::filesystem::directory_iterator f_iter ; 25typedef std::filesystem::directory_entry f_entry ; 26 27static int _debug = 0 ; 28 29namespace slip { 30 31// https://stackoverflow.com/questions/865668/how-to-parse-command-line-arguments-in-c 32char * getCmdOption (char ** begin ,char ** end ,const std::string & option ) { 33char ** itr = std::find (begin ,end ,option ); 34if (itr != end && ++ itr != end ) { 35return * itr ; 36 } 37return 0 ; 38} 39 40bool cmdOptionExists (char ** begin ,char ** end ,const std::string & option ) { 41return std::find (begin ,end ,option )!= end ; 42} 43 44void printUsage () { 45 std::cout 46 <<"Usage: slippc-tests [-t <testlevel] [-d <debuglevel]:" << std::endl 47// << " -i Parse and analyze <infile> (not very useful on its own)" << std::endl 48// << " -j Output <infile> in .json format to <jsonfile> (use \"-\" for stdout)" << std::endl 49// << " -a Output an analysis of <infile> in .json format to <analysisfile> (use \"-\" for stdout)" << std::endl 50// << " -f When used with -j <jsonfile>, write full frame info (instead of just frame deltas)" << std::endl 51// << " -x Compress or decompress a replay" << std::endl 52// << " -X Set output file name for compression" << std::endl 53// << std::endl 54// << "Debug options:" << std::endl 55 <<" -t Run tests at level <testlevel>" << std::endl 56 <<" -d Run debug at level <debuglevel>" << std::endl 57// << " --raw-enc Output raw encodes with -x (DANGEROUS, debug only)" << std::endl 58// << " -h Show this help message" << std::endl 59 ; 60} 61 62void testTester () { 63TSUITE ("Basic Pass" ); 64ASSERT ("Pass 1" ,1 == 1 , 651 <<" != " <<1 ); 66ASSERT ("Pass 2" ,1 != 2 , 671 <<" == " <<2 ); 68ASSERT ("Pass 3" ,2 == 2 , 692 <<" != " <<2 ); 70TSUITE ("Basic Assert" ); 71ASSERT ("Pass" ,1 == 1 , 721 <<" != " <<1 ); 73ASSERT ("Fail" ,1 == 2 , 741 <<" != " <<2 ); 75ASSERT ("Fail 2" ,2 != 2 , 762 <<" == " <<2 ); 77TSUITE ("Basic Suggest" ); 78SUGGEST ("Suggest Pass" ,1 == 1 , 791 <<" != " <<1 ); 80SUGGEST ("Suggest Fail" ,1 == 2 , 811 <<" != " <<2 ); 82TSUITE ("Basic Both" ); 83SUGGEST ("Both Pass" ,1 == 1 , 841 <<" != " <<1 ); 85SUGGEST ("Both Warn" ,1 == 2 , 861 <<" != " <<2 ); 87ASSERT ("Both Fail" ,1 == 2 , 881 <<" != " <<2 ); 89TSUITE ("All Fail" ); 90ASSERT ("All Fail 1" ,1 != 1 , 911 <<" == " <<1 ); 92ASSERT ("All Fail 2" ,2 != 2 , 932 <<" == " <<2 ); 94TSUITE ("Vars" ); 95int x = 1 ,y = 1 ,z = 2 ; 96ASSERT ("Var Pass 1" ,x == y , 97x <<" == " <<y ); 98ASSERT ("Var Fail 1" ,x != y , 99x <<" == " <<y ); 100ASSERT ("Var Fail 2" ,x == z , 101x <<" != " <<z ); 102TSUITE ("Errors" ); 103ASSERT ("Error 1" ,[](){throw std::logic_error ("Error Test" );return true;}(), 104"1/0" ); 105} 106 107int testTestFiles () { 108// TSUITE("Files Available"); 109return 0 ; 110} 111 112int sanityCheck (slip::Parser * p , std::string name , std::string path ) { 113ASSERT (name + " Exists" ,access (path .c_str (),F_OK )== 0 , 114name <<" does not exist" ); 115BAILONFAIL (1 ); 116ASSERT (name + " Parses" ,p -> load (path .c_str ()), 117name <<" does not parse" ); 118BAILONFAIL (1 ); 119 120const SlippiReplay * r = p -> replay (); 121ASSERT (" First frame is -123" ,r -> first_frame == -123 , 122name + " first frame is " <<r -> first_frame ); 123int playing = -1 ; 124for (unsigned i = 0 ;i < 8 ;++ i ) { 125int pt = r -> player [i ].player_type ; 126ASSERT (" Port " + std::to_string (i )+ " player type < 4" ,pt < 4 , 127"Port " <<i <<" player type is " <<pt ); 128if (pt < 3 ) { 129playing = i ; 130 } 131 } 132ASSERT (" Game has at least 1 player" ,playing >=0 , 133"Game has no players" ); 134BAILONFAIL (1 ); 135 136for (unsigned pnum = 0 ;pnum < 8 ;++ pnum ) { 137if (r -> player [pnum ].player_type == 3 ) { 138continue ; 139 } 140unsigned flag_char = 0 ,flag_jumps = 0 ,flag_dmg = 0 ,flag_shield = 0 , 141flag_lcancel = 0 ,flag_hurt = 0 ,flag_stocks = 0 ,flag_stocks_inc = 0 ; 142unsigned char cid = r -> player [pnum ].frame [0 ].char_id ; 143bool sheik = ((cid == 7 )|| (cid == 19 )); 144for (unsigned f = 1 ;f < r -> frame_count ;++ f ) { 145SlippiFrame sf = r -> player [pnum ].frame [f ]; 146if (sf .action_post > Action ::Sleep ) {//if we're not dead 147if (sf .char_id != cid ) { 148if (!(sheik && (sf .char_id == 7 || sf .char_id == 19 ))) { 149++ flag_char ; 150 } 151 } 152 } 153if (sf .jumps > 6 ) { 154++ flag_jumps ; 155 } 156if ((sf .percent_pre > 1000 )|| (sf .percent_pre < 0 )) { 157++ flag_dmg ; 158 } 159if (sf .shield >=61 ) { 160++ flag_shield ; 161 } 162if (sf .l_cancel > 2 ) { 163++ flag_lcancel ; 164 } 165if (sf .hurt_by > 8 ) { 166++ flag_hurt ; 167 } 168if (sf .stocks > 99 ) { 169++ flag_stocks ; 170 } 171 } 172 std::string ps = std::to_string (pnum + 1 ); 173ASSERT (" Port " + ps + " character is consistent throughout game" ,flag_char == 0 , 174ps <<"'s character changes throughout the game" ); 175ASSERT (" Port " + ps + " character never has more than 6 jumps" ,flag_jumps == 0 , 176ps <<" has more than 6 jumps" ); 177ASSERT (" Port " + ps + " damage is always between 0 and 1000" ,flag_dmg == 0 , 178ps <<" has weird damage" ); 179ASSERT (" Port " + ps + " shield is always <= 60" ,flag_shield == 0 , 180ps <<" has more than 60 shield" ); 181ASSERT (" Port " + ps + " l cancel status is always <= 2" ,flag_lcancel == 0 , 182ps <<"'s l cancel status is more than 2" ); 183ASSERT (" Port " + ps + " hurt by player id always < 8" ,flag_hurt == 0 , 184ps <<"'s hurt by player >= 8" ); 185ASSERT (" Port " + ps + " stocks always <= 99" ,flag_stocks == 0 , 186ps <<"'s stocks > 99" ); 187 } 188 189return 0 ; 190} 191 192int testCorruptFiles () { 193TSUITE ("Corrupt File Sanity Checks" ); 194int errors = 0 ; 195for (const f_entry & entry :f_iter (PATH (TESTDIR ) /PATH (CORRUPTDIR ))) { 196 std::string path = entry .path ().string (); 197 std::string name = entry .path ().stem ().string (); 198// for(unsigned i = 0; i < ncomps; ++i) { 199 slip::Parser * p = new slip::Parser (_debug ); 200if (sanityCheck (p ,name ,path )!= 0 ) { 201++ errors ; 202 } 203delete p ; 204 slip::Compressor * c = new slip::Compressor (_debug ); 205bool loaded = c -> loadFromFile (path .c_str ()); 206ASSERTNOERR ("Compressor refuses to compress " + name ,!loaded , 207"Compressor attempted to compress corrupt file " <<name ); 208delete c ; 209 }; 210return 0 ; 211} 212 213int testConsistencySanity () { 214TSUITE ("Parser Sanity Checks" ); 215int errors = 0 ; 216for (const f_entry & entry :f_iter (PATH (TESTDIR ) /PATH (STANDARDDIR ))) { 217 std::string path = entry .path ().string (); 218 std::string name = entry .path ().stem ().string (); 219// for(unsigned i = 0; i < ncomps; ++i) { 220 slip::Parser * p = new slip::Parser (_debug ); 221if (sanityCheck (p ,name ,path )!= 0 ) { 222++ errors ; 223 } 224delete p ; 225 }; 226return 0 ; 227} 228 229 230int testKnownFiles () { 231 std::string known1 = (PATH (TESTDIR ) /PATH (STANDARDDIR ) /PATH (TSLPFILE )).string (); 232 std::string known2 = (PATH (TESTDIR ) /PATH (STANDARDDIR ) /PATH (TCMPFILE )).string (); 233 slip::Parser * p ; 234 235TSUITE ("Known File Parsing" ); 236ASSERT ("File Exists" ,access (known1 .c_str (),F_OK )== 0 , 237"File " <<known1 <<" does not exist" ); 238BAILONFAIL (1 ); 239 std::string test_md5 = md5compressed (known1 ); 240ASSERT ("MD5 of file is 8ba0485603d5d99cdfd8cead63ba6c1f" ,test_md5 .compare ("8ba0485603d5d99cdfd8cead63ba6c1f" )== 0 , 241"MD5 of file is " <<test_md5 ); 242BAILONFAIL (1 ); 243p = new slip::Parser (_debug ); 244ASSERT ("File Parses" ,p -> load ((known1 ).c_str ()), 245"File does not parse" ); 246BAILONFAIL (1 ); 247const SlippiReplay * r = p -> replay (); 248ASSERT ("File version is 3.9.0" ,r -> slippi_version .compare ("3.9.0" )== 0 , 249"File version is " <<r -> slippi_version ); 250ASSERT ("First frame is -123" ,r -> first_frame == -123 , 251"First frame is " <<r -> first_frame ); 252ASSERT ("Frame count is 13662" ,r -> frame_count == 13662 , 253"Frame count is " <<r -> frame_count ); 254ASSERT ("Seed is 3969935363" ,r -> seed == 3969935363 , 255"Seed is " <<r -> seed ); 256ASSERT ("Played on Nintendont" ,r -> played_on .compare ("nintendont" )== 0 , 257"Game played on " <<r -> played_on ); 258ASSERT ("Played on date 2021-12-13T10:55:05" ,r -> start_time .compare ("2021-12-13T10:55:05" )== 0 , 259"Game played on date " <<r -> start_time ); 260ASSERT ("Port 1 is empty" ,r -> player [0 ].player_type == 3 , 261"Port 1 is not empty" ); 262ASSERT ("Port 2 is empty" ,r -> player [1 ].player_type == 3 , 263"Port 2 is not empty" ); 264ASSERT ("Port 3 played Fox" ,r -> player [2 ].ext_char_id == 2 , 265"Port 3 played " <<r -> player [2 ].ext_char_id <<" (" <<CharExt ::name [r -> player [2 ].ext_char_id ] <<")" ); 266ASSERT ("Port 4 played Marth" ,r -> player [3 ].ext_char_id == 9 , 267"Port 4 played " <<r -> player [3 ].ext_char_id <<" (" <<CharExt ::name [r -> player [3 ].ext_char_id ] <<")" ); 268ASSERT ("Game played on Dream Land" ,r -> stage == 28 , 269"Game played on" <<r -> stage <<" (" <<Stage ::name [r -> stage ] <<")" ); 270ASSERT ("Port 3's damage on frame 2345 = 9.4%" ,NEAR (r -> player [2 ].frame [2345 ].percent_post ,9.4f ), 271"Port 3's damage on frame 2345 = " <<r -> player [2 ].frame [2345 ].percent_post ); 272ASSERT ("Port 4's damage on frame 2345 = 117.46%" ,NEAR (r -> player [3 ].frame [2345 ].percent_post ,117.46f ), 273"Port 4's damage on frame 2345 = " <<r -> player [3 ].frame [2345 ].percent_post ); 274ASSERT ("Port 3's joystick x on frame 4444 = -0.975" ,NEAR (r -> player [2 ].frame [4444 ].joy_x ,-0.975f ), 275"Port 3's joystick x on frame 4444 = " <<r -> player [2 ].frame [4444 ].joy_x ); 276ASSERT ("Port 4's joystick y on frame 4444 = 0" ,NEAR (r -> player [3 ].frame [4444 ].joy_y ,0.0f ), 277"Port 4's joystick y on frame 4444 = " <<r -> player [3 ].frame [4444 ].joy_y ); 278ASSERT ("Port 3's y pos on frame 4444 = 0.0089" ,NEAR (r -> player [2 ].frame [4444 ].pos_y_post ,0.0089f ), 279"Port 3's y pos on frame 4444 = " <<r -> player [2 ].frame [4444 ].pos_y_post ); 280ASSERT ("Port 4's x pos on frame 4444 = 0.0089" ,NEAR (r -> player [3 ].frame [4444 ].pos_x_post ,-22.0653 ), 281"Port 4's x pos on frame 4444 = " <<r -> player [3 ].frame [4444 ].pos_x_post ); 282ASSERT ("Port 3 has 3 stocks on frame 4444" ,r -> player [2 ].frame [4444 ].stocks == 3 , 283"Port 3 has " <<r -> player [2 ].frame [4444 ].stocks <<" stocks on frame 4444" ); 284ASSERT ("Port 4 has 3 stocks on frame 4444" ,r -> player [3 ].frame [4444 ].stocks == 3 , 285"Port 4 has " <<r -> player [3 ].frame [4444 ].stocks <<" stocks on frame 4444" ); 286ASSERT ("Port 3 is in action 'Turn' on frame 5000" ,r -> player [2 ].frame [5000 ].action_post == 18 , 287"Port 3 is in action " <<r -> player [2 ].frame [5000 ].action_post <<" = " <<Action ::name [r -> player [2 ].frame [5000 ].action_post ]); 288ASSERT ("Port 3 is in action 'DamageFlyLw' on frame 6000" ,r -> player [2 ].frame [6000 ].action_post == 89 , 289"Port 3 is in action " <<r -> player [2 ].frame [6000 ].action_post <<" = " <<Action ::name [r -> player [2 ].frame [6000 ].action_post ]); 290ASSERT ("Port 3 is in action 'DamageFlyRoll' on frame 7000" ,r -> player [2 ].frame [7000 ].action_post == 91 , 291"Port 3 is in action " <<r -> player [2 ].frame [7000 ].action_post <<" = " <<Action ::name [r -> player [2 ].frame [7000 ].action_post ]); 292ASSERT ("Port 3 is in action 'Catch' on frame 8000" ,r -> player [2 ].frame [8000 ].action_post == 212 , 293"Port 3 is in action " <<r -> player [2 ].frame [8000 ].action_post <<" = " <<Action ::name [r -> player [2 ].frame [8000 ].action_post ]); 294ASSERT ("Port 3 is in action 'AttackAirN' on frame 9000" ,r -> player [2 ].frame [9000 ].action_post == 65 , 295"Port 3 is in action " <<r -> player [2 ].frame [9000 ].action_post <<" = " <<Action ::name [r -> player [2 ].frame [9000 ].action_post ]); 296ASSERT ("Port 3 is in action 'EscapeN' on frame 10000" ,r -> player [2 ].frame [10000 ].action_post == 350 , 297"Port 3 is in action " <<r -> player [2 ].frame [10000 ].action_post <<" = " <<Action ::name [r -> player [2 ].frame [10000 ].action_post ]); 298ASSERT ("Port 4 is in action 'Fall' on frame 5000" ,r -> player [3 ].frame [5000 ].action_post == 29 , 299"Port 4 is in action " <<r -> player [3 ].frame [5000 ].action_post <<" = " <<Action ::name [r -> player [3 ].frame [5000 ].action_post ]); 300ASSERT ("Port 4 is in action 'AttackAirF' on frame 6000" ,r -> player [3 ].frame [6000 ].action_post == 66 , 301"Port 4 is in action " <<r -> player [3 ].frame [6000 ].action_post <<" = " <<Action ::name [r -> player [3 ].frame [6000 ].action_post ]); 302ASSERT ("Port 4 is in action 'KneeBend' on frame 7000" ,r -> player [3 ].frame [7000 ].action_post == 24 , 303"Port 4 is in action " <<r -> player [3 ].frame [7000 ].action_post <<" = " <<Action ::name [r -> player [3 ].frame [7000 ].action_post ]); 304ASSERT ("Port 4 is in action 'JumpF' on frame 8000" ,r -> player [3 ].frame [8000 ].action_post == 25 , 305"Port 4 is in action " <<r -> player [3 ].frame [8000 ].action_post <<" = " <<Action ::name [r -> player [3 ].frame [8000 ].action_post ]); 306ASSERT ("Port 4 is in action 'GuardSetOff' on frame 9000" ,r -> player [3 ].frame [9000 ].action_post == 181 , 307"Port 4 is in action " <<r -> player [3 ].frame [9000 ].action_post <<" = " <<Action ::name [r -> player [3 ].frame [9000 ].action_post ]); 308ASSERT ("Port 4 is in action 'JumpF' on frame 10000" ,r -> player [3 ].frame [10000 ].action_post == 25 , 309"Port 4 is in action " <<r -> player [3 ].frame [10000 ].action_post <<" = " <<Action ::name [r -> player [3 ].frame [10000 ].action_post ]); 310delete p ; 311 312TSUITE ("Known File Compression" ); 313//Removing existing temporary zlp and slp files 314if (fileExists (tmpzlp .c_str ())) { 315remove (tmpzlp .c_str ()); 316 } 317if (fileExists (tmpunzlp .c_str ())) { 318remove (tmpunzlp .c_str ()); 319 } 320ASSERT ("Uncompressed File Exists" ,access (known2 .c_str (),F_OK )== 0 , 321"File does not exist" ); 322BAILONFAIL (1 ); 323 std::string test_md5_2 = md5compressed (known2 ); 324ASSERT ("MD5 of uncompressed file is 7ea1aa5b49f87ab77a66bd8541810d50" ,test_md5_2 .compare ("7ea1aa5b49f87ab77a66bd8541810d50" )== 0 , 325"MD5 of file is " <<test_md5_2 ); 326BAILONFAIL (1 ); 327 slip::Compressor * c = new slip::Compressor (_debug ); 328c -> setOutputFilename (tmpzlp .c_str ()); 329bool loaded = c -> loadFromFile (known2 .c_str ()); 330ASSERTNOERR ("Compressor Loads File" ,loaded , 331"Compressor failed to load known file" ); 332BAILONFAIL (1 ); 333ASSERT ("Compressor Validates File" ,c -> validate (), 334"Compressor failed to validate known file" ); 335BAILONFAIL (1 ); 336c -> saveToFile (false); 337ASSERT ("Compressed File is Generated" ,access (tmpzlp .c_str (),F_OK )== 0 , 338"Compressor failed to save compressed output file" ); 339BAILONFAIL (1 ); 340delete c ; 341 342 std::string test_md5_z = md5file (tmpzlp .c_str ()); 343SUGGEST ("MD5 of compressed file is 8af440882c30c4ac29b935ae3d588e03" ,test_md5_z .compare ("8af440882c30c4ac29b935ae3d588e03" )== 0 , 344"MD5 of file is " <<test_md5_z <<", compression algorithm may have changed" ); 345 346c = new slip::Compressor (_debug ); 347ASSERT ("Compressor Loads Compressed File" ,c -> loadFromFile (tmpzlp .c_str ()), 348"Compressor failed to load compressed known file" ); 349BAILONFAIL (1 ); 350ASSERT ("Compressor Validates Compressed File" ,c -> validate (), 351"Compressor failed to validate compressed known file" ); 352BAILONFAIL (1 ); 353c -> saveToFile (false); 354ASSERT ("In-place decompressed File is Generated" ,access (tmpunzlp .c_str (),F_OK )== 0 , 355"Compressor failed to save decompressed output file" ); 356BAILONFAIL (1 ); 357delete c ; 358 359 std::string test_md5_3 = md5file (tmpunzlp .c_str ()); 360ASSERT ("MD5 of restored file is 7ea1aa5b49f87ab77a66bd8541810d50" ,test_md5_3 .compare ("7ea1aa5b49f87ab77a66bd8541810d50" )== 0 , 361"MD5 of restored file is " <<test_md5_3 ); 362 363return 0 ; 364} 365 366int testCompressionBackcompat () { 367TSUITE ("Backwards Compatible Decompression" ); 368for (const f_entry & entry :f_iter (PATH (TESTDIR ) /PATH (BACKCOMPATDIR ))) { 369 std::string path = entry .path ().string (); 370 std::string name = entry .path ().stem ().string (); 371// md5 checksum is first 32 characters of filename 372 std::string test_md5_o = name .substr (0 ,32 ); 373// base name is rest of filename 374name = name .substr (33 ,name .length ()- 33 ); 375 376//Removing existing temporary zlp and slp files 377if (fileExists (tmpunzlp .c_str ())) { 378remove (tmpunzlp .c_str ()); 379 } 380 381ASSERT (name + ".zlp Exists" ,access (path .c_str (),F_OK )== 0 , 382name <<" does not exist" ); 383BAILONFAIL (1 ); 384 385 slip::Compressor * c = new slip::Compressor (_debug ); 386c -> setOutputFilename (tmpunzlp .c_str ()); 387bool loaded = c -> loadFromFile (path .c_str ()); 388ASSERTNOERR ("Decompressor Loads " + name ,loaded , 389"Decompressor failed to load " <<name ); 390BAILONFAIL (1 ); 391ASSERT ("Compressor Validates " + name ,c -> validate (), 392"Decompressor failed to validate " <<name ); 393BAILONFAIL (1 ); 394c -> saveToFile (false); 395ASSERT ("Compressed File for " + name + " is Generated" ,access (tmpunzlp .c_str (),F_OK )== 0 , 396"Decompressor failed to save compressed output file for " <<name ); 397BAILONFAIL (1 ); 398delete c ; 399 400 std::string test_md5_r = md5file (tmpunzlp .c_str ()); 401ASSERT ("MD5 of restored file for " + name + " is " + test_md5_o ,test_md5_r .compare (test_md5_o )== 0 , 402"MD5 of restored file for " <<name <<" is " <<test_md5_r ); 403 } 404return 0 ; 405} 406 407int testCompressionVersions () { 408 slip::Compressor * c ; 409TSUITE ("All Version Compression" ); 410for (const f_entry & entry :f_iter (PATH (TESTDIR ) /PATH (STANDARDDIR ))) { 411 std::string path = entry .path ().string (); 412 std::string name = entry .path ().stem ().string (); 413//Removing existing temporary zlp and slp files 414if (fileExists (tmpzlp .c_str ())) { 415remove (tmpzlp .c_str ()); 416 } 417if (fileExists (tmpunzlp .c_str ())) { 418remove (tmpunzlp .c_str ()); 419 } 420ASSERT (name + " Exists" ,access (path .c_str (),F_OK )== 0 , 421name <<" does not exist" ); 422NEXTONFAIL (); 423 std::string test_md5_o = md5compressed (path ); 424 425c = new slip::Compressor (_debug ); 426c -> setOutputFilename (tmpzlp .c_str ()); 427bool loaded = c -> loadFromFile ((path ).c_str ()); 428ASSERTNOERR ("Compressor Loads " + name ,loaded , 429"Compressor failed to load " <<name ); 430NEXTONFAIL (); 431ASSERT ("Compressor Validates " + name ,c -> validate (), 432"Compressor failed to validate " <<name ); 433NEXTONFAIL (); 434c -> saveToFile (false); 435ASSERT ("Compressed File for " + name + " is Generated" ,access (tmpzlp .c_str (),F_OK )== 0 , 436"Compressor failed to save compressed output file for " <<name ); 437NEXTONFAIL (); 438delete c ; 439 440c = new slip::Compressor (_debug ); 441ASSERT ("Compressor Loads Compressed " + name ,c -> loadFromFile (tmpzlp .c_str ()), 442"Compressor failed to load compressed " <<name ); 443BAILONFAIL (1 ); 444ASSERT ("Compressor Validates Compressed " + name ,c -> validate (), 445"Compressor failed to validate compressed " <<name ); 446BAILONFAIL (1 ); 447c -> saveToFile (false); 448ASSERT ("In-place Decompressed File is Generated for " + name ,access (tmpunzlp .c_str (),F_OK )== 0 , 449"Compressor failed to save decompressed output file for " <<name ); 450BAILONFAIL (1 ); 451delete c ; 452 453 std::string test_md5_r = md5file (tmpunzlp .c_str ()); 454ASSERT ("MD5 of restored file for " + name + " is " + test_md5_o ,test_md5_r .compare (test_md5_o )== 0 , 455"MD5 of restored file for " <<name <<" is " <<test_md5_r ); 456 } 457return 0 ; 458} 459 460int runtests (int argc ,char ** argv ) { 461if (cmdOptionExists (argv ,argv + argc ,"-h" )) { 462printUsage (); 463return 0 ; 464 } 465 466char * dlevel = getCmdOption (argv ,argv + argc ,"-d" ); 467char * tlevel = getCmdOption (argv ,argv + argc ,"-t" ); 468if (dlevel ) { 469if (dlevel [0 ] >='0' && dlevel [0 ] <='9' ) { 470_debug = dlevel [0 ]- '0' ; 471 }else { 472 std::cerr <<"Warning: invalid debug level" << std::endl ; 473 } 474 } 475int testlevel = 0 ; 476if (tlevel ) { 477if (tlevel [0 ] >='0' && tlevel [0 ] <='9' ) { 478testlevel = tlevel [0 ]- '0' ; 479 }else { 480 std::cerr <<"Warning: invalid test level" << std::endl ; 481 } 482 } 483 484testTestFiles (); 485testKnownFiles (); 486testCorruptFiles (); 487testCompressionBackcompat (); 488testConsistencySanity (); 489if (testlevel >=1 ) { 490testCompressionVersions (); 491 } 492TESTRESULTS (); 493 494return 0 ; 495} 496 497} 498 499int main (int argc ,char ** argv ) { 500return slip::runtests (argc ,argv ); 501}