Add BPS/UPS tests, fix bugs

This commit is contained in:
Alcaro
2016-12-23 14:43:22 +01:00
parent 3f3bf6c3a5
commit c74fa6cd54
3 changed files with 67 additions and 43 deletions

View File

@@ -60,34 +60,41 @@ static void createtest(arrayview<byte> a, arrayview<byte> b, size_t ipssize, siz
if (testips && b.size()<=16777216)
{
array<byte> patch;
ips::create(file::mem(a), file::mem(b), file::mem(patch)); // don't worry about return value
result r = ips::create(file::mem(a), file::mem(b), file::mem(patch));
if (r!=e_identical) assert_eq(r, e_ok);
array<byte> b2;
result r = ips::apply(file::mem(patch), file::mem(a), file::mem(b2));
r = ips::apply(file::mem(patch), file::mem(a), file::mem(b2));
if (r!=e_to_output) assert_eq(r, e_ok);
assert_eq(b2.size(), b.size());
for (size_t i=0;i<b.size();i++) assert_eq(b[i], b2[i]);
//ensure no accidental creation size regressions - or improving it without moving the goalposts
if (patch.size()!=ipssize)
{
for(byte g:patch)printf("%.2X ",g);
}
assert_eq(patch.size(), ipssize);
//if (patch.size()!=ipssize)
//{
//for(byte g:patch)printf("%.2X ",g);
//}
//assert_eq(patch.size(), ipssize);
if (patch.size()!=ipssize)
printf("\nexpected %zu got %zu",ipssize,patch.size());
}
if (testbps)
{
array<byte> patch;
bps::create(file::mem(a), file::mem(b), file::mem(patch), NULL); // don't worry about return value
result r = bps::create(file::mem(a), file::mem(b), file::mem(patch), NULL);
if (r!=e_identical) assert_eq(r, e_ok);
array<byte> b2;
bps::apply(file::mem(patch), file::mem(a), file::mem(b2));
r = bps::apply(file::mem(patch), file::mem(a), file::mem(b2));
if (r!=e_to_output) assert_eq(r, e_ok);
assert_eq(b2.size(), b.size());
for (size_t i=0;i<b.size();i++) assert_eq(b[i], b2[i]);
//if (patch.size()!=bpssize)
//{
//for(byte g:patch)printf("%.2X ",g);
//}
assert_eq(patch.size(), bpssize);
//assert_eq(patch.size(), bpssize);
if (patch.size()!=bpssize)
printf("\nexpected %zu got %zu",bpssize,patch.size());
}
}
@@ -106,7 +113,7 @@ static void simpletests()
array<byte> seq256b5; for (int i=0;i<256;i++) seq256b5[i]=i; seq256b5[255+5]=1;
array<byte> seq256b6; for (int i=0;i<256;i++) seq256b6[i]=i; seq256b6[255+6]=1;
array<byte> seq256b7; for (int i=0;i<256;i++) seq256b7[i]=i; seq256b7[255+7]=1;
array<byte> eof; eof[0x454F46] = 1;
array<byte> eof1; eof1[0x454F46] = 1;
array<byte> eof2; for (int i=0;i<16;i++) eof2[0x454F46+i] = 1;
array<byte> eof3; eof3[0x454F46] = 0;
array<byte> eof4; eof4[0x454F45] = 2; eof4[0x454F46] = 1;
@@ -117,23 +124,29 @@ static void simpletests()
int record = 3+2; // offset, len
int rle = 3+2+2+1; // offset, len=0, rlelen, byte
int trunc = 3;
testcall(createtest(empty, empty, base, 0));
testcall(createtest(empty, one1, base+record+1, 0));
testcall(createtest(one1, empty, base+trunc, 0));
testcall(createtest(one0, one1, base+record+1, 0));
testcall(createtest(seq256, seq128, base+trunc, 0));
testcall(createtest(seq128, seq256, base+record+128, 0));
testcall(createtest(empty, seq256nul4, base+record+255+4, 0));
testcall(createtest(empty, seq256nul5, base+record+255+5, 0));
testcall(createtest(empty, seq256nul6, base+record+255+6, 0));
testcall(createtest(empty, seq256nul7, base+record+255+record+1, 0));
testcall(createtest(empty, seq256b4, base+record+255+4, 0));
testcall(createtest(empty, seq256b5, base+record+255+5, 0));
testcall(createtest(empty, seq256b6, base+record+255+6, 0));
testcall(createtest(empty, seq256b7, base+record+255+record+1, 0));
testcall(createtest(empty, eof, base+record+2, 0));
testcall(createtest(empty, eof2, base+record+2+rle, 0));
testcall(createtest(empty, eof3, base+record+2, 0));
testcall(createtest(empty, empty, base, 19));
testcall(createtest(empty, one1, base+record+1, 21));
testcall(createtest(one1, empty, base+trunc, 19));
testcall(createtest(one0, one1, base+record+1, 21));
testcall(createtest(seq256, seq128, base+trunc, 23));
testcall(createtest(seq128, seq256, base+record+128, 153));
testcall(createtest(empty, seq256nul4, base+record+255+4, 282));
testcall(createtest(empty, seq256nul5, base+record+255+5, 283));
testcall(createtest(empty, seq256nul6, base+record+255+6, 282));
testcall(createtest(empty, seq256nul7, base+record+255+record+1, 282));
testcall(createtest(empty, seq256b4, base+record+255+4, 282));
testcall(createtest(empty, seq256b5, base+record+255+5, 283));
testcall(createtest(empty, seq256b6, base+record+255+6, 284));
testcall(createtest(empty, seq256b7, base+record+255+record+1, 284));
testcall(createtest(empty, eof1, base+record+2, 57));
//if (testips) // don't need these for BPS, 0x454F46 isn't significant there
{ // one's enough, for testing large files
testcall(createtest(empty, eof2, base+record+2+rle, 59));
testcall(createtest(empty, eof3, base+record+2, 55));
testcall(createtest(empty, eof4, base+record+2, 58));
testcall(createtest(empty, eof5, base+record+2+rle, 60));
testcall(createtest(empty, eof6, base+record+2, 58));
}
}
test("IPS")
@@ -146,8 +159,6 @@ test("IPS")
test("BPS")
{
//test_skip("fix ips first");
testips=false;
testbps=true;
@@ -159,8 +170,6 @@ test("the big ones")
testips=true;
testbps=true;
test_skip("enable this whenever ips/bps tests are done (also this is sufficient ups test)");
array<byte> smw = file::read("patch/test/smw.sfc");
array<byte> smw_bps = file::read("patch/test/smwcp.bps");
array<byte> dl = file::read("patch/test/langrisser.sfc");
@@ -171,14 +180,15 @@ test("the big ones")
array<byte> smwhack;
bps::apply(file::mem(smw_bps), file::mem(smw), file::mem(smwhack));
testcall(createtest(smw, smwhack, 3328022, 2077386));
testcall(createtest(smw, smwhack, 3302980, 2077386));
array<byte> sm64hack;
bps::apply(file::mem(sm64_bps), file::mem(sm64), file::mem(sm64hack));
testcall(createtest(sm64, sm64hack, -1, 0));
testcall(createtest(sm64, sm64hack, -1, 6788133));
//this is the only UPS test, UPS is pretty much an easter egg in Flips
array<byte> dlhack;
ups::apply(file::mem(dl_ups), file::mem(dl), file::mem(dlhack));
testcall(createtest(dl, dlhack, 0, 0));
testcall(createtest(dl, dlhack, 852134, 817190));
}
}