Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/android-card-ui.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ jobs:
adb shell pm disable-user --user 0 com.google.android.apps.messaging
sleep 10
set +e
python3 tools/run_android_emulator_tests.py --output test-output/android-card-ui --classes cloud.gitwide.ampverse.CardUiDeviceTest,cloud.gitwide.ampverse.CleanUiDeviceTest,cloud.gitwide.ampverse.RadioOfflineTest,cloud.gitwide.ampverse.IncrementalSyncDeviceTest,cloud.gitwide.ampverse.PhoneListeningDeviceTest,cloud.gitwide.ampverse.DjLoadPadsDeviceTest,cloud.gitwide.ampverse.AudioFeatureDeviceTest,cloud.gitwide.ampverse.CastBadgeLayoutDeviceTest,cloud.gitwide.ampverse.RemoteDiscoveryDeviceTest,cloud.gitwide.ampverse.DiscoveryDeviceTest,cloud.gitwide.ampverse.RemoteTaskCardsDeviceTest,cloud.gitwide.ampverse.LabNavigationDeviceTest,cloud.gitwide.ampverse.lab.EditingSessionTest,cloud.gitwide.ampverse.ModuleBadgesDeviceTest,cloud.gitwide.ampverse.LibrarySyncCardsDeviceTest,cloud.gitwide.ampverse.LibraryChooserDeviceTest,cloud.gitwide.ampverse.MusicBackupDeviceTest,cloud.gitwide.ampverse.LibraryStoreDeviceTest,cloud.gitwide.ampverse.CatalogDeviceTest
python3 tools/run_android_emulator_tests.py --output test-output/android-card-ui --classes cloud.gitwide.ampverse.SongIdentityDeviceTest,cloud.gitwide.ampverse.CardUiDeviceTest,cloud.gitwide.ampverse.CleanUiDeviceTest,cloud.gitwide.ampverse.RadioOfflineTest,cloud.gitwide.ampverse.IncrementalSyncDeviceTest,cloud.gitwide.ampverse.PhoneListeningDeviceTest,cloud.gitwide.ampverse.DjLoadPadsDeviceTest,cloud.gitwide.ampverse.AudioFeatureDeviceTest,cloud.gitwide.ampverse.CastBadgeLayoutDeviceTest,cloud.gitwide.ampverse.RemoteDiscoveryDeviceTest,cloud.gitwide.ampverse.DiscoveryDeviceTest,cloud.gitwide.ampverse.RemoteTaskCardsDeviceTest,cloud.gitwide.ampverse.LabNavigationDeviceTest,cloud.gitwide.ampverse.lab.EditingSessionTest,cloud.gitwide.ampverse.ModuleBadgesDeviceTest,cloud.gitwide.ampverse.LibrarySyncCardsDeviceTest,cloud.gitwide.ampverse.LibraryChooserDeviceTest,cloud.gitwide.ampverse.MusicBackupDeviceTest,cloud.gitwide.ampverse.LibraryStoreDeviceTest,cloud.gitwide.ampverse.CatalogDeviceTest
result=$?
mkdir -p test-output/android-card-ui
adb logcat -d > test-output/android-card-ui/logcat.txt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class DjLoadPadsDeviceTest {
assertTrue(e.queue(Arrays.asList(high,low,high),rules));java.lang.reflect.Field cursor=DjEngine.class.getDeclaredField("nextAuto");cursor.setAccessible(true);cursor.setInt(e,1);e.mixStyle("Hype");plan.invoke(e,0,1);assertEquals("Keep the played prefix when a song occurs again later",high,e.autoQueue.get(0));assertEquals(high,e.autoQueue.get(1));assertEquals(low,e.autoQueue.get(2));
org.json.JSONObject ramp=new org.json.JSONObject(rules.toString()).put("smart",true).put("energy",.2).put("energy_progression",new org.json.JSONObject().put("target",.9).put("transitions",4));
assertTrue(e.queue(Arrays.asList(low,high),ramp));e.mixStyle("Hype");plan.invoke(e,0,1);assertEquals("Keep the explicit ramp's planned order",low,e.autoQueue.get(0));
assertNotNull("Unknown outgoing energy must use the shared unknown-data policy, not make every cost NaN",DjLogic.replacement(context,null,Arrays.asList(low,high),new org.json.JSONObject().put("style","Hype"),Collections.emptyList()));
assertNotNull("Unknown outgoing energy must use the shared unknown-data policy, not make every cost NaN",DjLogic.replacement(context,null,Arrays.asList(low,high),new org.json.JSONObject().put("style","Hype"),Collections.emptyList(),Collections.emptyList()));
android.os.Bundle unknown=new android.os.Bundle();unknown.putString("amp-preparation",new org.json.JSONObject().put("energy",.8).put("perceptual_energy",org.json.JSONObject.NULL).toString());
MediaItem uncertain=new MediaItem.Builder().setMediaId("style-unknown-measurement").setUri("file:///unknown.wav").setMediaMetadata(new androidx.media3.common.MediaMetadata.Builder().setExtras(unknown).build()).build();
assertTrue("A missing normalized score cannot silently become legacy loudness",Double.isNaN(PhonePlaylists.knownEnergy(context,uncertain)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ private static final class Fixture implements AutoCloseable {
accept=new Thread(()->{while(!server.isClosed())try{Socket socket=server.accept();clients.execute(()->serve(socket));}catch(Exception error){if(!server.isClosed())failure.compareAndSet(null,error);}},"library-download-fixture");accept.start();
}
String base(){return "http://"+server.getInetAddress().getHostAddress()+":"+server.getLocalPort();}
final Map<String,byte[]> audioVariants=new HashMap<>();
synchronized byte[] audio(String path){
// Distinct fixture songs must contain distinct PCM now that repeat
// detection compares audio rather than just their different paths.
return audioVariants.computeIfAbsent(path,key->{byte[] data=wave.clone();double frequency=220+110*audioVariants.size();ByteBuffer pcm=ByteBuffer.wrap(data).order(ByteOrder.LITTLE_ENDIAN);for(int n=44;n+1<data.length;n+=2)pcm.putShort(n,(short)(500*Math.sin(2*Math.PI*frequency*((n-44)/2)/44100.)));return data;});
}
JSONObject ref(String path)throws Exception{return new JSONObject().put("track_key",PlaylistSyncModel.trackKey(path)).put("relative_path",path).put("library_id",library);}
JSONObject envelope(String id,boolean smart,String name)throws Exception{return new JSONObject().put("document_id",id).put("kind",smart?"smart":"normal").put("document_version",smart?2:1).put("revision","revision-1").put("document",smart?new JSONObject().put("name",name).put("id",id).put("style","steady"):new JSONObject().put("name",name).put("version",1).put("tracks",new JSONArray().put(ref("a.wav")).put(ref("b.wav")).put(ref("a.wav"))));}
JSONObject status()throws Exception{return new JSONObject().put("server_id",identity).put("library_id",library).put("station_id","fixture-station").put("station_name","Office computer").put("password_required",true).put("running",false).put("capabilities",new JSONObject().put("player_queue",1).put("player_track_refs","library_path_v1").put("private_audio","library_path_v1").put("playlist_snapshot","library_path_v1"));}
Expand All @@ -60,14 +66,14 @@ else if(path.startsWith("/api/player/metadata?")){
assertEquals(identity,headers.get("x-amp-server"));assertEquals(library,headers.get("x-amp-library"));assertEquals("fixture-secret",headers.get("x-amp-password"));
String song=android.net.Uri.parse(base()+path).getQueryParameter("path");
body=new JSONObject().put("server_id",identity).put("library_id",library).put("path",song).put("track_key",PlaylistSyncModel.trackKey(song))
.put("bytes",wave.length).put("sha256",AppUpdate.hex(java.security.MessageDigest.getInstance("SHA-256").digest(wave)))
.put("bytes",wave.length).put("sha256",AppUpdate.hex(java.security.MessageDigest.getInstance("SHA-256").digest(audio(song))))
.put("preparation_available",true).put("preparation_current",true).put("revision","fixture-analysis")
.put("preparation",new JSONObject().put("bpm",128).put("key","8A").put("cues",new JSONArray()));
}
else if(path.startsWith("/api/player/audio?")){
if(first.startsWith("GET ")&&failAfter>=0&&audioReads.getAndIncrement()>=failAfter)return;
assertEquals(identity,headers.get("x-amp-server"));assertEquals(library,headers.get("x-amp-library"));assertEquals("fixture-secret",headers.get("x-amp-password"));
boolean second="b.wav".equals(android.net.Uri.parse(base()+path).getQueryParameter("path"));if(second&&failSecond){code=503;body=new JSONObject().put("error","Fixture song unavailable");}else{audio=wave;if(second&&slowSecond){OutputStream out=socket.getOutputStream();out.write(("HTTP/1.1 200 OK\r\nContent-Type: audio/wav\r\nContent-Length: "+wave.length+"\r\nConnection: close\r\n\r\n").getBytes(StandardCharsets.US_ASCII));out.flush();blocked.countDown();release.await(12,TimeUnit.SECONDS);try{out.write(wave);out.flush();}catch(IOException cancelled){}return;}}
String song=android.net.Uri.parse(base()+path).getQueryParameter("path");boolean second="b.wav".equals(song);if(second&&failSecond){code=503;body=new JSONObject().put("error","Fixture song unavailable");}else{audio=audio(song);if(second&&slowSecond){OutputStream out=socket.getOutputStream();out.write(("HTTP/1.1 200 OK\r\nContent-Type: audio/wav\r\nContent-Length: "+audio.length+"\r\nConnection: close\r\n\r\n").getBytes(StandardCharsets.US_ASCII));out.flush();blocked.countDown();release.await(12,TimeUnit.SECONDS);try{out.write(audio);out.flush();}catch(IOException cancelled){}return;}}
}else{failure.compareAndSet(null,new AssertionError("Unexpected request "+first));code=404;body=new JSONObject();}
byte[] payload=audio!=null?audio:body.toString().getBytes(StandardCharsets.UTF_8);OutputStream out=socket.getOutputStream();out.write(("HTTP/1.1 "+code+" OK\r\nContent-Type: "+(audio==null?"application/json":"audio/wav")+"\r\nContent-Length: "+payload.length+"\r\nConnection: close\r\n\r\n").getBytes(StandardCharsets.US_ASCII));if(!first.startsWith("HEAD "))out.write(payload);out.flush();
}catch(Throwable error){if(!server.isClosed())failure.compareAndSet(null,error);}}
Expand Down Expand Up @@ -165,6 +171,7 @@ private interface Check {boolean ready()throws Exception;}
Context c=ApplicationProvider.getApplicationContext();SharedPreferences locals=c.getSharedPreferences("phone-playlists",0);String drafts=locals.getString("lists",null);locals.edit().putString("lists","[]").commit();
JSONObject[] lists=new JSONObject[2];File original=new File(c.getCacheDir(),"qa-original-kept.wav");
try(Fixture fixture=new Fixture(30)){
assertFalse("Fixture songs represent distinct audio",Arrays.equals(fixture.audio("a.wav"),fixture.audio("b.wav")));
try(FileOutputStream out=new FileOutputStream(original)){out.write(fixture.wave);}
PlaylistSync.enable(c,fixture.base(),"fixture-secret",fixture.identity,fixture.library);lists[0]=list(c,"Office mix");lists[1]=list(c,"edm");
try(ActivityScenario<MainActivity> screen=ActivityScenario.launch(new Intent(c,MainActivity.class).putExtra("module","AMP DJ"))){
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package cloud.gitwide.ampverse;

import androidx.media3.common.MediaItem;
import androidx.media3.common.MediaMetadata;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.*;
import static org.junit.Assert.*;

@RunWith(AndroidJUnit4.class)
public class SongIdentityDeviceTest {
private MediaItem song(String id,String title) {
return new MediaItem.Builder().setMediaId(id).setUri("file:///"+id+".mp3")
.setMediaMetadata(new MediaMetadata.Builder().setArtist("Artist").setTitle(title).build()).build();
}
@Test public void removedPlayingAndRecentItemsKeepTheirIdentityDuringRefill() {
MediaItem current=song("removed","Song (Radio Edit)"),copy=song("copy","Song (Extended Mix)");
MediaItem heard=song("heard","Previous (Club_Remix)"),edit=song("edit","Previous (Radio-Edit)"),next=song("next","Next");
List<MediaItem> candidates=Arrays.asList(copy,edit,next);
assertEquals(Collections.singletonList(next),PhoneSmartRules.repeatCandidates(candidates,Collections.singletonList(heard),current,Collections.emptyList(),5));
assertTrue(PhoneSmartRules.repeatCandidates(Collections.singletonList(copy),Collections.emptyList(),current,Collections.emptyList(),5).isEmpty());
}
@Test public void loadedDeckAliasesRemainExcludedWhenRecentHistoryRelaxes() {
MediaItem loaded=song("loaded","Song (Radio Edit)"),edit=song("edit","Song (Extended Mix)");
assertTrue(PhoneSmartRules.repeatCandidates(Collections.singletonList(edit),Collections.emptyList(),null,Collections.singletonList(loaded),0).isEmpty());
assertNull(DjLogic.replacement(androidx.test.platform.app.InstrumentationRegistry.getInstrumentation().getTargetContext(),null,
Collections.singletonList(edit),new org.json.JSONObject(),Collections.emptyList(),Collections.singletonList(loaded)));
}
}
Loading
Loading