blob: 8776ee3391c1104370f37f058e310759d63a8478 [file] [log] [blame]
andresp@webrtc.org6b68c282013-05-13 08:06:36 +00001/*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020010#include "modules/audio_processing/include/config.h"
andresp@webrtc.org6b68c282013-05-13 08:06:36 +000011
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020012#include "test/gtest.h"
andresp@webrtc.org6b68c282013-05-13 08:06:36 +000013
14namespace webrtc {
15namespace {
16
17struct MyExperiment {
aluebs688e3082016-01-14 04:32:46 -080018 static const ConfigOptionID identifier = ConfigOptionID::kMyExperimentForTest;
pbos@webrtc.org2de80dd2013-06-27 10:18:09 +000019 static const int kDefaultFactor;
20 static const int kDefaultOffset;
andresp@webrtc.org6b68c282013-05-13 08:06:36 +000021
22 MyExperiment()
23 : factor(kDefaultFactor), offset(kDefaultOffset) {}
24
25 MyExperiment(int factor, int offset)
26 : factor(factor), offset(offset) {}
27
28 int factor;
29 int offset;
30};
31
pbos@webrtc.org2de80dd2013-06-27 10:18:09 +000032const int MyExperiment::kDefaultFactor = 1;
33const int MyExperiment::kDefaultOffset = 2;
34
andresp@webrtc.org6b68c282013-05-13 08:06:36 +000035TEST(Config, ReturnsDefaultInstanceIfNotConfigured) {
36 Config config;
37 const MyExperiment& my_exp = config.Get<MyExperiment>();
38 EXPECT_EQ(MyExperiment::kDefaultFactor, my_exp.factor);
39 EXPECT_EQ(MyExperiment::kDefaultOffset, my_exp.offset);
40}
41
42TEST(Config, ReturnOptionWhenSet) {
43 Config config;
44 config.Set<MyExperiment>(new MyExperiment(5, 1));
45 const MyExperiment& my_exp = config.Get<MyExperiment>();
46 EXPECT_EQ(5, my_exp.factor);
47 EXPECT_EQ(1, my_exp.offset);
48}
49
50TEST(Config, SetNullSetsTheOptionBackToDefault) {
51 Config config;
52 config.Set<MyExperiment>(new MyExperiment(5, 1));
53 config.Set<MyExperiment>(NULL);
54 const MyExperiment& my_exp = config.Get<MyExperiment>();
55 EXPECT_EQ(MyExperiment::kDefaultFactor, my_exp.factor);
56 EXPECT_EQ(MyExperiment::kDefaultOffset, my_exp.offset);
57}
58
59struct Algo1_CostFunction {
aluebs688e3082016-01-14 04:32:46 -080060 static const ConfigOptionID identifier =
61 ConfigOptionID::kAlgo1CostFunctionForTest;
andresp@webrtc.org6b68c282013-05-13 08:06:36 +000062 Algo1_CostFunction() {}
63
64 virtual int cost(int x) const {
65 return x;
66 }
67
68 virtual ~Algo1_CostFunction() {}
69};
70
71struct SqrCost : Algo1_CostFunction {
72 virtual int cost(int x) const {
73 return x*x;
74 }
75};
76
pbos@webrtc.org2de80dd2013-06-27 10:18:09 +000077TEST(Config, SupportsPolymorphism) {
andresp@webrtc.org6b68c282013-05-13 08:06:36 +000078 Config config;
79 config.Set<Algo1_CostFunction>(new SqrCost());
80 EXPECT_EQ(25, config.Get<Algo1_CostFunction>().cost(5));
81}
82} // namespace
83} // namespace webrtc