decode_api_test.cc 2.17 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.
*/

12

James Zern's avatar
James Zern committed
13 14
#include "third_party/googletest/src/include/gtest/gtest.h"

Adrian Grange's avatar
Adrian Grange committed
15
#include "./aom_config.h"
16
#include "test/ivf_video_source.h"
Adrian Grange's avatar
Adrian Grange committed
17
#include "aom/aomdx.h"
Adrian Grange's avatar
Adrian Grange committed
18
#include "aom/aom_decoder.h"
James Zern's avatar
James Zern committed
19 20 21 22 23 24

namespace {

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

TEST(DecodeAPI, InvalidParams) {
Adrian Grange's avatar
Adrian Grange committed
25
  static const aom_codec_iface_t *kCodecs[] = {
26 27
#if CONFIG_AV1_DECODER
    &aom_codec_av1_dx_algo,
James Zern's avatar
James Zern committed
28 29
#endif
  };
clang-format's avatar
clang-format committed
30
  uint8_t buf[1] = { 0 };
Adrian Grange's avatar
Adrian Grange committed
31
  aom_codec_ctx_t dec;
James Zern's avatar
James Zern committed
32

Adrian Grange's avatar
Adrian Grange committed
33 34 35 36 37
  EXPECT_EQ(AOM_CODEC_INVALID_PARAM, aom_codec_dec_init(NULL, NULL, NULL, 0));
  EXPECT_EQ(AOM_CODEC_INVALID_PARAM, aom_codec_dec_init(&dec, NULL, NULL, 0));
  EXPECT_EQ(AOM_CODEC_INVALID_PARAM, aom_codec_decode(NULL, NULL, 0, NULL, 0));
  EXPECT_EQ(AOM_CODEC_INVALID_PARAM, aom_codec_decode(NULL, buf, 0, NULL, 0));
  EXPECT_EQ(AOM_CODEC_INVALID_PARAM,
Adrian Grange's avatar
Adrian Grange committed
38
            aom_codec_decode(NULL, buf, NELEMENTS(buf), NULL, 0));
Adrian Grange's avatar
Adrian Grange committed
39
  EXPECT_EQ(AOM_CODEC_INVALID_PARAM,
Adrian Grange's avatar
Adrian Grange committed
40
            aom_codec_decode(NULL, NULL, NELEMENTS(buf), NULL, 0));
Adrian Grange's avatar
Adrian Grange committed
41
  EXPECT_EQ(AOM_CODEC_INVALID_PARAM, aom_codec_destroy(NULL));
Adrian Grange's avatar
Adrian Grange committed
42
  EXPECT_TRUE(aom_codec_error(NULL) != NULL);
James Zern's avatar
James Zern committed
43 44

  for (int i = 0; i < NELEMENTS(kCodecs); ++i) {
Adrian Grange's avatar
Adrian Grange committed
45
    EXPECT_EQ(AOM_CODEC_INVALID_PARAM,
Adrian Grange's avatar
Adrian Grange committed
46
              aom_codec_dec_init(NULL, kCodecs[i], NULL, 0));
James Zern's avatar
James Zern committed
47

Adrian Grange's avatar
Adrian Grange committed
48 49
    EXPECT_EQ(AOM_CODEC_OK, aom_codec_dec_init(&dec, kCodecs[i], NULL, 0));
    EXPECT_EQ(AOM_CODEC_UNSUP_BITSTREAM,
Adrian Grange's avatar
Adrian Grange committed
50
              aom_codec_decode(&dec, buf, NELEMENTS(buf), 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_decode(&dec, NULL, NELEMENTS(buf), NULL, 0));
Adrian Grange's avatar
Adrian Grange committed
53
    EXPECT_EQ(AOM_CODEC_INVALID_PARAM, aom_codec_decode(&dec, buf, 0, NULL, 0));
James Zern's avatar
James Zern committed
54

Adrian Grange's avatar
Adrian Grange committed
55
    EXPECT_EQ(AOM_CODEC_OK, aom_codec_destroy(&dec));
James Zern's avatar
James Zern committed
56 57 58 59
  }
}

}  // namespace