From: Utkarsh Tiwari Date: Wed, 3 Jan 2024 05:47:56 +0000 (+0530) Subject: [TCT][Tool][Non-ACR] UI modifications and void support added X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F56%2F303656%2F2;p=test%2Ftct%2Fnative%2Fapi.git [TCT][Tool][Non-ACR] UI modifications and void support added Change-Id: Ib252d22725535d5659d0f17b254d2f6dcfc04b9f Signed-off-by: Utkarsh Tiwari --- diff --git a/tool/TC_Assistant_Tool/check_if_tc_exists.py b/tool/TC_Assistant_Tool/check_if_tc_exists.py index f7d0ddbd6..09c15e860 100644 --- a/tool/TC_Assistant_Tool/check_if_tc_exists.py +++ b/tool/TC_Assistant_Tool/check_if_tc_exists.py @@ -10,7 +10,7 @@ def check_if_tc_already_exists(MODULE_NAME, HEADER_FILE_NAME, FILE_NAME_C, API_N DIR = CURRENT_PATH + "src/utc/" ROOTSTRAPS_DIR = get_latest_rootstrap() + "/" if MODULE_NAME == 'bluetooth': - MODULE_NAME = 'network' + MODULE_NAME = 'network' MODULE_NAME = get_api_header_file_contained_folder_name(ROOTSTRAPS_DIR, HEADER_FILE_NAME) with open(DIR + "/" + MODULE_NAME + "/" + FILE_NAME_C,"r") as file_one: for line in file_one: diff --git a/tool/TC_Assistant_Tool/enum_finder.py b/tool/TC_Assistant_Tool/enum_finder.py index 74d1c63cc..466d2590f 100644 --- a/tool/TC_Assistant_Tool/enum_finder.py +++ b/tool/TC_Assistant_Tool/enum_finder.py @@ -8,7 +8,8 @@ def check_api_header_file_location(HEADER_FILE_NAME, API_SEARCH): DIR = get_latest_rootstrap() with open(DIR + "//" + HEADER_FILE_NAME,"r") as file_one: for line_no, line in enumerate(file_one): - if line.find("int" + " " + API_SEARCH + "(") != -1: + line = line.strip() + if (line.find(API_SEARCH + "(") != -1 or line.find(API_SEARCH + " (") != -1) and line[:1] != '*': return True return False diff --git a/tool/TC_Assistant_Tool/header_file_parse.py b/tool/TC_Assistant_Tool/header_file_parse.py index ce04e4f3d..02ee12198 100644 --- a/tool/TC_Assistant_Tool/header_file_parse.py +++ b/tool/TC_Assistant_Tool/header_file_parse.py @@ -8,14 +8,14 @@ def input_output_text_extract(MODULE_NAME, HEADER_FILE_NAME, API_SEARCH): api_info = [] DIR = get_latest_rootstrap() if MODULE_NAME == 'bluetooth': - MODULE_NAME = 'network' - + MODULE_NAME = 'network' line_no = 0 flag = False with open(DIR + "/" + HEADER_FILE_NAME,"r") as file_one: for line in file_one: line_no += 1 - if line.find("int" + " " + API_SEARCH) != -1: + line = line.strip() + if (line.find(API_SEARCH + "(") != -1 or line.find(API_SEARCH + " (") != -1) and line[:1] != '*': api_info.append(line) flag = True break @@ -82,3 +82,4 @@ def api_description_extract(MODULE_NAME, HEADER_FILE_NAME, API_SEARCH): return desc + diff --git a/tool/TC_Assistant_Tool/list_all_apis.py b/tool/TC_Assistant_Tool/list_all_apis.py index 7e4012b06..7110a3af3 100644 --- a/tool/TC_Assistant_Tool/list_all_apis.py +++ b/tool/TC_Assistant_Tool/list_all_apis.py @@ -9,6 +9,7 @@ def extract_all_apis_text(MODULE_NAME, HEADER_FILE_NAME): with open(DIR + "/" + HEADER_FILE_NAME,"r") as file_one: for line in file_one: + line = line.strip() if line.find("int" + " " ) != -1: if "typedef" not in line: api_info.append(line) diff --git a/tool/TC_Assistant_Tool/tct_assistance.py b/tool/TC_Assistant_Tool/tct_assistance.py index 4d9556b6d..76f4e771d 100644 --- a/tool/TC_Assistant_Tool/tct_assistance.py +++ b/tool/TC_Assistant_Tool/tct_assistance.py @@ -61,7 +61,11 @@ import tkinter import tkinter as tk from tkinter.ttk import Progressbar from update_module_mapper_file import * -base = Tk() +import customtkinter +from CTkMessagebox import CTkMessagebox +customtkinter.set_appearance_mode("#d3d3d3") +customtkinter.set_default_color_theme("blue") +base = customtkinter.CTk() style = ttk.Style() # initializing log file @@ -526,6 +530,7 @@ def get_response(message): return "ThankYou for providing input." + "\n" + "TC already exists for API: " + API_SEARCH + "\n" + "Please try writing again." + "\n\n[ To navigate, please type 'Back' ]" api_return_values = get_api_return_values() + # print("api_return_values", api_return_values) api_params = get_api_parameters(API_NAMES) for k, v in api_return_values.items(): for i in API_NAMES: @@ -624,13 +629,13 @@ def get_response(message): elif intent == 'prepostinfo': enum_dict_pre_post = {} - + header_files_dict = get_header_files(MODULE_NAME) pre_post_api_names = message ## print("pre post details---------------", pre_post_api_names) NEGATIVE_TC_COUNT = 10 last_stage_index = 4 - + # get_pre_post_api_list_info(API_NAMES, MODULE_NAME, pre_post_api_names) #CURR_API_IND = 0 ## print("api length", API_NAMES) @@ -749,7 +754,8 @@ def get_response(message): ## print("enum_dict",enum_dict) ## print("enum_dict_pre_post",enum_dict_pre_post) ## print("feature_name",feature_name) - get_tc_template_code = tc_code_write1(RET_TYPE, MODULE_NAME, API_NAMES[API_IDX], PRE_POST_API_LIST, PRE_POST_API_ARGS_LIST, FUNC_API_ALL_ARGS[API_IDX], HEADER_FILE_CONTAINED_FOLDER, enum_dict, enum_dict_pre_post, feature_name, callback_duplicate_check) + # print("RET_TYPE ", RET_TYPE) + get_tc_template_code = tc_code_write1(get_all_api_list, MODULE_NAME, API_NAMES[API_IDX], PRE_POST_API_LIST, PRE_POST_API_ARGS_LIST, FUNC_API_ALL_ARGS[API_IDX], HEADER_FILE_CONTAINED_FOLDER, enum_dict, enum_dict_pre_post, feature_name, callback_duplicate_check) ## print("get_tc_template_code",get_tc_template_code) appended_code = appended_code + "\n" + get_tc_template_code ## print("tc_code from tct_assistance ") @@ -758,7 +764,7 @@ def get_response(message): #appended_negative_tc_code = appended_negative_tc_code + appended_code # print("TARGET_API_INPUT_PARAMS_LIST",TARGET_API_INPUT_PARAMS_LIST) if len(TARGET_API_INPUT_PARAMS_LIST) > 0: - appended_negative_tc_code = appended_negative_tc_code + get_tc_template_code + "\n" + all_negative_tc_combined(RET_TYPE, MODULE_NAME, API_NAMES[API_IDX], PRE_POST_API_LIST, PRE_POST_API_ARGS_LIST, FUNC_API_ALL_ARGS[API_IDX], HEADER_FILE_CONTAINED_FOLDER, 10, feature_name, enum_dict, enum_dict_pre_post) + "\n" + appended_negative_tc_code = appended_negative_tc_code + get_tc_template_code + "\n" + all_negative_tc_combined(get_all_api_list, MODULE_NAME, API_NAMES[API_IDX], PRE_POST_API_LIST, PRE_POST_API_ARGS_LIST, FUNC_API_ALL_ARGS[API_IDX], HEADER_FILE_CONTAINED_FOLDER, 10, feature_name, enum_dict, enum_dict_pre_post) + "\n" flag_check_negative = True input_params.append(len(TARGET_API_INPUT_PARAMS_LIST)) TARGET_API_INPUT_PARAMS_LIST.clear() @@ -991,6 +997,19 @@ def select_all(event): EntryBox.see(INSERT) return 'break' +def autoscroll_to_end(): + ChatLog.insert(END,"\n") + if scrollbar.get()[1]==1.0: + ChatLog.see(END) + if scrollbar.get()[0] > 0.0 and scrollbar.get()[1]!=1.0 : + ChatLog.see(END) + return + if scrollbar.get()[0] == 0.0 and scrollbar.get()[1] <= 1.0: + ChatLog.see(END) + if scrollbar.get()[0] == 1.0 and scrollbar.get()[1] != 1.0: + ChatLog.see(END) + base.after(1,autoscroll_to_end) + def send(event=None): msg = EntryBox.get("1.0",'end-1c').strip() EntryBox.delete("0.0",END) @@ -1008,14 +1027,17 @@ def send(event=None): ChatLog.tag_configure('tag-left', justify='left') ChatLog.tag_configure('tag-right', justify='right') ChatLog.insert(END, '\n') - User = Label(ChatLog,text=f"You: "+msg,background='#d0ffff', justify='left', padx=10, pady=5,font=("Malgun Gothic", 11 ),wraplength=500, cursor="hand1") + User = customtkinter.CTkLabel(ChatLog,text=f"You: "+msg, fg_color='#0066CC',corner_radius=10,text_color='white', justify='left', padx=10, pady=5,font=("Malgun Gothic", 13 ),wraplength=500, cursor="hand1") ChatLog.insert('end', '\n ','tag-right') ChatLog.window_create('end', window=User) ChatLog.insert(END, '\n') ChatLog.yview(END) + ChatLog.yview_moveto('0.0') + ChatLog.see(tk.END) + autoscroll_to_end() if msg.lower() == "exit": res = "Thanks, Goodbye !!" - User = Label(ChatLog,text="Assistant: "+res,background='#ffffd0', justify='left', padx=10, pady=5,font=("Malgun Gothic", 11 ),wraplength=500, cursor="hand1") + User = customtkinter.CTkLabel(ChatLog,text="Assistant: "+res, fg_color='#C0C0C0',corner_radius=10,text_color='black', justify='left', padx=10, pady=5,font=("Malgun Gothic", 13 ),wraplength=500, cursor="hand1") ChatLog.insert('end', '\n') # space to move Label to the right ChatLog.window_create('end', window=User) ChatLog.insert(END, '\n') @@ -1036,7 +1058,7 @@ def send(event=None): log_info_save(logger, "Assitant", res) if res == "exit": res = "Thanks, Goodbye !!" - User = Label(ChatLog,text="Assistant: "+res,background='#ffffd0', justify='left', padx=10, pady=5,font=("Malgun Gothic", 11 ),wraplength=500, cursor="hand1") + User = customtkinter.CTkLabel(ChatLog,text="Assistant: "+res, fg_color='#C0C0C0',corner_radius=10,text_color='black', justify='left', padx=10, pady=5,font=("Malgun Gothic", 13 ),wraplength=500, cursor="hand1") ChatLog.insert('end', '\n') # space to move Label to the right ChatLog.window_create('end', window=User) ChatLog.insert(END, '\n') @@ -1045,12 +1067,14 @@ def send(event=None): #time.sleep(2) base.after(1000,base.quit) elif msg.lower() != 'exit' and res != 'exit': - Bot = Label(ChatLog,text="Assistant: "+res,background='#ffffd0', justify='left', padx=10, pady=5,font=("Malgun Gothic", 11 ),wraplength=500, cursor="hand1") + Bot = customtkinter.CTkLabel(ChatLog,text="Assistant: "+res, fg_color='#C0C0C0',corner_radius=10,text_color='black', justify='left', padx=10, pady=5,font=("Malgun Gothic", 13 ),wraplength=500, cursor="hand1") ChatLog.insert('end', '\n') # space to move Label to the right ChatLog.window_create('end', window=Bot) ChatLog.insert(END, '\n') ChatLog.config(state=NORMAL) ChatLog.yview(END) + ChatLog.yview_moveto('0.0') + ChatLog.see(tk.END) User.bind("", lambda e:copy_text(msg)) Bot.bind("", lambda e:copy_text(res)) @@ -1061,26 +1085,27 @@ def send(event=None): def helpText(): # subprocess.call([opener, '/home/sri/tctapi/7.0/api/tool/TC_Assistant/HELP_TEXT.txt']) #Creates a Button to Open the Toplevel Window which opens a popup to display all the instructions - top= Toplevel(base) - top.geometry("750x820") + top= customtkinter.CTkToplevel(base) + top.geometry("700x720") top.title("Help Guide") with open('HELP_TEXT.txt', 'r') as file: data = file.read() - scroll_bar_help = Scrollbar(top) - scroll_bar_help.pack( side = RIGHT, fill = Y ) - mylist = Text(top, bd=0, bg="light grey", height="50", width="30", font="Arial",wrap=WORD) + mylist = customtkinter.CTkTextbox(top, bg_color="#EBEBEB", height=720, width=30,wrap=WORD) + scroll_bar_help = customtkinter.CTkScrollbar(top, command=mylist.yview,height=656) mylist.insert(END, data) mylist.pack(fill = BOTH ) - mylist.config(state=DISABLED) - scroll_bar_help.config( command = mylist.yview ) + mylist.configure(state=DISABLED) mylist['yscrollcommand'] = scroll_bar_help.set def on_closing(): - if messagebox.askokcancel("Quit", "Do you want to quit?"): - ## print("TC Assistant tool is closed..Goodbye..!!") - sys.exit() + # get yes/no answers + msg = CTkMessagebox(title="Exit?", message="Do you want to close the program?", + icon="question", option_1="No", option_2="Yes", option_3="") + response = msg.get() + + if response=="Yes": base.destroy() @@ -1091,46 +1116,46 @@ base.call('wm', 'iconphoto', base._w, ImageTk.PhotoImage(file=CURRENT_PATH_IMG + base.geometry("600x800") base.resizable(width=FALSE, height=FALSE) # base.eval('tk::PlaceWindow . center') +base.grid_rowconfigure(0, weight=1) +base.grid_columnconfigure(0, weight=1) center(base) -ChatLog = Text(base, bd=0, bg="white", height="8", width="10", font="Arial",wrap=WORD) -ChatLog.pack(fill=BOTH) +ChatLog = Text(base, bd=0, relief=FLAT, bg='#d3d3d3', highlightthickness=0, font="Arial",wrap=WORD) +ChatLog.pack(fill=BOTH, expand=True) welcomeText = "Hey, Welcome to TC Assistance System. Tell me how would you like to proceed? \n > You can add a new UTC in existing module [Type: 'existing']\n > You can add UTC in new module [Type: 'new']\n" log_info_save(logger, "Assitant", welcomeText) -Bot = Label(ChatLog,text="Assistant: "+welcomeText,background='#ffffd0', justify='left', padx=10, pady=5,font=("Malgun Gothic", 11),wraplength=500, cursor="hand2") +Bot = customtkinter.CTkLabel(ChatLog,text="Assistant: "+welcomeText, justify='left', fg_color='#C0C0C0',text_color='black',corner_radius=10,font=("Malgun Gothic", 13),wraplength=500, cursor="hand2") ChatLog.insert('end', '\n ') ChatLog.window_create('end', window=Bot) ChatLog.insert(END, '\n') ChatLog.config(state=DISABLED) -scrollbar = Scrollbar(base, command=ChatLog.yview) -ChatLog['yscrollcommand'] = scrollbar.set - -SendButton = Button(base, font=("Verdana", 11, 'bold'), text="Send", width="9", height=5, - bd=5, bg="#6495ED", activebackground="#6495ED", fg='#ffffff', - command=send, relief="raised") +scrollbar = customtkinter.CTkScrollbar(base, command=ChatLog.yview,height=656, orientation = 'vertical') +ChatLog.configure(yscrollcommand=scrollbar.set) +my_font = customtkinter.CTkFont("Malgun Gothic", 15, weight='bold') +SendButton = customtkinter.CTkButton(base, text="Send", width=115, height=60, border_width=0,font=my_font,command=send) -EntryBox = Text(base, bd=1, bg="white", width="29", height="5", font=("Malgun Gothic", 12)) +EntryBox = customtkinter.CTkTextbox(base, corner_radius=10, fg_color="#d3d3d3",text_color='#141414', border_width=0.5 , border_color="#343434", font=("Malgun Gothic", 15),width=455, height=70) EntryBox.focus_set() EntryBox.pack() -copyrightText = Label(base,text='Copyright (c) 2023 Samsung Electronics Co., Ltd.',justify='right',padx=4,font=("Verdana",10)) - -helpButton = Button(base,font=("Verdana",10),text='Help',width=5,height=2,bg='black',activebackground='grey',fg='white',command= helpText) +copyrightText = customtkinter.CTkLabel(base,text='Copyright (c) 2023 Samsung Electronics Co., Ltd.',justify='right',padx=4) +helpButton = customtkinter.CTkButton(base,text='Help',width=115,fg_color='#757575',hover_color="#343434",text_color='white',command= helpText) +ChatLog.yview(END) -scrollbar.place(x=576, y=22, height=656) +scrollbar.place(x=576, y=22) ChatLog.place(x=6, y=22, height=656, width=570) -EntryBox.place(x=6, y=680, height=80, width=455) -SendButton.place(x=461, y=678, height=83) +EntryBox.place(x=6, y=690) +SendButton.place(x=470, y=688) copyrightText.place(x=6, y=770) -helpButton.place(x=530,y=765,height=30,width=60) -# progress.place(width=150) +helpButton.place(x=470,y=765) +progress.place(width=150) progress.pack(fill=X, ipady=2) base.bind('',send) base.protocol("WM_DELETE_WINDOW", on_closing) diff --git a/tool/TC_Assistant_Tool/template_tc.py b/tool/TC_Assistant_Tool/template_tc.py index f6669ae25..ebd8232f6 100644 --- a/tool/TC_Assistant_Tool/template_tc.py +++ b/tool/TC_Assistant_Tool/template_tc.py @@ -266,6 +266,7 @@ def concat_params(CURR_API, v, check_if_param_is_in_or_out_dict, inp_out_params_ else: return FUNC_ARGS + def combined_func_args(lst): return set(lst) @@ -361,7 +362,6 @@ def tc_code_write1(RET_TYPE, MODULE_NAME, API_NAME, PRE_POST_API_LIST, PRE_POST_ TARGET_API_NAME_CB = API_NAME callback_func_combined = "" - # print("aaaaaaaaaaaaca",all_callback_args) for cb_name in all_callback_args: for header_file in header_files_dict: #print("header_files_dict",header_files_dict) @@ -377,35 +377,39 @@ def tc_code_write1(RET_TYPE, MODULE_NAME, API_NAME, PRE_POST_API_LIST, PRE_POST_ # callback_duplicate_check = callback_duplicate_check + all_callback_args # print("callback_func_combined") + API_NAME = API_NAME.strip() + # print("RET_TYPE - ", RET_TYPE, "API_NAME - ", API_NAME) + tc_code0 = ( - "/**\n" - f"* @testcase utc_{API_NAME}_p\n" - "* @since_tizen 8_0\n" - "* @type Positive\n" - f"* @description {api_desc}\n" - "* @scenario \n" - "*/\n") - tc_code = ( - f"{RET_TYPE} utc_{API_NAME}_p(void)\n" - "{\n" - " int ret;\n") - # tc_code4 = ( - # f" {k};" - # "\n" - # for k in all_comb_args_set) - # ## print("#########") - # ## print(inp_out_params_list_updated) - ## print("all_comb_args_set from tc_code") - # print("inp_out_params_list_updated final",inp_out_params_list_updated) + "/**\n" + f"* @testcase utc_{API_NAME}_p\n" + "* @since_tizen 8_0\n" + "* @type Positive\n" + f"* @description {api_desc}\n" + "* @scenario \n" + "*/\n") + + + if RET_TYPE[API_NAME] != 'void': + tc_code = ( + f"int utc_{API_NAME}_p(void)\n" + "{\n" + f" {RET_TYPE[API_NAME]} ret;\n") + else: + tc_code = ( + f"int utc_{API_NAME}_p(void)\n" + "{\n" + f" int ret;\n") + + tc_code4 = iniatialize_variables(inp_out_params_list_updated, all_comb_args_set, enum_dict, enum_dict_pre_post) # print("tc_code_4", tc_code4) tc_code6 = callback_func_combined - # f" {i}" for i in pre_apis - # f"{PRE_POST_API_ARGS_LIST[i]}" + check_if_param_is_in_or_out_dict = init_params_in_out_dict(inp_out_params_list_updated) # function call to iniatialize - # print("inp_out_params_list_updated",inp_out_params_list_updated) + # print("inp_out_params_list_updated",inp_out_params_list_updated) list_target_api_in_params(API_NAME, check_if_param_is_in_or_out_dict, inp_out_params_list_updated) if MODULE_NAME == "nsd": @@ -413,42 +417,53 @@ def tc_code_write1(RET_TYPE, MODULE_NAME, API_NAME, PRE_POST_API_LIST, PRE_POST_ if MODULE_NAME == "email": MODULE_NAME = "emails" - tc_code1 = (f" ret = {i}({concat_params(i, PRE_POST_API_ARGS_LIST[i], check_if_param_is_in_or_out_dict, inp_out_params_list_updated, all_callback_args, IDX_CALLBACK, PRE_POST_API_ARGS_LIST, TARGET_API_ARGS, TARGET_API_NAME_CB)});\n assert_eq(ret, TIZEN_ERROR_NONE);\n\n" for i in pre_apis) + tc_code1 = (f" ret = {i}({concat_params(i, PRE_POST_API_ARGS_LIST[i], check_if_param_is_in_or_out_dict, inp_out_params_list_updated, all_callback_args, IDX_CALLBACK, PRE_POST_API_ARGS_LIST, TARGET_API_ARGS, TARGET_API_NAME_CB)});\n assert_eq(ret, TIZEN_ERROR_NONE);\n\n" if RET_TYPE[i] != 'void' else f" {i}({concat_params(i, PRE_POST_API_ARGS_LIST[i], check_if_param_is_in_or_out_dict, inp_out_params_list_updated, all_callback_args, IDX_CALLBACK, PRE_POST_API_ARGS_LIST, TARGET_API_ARGS, TARGET_API_NAME_CB)});\n\n" for i in pre_apis) + + # print("tc_code1",tc_code1) tc_code_feature = "" - if feature_name != "": - x = feature_name.split('/') - length = len(x) - key_word = x[length - 1] - key_word=key_word.replace('.','_') - - tc_code_feature = (f" bool {key_word}_supported = false; \n\n" - f" ret = system_info_get_platform_bool(\"{feature_name}\", &{key_word}_supported);\n" - f" if({key_word}_supported == false)" + "{\n" - f" ret = {API_NAME}({concat_params(API_NAME, TARGET_API_ARGS, check_if_param_is_in_or_out_dict, inp_out_params_list_updated, all_callback_args, IDX_CALLBACK, PRE_POST_API_ARGS_LIST, TARGET_API_ARGS, TARGET_API_NAME_CB)});\n" - f" assert_eq(ret, TIZEN_ERROR_NOT_SUPPORTED);\n" - f" return 0;\n" - " }\n\n") - - ## print("tc_code_feature",tc_code_feature) - # print("lAPI_NAME",API_NAME, "TARGET_API_ARGS",TARGET_API_ARGS, "check_if_param_is_in_or_out_dict",check_if_param_is_in_or_out_dict, "inp_out_params_list_updated",inp_out_params_list_updated, "all_callback_args",all_callback_args, "IDX_CALLBACK",IDX_CALLBACK) - tc_code2 = (f" ret = {API_NAME}({concat_params(API_NAME, TARGET_API_ARGS, check_if_param_is_in_or_out_dict, inp_out_params_list_updated, all_callback_args, IDX_CALLBACK, PRE_POST_API_ARGS_LIST, TARGET_API_ARGS, TARGET_API_NAME_CB)});\n" - f" assert_eq(ret, TIZEN_ERROR_NONE);\n\n") - tc_code3 = (f" ret = {j}({concat_params(j, PRE_POST_API_ARGS_LIST[j], check_if_param_is_in_or_out_dict, inp_out_params_list_updated, all_callback_args, IDX_CALLBACK, PRE_POST_API_ARGS_LIST, TARGET_API_ARGS, TARGET_API_NAME_CB)});\n assert_eq(ret, TIZEN_ERROR_NONE);\n\n" - # f" return 0;\n" - # "}\n" + if RET_TYPE[API_NAME] != 'void': + if feature_name != "": + x = feature_name.split('/') + length = len(x) + key_word = x[length - 1] + key_word=key_word.replace('.','_') + + tc_code_feature = (f" bool {key_word}_supported = false; \n\n" + f" ret = system_info_get_platform_bool(\"{feature_name}\", &{key_word}_supported);\n" + f" if({key_word}_supported == false)" + "{\n" + f" ret = {API_NAME}({concat_params(API_NAME, TARGET_API_ARGS, check_if_param_is_in_or_out_dict, inp_out_params_list_updated, all_callback_args, IDX_CALLBACK, PRE_POST_API_ARGS_LIST, TARGET_API_ARGS, TARGET_API_NAME_CB)});\n" + f" assert_eq(ret, TIZEN_ERROR_NOT_SUPPORTED);\n" + f" return 0;\n" + " }\n\n") + + # print("tc_code_feature",tc_code_feature) + + if RET_TYPE[API_NAME] == 'void': + tc_code2 = (f" {API_NAME}({concat_params(API_NAME, TARGET_API_ARGS, check_if_param_is_in_or_out_dict, inp_out_params_list_updated, all_callback_args, IDX_CALLBACK, PRE_POST_API_ARGS_LIST, TARGET_API_ARGS, TARGET_API_NAME_CB)});\n\n") + + else: + tc_code2 = (f" ret = {API_NAME}({concat_params(API_NAME, TARGET_API_ARGS, check_if_param_is_in_or_out_dict, inp_out_params_list_updated, all_callback_args, IDX_CALLBACK, PRE_POST_API_ARGS_LIST, TARGET_API_ARGS, TARGET_API_NAME_CB)});\n assert_eq(ret, TIZEN_ERROR_NONE);\n\n") + + # print("tc_code2",tc_code2) + + tc_code3 = (f" ret = {j}({concat_params(j, PRE_POST_API_ARGS_LIST[j], check_if_param_is_in_or_out_dict, inp_out_params_list_updated, all_callback_args, IDX_CALLBACK, PRE_POST_API_ARGS_LIST, TARGET_API_ARGS, TARGET_API_NAME_CB)});\n assert_eq(ret, TIZEN_ERROR_NONE);\n\n" if RET_TYPE[j] != 'void' else f" {j}({concat_params(j, PRE_POST_API_ARGS_LIST[j], check_if_param_is_in_or_out_dict, inp_out_params_list_updated, all_callback_args, IDX_CALLBACK, PRE_POST_API_ARGS_LIST, TARGET_API_ARGS, TARGET_API_NAME_CB)});\n\n" + for j in post_apis) - ## print("tc code 3", ''.join(tc_code3)) + + + + # print("tc code 3", ''.join(tc_code3)) tc_code5 = (f" return 0;\n" "}\n") - ## print("tc code 5", tc_code5) + # print("tc code 5", tc_code5) ## print("tc_code_6", tc_code6) ## print("checking tccode1") ## print(''.join(tc_code1)) ## print("\n" + ''.join(tc_code1)) ## print("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^66") - ## print("checking tc") - ## print(tc_code6 + "\n\n" + tc_code0 + tc_code + tc_code4 + "\n" + ''.join(tc_code1) + tc_code_feature + tc_code2 + ''.join(tc_code3) + tc_code5) + # print("checking tc") + # print("\n" + tc_code6 + "\n\n" + tc_code0 + tc_code + tc_code4 + "\n" + ''.join(tc_code1) + tc_code_feature + tc_code2 + ''.join(tc_code3) + tc_code5) return "\n" + tc_code6 + "\n\n" + tc_code0 + tc_code + tc_code4 + "\n" + ''.join(tc_code1) + tc_code_feature + tc_code2 + ''.join(tc_code3) + tc_code5 diff --git a/tool/TC_Assistant_Tool/template_tc_negative.py b/tool/TC_Assistant_Tool/template_tc_negative.py index 4b3c1fb61..236b0fb0a 100644 --- a/tool/TC_Assistant_Tool/template_tc_negative.py +++ b/tool/TC_Assistant_Tool/template_tc_negative.py @@ -26,7 +26,7 @@ def check_if_str_or_int(inp_string): return "NULL" else: return "None" - + #NULL in case of handle, -1 for int or float or double def check_if_str_or_int_neg(list_of_all_params_with_retval, inp_string): for val in list_of_all_params_with_retval: @@ -47,7 +47,7 @@ def iniatialize_variables(inp_out_params_list_updated, all_comb_args_set, enum_d for pos, ele in enumerate(all_comb_args_set): if ele.find("_cb")>0: all_comb_args_set[pos] ="" - elif ele.split()[-1] in check_if_param_is_in_or_out_dict: + elif ele.split()[-1] in check_if_param_is_in_or_out_dict: dict_value = check_if_param_is_in_or_out_dict[ele.split()[-1]] ele1 = ele if dict_value == "in" and "char" in ele: @@ -85,12 +85,12 @@ def iniatialize_variables(inp_out_params_list_updated, all_comb_args_set, enum_d all_comb_args_set.remove(all_comb_args_set[pos]) # break store_last_word_of_args.append(ele.split()[-1]) - ## print("iniatialized variables 2") + ## print("iniatialized variables 2") for i in all_comb_args_set: if i == 'void' or i == 'void;' or i == '' or i == ' ' or i == ';': all_comb_args_set.remove(i) - + for pos, i in enumerate(all_comb_args_set): # print("reached till here tc_code4 part 0") # print(all_comb_args_set) @@ -104,7 +104,7 @@ def iniatialize_variables(inp_out_params_list_updated, all_comb_args_set, enum_d flag = 0 flag_pre_post = 0 - # print("reached till here tc_code4 part 1",enum_dict) + # print("reached till here tc_code4 part 1",enum_dict) for ele, val in enum_dict.items(): # print("entered", ele, val) for ele1, val1 in val.items(): @@ -117,7 +117,7 @@ def iniatialize_variables(inp_out_params_list_updated, all_comb_args_set, enum_d flag = 1 break if flag == 1: - break + break # print("reached till here tc_code4 part 2",enum_dict_pre_post) if "=" not in all_comb_args_set[pos]: for ele, val in enum_dict_pre_post.items(): @@ -132,7 +132,7 @@ def iniatialize_variables(inp_out_params_list_updated, all_comb_args_set, enum_d flag = 1 break if flag == 1: - break + break # print("reached till here tc_code4 part 3") # print("all arguments sequential ", i) if i == "void" or i == "void;" or i == "" or i == " ": @@ -143,7 +143,7 @@ def iniatialize_variables(inp_out_params_list_updated, all_comb_args_set, enum_d f" {k};" "\n" for k in all_comb_args_set) - + # print(tc_code4) return ''.join(tc_code4) @@ -163,7 +163,7 @@ def concat_params(CURR_API, v, check_if_param_is_in_or_out_dict, inp_out_params_ # print("COMBINED_API_ARGS_DICT_CB", COMBINED_API_ARGS_DICT_CB) for j in range(0, len(v)): if (v[j].split()[-1]).replace('*', '') in check_if_param_is_in_or_out_dict: - + for ij in inp_out_params_list_updated[CURR_API]: key = list(ij.keys())[0] value = ij[key] @@ -247,7 +247,7 @@ def concat_params_target(CURR_API, v, check_if_param_is_in_or_out_dict, inp_out_ else: return FUNC_ARGS -def combined_func_args(lst): +def combined_func_args(lst): return set(lst) def init_params_in_out_dict(inp_out_params_list_updated): @@ -266,7 +266,7 @@ def calc_count_of_in_params(API_NAME, inp_out_params_list_updated): in_out_array = inp_out_params_list_updated[API_NAME] else: in_out_array = [] - + for ele in in_out_array: key = list(ele.keys())[0] val = ele[key] @@ -329,7 +329,7 @@ def tc_code_write_negative(RET_TYPE, MODULE_NAME, API_NAME, PRE_POST_API_LIST, P if "_cb" in ele: all_callback_args.append(ele.split(" ")[0]) - + header_files_dict = get_header_files(MODULE_NAME) # for ever file in the dictionary we have to check if all the api names provided by the user exists or not # we will take api names one by one and check in all the files if it exists or not @@ -339,7 +339,7 @@ def tc_code_write_negative(RET_TYPE, MODULE_NAME, API_NAME, PRE_POST_API_LIST, P for API_SEARCH in post_apis: for HEADER_FILE_NAME in header_files_dict: inp_out_params_list_updated = input_output_params_extract(MODULE_NAME, HEADER_FILE_NAME, API_SEARCH, inp_out_params_list_updated) - for HEADER_FILE_NAME in header_files_dict: + for HEADER_FILE_NAME in header_files_dict: inp_out_params_list_updated = input_output_params_extract(MODULE_NAME, HEADER_FILE_NAME, API_NAME, inp_out_params_list_updated) api_desc = api_description_extract(MODULE_NAME, HEADER_FILE_NAME, API_NAME) @@ -374,17 +374,30 @@ def tc_code_write_negative(RET_TYPE, MODULE_NAME, API_NAME, PRE_POST_API_LIST, P "* @scenario \n" "*/\n") - if INPUT_PARAMETERS_COUNT > 1: - tc_code = ( - f"{RET_TYPE} utc_{API_NAME}_n{NEGATIVE_TC_COUNT}(void)\n" - "{\n" - " int ret;\n") + + if RET_TYPE[API_NAME] == 'void': + if INPUT_PARAMETERS_COUNT > 1: + tc_code = ( + f"int utc_{API_NAME}_n{NEGATIVE_TC_COUNT}(void)\n" + "{\n" + f" int ret;\n") + else: + tc_code = ( + f"int utc_{API_NAME}_n(void)\n" + "{\n" + f" int ret;\n") else: - tc_code = ( - f"{RET_TYPE} utc_{API_NAME}_n(void)\n" - "{\n" - " int ret;\n") - + if INPUT_PARAMETERS_COUNT > 1: + tc_code = ( + f"int utc_{API_NAME}_n{NEGATIVE_TC_COUNT}(void)\n" + "{\n" + f" {RET_TYPE[API_NAME]} ret;\n") + else: + tc_code = ( + f"int utc_{API_NAME}_n(void)\n" + "{\n" + f" {RET_TYPE[API_NAME]} ret;\n") + tc_code4 = iniatialize_variables(inp_out_params_list_updated, all_comb_args_set, enum_dict, enum_dict_pre_post) @@ -393,8 +406,10 @@ def tc_code_write_negative(RET_TYPE, MODULE_NAME, API_NAME, PRE_POST_API_LIST, P if MODULE_NAME == "email": MODULE_NAME = "emails" - tc_code1 = (f" ret = {i}({concat_params(i, PRE_POST_API_ARGS_LIST[i], check_if_param_is_in_or_out_dict, inp_out_params_list_updated, all_callback_args, IDX_CALLBACK, PRE_POST_API_ARGS_LIST, TARGET_API_ARGS, TARGET_API_NAME_CB)});\n assert_eq(ret, TIZEN_ERROR_NONE);\n\n" for i in pre_apis) - + + tc_code1 = (f" ret = {i}({concat_params(i, PRE_POST_API_ARGS_LIST[i], check_if_param_is_in_or_out_dict, inp_out_params_list_updated, all_callback_args, IDX_CALLBACK, PRE_POST_API_ARGS_LIST, TARGET_API_ARGS, TARGET_API_NAME_CB)});\n assert_eq(ret, TIZEN_ERROR_NONE);\n\n" if RET_TYPE[i] != 'void' else f" {i}({concat_params(i, PRE_POST_API_ARGS_LIST[i], check_if_param_is_in_or_out_dict, inp_out_params_list_updated, all_callback_args, IDX_CALLBACK, PRE_POST_API_ARGS_LIST, TARGET_API_ARGS, TARGET_API_NAME_CB)});\n\n" for i in pre_apis) + + # add invalid parameters to negative tc target api for HEADER_FILE_NAME in header_files_dict: RETVAL_INVALID_PARAMETERS = get_retval_of_invalid_params(MODULE_NAME, HEADER_FILE_NAME, API_NAME) @@ -402,26 +417,33 @@ def tc_code_write_negative(RET_TYPE, MODULE_NAME, API_NAME, PRE_POST_API_LIST, P break tc_code_feature = "" - if feature_name != "": - x = feature_name.split('/') - length = len(x) - key_word = x[length - 1] - key_word=key_word.replace('.','_') - - tc_code_feature = (f" bool {key_word}_supported = false; \n\n" - f" ret = system_info_get_platform_bool(\"{feature_name}\", &{key_word}_supported);\n" - f" if({key_word}_supported == false)" + "{\n" - f" ret = {API_NAME}({concat_params_target(API_NAME, FUNC_ARGS, check_if_param_is_in_or_out_dict, inp_out_params_list_updated, all_callback_args, IDX_CALLBACK, INPUT_PARAMETER_MARKED_NULL, all_comb_args_set, PRE_POST_API_ARGS_LIST, TARGET_API_ARGS, TARGET_API_NAME_CB)});\n" - f" assert_eq(ret, TIZEN_ERROR_NOT_SUPPORTED);\n" - f" return 0;\n" - " }\n\n") - tc_code2 = (f" ret = {API_NAME}({concat_params_target(API_NAME, FUNC_ARGS, check_if_param_is_in_or_out_dict, inp_out_params_list_updated, all_callback_args, IDX_CALLBACK, INPUT_PARAMETER_MARKED_NULL, all_comb_args_set, PRE_POST_API_ARGS_LIST, TARGET_API_ARGS, TARGET_API_NAME_CB)});\n" - f" assert_eq(ret, {RETVAL_INVALID_PARAMETERS});\n\n") - - tc_code3 = (f" ret = {j}({concat_params(j, PRE_POST_API_ARGS_LIST[j], check_if_param_is_in_or_out_dict, inp_out_params_list_updated, all_callback_args, IDX_CALLBACK, PRE_POST_API_ARGS_LIST, TARGET_API_ARGS, TARGET_API_NAME_CB)});\n assert_eq(ret, TIZEN_ERROR_NONE);\n\n" + if RET_TYPE[API_NAME] != 'void': + if feature_name != "": + x = feature_name.split('/') + length = len(x) + key_word = x[length - 1] + key_word=key_word.replace('.','_') + + tc_code_feature = (f" bool {key_word}_supported = false; \n\n" + f" ret = system_info_get_platform_bool(\"{feature_name}\", &{key_word}_supported);\n" + f" if({key_word}_supported == false)" + "{\n" + f" ret = {API_NAME}({concat_params_target(API_NAME, FUNC_ARGS, check_if_param_is_in_or_out_dict, inp_out_params_list_updated, all_callback_args, IDX_CALLBACK, INPUT_PARAMETER_MARKED_NULL, all_comb_args_set, PRE_POST_API_ARGS_LIST, TARGET_API_ARGS, TARGET_API_NAME_CB)});\n" + f" assert_eq(ret, TIZEN_ERROR_NOT_SUPPORTED);\n" + f" return 0;\n" + " }\n\n") + + if RET_TYPE[API_NAME] == 'void': + tc_code2 = (f" {API_NAME}({concat_params_target(API_NAME, FUNC_ARGS, check_if_param_is_in_or_out_dict, inp_out_params_list_updated, all_callback_args, IDX_CALLBACK, INPUT_PARAMETER_MARKED_NULL, all_comb_args_set, PRE_POST_API_ARGS_LIST, TARGET_API_ARGS, TARGET_API_NAME_CB)});\n\n") + else: + tc_code2 = (f" ret = {API_NAME}({concat_params_target(API_NAME, FUNC_ARGS, check_if_param_is_in_or_out_dict, inp_out_params_list_updated, all_callback_args, IDX_CALLBACK, INPUT_PARAMETER_MARKED_NULL, all_comb_args_set, PRE_POST_API_ARGS_LIST, TARGET_API_ARGS, TARGET_API_NAME_CB)});\n" + f" assert_eq(ret, {RETVAL_INVALID_PARAMETERS});\n\n") + + + tc_code3 = (f" ret = {j}({concat_params(j, PRE_POST_API_ARGS_LIST[j], check_if_param_is_in_or_out_dict, inp_out_params_list_updated, all_callback_args, IDX_CALLBACK, PRE_POST_API_ARGS_LIST, TARGET_API_ARGS, TARGET_API_NAME_CB)});\n assert_eq(ret, TIZEN_ERROR_NONE);\n\n" if RET_TYPE[j] != 'void' else f" {j}({concat_params(j, PRE_POST_API_ARGS_LIST[j], check_if_param_is_in_or_out_dict, inp_out_params_list_updated, all_callback_args, IDX_CALLBACK, PRE_POST_API_ARGS_LIST, TARGET_API_ARGS, TARGET_API_NAME_CB)});\n\n" for j in post_apis) + tc_code5 = (f" return 0;\n" "}\n") @@ -444,7 +466,7 @@ def all_negative_tc_combined(RET_TYPE, MODULE_NAME, API_NAME, PRE_POST_API_LIST, get_no_of_negative_tc_count(INPUT_PARAMETERS_COUNT) break flag = 0 - + return negative_tc_code diff --git a/tool/TC_Assistant_Tool/validate_api.py b/tool/TC_Assistant_Tool/validate_api.py index d11435b74..68270232d 100644 --- a/tool/TC_Assistant_Tool/validate_api.py +++ b/tool/TC_Assistant_Tool/validate_api.py @@ -30,7 +30,8 @@ def check_api_in_module(HEADER_FILE_NAME, API_SEARCH): with open(DIR + "//" + HEADER_FILE_NAME,"r") as file_one: updated_line_multiple='' for line_no, line in enumerate(file_one): - if line.find("int" + " " + API_SEARCH + "(") != -1: + line = line.strip() + if (line.find(API_SEARCH + "(") != -1 or line.find(API_SEARCH + " (") != -1) and line[:1] != '*': found_api = True updated_line = line.strip()