Anda di halaman 1dari 35

Software Testing

White Box Testing (Code inspection/ Code


walkthrough)

1-1

Code Walkthrough

It is the technique to check your code.


It is an informal technique for analysis.
It is taken after coding the module is completed.
Development team takes some test codes and simulate
execution of code by hand.
Some guidelines
Team size should be between 3 to 7 members
Focused on discovery of errors and not how to fix it.
Top level should not participate in discussion.

1-2

Code Inspections

It aim explicitly at the discovery of commonly made errors


During code inspection the code is examined for the
presence of certain kinds of errors in contrast to hand
simulation
Some classical programming errors which can be looked
for during code inspections:
1) use of uninitalized variables
2) Jumps into loops
3) Non terminated loops
4) Incompatible assignment.
1-3

Code Inspections
5) Array indices out of bound
6) Improper storage allocation and deallocation
7) Mismatch between actual and formal parameters in
function calls
8) Use of incorrect logical operators or incorrect
precedence among operators
9) Improper modification of loop variable
10) Comparison of equality of floating point value, etc.

1-4

Code Walkthrough Problems (1)


main()
{
float a = 5, b = 2;
int c;
c = a % b;
printf(%d,c);
}

1-5

Code Walkthrough Problems (2)


main()
{
int x;
x = 3**4 7^8;
printf(x= %d,x);
}

1-6

Code Walkthrough Problems (3)


main()
{
/* this program attempts to find what happens when /*
-32768 to +32767*/ is exceeded */
int a = 330000;
float b = 3.46100;
printf(a= %d b= %f\n,a,b);
}

1-7

Code Walkthrough Problems (4)


main()
{
int x = 10;
if x >= 2
printf(%d\n,x);
}

1-8

Code Walkthrough Problems (5)


main()
{
int k = 12, n =30;
k = ( k > 5 && n = 4 ? 100 : 200);
printf(k=%d,k);
}

1-9

Code Walkthrough Problems (6)


main()
{
int j = 1;
while(j <= 255);
{
printf(%c %d\n,j,j);
j++;
}
}

1-10

Code Walkthrough Problems (7)


main()
{
int x = 1, y = 5;
y * = x;
printf(x = %d y = %d\n,x,y);
}

1-11

Code Walkthrough Problems (8)


main()
{
int x = 3, z;
z = x----1;
printf(x = %d z = %d\n,x,z);
}

1-12

Code Walkthrough Problems (9)


main()
{
int i = 1;
for( i = -1 ; i <= 10; i++)
{
if( i < 5)
continue;
else
break;
printf(Gets printed only once);
}
}
1-13

Code Walkthrough Problems (10)


main()
{
int x = 10, y;
y = --x--;
printf(x = %d y = %d\n,x,y);
}

1-14

Code Walkthrough Problems (11)


main()
{
int i;
printf( Enter any number);
scanf(%d,&i);
switch (i)
{
case 1:
printf(DO);
case 2:
printf(RE);
case 3:
printf(ME);
case default :
printf(FA SO LA DO);
}
}
1-15

Code Walkthrough Problems (12)


main()
{
int i = 3;
switch (i)
{
case 1:
printf(HELLO);
case 2:
printf(HI);
break;
case 3:
continue;
default :
printf(GOODBYE);
}
}
1-16

Code Walkthrough Problems (13)


main()
{
char ch = E;
switch (ch)
{
case (ch >= 65 && ch <= 90):
printf( Capital Letter);
break;
case (ch >= 97 && ch <= 122):
printf( Small case Letter);
break;
case (ch >= 48 && ch <= 57):
printf( Digit);
break;
default :
printf(Any other character);
}
}
1-17

Code Walkthrough Problems (14)


main()
{
c ()
{
c()
{
printf( C is a C \n);
}
printf( . Is a C . \n);
}
printf(.. Is a sea after all!);
}
1-18

