#include <sensor_internal.h>
#include <sensor_internal_deprecated.h>
#include <sensor_types.h>
+#include <sensor_types_private.h>
#include <sensor_utils.h>
#include <channel_handler.h>
#include <sensor_provider.h>
#include <sensor_log.h>
#include <unordered_map>
+#include <regex>
#define CONVERT_OPTION_PAUSE_POLICY(option) ((option) ^ 0b11)
{
retvm_if(!provider, -EINVAL, "Invalid paramter");
+ std::string str_uri(uri);
+ retvm_if(str_uri.find(PREDEFINED_TYPE_URI) != std::string::npos,
+ -EINVAL, "Invalid URI format[%s]", uri);
+
+ static std::regex uri_regex(SENSOR_URI_REGEX, std::regex::optimize);
+ retvm_if(!std::regex_match(uri, uri_regex),
+ -EINVAL, "Invalid URI format[%s]", uri);
+
sensor_provider *p;
p = new(std::nothrow) sensor_provider(uri);
/* TODO: change it from manual test to auto-test */
TESTCASE(sensor_api_mysensor_provider, provider_p_1)
{
- const char *uri = "http://example.org/mysensor/mysensor";
+ const char *uri = "http://example.org/sensor/mysensor/mysensor";
const char *name = "mysensor";
const char *vendor = "tizen";
TESTCASE(sensor_api_mysensor_listener, listener_p_1)
{
- const char *uri = "http://example.org/mysensor/mysensor";
+ const char *uri = "http://example.org/sensor/mysensor/mysensor";
int err;
bool ret;
int handle;
static void add_mysensor(void)
{
- const char *uri = "http://example.org/mysensor/mysensor";
+ const char *uri = "http://example.org/sensor/mysensor/mysensor";
const char *name = "mysensor";
const char *vendor = "tizen";
--- /dev/null
+/*
+ * sensorctl
+ *
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * 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.
+ *
+ */
+
+#include <unistd.h>
+#include <string.h>
+#include <sensor_internal.h>
+
+#include "log.h"
+#include "mainloop.h"
+#include "test_bench.h"
+
+TESTCASE(sensor_api_provider_uri, provider_check_uri)
+{
+ int err;
+ sensord_provider_h provider;
+
+ const char *uri_p1 = "http://example.org/sensor/mysensor_type/mysensor";
+ const char *uri_p2 = "http://developer.samsung.com/sensor/mysensor_type/mysensor";
+ const char *uri_n1 = "http://tizen.org/sensor/accelerometer/mysensor";
+ const char *uri_n2 = "http://tizen.org/mysensor/accelerometer/mysensor";
+ const char *uri_n3 = "http:/example.org/sensor/mysensor_type/mysensor";
+ const char *uri_n5 = "http://example.org/sensor/mysensor_type";
+ const char *uri_n4 = "http://example.org/sensor/mysensor_type/mysensor/mysensor";
+
+ err = sensord_create_provider(uri_p1, &provider);
+ EXPECT_EQ(err, 0);
+ err = sensord_create_provider(uri_p2, &provider);
+ EXPECT_EQ(err, 0);
+ err = sensord_create_provider(uri_n1, &provider);
+ EXPECT_EQ(err, -EINVAL);
+ err = sensord_create_provider(uri_n2, &provider);
+ EXPECT_EQ(err, -EINVAL);
+ err = sensord_create_provider(uri_n3, &provider);
+ EXPECT_EQ(err, -EINVAL);
+ err = sensord_create_provider(uri_n4, &provider);
+ EXPECT_EQ(err, -EINVAL);
+ err = sensord_create_provider(uri_n5, &provider);
+ EXPECT_EQ(err, -EINVAL);
+
+ return true;
+}
--- /dev/null
+/*
+ * sensord
+ *
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * 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.
+ *
+ */
+
+#ifndef __SENSOR_TYPES_PRIVATE__
+#define __SENSOR_TYPES_PRIVATE__
+
+#define URI_REGEX(CATEGORY) R"~(^http:\/\/[\w-]+(\.[\w-]+)*\/)~" CATEGORY R"~(\/[\w-]+(\.[\w-]+)*(\/[\w-]+(\.[\w-]+)*)$)~"
+#define SENSOR_URI_REGEX URI_REGEX("sensor")
+
+#define PREDEFINED_TYPE_URI "http://tizen.org/sensor/"
+
+#endif /* __SENSOR_TYPES_PRIVATE__ */