Blame encoder/vaapiencoder_host_unittest.cpp

Packit 1244b8
/*
Packit 1244b8
 * Copyright 2016 Intel Corporation
Packit 1244b8
 *
Packit 1244b8
 * Licensed under the Apache License, Version 2.0 (the "License");
Packit 1244b8
 * you may not use this file except in compliance with the License.
Packit 1244b8
 * You may obtain a copy of the License at
Packit 1244b8
 *
Packit 1244b8
 *     http://www.apache.org/licenses/LICENSE-2.0
Packit 1244b8
 *
Packit 1244b8
 * Unless required by applicable law or agreed to in writing, software
Packit 1244b8
 * distributed under the License is distributed on an "AS IS" BASIS,
Packit 1244b8
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Packit 1244b8
 * See the License for the specific language governing permissions and
Packit 1244b8
 * limitations under the License.
Packit 1244b8
 */
Packit 1244b8
Packit 1244b8
#ifdef HAVE_CONFIG_H
Packit 1244b8
#include "config.h"
Packit 1244b8
#endif
Packit 1244b8
Packit 1244b8
//
Packit 1244b8
// The unittest header must be included before va_x11.h (which might be included
Packit 1244b8
// indirectly).  The va_x11.h includes Xlib.h and X.h.  And the X headers
Packit 1244b8
// define 'Bool' and 'None' preprocessor types.  Gtest uses the same names
Packit 1244b8
// to define some struct placeholders.  Thus, this creates a compile conflict
Packit 1244b8
// if X defines them before gtest.  Hence, the include order requirement here
Packit 1244b8
// is the only fix for this right now.
Packit 1244b8
//
Packit 1244b8
// See bug filed on gtest at https://github.com/google/googletest/issues/371
Packit 1244b8
// for more details.
Packit 1244b8
//
Packit 1244b8
#include "common/unittest.h"
Packit 1244b8
Packit 1244b8
// primary header
Packit 1244b8
#include "VideoEncoderHost.h"
Packit 1244b8
Packit 1244b8
// system headers
Packit 1244b8
#include <algorithm>
Packit 1244b8
#include <string>
Packit 1244b8
#include <set>
Packit 1244b8
Packit 1244b8
namespace YamiMediaCodec {
Packit 1244b8
Packit 1244b8
std::set<std::string>& expectations()
Packit 1244b8
{
Packit 1244b8
    static std::set<std::string> e;
Packit 1244b8
Packit 1244b8
#if __BUILD_H264_ENCODER__
Packit 1244b8
    e.insert(YAMI_MIME_H264);
Packit 1244b8
    e.insert(YAMI_MIME_AVC);
Packit 1244b8
#endif
Packit 1244b8
Packit 1244b8
#if __BUILD_H265_ENCODER__
Packit 1244b8
    e.insert(YAMI_MIME_H265);
Packit 1244b8
    e.insert(YAMI_MIME_HEVC);
Packit 1244b8
#endif
Packit 1244b8
Packit 1244b8
#if __BUILD_VP8_ENCODER__
Packit 1244b8
    e.insert(YAMI_MIME_VP8);
Packit 1244b8
#endif
Packit 1244b8
Packit 1244b8
#if __BUILD_VP9_ENCODER__
Packit 1244b8
    e.insert(YAMI_MIME_VP9);
Packit 1244b8
#endif
Packit 1244b8
Packit 1244b8
#if __BUILD_JPEG_ENCODER__
Packit 1244b8
    e.insert(YAMI_MIME_JPEG);
Packit 1244b8
#endif
Packit 1244b8
Packit 1244b8
    return e;
Packit 1244b8
}
Packit 1244b8
Packit 1244b8
class VaapiEncoderHostTest
Packit 1244b8
    : public ::testing::TestWithParam<std::string>
Packit 1244b8
{ };
Packit 1244b8
Packit 1244b8
TEST_P(VaapiEncoderHostTest, createVideoEncoder)
Packit 1244b8
{
Packit 1244b8
    std::string mime = GetParam();
Packit 1244b8
    IVideoEncoder *encoder = createVideoEncoder(mime.c_str());
Packit 1244b8
    bool expect = expectations().count(mime) != 0;
Packit 1244b8
Packit 1244b8
    EXPECT_EQ(expect, (encoder != NULL))
Packit 1244b8
        << "createVideoEncoder(" << mime << "): "
Packit 1244b8
        << "did not " << (expect ? "SUCCEED" : "FAIL")
Packit 1244b8
        << " as it should have.";
Packit 1244b8
Packit 1244b8
    releaseVideoEncoder(encoder);
Packit 1244b8
}
Packit 1244b8
Packit 1244b8
TEST_P(VaapiEncoderHostTest, getVideoEncoderMimeTypesContains)
Packit 1244b8
{
Packit 1244b8
    std::string mime = GetParam();
Packit 1244b8
    std::vector<std::string> avail = getVideoEncoderMimeTypes();
Packit 1244b8
Packit 1244b8
    bool expect = expectations().count(mime) != 0;
Packit 1244b8
    bool actual = std::find(avail.begin(), avail.end(), mime) != avail.end();
Packit 1244b8
Packit 1244b8
    EXPECT_EQ( expect, actual );
Packit 1244b8
}
Packit 1244b8
Packit 1244b8
INSTANTIATE_TEST_CASE_P(
Packit 1244b8
    MimeType, VaapiEncoderHostTest,
Packit 1244b8
    ::testing::Values(
Packit 1244b8
        YAMI_MIME_H264, YAMI_MIME_AVC, YAMI_MIME_H265, YAMI_MIME_HEVC,
Packit 1244b8
        YAMI_MIME_MPEG2, YAMI_MIME_VC1, YAMI_MIME_VP8, YAMI_MIME_VP9,
Packit 1244b8
        YAMI_MIME_JPEG));
Packit 1244b8
}