Friday, November 6, 2009

Snomobile Trailer Cap

Testable surfaces

In his great lecture on the Crusade against errors in software
the first Swiss Testing Night of 12 June of the year, reports Jerome Mueller of developers who can literally think of everything and just about anything. When asked after the draft of their application, they give so clever things to like:
The business layer then uses the Persistence Layer. The Persistence Layer, we have to ensure database independence. And the business layer, we can deploy on different machines and so scale.


The software is designed for everything! Switching from Oracle to XML files? No problem! Switching from Windows to Linux? No problem! Instead of the log files are the log entries be sent to a web service? Piece of cake!


But, according to Müller, one of

can not answer the developer, namely the question of
which concepts he has built, that the application "testable" is. Can I open each screen mask within 3 seconds and set the condition of the data displayed, so I can test the UI behavior? How do I create test data?
etc. The answer is unfortunately often very short and can be summarized in zero words.
To me this complaint to suspend, I have written for our current project, a BSP program that accurately this can be: Every picture - and that means in our MVC framework: each panel - go to a mouse click.

The report not only helps in testing the UI behavior, but also displays a log of the HTML code inspections by Dave Raggett
HTML Tidy program so that you recognize as Schachtelungsfehler in the source code. The program calls for entering a BSP application and one in this application according to the Flow Logic defined panels with an internal HTTP request exactly this panel and shows three aspects of representation: The browser view using an embedded HTML viewer control, and the HTML source code and the protocol of tests on HTML Tidy. Here is a screenshot with a our "Hello World" applications of the MVC frameworks:

The images that appear in this test program, are always with the same test data filled, regardless of the amount actually maintained in the system master or transaction data. How is this possible?

A small intervention in the MVC Framework allows the artifice, rather than using the "productive" Models of the business logic decoupled subclasses that implement a tagging interface zif_testdata . The application parameter structure zif_mvc_framework , which is responsible to call, the application to use the models, controllers and views. The standard implementation zcl_mvc_framework takes this information to the config.xml file
, which is in MIME part of the BSP application filed. In the development system I have held this standard implementation of an alternative implementation

zcl_mvc_framework_test deposited:


These attacks exactly one point: In assessing the models. It provides instead of the model itself returns a subclass that implements the interface zif_testdata - if such exist. The only place with a different Logic is therefore the method get_model () :

method zif_mvc_framework ~ get_model.
es_model = go_framework-> get_model (iv_model_id).

* Model substitute test class
replace_class_by_testclass (changing cs_model = es_model).
ENDMETHOD.
The data that the user interface needs to be fixed now established in this test model. Thus, the UI looks in the UI test mode from the same and may be protected by periodically running automated tests to verify the example that the HTML document has the expected DOM tree.
the program HTML Tidy can be accessed easily by the way in the ABAP stack be because there is an ABAP wrapper: class cl_htmltidy . If go_tidy
an object variable of this class known, one can configure HTML Tidy at load time of his class or his reports or the creation time his object, as follows:
go_tidy cl_htmltidy = => create (). define _set_option. call method go_tidy-> set_options
exporting
option = & 1
 value = & 2  end-of-definition. 

_set_option:
'indent' 'auto',
'indent-spaces' '2 '
' input-encoding 'utf8'. ! Must be written (not "utf-8")


Calling is important to note that the class
cl_htmltidy
expecting her input always in UTF-8

format and returns the results in this format. So you have the HTML code first with the conversion class
cl_abap_conv_out_ce
a XSTRING produce the text in the character encoding UTF-8 contains
. Only then can you call HTML Tidy:

* ---

get_tidy form.

data: lv_in type xstring,
lo_error type ref to cx_root.

statics: so_conv type ref to cl_abap_conv_out_ce.

if so_conv is not bound.
so_conv? Cl_abap_conv_out_ce = => create ( encoding = '4110' ).
endif.

try.
call method so_conv->convert
exporting data = gv_code importing
buffer = lv_in.

call method go_tidy->repair
exporting input = lv_in diagnostics = 'X'
importing

* --> In einem TextEditControl anzeigen:

errors = gv_tidy.
catch cx_root into lo_error.
zcl_messages=>show_exception( lo_error ).
endtry.

endform. "tidy_get

