SoundTriggerTestpublic class SoundTriggerTest extends android.test.InstrumentationTestCase
Fields Summary |
---|
private Random | mRandom |
Methods Summary |
---|
public void | testKeyphraseParcelUnparcel_noUsers()
Keyphrase keyphrase = new Keyphrase(1, 0, "en-US", "hello", null);
// Write to a parcel
Parcel parcel = Parcel.obtain();
keyphrase.writeToParcel(parcel, 0);
// Read from it
parcel.setDataPosition(0);
Keyphrase unparceled = Keyphrase.CREATOR.createFromParcel(parcel);
// Verify that they are the same
assertEquals(keyphrase.id, unparceled.id);
assertNull(unparceled.users);
assertEquals(keyphrase.locale, unparceled.locale);
assertEquals(keyphrase.text, unparceled.text);
| public void | testKeyphraseParcelUnparcel_pos()
Keyphrase keyphrase = new Keyphrase(1, 0, "en-US", "hello", new int[] {1, 2, 3, 4, 5});
// Write to a parcel
Parcel parcel = Parcel.obtain();
keyphrase.writeToParcel(parcel, 0);
// Read from it
parcel.setDataPosition(0);
Keyphrase unparceled = Keyphrase.CREATOR.createFromParcel(parcel);
// Verify that they are the same
assertEquals(keyphrase.id, unparceled.id);
assertTrue(Arrays.equals(keyphrase.users, unparceled.users));
assertEquals(keyphrase.locale, unparceled.locale);
assertEquals(keyphrase.text, unparceled.text);
| public void | testKeyphraseParcelUnparcel_zeroUsers()
Keyphrase keyphrase = new Keyphrase(1, 0, "en-US", "hello", new int[0]);
// Write to a parcel
Parcel parcel = Parcel.obtain();
keyphrase.writeToParcel(parcel, 0);
// Read from it
parcel.setDataPosition(0);
Keyphrase unparceled = Keyphrase.CREATOR.createFromParcel(parcel);
// Verify that they are the same
assertEquals(keyphrase.id, unparceled.id);
assertTrue(Arrays.equals(keyphrase.users, unparceled.users));
assertEquals(keyphrase.locale, unparceled.locale);
assertEquals(keyphrase.text, unparceled.text);
| public void | testKeyphraseRecognitionEventParcelUnparcel_largeData()
byte[] data = new byte[200 * 1024];
mRandom.nextBytes(data);
KeyphraseRecognitionExtra[] kpExtra = new KeyphraseRecognitionExtra[4];
ConfidenceLevel cl1 = new ConfidenceLevel(1, 90);
ConfidenceLevel cl2 = new ConfidenceLevel(2, 30);
kpExtra[0] = new KeyphraseRecognitionExtra(1,
SoundTrigger.RECOGNITION_MODE_USER_IDENTIFICATION, 0,
new ConfidenceLevel[] {cl1, cl2});
kpExtra[1] = new KeyphraseRecognitionExtra(1,
SoundTrigger.RECOGNITION_MODE_VOICE_TRIGGER, 0,
new ConfidenceLevel[] {cl2});
kpExtra[2] = new KeyphraseRecognitionExtra(1,
SoundTrigger.RECOGNITION_MODE_VOICE_TRIGGER, 0, null);
kpExtra[3] = new KeyphraseRecognitionExtra(1,
SoundTrigger.RECOGNITION_MODE_VOICE_TRIGGER, 0,
new ConfidenceLevel[0]);
KeyphraseRecognitionEvent re = new KeyphraseRecognitionEvent(
SoundTrigger.RECOGNITION_STATUS_FAILURE, 1, true, 2, 3, 4, false, null, data,
kpExtra);
// Write to a parcel
Parcel parcel = Parcel.obtain();
re.writeToParcel(parcel, 0);
// Read from it
parcel.setDataPosition(0);
KeyphraseRecognitionEvent unparceled =
KeyphraseRecognitionEvent.CREATOR.createFromParcel(parcel);
// Verify that they are the same
assertEquals(re, unparceled);
| public void | testKeyphraseRecognitionEventParcelUnparcel_noKeyphrases()
KeyphraseRecognitionEvent re = new KeyphraseRecognitionEvent(
SoundTrigger.RECOGNITION_STATUS_SUCCESS, 1, true, 2, 3, 4, false, null, null, null);
// Write to a parcel
Parcel parcel = Parcel.obtain();
re.writeToParcel(parcel, 0);
// Read from it
parcel.setDataPosition(0);
KeyphraseRecognitionEvent unparceled =
KeyphraseRecognitionEvent.CREATOR.createFromParcel(parcel);
// Verify that they are the same
assertEquals(re, unparceled);
| public void | testKeyphraseRecognitionEventParcelUnparcel_zeroData()
KeyphraseRecognitionExtra[] kpExtra = new KeyphraseRecognitionExtra[0];
KeyphraseRecognitionEvent re = new KeyphraseRecognitionEvent(
SoundTrigger.RECOGNITION_STATUS_FAILURE, 2, true, 2, 3, 4, false, null, new byte[1],
kpExtra);
// Write to a parcel
Parcel parcel = Parcel.obtain();
re.writeToParcel(parcel, 0);
// Read from it
parcel.setDataPosition(0);
KeyphraseRecognitionEvent unparceled =
KeyphraseRecognitionEvent.CREATOR.createFromParcel(parcel);
// Verify that they are the same
assertEquals(re, unparceled);
| public void | testKeyphraseSoundModelParcelUnparcel_largeData()
Keyphrase[] keyphrases = new Keyphrase[2];
keyphrases[0] = new Keyphrase(1, 0, "en-US", "hello", new int[] {0});
keyphrases[1] = new Keyphrase(2, 0, "fr-FR", "there", new int[] {1, 2});
byte[] data = new byte[200 * 1024];
mRandom.nextBytes(data);
KeyphraseSoundModel ksm = new KeyphraseSoundModel(UUID.randomUUID(), UUID.randomUUID(),
data, keyphrases);
// Write to a parcel
Parcel parcel = Parcel.obtain();
ksm.writeToParcel(parcel, 0);
// Read from it
parcel.setDataPosition(0);
KeyphraseSoundModel unparceled = KeyphraseSoundModel.CREATOR.createFromParcel(parcel);
// Verify that they are the same
assertEquals(ksm.uuid, unparceled.uuid);
assertEquals(ksm.type, unparceled.type);
assertTrue(Arrays.equals(ksm.data, unparceled.data));
assertTrue(Arrays.equals(ksm.keyphrases, unparceled.keyphrases));
| public void | testKeyphraseSoundModelParcelUnparcel_noData()
Keyphrase[] keyphrases = new Keyphrase[2];
keyphrases[0] = new Keyphrase(1, 0, "en-US", "hello", new int[] {0});
keyphrases[1] = new Keyphrase(2, 0, "fr-FR", "there", new int[] {1, 2});
KeyphraseSoundModel ksm = new KeyphraseSoundModel(UUID.randomUUID(), UUID.randomUUID(),
null, keyphrases);
// Write to a parcel
Parcel parcel = Parcel.obtain();
ksm.writeToParcel(parcel, 0);
// Read from it
parcel.setDataPosition(0);
KeyphraseSoundModel unparceled = KeyphraseSoundModel.CREATOR.createFromParcel(parcel);
// Verify that they are the same
assertEquals(ksm.uuid, unparceled.uuid);
assertNull(unparceled.data);
assertEquals(ksm.type, unparceled.type);
assertTrue(Arrays.equals(keyphrases, unparceled.keyphrases));
| public void | testKeyphraseSoundModelParcelUnparcel_noKeyphrases()
byte[] data = new byte[10];
mRandom.nextBytes(data);
KeyphraseSoundModel ksm = new KeyphraseSoundModel(UUID.randomUUID(), UUID.randomUUID(),
data, null);
// Write to a parcel
Parcel parcel = Parcel.obtain();
ksm.writeToParcel(parcel, 0);
// Read from it
parcel.setDataPosition(0);
KeyphraseSoundModel unparceled = KeyphraseSoundModel.CREATOR.createFromParcel(parcel);
// Verify that they are the same
assertEquals(ksm.uuid, unparceled.uuid);
assertEquals(ksm.type, unparceled.type);
assertNull(unparceled.keyphrases);
assertTrue(Arrays.equals(ksm.data, unparceled.data));
| public void | testKeyphraseSoundModelParcelUnparcel_zeroData()
Keyphrase[] keyphrases = new Keyphrase[2];
keyphrases[0] = new Keyphrase(1, 0, "en-US", "hello", new int[] {0});
keyphrases[1] = new Keyphrase(2, 0, "fr-FR", "there", new int[] {1, 2});
KeyphraseSoundModel ksm = new KeyphraseSoundModel(UUID.randomUUID(), UUID.randomUUID(),
new byte[0], keyphrases);
// Write to a parcel
Parcel parcel = Parcel.obtain();
ksm.writeToParcel(parcel, 0);
// Read from it
parcel.setDataPosition(0);
KeyphraseSoundModel unparceled = KeyphraseSoundModel.CREATOR.createFromParcel(parcel);
// Verify that they are the same
assertEquals(ksm.uuid, unparceled.uuid);
assertEquals(ksm.type, unparceled.type);
assertTrue(Arrays.equals(ksm.keyphrases, unparceled.keyphrases));
assertTrue(Arrays.equals(ksm.data, unparceled.data));
| public void | testKeyphraseSoundModelParcelUnparcel_zeroKeyphrases()
byte[] data = new byte[10];
mRandom.nextBytes(data);
KeyphraseSoundModel ksm = new KeyphraseSoundModel(UUID.randomUUID(), UUID.randomUUID(),
data, new Keyphrase[0]);
// Write to a parcel
Parcel parcel = Parcel.obtain();
ksm.writeToParcel(parcel, 0);
// Read from it
parcel.setDataPosition(0);
KeyphraseSoundModel unparceled = KeyphraseSoundModel.CREATOR.createFromParcel(parcel);
// Verify that they are the same
assertEquals(ksm.uuid, unparceled.uuid);
assertEquals(ksm.type, unparceled.type);
assertTrue(Arrays.equals(ksm.keyphrases, unparceled.keyphrases));
assertTrue(Arrays.equals(ksm.data, unparceled.data));
| public void | testRecognitionEventParcelUnparcel_largeAudioData()
byte[] data = new byte[200 * 1024];
mRandom.nextBytes(data);
RecognitionEvent re = new RecognitionEvent(SoundTrigger.RECOGNITION_STATUS_ABORT, 1,
false, 2, 3, 4, true,
(new AudioFormat.Builder())
.setChannelMask(AudioFormat.CHANNEL_IN_MONO)
.setEncoding(AudioFormat.ENCODING_PCM_16BIT)
.setSampleRate(16000)
.build(),
data);
// Write to a parcel
Parcel parcel = Parcel.obtain();
re.writeToParcel(parcel, 0);
// Read from it
parcel.setDataPosition(0);
RecognitionEvent unparceled = RecognitionEvent.CREATOR.createFromParcel(parcel);
// Verify that they are the same
assertEquals(re, unparceled);
| public void | testRecognitionEventParcelUnparcel_largeData()
byte[] data = new byte[200 * 1024];
mRandom.nextBytes(data);
RecognitionEvent re = new RecognitionEvent(SoundTrigger.RECOGNITION_STATUS_ABORT, 1,
false, 2, 3, 4, false, null, data);
// Write to a parcel
Parcel parcel = Parcel.obtain();
re.writeToParcel(parcel, 0);
// Read from it
parcel.setDataPosition(0);
RecognitionEvent unparceled = RecognitionEvent.CREATOR.createFromParcel(parcel);
// Verify that they are the same
assertEquals(re, unparceled);
| public void | testRecognitionEventParcelUnparcel_noData()
RecognitionEvent re = new RecognitionEvent(SoundTrigger.RECOGNITION_STATUS_SUCCESS, 1,
true, 2, 3, 4, false, null, null);
// Write to a parcel
Parcel parcel = Parcel.obtain();
re.writeToParcel(parcel, 0);
// Read from it
parcel.setDataPosition(0);
RecognitionEvent unparceled = RecognitionEvent.CREATOR.createFromParcel(parcel);
// Verify that they are the same
assertEquals(re, unparceled);
| public void | testRecognitionEventParcelUnparcel_zeroData()
RecognitionEvent re = new RecognitionEvent(SoundTrigger.RECOGNITION_STATUS_FAILURE, 1,
true, 2, 3, 4, false, null, new byte[1]);
// Write to a parcel
Parcel parcel = Parcel.obtain();
re.writeToParcel(parcel, 0);
// Read from it
parcel.setDataPosition(0);
RecognitionEvent unparceled = RecognitionEvent.CREATOR.createFromParcel(parcel);
// Verify that they are the same
assertEquals(re, unparceled);
|
|