Skip to content

Commit

Permalink
Add a version of the state test with null cookies
Browse files Browse the repository at this point in the history
Since setting the cookie fields is optional.
  • Loading branch information
robbert-vdh committed Oct 3, 2022
1 parent 66185a6 commit ba9564c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
17 changes: 16 additions & 1 deletion src/tests/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const INCONSISTENT_NOTE_PROCESSING: &str = "process-note-inconsistent";
const CONVERT_PARAMS: &str = "param-conversions";
const WRONG_NAMESPACE_SET_PARAMS: &str = "param-set-wrong-namespace";
const BASIC_STATE_REPRODUCIBILITY: &str = "state-reproducibility-basic";
const NULL_COOKIES_STATE_REPRODUCIBILITY: &str = "state-reproducibility-null-cookies";
const FLUSH_STATE_REPRODUCIBILITY: &str = "state-reproducibility-flush";
const BUFFERED_STATE_STREAMS: &str = "state-buffered-streams";

Expand All @@ -28,6 +29,7 @@ pub enum PluginTestCase {
ConvertParams,
WrongNamespaceSetParams,
BasicStateReproducibility,
NullCookiesStateReproducibility,
FlushStateReproducibility,
BufferedStateStreams,
}
Expand All @@ -44,6 +46,7 @@ impl<'a> TestCase<'a> for PluginTestCase {
PluginTestCase::ConvertParams,
PluginTestCase::WrongNamespaceSetParams,
PluginTestCase::BasicStateReproducibility,
PluginTestCase::NullCookiesStateReproducibility,
PluginTestCase::FlushStateReproducibility,
PluginTestCase::BufferedStateStreams,
];
Expand All @@ -60,6 +63,9 @@ impl<'a> TestCase<'a> for PluginTestCase {
CONVERT_PARAMS => Some(PluginTestCase::ConvertParams),
WRONG_NAMESPACE_SET_PARAMS => Some(PluginTestCase::WrongNamespaceSetParams),
BASIC_STATE_REPRODUCIBILITY => Some(PluginTestCase::BasicStateReproducibility),
NULL_COOKIES_STATE_REPRODUCIBILITY => {
Some(PluginTestCase::NullCookiesStateReproducibility)
}
FLUSH_STATE_REPRODUCIBILITY => Some(PluginTestCase::FlushStateReproducibility),
BUFFERED_STATE_STREAMS => Some(PluginTestCase::BufferedStateStreams),
_ => None,
Expand All @@ -74,6 +80,7 @@ impl<'a> TestCase<'a> for PluginTestCase {
PluginTestCase::ConvertParams => CONVERT_PARAMS,
PluginTestCase::WrongNamespaceSetParams => WRONG_NAMESPACE_SET_PARAMS,
PluginTestCase::BasicStateReproducibility => BASIC_STATE_REPRODUCIBILITY,
PluginTestCase::NullCookiesStateReproducibility => NULL_COOKIES_STATE_REPRODUCIBILITY,
PluginTestCase::FlushStateReproducibility => FLUSH_STATE_REPRODUCIBILITY,
PluginTestCase::BufferedStateStreams => BUFFERED_STATE_STREAMS,
}
Expand Down Expand Up @@ -112,6 +119,11 @@ impl<'a> TestCase<'a> for PluginTestCase {
the same and whether saving the state once more results in the same state file \
as before. The parameter values are updated using the process function.",
),
PluginTestCase::NullCookiesStateReproducibility => format!(
"The exact same test as {BASIC_STATE_REPRODUCIBILITY}, but with all cookies in \
the parameter events set to null pointers. The plugin should handle this in the \
same way as the other test case.",
),
PluginTestCase::FlushStateReproducibility => String::from(
"Randomizes a plugin's parameters, saves its state, recreates the plugin \
instance, sets the same parameters as before, saves the state again, and then \
Expand Down Expand Up @@ -159,7 +171,10 @@ impl<'a> TestCase<'a> for PluginTestCase {
params::test_wrong_namespace_set_params(library, plugin_id)
}
PluginTestCase::BasicStateReproducibility => {
state::test_basic_state_reproducibility(library, plugin_id)
state::test_basic_state_reproducibility(library, plugin_id, false)
}
PluginTestCase::NullCookiesStateReproducibility => {
state::test_basic_state_reproducibility(library, plugin_id, true)
}
PluginTestCase::FlushStateReproducibility => {
state::test_flush_state_reproducibility(library, plugin_id)
Expand Down
27 changes: 25 additions & 2 deletions src/tests/plugin/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,15 @@ const ACTUAL_STATE_FILE_NAME: &str = "state-actual";
/// The test for `PluginTestCase::BasicStateReproducibility`. See the description of this test for a
/// detailed explanation, but we essentially check if saving a loaded state results in the same
/// state file, and whether a plugin's parameters are the same after loading the state.
pub fn test_basic_state_reproducibility(library: &PluginLibrary, plugin_id: &str) -> TestStatus {
///
/// The `zero_out_cookies` parameter offers an alternative on this test that sends parameter change
/// events with all cookies set to null pointers. The plugin should behave identically when this
/// happens.
pub fn test_basic_state_reproducibility(
library: &PluginLibrary,
plugin_id: &str,
zero_out_cookies: bool,
) -> TestStatus {
let mut prng = new_prng();

let host = Host::new();
Expand Down Expand Up @@ -72,9 +80,24 @@ pub fn test_basic_state_reproducibility(library: &PluginLibrary, plugin_id: &str
// We can't compare the values from these events direclty as the plugin
// may round the values during the parameter set
let param_fuzzer = ParamFuzzer::new(&param_infos);
let random_param_set_events: Vec<_> =
let mut random_param_set_events: Vec<_> =
param_fuzzer.randomize_params_at(&mut prng, 0).collect();

// This is a variation on the test that checks whether the plugin handles null
// pointer cookies correctly
if zero_out_cookies {
for event in &mut random_param_set_events {
match event {
Event::ParamValue(event) => {
event.cookie = std::ptr::null_mut();
}
event => {
panic!("Unexpected event {event:?}, this is a clap-validator bug")
}
}
}
}

let (mut input_buffers, mut output_buffers) =
audio_ports_config.create_buffers(512);
ProcessingTest::new_out_of_place(&plugin, &mut input_buffers, &mut output_buffers)?
Expand Down

0 comments on commit ba9564c

Please sign in to comment.