From 910b16ec9fb9bce36311620164eb08218fda29b1 Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Sat, 29 Sep 2012 09:14:29 +0100 Subject: [PATCH] Added LongPulses test --- logicdatasnapshot.h | 2 + test/logicdatasnapshot.cpp | 83 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) diff --git a/logicdatasnapshot.h b/logicdatasnapshot.h index 974aff6c..f3c637cb 100644 --- a/logicdatasnapshot.h +++ b/logicdatasnapshot.h @@ -28,6 +28,7 @@ namespace LogicDataSnapshotTest { class Basic; class LargeData; class Pulses; + class LongPulses; } class LogicDataSnapshot : public DataSnapshot @@ -92,4 +93,5 @@ private: friend class LogicDataSnapshotTest::Basic; friend class LogicDataSnapshotTest::LargeData; friend class LogicDataSnapshotTest::Pulses; + friend class LogicDataSnapshotTest::LongPulses; }; diff --git a/test/logicdatasnapshot.cpp b/test/logicdatasnapshot.cpp index 2c24bd3c..9d647e6c 100644 --- a/test/logicdatasnapshot.cpp +++ b/test/logicdatasnapshot.cpp @@ -328,4 +328,87 @@ BOOST_AUTO_TEST_CASE(Pulses) BOOST_CHECK_EQUAL(edges[i].second, false); } +BOOST_AUTO_TEST_CASE(LongPulses) +{ + const int Cycles = 3; + const int Period = 64; + const int PulseWidth = 16; + const int Length = Cycles * Period; + + int j; + vector edges; + + //----- Create a LogicDataSnapshot -----// + sr_datafeed_logic logic; + logic.unitsize = 1; + logic.length = Length; + logic.data = (uint64_t*)new uint8_t[Length]; + uint8_t *p = (uint8_t*)logic.data; + + for(int i = 0; i < Cycles; i++) { + for(j = 0; j < PulseWidth; j++) + *p++ = 0xFF; + for(j; j < Period; j++) + *p++ = 0x00; + } + + LogicDataSnapshot s(logic); + + //----- Check the mip-map -----// + // Check mip map level 0 + BOOST_CHECK_EQUAL(s._mip_map[0].length, 12); + BOOST_CHECK_EQUAL(s._mip_map[0].data_length, + LogicDataSnapshot::MipMapDataUnit); + BOOST_REQUIRE(s._mip_map[0].data != NULL); + + for(int i = 0; i < s._mip_map[0].length;) { + for(j = 0; i < s._mip_map[0].length && j < 2; j++) { + BOOST_TEST_MESSAGE( + "Testing mip_map[0].data[" << i << "]"); + BOOST_CHECK_EQUAL(s.get_subsample(0, i++) & 0xFF, 0xFF); + } + + for(j; i < s._mip_map[0].length && + j < Period/LogicDataSnapshot::MipMapScaleFactor; j++) { + BOOST_TEST_MESSAGE( + "Testing mip_map[0].data[" << i << "]"); + BOOST_CHECK_EQUAL(s.get_subsample(0, i++) & 0xFF, 0x00); + } + } + + // Check the higher levels are all inactive + for(int i = 1; i < LogicDataSnapshot::ScaleStepCount; i++) { + const LogicDataSnapshot::MipMapLevel &m = s._mip_map[i]; + BOOST_CHECK_EQUAL(m.length, 0); + BOOST_CHECK_EQUAL(m.data_length, 0); + BOOST_CHECK(m.data == NULL); + } + + //----- Test get_subsampled_edges at a full scale -----// + s.get_subsampled_edges(edges, 0, Length-1, 16.0f, 2); + BOOST_REQUIRE_EQUAL(edges.size(), Cycles * 2 + 1); + + for(int i = 0; i < Cycles; i++) { + BOOST_CHECK_EQUAL(edges[i*2].first, i * Period); + BOOST_CHECK_EQUAL(edges[i*2].second, true); + BOOST_CHECK_EQUAL(edges[i*2+1].first, i * Period + PulseWidth); + BOOST_CHECK_EQUAL(edges[i*2+1].second, false); + } + + BOOST_CHECK_EQUAL(edges.back().first, Length-1); + BOOST_CHECK_EQUAL(edges.back().second, false); + + //----- Test get_subsampled_edges at a simplified scale -----// + edges.clear(); + s.get_subsampled_edges(edges, 0, Length-1, 17.0f, 2); + + for(int i = 0; i < Cycles; i++) { + BOOST_CHECK_EQUAL(edges[i].first, i * Period); + BOOST_CHECK_EQUAL(edges[i].second, false); + } + + BOOST_CHECK_EQUAL(edges.back().first, Length-1); + BOOST_CHECK_EQUAL(edges.back().second, false); +} + BOOST_AUTO_TEST_SUITE_END() -- 2.30.2