Home | History | Annotate | Download | only in tests
      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 =
     44       AudioRequestManager::getSampleCountFromRateAndDuration(16000,
     45           Nanoseconds(62500));
     46   EXPECT_EQ(sampleCount, 1);
     47 }
     48 
     49 TEST(AudioSampleCountFromRateAndDuration, OneHundredSample) {
     50   uint32_t sampleCount =
     51       AudioRequestManager::getSampleCountFromRateAndDuration(16000,
     52           Nanoseconds(6250000));
     53   EXPECT_EQ(sampleCount, 100);
     54 }
     55 
     56 TEST(AudioSampleCountFromRateAndDuration, OneThousandSample) {
     57   uint32_t sampleCount =
     58       AudioRequestManager::getSampleCountFromRateAndDuration(16000,
     59           Nanoseconds(62500000));
     60   EXPECT_EQ(sampleCount, 1000);
     61 }
     62