]> sigrok.org Git - pulseview.git/commitdiff
Tests: Add another unit test for Segment class
authorSoeren Apel <redacted>
Mon, 1 May 2017 13:14:50 +0000 (15:14 +0200)
committerUwe Hermann <redacted>
Fri, 5 May 2017 21:41:27 +0000 (23:41 +0200)
pv/data/segment.hpp
test/data/segment.cpp

index 3305f4c8d3033b7ce05f0b06cfcd98cd4549ae82..7338bd3896f5a055bbe5575b3f06ba514b9cdb90 100644 (file)
@@ -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;
 };
 
index 9a47249e4b5881a173cdf5c1d8a35f2b5963654b..d1c35ee1a34aa2f8ebf94f703b9c1be5167fd3df 100644 (file)
@@ -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));