Tidy can not only be like this to validate websites eisetzen, but can also convert HTML to XHTML. There are many practical applications: Tidy could be a bit of help to migrate to the view content of a project or application from HTML to XHTML. Also, Tidy can be combined with the built-in ABAP XML parser as an HTML parser to use, so that one can also examine the HTML DOM of a Web application with ABAP resources.

Tuesday, November 3, 2009

Forgot Combination My Master Lock Can Unlock

Global and local variables

It's an old programming principle that one should avoid global data as possible and instead work better with parameterized blocks of code (methods, functions, ...) and local variables. To the pros and to understand the various disadvantages of variable scope, is also a look at the foundations of their deployment makes sense.

When speaking in ABAP of global data, we mean not - as is also common - application-wide hidden data, but variables declared on a code unit , so a class, program or function group, suitable and valid . The access is - except for public class attributes - modular: limited to the procedures of each unit of code. is packed only in the classical monolith in which all the code into a single report, the two concepts coincide: Program Global data Then, application-wide global. [1] this difference between application-wide data and global data must be kept in mind when we follow the literature in discussions of global data. In the C / C + + literature with global data often meant the application-wide data. These are particularly problematic. Many of the problems but they have in common with each unit of code data defined. Even if access is restricted, remains reserved for global variables memory area for the life of the unit of code received. For programs, function groups, and static class attributes means that for the entire application. Only instance attributes are usually short-lived - if not a reference to the instance is gone, the instance is removed along with their attributes. The main difficulty with global data is the so-called "Reentrance" problem: If a procedure is called in a unit of code, changed global variables in the rule (otherwise if they had been declared more sense not as variables but as constants). In a later call to the value of the variable is therefore determined by the call-history of the procedure, it is uncertain from the perspective of the later call. This makes the code more difficult to reconstruct. Reentrant code however, does exactly the same each time, it generates no side effects. In programming languages such as Java or C + +, in which the same code path can be run by different threads is, Reentrance a necessary criterion for concurrent programming dar. In ABAP there is indeed starting new task - a Reentrance problem you have with these concepts but not, must be locked against changes, if you want to change their global data
Shared Objects - the naive attempt to change within a method leads to global data, the program is canceled when you are in normal read mode of the object is located. While changing engage other consumers back to the early, consistent version of the object. Each process is therefore working at any time with a consistent data data object.


The
CallFunction
with the addition

starting new task
in general is no concurrency, because the function module is executed for each call in a new, spotlessly clean mode, present in which all code units again in the initial state.
Global variables are convenient, because its values always has access. But this convenience has a price: Because of the scattered use in a variety of procedures increases the complexity of each global variable of the program. It is much easier to refactor a procedure that is not using global data. Therefore, there is the following rule:


Global variables should be introduced only if there are no alternatives.


course, there are also cases where the use of global variables makes sense. For example, you need global data common to the holding of

session data, such as to remember in a transaction, a user inputs: Each dialog step of the transaction is the first control to the user, then passed back to the computer. The computer must, however, keep the entries made previously in memory. Local variables are, of course, this is not possible since been removed at the handover of control to the user all the call stacks. The next input trigger then the PAI modules new call stack. But in the code units that are run here, must be available earlier entries - that's only if they are marked as global (or static) variables. But even if global variables are justified in some situations and useful are the local variables are usually the better alternative dar. are called local variables and "variables on the stack. Why? "The Stack" is a virtual machine for microprocessors and conventional memory construct with which the system is noted in procedure calls, the return addresses. There is a stack pointer

is the address of the current top of stack and built

push - and pop operations to copy data into the stack and take from him. It is this stack is used to manage local data: The need for local data storage space is easy on the current stack pointer is added [2] This is very quick and shall, at the deepest level, that local data actually used only within a procedure. can be.
A simple example - a routine for adding two integers is to illustrate how this works at the machine level on. The obvious source for such a routine in C for


int add (int x, int y) { return x + y; } would, however, of any optimizer immediately as inline detected worthy, that the complete call of the function would be optimized away. Instead, the command processor add for adding two numbers would be generated directly in the bytecode into the call position. Even if we write the same thing a bit complicated, int add (int x, int y) {int z
;
z = x + y; return z;} add (1,1);

