Table of contents :

Introduction

I . Build an application to test.

II . Run toaster.

III . Load the application.

IV . The File and Execute menus.

V . Build your first Unit Test.

VI . Build your first integration test.

Conclusion

Introduction.

Welcome at the Toaster online tutorial.

I'm going to help you in your first steps with Toaster for Linux. Let's start.



I . Build an application to test.

Under your favourite editor, edit the following files (download files here) :

test.h

typedef struct
{
int tab_value[4];
int result;
} arg_list;

typedef struct
{
int size;
int *first;
} dyn_list;

t

test.c

#include "test.h"

int multiplication;

static void init_arg_list (arg_list *list)
{
int ind;

for (ind = 0; ind < 4; ind ++)
{
list->tab_value[ind] = 0;
}

list->result = 0;

return;
}

static void comput_arg_list (arg_list *list)
{
int ind;
int result;

result = multiplication;

for (ind = 0; ind < 4; ind ++)
{
if (multiplication)
{
result = result * list->tab_value[ind];
}
else
{
result = result + list->tab_value[ind];
}
}


list->result = result;

return;
}

static void init_dyn_list (dyn_list *list)
{
list->size = 0;
list->first = (int*)0;

return;
}

static int comput_dyn_list (dyn_list *list, int mult)
{
int ind;
int result;


if (mult)
{
result = 1;
}
else
{
result = 0;
}

for (ind = 0; ind < list->size; ind ++)
{
if (mult)
{
result = result * list->first[ind];
}
else
{
result = result + list->first[ind];
}
}

return result;
}

static void add_int_in_dyn_list (dyn_list *list, int element)
{
if (list->size == 0)
{
list->first = (int*)malloc(sizeof(int));
list->first[0] = element;
list->size++;
}
else
{
realloc((void*)list->first, sizeof(int)*list->size);
list->size++;
list->first[list->size -1] = element;
}

return;
}

main ()
{
return 0;
}



And compile it with the command :

cc -g -o test test.c



II . Run toaster.

Go on the "test" directory and launch toaster with "toaster" command (the installation directory of Toaster must be in your PATH environment variable).

Note : launching toaster in background (with &) can be hazardous.

III . Load the application.

In the File menu, activate the Load executable item and select the "test" executable you've just compiled.

You must obtain something like this :






The Application View represents your loaded executable. You can see subprograms, global variables and types.

The symbols are :

For an array of something.

For a data in predefined type.

For a global variable.

For a pointer.

For a subprogram.

For the return of a subprogram.

For a structure description.

For a typedef description.



Now, look at the menus ...

IV . The File and Execute menus.

The File menu :

Open : load a Toaster file you've saved during another session.

Save : save a Toaster file which describe your current session.

Load Executable : load an executable.

Quit : quit Toaster session.

The Execution menu :

Execute : write and run the GDB script to perform your tests. A text box with the standard output of GDB is shown when execution is terminated.

Write : write the GDB script and show it to you.



V . Build your first Unit Test.

A Unit Test is a test which permit to test the execution of a subprogram of your application : you must define what you give as inputs to your subprogram, and what you're expecting for outputs. Toaster will show you if your subprogram is ok ...

Let's go to build a first Unit Test, on the comput_arg_list subprogram.

1 - Drag and drop comput_arg_list from Application View to Test Script tree.

2 - Drag and drop multiplication global variable from Application View to Object Factory tree.

3 - Expand all nodes of Test Script tree and Object Factory tree. The new symbols in this tree are :

Input

For input values of your tested subprogram.

Expected

For the output values you're expecting for your tested subprogram.

Output

For the output values Toaster has observed.

For Value which has not been yet tested by Toater.

For a value which has been tested by Toaster, when expected values and output values are the same.

For a value which has been tested, when expected values and output values are not the same.



4 - Try the popup menu on different lines of the trees.

Reference

On structure (), array (), pointer () etc, this menu item permit to test pointer value (0x....) and not pointed elements

Literal

On structure, array, pointer etc, this menu item allow you to give a full description of the pointed value.
For example, if you select Literal on the pointer of a char* value, you can directly enter "my string" as value.

Expand elements

On an item which has been defined as tested with "Reference" format (see first line of this array), expand subtree and allow you to test pointed elements.

Add pointed element

On a pointer, allow you to add one pointed element. For example, for an "int *a" value, this mode allow you to test a[0], a[1] etc ...

Delete last pointed element

On a pointer, allow you to delete the last pointed element you add.

Delete global/subprogram

On a Global Variable or a Subprogram, this action allow you to remove selected element from test.


5 - Click on terminal tree elements and enter value for them. Do it to obtain the following status.




The Toaster icon at the top of the window shows you that your test is'nt "Up to Date" (you must execute it to obtain results).


6 - Select Execute item on the Execution menu.


After few seconds (or more for little computer), the following window appear :




Scroll it down and look at the bottom of the gdb output.

The message "Execution finished ... No error." means that results are available.


Click OK to close File View.


7 - Look at the results.


Your toasts are hot !!! Look at the top of the window : the Toaster icon has changed. It means that results are "Up to date". If you modify Test Script tree or Object Factory tree now, you'll be back in the "Execution needed status".


Expand the Output subtree of your tested subprogram. You must observe something like that :




It means that all your tested values are OK. The symbol of the return symbol means that it has not been tested by toaster (it's a void return).


8 - Save your test.


Now, you can save your test with the Save item of the File menu. The saved file can be reload latter to run the test again after modification on your application.


9 - You have perform your first Unit Test with Toaster.

VI . Build your first integration test.

1 - Run toaster (see V).

2 - Load the test executable (see V).

3 - Drag and drop subprogram init_dyn_list in Test Script tree.

4 - Drag and drop subprogram add_int_in_dyn_list in Test Script tree.

5 - Drag and drop another subprogram add_int_in_dyn_list in Test Script tree.

6 - Drag and drop subprogram comput_dyn_list in Test Script tree.

7 - Drag and drop the type dyn_list in Object Factory tree.

Now an object named User_Object_1 is in Object Factory tree.

A user object is an object which isn't present in your tested application : toaster will build it from a type defined somewhere in application.

Click on User_Object_1 and rename it as my_list.

8 - Now assign values to objects of Object Factory and Test Script.

- expand all symbols of the two trees (in Test Script tree, just expand Input and Expected subtrees).

- Click on the "first" pointer of my_list in Object Factory. Select Reference in the popup menu, and give 0x0 as value.

- For values of Test Script tree, try to obtain following status (be careful about the format column) :

NOTE : to obtain more pointed values for "first" pointers, click on them and select Add pointed element in popup menu.

NOTE : be careful about values "$my_list" : don't forget the '$' character.

For init_dyn_list :






For the first add_int_in_dyn_list :






For the second add_int_in_dyn_list :






For comput_dyn_list :






9 - Run it ...

10 - The comput_dyn_list test is failed ... Try to correct it.

11 - Save your test file with Save item in File menu.

NOTE : If you don't find how to build this Integration test, look at the download section for the saved toaster file (then execute toaster in the test executable directory to permit Toaster to find it).



Conclusion

You have build Unit test and Integration Test on two simple application. Now try to use Toaster on bigger executable.

Some C features are not yet fully supported. So please report bugs using the bug report of Toaster page.