All files / src/git zcl_abapgit_git_pack.clas.testclasses.abap

99.75% Statements 826/828
100% Branches 40/40
97.56% Functions 40/41
99.75% Lines 826/828

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 8291x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 6x 6x 1x 1x 5x 5x 1x 1x     1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1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5x 5x 5x 5x 5x 5x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
CLASS ltcl_progress_double DEFINITION CREATE PUBLIC FOR TESTING.
 
  PUBLIC SECTION.
    INTERFACES zif_abapgit_progress.
  PROTECTED SECTION.
  PRIVATE SECTION.
 
ENDCLASS.
 
CLASS ltcl_progress_double IMPLEMENTATION.
 
  METHOD zif_abapgit_progress~set_total.
    RETURN.
  ENDMETHOD.
 
  METHOD zif_abapgit_progress~show.
    RETURN.
  ENDMETHOD.
 
  METHOD zif_abapgit_progress~off.
    RETURN.
  ENDMETHOD.
 
ENDCLASS.
 
CLASS ltcl_tree DEFINITION FOR TESTING DURATION SHORT RISK LEVEL HARMLESS FINAL.
 
  PRIVATE SECTION.
    METHODS:
      test01 FOR TESTING RAISING zcx_abapgit_exception,
      test02 FOR TESTING RAISING zcx_abapgit_exception,
      test03 FOR TESTING RAISING zcx_abapgit_exception.
 
ENDCLASS.
 
CLASS ltcl_tree IMPLEMENTATION.
 
  METHOD test01.
 
    DATA: lt_nodes  TYPE zcl_abapgit_git_pack=>ty_nodes_tt,
          ls_node   LIKE LINE OF lt_nodes,
          lv_data   TYPE xstring,
          lt_result TYPE zcl_abapgit_git_pack=>ty_nodes_tt.
 
    CLEAR ls_node.
    ls_node-chmod = zif_abapgit_git_definitions=>c_chmod-file.
    ls_node-name = 'foobar.txt'.
    ls_node-sha1 = '5f46cb3c4b7f0b3600b64f744cde614a283a88dc'.
    APPEND ls_node TO lt_nodes.
 
    lv_data = zcl_abapgit_git_pack=>encode_tree( lt_nodes ).
    lt_result = zcl_abapgit_git_pack=>decode_tree( lv_data ).
 
    cl_abap_unit_assert=>assert_equals(
        exp = lt_nodes
        act = lt_result ).
 
  ENDMETHOD.
 
  METHOD test02.
 
    DATA: lt_nodes  TYPE zcl_abapgit_git_pack=>ty_nodes_tt,
          ls_node   LIKE LINE OF lt_nodes,
          lv_data   TYPE xstring,
          lt_result TYPE zcl_abapgit_git_pack=>ty_nodes_tt.
 
    CLEAR ls_node.
    ls_node-chmod = zif_abapgit_git_definitions=>c_chmod-file.
    ls_node-name = 'foobar.txt'.
    ls_node-sha1 = '5f46cb3c4b7f0b3600b64f744cde614a283a88dc'.
    APPEND ls_node TO lt_nodes.
 
    CLEAR ls_node.
    ls_node-chmod = zif_abapgit_git_definitions=>c_chmod-file.
    ls_node-name = 'something.md'.
    ls_node-sha1 = '1236cb3c4b7f0b3600b64f744cde614a283a88dc'.
    APPEND ls_node TO lt_nodes.
 
    lv_data = zcl_abapgit_git_pack=>encode_tree( lt_nodes ).
    lt_result = zcl_abapgit_git_pack=>decode_tree( lv_data ).
 
    cl_abap_unit_assert=>assert_equals(
        exp = lt_nodes
        act = lt_result ).
 
  ENDMETHOD.
 
  METHOD test03.
 
    DATA: lt_nodes  TYPE zcl_abapgit_git_pack=>ty_nodes_tt,
          ls_node   LIKE LINE OF lt_nodes,
          lv_data   TYPE xstring,
          lt_result TYPE zcl_abapgit_git_pack=>ty_nodes_tt.
 
    CLEAR ls_node.
    ls_node-chmod = zif_abapgit_git_definitions=>c_chmod-file.
    ls_node-name = 'foobar.txt'.
    ls_node-sha1 = '0000003c4b7f0b3600b64f744cde614a28000000'.
    APPEND ls_node TO lt_nodes.
 
    lv_data = zcl_abapgit_git_pack=>encode_tree( lt_nodes ).
    lt_result = zcl_abapgit_git_pack=>decode_tree( lv_data ).
 
    cl_abap_unit_assert=>assert_equals(
        exp = lt_nodes
        act = lt_result ).
 
  ENDMETHOD.
 
