Audio plugin host https://kx.studio/carla
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.

95 lines
2.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 6 technical preview.
  4. Copyright (c) 2020 - Raw Material Software Limited
  5. You may use this code under the terms of the GPL v3
  6. (see www.gnu.org/licenses).
  7. For this technical preview, this file is not subject to commercial licensing.
  8. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  9. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  10. DISCLAIMED.
  11. ==============================================================================
  12. */
  13. namespace juce
  14. {
  15. #if JUCE_UNIT_TESTS
  16. class ValueWithDefaultTests : public UnitTest
  17. {
  18. public:
  19. ValueWithDefaultTests()
  20. : UnitTest ("ValueWithDefault", UnitTestCategories::values)
  21. {}
  22. void runTest() override
  23. {
  24. beginTest ("default constructor");
  25. {
  26. ValueWithDefault vwd;
  27. expect (vwd.isUsingDefault());
  28. expect (vwd.get() == var());
  29. }
  30. beginTest ("missing property");
  31. {
  32. ValueTree t ("root");
  33. ValueWithDefault vwd (t, "testKey", nullptr, "default");
  34. expect (vwd.isUsingDefault());
  35. expectEquals (vwd.get().toString(), String ("default"));
  36. }
  37. beginTest ("non-empty property");
  38. {
  39. ValueTree t ("root");
  40. t.setProperty ("testKey", "non-default", nullptr);
  41. ValueWithDefault vwd (t, "testKey", nullptr, "default");
  42. expect (! vwd.isUsingDefault());
  43. expectEquals (vwd.get().toString(), String ("non-default"));
  44. }
  45. beginTest ("set default");
  46. {
  47. ValueTree t ("root");
  48. ValueWithDefault vwd (t, "testkey", nullptr);
  49. vwd.setDefault ("default");
  50. expect (vwd.isUsingDefault());
  51. expectEquals (vwd.get().toString(), String ("default"));
  52. }
  53. beginTest ("set value");
  54. {
  55. ValueTree t ("root");
  56. t.setProperty ("testkey", "testvalue", nullptr);
  57. ValueWithDefault vwd (t, "testkey", nullptr, "default");
  58. vwd = "newvalue";
  59. expect (! vwd.isUsingDefault());
  60. expectEquals (t["testkey"].toString(), String ("newvalue"));
  61. vwd.resetToDefault();
  62. expect (vwd.isUsingDefault());
  63. expect (t["testkey"] == var());
  64. }
  65. }
  66. };
  67. static ValueWithDefaultTests valueWithDefaultTests;
  68. #endif
  69. } // namespace juce