would have the procedure under current Compilers are not good chances of survival. If it still creates - for example by changing the settings and the optimizer inlining prohibits [3], we obtain in x86 assembly code such as the following result.
start:; sample call: Calculate 1 + 1
push 1; parameters y and ...
 push 1; ... Parameter x on the stack lay 
call _add; is in EAX after executing the value 2
...
_add:
push ebp; save register of references EBP mov ebp, esp; Top of Stack noted add esp, 0FFFFFFFCh , Subtract 4 bytes from ESP (for z)
mov eax, [ebp +8]; Load parameters x in
EAX add eax, [ebp +0 Ch]; parameter y
add add mov [ebp-4], eax; result in local variable store z
leave; makes implicit POP EBP EBP - ret> ESP
8; return value is always EAX
, ie 8 bytes for call parameters purge
of the processor used stack pointer in the x86 processor family ESP
. The auxiliary register
 
EBP is used during a procedure as a reference, it contains the contents of the stack immediately after jumping to the routine.

The above code line shows the first example of call in the main program: you want to add one and one. These two ones must first be placed on the stack. Then the routine is called for adding. The call

command will then internally the return address of the instruction pointer on the stack and sets the instruction pointer to the beginning of Addierroutine. There, the

EBP is saved to the stack and then overwritten with the current value of ESP

.

The next statement is interesting: it simply be deducted 4 bytes from the stack pointer. Since the stack with push

descends in the address space, ie this: These four bytes are reserved by the simple subtraction

. Way local variables are treated in assembler, for this subtraction is the translation of C statement int z; follows further below to access the local variable:
mov [ebp-4], eax; result z in a local variable store
   The variable is then accessed with indirect addressing on their own, the assembler known offset. 

Exactly the same stack, which is used for subroutine calls to remember the return addresses, is thus used for the management of procedure parameters and local variables. This is ensure that these variables in the current call level, but not available at higher levels, since leaving the routine, the stack pointer so degraded along with the transfer parameters.

What happens now when a subroutine call in the subroutine? On the stack are other parameters, local variables and return address. The data of the calling subroutine, but all are still on the stack and therefore in principle available. If the calling sub-program would tell the called subprogram, the addresses of its local data and call parameters, this could also access it. That would be a passing parameters using the standard "call by reference" as in ABAP for all procedure calls is the default.




This example shows that the speech, local variables and procedure parameters "live on the stack is taken too literally. Binding to the call stack has many advantages that characterize the local variables before alternatives such as static or global variables. For example, local variables are automatically "thread-safe" because the call stack is specific to a process that he can never share with other processes. In addition, there is never a problem Reentrance: The content of local variables is not on the call history. If the local variables in ABAP on entering the procedure implicitly initialized are, their value can be changed only by the code itself of the procedure, so any time is imminent.

[1] For functional groups has come to be used in the ABAP world the way of speaking, their global data represent the "global mind" of the functional group.
[2] In
x86 Assembler
is subtracted, as the stack from top to bottom "is growing, a

push operation so the stack pointer decreases. But those are implementation details.
[3] or, as I did it, encodes the same routine in assembly language.


Sunday, November 1, 2009

How To Dispose Whisper Sanitary Napkins

Web applications validate

The languages (X) HTML, CSS and JavaScript remain the three basic elements of surfaces in Internet - a free program will add more and more XML with XSL style sheets. With most programming languages have this in common that they are not enough highly complex and usually expensive development platform (IDE) need, but a dog usually plain text editor for developing. In a pinch, it goes with "Notepad" - but a bit more comfort to wish you, as a rule anyway. In most programming and markup languages is happy about the following features:



Free search, extraction and replacement with regular expressions, possibility Color highlighting of keywords and comments

discovery of corresponding Brackets, whether square, round or curly

extraction of a kind of Contents - Section specific markers in the document to keep track of documents in large and per-click in a section of branch. In HTML, this is the heading tags
\u0026lt;h1>
, \u0026lt;h2>
, etc., in each JavaScript function
An explicitly callable "Pretty Printer" for Spalteneinrückungen - but by no means an automatic!
An explicitly callable "Code Inspector" and syntax check, references to obsolete language elements or critical Codes.
definable key code assignments for commonly used menu items.