ENDCLASS.
 
 
CLASS ltcl_type_and_length DEFINITION DEFERRED.
CLASS zcl_abapgit_git_pack DEFINITION LOCAL FRIENDS ltcl_type_and_length.
 
CLASS ltcl_type_and_length DEFINITION FOR TESTING DURATION SHORT RISK LEVEL HARMLESS FINAL.
 
  PRIVATE SECTION.
    METHODS:
      test
        IMPORTING
          iv_length   TYPE i
          iv_type     TYPE zif_abapgit_git_definitions=>ty_type DEFAULT zif_abapgit_git_definitions=>c_type-commit
          iv_expected TYPE xstring
        RAISING
          zcx_abapgit_exception,
      type_and_length_0 FOR TESTING RAISING zcx_abapgit_exception,
      type_and_length_1 FOR TESTING RAISING zcx_abapgit_exception,
      type_and_length_10 FOR TESTING RAISING zcx_abapgit_exception,
      type_and_length_15 FOR TESTING RAISING zcx_abapgit_exception,
      type_and_length_16 FOR TESTING RAISING zcx_abapgit_exception,
      type_and_length_17 FOR TESTING RAISING zcx_abapgit_exception,
      type_and_length_100 FOR TESTING RAISING zcx_abapgit_exception,
      type_and_length_128 FOR TESTING RAISING zcx_abapgit_exception,
      type_and_length_2047 FOR TESTING RAISING zcx_abapgit_exception,
      type_and_length_2048 FOR TESTING RAISING zcx_abapgit_exception,
      type_and_length_90000 FOR TESTING RAISING zcx_abapgit_exception,
      type_and_length_1000000 FOR TESTING RAISING zcx_abapgit_exception.
 
ENDCLASS.
 
CLASS ltcl_type_and_length IMPLEMENTATION.
 
  METHOD test.
 
    DATA: lv_result TYPE xstring.
 
    lv_result = zcl_abapgit_git_pack=>type_and_length(
      iv_type   = iv_type
      iv_length = iv_length ).
 
    cl_abap_unit_assert=>assert_equals(
      act = lv_result
      exp = iv_expected ).
 
  ENDMETHOD.
 
  METHOD type_and_length_100.
 
    test( iv_length   = 100
          iv_expected = '9406' ).
 
  ENDMETHOD.
 
  METHOD type_and_length_2047.
 
    test( iv_length   = 2047
          iv_expected = '9F7F' ).
 
  ENDMETHOD.
 
  METHOD type_and_length_2048.
 
    test( iv_length   = 2048
          iv_expected = '908001' ).
 
  ENDMETHOD.
 
  METHOD type_and_length_90000.
 
    test( iv_length   = 90000
          iv_type     = zif_abapgit_git_definitions=>c_type-blob
          iv_expected = 'B0F92B' ).
 
  ENDMETHOD.
 
  METHOD type_and_length_10.
 
    test( iv_length   = 10
          iv_expected = '1A' ).
 
  ENDMETHOD.
 
  METHOD type_and_length_1000000.
 
    test( iv_length   = 1000000
          iv_expected = '90A4E803' ).
 
  ENDMETHOD.
 
  METHOD type_and_length_0.
 
    test( iv_length   = 0
          iv_expected = '10' ).
 
  ENDMETHOD.
 
  METHOD type_and_length_128.
 
    test( iv_length   = 128
          iv_expected = '9008' ).
 
  ENDMETHOD.
 
  METHOD type_and_length_1.
 
    test( iv_length   = 1
          iv_expected = '11' ).
 
  ENDMETHOD.
 
  METHOD type_and_length_15.
 
    test( iv_length   = 15
          iv_expected = '1F' ).
 
  ENDMETHOD.
 
  METHOD type_and_length_16.
 
    test( iv_length   = 16
          iv_expected = '9001' ).
 
  ENDMETHOD.
 
  METHOD type_and_length_17.
 
    test( iv_length   = 17
          iv_expected = '9101' ).
 
  ENDMETHOD.
 
