diff --git a/src/zcl_excel_common.clas.testclasses.abap b/src/zcl_excel_common.clas.testclasses.abap index 7ffcb5a..d7c336c 100644 --- a/src/zcl_excel_common.clas.testclasses.abap +++ b/src/zcl_excel_common.clas.testclasses.abap @@ -9,55 +9,45 @@ CLASS zcl_excel_common DEFINITION LOCAL FRIENDS lcl_excel_common_test. CLASS lcl_excel_common_test DEFINITION FOR TESTING RISK LEVEL HARMLESS DURATION SHORT. -*? -*? -*? -*?lcl_Excel_Common_Test -*? -*?f_Cut -*? -*?ZCL_EXCEL_COMMON -*? -*? -*?X -*? -*?X -*? -*?X -*? -*?X -*? -*? -*? -*? + PRIVATE SECTION. * ================ DATA: - lx_excel TYPE REF TO zcx_excel, - ls_symsg_act TYPE symsg, " actual messageinformation of exception - ls_symsg_exp TYPE symsg, " expected messageinformation of exception - f_cut TYPE REF TO zcl_excel_common. "class under test + lx_excel TYPE REF TO zcx_excel, + ls_symsg_act TYPE symsg, " actual messageinformation of exception + ls_symsg_exp TYPE symsg, " expected messageinformation of exception + f_cut TYPE REF TO zcl_excel_common. "class under test - CLASS-METHODS: class_setup. - CLASS-METHODS: class_teardown. METHODS: setup. - METHODS: teardown. -* METHODS: char2hex FOR TESTING. METHODS: convert_column2alpha FOR TESTING. METHODS: convert_column2int FOR TESTING. METHODS: date_to_excel_string FOR TESTING. METHODS: encrypt_password FOR TESTING. METHODS: excel_string_to_date FOR TESTING. METHODS: excel_string_to_time FOR TESTING. -* METHODS: number_to_excel_string FOR TESTING. METHODS: time_to_excel_string FOR TESTING. METHODS: split_file FOR TESTING. - METHODS: convert_range2column_a_row FOR TESTING. + METHODS: convert_range2column_a_row FOR TESTING RAISING cx_static_check. METHODS: describe_structure FOR TESTING. - METHODS: calculate_cell_distance FOR TESTING. + METHODS macro_calculate_cell_distance + IMPORTING + iv_reference_cell TYPE clike + iv_current_cell TYPE clike + iv_expected_column TYPE i + iv_expected_row TYPE i + RAISING + cx_static_check. + METHODS: calculate_cell_distance FOR TESTING RAISING cx_static_check. + + METHODS macro_shift_formula + IMPORTING + iv_reference_formula TYPE clike + iv_shift_cols TYPE i + iv_shift_rows TYPE i + iv_expected TYPE string. METHODS: shift_formula FOR TESTING. METHODS: is_cell_in_range FOR TESTING. -ENDCLASS. "lcl_Excel_Common_Test +ENDCLASS. *----------------------------------------------------------------------* @@ -68,20 +58,6 @@ ENDCLASS. "lcl_Excel_Common_Test CLASS lcl_excel_common_test IMPLEMENTATION. * =========================================== - METHOD class_setup. -* =================== - - - ENDMETHOD. "class_Setup - - - METHOD class_teardown. -* ====================== - - - ENDMETHOD. "class_Teardown - - METHOD setup. * ============= @@ -89,13 +65,6 @@ CLASS lcl_excel_common_test IMPLEMENTATION. ENDMETHOD. "setup - METHOD teardown. -* ================ - - - ENDMETHOD. "teardown - - METHOD convert_column2alpha. * ============================ DATA ep_column TYPE zexcel_cell_column_alpha. @@ -706,9 +675,9 @@ CLASS lcl_excel_common_test IMPLEMENTATION. METHOD split_file. * ============================ - DATA: ep_file TYPE text255, - ep_extension TYPE char10, - ep_dotextension TYPE char10. + DATA: ep_file TYPE text255, + ep_extension TYPE char10, + ep_dotextension TYPE char10. * Test 1. Basic conversion @@ -959,130 +928,284 @@ CLASS lcl_excel_common_test IMPLEMENTATION. ENDMETHOD. "describe_structure + METHOD macro_calculate_cell_distance. + + DATA: lv_offset_rows TYPE i, + lv_offset_cols TYPE i, + lv_message TYPE string. + + zcl_excel_common=>calculate_cell_distance( EXPORTING iv_reference_cell = iv_reference_cell + iv_current_cell = iv_current_cell + IMPORTING ev_row_difference = lv_offset_rows + ev_col_difference = lv_offset_cols ). +* Check delta columns + CONCATENATE 'Error calculating column difference in test:' + iv_reference_cell + '->' + iv_current_cell + INTO lv_message SEPARATED BY space. + cl_abap_unit_assert=>assert_equals( act = lv_offset_cols + exp = iv_expected_column + msg = lv_message + quit = 0 " continue tests + level = if_aunit_constants=>critical ). +* Check delta rows + CONCATENATE 'Error calculating row difference in test:' + iv_reference_cell + '->' + iv_current_cell + INTO lv_message SEPARATED BY space. + cl_abap_unit_assert=>assert_equals( act = lv_offset_rows + exp = iv_expected_row + msg = lv_message + quit = 0 " continue tests + level = if_aunit_constants=>critical ). + + ENDMETHOD. METHOD calculate_cell_distance. - DATA: lv_offset_rows TYPE i, - lv_offset_cols TYPE i, - lv_message TYPE string. - DEFINE macro_calculate_cell_distance. - zcl_excel_common=>calculate_cell_distance( exporting iv_reference_cell = &1 - iv_current_cell = &2 - importing ev_row_difference = lv_offset_rows - ev_col_difference = lv_offset_cols ). -* Check delta columns - concatenate 'Error calculating column difference in test:' - &1 - '->' - &2 - into lv_message separated by space. - cl_abap_unit_assert=>assert_equals( act = lv_offset_cols - exp = &3 - msg = lv_message - quit = 0 " continue tests - level = if_aunit_constants=>critical ). -* Check delta rows - concatenate 'Error calculating row difference in test:' - &1 - '->' - &2 - into lv_message separated by space. - cl_abap_unit_assert=>assert_equals( act = lv_offset_rows - exp = &4 - msg = lv_message - quit = 0 " continue tests - level = if_aunit_constants=>critical ). - END-OF-DEFINITION. + " Same cell + macro_calculate_cell_distance( + iv_reference_cell = 'C12' + iv_current_cell = 'C12' + iv_expected_column = 0 + iv_expected_row = 0 ). + " Shift down 1 place + macro_calculate_cell_distance( + iv_reference_cell = 'C12' + iv_current_cell = 'C13' + iv_expected_column = 0 + iv_expected_row = 1 ). - macro_calculate_cell_distance: - 'C12' 'C12' 0 0 , " Same cell - 'C12' 'C13' 0 1 , " Shift down 1 place - 'C12' 'C25' 0 13 , " Shift down some places - 'C12' 'C11' 0 -1 , " Shift up 1 place - 'C12' 'C1' 0 -11 , " Shift up some place - 'C12' 'D12' 1 0 , " Shift right 1 place - 'C12' 'AA12' 24 0 , " Shift right some places - 'C12' 'B12' -1 0 , " Shift left 1 place - 'AA12' 'C12' -24 0 , " Shift left some place - 'AA121' 'C12' -24 -109 . " The full package. + " Shift down some places + macro_calculate_cell_distance( + iv_reference_cell = 'C12' + iv_current_cell = 'C25' + iv_expected_column = 0 + iv_expected_row = 13 ). - ENDMETHOD. "CALCULATE_CELL_DISTANCE + " Shift up 1 place + macro_calculate_cell_distance( + iv_reference_cell = 'C12' + iv_current_cell = 'C11' + iv_expected_column = 0 + iv_expected_row = -1 ). + + " Shift up some place + macro_calculate_cell_distance( + iv_reference_cell = 'C12' + iv_current_cell = 'C1' + iv_expected_column = 0 + iv_expected_row = -11 ). + + " Shift right 1 place + macro_calculate_cell_distance( + iv_reference_cell = 'C12' + iv_current_cell = 'D12' + iv_expected_column = 1 + iv_expected_row = 0 ). + + " Shift right some places + macro_calculate_cell_distance( + iv_reference_cell = 'C12' + iv_current_cell = 'AA12' + iv_expected_column = 24 + iv_expected_row = 0 ). + + " Shift left 1 place + macro_calculate_cell_distance( + iv_reference_cell = 'C12' + iv_current_cell = 'B12' + iv_expected_column = -1 + iv_expected_row = 0 ). + + " Shift left some place + macro_calculate_cell_distance( + iv_reference_cell = 'AA12' + iv_current_cell = 'C12' + iv_expected_column = -24 + iv_expected_row = 0 ). + + " The full package. + macro_calculate_cell_distance( + iv_reference_cell = 'AA121' + iv_current_cell = 'C12' + iv_expected_column = -24 + iv_expected_row = -109 ). + + ENDMETHOD. + + METHOD macro_shift_formula. + + DATA: lv_resulting_formula TYPE string, + lv_message TYPE string, + lv_counter TYPE num8. + + ADD 1 TO lv_counter. + CLEAR lv_resulting_formula. + TRY. + lv_resulting_formula = zcl_excel_common=>shift_formula( iv_reference_formula = iv_reference_formula + iv_shift_cols = iv_shift_cols + iv_shift_rows = iv_shift_rows ). + CONCATENATE 'Wrong result in test' + lv_counter + 'shifting formula ' + iv_reference_formula + INTO lv_message SEPARATED BY space. + cl_abap_unit_assert=>assert_equals( act = lv_resulting_formula + exp = iv_expected + msg = lv_message + quit = 0 " continue tests + level = if_aunit_constants=>critical ). + CATCH zcx_excel. + CONCATENATE 'Unexpected exception occurred in test' + lv_counter + 'shifting formula ' + iv_reference_formula + INTO lv_message SEPARATED BY space. + cl_abap_unit_assert=>assert_equals( act = lv_resulting_formula + exp = iv_expected + msg = lv_message + quit = 0 " continue tests + level = if_aunit_constants=>critical ). + ENDTRY. + + ENDMETHOD. METHOD shift_formula. - DATA: lv_resulting_formula TYPE string, - lv_message TYPE string, - lv_counter TYPE num8. - DEFINE macro_shift_formula. - add 1 to lv_counter. - clear lv_resulting_formula. - try. - lv_resulting_formula = zcl_excel_common=>shift_formula( iv_reference_formula = &1 - iv_shift_cols = &2 - iv_shift_rows = &3 ). - concatenate 'Wrong result in test' - lv_counter - 'shifting formula ' - &1 - into lv_message separated by space. - cl_abap_unit_assert=>assert_equals( act = lv_resulting_formula - exp = &4 - msg = lv_message - quit = 0 " continue tests - level = if_aunit_constants=>critical ). - catch zcx_excel. - concatenate 'Unexpected exception occurred in test' - lv_counter - 'shifting formula ' - &1 - into lv_message separated by space. - cl_abap_unit_assert=>assert_equals( act = lv_resulting_formula - exp = &4 - msg = lv_message - quit = 0 " continue tests - level = if_aunit_constants=>critical ). - endtry. - END-OF-DEFINITION. + " Very basic check + macro_shift_formula( + iv_reference_formula = 'C17' + iv_shift_cols = 0 + iv_shift_rows = 0 + iv_expected = 'C17' ). -* Test shifts that should result in a valid output - macro_shift_formula: - 'C17' 0 0 'C17', " Very basic check - 'C17' 2 3 'E20', " Check shift right and down - 'C17' -2 -3 'A14', " Check shift left and up - '$C$17' 1 1 '$C$17', " Fixed columns/rows - 'SUM($C17:C$23)+C30' 1 11 'SUM($C28:D$23)+D41', " Operators and Ranges, mixed fixed rows or columns - 'RNGNAME1+C7' -1 -4 'RNGNAME1+B3', " Operators and Rangename - '"Date:"&TEXT(B2)' 1 1 '"Date:"&TEXT(C3)', " String literals and string concatenation - '[TEST6.XLSX]SHEET1!A1' 1 11 '[TEST6.XLSX]SHEET1!B12', " External sheet reference - `X(B13, "KK" ) ` 1 1 `X(C14,"KK")`, " superflous blanks, multi-argument functions, literals in function, unknown functions -* 'SIN((((((B2))))))' 1 1 'SIN((((((C3))))))', " Deep nesting -* 'SIN(SIN(SIN(SIN(E22))))' 0 1 'SIN(SIN(SIN(SIN(E23))))', " Different type of deep nesting - `SIN(SIN(SIN(SIN(E22))))` 0 1 'SIN(SIN(SIN(SIN(E23))))', " same as above - but with string input instead of Char-input - 'HEUTE()' 2 5 'HEUTE()', " Functions w/o arguments, No cellreferences - '"B2"' 2 5 '"B2"', " No cellreferences - '' 2 5 '', " Empty - 'A1+$A1+A$1+$A$1+B2' -1 0 '#REF!+$A1+#REF!+$A$1+A2', " Referencing error , column only , underflow - 'A1+$A1+A$1+$A$1+B2' 0 -1 '#REF!+#REF!+A$1+$A$1+B1', " Referencing error , row only , underflow - 'A1+$A1+A$1+$A$1+B2' -1 -1 '#REF!+#REF!+#REF!+$A$1+A1'. " Referencing error , row and column , underflow - ENDMETHOD. "SHIFT_FORMULA +" Check shift right and down + macro_shift_formula( + iv_reference_formula = 'C17' + iv_shift_cols = 2 + iv_shift_rows = 3 + iv_expected = 'E20' ). + +" Check shift left and up + macro_shift_formula( + iv_reference_formula = 'C17' + iv_shift_cols = -2 + iv_shift_rows = -3 + iv_expected = 'A14' ). + +" Fixed columns/rows + macro_shift_formula( + iv_reference_formula = '$C$17' + iv_shift_cols = 1 + iv_shift_rows = 1 + iv_expected = '$C$17' ). + +" Operators and Ranges, mixed fixed rows or columns + macro_shift_formula( + iv_reference_formula = 'SUM($C17:C$23)+C30' + iv_shift_cols = 1 + iv_shift_rows = 11 + iv_expected = 'SUM($C28:D$23)+D41' ). + +" Operators and Rangename + macro_shift_formula( + iv_reference_formula = 'RNGNAME1+C7' + iv_shift_cols = -1 + iv_shift_rows = -4 + iv_expected = 'RNGNAME1+B3' ). + +" String literals and string concatenation + macro_shift_formula( + iv_reference_formula = '"Date:"&TEXT(B2)' + iv_shift_cols = 1 + iv_shift_rows = 1 + iv_expected = '"Date:"&TEXT(C3)' ). + +" External sheet reference + macro_shift_formula( + iv_reference_formula = '[TEST6.XLSX]SHEET1!A1' + iv_shift_cols = 1 + iv_shift_rows = 11 + iv_expected = '[TEST6.XLSX]SHEET1!B12' ). + +" superflous blanks, multi-argument functions, literals in function, unknown functions + macro_shift_formula( + iv_reference_formula = `X(B13, "KK" ) ` + iv_shift_cols = 1 + iv_shift_rows = 1 + iv_expected = `X(C14,"KK")` ). + +" same as above - but with string input instead of Char-input + macro_shift_formula( + iv_reference_formula = `SIN(SIN(SIN(SIN(E22))))` + iv_shift_cols = 0 + iv_shift_rows = 1 + iv_expected = 'SIN(SIN(SIN(SIN(E23))))' ). + +" Functions w/o arguments, No cellreferences + macro_shift_formula( + iv_reference_formula = 'HEUTE()' + iv_shift_cols = 2 + iv_shift_rows = 5 + iv_expected = 'HEUTE()' ). + +" No cellreferences + macro_shift_formula( + iv_reference_formula = '"B2"' + iv_shift_cols = 2 + iv_shift_rows = 5 + iv_expected = '"B2"' ). + +" Empty + macro_shift_formula( + iv_reference_formula = '' + iv_shift_cols = 2 + iv_shift_rows = 5 + iv_expected = '' ). + +" Referencing error , column only , underflow + macro_shift_formula( + iv_reference_formula = 'A1+$A1+A$1+$A$1+B2' + iv_shift_cols = -1 + iv_shift_rows = 0 + iv_expected = '#REF!+$A1+#REF!+$A$1+A2' ). + +" Referencing error , row only , underflow + macro_shift_formula( + iv_reference_formula = 'A1+$A1+A$1+$A$1+B2' + iv_shift_cols = 0 + iv_shift_rows = -1 + iv_expected = '#REF!+#REF!+A$1+$A$1+B1' ). + +" Referencing error , row and column , underflow + macro_shift_formula( + iv_reference_formula = 'A1+$A1+A$1+$A$1+B2' + iv_shift_cols = -1 + iv_shift_rows = -1 + iv_expected = '#REF!+#REF!+#REF!+$A$1+A1' ). + + ENDMETHOD. METHOD is_cell_in_range. DATA ep_cell_in_range TYPE abap_bool. * Test 1: upper left corner (in range) TRY. - ep_cell_in_range = zcl_excel_common=>is_cell_in_range( - ip_column = 'B' - ip_row = 2 - ip_range = 'B2:D4' ). + ep_cell_in_range = zcl_excel_common=>is_cell_in_range( + ip_column = 'B' + ip_row = 2 + ip_range = 'B2:D4' ). - cl_abap_unit_assert=>assert_equals( - act = ep_cell_in_range - exp = abap_true - msg = 'Check cell in range failed' - level = if_aunit_constants=>critical ). - CATCH zcx_excel. + cl_abap_unit_assert=>assert_equals( + act = ep_cell_in_range + exp = abap_true + msg = 'Check cell in range failed' + level = if_aunit_constants=>critical ). + CATCH zcx_excel. cl_abap_unit_assert=>fail( msg = 'Unexpected exception' level = if_aunit_constants=>critical ). @@ -1090,17 +1213,17 @@ CLASS lcl_excel_common_test IMPLEMENTATION. * Test 2: lower right corner (in range) TRY. - ep_cell_in_range = zcl_excel_common=>is_cell_in_range( - ip_column = 'D' - ip_row = 4 - ip_range = 'B2:D4' ). + ep_cell_in_range = zcl_excel_common=>is_cell_in_range( + ip_column = 'D' + ip_row = 4 + ip_range = 'B2:D4' ). - cl_abap_unit_assert=>assert_equals( - act = ep_cell_in_range - exp = abap_true - msg = 'Check cell in range failed' - level = if_aunit_constants=>critical ). - CATCH zcx_excel. + cl_abap_unit_assert=>assert_equals( + act = ep_cell_in_range + exp = abap_true + msg = 'Check cell in range failed' + level = if_aunit_constants=>critical ). + CATCH zcx_excel. cl_abap_unit_assert=>fail( msg = 'Unexpected exception' level = if_aunit_constants=>critical ). @@ -1108,17 +1231,17 @@ CLASS lcl_excel_common_test IMPLEMENTATION. * Test 3: left side (out of range) TRY. - ep_cell_in_range = zcl_excel_common=>is_cell_in_range( - ip_column = 'A' - ip_row = 3 - ip_range = 'B2:D4' ). + ep_cell_in_range = zcl_excel_common=>is_cell_in_range( + ip_column = 'A' + ip_row = 3 + ip_range = 'B2:D4' ). - cl_abap_unit_assert=>assert_equals( - act = ep_cell_in_range - exp = abap_false - msg = 'Check cell in range failed' - level = if_aunit_constants=>critical ). - CATCH zcx_excel. + cl_abap_unit_assert=>assert_equals( + act = ep_cell_in_range + exp = abap_false + msg = 'Check cell in range failed' + level = if_aunit_constants=>critical ). + CATCH zcx_excel. cl_abap_unit_assert=>fail( msg = 'Unexpected exception' level = if_aunit_constants=>critical ). @@ -1126,17 +1249,17 @@ CLASS lcl_excel_common_test IMPLEMENTATION. * Test 4: upper side (out of range) TRY. - ep_cell_in_range = zcl_excel_common=>is_cell_in_range( - ip_column = 'C' - ip_row = 1 - ip_range = 'B2:D4' ). + ep_cell_in_range = zcl_excel_common=>is_cell_in_range( + ip_column = 'C' + ip_row = 1 + ip_range = 'B2:D4' ). - cl_abap_unit_assert=>assert_equals( - act = ep_cell_in_range - exp = abap_false - msg = 'Check cell in range failed' - level = if_aunit_constants=>critical ). - CATCH zcx_excel. + cl_abap_unit_assert=>assert_equals( + act = ep_cell_in_range + exp = abap_false + msg = 'Check cell in range failed' + level = if_aunit_constants=>critical ). + CATCH zcx_excel. cl_abap_unit_assert=>fail( msg = 'Unexpected exception' level = if_aunit_constants=>critical ). @@ -1144,17 +1267,17 @@ CLASS lcl_excel_common_test IMPLEMENTATION. * Test 5: right side (out of range) TRY. - ep_cell_in_range = zcl_excel_common=>is_cell_in_range( - ip_column = 'E' - ip_row = 3 - ip_range = 'B2:D4' ). + ep_cell_in_range = zcl_excel_common=>is_cell_in_range( + ip_column = 'E' + ip_row = 3 + ip_range = 'B2:D4' ). - cl_abap_unit_assert=>assert_equals( - act = ep_cell_in_range - exp = abap_false - msg = 'Check cell in range failed' - level = if_aunit_constants=>critical ). - CATCH zcx_excel. + cl_abap_unit_assert=>assert_equals( + act = ep_cell_in_range + exp = abap_false + msg = 'Check cell in range failed' + level = if_aunit_constants=>critical ). + CATCH zcx_excel. cl_abap_unit_assert=>fail( msg = 'Unexpected exception' level = if_aunit_constants=>critical ). @@ -1162,21 +1285,21 @@ CLASS lcl_excel_common_test IMPLEMENTATION. * Test 6: lower side (out of range) TRY. - ep_cell_in_range = zcl_excel_common=>is_cell_in_range( - ip_column = 'C' - ip_row = 5 - ip_range = 'B2:D4' ). + ep_cell_in_range = zcl_excel_common=>is_cell_in_range( + ip_column = 'C' + ip_row = 5 + ip_range = 'B2:D4' ). - cl_abap_unit_assert=>assert_equals( - act = ep_cell_in_range - exp = abap_false - msg = 'Check cell in range failed' - level = if_aunit_constants=>critical ). - CATCH zcx_excel. + cl_abap_unit_assert=>assert_equals( + act = ep_cell_in_range + exp = abap_false + msg = 'Check cell in range failed' + level = if_aunit_constants=>critical ). + CATCH zcx_excel. cl_abap_unit_assert=>fail( msg = 'Unexpected exception' level = if_aunit_constants=>critical ). ENDTRY. ENDMETHOD. -ENDCLASS. "lcl_Excel_Common_Test +ENDCLASS.