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
126
127
#include "gate/tests.hpp"
#include "gate/io/videosources.hpp"
#include "gate/graphics/images.hpp"
#include "gate/files.hpp"
#include "gate/environments.hpp"

using namespace gate;
using namespace gate::io;

GATEXX_TEST_UNIT(VideoFrame)
{
    VideoFormat format;
    format.frames_per_second = 30.0f;
    format.width = 640;
    format.height = 480;
    format.bits_per_pixel = 32;

    GATEXX_TEST_CHECK(format.hashCode() != 0);

    {
        const VideoFormat format2(format);
        VideoFormat format3;
        format3 = format2;<--- Variable 'format3' is reassigned a value before the old one has been used.
        format3 = format;<--- Variable 'format3' is reassigned a value before the old one has been used.
        GATEXX_TEST_CHECK_EQUAL(format.encoding_id, format3.encoding_id);
        GATEXX_TEST_CHECK_EQUAL(format.compression, format3.compression);
        GATEXX_TEST_CHECK_EQUAL(format.frames_per_second, format3.frames_per_second);
        GATEXX_TEST_CHECK_EQUAL(format.width, format3.width);
        GATEXX_TEST_CHECK_EQUAL(format.height, format3.height);
        GATEXX_TEST_CHECK_EQUAL(format.bits_per_pixel, format3.bits_per_pixel);
    }

    VideoFrame frame(format);
    GATEXX_TEST_CHECK(frame.c_impl() != NULL);
    GATEXX_TEST_CHECK_NOTHROW(frame.getFormat());
    GATEXX_TEST_CHECK_NOTHROW(frame.getImage());
    GATEXX_TEST_CHECK_NOTHROW(frame.getRecordTime());

    {
        VideoFrame frame2(frame);
        VideoFrame frame3(format);
        frame3 = frame2;
        GATEXX_TEST_CHECK_EQUAL(frame3.getFormat().hashCode(), frame.getFormat().hashCode());
    }
}

GATEXX_TEST_UNIT(VideoSource)
{
    Array<VideoSource> sources;
    GATEXX_TRY_IGNORE(sources = VideoSources::enumSources());

    GATEXX_ENUMERATE(const VideoSource, source, sources.enumerate())
    {
        GATEXX_TEST_CHECK(source->c_impl() != NULL);
    }
}

GATEXX_TEST_UNIT(VideoScreenControl)
{
    GATEXX_TRY_IGNORE(
        VideoScreenControl control;
        control.c_impl();
    )
}

class GATE_API_LOCAL VideoTempFilesFixture
{
public:
    const FilePath testDirectory;
    const String testFile;

    VideoTempFilesFixture()
    :   testDirectory(FilePath(Environment::getTempPath()) / "gatevideotest"),
        testFile((testDirectory / "frames").toString())
    {
        if (File::exists(this->testDirectory))
        {
            GATEXX_TRY_IGNORE(File::removeDirectoryRecursive(this->testDirectory));
        }
        GATEXX_TRY_IGNORE(File::createAllDirectories(this->testDirectory));
    }

    ~VideoTempFilesFixture() noexcept
    {
        GATEXX_TRY_IGNORE(File::removeDirectoryRecursive(this->testDirectory));
    }
};

void test_video_writer(VideoWriter writer, VideoFormat const& format)
{
    GATEXX_TEST_CHECK(writer.c_impl() != NULL);
    GATEXX_TEST_CHECK(!writer.getInterfaceName().empty());

    graph::RasterImage image(format.width, format.height, graph::RasterImage::PixelFormat_rgb32);
    {
        image.clear(graph::Color::White);
        VideoFrame frame(format, image);
        GATEXX_TEST_CHECK_NOTHROW(writer.write(frame));
    }
    {
        image.clear(graph::Color::Yellow);
        VideoFrame frame(format, image);
        GATEXX_TEST_CHECK_NOTHROW(writer.write(frame));
    }
    {
        image.clear(graph::Color::Red);
        VideoFrame frame(format, image);
        GATEXX_TEST_CHECK_NOTHROW(writer.write(frame));
    }
}


GATEXX_TEST_UNIT(VideoWriterJPEG)
{
    VideoTempFilesFixture fixture;
    VideoFormat const format(320, 240, 32, 15.0f);
    VideoWriter writer = VideoFileWriter::create(VideoFileWriter::FileType_JPEG, fixture.testFile, format);
    test_video_writer(writer, format);
}

GATEXX_TEST_UNIT(VideoWriterPNG)
{
    VideoTempFilesFixture fixture;
    VideoFormat const format(320, 240, 32, 15.0f);
    VideoWriter writer = VideoFileWriter::create(VideoFileWriter::FileType_PNG, fixture.testFile, format);
    test_video_writer(writer, format);
}