ENDCLASS.
 
CLASS ltcl_pack DEFINITION DEFERRED.
CLASS zcl_abapgit_git_pack DEFINITION LOCAL FRIENDS ltcl_pack.
 
CLASS ltcl_pack DEFINITION FOR TESTING DURATION SHORT RISK LEVEL HARMLESS FINAL.
 
  PRIVATE SECTION.
 
    CONSTANTS: c_sha TYPE zif_abapgit_git_definitions=>ty_sha1 VALUE '5f46cb3c4b7f0b3600b64f744cde614a283a88dc'.
 
    METHODS setup.
 
    METHODS:
      commit FOR TESTING
        RAISING zcx_abapgit_exception,
      commit_newline FOR TESTING
        RAISING zcx_abapgit_exception,
      signed_commit FOR TESTING
        RAISING zcx_abapgit_exception,
      pack_short FOR TESTING
        RAISING zcx_abapgit_exception,
      pack_long FOR TESTING
        RAISING zcx_abapgit_exception,
      pack_multiple FOR TESTING
        RAISING zcx_abapgit_exception,
      sort_tree1 FOR TESTING,
      sort_tree2 FOR TESTING.
 
    METHODS:
      object_blob
        IMPORTING iv_data          TYPE xstring
        RETURNING VALUE(rs_object) TYPE zif_abapgit_definitions=>ty_object
        RAISING   zcx_abapgit_exception.
 
ENDCLASS.
 
 
CLASS ltcl_pack IMPLEMENTATION.
 
  METHOD setup.
    DATA lo_progress_double TYPE REF TO ltcl_progress_double.
    CREATE OBJECT lo_progress_double TYPE ltcl_progress_double.
 
    zcl_abapgit_progress=>set_instance( lo_progress_double ).
  ENDMETHOD.
 
  METHOD sort_tree1.
 
    DATA: lt_tree TYPE zcl_abapgit_git_pack=>ty_nodes_tt.
 
    FIELD-SYMBOLS: <ls_tree> LIKE LINE OF lt_tree.
 
 
    APPEND INITIAL LINE TO lt_tree ASSIGNING <ls_tree>.
    <ls_tree>-chmod = zif_abapgit_git_definitions=>c_chmod-file.
    <ls_tree>-name  = 'b.txt'.
    <ls_tree>-sha1  = '0123'.
 
    APPEND INITIAL LINE TO lt_tree ASSIGNING <ls_tree>.
    <ls_tree>-chmod = zif_abapgit_git_definitions=>c_chmod-file.
    <ls_tree>-name  = 'a.txt'.
    <ls_tree>-sha1  = '0123'.
 
    lt_tree = zcl_abapgit_git_pack=>sort_tree( lt_tree ).
 
    READ TABLE lt_tree INDEX 1 ASSIGNING <ls_tree>.
    cl_abap_unit_assert=>assert_subrc( ).
 
    cl_abap_unit_assert=>assert_equals(
      act = <ls_tree>-name
      exp = 'a.txt' ).
 
  ENDMETHOD.
 
  METHOD sort_tree2.
 
    DATA: lt_tree TYPE zcl_abapgit_git_pack=>ty_nodes_tt.
 
    FIELD-SYMBOLS: <ls_tree> LIKE LINE OF lt_tree.
 
 
    APPEND INITIAL LINE TO lt_tree ASSIGNING <ls_tree>.
    <ls_tree>-chmod = zif_abapgit_git_definitions=>c_chmod-file.
    <ls_tree>-name  = 'foo.txt'.
    <ls_tree>-sha1  = '0123'.
 
    APPEND INITIAL LINE TO lt_tree ASSIGNING <ls_tree>.
    <ls_tree>-chmod = zif_abapgit_git_definitions=>c_chmod-dir.
    <ls_tree>-name  = 'foo'.
    <ls_tree>-sha1  = '0123'.
 
    lt_tree = zcl_abapgit_git_pack=>sort_tree( lt_tree ).
 
    READ TABLE lt_tree INDEX 1 ASSIGNING <ls_tree>.
    cl_abap_unit_assert=>assert_subrc( ).
 
    cl_abap_unit_assert=>assert_equals(
      act = <ls_tree>-name
      exp = 'foo.txt' ).
 
  ENDMETHOD.
 
  METHOD pack_multiple.
 
    CONSTANTS: lc_data TYPE x LENGTH 15 VALUE '123456789ABCDEF545794254754554',
               lc_sha  TYPE zif_abapgit_git_definitions=>ty_sha1 VALUE '5f46cb3c4b7f0b3600b64f744cde614a283a88dc'.
 
    DATA: lt_objects TYPE zif_abapgit_definitions=>ty_objects_tt,
          ls_object  LIKE LINE OF lt_objects,
          lt_nodes   TYPE zcl_abapgit_git_pack=>ty_nodes_tt,
          ls_node    LIKE LINE OF lt_nodes,
          ls_commit  TYPE zcl_abapgit_git_pack=>ty_commit,
          lt_result  TYPE zif_abapgit_definitions=>ty_objects_tt,
          lv_data    TYPE xstring.
 
 
