1 //
2 // Copyright (C) 2025 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 <gmock/gmock.h>
18 #include <gtest/gtest.h>
19
20 #include "gki.h"
21 #include "gki_common.h"
22 #include "nfc_target.h"
23
24 class GkiTimerTest : public ::testing::Test {
25 protected:
SetUp()26 void SetUp() override { gki_timers_init(); }
27 };
28
mock_callback(bool start)29 void mock_callback(bool start) { (void)start; }
30
TEST_F(GkiTimerTest,Timer)31 TEST_F(GkiTimerTest, Timer) {
32 GKI_start_timer(NFC_TIMER_ID, GKI_SECS_TO_TICKS(1), true);
33 GKI_timer_update(5);
34 EXPECT_EQ(GKI_get_tick_count(), 5);
35 gki_adjust_timer_count(10);
36 EXPECT_EQ(GKI_ready_to_sleep(), 10);
37 GKI_stop_timer(NFC_TIMER_ID);
38 }
39
TEST_F(GkiTimerTest,List)40 TEST_F(GkiTimerTest, List) {
41 GKI_timer_queue_register_callback(mock_callback);
42 TIMER_LIST_Q timer_list_queue;
43 GKI_init_timer_list(&timer_list_queue);
44 TIMER_LIST_ENT timer_list_ent;
45 GKI_init_timer_list_entry(&timer_list_ent);
46 timer_list_ent.in_use = true;
47 timer_list_ent.ticks = 10;
48 GKI_add_to_timer_list(&timer_list_queue, &timer_list_ent);
49 EXPECT_EQ(GKI_get_remaining_ticks(&timer_list_queue, &timer_list_ent), 10);
50 GKI_update_timer_list(&timer_list_queue, 1);
51 EXPECT_FALSE(GKI_timer_queue_empty());
52 GKI_remove_from_timer_list(&timer_list_queue, &timer_list_ent);
53 }
54