Skip to content

Commit

Permalink
Test file updated changes
Browse files Browse the repository at this point in the history
  • Loading branch information
VishwanathB45 committed Jul 14, 2023
1 parent f60c507 commit 23e4ef1
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 48 deletions.
17 changes: 10 additions & 7 deletions base/include/TestSignalGeneratorSrc.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class TestSignalGeneratorProps : public ModuleProps
public:
TestSignalGeneratorProps() {}
TestSignalGeneratorProps(int _width, int _height)
: width(_width), height(_height){}
: width(_width), height(_height) {}

~TestSignalGeneratorProps() {}

Expand All @@ -17,11 +17,11 @@ class TestSignalGeneratorProps : public ModuleProps
friend class boost::serialization::access;

template <class Archive>
void serialize(Archive& ar, const unsigned int version)
void serialize(Archive &ar, const unsigned int version)
{
ar & boost::serialization::base_object<ModuleProps>(*this);
ar & width;
ar & height;
ar &boost::serialization::base_object<ModuleProps>(*this);
ar &width;
ar &height;
}
};

Expand All @@ -33,15 +33,18 @@ class TestSignalGenerator : public Module

bool init();
bool term();
void setProps(TestSignalGeneratorProps& props);
void setProps(TestSignalGeneratorProps &props);
TestSignalGeneratorProps getProps();

protected:
bool produce();
bool validateOutputPins();
void setMetadata(framemetadata_sp& metadata);
void setMetadata(framemetadata_sp &metadata);

private:
class Detail;
boost::shared_ptr<Detail> mDetail;
size_t outputFrameSize;
framemetadata_sp mOutputMetadata;
std::string mOutputPinId;
};
45 changes: 29 additions & 16 deletions base/src/TestSignalGeneratorSrc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
class TestSignalGenerator::Detail
{
public:
Detail(TestSignalGeneratorProps &_props) : mProps(_props), start_shade(0), end_shade(255), current_shade(start_shade){}

Detail(TestSignalGeneratorProps &_props)
: mProps(_props), start_shade(0), end_shade(255), current_shade(start_shade) {}

~Detail() {}

~Detail(){}

bool generate(frame_sp &frame)
{
auto *frame_ptr = frame->data();
Expand All @@ -29,21 +29,33 @@ class TestSignalGenerator::Detail
return true;
}

void setProps(const TestSignalGeneratorProps &_props)
{
mProps = _props;
}
void reset()
{
current_shade = start_shade;
}

TestSignalGeneratorProps mProps;
int start_shade;
int end_shade;
int current_shade;
};

TestSignalGenerator::TestSignalGenerator(TestSignalGeneratorProps _props)
: Module(SOURCE, "TestSignalGenerator", _props)
: Module(SOURCE, "TestSignalGenerator", _props), outputFrameSize(0)
{
mDetail.reset(new Detail(_props));
mOutputMetadata = framemetadata_sp(new RawImagePlanarMetadata(_props.width, _props.height, ImageMetadata::ImageType::YUV420, size_t(0), CV_8U));
mOutputPinId = addOutputPin(mOutputMetadata);
}

TestSignalGenerator::~TestSignalGenerator(){
TestSignalGenerator::~TestSignalGenerator()
{
mDetail->~Detail();
};
}

bool TestSignalGenerator::validateOutputPins()
{
Expand All @@ -56,7 +68,7 @@ bool TestSignalGenerator::validateOutputPins()
auto frameType = metadata->getFrameType();
if (frameType != FrameMetadata::RAW_IMAGE_PLANAR)
{
LOG_ERROR << "<" << getId() << ">::validateOutputPins input frameType is expected to be RAW_IMAGE_PLANAR. Actual<" << frameType << ">";
LOG_ERROR << "<" << getId() << ">::validateOutputPins output frameType should be RAW_IMAGE_PLANAR. Actual<" << frameType << ">";
return false;
}

Expand All @@ -69,15 +81,16 @@ bool TestSignalGenerator::init()
{
return false;
}
outputFrameSize = (getProps().width * getProps().height * 3) >> 1;

return true;
}

bool TestSignalGenerator::produce()
{
size_t read_size = (getProps().width * getProps().height * 3) >> 1;
auto mPinId = getOutputPinIdByType(FrameMetadata::RAW_IMAGE_PLANAR);
frame_container frames;
frame_sp frame = makeFrame(read_size);
frame_sp frame = makeFrame(outputFrameSize);
mDetail->generate(frame);
frames.insert(make_pair(mPinId, frame));
send(frames);
Expand All @@ -97,14 +110,14 @@ void TestSignalGenerator::setMetadata(framemetadata_sp &metadata)
}
}

TestSignalGeneratorProps TestSignalGenerator::getProps()
void TestSignalGenerator::setProps(TestSignalGeneratorProps &_props)
{
return mDetail->mProps;
mDetail->setProps(_props);
outputFrameSize = (_props.width * _props.height * 3) >> 1;
mDetail->reset();
}

void TestSignalGenerator::setProps(TestSignalGeneratorProps& _props)
TestSignalGeneratorProps TestSignalGenerator::getProps()
{
mDetail->mProps = _props;
return mDetail->mProps;
}


45 changes: 20 additions & 25 deletions base/test/testSignalGeneratorSrc_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,9 @@ class SinkModule : public Module
return true;
}
};

BOOST_AUTO_TEST_CASE(Basic)
{
auto source = boost::shared_ptr<TestSignalGenerator>(new TestSignalGenerator(TestSignalGeneratorProps(400, 400)));
auto metadata = framemetadata_sp(new RawImagePlanarMetadata(400, 400, ImageMetadata::ImageType::YUV420, size_t(0), CV_8U));
source->addOutputPin(metadata);
auto sink = boost::shared_ptr<ExternalSinkModule>(new ExternalSinkModule());
source->setNext(sink);
BOOST_TEST(source->init());
Expand All @@ -47,43 +44,41 @@ BOOST_AUTO_TEST_CASE(Basic)
BOOST_TEST(frames.size() == 1);
auto outputFrame = frames.cbegin()->second;
BOOST_TEST(outputFrame->getMetadata()->getFrameType() == FrameMetadata::RAW_IMAGE_PLANAR);
Test_Utils::saveOrCompare("./data/testOutput/TestSample.raw", const_cast<const uint8_t *>(static_cast<uint8_t *>(outputFrame->data())), outputFrame->size(), 0);
Test_Utils::saveOrCompare("./data/TestSample.raw", const_cast<const uint8_t *>(static_cast<uint8_t *>(outputFrame->data())), outputFrame->size(), 0);
}

BOOST_AUTO_TEST_CASE(PropsChange)
BOOST_AUTO_TEST_CASE(getSetProps)
{
auto source = boost::shared_ptr<TestSignalGenerator>(new TestSignalGenerator(TestSignalGeneratorProps(640, 360)));
auto metadata = framemetadata_sp(new RawImagePlanarMetadata(640, 360, ImageMetadata::ImageType::YUV420, size_t(0), CV_8U));
source->addOutputPin(metadata);
auto sink = boost::shared_ptr<SinkModule>(new SinkModule(SinkModuleProps()));
source->setNext(sink);
source->init();
sink->init();
source->step();
auto sinkQue = sink->getQue();
auto framedata = sinkQue->pop();
auto frameMetadata = framedata.begin()->second->getMetadata();
frame_container frames;
frames = sinkQue->pop();
auto frameMetadata = frames.begin()->second->getMetadata();
auto size = frameMetadata->getDataSize() / 1.5;
auto currentProps = source->getProps();
BOOST_ASSERT(size == currentProps.width * currentProps.height);
BOOST_TEST(framedata.size() == 1);
auto outputFrame = framedata.cbegin()->second;
BOOST_TEST(frames.size() == 1);
auto outputFrame = frames.cbegin()->second;
BOOST_TEST(outputFrame->getMetadata()->getFrameType() == FrameMetadata::RAW_IMAGE_PLANAR);
Test_Utils::saveOrCompare("./data/testOutput/TestSample1.raw", const_cast<const uint8_t *>(static_cast<uint8_t *>(outputFrame->data())), outputFrame->size(), 0);
TestSignalGeneratorProps propsChange(400, 400);
source->setProps(propsChange);
source->step();
Test_Utils::saveOrCompare("./data/TestSample1.raw", const_cast<const uint8_t *>(static_cast<uint8_t *>(outputFrame->data())), outputFrame->size(), 0);
TestSignalGeneratorProps newProps(400, 400);
source->setProps(newProps);
source->step();
auto secondque = sink->getQue();
auto framedata2 = secondque->pop();
auto frameMetadata2 = framedata2.begin()->second->getMetadata();
auto size2 = frameMetadata2->getDataSize() / 1.5;
auto currentProps2 = source->getProps();
BOOST_ASSERT(size2 == currentProps2.width * currentProps2.height);
BOOST_TEST(framedata2.size() == 1);
auto outputFrame2 = framedata2.cbegin()->second;
BOOST_TEST(outputFrame2->getMetadata()->getFrameType() == FrameMetadata::RAW_IMAGE_PLANAR);
Test_Utils::saveOrCompare("./data/testOutput/TestSample2.raw", const_cast<const uint8_t *>(static_cast<uint8_t *>(outputFrame2->data())), outputFrame2->size(), 0);
sinkQue = sink->getQue();
frames = sinkQue->pop();
frameMetadata = frames.begin()->second->getMetadata();
size = frameMetadata->getDataSize() / 1.5;
currentProps = source->getProps();
BOOST_ASSERT(size == currentProps.width * currentProps.height);
BOOST_TEST(frames.size() == 1);
outputFrame = frames.cbegin()->second;
BOOST_TEST(outputFrame->getMetadata()->getFrameType() == FrameMetadata::RAW_IMAGE_PLANAR);
Test_Utils::saveOrCompare("./data/TestSample2.raw", const_cast<const uint8_t *>(static_cast<uint8_t *>(outputFrame->data())), outputFrame->size(), 0);
}

BOOST_AUTO_TEST_SUITE_END()
Binary file added data/TestSample.raw
Binary file not shown.
Binary file added data/TestSample1.raw
Binary file not shown.
Binary file added data/TestSample2.raw
Binary file not shown.

0 comments on commit 23e4ef1

Please sign in to comment.