1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include "gtest/gtest.h" 18 19 #include "chre/core/audio_request_manager.h" 20 21 using chre::AudioRequestManager; 22 using chre::Nanoseconds; 23 24 TEST(AudioDurationFromSampleCountAndRate, HalfSecond) { 25 Nanoseconds duration = 26 AudioRequestManager::getDurationFromSampleCountAndRate(8000, 16000); 27 EXPECT_EQ(duration.toRawNanoseconds(), 500000000); 28 } 29 30 TEST(AudioDurationFromSampleCountAndRate, OneSecond) { 31 Nanoseconds duration = 32 AudioRequestManager::getDurationFromSampleCountAndRate(16000, 16000); 33 EXPECT_EQ(duration.toRawNanoseconds(), 1000000000); 34 } 35 36 TEST(AudioDurationFromSampleCountAndRate, OneHundredSecond) { 37 Nanoseconds duration = 38 AudioRequestManager::getDurationFromSampleCountAndRate(1600000, 16000); 39 EXPECT_EQ(duration.toRawNanoseconds(), 100000000000); 40 } 41 42 TEST(AudioSampleCountFromRateAndDuration, OneSample) { 43 uint32_t sampleCount = AudioRequestManager::getSampleCountFromRateAndDuration( 44 16000, Nanoseconds(62500)); 45 EXPECT_EQ(sampleCount, 1); 46 } 47 48 TEST(AudioSampleCountFromRateAndDuration, OneHundredSample) { 49 uint32_t sampleCount = AudioRequestManager::getSampleCountFromRateAndDuration( 50 16000, Nanoseconds(6250000)); 51 EXPECT_EQ(sampleCount, 100); 52 } 53 54 TEST(AudioSampleCountFromRateAndDuration, OneThousandSample) { 55 uint32_t sampleCount = AudioRequestManager::getSampleCountFromRateAndDuration( 56 16000, Nanoseconds(62500000)); 57 EXPECT_EQ(sampleCount, 1000); 58 } 59