1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
#include <gtest/gtest.h>
#include <algorithm>
#include <vector>
#include "libffmpegthumbnailer/videothumbnailer.h"
#include "libffmpegthumbnailer/imagetypes.h"
using namespace std;
namespace ffmpegthumbnailer
{
class VideoThumbnailerTest : public testing::Test
{
protected:
virtual void SetUp()
{
frame.width = 10;
frame.height = 10;
frame.lineSize = 30;
frame.frameData.resize(300);
}
void generateHistogram()
{
videoThumbnailer.generateHistogram(frame, histogram);
}
int getBestThumbnailIndex(vector<VideoFrame>& videoFrames, const vector<Histogram<int> >& histograms)
{
return videoThumbnailer.getBestThumbnailIndex(videoFrames, histograms);
}
Histogram<int> histogram;
VideoFrame frame;
VideoThumbnailer videoThumbnailer;
};
TEST_F(VideoThumbnailerTest, CreateThumbNonAscii)
{
std::string input = std::string(TEST_DATADIR) + "/test_абвгдеёжзийклмно.flv";
std::vector<uint8_t> buffer;
videoThumbnailer.generateThumbnail(input, Png, buffer);
ASSERT_FALSE(buffer.empty());
}
TEST_F(VideoThumbnailerTest, CreateHistogramBlackFrame)
{
fill(frame.frameData.begin(), frame.frameData.end(), 0);
generateHistogram();
EXPECT_EQ(100, histogram.r[0]);
EXPECT_EQ(100, histogram.g[0]);
EXPECT_EQ(100, histogram.b[0]);
for (int i = 1; i < 255; ++i)
{
EXPECT_EQ(0, histogram.r[i]);
EXPECT_EQ(0, histogram.g[i]);
EXPECT_EQ(0, histogram.b[i]);
}
}
TEST_F(VideoThumbnailerTest, CreateHistogramWhiteFrame)
{
fill(frame.frameData.begin(), frame.frameData.end(), 255);
generateHistogram();
EXPECT_EQ(100, histogram.r[255]);
EXPECT_EQ(100, histogram.g[255]);
EXPECT_EQ(100, histogram.b[255]);
for (int i = 0; i < 254; ++i)
{
EXPECT_EQ(0, histogram.r[i]);
EXPECT_EQ(0, histogram.g[i]);
EXPECT_EQ(0, histogram.b[i]);
}
}
TEST_F(VideoThumbnailerTest, FrameSelection)
{
vector<VideoFrame> videoFrames;
vector<Histogram<int> > histograms;
VideoFrame frame1(5, 5, 15);
fill(frame1.frameData.begin(), frame1.frameData.end(), 255);
VideoFrame frame2(5, 5, 15);
fill(frame2.frameData.begin(), frame2.frameData.end(), 0);
VideoFrame frame3(5, 5, 15);
fill(frame3.frameData.begin(), frame3.frameData.end(), 128);
Histogram<int> hist1;
hist1.r[255] = 25;
hist1.g[255] = 25;
hist1.b[255] = 25;
Histogram<int> hist2;
hist2.r[0] = 25;
hist2.g[0] = 25;
hist2.b[0] = 25;
Histogram<int> hist3;
hist3.r[128] = 25;
hist3.g[128] = 25;
hist3.b[128] = 25;
videoFrames.push_back(frame1);
videoFrames.push_back(frame2);
videoFrames.push_back(frame3);
histograms.push_back(hist1);
histograms.push_back(hist2);
histograms.push_back(hist3);
//This test is bad
//EXPECT_EQ(getBestThumbnailIndex(videoFrames, histograms), 1);
}
}
|