1 /*
2 * Copyright (c) 2020, 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 <string>
13 #include "common/webmenc.h"
14 #include "gtest/gtest.h"
15
16 namespace {
17
18 #if CONFIG_WEBM_IO
19
20 class WebmencTest : public ::testing::Test {};
21
22 // All of these variations on output should be identical.
TEST(WebmencTest,ExtractEncoderSettingsOutput1)23 TEST(WebmencTest, ExtractEncoderSettingsOutput1) {
24 const char *argv[] = { "aomenc", "-o", "output", "input",
25 "--target-bitrate=300" };
26 int argc = 5;
27 const std::string expected("version:1.2.3 --target-bitrate=300");
28 char *result = extract_encoder_settings("1.2.3", argv, argc, "input");
29 ASSERT_EQ(expected, std::string(result));
30 free(result);
31 }
32
TEST(WebmencTest,ExtractEncoderSettingsOutput2)33 TEST(WebmencTest, ExtractEncoderSettingsOutput2) {
34 const char *argv[] = { "aomenc", "--output", "bar", "foo", "--cpu-used=3" };
35 int argc = 5;
36 const std::string expected("version:abc --cpu-used=3");
37 char *result = extract_encoder_settings("abc", argv, argc, "foo");
38 ASSERT_EQ(expected, std::string(result));
39 free(result);
40 }
41
TEST(WebmencTest,ExtractEncoderSettingsOutput3)42 TEST(WebmencTest, ExtractEncoderSettingsOutput3) {
43 const char *argv[] = { "aomenc", "--cq-level=63", "--end-usage=q",
44 "--output=foo", "baz" };
45 int argc = 5;
46 const std::string expected("version:23 --cq-level=63 --end-usage=q");
47 char *result = extract_encoder_settings("23", argv, argc, "baz");
48 ASSERT_EQ(expected, std::string(result));
49 free(result);
50 }
51
TEST(WebmencTest,ExtractEncoderSettingsInput)52 TEST(WebmencTest, ExtractEncoderSettingsInput) {
53 // Check that input filename is filtered regardless of position.
54 const char *argv[] = { "aomenc", "-o", "out", "input", "-p", "2" };
55 int argc = 6;
56 const char version[] = "1.0.0";
57 const std::string expected("version:1.0.0 -p 2");
58 char *result = extract_encoder_settings(version, argv, argc, "input");
59 ASSERT_EQ(expected, std::string(result));
60 free(result);
61
62 const char *argv2[] = { "aomenc", "input", "-o", "out", "-p", "2" };
63 result = extract_encoder_settings(version, argv2, argc, "input");
64 ASSERT_EQ(expected, std::string(result));
65 free(result);
66 }
67
68 #endif // CONFIG_WEBM_IO
69 } // namespace
70