79 lines
3.8 KiB
Java
79 lines
3.8 KiB
Java
package cloud.molberg.mgutility;
|
|
|
|
import android.content.Context;
|
|
import android.os.SystemClock;
|
|
|
|
public final class LiquidAudioIntegrationTest {
|
|
private static void check(boolean condition, String message) {
|
|
if (!condition) throw new AssertionError(message);
|
|
}
|
|
|
|
private static void tick(Context context, float distance, boolean active, int samples) {
|
|
for (int index = 0; index < samples; index++) {
|
|
SystemClock.now += 1000L;
|
|
AdaptiveAudioLevelingManager.updateSpeed(context, 60f, distance, active);
|
|
}
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
Context context = new Context();
|
|
MgServiceBridge bridge = MgServiceBridge.get();
|
|
LiquidSoundBalanceManager.Config defaults = LiquidSoundBalanceManager.config(context);
|
|
check(defaults.anchorX == 7 && defaults.anchorY == 7 && !defaults.volumeBoost, "safe migration defaults");
|
|
LiquidSoundBalanceManager.save(context, true, 1.5f, 65, true, true, 3, 11, false, true, 50);
|
|
LiquidSoundBalanceManager.save(context, false, 1.5f, 65, true, true);
|
|
LiquidSoundBalanceManager.Config saved = LiquidSoundBalanceManager.config(context);
|
|
check(!saved.enabled && saved.anchorX == 3 && saved.anchorY == 11 && saved.volumeBoost && saved.boostPercent == 50,
|
|
"control-panel toggle preserves anchors and boost preferences");
|
|
LiquidSoundBalanceManager.save(context, true, 1f, 100, true, true, -1, 99, false, true, 200);
|
|
saved = LiquidSoundBalanceManager.config(context);
|
|
check(saved.anchorX == 0 && saved.anchorY == 14 && saved.boostPercent == 100, "persisted settings are clamped");
|
|
|
|
tick(context, 1.5f, true, 20);
|
|
check(bridge.volume == 15, "distance boost reaches 150% without compounding on each poll");
|
|
tick(context, 1f, true, 20);
|
|
check(bridge.volume == 10, "settling returns exactly to base volume");
|
|
tick(context, 1.5f, true, 20);
|
|
bridge.volume = 18;
|
|
tick(context, 1.5f, true, 1);
|
|
check(bridge.volume == 18, "manual volume is not immediately overwritten");
|
|
tick(context, 1f, true, 20);
|
|
check(bridge.volume == 12, "manual change updates the base, not the boosted value");
|
|
tick(context, 1.5f, true, 20);
|
|
tick(context, 1f, false, 1);
|
|
check(bridge.volume == 12, "disabling compensation restores latest base");
|
|
|
|
bridge.volume = 10;
|
|
AdaptiveAudioLevelingManager.save(context, true, 120, 20, 120, 70, 120, 110);
|
|
tick(context, 1.5f, true, 20);
|
|
check(bridge.volume == 18, "speed and position boosts share one base reference");
|
|
tick(context, 1f, false, 20);
|
|
check(bridge.volume == 12, "disabling distance boost leaves speed leveling intact");
|
|
AdaptiveAudioLevelingManager.save(context, false, 120, 20, 120, 70, 120, 110);
|
|
check(bridge.volume == 10, "disabling both restores original base");
|
|
|
|
bridge.volume = 0;
|
|
tick(context, 2f, true, 10);
|
|
check(bridge.volume == 0, "compensation does not unmute");
|
|
tick(context, 1f, false, 1);
|
|
bridge.volume = 15;
|
|
tick(context, 2f, true, 20);
|
|
check(bridge.volume == 20, "boost never exceeds hardware maximum");
|
|
bridge.failWrites = true;
|
|
tick(context, 1f, false, 1);
|
|
check(bridge.volume == 20, "failed restore does not claim success");
|
|
bridge.failWrites = false;
|
|
tick(context, 1f, false, 1);
|
|
check(bridge.volume == 15, "failed restore retains base for retry");
|
|
|
|
bridge.volume = 10;
|
|
tick(context, 1.5f, true, 20);
|
|
bridge.failReads = true;
|
|
tick(context, 1f, false, 1);
|
|
bridge.failReads = false;
|
|
tick(context, 1f, false, 1);
|
|
check(bridge.volume == 10, "unavailable mixer retains restoration reference");
|
|
System.out.println("LiquidAudioIntegrationTest: OK");
|
|
}
|
|
}
|