From: Somin Kim Date: Tue, 5 Jul 2016 09:31:54 +0000 (+0900) Subject: [UTC][context][ACR-672][New TCs for custom event/condition added] X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=21e74f2170d3123693f9dd6d1f9cf00a5f7e6a83;p=test%2Ftct%2Fnative%2Fapi.git [UTC][context][ACR-672][New TCs for custom event/condition added] Change-Id: I0f92d487907aca53906f9164c358b7500262d888 Signed-off-by: Somin Kim --- diff --git a/src/utc/context/public.list b/src/utc/context/public.list index 1d66816..b5e875a 100755 --- a/src/utc/context/public.list +++ b/src/utc/context/public.list @@ -23,6 +23,11 @@ context_trigger_rule_entry_add_comparison context_trigger_rule_entry_add_option_int context_trigger_rule_entry_add_option_string context_trigger_rule_entry_add_option +context_trigger_custom_register +context_trigger_custom_unregister +context_trigger_custom_publish +context_trigger_rule_custom_event_create +context_trigger_rule_custom_condition_create context_history_create context_history_destroy context_history_filter_create diff --git a/src/utc/context/tct-context-core_mobile.h b/src/utc/context/tct-context-core_mobile.h index f264e9a..44858c3 100755 --- a/src/utc/context/tct-context-core_mobile.h +++ b/src/utc/context/tct-context-core_mobile.h @@ -108,6 +108,16 @@ extern int utc_context_trigger_rule_entry_add_option_p1(void); extern int utc_context_trigger_rule_entry_add_option_p2(void); extern int utc_context_trigger_rule_entry_add_option_p3(void); extern int utc_context_trigger_rule_entry_add_option_n(void); +extern int utc_context_trigger_custom_register_p(void); +extern int utc_context_trigger_custom_register_n(void); +extern int utc_context_trigger_custom_unregister_p(void); +extern int utc_context_trigger_custom_unregister_n(void); +extern int utc_context_trigger_custom_publish_p(void); +extern int utc_context_trigger_custom_publish_n(void); +extern int utc_context_trigger_rule_custom_event_create_p(void); +extern int utc_context_trigger_rule_custom_event_create_n(void); +extern int utc_context_trigger_rule_custom_condition_create_p(void); +extern int utc_context_trigger_rule_custom_condition_create_n(void); testcase tc_array[] = { {"utc_context_history_create_p", utc_context_history_create_p, utc_context_history_startup, utc_context_history_cleanup}, @@ -194,6 +204,16 @@ testcase tc_array[] = { {"utc_context_trigger_rule_entry_add_option_p2", utc_context_trigger_rule_entry_add_option_p2, utc_context_trigger_startup, utc_context_trigger_cleanup}, {"utc_context_trigger_rule_entry_add_option_p3", utc_context_trigger_rule_entry_add_option_p3, utc_context_trigger_startup, utc_context_trigger_cleanup}, {"utc_context_trigger_rule_entry_add_option_n", utc_context_trigger_rule_entry_add_option_n, utc_context_trigger_startup, utc_context_trigger_cleanup}, + {"utc_context_trigger_custom_register_p", utc_context_trigger_custom_register_p, utc_context_trigger_startup, utc_context_trigger_cleanup}, + {"utc_context_trigger_custom_register_n", utc_context_trigger_custom_register_n, utc_context_trigger_startup, utc_context_trigger_cleanup}, + {"utc_context_trigger_custom_unregister_p", utc_context_trigger_custom_unregister_p, utc_context_trigger_startup, utc_context_trigger_cleanup}, + {"utc_context_trigger_custom_unregister_n", utc_context_trigger_custom_unregister_n, utc_context_trigger_startup, utc_context_trigger_cleanup}, + {"utc_context_trigger_custom_publish_p", utc_context_trigger_custom_publish_p, utc_context_trigger_startup, utc_context_trigger_cleanup}, + {"utc_context_trigger_custom_publish_n", utc_context_trigger_custom_publish_n, utc_context_trigger_startup, utc_context_trigger_cleanup}, + {"utc_context_trigger_rule_custom_event_create_p", utc_context_trigger_rule_custom_event_create_p, utc_context_trigger_startup, utc_context_trigger_cleanup}, + {"utc_context_trigger_rule_custom_event_create_n", utc_context_trigger_rule_custom_event_create_n, utc_context_trigger_startup, utc_context_trigger_cleanup}, + {"utc_context_trigger_rule_custom_condition_create_p", utc_context_trigger_rule_custom_condition_create_p, utc_context_trigger_startup, utc_context_trigger_cleanup}, + {"utc_context_trigger_rule_custom_condition_create_n", utc_context_trigger_rule_custom_condition_create_n, utc_context_trigger_startup, utc_context_trigger_cleanup}, {NULL, NULL} }; diff --git a/src/utc/context/utc-context-trigger-custom.h b/src/utc/context/utc-context-trigger-custom.h new file mode 100755 index 0000000..80c72f6 --- /dev/null +++ b/src/utc/context/utc-context-trigger-custom.h @@ -0,0 +1,45 @@ +// +// Copyright (c) 2016 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 __UTC_CONTEXT_TRIGGER_CUSTOM_H__ +#define __UTC_CONTEXT_TRIGGER_CUSTOM_H__ + + +#define CONTEXT_TEST_PACKAGE_ID "core-context-tests" +#define CUSTOM_ITEM_WEATHER "weather" + +#define CUSTOM_WEATHER_TEMPLATE "{ \"temperature\": { \"type\": \"integer\", \"minimum\": -50, \"maximum\": 50}, \"status\": { \"enum\": [ \"sunny\", \"snowy\", \"cloudy\", \"rainy\"]} }" +#define CUSTOM_WEATHER_TEMPLATE2 "{ \"humidity\": { \"type\": \"integer\", \"minimum\": 0, \"maximum\": 100}, \"status\": { \"enum\": [ \"cold\", \"cool\", \"warm\", \"hot\"]} }" +#define CUSTOM_WEATHER_TEMPLATE_INVALID_JSON "{ \"temperature\": { \"type\": \"integer\", \"minimum\": -50, \"maximum\": 50}, \"status\": { \"enum\": [ \"sunny\", \"snowy\", \"cloudy\", \"rainy\"} }" +#define CUSTOM_WEATHER_TEMPLATE_INVALID1 "{ \"temperature\": { \"type\": \"string\", \"minimum\": -50, \"maximum\": 50}, \"status\": { \"enum\": [ \"sunny\", \"snowy\", \"cloudy\", \"rainy\"]} }" +#define CUSTOM_WEATHER_TEMPLATE_INVALID2 "{ \"temperature\": { \"type\": \"integer\", \"minimum\": -50, \"maximum\": 50}, \"status\": { \"type\": \"string\", \"maximum\": 15, \"enum\": [ \"sunny\", \"snowy\", \"cloudy\", \"rainy\"]} }" +#define CUSTOM_WEATHER_TEMPLATE_INVALID3 "{ \"temperature\": { \"type\": \"integer\", \"minimum\": -50, \"maximum\": 50}, \"status\": { \"enum\": [ 5, 6, 7]} }" +#define CUSTOM_WEATHER_TEMPLATE_INVALID4 "{ \"temperature\": { \"type\": \"integer\", \"minimum\": -50, \"maximum\": 50}, \"status\": { \"maximum\": 15, \"enum\": [ \"sunny\", \"snowy\", \"cloudy\", \"rainy\"]} }" + +// Valid +#define CUSTOM_WEATHER_DATA1 "{\"temperature\": 30, \"status\":\"sunny\"}" +#define CUSTOM_WEATHER_DATA2 "{\"temperature\": -1, \"status\":\"snowy\"}" +// Invalid KEY +#define CUSTOM_WEATHER_DATA_INVALID_KEY "{\"humidity\": 20, \"status\":\"cloudy\"}" +// Invalid value +#define CUSTOM_WEATHER_DATA_INVALID_VAL_INT "{\"temperature\": -100, \"status\":\"cloudy\"}" +#define CUSTOM_WEATHER_DATA_INVALID_VAL_STR "{\"temperature\": 30, \"status\":\"windy\"}" +// Invalid type +#define CUSTOM_WEATHER_DATA_INVALID_TYPE "{\"temperature\": 20, \"status\": 50}" +// Invalid json +#define CUSTOM_WEATHER_DATA_INVALID_JSON "{\"temperature\": 30 \"status\":\"sunny\"}" + + +#endif // __UTC_CONTEXT_TRIGGER_CUSTOM_H__ diff --git a/src/utc/context/utc-context-trigger.c b/src/utc/context/utc-context-trigger.c index f98a109..8dd9902 100755 --- a/src/utc/context/utc-context-trigger.c +++ b/src/utc/context/utc-context-trigger.c @@ -14,6 +14,7 @@ // limitations under the License. // #include "utc-context-common.h" +#include "utc-context-trigger-custom.h" #include #include #include "tct_app_common.h" @@ -128,6 +129,8 @@ void utc_context_trigger_cleanup(void) free(disabled_arr); disabled_arr = NULL; } + + context_trigger_custom_unregister(CUSTOM_ITEM_WEATHER); } /** @@ -2642,3 +2645,287 @@ int utc_context_trigger_rule_entry_add_option_n(void) return 0; } + +/** + * @testcase utc_context_trigger_custom_register_p + * @since_tizen 3.0 + * @description Positive test case of context_trigger_custom_register() + */ +int utc_context_trigger_custom_register_p(void) +{ + int error = CONTEXT_TRIGGER_ERROR_NONE; + + error = context_trigger_custom_register(CUSTOM_ITEM_WEATHER, CUSTOM_WEATHER_TEMPLATE); + assert_eq(error, CONTEXT_TRIGGER_ERROR_NONE); + + // Register same name & template again + error = context_trigger_custom_register(CUSTOM_ITEM_WEATHER, CUSTOM_WEATHER_TEMPLATE); + assert_eq(error, CONTEXT_TRIGGER_ERROR_NONE); + + context_trigger_custom_unregister(CUSTOM_ITEM_WEATHER); + + return 0; +} + +/** + * @testcase utc_context_trigger_custom_register_n + * @since_tizen 3.0 + * @description Negative test case of context_trigger_custom_register() + */ +int utc_context_trigger_custom_register_n(void) +{ + int error = CONTEXT_TRIGGER_ERROR_NONE; + + // Err: Null parameter + error = context_trigger_custom_register(NULL, CUSTOM_WEATHER_TEMPLATE); + assert_eq(error, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER); + + error = context_trigger_custom_register(CUSTOM_ITEM_WEATHER, NULL); + assert_eq(error, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER); + + error = context_trigger_custom_register(CUSTOM_ITEM_WEATHER, CUSTOM_WEATHER_TEMPLATE_INVALID_JSON); + assert_eq(error, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER); + + // Err: Invalid template (invalid, string->int, int->string) + error = context_trigger_custom_register(CUSTOM_ITEM_WEATHER, CUSTOM_WEATHER_TEMPLATE_INVALID1); + assert_eq(error, CONTEXT_TRIGGER_ERROR_INVALID_DATA); + + error = context_trigger_custom_register(CUSTOM_ITEM_WEATHER, CUSTOM_WEATHER_TEMPLATE_INVALID2); + assert_eq(error, CONTEXT_TRIGGER_ERROR_INVALID_DATA); + + error = context_trigger_custom_register(CUSTOM_ITEM_WEATHER, CUSTOM_WEATHER_TEMPLATE_INVALID3); + assert_eq(error, CONTEXT_TRIGGER_ERROR_INVALID_DATA); + + error = context_trigger_custom_register(CUSTOM_ITEM_WEATHER, CUSTOM_WEATHER_TEMPLATE_INVALID4); + assert_eq(error, CONTEXT_TRIGGER_ERROR_INVALID_DATA); + + // Err: Register same item name but different template + error = context_trigger_custom_register(CUSTOM_ITEM_WEATHER, CUSTOM_WEATHER_TEMPLATE); + assert_eq(error, CONTEXT_TRIGGER_ERROR_NONE); + + error = context_trigger_custom_register(CUSTOM_ITEM_WEATHER, CUSTOM_WEATHER_TEMPLATE2); + assert_eq(error, CONTEXT_TRIGGER_ERROR_DATA_EXIST); + + context_trigger_custom_unregister(CUSTOM_ITEM_WEATHER); + + return 0; +} + +/** + * @testcase utc_context_trigger_custom_unregister_p + * @since_tizen 3.0 + * @description Positive test case of context_trigger_custom_unregister() + */ +int utc_context_trigger_custom_unregister_p(void) +{ + int error = CONTEXT_TRIGGER_ERROR_NONE; + + error = context_trigger_custom_register(CUSTOM_ITEM_WEATHER, CUSTOM_WEATHER_TEMPLATE); + assert_eq(error, CONTEXT_TRIGGER_ERROR_NONE); + + error = context_trigger_custom_unregister(CUSTOM_ITEM_WEATHER); + assert_eq(error, CONTEXT_TRIGGER_ERROR_NONE); + + return 0; +} + +/** + * @testcase utc_context_trigger_custom_unregister_n + * @since_tizen 3.0 + * @description Negative test case of context_trigger_custom_unregister() + */ +int utc_context_trigger_custom_unregister_n(void) +{ + int error = CONTEXT_TRIGGER_ERROR_NONE; + + // Err: Null parameter + error = context_trigger_custom_unregister(NULL); + assert_eq(error, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER); + + // Err: Not supported + error = context_trigger_custom_unregister(CUSTOM_ITEM_WEATHER); + assert_eq(error, CONTEXT_TRIGGER_ERROR_NOT_SUPPORTED); + + return 0; +} + +/** + * @testcase utc_context_trigger_custom_publish_p + * @since_tizen 3.0 + * @description Positive test case of context_trigger_custom_publish() + */ +int utc_context_trigger_custom_publish_p(void) +{ + int error = CONTEXT_TRIGGER_ERROR_NONE; + + error = context_trigger_custom_register(CUSTOM_ITEM_WEATHER, CUSTOM_WEATHER_TEMPLATE); + assert_eq(error, CONTEXT_TRIGGER_ERROR_NONE); + + error = context_trigger_custom_publish(CUSTOM_ITEM_WEATHER, CUSTOM_WEATHER_DATA1); + assert_eq(error, CONTEXT_TRIGGER_ERROR_NONE); + + error = context_trigger_custom_publish(CUSTOM_ITEM_WEATHER, CUSTOM_WEATHER_DATA2); + assert_eq(error, CONTEXT_TRIGGER_ERROR_NONE); + + context_trigger_custom_unregister(CUSTOM_ITEM_WEATHER); + + return 0; +} + +/** + * @testcase utc_context_trigger_custom_publish_n + * @since_tizen 3.0 + * @description NegativePositive test case of context_trigger_custom_publish() + */ +int utc_context_trigger_custom_publish_n(void) +{ + int error = CONTEXT_TRIGGER_ERROR_NONE; + + // Err: Not supported + error = context_trigger_custom_publish(CUSTOM_ITEM_WEATHER, CUSTOM_WEATHER_DATA1); + assert_eq(error, CONTEXT_TRIGGER_ERROR_NOT_SUPPORTED); + + context_trigger_custom_register(CUSTOM_ITEM_WEATHER, CUSTOM_WEATHER_TEMPLATE); + + // Err: Invalid parameter + error = context_trigger_custom_publish(CUSTOM_ITEM_WEATHER, NULL); + assert_eq(error, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER); + + error = context_trigger_custom_publish(NULL, CUSTOM_WEATHER_DATA1); + assert_eq(error, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER); + + error = context_trigger_custom_publish(CUSTOM_ITEM_WEATHER, CUSTOM_WEATHER_DATA_INVALID_JSON); + assert_eq(error, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER); + + // Err: Invalid data + error = context_trigger_custom_publish(CUSTOM_ITEM_WEATHER, CUSTOM_WEATHER_DATA_INVALID_KEY); + assert_eq(error, CONTEXT_TRIGGER_ERROR_INVALID_DATA); + + error = context_trigger_custom_publish(CUSTOM_ITEM_WEATHER, CUSTOM_WEATHER_DATA_INVALID_VAL_INT); + assert_eq(error, CONTEXT_TRIGGER_ERROR_INVALID_DATA); + + error = context_trigger_custom_publish(CUSTOM_ITEM_WEATHER, CUSTOM_WEATHER_DATA_INVALID_VAL_STR); + assert_eq(error, CONTEXT_TRIGGER_ERROR_INVALID_DATA); + + error = context_trigger_custom_publish(CUSTOM_ITEM_WEATHER, CUSTOM_WEATHER_DATA_INVALID_TYPE); + assert_eq(error, CONTEXT_TRIGGER_ERROR_INVALID_DATA); + + + context_trigger_custom_unregister(CUSTOM_ITEM_WEATHER); + + return 0; +} + +/** + * @testcase utc_context_trigger_rule_custom_event_create_p + * @since_tizen 3.0 + * @description Positive test case of context_trigger_rule_custom_event_create() + */ +int utc_context_trigger_rule_custom_event_create_p(void) +{ + int error = CONTEXT_TRIGGER_ERROR_NONE; + + context_trigger_rule_entry_h event1 = NULL; + context_trigger_rule_entry_h event2 = NULL; + + context_trigger_custom_register(CUSTOM_ITEM_WEATHER, CUSTOM_WEATHER_TEMPLATE); + + error = context_trigger_rule_custom_event_create(CUSTOM_ITEM_WEATHER, CONTEXT_TEST_PACKAGE_ID, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &event1); + assert_eq(error, CONTEXT_TRIGGER_ERROR_NONE); + + error = context_trigger_rule_custom_event_create(CUSTOM_ITEM_WEATHER, CONTEXT_TEST_PACKAGE_ID, CONTEXT_TRIGGER_LOGICAL_DISJUNCTION, &event2); + assert_eq(error, CONTEXT_TRIGGER_ERROR_NONE); + + context_trigger_rule_entry_destroy(event1); + context_trigger_rule_entry_destroy(event2); + + context_trigger_custom_unregister(CUSTOM_ITEM_WEATHER); + + return 0; +} + +/** + * @testcase utc_context_trigger_rule_custom_event_create_n + * @since_tizen 3.0 + * @description Negative test case of context_trigger_rule_custom_event_create() + */ +int utc_context_trigger_rule_custom_event_create_n(void) +{ + int error = CONTEXT_TRIGGER_ERROR_NONE; + context_trigger_rule_entry_h event = NULL; + + // Err: Invalid parameter + error = context_trigger_rule_custom_event_create(NULL, CONTEXT_TEST_PACKAGE_ID, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &event); + assert_eq(error, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER); + + error = context_trigger_rule_custom_event_create(CUSTOM_ITEM_WEATHER, NULL, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &event); + assert_eq(error, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER); + + error = context_trigger_rule_custom_event_create(CUSTOM_ITEM_WEATHER, CONTEXT_TEST_PACKAGE_ID, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, NULL); + assert_eq(error, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER); + + // Err: Not supported + error = context_trigger_rule_custom_event_create(CUSTOM_ITEM_WEATHER, CONTEXT_TEST_PACKAGE_ID, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &event); + assert_eq(error, CONTEXT_TRIGGER_ERROR_NOT_SUPPORTED); + + context_trigger_rule_entry_destroy(event); + + return 0; +} + +/** + * @testcase utc_context_trigger_rule_custom_condition_create_p + * @since_tizen 3.0 + * @description Positive test case of context_trigger_rule_custom_condition_create() + */ +int utc_context_trigger_rule_custom_condition_create_p(void) +{ + int error = CONTEXT_TRIGGER_ERROR_NONE; + + context_trigger_rule_entry_h condition1 = NULL; + context_trigger_rule_entry_h condition2 = NULL; + + context_trigger_custom_register(CUSTOM_ITEM_WEATHER, CUSTOM_WEATHER_TEMPLATE); + + error = context_trigger_rule_custom_condition_create(CUSTOM_ITEM_WEATHER, CONTEXT_TEST_PACKAGE_ID, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &condition1); + assert_eq(error, CONTEXT_TRIGGER_ERROR_NONE); + + error = context_trigger_rule_custom_condition_create(CUSTOM_ITEM_WEATHER, CONTEXT_TEST_PACKAGE_ID, CONTEXT_TRIGGER_LOGICAL_DISJUNCTION, &condition2); + assert_eq(error, CONTEXT_TRIGGER_ERROR_NONE); + + context_trigger_rule_entry_destroy(condition1); + context_trigger_rule_entry_destroy(condition2); + + context_trigger_custom_unregister(CUSTOM_ITEM_WEATHER); + + return 0; +} + +/** + * @testcase utc_context_trigger_rule_custom_condition_create_n + * @since_tizen 3.0 + * @description Negative test case of context_trigger_rule_custom_condition_create() + */ +int utc_context_trigger_rule_custom_condition_create_n(void) +{ + int error = CONTEXT_TRIGGER_ERROR_NONE; + context_trigger_rule_entry_h condition = NULL; + + // Err: Invalid parameter + error = context_trigger_rule_custom_condition_create(NULL, CONTEXT_TEST_PACKAGE_ID, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &condition); + assert_eq(error, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER); + + error = context_trigger_rule_custom_condition_create(CUSTOM_ITEM_WEATHER, NULL, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &condition); + assert_eq(error, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER); + + error = context_trigger_rule_custom_condition_create(CUSTOM_ITEM_WEATHER, CONTEXT_TEST_PACKAGE_ID, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, NULL); + assert_eq(error, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER); + + // Err: Not supported + error = context_trigger_rule_custom_condition_create(CUSTOM_ITEM_WEATHER, CONTEXT_TEST_PACKAGE_ID, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &condition); + assert_eq(error, CONTEXT_TRIGGER_ERROR_NOT_SUPPORTED); + + context_trigger_rule_entry_destroy(condition); + + return 0; +}