Home | History | Annotate | Download | only in test
      1 /******************************************************************************
      2  *
      3  *  Copyright (C) 2016 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 extern "C" {
     22 #include "btif/include/btif_storage.h"
     23 #include "btif/include/btif_util.h"
     24 }
     25 
     26 TEST(BtifStorageTest, test_string_to_uuid) {
     27   const char *s1 = "e39c6285-867f-4b1d-9db0-35fbd9aebf22";
     28   const uint8_t u1[] = {0xe3, 0x9c, 0x62, 0x85, 0x86, 0x7f, 0x4b, 0x1d,
     29                         0x9d, 0xb0, 0x35, 0xfb, 0xd9, 0xae, 0xbf, 0x22};
     30 
     31   bt_uuid_t uuid;
     32   memset(&uuid, 0, sizeof(uuid));
     33   EXPECT_FALSE(memcmp(&uuid, u1, sizeof(u1)) == 0);
     34 
     35   bool rc = string_to_uuid(s1, &uuid);
     36   EXPECT_TRUE(rc);
     37   EXPECT_TRUE(memcmp(&uuid, u1, sizeof(u1)) == 0);
     38 }
     39 
     40 TEST(BtifStorageTest, test_string_to_uuid_invalid) {
     41   bt_uuid_t uuid;
     42   bool rc = string_to_uuid("This is not a UUID", &uuid);
     43   EXPECT_FALSE(rc);
     44 }
     45 
     46 TEST(BtifStorageTest, test_uuid_split_multiple) {
     47   const char *s1 = "e39c6285-867f-4b1d-9db0-35fbd9aebf22 e39c6285-867f-4b1d-9db0-35fbd9aebf23";
     48   const uint8_t u1[] = {0xe3, 0x9c, 0x62, 0x85, 0x86, 0x7f, 0x4b, 0x1d,
     49                         0x9d, 0xb0, 0x35, 0xfb, 0xd9, 0xae, 0xbf, 0x22};
     50   const uint8_t u2[] = {0xe3, 0x9c, 0x62, 0x85, 0x86, 0x7f, 0x4b, 0x1d,
     51                         0x9d, 0xb0, 0x35, 0xfb, 0xd9, 0xae, 0xbf, 0x23};
     52 
     53   bt_uuid_t uuids[2];
     54   size_t num_uuids = btif_split_uuids_string(s1, uuids, 2);
     55   EXPECT_EQ(num_uuids, 2u);
     56   EXPECT_TRUE(memcmp(&uuids[0], u1, sizeof(u1)) == 0);
     57   EXPECT_TRUE(memcmp(&uuids[1], u2, sizeof(u2)) == 0);
     58 }
     59 
     60 TEST(BtifStorageTest, test_uuid_split_partial) {
     61   const char *s1 = "e39c6285-867f-4b1d-9db0-35fbd9aebf22 e39c6285-867f-4b1d-9db0-35fbd9aebf23";
     62 
     63   bt_uuid_t uuids[2];
     64   size_t num_uuids = btif_split_uuids_string(s1, uuids, 1);
     65   EXPECT_EQ(num_uuids, 1u);
     66 }
     67