You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.2 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  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. */
  10. #include "modules/audio_processing/include/config.h"
  11. #include "test/gtest.h"
  12. namespace webrtc {
  13. namespace {
  14. struct MyExperiment {
  15. static const ConfigOptionID identifier = ConfigOptionID::kMyExperimentForTest;
  16. static const int kDefaultFactor;
  17. static const int kDefaultOffset;
  18. MyExperiment() : factor(kDefaultFactor), offset(kDefaultOffset) {}
  19. MyExperiment(int factor, int offset) : factor(factor), offset(offset) {}
  20. int factor;
  21. int offset;
  22. };
  23. const int MyExperiment::kDefaultFactor = 1;
  24. const int MyExperiment::kDefaultOffset = 2;
  25. TEST(Config, ReturnsDefaultInstanceIfNotConfigured) {
  26. Config config;
  27. const MyExperiment& my_exp = config.Get<MyExperiment>();
  28. EXPECT_EQ(MyExperiment::kDefaultFactor, my_exp.factor);
  29. EXPECT_EQ(MyExperiment::kDefaultOffset, my_exp.offset);
  30. }
  31. TEST(Config, ReturnOptionWhenSet) {
  32. Config config;
  33. config.Set<MyExperiment>(new MyExperiment(5, 1));
  34. const MyExperiment& my_exp = config.Get<MyExperiment>();
  35. EXPECT_EQ(5, my_exp.factor);
  36. EXPECT_EQ(1, my_exp.offset);
  37. }
  38. TEST(Config, SetNullSetsTheOptionBackToDefault) {
  39. Config config;
  40. config.Set<MyExperiment>(new MyExperiment(5, 1));
  41. config.Set<MyExperiment>(NULL);
  42. const MyExperiment& my_exp = config.Get<MyExperiment>();
  43. EXPECT_EQ(MyExperiment::kDefaultFactor, my_exp.factor);
  44. EXPECT_EQ(MyExperiment::kDefaultOffset, my_exp.offset);
  45. }
  46. struct Algo1_CostFunction {
  47. static const ConfigOptionID identifier =
  48. ConfigOptionID::kAlgo1CostFunctionForTest;
  49. Algo1_CostFunction() {}
  50. virtual int cost(int x) const { return x; }
  51. virtual ~Algo1_CostFunction() {}
  52. };
  53. struct SqrCost : Algo1_CostFunction {
  54. virtual int cost(int x) const { return x * x; }
  55. };
  56. TEST(Config, SupportsPolymorphism) {
  57. Config config;
  58. config.Set<Algo1_CostFunction>(new SqrCost());
  59. EXPECT_EQ(25, config.Get<Algo1_CostFunction>().cost(5));
  60. }
  61. } // namespace
  62. } // namespace webrtc