Commit af0c102b authored by Alex Converse's avatar Alex Converse

ans: Add a final state serialization test

Make sure all legal final states can both be serialized an unserialized.

Change-Id: I74d96598a2b206fbc6c82a06649347afb5f9bbd8
parent 8b613216
......@@ -154,7 +154,7 @@ bool check_rans(const std::vector<int> &sym_vec, const rans_sym *const tab,
return ans_read_end(&d) != 0;
}
class AbsTest : public ::testing::Test {
class AbsTestFix : public ::testing::Test {
protected:
static void SetUpTestCase() { pv_vec_ = abs_encode_build_vals(kNumBools); }
virtual void SetUp() { buf_ = new uint8_t[kNumBools / 8]; }
......@@ -163,9 +163,9 @@ class AbsTest : public ::testing::Test {
static PvVec pv_vec_;
uint8_t *buf_;
};
PvVec AbsTest::pv_vec_;
PvVec AbsTestFix::pv_vec_;
class AnsTest : public ::testing::Test {
class AnsTestFix : public ::testing::Test {
protected:
static void SetUpTestCase() {
sym_vec_ = ans_encode_build_vals(rans_sym_tab_, kNumSyms);
......@@ -177,11 +177,30 @@ class AnsTest : public ::testing::Test {
static rans_sym rans_sym_tab_[kRansSymbols];
uint8_t *buf_;
};
std::vector<int> AnsTest::sym_vec_;
rans_sym AnsTest::rans_sym_tab_[kRansSymbols];
std::vector<int> AnsTestFix::sym_vec_;
rans_sym AnsTestFix::rans_sym_tab_[kRansSymbols];
TEST_F(AbsTest, Uabs) { EXPECT_TRUE(check_uabs(pv_vec_, buf_)); }
TEST_F(AnsTest, Rans) {
TEST_F(AbsTestFix, Uabs) { EXPECT_TRUE(check_uabs(pv_vec_, buf_)); }
TEST_F(AnsTestFix, Rans) {
EXPECT_TRUE(check_rans(sym_vec_, rans_sym_tab_, buf_));
}
TEST(AnsTest, FinalStateSerialization) {
for (unsigned i = L_BASE; i < L_BASE * IO_BASE; ++i) {
uint8_t buf[8];
AnsCoder c;
ans_write_init(&c, buf);
c.state = i;
const int written_size = ans_write_end(&c);
ASSERT_LT(static_cast<size_t>(written_size), sizeof(buf));
AnsDecoder d;
#if ANS_MAX_SYMBOLS
// There is no real data window here because no symbols are sent through
// ans (only synthetic states), so use a dummy value
d.window_size = 1024;
#endif
const int read_init_status = ans_read_init(&d, buf, written_size);
EXPECT_EQ(read_init_status, 0);
EXPECT_EQ(d.state, i);
}
}
} // namespace
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment