Skip to content

Commit

Permalink
Add VTBMS stats test
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianFeldmann committed Jul 16, 2024
1 parent 9b9a65d commit e9bd096
Show file tree
Hide file tree
Showing 4 changed files with 454 additions and 60 deletions.
132 changes: 132 additions & 0 deletions YUViewUnitTest/statistics/CheckFunctions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/* This file is part of YUView - The YUV player with advanced analytics toolset
* <https://github.com/IENT/YUView>
* Copyright (C) 2015 Institut für Nachrichtentechnik, RWTH Aachen University, GERMANY
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations including
* the two.
*
* You must obey the GNU General Public License in all respects for all
* of the code used other than OpenSSL. If you modify file(s) with this
* exception, you may extend this exception to your version of the
* file(s), but you are not obligated to do so. If you do not wish to do
* so, delete this exception statement from your version. If you delete
* this exception statement from all source files in the program, then
* also delete it here.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "CheckFunctions.h"

#include "gtest/gtest.h"

namespace yuviewTest::statistics
{

void checkVectorList(const std::vector<stats::StatsItemVector> &vectors,
const std::vector<CheckStatsItem> &checkItems)
{
EXPECT_EQ(vectors.size(), checkItems.size());
for (unsigned i = 0; i < vectors.size(); i++)
{
const auto vec = vectors[i];
const auto chk = checkItems[i];
EXPECT_EQ(unsigned(vec.pos[0]), chk.x);
EXPECT_EQ(unsigned(vec.pos[1]), chk.y);
EXPECT_EQ(unsigned(vec.size[0]), chk.w);
EXPECT_EQ(unsigned(vec.size[1]), chk.h);
EXPECT_EQ(vec.point[0].x, chk.v0);
EXPECT_EQ(vec.point[0].y, chk.v1);
}
}

void checkValueList(const std::vector<stats::StatsItemValue> &values,
const std::vector<CheckStatsItem> &checkItems)
{
EXPECT_EQ(values.size(), checkItems.size());
for (unsigned i = 0; i < values.size(); i++)
{
const auto val = values[i];
const auto chk = checkItems[i];
EXPECT_EQ(unsigned(val.pos[0]), chk.x);
EXPECT_EQ(unsigned(val.pos[1]), chk.y);
EXPECT_EQ(unsigned(val.size[0]), chk.w);
EXPECT_EQ(unsigned(val.size[1]), chk.h);
EXPECT_EQ(val.value, chk.v0);
}
}

void checkAffineTFVectorList(const std::vector<stats::StatsItemAffineTF> &affineTFvectors,
const std::vector<CheckAffineTFItem> &checkItems)
{
EXPECT_EQ(affineTFvectors.size(), checkItems.size());
for (unsigned i = 0; i < affineTFvectors.size(); i++)
{
auto vec = affineTFvectors[i];
auto chk = checkItems[i];
EXPECT_EQ(unsigned(vec.pos[0]), chk.x);
EXPECT_EQ(unsigned(vec.pos[1]), chk.y);
EXPECT_EQ(unsigned(vec.size[0]), chk.w);
EXPECT_EQ(unsigned(vec.size[1]), chk.h);
EXPECT_EQ(vec.point[0].x, chk.v0);
EXPECT_EQ(vec.point[0].y, chk.v1);
EXPECT_EQ(vec.point[1].x, chk.v2);
EXPECT_EQ(vec.point[1].y, chk.v3);
EXPECT_EQ(vec.point[2].x, chk.v4);
EXPECT_EQ(vec.point[2].y, chk.v5);
}
}

void checkLineList(const std::vector<stats::StatsItemVector> &lines,
const std::vector<CheckLineItem> &checkItems)
{
EXPECT_EQ(lines.size(), checkItems.size());
for (unsigned i = 0; i < lines.size(); i++)
{
auto vec = lines[i];
auto chk = checkItems[i];
EXPECT_EQ(unsigned(vec.pos[0]), chk.x);
EXPECT_EQ(unsigned(vec.pos[1]), chk.y);
EXPECT_EQ(unsigned(vec.size[0]), chk.w);
EXPECT_EQ(unsigned(vec.size[1]), chk.h);
EXPECT_EQ(vec.point[0].x, chk.v0);
EXPECT_EQ(vec.point[0].y, chk.v1);
EXPECT_EQ(vec.point[1].x, chk.v2);
EXPECT_EQ(vec.point[1].y, chk.v3);
}
}

void checkPolygonvectorList(const std::vector<stats::StatsItemPolygonVector> &polygonList,
const std::vector<CheckPolygonVectorItem> &checkItems)
{
EXPECT_EQ(polygonList.size(), checkItems.size());
for (unsigned i = 0; i < polygonList.size(); i++)
{
auto polygon = polygonList[i];
auto chk = checkItems[i];
for (unsigned i = 0; i < polygon.corners.size(); i++)
{
auto corner = polygon.corners[i];
EXPECT_EQ(unsigned(corner.x), chk.x[i]);
EXPECT_EQ(unsigned(corner.y), chk.y[i]);
}
EXPECT_EQ(polygon.point.x, chk.v0);
EXPECT_EQ(polygon.point.y, chk.v1);
}
}

} // namespace yuviewTest::statistics
80 changes: 80 additions & 0 deletions YUViewUnitTest/statistics/CheckFunctions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/* This file is part of YUView - The YUV player with advanced analytics toolset
* <https://github.com/IENT/YUView>
* Copyright (C) 2015 Institut für Nachrichtentechnik, RWTH Aachen University, GERMANY
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations including
* the two.
*
* You must obey the GNU General Public License in all respects for all
* of the code used other than OpenSSL. If you modify file(s) with this
* exception, you may extend this exception to your version of the
* file(s), but you are not obligated to do so. If you do not wish to do
* so, delete this exception statement from your version. If you delete
* this exception statement from all source files in the program, then
* also delete it here.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include <statistics/FrameTypeData.h>

namespace yuviewTest::statistics
{

struct CheckStatsItem
{
unsigned x{}, y{}, w{}, h{};
int v0{}, v1{};
};

struct CheckAffineTFItem
{
unsigned x{}, y{}, w{}, h{};
int v0{}, v1{}, v2{}, v3{}, v4{}, v5{};
};

struct CheckLineItem
{
unsigned x{}, y{}, w{}, h{};
int v0{}, v1{}, v2{}, v3{};
};

struct CheckPolygonVectorItem
{
int v0{}, v1{};
unsigned x[5];
unsigned y[5];
};

void checkValueList(const std::vector<stats::StatsItemValue> &values,
const std::vector<CheckStatsItem> &checkItems);

void checkVectorList(const std::vector<stats::StatsItemVector> &vectors,
const std::vector<CheckStatsItem> &checkItems);

void checkAffineTFVectorList(const std::vector<stats::StatsItemAffineTF> &affineTFvectors,
const std::vector<CheckAffineTFItem> &checkItems);

void checkLineList(const std::vector<stats::StatsItemVector> &lines,
const std::vector<CheckLineItem> &checkItems);

void checkPolygonvectorList(const std::vector<stats::StatsItemPolygonVector> &polygonList,
const std::vector<CheckPolygonVectorItem> &checkItems);

} // namespace yuviewTest::statistics
83 changes: 23 additions & 60 deletions YUViewUnitTest/statistics/StatisticsFileCSVTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

#include "gtest/gtest.h"

#include "CheckFunctions.h"

#include <TemporaryFile.h>
#include <statistics/StatisticsFileCSV.h>

Expand Down Expand Up @@ -101,45 +103,6 @@ ByteVector getCSVTestData()
return data;
}

struct CheckStatsItem
{
unsigned x{}, y{}, w{}, h{};
int v0{}, v1{};
};

void checkVectorList(const std::vector<stats::StatsItemVector> &vectors,
const std::vector<CheckStatsItem> &checkItems)
{
EXPECT_EQ(vectors.size(), checkItems.size());
for (unsigned i = 0; i < vectors.size(); i++)
{
const auto vec = vectors[i];
const auto chk = checkItems[i];
EXPECT_EQ(unsigned(vec.pos[0]), chk.x);
EXPECT_EQ(unsigned(vec.pos[1]), chk.y);
EXPECT_EQ(unsigned(vec.size[0]), chk.w);
EXPECT_EQ(unsigned(vec.size[1]), chk.h);
EXPECT_EQ(vec.point[0].x, chk.v0);
EXPECT_EQ(vec.point[0].y, chk.v1);
}
}

void checkValueList(const std::vector<stats::StatsItemValue> &values,
const std::vector<CheckStatsItem> &checkItems)
{
EXPECT_EQ(values.size(), checkItems.size());
for (unsigned i = 0; i < values.size(); i++)
{
const auto val = values[i];
const auto chk = checkItems[i];
EXPECT_EQ(unsigned(val.pos[0]), chk.x);
EXPECT_EQ(unsigned(val.pos[1]), chk.y);
EXPECT_EQ(unsigned(val.size[0]), chk.w);
EXPECT_EQ(unsigned(val.size[1]), chk.h);
EXPECT_EQ(val.value, chk.v0);
}
}

TEST(StatisticsFileCSV, testCSVFileParsing)
{
yuviewTest::TemporaryFile csvFile(getCSVTestData());
Expand Down Expand Up @@ -270,36 +233,36 @@ TEST(StatisticsFileCSV, testCSVFileParsing)
// Now we should get the data
statFile.loadStatisticData(statData, 1, 9);
EXPECT_EQ(statData.getFrameIndex(), 1);
checkVectorList(statData[9].vectorData,
{{0, 32, 8, 16, 1, 0},
{8, 32, 8, 16, 0, 0},
{112, 56, 4, 8, 0, 0},
{116, 56, 4, 8, 0, 0},
{128, 32, 32, 16, 0, 0},
{128, 48, 32, 16, 0, 0}});
yuviewTest::statistics::checkVectorList(statData[9].vectorData,
{{0, 32, 8, 16, 1, 0},
{8, 32, 8, 16, 0, 0},
{112, 56, 4, 8, 0, 0},
{116, 56, 4, 8, 0, 0},
{128, 32, 32, 16, 0, 0},
{128, 48, 32, 16, 0, 0}});
EXPECT_EQ(statData[9].valueData.size(), size_t(0));

statFile.loadStatisticData(statData, 1, 11);
EXPECT_EQ(statData.getFrameIndex(), 1);
checkVectorList(statData[11].vectorData,
{{0, 32, 8, 16, 31, 0},
{8, 32, 8, 16, -33, 0},
{112, 56, 4, 8, -30, 0},
{116, 56, 4, 8, -30, 0},
{128, 32, 32, 16, -31, 0},
{128, 48, 32, 16, -31, 0},
{160, 32, 32, 16, -31, 0}});
yuviewTest::statistics::checkVectorList(statData[11].vectorData,
{{0, 32, 8, 16, 31, 0},
{8, 32, 8, 16, -33, 0},
{112, 56, 4, 8, -30, 0},
{116, 56, 4, 8, -30, 0},
{128, 32, 32, 16, -31, 0},
{128, 48, 32, 16, -31, 0},
{160, 32, 32, 16, -31, 0}});
EXPECT_EQ(statData[11].valueData.size(), size_t(0));

statFile.loadStatisticData(statData, 7, 3);
EXPECT_EQ(statData.getFrameIndex(), 7);
EXPECT_EQ(statData[3].vectorData.size(), size_t(0));
checkValueList(statData[3].valueData,
{{0, 32, 8, 16, 1},
{128, 48, 32, 16, 0},
{384, 0, 64, 64, 0},
{520, 32, 24, 32, 0},
{576, 40, 32, 24, 0}});
yuviewTest::statistics::checkValueList(statData[3].valueData,
{{0, 32, 8, 16, 1},
{128, 48, 32, 16, 0},
{384, 0, 64, 64, 0},
{520, 32, 24, 32, 0},
{576, 40, 32, 24, 0}});
}

} // namespace
Loading

0 comments on commit e9bd096

Please sign in to comment.