cdef(highbd): Remove unnecessary loop code.
[aom.git] / test / av1_key_value_api_test.cc
blob058b8ce443d3295a6586906e21d88d8e213045f6
1 /*
2 * Copyright (c) 2021, Alliance for Open Media. All rights reserved
4 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
12 #include <cstring>
13 #include <tuple>
15 #include "aom/aom_codec.h"
16 #include "aom/aom_decoder.h"
17 #include "aom/aom_encoder.h"
18 #include "aom/aomcx.h"
19 #include "aom/aomdx.h"
20 #include "config/aom_config.h"
21 #include "third_party/googletest/src/googletest/include/gtest/gtest.h"
23 namespace {
24 typedef std::tuple<const char *, const char *> KeyValParam;
26 class BaseKeyValAPI : public testing::Test {
27 public:
28 void SetUp() override {
29 #if CONFIG_AV1_ENCODER
30 aom_codec_iface_t *iface_cx = aom_codec_av1_cx();
31 aom_codec_enc_cfg_t enc_cfg;
32 #if CONFIG_REALTIME_ONLY
33 const int usage = 1;
34 #else
35 const int usage = 0;
36 #endif
37 EXPECT_EQ(AOM_CODEC_OK,
38 aom_codec_enc_config_default(iface_cx, &enc_cfg, usage));
39 EXPECT_EQ(AOM_CODEC_OK,
40 aom_codec_enc_init(&enc_, iface_cx, &enc_cfg, usage));
41 #endif
42 #if CONFIG_AV1_DECODER
43 aom_codec_iface_t *iface_dx = aom_codec_av1_dx();
44 aom_codec_dec_cfg_t dec_cfg = { 0, 0, 0, !FORCE_HIGHBITDEPTH_DECODING };
46 EXPECT_EQ(AOM_CODEC_OK, aom_codec_dec_init(&dec_, iface_dx, &dec_cfg, 0));
47 #endif
50 void TearDown() override {
51 #if CONFIG_AV1_ENCODER
52 EXPECT_EQ(AOM_CODEC_OK, aom_codec_destroy(&enc_));
53 #endif
54 #if CONFIG_AV1_DECODER
55 EXPECT_EQ(AOM_CODEC_OK, aom_codec_destroy(&dec_));
56 #endif
59 protected:
60 #if CONFIG_AV1_ENCODER
61 aom_codec_ctx_t enc_;
62 #endif
63 #if CONFIG_AV1_DECODER
64 aom_codec_ctx_t dec_;
65 #endif
68 // Tests on encoder options.
69 // Need to add ones for the decoder in the future if it is also supported in the
70 // key & value API.
71 #if CONFIG_AV1_ENCODER
72 class EncValidTest : public BaseKeyValAPI,
73 public testing::WithParamInterface<KeyValParam> {};
74 class EncInvalidTest : public BaseKeyValAPI,
75 public testing::WithParamInterface<KeyValParam> {};
77 TEST_P(EncValidTest, Valid) {
78 const char *key = std::get<0>(GetParam());
79 const char *val = std::get<1>(GetParam());
80 EXPECT_EQ(AOM_CODEC_OK, aom_codec_set_option(&enc_, key, val));
83 TEST_P(EncInvalidTest, NullArg) {
84 const char *key = std::get<0>(GetParam());
85 const char *val = std::get<1>(GetParam());
86 EXPECT_EQ(AOM_CODEC_INVALID_PARAM, aom_codec_set_option(nullptr, key, val));
87 EXPECT_EQ(AOM_CODEC_INVALID_PARAM, aom_codec_set_option(&enc_, nullptr, val));
88 EXPECT_EQ(AOM_CODEC_INVALID_PARAM, aom_codec_set_option(&enc_, key, nullptr));
91 TEST_P(EncInvalidTest, InvalidParam) {
92 const char *key = std::get<0>(GetParam());
93 const char *val = std::get<1>(GetParam());
94 EXPECT_EQ(AOM_CODEC_INVALID_PARAM, aom_codec_set_option(&enc_, key, val));
95 ASSERT_NE(aom_codec_error_detail(&enc_), nullptr);
96 EXPECT_GT(strlen(aom_codec_error_detail(&enc_)), 0u);
99 // No test for ratio / list for now since the API does not support any of the
100 // parameters of these type.
101 // The string type typically involves reading a path/file, which brings
102 // potential fails.
103 const KeyValParam enc_valid_params[] = {
104 std::make_tuple("min-gf-interval", "10"), // uint
105 std::make_tuple("min-partition-size", "4"), // int
106 std::make_tuple("tune", "psnr"), // enum
109 const KeyValParam enc_invalid_params[] = {
110 // no match
111 std::make_tuple("a-b-c", "10"),
112 // uint
113 std::make_tuple("min-gf-interval", "-1"),
114 std::make_tuple("min-gf-interval", "1.1"),
115 std::make_tuple("min-gf-interval", "abc"),
116 // int
117 std::make_tuple("min-partition-size", "1.1"),
118 std::make_tuple("min-partition-size", "abc"),
119 // enum
120 std::make_tuple("tune", "PsnR1"),
121 // out of range
122 std::make_tuple("cq-level", "1000"),
125 INSTANTIATE_TEST_SUITE_P(KeyValAPI, EncValidTest,
126 testing::ValuesIn(enc_valid_params));
128 INSTANTIATE_TEST_SUITE_P(KeyValAPI, EncInvalidTest,
129 testing::ValuesIn(enc_invalid_params));
130 #endif // CONFIG_AV1_ENCODER
132 } // namespace