1 /****************************************************************************** 2 * 3 * Copyright (C) 2014 Google, Inc. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at: 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 ******************************************************************************/ 18 19 #include <gtest/gtest.h> 20 21 #include "osi/test/AllocationTestHarness.h" 22 23 extern "C" { 24 #include "btcore/include/bdaddr.h" 25 #include "btcore/include/module.h" 26 #include "device/include/classic/peer.h" 27 28 extern const module_t classic_peer_module; 29 } 30 31 class ClassicPeerTest : public AllocationTestHarness { 32 protected: 33 virtual void SetUp() { 34 AllocationTestHarness::SetUp(); 35 36 module_management_start(); 37 module_init(&classic_peer_module); 38 } 39 40 virtual void TearDown() { 41 module_clean_up(&classic_peer_module); 42 module_management_stop(); 43 44 AllocationTestHarness::TearDown(); 45 } 46 }; 47 48 TEST_F(ClassicPeerTest, test_basic_get) { 49 bt_bdaddr_t test_address; 50 string_to_bdaddr("12:34:56:78:9A:BC", &test_address); 51 52 classic_peer_t *peer = classic_peer_by_address(&test_address); 53 54 EXPECT_TRUE(peer != NULL); 55 // The stored address should be a copy (different memory address) 56 EXPECT_NE(&test_address, classic_peer_get_address(peer)); 57 EXPECT_TRUE(bdaddr_equals(&test_address, classic_peer_get_address(peer))); 58 } 59 60 TEST_F(ClassicPeerTest, test_multi_get_are_same) { 61 bt_bdaddr_t test_address; 62 string_to_bdaddr("12:34:56:78:9A:BC", &test_address); 63 64 classic_peer_t *peer = classic_peer_by_address(&test_address); 65 classic_peer_t *peer_again = classic_peer_by_address(&test_address); 66 67 EXPECT_TRUE(peer != NULL); 68 EXPECT_TRUE(peer_again != NULL); 69 EXPECT_EQ(peer, peer_again); 70 } 71 72 TEST_F(ClassicPeerTest, test_multi_get_different) { 73 bt_bdaddr_t test_address0; 74 bt_bdaddr_t test_address1; 75 string_to_bdaddr("12:34:56:78:9A:BC", &test_address0); 76 string_to_bdaddr("42:42:42:42:42:42", &test_address1); 77 78 classic_peer_t *peer0 = classic_peer_by_address(&test_address0); 79 classic_peer_t *peer1 = classic_peer_by_address(&test_address1); 80 81 EXPECT_TRUE(peer0 != NULL); 82 EXPECT_TRUE(peer1 != NULL); 83 EXPECT_TRUE(bdaddr_equals(&test_address0, classic_peer_get_address(peer0))); 84 EXPECT_TRUE(bdaddr_equals(&test_address1, classic_peer_get_address(peer1))); 85 } 86 87