encode_api_test.cc 2.33 KB
Newer Older
James Zern's avatar
James Zern committed
1
2
3
4
5
6
7
8
9
10
11
12
/*
 *  Copyright (c) 2016 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.
 */

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

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

namespace {

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

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

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

Adrian Grange's avatar
Adrian Grange committed
40
41
42
43
44
45
  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
46
            aom_codec_enc_config_default(NULL, NULL, 0));
Adrian Grange's avatar
Adrian Grange committed
47
  EXPECT_EQ(AOM_CODEC_INVALID_PARAM,
Adrian Grange's avatar
Adrian Grange committed
48
49
            aom_codec_enc_config_default(NULL, &cfg, 0));
  EXPECT_TRUE(aom_codec_error(NULL) != NULL);
James Zern's avatar
James Zern committed
50
51

  for (int i = 0; i < NELEMENTS(kCodecs); ++i) {
Adrian Grange's avatar
Adrian Grange committed
52
    SCOPED_TRACE(aom_codec_iface_name(kCodecs[i]));
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_init(NULL, kCodecs[i], NULL, 0));
Adrian Grange's avatar
Adrian Grange committed
55
    EXPECT_EQ(AOM_CODEC_INVALID_PARAM,
Adrian Grange's avatar
Adrian Grange committed
56
              aom_codec_enc_init(&enc, kCodecs[i], NULL, 0));
Adrian Grange's avatar
Adrian Grange committed
57
    EXPECT_EQ(AOM_CODEC_INVALID_PARAM,
Adrian Grange's avatar
Adrian Grange committed
58
              aom_codec_enc_config_default(kCodecs[i], &cfg, 1));
James Zern's avatar
James Zern committed
59

Adrian Grange's avatar
Adrian Grange committed
60
61
62
    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
63

Adrian Grange's avatar
Adrian Grange committed
64
    EXPECT_EQ(AOM_CODEC_OK, aom_codec_destroy(&enc));
James Zern's avatar
James Zern committed
65
66
67
68
  }
}

}  // namespace