* blob
    lv_data = lc_data.
    CLEAR ls_object.
    ls_object-sha1 = zcl_abapgit_hash=>sha1_blob( lv_data ).
    ls_object-type = zif_abapgit_git_definitions=>c_type-blob.
    ls_object-data = lv_data.
    ls_object-index = 1.
    ls_object-adler32 = zcl_abapgit_hash=>adler32( lv_data ).
    APPEND ls_object TO lt_objects.
 
* commit
    CLEAR ls_commit.
    ls_commit-tree      = lc_sha.
    ls_commit-parent    = lc_sha.
    ls_commit-author    = 'John Foobar'.
    ls_commit-committer = 'John Foobar'.
    ls_commit-body      = 'body'.
    lv_data = zcl_abapgit_git_pack=>encode_commit( ls_commit ).
    CLEAR ls_object.
    ls_object-sha1 = zcl_abapgit_hash=>sha1_commit( lv_data ).
    ls_object-type = zif_abapgit_git_definitions=>c_type-commit.
    ls_object-data = lv_data.
    ls_object-index = 2.
    ls_object-adler32 = zcl_abapgit_hash=>adler32( lv_data ).
    APPEND ls_object TO lt_objects.
 
* tree
    CLEAR ls_node.
    ls_node-chmod     = '12456'.
    ls_node-name      = 'foobar.abap'.
    ls_node-sha1      = lc_sha.
    APPEND ls_node TO lt_nodes.
    lv_data = zcl_abapgit_git_pack=>encode_tree( lt_nodes ).
    CLEAR ls_object.
    ls_object-sha1 = zcl_abapgit_hash=>sha1_tree( lv_data ).
    ls_object-type = zif_abapgit_git_definitions=>c_type-tree.
    ls_object-data = lv_data.
    ls_object-index = 3.
    ls_object-adler32 = zcl_abapgit_hash=>adler32( lv_data ).
    APPEND ls_object TO lt_objects.
 
 
    CLEAR lv_data.
    lv_data = zcl_abapgit_git_pack=>encode( lt_objects ).
    lt_result = zcl_abapgit_git_pack=>decode( lv_data ).
 
    cl_abap_unit_assert=>assert_equals(
        exp = lt_objects
        act = lt_result ).
 
  ENDMETHOD.
 
  METHOD object_blob.
 
    rs_object-sha1 = zcl_abapgit_hash=>sha1_blob( iv_data ).
    rs_object-type = zif_abapgit_git_definitions=>c_type-blob.
    rs_object-data = iv_data.
    rs_object-index = 1.
    rs_object-adler32 = zcl_abapgit_hash=>adler32( iv_data ).
 
  ENDMETHOD.
 
  METHOD pack_short.
 
    CONSTANTS: lc_data TYPE x LENGTH 8 VALUE '0123456789ABCDEF'.
 
    DATA: lt_objects TYPE zif_abapgit_definitions=>ty_objects_tt,
          ls_object  LIKE LINE OF lt_objects,
          lt_result  TYPE zif_abapgit_definitions=>ty_objects_tt,
          lv_data    TYPE xstring.
 
 
    lv_data = lc_data.
 
    ls_object = object_blob( lv_data ).
    APPEND ls_object TO lt_objects.
 
    CLEAR lv_data.
    lv_data = zcl_abapgit_git_pack=>encode( lt_objects ).
    lt_result = zcl_abapgit_git_pack=>decode( lv_data ).
 
    cl_abap_unit_assert=>assert_equals(
        exp = lt_objects
        act = lt_result ).
 
  ENDMETHOD.
 
  METHOD pack_long.
 
    CONSTANTS: lc_data TYPE x LENGTH 8 VALUE '0123456789ABCDEF'.
 
    DATA: lt_objects TYPE zif_abapgit_definitions=>ty_objects_tt,
          ls_object  LIKE LINE OF lt_objects,
          lv_xstring TYPE xstring,
          lt_result  TYPE zif_abapgit_definitions=>ty_objects_tt,
          lv_data    TYPE xstring.
 
 
    lv_xstring = lc_data.
    DO 20 TIMES.
      CONCATENATE lv_xstring lv_data INTO lv_data IN BYTE MODE.
    ENDDO.
 
    ls_object = object_blob( lv_data ).
    APPEND ls_object TO lt_objects.
 
    CLEAR lv_data.
    lv_data = zcl_abapgit_git_pack=>encode( lt_objects ).
    lt_result = zcl_abapgit_git_pack=>decode( lv_data ).
 
    cl_abap_unit_assert=>assert_equals(
        exp = lt_objects
        act = lt_result ).
 
  ENDMETHOD.
 
  METHOD commit.
 
    DATA: ls_commit TYPE zcl_abapgit_git_pack=>ty_commit,
          ls_result TYPE zcl_abapgit_git_pack=>ty_commit,
          lv_data   TYPE xstring.
 
 
    ls_commit-tree      = c_sha.
    ls_commit-parent    = c_sha.
    ls_commit-author    = 'larshp <larshp@hotmail.com> 1387823471 +0100'.
    ls_commit-committer = 'larshp <larshp@hotmail.com> 1387823471 +0100'.
    ls_commit-body      = 'very informative'.
 
    lv_data = zcl_abapgit_git_pack=>encode_commit( ls_commit ).
    ls_result = zcl_abapgit_git_pack=>decode_commit( lv_data ).
 
    cl_abap_unit_assert=>assert_equals(
        exp = ls_commit
        act = ls_result ).
 
  ENDMETHOD.
 
  METHOD commit_newline.
 
    DATA: ls_commit TYPE zcl_abapgit_git_pack=>ty_commit,
          ls_result TYPE zcl_abapgit_git_pack=>ty_commit,
          lv_data   TYPE xstring.
 
 
    ls_commit-tree      = c_sha.
    ls_commit-parent    = c_sha.
    ls_commit-author    = 'larshp <larshp@hotmail.com> 1387823471 +0100'.
    ls_commit-committer = 'larshp <larshp@hotmail.com> 1387823471 +0100'.
    ls_commit-body      = 'very informative'
                        && cl_abap_char_utilities=>newline
                        && cl_abap_char_utilities=>newline.
 
    lv_data = zcl_abapgit_git_pack=>encode_commit( ls_commit ).
    ls_result = zcl_abapgit_git_pack=>decode_commit( lv_data ).
 
    cl_abap_unit_assert=>assert_equals(
        exp = ls_commit
        act = ls_result ).
 
  ENDMETHOD.
 
  METHOD signed_commit.
 
    DATA: ls_commit TYPE zcl_abapgit_git_pack=>ty_commit,
          ls_result TYPE zcl_abapgit_git_pack=>ty_commit,
          lv_data   TYPE xstring.
 
    ls_commit-tree      = c_sha.
    ls_commit-parent    = c_sha.
    ls_commit-author    = 'larshp <larshp@hotmail.com> 1387823471 +0100'.
    ls_commit-committer = 'larshp <larshp@hotmail.com> 1387823471 +0100'.
    ls_commit-body      = 'very informative'.
    ls_commit-gpgsig    = '-----END PGP SIGNATURE-----'
                          && |{ cl_abap_char_utilities=>newline } { cl_abap_char_utilities=>newline }|.
 
    lv_data = zcl_abapgit_git_pack=>encode_commit( ls_commit ).
    ls_result = zcl_abapgit_git_pack=>decode_commit( lv_data ).
 
    cl_abap_unit_assert=>assert_equals(
        exp = ls_commit
        act = ls_result ).
 
  ENDMETHOD.
 
