From 80010875f7f4c2731e9bff27812bd1509b4b58e5 Mon Sep 17 00:00:00 2001 From: Lars Hvam Date: Wed, 28 Feb 2018 13:15:53 +0100 Subject: [PATCH] hash class, add unit tests (#1226) --- src/utils/zcl_abapgit_hash.clas.abap | 30 +++++++------ .../zcl_abapgit_hash.clas.testclasses.abap | 42 +++++++++++++++++++ src/utils/zcl_abapgit_hash.clas.xml | 1 + 3 files changed, 61 insertions(+), 12 deletions(-) create mode 100644 src/utils/zcl_abapgit_hash.clas.testclasses.abap diff --git a/src/utils/zcl_abapgit_hash.clas.abap b/src/utils/zcl_abapgit_hash.clas.abap index 3142a16e9..5cf72681f 100644 --- a/src/utils/zcl_abapgit_hash.clas.abap +++ b/src/utils/zcl_abapgit_hash.clas.abap @@ -3,21 +3,27 @@ CLASS zcl_abapgit_hash DEFINITION CREATE PUBLIC . PUBLIC SECTION. + CLASS-METHODS adler32 - IMPORTING iv_xstring TYPE xstring - RETURNING VALUE(rv_checksum) TYPE zif_abapgit_definitions=>ty_adler32. - + IMPORTING + !iv_xstring TYPE xstring + RETURNING + VALUE(rv_checksum) TYPE zif_abapgit_definitions=>ty_adler32 . CLASS-METHODS sha1 - IMPORTING iv_type TYPE zif_abapgit_definitions=>ty_type - iv_data TYPE xstring - RETURNING VALUE(rv_sha1) TYPE zif_abapgit_definitions=>ty_sha1 - RAISING zcx_abapgit_exception. - + IMPORTING + !iv_type TYPE zif_abapgit_definitions=>ty_type + !iv_data TYPE xstring + RETURNING + VALUE(rv_sha1) TYPE zif_abapgit_definitions=>ty_sha1 + RAISING + zcx_abapgit_exception . CLASS-METHODS sha1_raw - IMPORTING iv_data TYPE xstring - RETURNING VALUE(rv_sha1) TYPE zif_abapgit_definitions=>ty_sha1 - RAISING zcx_abapgit_exception. - + IMPORTING + !iv_data TYPE xstring + RETURNING + VALUE(rv_sha1) TYPE zif_abapgit_definitions=>ty_sha1 + RAISING + zcx_abapgit_exception . ENDCLASS. diff --git a/src/utils/zcl_abapgit_hash.clas.testclasses.abap b/src/utils/zcl_abapgit_hash.clas.testclasses.abap new file mode 100644 index 000000000..0d48a2554 --- /dev/null +++ b/src/utils/zcl_abapgit_hash.clas.testclasses.abap @@ -0,0 +1,42 @@ + +CLASS ltcl_test DEFINITION FOR TESTING + DURATION SHORT + RISK LEVEL HARMLESS FINAL. + + PRIVATE SECTION. + METHODS: + adler32 FOR TESTING, + sha1 FOR TESTING RAISING zcx_abapgit_exception. + +ENDCLASS. + + +CLASS ltcl_test IMPLEMENTATION. + + METHOD adler32. + + DATA: lv_adler TYPE zif_abapgit_definitions=>ty_adler32. + + lv_adler = zcl_abapgit_hash=>adler32( '1122334455667788' ). + + cl_abap_unit_assert=>assert_equals( + act = lv_adler + exp = '08000265' ). + + ENDMETHOD. + + METHOD sha1. + + DATA: lv_sha1 TYPE zif_abapgit_definitions=>ty_sha1. + + lv_sha1 = zcl_abapgit_hash=>sha1( + iv_type = zif_abapgit_definitions=>gc_type-commit + iv_data = '112211221122' ). + + cl_abap_unit_assert=>assert_equals( + act = lv_sha1 + exp = 'af2261a340c5188baf86a64a581d22012303023c' ). + + ENDMETHOD. + +ENDCLASS. diff --git a/src/utils/zcl_abapgit_hash.clas.xml b/src/utils/zcl_abapgit_hash.clas.xml index 2892066db..3c45176da 100644 --- a/src/utils/zcl_abapgit_hash.clas.xml +++ b/src/utils/zcl_abapgit_hash.clas.xml @@ -12,6 +12,7 @@ X X X + X