1 /*
2 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
3 *
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.
10 */
11
12 #include "third_party/googletest/src/googletest/include/gtest/gtest.h"
13
14 #include "config/aom_config.h"
15
16 #include "test/util.h"
17 #include "aom/aomcx.h"
18 #include "aom/aom_encoder.h"
19
20 namespace {
21
TEST(EncodeAPI,InvalidParams)22 TEST(EncodeAPI, InvalidParams) {
23 static const aom_codec_iface_t *kCodecs[] = {
24 #if CONFIG_AV1_ENCODER
25 aom_codec_av1_cx(),
26 #endif
27 };
28 uint8_t buf[1] = { 0 };
29 aom_image_t img;
30 aom_codec_ctx_t enc;
31 aom_codec_enc_cfg_t cfg;
32
33 EXPECT_EQ(&img, aom_img_wrap(&img, AOM_IMG_FMT_I420, 1, 1, 1, buf));
34
35 EXPECT_EQ(AOM_CODEC_INVALID_PARAM, aom_codec_enc_init(NULL, NULL, NULL, 0));
36 EXPECT_EQ(AOM_CODEC_INVALID_PARAM, aom_codec_enc_init(&enc, NULL, NULL, 0));
37 EXPECT_EQ(AOM_CODEC_INVALID_PARAM, aom_codec_encode(NULL, NULL, 0, 0, 0));
38 EXPECT_EQ(AOM_CODEC_INVALID_PARAM, aom_codec_encode(NULL, &img, 0, 0, 0));
39 EXPECT_EQ(AOM_CODEC_INVALID_PARAM, aom_codec_destroy(NULL));
40 EXPECT_EQ(AOM_CODEC_INVALID_PARAM,
41 aom_codec_enc_config_default(NULL, NULL, 0));
42 EXPECT_EQ(AOM_CODEC_INVALID_PARAM,
43 aom_codec_enc_config_default(NULL, &cfg, 0));
44 EXPECT_TRUE(aom_codec_error(NULL) != NULL);
45
46 for (int i = 0; i < NELEMENTS(kCodecs); ++i) {
47 SCOPED_TRACE(aom_codec_iface_name(kCodecs[i]));
48 EXPECT_EQ(AOM_CODEC_INVALID_PARAM,
49 aom_codec_enc_init(NULL, kCodecs[i], NULL, 0));
50 EXPECT_EQ(AOM_CODEC_INVALID_PARAM,
51 aom_codec_enc_init(&enc, kCodecs[i], NULL, 0));
52 EXPECT_EQ(AOM_CODEC_INVALID_PARAM,
53 aom_codec_enc_config_default(kCodecs[i], &cfg, 2));
54
55 EXPECT_EQ(AOM_CODEC_OK, aom_codec_enc_config_default(kCodecs[i], &cfg, 0));
56 EXPECT_EQ(AOM_CODEC_OK, aom_codec_enc_init(&enc, kCodecs[i], &cfg, 0));
57
58 EXPECT_EQ(NULL, aom_codec_get_global_headers(NULL));
59
60 aom_fixed_buf_t *glob_headers = aom_codec_get_global_headers(&enc);
61 EXPECT_TRUE(glob_headers->buf != NULL);
62 if (glob_headers) {
63 free(glob_headers->buf);
64 free(glob_headers);
65 }
66
67 EXPECT_EQ(AOM_CODEC_OK, aom_codec_encode(&enc, NULL, 0, 0, 0));
68
69 EXPECT_EQ(AOM_CODEC_OK, aom_codec_destroy(&enc));
70 }
71 }
72
73 } // namespace
74