All files / output zcl_abapgit_zlib_stream.clas.testclasses.mjs

100% Statements 133/133
93.33% Branches 14/15
100% Functions 10/10
100% Lines 133/133

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 1331x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 1x 7x 7x 7x 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 8x 8x 8x 8x 8x 8x 8x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 16x 16x 16x 16x 16x 16x 16x 16x 16x 1x 1x 1x 1x 1x 1x 1x 1x 8x 8x 8x 1x 1x 1x 1x 1x 1x 1x 1x
const {zcl_abapgit_zlib_stream} = await import("./zcl_abapgit_zlib_stream.clas.mjs");
const {cx_root} = await import("./cx_root.clas.mjs");
// zcl_abapgit_zlib_stream.clas.testclasses.abap
 
 
class ltcl_test {
  static STATIC_SUPER = undefined;
  static INTERNAL_TYPE = 'CLAS';
  static INTERNAL_NAME = 'CLAS-ZCL_ABAPGIT_ZLIB_STREAM-LTCL_TEST';
  static IMPLEMENTED_INTERFACES = [];
  static ATTRIBUTES = {};
  static METHODS = {"TEST": {"visibility": "I", "parameters": {}},
  "TEST_BYTE_00": {"visibility": "I", "parameters": {}},
  "TEST_BYTE_FF": {"visibility": "I", "parameters": {}},
  "TEST_EMPTY": {"visibility": "I", "parameters": {}},
  "TEST_TAKE_BIT_VS_TAKE_BITS": {"visibility": "I", "parameters": {}},
  "TEST_TAKE_BIT_CROSS_BYTE": {"visibility": "I", "parameters": {}},
  "TEST_TAKE_BIT_LAST_CLEARS": {"visibility": "I", "parameters": {}}};
  constructor() {
    this.me = new abap.types.ABAPObject();
    this.me.set(this);
    this.INTERNAL_ID = abap.internalIdCounter++;
    this.FRIENDS_ACCESS_INSTANCE = {
      "test": this.#test.bind(this),
      "test_byte_00": this.#test_byte_00.bind(this),
      "test_byte_ff": this.#test_byte_ff.bind(this),
      "test_empty": this.#test_empty.bind(this),
      "test_take_bit_vs_take_bits": this.#test_take_bit_vs_take_bits.bind(this),
      "test_take_bit_cross_byte": this.#test_take_bit_cross_byte.bind(this),
      "test_take_bit_last_clears": this.#test_take_bit_last_clears.bind(this),
    };
  }
  async constructor_(INPUT) {
    if (super.constructor_) { await super.constructor_(INPUT); }
    return this;
  }
  async #test() {
    let lo_stream = new abap.types.ABAPObject({qualifiedName: "ZCL_ABAPGIT_ZLIB_STREAM", RTTIName: "\\CLASS=ZCL_ABAPGIT_ZLIB_STREAM"});
    let lv_remaining = new abap.types.Integer({qualifiedName: "I"});
    let lv_int = new abap.types.Integer({qualifiedName: "I"});
    let lv_bits = new abap.types.String({qualifiedName: "STRING"});
    let lv_bytes = new abap.types.XString({qualifiedName: "XSTRING"});
    lo_stream.set(await (new abap.Classes['ZCL_ABAPGIT_ZLIB_STREAM']()).constructor_({iv_data: abap.CharacterFactory.get(12, '112233445566')}));
    lv_bits.set((await lo_stream.get().take_bits({iv_length: abap.IntegerFactory.get(8)})));
    await abap.Classes['CL_ABAP_UNIT_ASSERT'].assert_equals({act: lv_bits, exp: abap.CharacterFactory.get(8, '00010001')});
    lv_remaining.set((await lo_stream.get().remaining()));
    await abap.Classes['CL_ABAP_UNIT_ASSERT'].assert_equals({act: lv_remaining, exp: abap.IntegerFactory.get(6)});
    lv_int.set((await lo_stream.get().take_int({iv_length: abap.IntegerFactory.get(8)})));
    await abap.Classes['CL_ABAP_UNIT_ASSERT'].assert_equals({act: lv_int, exp: abap.IntegerFactory.get(34)});
    lv_bytes.set((await lo_stream.get().take_bytes({iv_length: abap.IntegerFactory.get(2)})));
    await abap.Classes['CL_ABAP_UNIT_ASSERT'].assert_equals({act: lv_bytes, exp: abap.CharacterFactory.get(4, '3344')});
  }
  async #test_empty() {
    let lo_stream = new abap.types.ABAPObject({qualifiedName: "ZCL_ABAPGIT_ZLIB_STREAM", RTTIName: "\\CLASS=ZCL_ABAPGIT_ZLIB_STREAM"});
    let lv_xstr = new abap.types.XString({qualifiedName: "XSTRING"});
    lo_stream.set(await (new abap.Classes['ZCL_ABAPGIT_ZLIB_STREAM']()).constructor_({iv_data: lv_xstr}));
    await abap.Classes['CL_ABAP_UNIT_ASSERT'].assert_equals({act: (await lo_stream.get().remaining()), exp: abap.IntegerFactory.get(1)});
  }
  async #test_byte_00() {
    let lo_stream = new abap.types.ABAPObject({qualifiedName: "ZCL_ABAPGIT_ZLIB_STREAM", RTTIName: "\\CLASS=ZCL_ABAPGIT_ZLIB_STREAM"});
    lo_stream.set(await (new abap.Classes['ZCL_ABAPGIT_ZLIB_STREAM']()).constructor_({iv_data: abap.CharacterFactory.get(2, '00')}));
    await abap.Classes['CL_ABAP_UNIT_ASSERT'].assert_equals({act: (await lo_stream.get().take_bits({iv_length: abap.IntegerFactory.get(8)})), exp: abap.CharacterFactory.get(8, '00000000')});
    lo_stream.set(await (new abap.Classes['ZCL_ABAPGIT_ZLIB_STREAM']()).constructor_({iv_data: abap.CharacterFactory.get(2, '00')}));
    await abap.Classes['CL_ABAP_UNIT_ASSERT'].assert_equals({act: (await lo_stream.get().take_int({iv_length: abap.IntegerFactory.get(8)})), exp: abap.IntegerFactory.get(0)});
    lo_stream.set(await (new abap.Classes['ZCL_ABAPGIT_ZLIB_STREAM']()).constructor_({iv_data: abap.CharacterFactory.get(2, '00')}));
    await abap.Classes['CL_ABAP_UNIT_ASSERT'].assert_equals({act: (await lo_stream.get().take_bytes({iv_length: abap.IntegerFactory.get(1)})), exp: abap.CharacterFactory.get(2, '00')});
  }
  async #test_byte_ff() {
    let lo_stream = new abap.types.ABAPObject({qualifiedName: "ZCL_ABAPGIT_ZLIB_STREAM", RTTIName: "\\CLASS=ZCL_ABAPGIT_ZLIB_STREAM"});
    lo_stream.set(await (new abap.Classes['ZCL_ABAPGIT_ZLIB_STREAM']()).constructor_({iv_data: abap.CharacterFactory.get(2, 'FF')}));
    await abap.Classes['CL_ABAP_UNIT_ASSERT'].assert_equals({act: (await lo_stream.get().take_bits({iv_length: abap.IntegerFactory.get(8)})), exp: abap.CharacterFactory.get(8, '11111111')});
    lo_stream.set(await (new abap.Classes['ZCL_ABAPGIT_ZLIB_STREAM']()).constructor_({iv_data: abap.CharacterFactory.get(2, 'FF')}));
    await abap.Classes['CL_ABAP_UNIT_ASSERT'].assert_equals({act: (await lo_stream.get().take_int({iv_length: abap.IntegerFactory.get(8)})), exp: new abap.types.Integer().set(255)});
    lo_stream.set(await (new abap.Classes['ZCL_ABAPGIT_ZLIB_STREAM']()).constructor_({iv_data: abap.CharacterFactory.get(2, 'FF')}));
    await abap.Classes['CL_ABAP_UNIT_ASSERT'].assert_equals({act: (await lo_stream.get().take_bytes({iv_length: abap.IntegerFactory.get(1)})), exp: abap.CharacterFactory.get(2, 'FF')});
  }
  async #test_take_bit_vs_take_bits() {
    let lo_stream1 = new abap.types.ABAPObject({qualifiedName: "ZCL_ABAPGIT_ZLIB_STREAM", RTTIName: "\\CLASS=ZCL_ABAPGIT_ZLIB_STREAM"});
    let lo_stream2 = new abap.types.ABAPObject({qualifiedName: "ZCL_ABAPGIT_ZLIB_STREAM", RTTIName: "\\CLASS=ZCL_ABAPGIT_ZLIB_STREAM"});
    let lv_bit = new abap.types.Integer({qualifiedName: "I"});
    let lv_bits = new abap.types.String({qualifiedName: "STRING"});
    lo_stream1.set(await (new abap.Classes['ZCL_ABAPGIT_ZLIB_STREAM']()).constructor_({iv_data: abap.CharacterFactory.get(2, 'A5')}));
    lo_stream2.set(await (new abap.Classes['ZCL_ABAPGIT_ZLIB_STREAM']()).constructor_({iv_data: abap.CharacterFactory.get(2, 'A5')}));
    const indexBackup1 = abap.builtin.sy.get().index.get();
    const unique493 = abap.IntegerFactory.get(8).get();
    for (let unique494 = 0; unique494 < unique493; unique494++) {
      abap.builtin.sy.get().index.set(unique494 + 1);
      lv_bit.set((await lo_stream1.get().take_bit()));
      lv_bits.set((await lo_stream2.get().take_bits({iv_length: abap.IntegerFactory.get(1)})));
      await abap.Classes['CL_ABAP_UNIT_ASSERT'].assert_equals({act: lv_bit, exp: lv_bits, msg: new abap.types.String().set(`Mismatch at bit ${abap.templateFormatting(abap.builtin.sy.get().index)}`)});
      await abap.Classes['CL_ABAP_UNIT_ASSERT'].assert_equals({act: (await lo_stream1.get().remaining()), exp: (await lo_stream2.get().remaining())});
      await abap.Classes['CL_ABAP_UNIT_ASSERT'].assert_equals({act: lo_stream1.get().FRIENDS_ACCESS_INSTANCE["mv_bits"], exp: lo_stream2.get().FRIENDS_ACCESS_INSTANCE["mv_bits"]});
    }
    abap.builtin.sy.get().index.set(indexBackup1);
  }
  async #test_take_bit_cross_byte() {
    let lo_stream1 = new abap.types.ABAPObject({qualifiedName: "ZCL_ABAPGIT_ZLIB_STREAM", RTTIName: "\\CLASS=ZCL_ABAPGIT_ZLIB_STREAM"});
    let lo_stream2 = new abap.types.ABAPObject({qualifiedName: "ZCL_ABAPGIT_ZLIB_STREAM", RTTIName: "\\CLASS=ZCL_ABAPGIT_ZLIB_STREAM"});
    let lv_bit = new abap.types.Integer({qualifiedName: "I"});
    let lv_bits = new abap.types.String({qualifiedName: "STRING"});
    lo_stream1.set(await (new abap.Classes['ZCL_ABAPGIT_ZLIB_STREAM']()).constructor_({iv_data: abap.CharacterFactory.get(4, 'A53C')}));
    lo_stream2.set(await (new abap.Classes['ZCL_ABAPGIT_ZLIB_STREAM']()).constructor_({iv_data: abap.CharacterFactory.get(4, 'A53C')}));
    const indexBackup1 = abap.builtin.sy.get().index.get();
    const unique495 = abap.IntegerFactory.get(16).get();
    for (let unique496 = 0; unique496 < unique495; unique496++) {
      abap.builtin.sy.get().index.set(unique496 + 1);
      await abap.Classes['CL_ABAP_UNIT_ASSERT'].assert_equals({act: (await lo_stream1.get().remaining()), exp: (await lo_stream2.get().remaining())});
      await abap.Classes['CL_ABAP_UNIT_ASSERT'].assert_equals({act: lo_stream1.get().FRIENDS_ACCESS_INSTANCE["mv_bits"], exp: lo_stream2.get().FRIENDS_ACCESS_INSTANCE["mv_bits"]});
      lv_bit.set((await lo_stream1.get().take_bit()));
      lv_bits.set((await lo_stream2.get().take_bits({iv_length: abap.IntegerFactory.get(1)})));
      await abap.Classes['CL_ABAP_UNIT_ASSERT'].assert_equals({act: lv_bit, exp: lv_bits, msg: new abap.types.String().set(`Mismatch at bit ${abap.templateFormatting(abap.builtin.sy.get().index)}`)});
      await abap.Classes['CL_ABAP_UNIT_ASSERT'].assert_equals({act: (await lo_stream1.get().remaining()), exp: (await lo_stream2.get().remaining())});
      await abap.Classes['CL_ABAP_UNIT_ASSERT'].assert_equals({act: lo_stream1.get().FRIENDS_ACCESS_INSTANCE["mv_bits"], exp: lo_stream2.get().FRIENDS_ACCESS_INSTANCE["mv_bits"]});
    }
    abap.builtin.sy.get().index.set(indexBackup1);
  }
  async #test_take_bit_last_clears() {
    let lo_stream = new abap.types.ABAPObject({qualifiedName: "ZCL_ABAPGIT_ZLIB_STREAM", RTTIName: "\\CLASS=ZCL_ABAPGIT_ZLIB_STREAM"});
    lo_stream.set(await (new abap.Classes['ZCL_ABAPGIT_ZLIB_STREAM']()).constructor_({iv_data: abap.CharacterFactory.get(4, 'A53C')}));
    const indexBackup1 = abap.builtin.sy.get().index.get();
    const unique497 = abap.IntegerFactory.get(8).get();
    for (let unique498 = 0; unique498 < unique497; unique498++) {
      abap.builtin.sy.get().index.set(unique498 + 1);
      await lo_stream.get().take_bit();
    }
    abap.builtin.sy.get().index.set(indexBackup1);
    await abap.Classes['CL_ABAP_UNIT_ASSERT'].assert_initial({act: lo_stream.get().FRIENDS_ACCESS_INSTANCE["mv_bits"], msg: new abap.types.String().set(`mv_bits must be initial after consuming all 8 bits`)});
    await abap.Classes['CL_ABAP_UNIT_ASSERT'].assert_equals({act: (await lo_stream.get().take_bit()), exp: abap.IntegerFactory.get(0), msg: new abap.types.String().set(`9th bit must come from second byte`)});
    await abap.Classes['CL_ABAP_UNIT_ASSERT'].assert_equals({act: lo_stream.get().FRIENDS_ACCESS_INSTANCE["mv_bits"], exp: abap.CharacterFactory.get(7, '0011110'), msg: new abap.types.String().set(`mv_bits must contain remaining 7 bits of second byte`)});
  }
}
abap.Classes['CLAS-ZCL_ABAPGIT_ZLIB_STREAM-LTCL_TEST'] = ltcl_test;
export {ltcl_test};