ENDCLASS.
 
CLASS ltcl_git_pack_decode_commit DEFINITION FOR TESTING
    RISK LEVEL HARMLESS DURATION SHORT FINAL.
 
  PUBLIC SECTION.
    METHODS:
      decode1 FOR TESTING
        RAISING zcx_abapgit_exception,
      decode2 FOR TESTING
        RAISING zcx_abapgit_exception,
      decode3 FOR TESTING
        RAISING zcx_abapgit_exception.
 
  PRIVATE SECTION.
    DATA: ms_raw TYPE zcl_abapgit_git_pack=>ty_commit,
          mv_str TYPE string.
 
    METHODS:
      setup,
      decode
        RAISING zcx_abapgit_exception,
      add
        IMPORTING iv_string TYPE string.
 
ENDCLASS.
 
CLASS ltcl_git_pack_decode_commit IMPLEMENTATION.
 
  METHOD setup.
    CLEAR ms_raw.
    CLEAR mv_str.
  ENDMETHOD.
 
  METHOD add.
 
    CONCATENATE mv_str iv_string cl_abap_char_utilities=>newline INTO mv_str.
 
  ENDMETHOD.
 
  METHOD decode.
 
    DATA: lv_xstr TYPE xstring.
 
 
    lv_xstr = zcl_abapgit_convert=>string_to_xstring_utf8( mv_str ).
 
    ms_raw = zcl_abapgit_git_pack=>decode_commit( lv_xstr ).
 
  ENDMETHOD.
 
  METHOD decode1.
 
    add( 'tree tree' ).
    add( 'parent parent1' ).
    add( 'parent parent2' ).
    add( 'author author' ).
    add( 'committer committer' ).
    add( '' ).
    add( 'comment' ).
 
    decode( ).
 
    cl_abap_unit_assert=>assert_equals(
      act = ms_raw-tree
      exp = 'tree' ).
    cl_abap_unit_assert=>assert_equals(
      act = ms_raw-author
      exp = 'author' ).
    cl_abap_unit_assert=>assert_equals(
      act = ms_raw-committer
      exp = 'committer' ).
    cl_abap_unit_assert=>assert_equals(
      act = ms_raw-parent
      exp = 'parent1' ).
    cl_abap_unit_assert=>assert_equals(
      act = ms_raw-parent2
      exp = 'parent2' ).
 
    cl_abap_unit_assert=>assert_char_cp(
      act = ms_raw-body
      exp = 'comment+' ).
 
  ENDMETHOD.
 
  METHOD decode2.
 
    add( 'tree tree' ).
    add( 'author author' ).
    add( 'committer committer' ).
    add( '' ).
    add( 'comment' ).
 
    decode( ).
 
    cl_abap_unit_assert=>assert_equals(
      act = ms_raw-tree
      exp = 'tree' ).
    cl_abap_unit_assert=>assert_equals(
      act = ms_raw-author
      exp = 'author' ).
    cl_abap_unit_assert=>assert_equals(
      act = ms_raw-committer
      exp = 'committer' ).
    cl_abap_unit_assert=>assert_equals(
      act = ms_raw-parent
      exp = '' ).
 
    cl_abap_unit_assert=>assert_char_cp(
      act = ms_raw-body
      exp = 'comment+' ).
 
  ENDMETHOD.
 
  METHOD decode3.
 
    add( 'tree tree' ).
    add( 'parent parent1' ).
    add( 'author author' ).
    add( 'committer committer' ).
    add( '' ).
    add( 'comment' ).
 
    decode( ).
 
    cl_abap_unit_assert=>assert_equals(
      act = ms_raw-tree
      exp = 'tree' ).
    cl_abap_unit_assert=>assert_equals(
      act = ms_raw-author
      exp = 'author' ).
    cl_abap_unit_assert=>assert_equals(
      act = ms_raw-committer
      exp = 'committer' ).
    cl_abap_unit_assert=>assert_equals(
      act = ms_raw-parent
      exp = 'parent1' ).
 
    cl_abap_unit_assert=>assert_char_cp(
      act = ms_raw-body
      exp = 'comment+' ).
 
  ENDMETHOD.
 
