3 #include <gtest/gtest.h>
28 "ljpoaweu9uwat7a9g0ujaW219U0U;DSJGEOPUJGAfPVAPUAS:FGJALGJ7804-85,"
29 "G;AKGPTG[ASIGSFDAS[DFSAPDFJASPFJSPADFJPAJPGAJSGSAGJAPJGAPJGPOIOO";
30 static uint32_t all_ad = 0xf9932612;
31 static uint32_t last64_ad = 0x583e1280;
37 ASSERT_EQ(ad.val(), 1);
38 ASSERT_EQ(ad.
size(), 0);
40 Adler32 ad2(test.data(), test.size());
41 ASSERT_EQ(ad2.val(), all_ad);
42 ASSERT_EQ(ad2.
size(), test.size());
45 TEST(adler32, single_update)
48 ad.
update(test.data(), test.size());
49 ASSERT_EQ(ad.val(), all_ad);
52 TEST(adler32, two_updates)
55 ad.
update(test.data(), test.size()/2);
56 ad.
update(test.data()+test.size()/2, test.size()-test.size()/2);
57 ASSERT_EQ(ad.val(), all_ad);
60 TEST(adler32, second_half_update)
63 ad.
update(test.data()+test.size()/2, test.size()-test.size()/2);
64 ASSERT_EQ(ad.val(), last64_ad);
67 TEST(adler32, update_and_reset)
70 ASSERT_EQ(ad.
update(test.data(), test.size()), all_ad);
71 ASSERT_EQ(ad.
reset(test.data()+test.size()/2, test.size()-test.size()/2), last64_ad);
72 ASSERT_EQ(ad.
reset(), 1);
75 TEST(adler32, combine)
77 Adler32 first(test.data(), test.size()/2),
78 second(test.data()+test.size()/2, test.size()/2);
80 ASSERT_EQ(first.combine(second), all_ad);
83 TEST(adler32, rolling_update)
87 size_t sz = test.size();
89 ad.
reset(test.data(), sz/2);
90 ASSERT_EQ(ad.
size(), 64);
93 for (
size_t i = 0; i < 64; i++)
95 ad.
rotate(test[i], test[64+i]);
97 ASSERT_EQ(ad, last64_ad);
101 TEST(adler32, verify_large_blocks)
111 for (
int blksz = 1; blksz < datasz>>1; blksz <<= 1)
113 cout <<
"testing adler32 rolling checksum for block size: " << blksz << endl;
115 ad.
reset(&dat[0], blksz);
117 for (
int i = 0; i < datasz-blksz; i++)
119 vad.
reset(&dat[i], blksz);
121 ad.
rotate(dat[i], dat[i+blksz]);
Adler32 rolling checksum.
static void rand_bytes(void *, int len)
Generate random bytes.
Adler-32 checksum allowing rolling calculation.
uint32_t rotate(unsigned char, unsigned char)
Update the checksum with next byte.
uint32_t reset()
Reset the checksum.
uint32_t update(const void *, int)
Update the checksum with buffer contents.
int size()
Size of the current window.
TEST(adler32, construct)
[Test vars]