-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.cpp
40 lines (34 loc) · 1.14 KB
/
test.cpp
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
#include "sm.hpp"
#include <obvious.hpp>
using namespace sm;
//=====declarations of sm.cpp private pieces under test=====//
unsigned decompress(const Buffer& source, uint32_t offset, Buffer* destination);
void compress(const Buffer& source, Buffer& destination);
//=====helpers=====//
#define COMPDECOMP(UNCOMPRESSED){\
Buffer compressed, decompressed;\
compress(UNCOMPRESSED, compressed);\
decompress(compressed, 0, &decompressed);\
EXPECT(decompressed.size(), UNCOMPRESSED.size())\
for(size_t i=0; i<decompressed.size(); ++i) EXPECT(decompressed[i], UNCOMPRESSED[i])\
}
void pushIncompressible(Buffer& b, unsigned i, uint8_t mask=0){
b.push_back(( i%128)^mask);
b.push_back((128+i/128)^mask);
}
//=====main=====//
int main(){
{
Buffer incompressible;
for(unsigned i=0; i<1025; i+=2) pushIncompressible(incompressible, i);
COMPDECOMP(incompressible);
}
{
Buffer uncompressed;
for(unsigned i=0; i<0x10001; ++i) uncompressed.push_back(0);
for(unsigned i=0; i<4; i+=2) pushIncompressible(uncompressed, i);
for(unsigned i=0; i<1024; ++i) uncompressed.push_back(uncompressed[0x10001+i%8]^0xFFu);
COMPDECOMP(uncompressed);
}
return 0;
}