ENDCLASS.
 
CLASS ltcl_tag DEFINITION FINAL FOR TESTING
  DURATION SHORT
  RISK LEVEL HARMLESS.
 
  PRIVATE SECTION.
    METHODS:
      decode_tag FOR TESTING RAISING cx_static_check.
ENDCLASS.
 
 
CLASS ltcl_tag IMPLEMENTATION.
 
  METHOD decode_tag.
 
    DATA: lv_test_data TYPE string,
          lv_xstring   TYPE xstring,
          ls_tag       TYPE zcl_abapgit_git_pack=>ty_tag.
 
    lv_test_data = |object 175f9a21b15a9012c97a3dd15aea6d74d4204b6b\n|
                && |type commit\n|
                && |tag tag_1\n|
                && |tagger Christian Guenter <christianguenter@googlemail.com> 1526718052 +0000\n|
                && |\n|
                && |This is an annotated tag\n|.
 
    lv_xstring = zcl_abapgit_convert=>string_to_xstring_utf8( lv_test_data ).
 
    ls_tag = zcl_abapgit_git_pack=>decode_tag( lv_xstring ).
 
    cl_abap_unit_assert=>assert_equals(
      exp = |175f9a21b15a9012c97a3dd15aea6d74d4204b6b|
      act = ls_tag-object ).
 
    cl_abap_unit_assert=>assert_equals(
      exp = 'commit'
      act = ls_tag-type ).
 
    cl_abap_unit_assert=>assert_equals(
      exp = 'tag_1'
      act = ls_tag-tag ).
 
    cl_abap_unit_assert=>assert_equals(
      exp = 'Christian Guenter'
      act = ls_tag-tagger_name ).
 
    cl_abap_unit_assert=>assert_equals(
      exp = 'christianguenter@googlemail.com'
      act = ls_tag-tagger_email ).
 
    cl_abap_unit_assert=>assert_equals(
      exp = 'This is an annotated tag'
      act = ls_tag-message ).
 
  ENDMETHOD.
 