Code Walkthrough Problems (15)


main()
{
void message();
int c;
printf (c before call =%d\n, c);
c= message();
printf (c after call =%d\n, c);
}
void message()
{
printf( Only he will survive who is C-fit);
}
1-19

Code Walkthrough Problems (16)


main()
{
int k = 35, z;
z = check(k);
printf (z =%d\n, z);
}
check(m)
{
int m;
if (m > 40)
return(!m++); /* ! Negation operator */
else
return(!++m);
}
1-20

Code Walkthrough Problems (17)


main()
{
int *c;
c = check(10,20);
printf (c =%d\n, c);
}
check(i, j)
int i, j;
{
int *p, *q;
p = &i;
q = &j;
i >= 45 ? return(p) : return(q);
}
1-21

Code Walkthrough Problems (18)


main()
{
int i;
for(i=1 ; i <=10; i++)
main();
printf (In the year of lord\n);
}

1-22

Code Walkthrough Problems (19)


main()
{
float a = 0.7;
double b = 0.7;
long double c = 0.7;
if(a == b | b == c)
printf (Condition satisfied);
else
printf (Condition not satisfied);
printf (a = %f \t b = %lf \t c = %Lf\n, a, b, c);
}
1-23

Code Walkthrough Problems (20)


main()
{
printf(in main i = %d\n,i);
func1();
}
int i = 5;
func1()
{
printf (In func1 i= %d\n,i);
}

1-24

Code Walkthrough Problems (21)


i=0;
main()
{
printf(in main i = %d\n,i);
i++;
val();
printf(in main i = %d\n,i);
}
val()
{
int i =100;
printf (In val i= %d\n,i);
i++;
}
1-25

Code Walkthrough Problems (22)


#define NO
#define YES
main()
{
int i = 5, j;
if ( i > 5)
j = YES;
else
j = NO;
printf(j = %d\n,j);
}

1-26

Code Walkthrough Problems (23)


#define E exit(0)
main()
{
int i = 4;
if ( i <= 5)
E;
else
printf(Get out anyway);
printf(WELL);
}

1-27

Code Walkthrough Problems (24)


main()
{
int SIZE = 10;
int arr[SIZE];
int i;
for ( i = 0; i <= SIZE; i++)
{
scanf(%d,&arr[i]);
printf(%d\t,arr[i]);
}
}

1-28

Code Walkthrough Problems (25)


main()
{
int arr[25];
int i;
for ( i = 0; i <= 100; i++)
{
arr[i]= 100;
printf(%d\t,arr[i]);
}
}

1-29

Code Walkthrough Problems (26)


main()
{
static char str[10]={0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
char *s;
int i;
s = str;
for ( i = 0; i <= 9; i++)
{
if(*s)
printf(%c,*s);
s++;
}
}
1-30

Code Walkthrough Problems (27)


main()
{
struct
{
char name[25];
char language[10];
}a;
static struct a ={Hacker, c};
printf(%s \t %s \t,a.name, a.language);
}

1-31

Code Walkthrough Problems (28)


struct virus
{
char signature[25];
int size;
} v[2];
main()
{
static struct v[0] ={Yankee Doodle, 1813};
static struct v[1] ={Dark Avenger, 1795};
int i;
for(i=0; i <= 1; i++)
printf(%s \t %d \t,v[i].signature, v[i].size);
}
1-32

Code Walkthrough Problems (29)


#include stdio.h
main()
{
char str[20];
FILE *fp;
fp = fopen(strcpy(str,ENGINE.C),w);
fclose(fp);
}

1-33

Code Walkthrough Problems (30)


#include stdio.h
main()
{
char str[80];
FILE *fp;
/* TRIAL.C contains only one line :
Its a round, round, round world! */
fp = fopen(TRIAL.C,r);
while(fgets(str,80,fp) !=EOF)
puts(str);
}

1-34

1-35

Anda mungkin juga menyukai