From: Soeren Apel Date: Mon, 1 May 2017 13:14:50 +0000 (+0200) Subject: Tests: Add another unit test for Segment class X-Git-Tag: pulseview-0.4.0~90 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=207ae8f6fb0b7a797349916afcd70e1add1b4d20;p=pulseview.git Tests: Add another unit test for Segment class --- diff --git a/pv/data/segment.hpp b/pv/data/segment.hpp index 3305f4c8..7338bd38 100644 --- a/pv/data/segment.hpp +++ b/pv/data/segment.hpp @@ -39,6 +39,7 @@ struct MediumSize32Single; struct MaxSize32Single; struct MediumSize32Multi; struct MaxSize32Multi; +struct MaxSize32MultiAtOnce; struct MaxSize32MultiIterated; } // namespace SegmentTest @@ -101,6 +102,7 @@ protected: friend struct SegmentTest::MaxSize32Single; friend struct SegmentTest::MediumSize32Multi; friend struct SegmentTest::MaxSize32Multi; + friend struct SegmentTest::MaxSize32MultiAtOnce; friend struct SegmentTest::MaxSize32MultiIterated; }; diff --git a/test/data/segment.cpp b/test/data/segment.cpp index 9a47249e..d1c35ee1 100644 --- a/test/data/segment.cpp +++ b/test/data/segment.cpp @@ -233,6 +233,36 @@ BOOST_AUTO_TEST_CASE(MaxSize32Multi) delete[] sample_data; } +BOOST_AUTO_TEST_CASE(MaxSize32MultiAtOnce) +{ + Segment s(1, sizeof(uint32_t)); + + // Chunk size is num*unit_size, so with pv::data::Segment::MaxChunkSize/unit_size, we reach the maximum size + uint32_t num_samples = 3*(pv::data::Segment::MaxChunkSize / sizeof(uint32_t)); + + //----- Add all samples, requiring multiple chunks, in one call ----// + uint32_t *data = new uint32_t[num_samples]; + for (uint32_t i = 0; i < num_samples; i++) + data[i] = i; + + s.append_samples(data, num_samples); + delete[] data; + + BOOST_CHECK(s.get_sample_count() == num_samples); + + for (uint32_t i = 0; i < num_samples; i++) { + uint8_t* sample_data = s.get_raw_samples(i, 1); + BOOST_CHECK_EQUAL(*((uint32_t*)sample_data), i); + delete[] sample_data; + } + + uint8_t* sample_data = s.get_raw_samples(0, num_samples); + for (uint32_t i = 0; i < num_samples; i++) { + BOOST_CHECK_EQUAL(*((uint32_t*)(sample_data + i * sizeof(uint32_t))), i); + } + delete[] sample_data; +} + BOOST_AUTO_TEST_CASE(MaxSize32MultiIterated) { Segment s(1, sizeof(uint32_t));