ENDCLASS.
 
CLASS ltcl_get_length DEFINITION DEFERRED.
CLASS zcl_abapgit_git_pack DEFINITION LOCAL FRIENDS ltcl_get_length.
 
CLASS ltcl_get_length DEFINITION FOR TESTING DURATION SHORT RISK LEVEL HARMLESS FINAL.
 
  PRIVATE SECTION.
    METHODS:
      test
        IMPORTING
          iv_data     TYPE xstring
          iv_expected TYPE i,
      length_0 FOR TESTING RAISING zcx_abapgit_exception,
      length_1 FOR TESTING RAISING zcx_abapgit_exception,
      length_15 FOR TESTING RAISING zcx_abapgit_exception,
      length_31 FOR TESTING RAISING zcx_abapgit_exception,
      length_22783 FOR TESTING RAISING zcx_abapgit_exception.
 
ENDCLASS.
 
CLASS ltcl_get_length IMPLEMENTATION.
 
  METHOD test.
 
    DATA lv_length TYPE i.
    DATA lv_data TYPE xstring.
 
    lv_data = iv_data.
 
    zcl_abapgit_git_pack=>get_length(
      IMPORTING
        ev_length = lv_length
      CHANGING
        cv_data   = lv_data ).
 
    cl_abap_unit_assert=>assert_equals(
      act = lv_length
      exp = iv_expected ).
 
  ENDMETHOD.
 
  METHOD length_0.
 
    test(
      iv_data     = '00'
      iv_expected = 0 ).
 
  ENDMETHOD.
 
  METHOD length_1.
 
    test(
      iv_data     = '01'
      iv_expected = 1 ).
 
  ENDMETHOD.
 
  METHOD length_15.
* four least significant bits set
    test(
      iv_data     = '0F'
      iv_expected = 15 ).
 
  ENDMETHOD.
 
  METHOD length_31.
 
    test(
      iv_data     = '8F01'
      iv_expected = 31 ).
 
  ENDMETHOD.
 
  METHOD length_22783.
 
    test(
      iv_data     = '8F8F0B'
      iv_expected = 22783 ).
 
  ENDMETHOD.
 
ENDCLASS.