Exercise-9.1: Unit test of APIs

  • Based on below table create unit test functions for positive cases and negative cases

  • Example : Positive cases

    • module_1_decl_4_test_1( ) –> char x[10] = “bangalore”; fun(x);

    • module_1_decl_4_test_2( ) –> char x[10] = “b”; fun(x);

    • module_1_decl_4_test_3( ) –> char x[10] = “”; fun(x);

    • module_1_decl_4_test_4( ) –> char x[10] = “\0”; fun(x);

    • module_1_decl_4_test_5( ) –> char x[10] = “banga\0lore”; fun(x);

    • module_1_decl_4_test_6( ) –> char x[10] = “\0bangalore”; fun(x);

module_1

Test Cases without structures

Snippet

decl_1

Input to an API is simple variable

char x; fun(x);

decl_2

Input to an API is address of simple variable

char x; fun(&x);

decl_3

Input to an API is pointer pointing to a simple variable

char x; *p; p = &x; fun(p);

decl_4

Input to an API is a single dimension array

char x[10]; fun(x);

decl_5

Input to an API is a pointer pointing to a single dimension array

char x[10]; *p; p = x; fun(p);

decl_6

Input to an API is a single dimension array which is part of two dimensional array

char x[2][3]; fun(x[1]);

decl_7

Input to an API is a pointer pointing to a single dimension array which is part of two dimensional array

char x[2][3]; *p; p = x[1]; fun(p);

decl_8

Input to an API is a pointer pointing to a memory block in heap - Single Pointer - Allocated using malloc

char *p=malloc(); fun(p);

decl_9

Input to an API is a pointer pointing to a memory block in heap - Double Pointer - Allocated using malloc

char **p=malloc(); *p=malloc(); fun(*p);

decl_10

Input to an API is a pointer pointing to a memory block in heap - Triple Pointer - Allocated using malloc

char ***p=malloc(); **p=malloc(); *p=malloc(); fun(*p);

decl_11

Input to an API is a pointer pointing to a memory block in heap - Single Pointer - Allocated using calloc

char *p=calloc(); fun(p);

decl_12

Input to an API is a pointer pointing to a memory block in heap - Double Pointer - Allocated using calloc

char **p=calloc(); *p=calloc(); fun(*p);

decl_13

Input to an API is a pointer pointing to a memory block in heap - Triple Pointer - Allocated using calloc

char ***p=calloc(); **p=calloc(); *p=calloc(); fun(*p);

decl_14

Input to an API is a pointer pointing to a memory block in heap - Single Pointer - Allocated using realloc

char *p=realloc(); fun(p);

decl_15

Input to an API is a pointer pointing to a memory block in heap - Double Pointer - Allocated using realloc

char **p=realloc(); *p=realloc(); fun(*p)

decl_16

Input to an API is a pointer pointing to a memory block in heap - Triple Pointer - Allocated using realloc

char ***p=realloc(); **p=realloc(); *p=realloc(); fun(*p);

module_2

Test Cases with structure instance

Snippet

decl_1

Input to an API is simple variable - Accessed using a structure instance

struct ABC {char x;} Q;

decl_2

Input to an API is address of simple variable - Accessed using a structure instance

struct ABC {char x;} Q;

decl_3

Input to an API is pointer pointing to a simple variable - Accessed using a structure instance

struct ABC {char x,*p;} Q;

decl_4

Input to an API is a single dimension array - Accessed using a structure instance

struct ABC {char x[10];} Q;

decl_5

Input to an API is a pointer pointing to a single dimension array - Accessed using a structure instance

struct ABC {char x[10], *p;} Q;

decl_6

Input to an API is a single dimension array which is part of two dimensional array - Accessed using a structure instance

struct ABC {char x[2][3];} Q;

decl_7

Input to an API is a pointer pointing to a single dimension array which is part of two dimensional array - Accessed using a structure instance

struct ABC {char x[2][3], *p;} Q;

decl_8

Input to an API is a pointer pointing to a memory block in heap - Single Pointer - Allocated using malloc - Accessed using a structure instance

struct ABC {char *p;} Q;

decl_9

Input to an API is a pointer pointing to a memory block in heap - Double Pointer - Allocated using malloc - Accessed using a structure instance

struct ABC {char **p;} Q;

decl_10

Input to an API is a pointer pointing to a memory block in heap - Triple Pointer - Allocated using malloc - Accessed using a structure instance

struct ABC {char ***p;} Q;

decl_11

Input to an API is a pointer pointing to a memory block in heap - Single Pointer - Allocated using calloc - Accessed using a structure instance

