!520 Update api interface

Merge pull request !520 from HYH/test
This commit is contained in:
openharmony_ci 2023-12-02 09:06:49 +00:00 committed by Gitee
commit d48126464e
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
6 changed files with 59 additions and 58 deletions

View File

@ -128,7 +128,7 @@ config("ohsensor_public_config") {
ohos_shared_library("ohsensor") {
sources = [ "src/native_sensor.cpp" ]
output_extension = "so"
defines = [ "API_EXPORT=__attribute__((visibility (\"default\")))" ]
configs = [ ":sensor_private_config" ]

View File

@ -74,7 +74,7 @@ Sensor_Result OH_Sensor_GetInfos(Sensor_Info **sensors, uint32_t *count)
return SENSOR_SUCCESS;
}
Sensor_Info **OH_Sensor_Info_Create(uint32_t count)
Sensor_Info **OH_Sensor_CreateInfos(uint32_t count)
{
auto sensors = new Sensor_Info *[count];
for (uint32_t i = 0; i < count; ++i) {
@ -83,7 +83,7 @@ Sensor_Info **OH_Sensor_Info_Create(uint32_t count)
return sensors;
}
int32_t OH_Sensor_Info_Destroy(Sensor_Info **sensors, uint32_t count)
int32_t OH_Sensor_DestroyInfos(Sensor_Info **sensors, uint32_t count)
{
for (uint32_t i = 0; i < count; ++i) {
delete sensors[i];
@ -314,12 +314,12 @@ int32_t OH_Sensor_Subscriber_GetCallback(Sensor_Subscriber* user, Sensor_EventCa
return SENSOR_SUCCESS;
}
Sensor_SubscriptionId *OH_Sensor_SubscriptionId_Create()
Sensor_SubscriptionId *OH_Sensor_CreateSubscriptionId()
{
return new (std::nothrow) Sensor_SubscriptionId();
}
int32_t OH_Sensor_SubscriptionId_Destroy(Sensor_SubscriptionId *id)
int32_t OH_Sensor_DestroySubscriptionId(Sensor_SubscriptionId *id)
{
if (id == nullptr) {
SEN_HILOGE("Parameter error");
@ -330,12 +330,12 @@ int32_t OH_Sensor_SubscriptionId_Destroy(Sensor_SubscriptionId *id)
return SENSOR_SUCCESS;
}
Sensor_SubscriptionAttribute *OH_Sensor_SubscriptionAttribute_Create()
Sensor_SubscriptionAttribute *OH_Sensor_CreateSubscriptionAttribute()
{
return new (std::nothrow) Sensor_SubscriptionAttribute();
}
int32_t OH_Sensor_SubscriptionAttribute_Destroy(Sensor_SubscriptionAttribute *attribute)
int32_t OH_Sensor_DestroySubscriptionAttribute(Sensor_SubscriptionAttribute *attribute)
{
if (attribute == nullptr) {
SEN_HILOGE("Parameter error");
@ -346,12 +346,12 @@ int32_t OH_Sensor_SubscriptionAttribute_Destroy(Sensor_SubscriptionAttribute *at
return SENSOR_SUCCESS;
}
Sensor_Subscriber *OH_Sensor_Subscriber_Create()
Sensor_Subscriber *OH_Sensor_CreateSubscriber()
{
return new (std::nothrow) Sensor_Subscriber();
}
int32_t OH_Sensor_Subscriber_Destroy(Sensor_Subscriber *user)
int32_t OH_Sensor_DestroySubscriber(Sensor_Subscriber *user)
{
if (user == nullptr) {
SEN_HILOGE("Parameter error");

View File

@ -25,5 +25,6 @@ ohos_ndk_headers("sensor_ndk_header") {
ohos_ndk_library("libsensor_ndk") {
ndk_description_file = "./libsensor.ndk.json"
output_name = "ohsensor"
output_extension = "so"
min_compact_version = "11"
}

View File

@ -57,27 +57,27 @@
"name": "OH_Sensor_Subscriber_GetCallback"
},
{
"name": "OH_Sensor_Info_Create"
"name": "OH_Sensor_CreateInfos"
},
{
"name": "OH_Sensor_Info_Destroy"
"name": "OH_Sensor_DestroyInfos"
},
{
"name": "OH_Sensor_SubscriptionId_Create"
"name": "OH_Sensor_CreateSubscriptionId"
},
{
"name": "OH_Sensor_SubscriptionId_Destroy"
"name": "OH_Sensor_DestroySubscriptionId"
},
{
"name": "OH_Sensor_SubscriptionAttribute_Create"
"name": "OH_Sensor_CreateSubscriptionAttribute"
},
{
"name": "OH_Sensor_SubscriptionAttribute_Destroy"
"name": "OH_Sensor_DestroySubscriptionAttribute"
},
{
"name": "OH_Sensor_Subscriber_Create"
"name": "OH_Sensor_CreateSubscriber"
},
{
"name": "OH_Sensor_Subscriber_Destroy"
"name": "OH_Sensor_DestroySubscriber"
}
]

View File

@ -187,7 +187,7 @@ typedef struct Sensor_Info Sensor_Info;
* returns <b>NULL</b> otherwise.
* @since 11
*/
Sensor_Info **OH_Sensor_Info_Create(uint32_t count);
Sensor_Info **OH_Sensor_CreateInfos(uint32_t count);
/**
* @brief Destroys an array of {@link Sensor_Info} instances and reclaims memory.
@ -198,7 +198,7 @@ Sensor_Info **OH_Sensor_Info_Create(uint32_t count);
* returns an error code defined in {@link Sensor_Result} otherwise.
* @since 11
*/
int32_t OH_Sensor_Info_Destroy(Sensor_Info **sensors, uint32_t count);
int32_t OH_Sensor_DestroyInfos(Sensor_Info **sensors, uint32_t count);
/**
* @brief Obtains the sensor name.
@ -355,7 +355,7 @@ typedef struct Sensor_SubscriptionId Sensor_SubscriptionId;
* returns <b>NULL</b> otherwise.
* @since 11
*/
Sensor_SubscriptionId *OH_Sensor_SubscriptionId_Create(void);
Sensor_SubscriptionId *OH_Sensor_CreateSubscriptionId(void);
/**
* @brief Destroys a {@link Sensor_SubscriptionId} instance and reclaims memory.
@ -365,7 +365,7 @@ Sensor_SubscriptionId *OH_Sensor_SubscriptionId_Create(void);
* returns an error code defined in {@link Sensor_Result} otherwise.
* @since 11
*/
int32_t OH_Sensor_SubscriptionId_Destroy(Sensor_SubscriptionId *id);
int32_t OH_Sensor_DestroySubscriptionId(Sensor_SubscriptionId *id);
/**
* @brief Obtains the sensor type.
@ -402,7 +402,7 @@ typedef struct Sensor_SubscriptionAttribute Sensor_SubscriptionAttribute;
* returns <b>NULL</b> otherwise.
* @since 11
*/
Sensor_SubscriptionAttribute *OH_Sensor_SubscriptionAttribute_Create(void);
Sensor_SubscriptionAttribute *OH_Sensor_CreateSubscriptionAttribute(void);
/**
* @brief Destroys a {@link Sensor_SubscriptionAttribute} instance and reclaims memory.
@ -412,7 +412,7 @@ Sensor_SubscriptionAttribute *OH_Sensor_SubscriptionAttribute_Create(void);
* returns an error code defined in {@link Sensor_Result} otherwise.
* @since 11
*/
int32_t OH_Sensor_SubscriptionAttribute_Destroy(Sensor_SubscriptionAttribute *attribute);
int32_t OH_Sensor_DestroySubscriptionAttribute(Sensor_SubscriptionAttribute *attribute);
/**
* @brief Sets the sensor data reporting interval.
@ -457,7 +457,7 @@ typedef struct Sensor_Subscriber Sensor_Subscriber;
* if the operation is successful; returns <b>NULL</b> otherwise.
* @since 11
*/
Sensor_Subscriber *OH_Sensor_Subscriber_Create(void);
Sensor_Subscriber *OH_Sensor_CreateSubscriber(void);
/**
* @brief Destroys a {@link Sensor_Subscriber} instance and reclaims memory.
@ -467,7 +467,7 @@ Sensor_Subscriber *OH_Sensor_Subscriber_Create(void);
* returns an error code defined in {@link Sensor_Result} otherwise.
* @since 11
*/
int32_t OH_Sensor_Subscriber_Destroy(Sensor_Subscriber *subscriber);
int32_t OH_Sensor_DestroySubscriber(Sensor_Subscriber *subscriber);
/**
* @brief Sets a callback function to report sensor data.

View File

@ -142,7 +142,7 @@ HWTEST_F(SensorAgentTest, OH_Sensor_GetInfos_001, TestSize.Level1)
uint32_t count = 0;
int32_t ret = OH_Sensor_GetInfos(nullptr, &count);
ASSERT_EQ(ret, SENSOR_SUCCESS);
Sensor_Info **sensors = OH_Sensor_Info_Create(count);
Sensor_Info **sensors = OH_Sensor_CreateInfos(count);
ASSERT_NE(sensors, nullptr);
ret = OH_Sensor_GetInfos(sensors, &count);
ASSERT_EQ(ret, SENSOR_SUCCESS);
@ -172,7 +172,7 @@ HWTEST_F(SensorAgentTest, OH_Sensor_GetInfos_001, TestSize.Level1)
static_cast<int32_t>(sensorType), sensorName, vendorName,
resolution, minSamplePeriod, maxSamplePeriod);
}
ret = OH_Sensor_Info_Destroy(sensors, count);
ret = OH_Sensor_DestroyInfos(sensors, count);
ASSERT_EQ(ret, SENSOR_SUCCESS);
}
@ -187,15 +187,15 @@ HWTEST_F(SensorAgentTest, OH_Sensor_GetInfos_002, TestSize.Level1)
HWTEST_F(SensorAgentTest, OH_Sensor_Subscribe_001, TestSize.Level1)
{
SEN_HILOGI("OH_Sensor_Subscribe_001 in");
g_user = OH_Sensor_Subscriber_Create();
g_user = OH_Sensor_CreateSubscriber();
int32_t ret = OH_Sensor_Subscriber_SetCallback(g_user, SensorDataCallbackImpl);
ASSERT_EQ(ret, SENSOR_SUCCESS);
Sensor_SubscriptionId *id = OH_Sensor_SubscriptionId_Create();
Sensor_SubscriptionId *id = OH_Sensor_CreateSubscriptionId();
ret = OH_Sensor_SubscriptionId_SetType(id, SENSOR_ID);
ASSERT_EQ(ret, SENSOR_SUCCESS);
Sensor_SubscriptionAttribute *attr = OH_Sensor_SubscriptionAttribute_Create();
Sensor_SubscriptionAttribute *attr = OH_Sensor_CreateSubscriptionAttribute();
ret = OH_Sensor_SubscriptionAttribute_SetSamplingInterval(attr, SENSOR_SAMPLE_PERIOD);
ASSERT_EQ(ret, SENSOR_SUCCESS);
@ -206,13 +206,13 @@ HWTEST_F(SensorAgentTest, OH_Sensor_Subscribe_001, TestSize.Level1)
ret = OH_Sensor_Unsubscribe(id, g_user);
ASSERT_EQ(ret, SENSOR_SUCCESS);
if (id != nullptr) {
OH_Sensor_SubscriptionId_Destroy(id);
OH_Sensor_DestroySubscriptionId(id);
}
if (attr != nullptr) {
OH_Sensor_SubscriptionAttribute_Destroy(attr);
OH_Sensor_DestroySubscriptionAttribute(attr);
}
if (g_user != nullptr) {
OH_Sensor_Subscriber_Destroy(g_user);
OH_Sensor_DestroySubscriber(g_user);
g_user = nullptr;
}
}
@ -220,42 +220,42 @@ HWTEST_F(SensorAgentTest, OH_Sensor_Subscribe_001, TestSize.Level1)
HWTEST_F(SensorAgentTest, OH_Sensor_Subscribe_002, TestSize.Level1)
{
SEN_HILOGI("OH_Sensor_Subscribe_002 in");
Sensor_SubscriptionId *id = OH_Sensor_SubscriptionId_Create();
Sensor_SubscriptionId *id = OH_Sensor_CreateSubscriptionId();
int32_t ret = OH_Sensor_SubscriptionId_SetType(id, SENSOR_ID);
ASSERT_EQ(ret, SENSOR_SUCCESS);
Sensor_SubscriptionAttribute *attr = OH_Sensor_SubscriptionAttribute_Create();
Sensor_SubscriptionAttribute *attr = OH_Sensor_CreateSubscriptionAttribute();
ret = OH_Sensor_SubscriptionAttribute_SetSamplingInterval(attr, SENSOR_SAMPLE_PERIOD);
ASSERT_EQ(ret, SENSOR_SUCCESS);
ret = OH_Sensor_Subscribe(id, attr, nullptr);
ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR);
if (id != nullptr) {
OH_Sensor_SubscriptionId_Destroy(id);
OH_Sensor_DestroySubscriptionId(id);
}
if (attr != nullptr) {
OH_Sensor_SubscriptionAttribute_Destroy(attr);
OH_Sensor_DestroySubscriptionAttribute(attr);
}
}
HWTEST_F(SensorAgentTest, OH_Sensor_Subscribe_003, TestSize.Level1)
{
SEN_HILOGI("OH_Sensor_Subscribe_003 in");
g_user = OH_Sensor_Subscriber_Create();
g_user = OH_Sensor_CreateSubscriber();
int32_t ret = OH_Sensor_Subscriber_SetCallback(g_user, SensorDataCallbackImpl);
ASSERT_EQ(ret, SENSOR_SUCCESS);
Sensor_SubscriptionAttribute *attr = OH_Sensor_SubscriptionAttribute_Create();
Sensor_SubscriptionAttribute *attr = OH_Sensor_CreateSubscriptionAttribute();
ret = OH_Sensor_SubscriptionAttribute_SetSamplingInterval(attr, SENSOR_SAMPLE_PERIOD);
ASSERT_EQ(ret, SENSOR_SUCCESS);
ret = OH_Sensor_Subscribe(nullptr, attr, g_user);
ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR);
if (attr != nullptr) {
OH_Sensor_SubscriptionAttribute_Destroy(attr);
OH_Sensor_DestroySubscriptionAttribute(attr);
}
if (g_user != nullptr) {
OH_Sensor_Subscriber_Destroy(g_user);
OH_Sensor_DestroySubscriber(g_user);
g_user = nullptr;
}
}
@ -263,21 +263,21 @@ HWTEST_F(SensorAgentTest, OH_Sensor_Subscribe_003, TestSize.Level1)
HWTEST_F(SensorAgentTest, OH_Sensor_Subscribe_004, TestSize.Level1)
{
SEN_HILOGI("OH_Sensor_Subscribe_004 in");
g_user = OH_Sensor_Subscriber_Create();
g_user = OH_Sensor_CreateSubscriber();
int32_t ret = OH_Sensor_Subscriber_SetCallback(g_user, SensorDataCallbackImpl);
ASSERT_EQ(ret, SENSOR_SUCCESS);
Sensor_SubscriptionId *id = OH_Sensor_SubscriptionId_Create();
Sensor_SubscriptionId *id = OH_Sensor_CreateSubscriptionId();
ret = OH_Sensor_SubscriptionId_SetType(id, SENSOR_ID);
ASSERT_EQ(ret, SENSOR_SUCCESS);
ret = OH_Sensor_Subscribe(id, nullptr, g_user);
ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR);
if (id != nullptr) {
OH_Sensor_SubscriptionId_Destroy(id);
OH_Sensor_DestroySubscriptionId(id);
}
if (g_user != nullptr) {
OH_Sensor_Subscriber_Destroy(g_user);
OH_Sensor_DestroySubscriber(g_user);
g_user = nullptr;
}
}
@ -285,14 +285,14 @@ HWTEST_F(SensorAgentTest, OH_Sensor_Subscribe_004, TestSize.Level1)
HWTEST_F(SensorAgentTest, OH_Sensor_Unsubscribe_001, TestSize.Level1)
{
SEN_HILOGI("OH_Sensor_Unsubscribe_001 in");
g_user = OH_Sensor_Subscriber_Create();
g_user = OH_Sensor_CreateSubscriber();
int32_t ret = OH_Sensor_Subscriber_SetCallback(g_user, SensorDataCallbackImpl);
ASSERT_EQ(ret, SENSOR_SUCCESS);
ret = OH_Sensor_Unsubscribe(nullptr, g_user);
ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR);
if (g_user != nullptr) {
OH_Sensor_Subscriber_Destroy(g_user);
OH_Sensor_DestroySubscriber(g_user);
g_user = nullptr;
}
}
@ -300,14 +300,14 @@ HWTEST_F(SensorAgentTest, OH_Sensor_Unsubscribe_001, TestSize.Level1)
HWTEST_F(SensorAgentTest, OH_Sensor_Unsubscribe_002, TestSize.Level1)
{
SEN_HILOGI("OH_Sensor_Unsubscribe_002 in");
Sensor_SubscriptionId *id = OH_Sensor_SubscriptionId_Create();
Sensor_SubscriptionId *id = OH_Sensor_CreateSubscriptionId();
int32_t ret = OH_Sensor_SubscriptionId_SetType(id, SENSOR_ID);
ASSERT_EQ(ret, SENSOR_SUCCESS);
ret = OH_Sensor_Unsubscribe(id, nullptr);
ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR);
if (id != nullptr) {
OH_Sensor_SubscriptionId_Destroy(id);
OH_Sensor_DestroySubscriptionId(id);
}
}
@ -329,11 +329,11 @@ HWTEST_F(SensorAgentTest, OH_Sensor_SubscriptionId_GetType_001, TestSize.Level1)
HWTEST_F(SensorAgentTest, OH_Sensor_SubscriptionId_GetType_002, TestSize.Level1)
{
SEN_HILOGI("OH_Sensor_SubscriptionId_GetType_002 in");
Sensor_SubscriptionId *id = OH_Sensor_SubscriptionId_Create();
Sensor_SubscriptionId *id = OH_Sensor_CreateSubscriptionId();
int32_t ret = OH_Sensor_SubscriptionId_GetType(id, nullptr);
ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR);
if (id != nullptr) {
OH_Sensor_SubscriptionId_Destroy(id);
OH_Sensor_DestroySubscriptionId(id);
}
}
@ -350,11 +350,11 @@ HWTEST_F(SensorAgentTest, OH_Sensor_SubscriptionAttribute_SetSamplingInterval_00
TestSize.Level1)
{
SEN_HILOGI("OH_Sensor_SubscriptionAttribute_SetSamplingInterval_002 in");
Sensor_SubscriptionAttribute *attr = OH_Sensor_SubscriptionAttribute_Create();
Sensor_SubscriptionAttribute *attr = OH_Sensor_CreateSubscriptionAttribute();
int32_t ret = OH_Sensor_SubscriptionAttribute_SetSamplingInterval(attr, INVALID_VALUE);
ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR);
if (attr != nullptr) {
OH_Sensor_SubscriptionAttribute_Destroy(attr);
OH_Sensor_DestroySubscriptionAttribute(attr);
}
}
@ -372,11 +372,11 @@ HWTEST_F(SensorAgentTest, OH_Sensor_SubscriptionAttribute_GetSamplingInterval_00
TestSize.Level1)
{
SEN_HILOGI("OH_Sensor_SubscriptionAttribute_GetSamplingInterval_002 in");
Sensor_SubscriptionAttribute *attr = OH_Sensor_SubscriptionAttribute_Create();
Sensor_SubscriptionAttribute *attr = OH_Sensor_CreateSubscriptionAttribute();
int32_t ret = OH_Sensor_SubscriptionAttribute_GetSamplingInterval(attr, nullptr);
ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR);
if (attr != nullptr) {
OH_Sensor_SubscriptionAttribute_Destroy(attr);
OH_Sensor_DestroySubscriptionAttribute(attr);
}
}
@ -390,7 +390,7 @@ HWTEST_F(SensorAgentTest, OH_Sensor_Subscriber_SetCallback_001, TestSize.Level1)
HWTEST_F(SensorAgentTest, OH_Sensor_Subscriber_SetCallback_002, TestSize.Level1)
{
SEN_HILOGI("OH_Sensor_Subscriber_SetCallback_002 in");
g_user = OH_Sensor_Subscriber_Create();
g_user = OH_Sensor_CreateSubscriber();
int32_t ret = OH_Sensor_Subscriber_SetCallback(g_user, nullptr);
ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR);
}
@ -406,11 +406,11 @@ HWTEST_F(SensorAgentTest, OH_Sensor_Subscriber_GetCallback_001, TestSize.Level1)
HWTEST_F(SensorAgentTest, OH_Sensor_Subscriber_GetCallback_002, TestSize.Level1)
{
SEN_HILOGI("OH_Sensor_Subscriber_GetCallback_002 in");
g_user = OH_Sensor_Subscriber_Create();
g_user = OH_Sensor_CreateSubscriber();
int32_t ret = OH_Sensor_Subscriber_GetCallback(g_user, nullptr);
ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR);
if (g_user != nullptr) {
OH_Sensor_Subscriber_Destroy(g_user);
OH_Sensor_DestroySubscriber(g_user);
}
}
} // namespace Sensors