decode_api_test.cc 2.05 KB
Newer Older
James Zern's avatar
James Zern committed
1 2 3 4 5 6 7 8 9
/*
 *  Copyright (c) 2014 The WebM project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */
10

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

Adrian Grange's avatar
Adrian Grange committed
13
#include "./aom_config.h"
14
#include "test/ivf_video_source.h"
Yaowu Xu's avatar
Yaowu Xu committed
15
#include "aom/vp8dx.h"
Adrian Grange's avatar
Adrian Grange committed
16
#include "aom/aom_decoder.h"
James Zern's avatar
James Zern committed
17 18 19 20 21 22

namespace {

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

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

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

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

Adrian Grange's avatar
Adrian Grange committed
46
    EXPECT_EQ(VPX_CODEC_OK, aom_codec_dec_init(&dec, kCodecs[i], NULL, 0));
James Zern's avatar
James Zern committed
47
    EXPECT_EQ(VPX_CODEC_UNSUP_BITSTREAM,
Adrian Grange's avatar
Adrian Grange committed
48
              aom_codec_decode(&dec, buf, NELEMENTS(buf), NULL, 0));
James Zern's avatar
James Zern committed
49
    EXPECT_EQ(VPX_CODEC_INVALID_PARAM,
Adrian Grange's avatar
Adrian Grange committed
50 51
              aom_codec_decode(&dec, NULL, NELEMENTS(buf), NULL, 0));
    EXPECT_EQ(VPX_CODEC_INVALID_PARAM, aom_codec_decode(&dec, buf, 0, NULL, 0));
James Zern's avatar
James Zern committed
52

Adrian Grange's avatar
Adrian Grange committed
53
    EXPECT_EQ(VPX_CODEC_OK, aom_codec_destroy(&dec));
James Zern's avatar
James Zern committed
54 55 56 57
  }
}

}  // namespace