Skip to content

Commit

Permalink
Changed license from GPL to LGPL
Browse files Browse the repository at this point in the history
  • Loading branch information
germanysources committed Oct 29, 2018
1 parent 641804e commit 256720c
Show file tree
Hide file tree
Showing 11 changed files with 327 additions and 689 deletions.
829 changes: 160 additions & 669 deletions LICENSE

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ Test Injections in ABAP before release 750.
It's the same idea like the commands test-seam and test-injection in ABAP release 750.
But this class can be used in older releases like 740.

See the wiki for further informations.
See the [wiki](https://github.com/germanysources/abap_test_injection/wiki) for further informations.
6 changes: 0 additions & 6 deletions license_addition

This file was deleted.

17 changes: 17 additions & 0 deletions src/.abapgit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<DATA>
<MASTER_LANGUAGE>D</MASTER_LANGUAGE>
<STARTING_FOLDER>/</STARTING_FOLDER>
<FOLDER_LOGIC>PREFIX</FOLDER_LOGIC>
<IGNORE>
<item>/.gitignore</item>
<item>/LICENSE</item>
<item>/README.md</item>
<item>/package.json</item>
<item>/.travis.yml</item>
</IGNORE>
</DATA>
</asx:values>
</asx:abap>
44 changes: 44 additions & 0 deletions src/zmakro_test_injection.prog.abap
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
*&---------------------------------------------------------------------*
*& Include ZMAKRO_TEST_INJECTION
*&---------------------------------------------------------------------*

DEFINE create_injection.

CREATE OBJECT ztest_injection=>self.

END-OF-DEFINITION.

DEFINE call_injection.
* call a macro with a active injection
* &1 injection name
* &2 called macro

in_set_active &1.
&2.
in_set_active &1.

END-OF-DEFINITION.

DEFINE in_set_active.
* activate injection
* &1 injection

ztest_injection=>self->injection_set_active( &1 ).

END-OF-DEFINITION.

DEFINE in_set_inactive.
* deactivate injection
* &1 die Injektion

ztest_injection=>self->injection_set_inactive( &1 ).

END-OF-DEFINITION.

DEFINE injection_active.
* check injection is active
* &1 injection name

IF ztest_injection=>injection_is_active( &1 ) = abap_true.

END-OF-DEFINITION.
22 changes: 22 additions & 0 deletions src/zmakro_test_injection.prog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_PROG" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<PROGDIR>
<NAME>ZMAKRO_TEST_INJECTION</NAME>
<STATE>A</STATE>
<VARCL>X</VARCL>
<SUBC>I</SUBC>
<RLOAD>D</RLOAD>
<UCCHECK>X</UCCHECK>
</PROGDIR>
<TPOOL>
<item>
<ID>R</ID>
<ENTRY>Makro Aufruf Test Injektionen</ENTRY>
<LENGTH>29</LENGTH>
</item>
</TPOOL>
</asx:values>
</asx:abap>
</abapGit>
43 changes: 32 additions & 11 deletions ztest_injection.clas.abap → src/ztest_injection.clas.abap
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
* Test Injektion ABAP
* Copyright (C) 2017 Johannes Gerbershagen
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU LESSER General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU LESSER General Public License for more details.

class ZTEST_INJECTION definition
public
create public .
Expand Down Expand Up @@ -28,13 +40,13 @@ public section.
!CALLER type CL_ABAP_GET_CALL_STACK=>FORMATTED_ENTRY
returning
value(IS_ACTIVE) type SAP_BOOL .
class-methods GET_INSTANCE
RETURNING VALUE(instance) TYPE REF TO ztest_injection.
protected section.

data:
* Pro Klasse=>Methode ist nur eine aktive Test-Injection moeglich
activ_injections TYPE SORTED TABLE OF activ_stack
WITH UNIQUE KEY injection.
CLASS-DATA actual_name TYPE injection. " aktueller Name Test-Injektion

methods GET_TESTCLASS
exporting
Expand All @@ -49,6 +61,17 @@ ENDCLASS.
CLASS ZTEST_INJECTION IMPLEMENTATION.


method GET_INSTANCE.

IF self IS NOT BOUND.
CREATE OBJECT self.
ENDIF.

instance = self.

endmethod.


method GET_TESTCLASS.

DATA: stack TYPE cl_abap_get_call_stack=>call_stack_internal,
Expand All @@ -60,7 +83,8 @@ CLASS ZTEST_INJECTION IMPLEMENTATION.

stack = cl_abap_get_call_stack=>get_call_stack( ).
formatted_stack = cl_abap_get_call_stack=>format_call_stack_with_struct( EXPORTING stack = stack ).
* Jetzt letzte Position suchen, ob Aufruf einer Testklasse erfolgt ist
* searches in stack, if method was called while executing a testclass.
* Assumes, that testclasses are executed from the program RS_AUNIT_CLASSTEST_SESSION
*kind=EVENT
*progname=RS_AUNIT_CLASSTEST_SESSION
*includename=RS_AUNIT_CLASSTEST_SESSION
Expand All @@ -72,15 +96,15 @@ CLASS ZTEST_INJECTION IMPLEMENTATION.
RAISE EXCEPTION TYPE cx_program_not_found.
ENDIF.

* letzte Methode bevor diese ztest_injection=>injection_set_active gerufen wird
* find method which calls ztest_injection=>injection_set_active
classname = cl_abap_classdescr=>get_class_name( me ).
Replace FIRST OCCURRENCE OF '\CLASS=' IN classname WITH space.
CONDENSE classname.
get_include ?= cl_oo_include_naming=>get_instance_by_name( classname ).
LOOP AT formatted_stack ASSIGNING <stack> FROM 2.

IF next = abap_true.
" Das ist der Aufrufer, der die Test-Injektion aktiviert
" This is the caller
caller = <stack>.
EXIT.
ENDIF.
Expand Down Expand Up @@ -127,22 +151,19 @@ CLASS ZTEST_INJECTION IMPLEMENTATION.
MOVE-CORRESPONDING caller TO new_injection.

INSERT new_injection INTO TABLE activ_injections.
ASSERT sy-subrc = 0. " sonst ist die Test-Injektion bereits aktiv
" d.h. fehlerhafter Source-Code
ASSERT sy-subrc = 0. " developer error injection is already active

endmethod.


METHOD injection_set_inactive.
* Injektion deaktivieren, d.h. aus Tabelle activ_injections loeschen
* Wenn Aufrufer mitgegeben wurde, wird nur der Aufrufer geloescht
* sonst werden alle Injektionen mit dem Namen name geloescht
* deactivate Injection, delete it from itab activ_injections
DATA: injection TYPE activ_stack.

injection-injection = name.
DELETE TABLE activ_injections FROM injection.
" IF sy-subrc <> 0.
" Injektion ist bereits deaktiviert
" injection is already inactive

ENDMETHOD.
ENDCLASS.
File renamed without changes.
10 changes: 8 additions & 2 deletions ztest_injection.clas.xml → src/ztest_injection.clas.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
</TLINE>
<TLINE>
<TDFORMAT>AS</TDFORMAT>
<TDLINE>class test_injektion definition or testing.</TDLINE>
<TDLINE>class test_injektion definition for testing.</TDLINE>
</TLINE>
<TLINE>
<TDFORMAT>AS</TDFORMAT>
Expand Down Expand Up @@ -105,7 +105,7 @@
</TLINE>
<TLINE>
<TDFORMAT>AS</TDFORMAT>
<TDLINE> if (ztest_injection=&gt;injection_is_activ( name = &apos;INJ1&apos;) = abap_true)</TDLINE>
<TDLINE> if ztest_injection=&gt;injection_is_activ( name = &apos;INJ1&apos;) = abap_true.</TDLINE>
</TLINE>
<TLINE>
<TDFORMAT>/=</TDFORMAT>
Expand Down Expand Up @@ -149,6 +149,12 @@
<LANGU>D</LANGU>
<DESCRIPT>Aufrufer Test-Injektion</DESCRIPT>
</SEOCOMPOTX>
<SEOCOMPOTX>
<CLSNAME>ZTEST_INJECTION</CLSNAME>
<CMPNAME>GET_INSTANCE</CMPNAME>
<LANGU>D</LANGU>
<DESCRIPT>Instanz erzeugen</DESCRIPT>
</SEOCOMPOTX>
<SEOCOMPOTX>
<CLSNAME>ZTEST_INJECTION</CLSNAME>
<CMPNAME>GET_TESTCLASS</CMPNAME>
Expand Down
19 changes: 19 additions & 0 deletions src/ztest_injection.prog.abap
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
*&---------------------------------------------------------------------*
*& Report ZTEST_INJECTION
*& unit test for injection. Not called from a testclass. It shouldn't fail.
*&---------------------------------------------------------------------*
REPORT ZTEST_INJECTION.

START-OF-SELECTION.

CREATE OBJECT ztest_injection=>self.

TRY.
ztest_injection=>self->injection_set_active( name = 'GH' ).
ASSert 1 = 0.
##NO_HANDLER
CATCH cx_program_not_found.
ENDTRY.

DATA(is_active) = ztest_injection=>injection_is_active( name = 'GH' ).
assert is_active = abap_false.
24 changes: 24 additions & 0 deletions src/ztest_injection.prog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_PROG" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<PROGDIR>
<NAME>ZTEST_INJECTION</NAME>
<STATE>A</STATE>
<VARCL>X</VARCL>
<SUBC>1</SUBC>
<RSTAT>T</RSTAT>
<RLOAD>D</RLOAD>
<FIXPT>X</FIXPT>
<UCCHECK>X</UCCHECK>
</PROGDIR>
<TPOOL>
<item>
<ID>R</ID>
<ENTRY>Unit-Test-Injektionen</ENTRY>
<LENGTH>21</LENGTH>
</item>
</TPOOL>
</asx:values>
</asx:abap>
</abapGit>

0 comments on commit 256720c

Please sign in to comment.