struct ABC {char *p;} Q;

decl_12

Input to an API is a pointer pointing to a memory block in heap - Double Pointer - Allocated using calloc - Accessed using a structure instance

struct ABC {char **p;} Q;

decl_13

Input to an API is a pointer pointing to a memory block in heap - Triple Pointer - Allocated using calloc - Accessed using a structure instance

struct ABC {char ***p;} Q;

decl_14

Input to an API is a pointer pointing to a memory block in heap - Single Pointer - Allocated using realloc - Accessed using a structure instance

struct ABC {char *p;} Q;

decl_15

Input to an API is a pointer pointing to a memory block in heap - Double Pointer - Allocated using realloc - Accessed using a structure instance

struct ABC {char **p;} Q;

decl_16

Input to an API is a pointer pointing to a memory block in heap - Triple Pointer - Allocated using realloc - Accessed using a structure instance

struct ABC {char ***p;} Q;

module_3

Test Cases with structure single pointer

Snippet

decl_1

Input to an API is simple variable - Accessed using a structure single pointer

struct ABC {char x;} *Q;

decl_2

Input to an API is address of simple variable - Accessed using a structure single pointer

struct ABC {char x;} *Q;

decl_3

Input to an API is pointer pointing to a simple variable - Accessed using a structure single pointer

struct ABC {char x,*p;} *Q;

decl_4

Input to an API is a single dimension array - Accessed using a structure single pointer

struct ABC {char x[10];} *Q;

decl_5

Input to an API is a pointer pointing to a single dimension array - Accessed using a structure single pointer

struct ABC {char x[10], *p;} *Q;

decl_6

Input to an API is a single dimension array which is part of two dimensional array - Accessed using a structure single pointer

struct ABC {char x[2][3];} *Q;

decl_7

Input to an API is a pointer pointing to a single dimension array which is part of two dimensional array - Accessed using a structure single pointer

struct ABC {char x[2][3], *p;} *Q;

decl_8

Input to an API is a pointer pointing to a memory block in heap - Single Pointer - Allocated using malloc - Accessed using a structure single pointer

struct ABC {char *p;} *Q;

decl_9

Input to an API is a pointer pointing to a memory block in heap - Double Pointer - Allocated using malloc - Accessed using a structure single pointer

struct ABC {char **p;} *Q;

decl_10

Input to an API is a pointer pointing to a memory block in heap - Triple Pointer - Allocated using malloc - Accessed using a structure single pointer

struct ABC {char ***p;} *Q;

decl_11

Input to an API is a pointer pointing to a memory block in heap - Single Pointer - Allocated using calloc - Accessed using a structure single pointer

struct ABC {char *p;} *Q;

decl_12

Input to an API is a pointer pointing to a memory block in heap - Double Pointer - Allocated using calloc - Accessed using a structure single pointer

struct ABC {char **p;} *Q;

decl_13

Input to an API is a pointer pointing to a memory block in heap - Triple Pointer - Allocated using calloc - Accessed using a structure single pointer

struct ABC {char ***p;} *Q;

decl_14

Input to an API is a pointer pointing to a memory block in heap - Single Pointer - Allocated using realloc - Accessed using a structure single pointer

struct ABC {char *p;} *Q;

decl_15

Input to an API is a pointer pointing to a memory block in heap - Double Pointer - Allocated using realloc - Accessed using a structure single pointer

struct ABC {char **p;} *Q;

decl_16

Input to an API is a pointer pointing to a memory block in heap - Triple Pointer - Allocated using realloc - Accessed using a structure single pointer

struct ABC {char ***p;} *Q;

module_4

Test Cases with structure double pointer

Snippet

decl_1

Input to an API is simple variable - Accessed using a structure double pointer

struct ABC {char x;} **Q;

decl_2

Input to an API is address of simple variable - Accessed using a structure double pointer

struct ABC {char x;} **Q;

decl_3

Input to an API is pointer pointing to a simple variable - Accessed using a structure double pointer

struct ABC {char x, *p;} **Q;

decl_4

Input to an API is a single dimension array - Accessed using a structure double pointer

struct ABC {char x[10];} **Q;

decl_5

Input to an API is a pointer pointing to a double dimension array - Accessed using a structure double pointer

struct ABC {char x[10], *p;} **Q;

decl_6

Input to an API is a double dimension array which is part of two dimensional array - Accessed using a structure double pointer

struct ABC {char x[2][3];} **Q;

decl_7

