Use libcutils' host implementation directly.
Also remove the tests of the mock property functions themselves, and
rely on the libcutils/libbase testing.
Bug: http://b/151789258
Test: treehugger
Change-Id: I455ef0c2e4f19f6e69b8f65a3b6d4595717c81cd
diff --git a/bluetooth/1.0/default/Android.bp b/bluetooth/1.0/default/Android.bp
index f66c25e..6e39d54 100644
--- a/bluetooth/1.0/default/Android.bp
+++ b/bluetooth/1.0/default/Android.bp
@@ -102,13 +102,13 @@
srcs: [
"bluetooth_address.cc",
"test/bluetooth_address_test.cc",
- "test/properties.cc",
],
local_include_dirs: [
"test",
],
shared_libs: [
"libbase",
+ "libcutils",
"liblog",
],
}
diff --git a/bluetooth/1.0/default/test/bluetooth_address_test.cc b/bluetooth/1.0/default/test/bluetooth_address_test.cc
index 2c8dbe5..ee52d33 100644
--- a/bluetooth/1.0/default/test/bluetooth_address_test.cc
+++ b/bluetooth/1.0/default/test/bluetooth_address_test.cc
@@ -120,95 +120,6 @@
EXPECT_FALSE(memcmp(addrA, addrB, BluetoothAddress::kStringLength) == 0);
}
-TEST_F(BluetoothAddressTest, property_set) {
- // Set the properties to empty strings.
- property_set(PERSIST_BDADDR_PROPERTY, "");
- property_set(PROPERTY_BT_BDADDR_PATH, "");
- property_set(FACTORY_BDADDR_PROPERTY, "");
-
- // Get returns 0.
- char prop[PROP_VALUE_MAX] = "";
- EXPECT_TRUE(property_get(PERSIST_BDADDR_PROPERTY, prop, NULL) == 0);
- EXPECT_TRUE(property_get(PROPERTY_BT_BDADDR_PATH, prop, NULL) == 0);
- EXPECT_TRUE(property_get(FACTORY_BDADDR_PROPERTY, prop, NULL) == 0);
-
- // Set the properties to known strings.
- property_set(PERSIST_BDADDR_PROPERTY, "1");
- property_set(PROPERTY_BT_BDADDR_PATH, "22");
- property_set(FACTORY_BDADDR_PROPERTY, "333");
-
- // Get returns the correct length.
- EXPECT_TRUE(property_get(PERSIST_BDADDR_PROPERTY, prop, NULL) == 1);
- EXPECT_TRUE(property_get(PROPERTY_BT_BDADDR_PATH, prop, NULL) == 2);
- EXPECT_TRUE(property_get(FACTORY_BDADDR_PROPERTY, prop, NULL) == 3);
-
- // Set the properties to empty strings again.
- property_set(PERSIST_BDADDR_PROPERTY, "");
- property_set(PROPERTY_BT_BDADDR_PATH, "");
- property_set(FACTORY_BDADDR_PROPERTY, "");
-
- // Get returns 0.
- EXPECT_TRUE(property_get(PERSIST_BDADDR_PROPERTY, prop, NULL) == 0);
- EXPECT_TRUE(property_get(PROPERTY_BT_BDADDR_PATH, prop, NULL) == 0);
- EXPECT_TRUE(property_get(FACTORY_BDADDR_PROPERTY, prop, NULL) == 0);
-}
-
-TEST_F(BluetoothAddressTest, property_get) {
- // Set the properties to known strings.
- property_set(PERSIST_BDADDR_PROPERTY, PERSIST_BDADDR_PROPERTY);
- property_set(PROPERTY_BT_BDADDR_PATH, PROPERTY_BT_BDADDR_PATH);
- property_set(FACTORY_BDADDR_PROPERTY, FACTORY_BDADDR_PROPERTY);
-
- // Get returns the same strings.
- char prop[PROP_VALUE_MAX] = "";
- EXPECT_TRUE(property_get(PERSIST_BDADDR_PROPERTY, prop, NULL) > 0);
- EXPECT_TRUE(strcmp(PERSIST_BDADDR_PROPERTY, prop) == 0);
-
- EXPECT_TRUE(property_get(PROPERTY_BT_BDADDR_PATH, prop, NULL) > 0);
- EXPECT_TRUE(strcmp(PROPERTY_BT_BDADDR_PATH, prop) == 0);
-
- EXPECT_TRUE(property_get(FACTORY_BDADDR_PROPERTY, prop, NULL) > 0);
- EXPECT_TRUE(strcmp(FACTORY_BDADDR_PROPERTY, prop) == 0);
-
- // Set a property to a different known string.
- char prop2[PROP_VALUE_MAX] = "Erased";
- property_set(PERSIST_BDADDR_PROPERTY, prop2);
-
- // Get returns the correct strings.
- EXPECT_TRUE(property_get(PERSIST_BDADDR_PROPERTY, prop, NULL) > 0);
- EXPECT_TRUE(strcmp(prop2, prop) == 0);
-
- EXPECT_TRUE(property_get(PROPERTY_BT_BDADDR_PATH, prop, NULL) > 0);
- EXPECT_TRUE(strcmp(PROPERTY_BT_BDADDR_PATH, prop) == 0);
-
- EXPECT_TRUE(property_get(FACTORY_BDADDR_PROPERTY, prop, NULL) > 0);
- EXPECT_TRUE(strcmp(FACTORY_BDADDR_PROPERTY, prop) == 0);
-
- // Set another property to prop2.
- property_set(PROPERTY_BT_BDADDR_PATH, prop2);
-
- EXPECT_TRUE(property_get(PERSIST_BDADDR_PROPERTY, prop, NULL) > 0);
- EXPECT_TRUE(strcmp(prop2, prop) == 0);
-
- EXPECT_TRUE(property_get(PROPERTY_BT_BDADDR_PATH, prop, NULL) > 0);
- EXPECT_TRUE(strcmp(prop2, prop) == 0);
-
- EXPECT_TRUE(property_get(FACTORY_BDADDR_PROPERTY, prop, NULL) > 0);
- EXPECT_TRUE(strcmp(FACTORY_BDADDR_PROPERTY, prop) == 0);
-
- // Set the third property to prop2.
- property_set(FACTORY_BDADDR_PROPERTY, prop2);
-
- EXPECT_TRUE(property_get(PERSIST_BDADDR_PROPERTY, prop, NULL) > 0);
- EXPECT_TRUE(strcmp(prop2, prop) == 0);
-
- EXPECT_TRUE(property_get(PROPERTY_BT_BDADDR_PATH, prop, NULL) > 0);
- EXPECT_TRUE(strcmp(prop2, prop) == 0);
-
- EXPECT_TRUE(property_get(FACTORY_BDADDR_PROPERTY, prop, NULL) > 0);
- EXPECT_TRUE(strcmp(prop2, prop) == 0);
-}
-
TEST_F(BluetoothAddressTest, get_local_address) {
EXPECT_TRUE(property_set(PERSIST_BDADDR_PROPERTY, "") == 0);
EXPECT_TRUE(property_set(FACTORY_BDADDR_PROPERTY, "") == 0);
diff --git a/bluetooth/1.0/default/test/properties.cc b/bluetooth/1.0/default/test/properties.cc
deleted file mode 100644
index 70de01e..0000000
--- a/bluetooth/1.0/default/test/properties.cc
+++ /dev/null
@@ -1,79 +0,0 @@
-//
-// Copyright 2016 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-#define LOG_TAG "properties"
-
-#include <ctype.h>
-#include <stdbool.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include <cutils/properties.h>
-#include <log/log.h>
-
-static const int MAX_PROPERTIES = 5;
-
-struct property {
- char key[PROP_KEY_MAX + 2];
- char value[PROP_VALUE_MAX + 2];
-};
-
-int num_properties = 0;
-struct property properties[MAX_PROPERTIES];
-
-// Find the correct entry.
-static int property_find(const char* key) {
- for (int i = 0; i < num_properties; i++) {
- if (strncmp(properties[i].key, key, PROP_KEY_MAX) == 0) {
- return i;
- }
- }
- return MAX_PROPERTIES;
-}
-
-int property_set(const char* key, const char* value) {
- if (strnlen(value, PROP_VALUE_MAX) > PROP_VALUE_MAX) return -1;
-
- // Check to see if the property exists.
- int prop_index = property_find(key);
-
- if (prop_index == MAX_PROPERTIES) {
- if (num_properties >= MAX_PROPERTIES) return -1;
- prop_index = num_properties;
- num_properties += 1;
- }
-
- // This is test code. Be nice and don't push the boundary cases!
- strncpy(properties[prop_index].key, key, PROP_KEY_MAX + 1);
- strncpy(properties[prop_index].value, value, PROP_VALUE_MAX + 1);
- return 0;
-}
-
-int property_get(const char* key, char* value, const char* default_value) {
- // This doesn't mock the behavior of default value
- if (default_value != NULL) ALOGE("%s: default_value is ignored!", __func__);
-
- // Check to see if the property exists.
- int prop_index = property_find(key);
-
- if (prop_index == MAX_PROPERTIES) return 0;
-
- int len = strlen(properties[prop_index].value);
- memcpy(value, properties[prop_index].value, len);
- value[len] = '\0';
- return len;
-}
diff --git a/bluetooth/1.0/default/test/sys/system_properties.h b/bluetooth/1.0/default/test/sys/system_properties.h
deleted file mode 100644
index b477a6b..0000000
--- a/bluetooth/1.0/default/test/sys/system_properties.h
+++ /dev/null
@@ -1,20 +0,0 @@
-//
-// Copyright 2016 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-// Mock sys/system_properties.h for testing
-
-#define PROP_VALUE_MAX 50
-#define PROP_KEY_MAX 50