29class ProcessorChainTest final :
public UnitTest
31 template <
int AddValue>
34 void prepare (
const ProcessSpec&)
noexcept { isPrepared =
true; }
35 void reset() noexcept { isReset =
true; }
37 template <
typename Context>
38 void process (
const Context& context)
noexcept
40 bufferWasClear = approximatelyEqual (context.getInputBlock().getSample (0, 0), 0.0f);
42 if (! context.isBypassed)
43 context.getOutputBlock().add (AddValue);
46 bool isPrepared =
false;
48 bool bufferWasClear =
false;
53 :
UnitTest (
"ProcessorChain", UnitTestCategories::dsp) {}
55 void runTest()
override
57 beginTest (
"After calling setBypass, processor is bypassed");
59 ProcessorChain<MockProcessor<1>, MockProcessor<2>> chain;
61 setBypassed<0> (chain,
true);
62 expect (isBypassed<0> (chain));
63 setBypassed<0> (chain,
false);
64 expect (! isBypassed<0> (chain));
66 setBypassed<1> (chain,
true);
67 expect (isBypassed<1> (chain));
68 setBypassed<1> (chain,
false);
69 expect (! isBypassed<1> (chain));
72 beginTest (
"After calling prepare, all processors are prepared");
74 ProcessorChain<MockProcessor<1>, MockProcessor<2>> chain;
76 expect (! get<0> (chain).isPrepared);
77 expect (! get<1> (chain).isPrepared);
79 chain.prepare (ProcessSpec{});
81 expect (get<0> (chain).isPrepared);
82 expect (get<1> (chain).isPrepared);
85 beginTest (
"After calling reset, all processors are reset");
87 ProcessorChain<MockProcessor<1>, MockProcessor<2>> chain;
89 expect (! get<0> (chain).isReset);
90 expect (! get<1> (chain).isReset);
94 expect (get<0> (chain).isReset);
95 expect (get<1> (chain).isReset);
98 beginTest (
"After calling process, all processors contribute to processing");
100 ProcessorChain<MockProcessor<1>, MockProcessor<2>> chain;
102 AudioBuffer<float> buffer (1, 1);
103 AudioBlock<float> block (buffer);
104 ProcessContextReplacing<float> context (block);
107 chain.process (context);
109 expect (get<0> (chain).bufferWasClear);
110 expect (! get<1> (chain).bufferWasClear);
112 setBypassed<0> (chain,
true);
114 chain.process (context);
116 expect (get<0> (chain).bufferWasClear);
117 expect (get<1> (chain).bufferWasClear);
119 setBypassed<1> (chain,
true);
121 chain.process (context);
123 expect (get<0> (chain).bufferWasClear);
124 expect (get<1> (chain).bufferWasClear);
126 setBypassed<0> (chain,
false);
128 chain.process (context);
130 expect (get<0> (chain).bufferWasClear);
131 expect (! get<1> (chain).bufferWasClear);
134 beginTest (
"Chains with trailing items that only support replacing contexts can be built");
136 AudioBuffer<float> inBuf (1, 1), outBuf (1, 1);
152 get<0> (c).setGainLinear (1.0f);
154 inBuf.setSample (0, 0, 1.0f);
162static ProcessorChainTest processorChainUnitTest;
void expectEquals(ValueType actual, ValueType expected, String failureMessage=String())
UnitTest(const String &name, const String &category=String())
void beginTest(const String &testName)
void expect(bool testResult, const String &failureMessage=String())
AudioBlock &JUCE_VECTOR_CALLTYPE multiplyBy(NumericType value) noexcept
void prepare(const ProcessSpec &spec)
void process(const ProcessContext &context) noexcept
AudioBlockType & getOutputBlock() const noexcept