Input to an API is a pointer pointing to a double dimension array which is part of two dimensional array - Accessed using a structure double pointer

struct ABC {char x[2][3], *p;} **Q;

decl_8

Input to an API is a pointer pointing to a memory block in heap - Single Pointer - Allocated using malloc - Accessed using a structure double pointer

struct ABC {char *p;} **Q;

decl_9

Input to an API is a pointer pointing to a memory block in heap - Double Pointer - Allocated using malloc - Accessed using a structure double pointer

struct ABC {char **p;} **Q;

decl_10

Input to an API is a pointer pointing to a memory block in heap - Triple Pointer - Allocated using malloc - Accessed using a structure double pointer

struct ABC {char ***p;} **Q;

decl_11

Input to an API is a pointer pointing to a memory block in heap - Single Pointer - Allocated using calloc - Accessed using a structure double pointer

struct ABC {char *p;} **Q;

decl_12

Input to an API is a pointer pointing to a memory block in heap - Double Pointer - Allocated using calloc - Accessed using a structure double pointer

struct ABC {char **p;} **Q;

decl_13

Input to an API is a pointer pointing to a memory block in heap - Triple Pointer - Allocated using calloc - Accessed using a structure double pointer

struct ABC {char ***p;} **Q;

decl_14

Input to an API is a pointer pointing to a memory block in heap - Single Pointer - Allocated using realloc - Accessed using a structure double pointer

struct ABC {char *p;} **Q;

decl_15

Input to an API is a pointer pointing to a memory block in heap - Double Pointer - Allocated using realloc - Accessed using a structure double pointer

struct ABC {char **p;} **Q;

decl_16

Input to an API is a pointer pointing to a memory block in heap - Triple Pointer - Allocated using realloc - Accessed using a structure double pointer

struct ABC {char ***p;} **Q;

module_5

Test Cases with structure triple pointer

Snippet

decl_1

Input to an API is simple variable - Accessed using a structure triple pointer

struct ABC {char x;} ***Q;

decl_2

Input to an API is address of simple variable - Accessed using a structure triple pointer

struct ABC {char x;} ***Q;

decl_3

Input to an API is pointer pointing to a simple variable - Accessed using a structure triple pointer

struct ABC {char x, *p;} ***Q;

decl_4

Input to an API is a single dimension array - Accessed using a structure triple pointer

struct ABC {char x[10];} ***Q;

decl_5

Input to an API is a pointer pointing to a triple dimension array - Accessed using a structure triple pointer

struct ABC {char x[10], *p;} ***Q;

decl_6

Input to an API is a triple dimension array which is part of two dimensional array - Accessed using a structure triple pointer

struct ABC {char x[2][3];} ***Q;

decl_7

Input to an API is a pointer pointing to a triple dimension array which is part of two dimensional array - Accessed using a structure triple pointer

struct ABC {char x[2][3], *p;} ***Q;

decl_8

Input to an API is a pointer pointing to a memory block in heap - Single Pointer - Allocated using malloc - Accessed using a structure triple pointer

struct ABC {char *p;} ***Q;

decl_9

Input to an API is a pointer pointing to a memory block in heap - Double Pointer - Allocated using malloc - Accessed using a structure triple pointer

struct ABC {char **p;} ***Q;

decl_10

Input to an API is a pointer pointing to a memory block in heap - Triple Pointer - Allocated using malloc - Accessed using a structure triple pointer

struct ABC {char ***p;} ***Q;

decl_11

Input to an API is a pointer pointing to a memory block in heap - Single Pointer - Allocated using calloc - Accessed using a structure triple pointer

struct ABC {char *p;} ***Q;

decl_12

Input to an API is a pointer pointing to a memory block in heap - Double Pointer - Allocated using calloc - Accessed using a structure triple pointer

struct ABC {char **p;} ***Q;

decl_13

Input to an API is a pointer pointing to a memory block in heap - Triple Pointer - Allocated using calloc - Accessed using a structure triple pointer

struct ABC {char ***p;} ***Q;

decl_14

Input to an API is a pointer pointing to a memory block in heap - Single Pointer - Allocated using realloc - Accessed using a structure triple pointer

struct ABC {char *p;} ***Q;

decl_15

Input to an API is a pointer pointing to a memory block in heap - Double Pointer - Allocated using realloc - Accessed using a structure triple pointer

struct ABC {char **p;} ***Q;

decl_16

Input to an API is a pointer pointing to a memory block in heap - Triple Pointer - Allocated using realloc - Accessed using a structure triple pointer

struct ABC {char ***p;} ***Q;