encode_api_test.cc 2.34 KB
Newer Older
James Zern's avatar
James Zern committed
1
/*
2
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
James Zern's avatar
James Zern committed
3
 *
4 5 6 7 8 9 10 11
 * This source code is subject to the terms of the BSD 2 Clause License and
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
 * was not distributed with this source code in the LICENSE file, you can
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
 * Media Patent License 1.0 was not distributed with this source code in the
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
*/

James Zern's avatar
James Zern committed
12 13 14

#include "third_party/googletest/src/include/gtest/gtest.h"

Adrian Grange's avatar
Adrian Grange committed
15
#include "./aom_config.h"
Adrian Grange's avatar
Adrian Grange committed
16
#include "aom/aomcx.h"
Adrian Grange's avatar
Adrian Grange committed
17
#include "aom/aom_encoder.h"
James Zern's avatar
James Zern committed
18 19 20 21 22 23

namespace {

#define NELEMENTS(x) static_cast<int>(sizeof(x) / sizeof(x[0]))

TEST(EncodeAPI, InvalidParams) {
Adrian Grange's avatar
Adrian Grange committed
24
  static const aom_codec_iface_t *kCodecs[] = {
25 26
#if CONFIG_AV1_ENCODER
    &aom_codec_av1_cx_algo,
James Zern's avatar
James Zern committed
27 28 29
#endif
  };
  uint8_t buf[1] = { 0 };
Adrian Grange's avatar
Adrian Grange committed
30 31 32
  aom_image_t img;
  aom_codec_ctx_t enc;
  aom_codec_enc_cfg_t cfg;
James Zern's avatar
James Zern committed
33

Adrian Grange's avatar
Adrian Grange committed
34
  EXPECT_EQ(&img, aom_img_wrap(&img, AOM_IMG_FMT_I420, 1, 1, 1, buf));
James Zern's avatar
James Zern committed
35

Adrian Grange's avatar
Adrian Grange committed
36 37 38 39 40 41
  EXPECT_EQ(AOM_CODEC_INVALID_PARAM, aom_codec_enc_init(NULL, NULL, NULL, 0));
  EXPECT_EQ(AOM_CODEC_INVALID_PARAM, aom_codec_enc_init(&enc, NULL, NULL, 0));
  EXPECT_EQ(AOM_CODEC_INVALID_PARAM, aom_codec_encode(NULL, NULL, 0, 0, 0, 0));
  EXPECT_EQ(AOM_CODEC_INVALID_PARAM, aom_codec_encode(NULL, &img, 0, 0, 0, 0));
  EXPECT_EQ(AOM_CODEC_INVALID_PARAM, aom_codec_destroy(NULL));
  EXPECT_EQ(AOM_CODEC_INVALID_PARAM,
Adrian Grange's avatar
Adrian Grange committed
42
            aom_codec_enc_config_default(NULL, NULL, 0));
Adrian Grange's avatar
Adrian Grange committed
43
  EXPECT_EQ(AOM_CODEC_INVALID_PARAM,
Adrian Grange's avatar
Adrian Grange committed
44 45
            aom_codec_enc_config_default(NULL, &cfg, 0));
  EXPECT_TRUE(aom_codec_error(NULL) != NULL);
James Zern's avatar
James Zern committed
46 47

  for (int i = 0; i < NELEMENTS(kCodecs); ++i) {
Adrian Grange's avatar
Adrian Grange committed
48
    SCOPED_TRACE(aom_codec_iface_name(kCodecs[i]));
Adrian Grange's avatar
Adrian Grange committed
49
    EXPECT_EQ(AOM_CODEC_INVALID_PARAM,
Adrian Grange's avatar
Adrian Grange committed
50
              aom_codec_enc_init(NULL, kCodecs[i], NULL, 0));
Adrian Grange's avatar
Adrian Grange committed
51
    EXPECT_EQ(AOM_CODEC_INVALID_PARAM,
Adrian Grange's avatar
Adrian Grange committed
52
              aom_codec_enc_init(&enc, kCodecs[i], NULL, 0));
Adrian Grange's avatar
Adrian Grange committed
53
    EXPECT_EQ(AOM_CODEC_INVALID_PARAM,
Adrian Grange's avatar
Adrian Grange committed
54
              aom_codec_enc_config_default(kCodecs[i], &cfg, 1));
James Zern's avatar
James Zern committed
55

Adrian Grange's avatar
Adrian Grange committed
56 57 58
    EXPECT_EQ(AOM_CODEC_OK, aom_codec_enc_config_default(kCodecs[i], &cfg, 0));
    EXPECT_EQ(AOM_CODEC_OK, aom_codec_enc_init(&enc, kCodecs[i], &cfg, 0));
    EXPECT_EQ(AOM_CODEC_OK, aom_codec_encode(&enc, NULL, 0, 0, 0, 0));
James Zern's avatar
James Zern committed
59

Adrian Grange's avatar
Adrian Grange committed
60
    EXPECT_EQ(AOM_CODEC_OK, aom_codec_destroy(&enc));
James Zern's avatar
James Zern committed
61 62 63 64
  }
}

}  // namespace