Manual callable, user-definable code templates, such as the HTML template - but by no means automatic code generation!


I have to 2003 worked with the editor TextPad , who had some of these features. Later I switched to UltraEdit - because it is commonly used editor in my company.
    For some time, has an attached JavaScript UltraEdit-processor, which offers a more flexible way as macros, recurring transactions, the text editor to automate. There is also a sentence of up to ten user-defined tools - operating system commands that can be applied to the current document. Using a predefined menu can be called even without further adjustment expenses HTML Tidy, a useful "Code Inspector for HTML and XHTML. It can also be used for mere parsing an XML document.
  • is for JavaScript code to the Inspector

  • JSLint JavaScript veteran Douglas Crockford. It was a natural idea to have this run with the built-in JavaScript UltraEdit processor. This is actually easily possible and also has the advantage that you can filter the output according to their own ideas in order not are flooded with messages, but only show what you yourself consider to be material. Anyone interested can, my version of UltraEdit JSLint downloaded from the website of the GNP practice book under
  • http://bsp.mits.ch/supplements/jslint.js . One has to only file in the Script folder pack of UltraEdit and has JSLint then to the script list available. tedious thing, but not impossible, it was a locally running version of the W3C to generate standard CSS validator
  • . The installation is complicated by the fact that the authors have not programmed their tool layer aware - there is no class with which the validator on a text like Input stream can apply, and generates a text-shaped output - but the implementation is as intertwined with the Jigsaw servlet server. Anyone who has a Java Runtime on his computer, can my 7 MB severe folder
css

download that contains all of the start of the CSS validator unfortunately necessary JAR files. After downloading and extracting it is necessary in the batch file
cssv.bat may change the name of the folder and can then configure a tool. I have the css folder as first-level subfolders on my memory stick and write the command, therefore, in the tool configuration as follows:

\\ css \\ cssv file :///% F% n% e The batch file assumes that the command java

can run. If this is not the case with you, you have to be chosen path of java.exe batch file fully qualify, for example, by placing the environment variable% JAVA_HOME% , or, if you do not have this configured by specifying the full path to java.exe . Again, you can control the Java class
FilterValidatorOutput.java
yet how much output you want to get from the validator.
 All these efforts are rewarded by the fact that you have the W3C validator for CSS files offline in the text editor is available. Before you post the files you have in order for HTML (with Tidy), CSS (with the W3C validator) and JavaScript (with Crockfords 
JSLint
) the possibility of consistency checks and audits access to critical code points-per-click or by keyboard shortcut.

need to these static tests after checking in the HTML, CSS and JavaScript code added yet dynamic. How to create automated tests for JavaScript, I have already described in this blog: With the lightweight unit testing framework
ECMA
people can write unit tests for JavaScript code. It is advisable to keep the current test suite and the latest on the release of the shipments into the Q-system to start - more often they start the better. more dynamic tests of course, affect the surface it self will call often in manual mode, the application and test if for example the new button works as expected. With automation to get there ahead anyway. It is useful to have a test mode without having business logic with which each frame of the application with a simple click may be called, where it is supplied with dummy data and displayed. Such a UI or test mode could be implemented in ABAP with a user parameter: instead of "productive" Models return to work in test mode with subclasses of these models, the dummy data. Once
 this is possible, you can also protect the surface as a whole with automated testing: Who has a test tool such as QuickTest Professional version, you can now record dialog steps and build expectations in the form of checkpoints. 

with standard tools, you can write tests in a dynamic language. With Perl has the component
HTML:: Parser
use to extract, for example, all links from a page or to navigate the DOM - the individual expectations can then test the module
test: Set More
.

for XML and XHTML output dynamic tests are very good to formulate the schema language Schematron . The language is - in contrast to other schema languages such as XSD schema or DTD's - not grammar-based, but based pattern. This makes it convenient to examine individual test expectations for the structure of the document: If the elements are nested in the expected manner? Are there certain substructures, if so, how often? Do the elements, the expected attribute values and text content? The pattern itself is collected in an XML Schematrondokument and can be used with an appropriate implementation of the XML documents to be checked.
 The combination of code inspectors and dynamic tests helps to protect the code to be developed and to ensure changes at all levels, that existing functionality not be altered or destroyed.