Y-lib
Loadrunner libraries
Macros | Functions | Variables
y_param_array.c File Reference

This file contains loadrunner parameter array helper functions. More...

#include "vugen.h"
#include "y_string.c"
#include "y_loadrunner_utils.c"

Go to the source code of this file.

Macros

#define y_array_count(param_array)   lr_paramarr_len(param_array)
 Determine the number of elements in the target parameter array. More...
 
#define y_array_get(source_param_array, param_array_index)   lr_paramarr_idx(source_param_array, param_array_index)
 Fetch the content of a specific element from a parameter list based on index. More...
 

Functions

char * y_array_get_no_zeroes (const char *source_param_array, const int param_array_index)
 Get the content the nth member of target parameter array, but without embedded zeroes. More...
 
void y_array_save (const char *value, const char *source_param_array, const int param_array_index)
 Save a string value into an array at a specified position. More...
 
void y_array_save_count (const int count, const char *source_param_array)
 
void y_array_add (const char *source_param_array, const char *value)
 
void y_array_concat (const char *source_param_array_first, const char *source_param_array_second, const char *result_array)
 Concatenate two arrays together and save the result into a third array. More...
 
char * y_array_get_random (const char *source_param_array)
 Get a random element from a parameter list. More...
 
char * y_array_get_random_no_zeroes (const char *source_param_array)
 Get a random element from a parameter list without embedded zeroes. More...
 
int y_array_pick_random (const char *source_param_array)
 Choose an element at random from a saved parameter list and store it in a parameter with the same name. More...
 
void y_array_dump (const char *source_param_array)
 Dump the contents of a list of saved parameters to standard output (the run log) More...
 
void y_array_save_param_list (const char *sourceParam, const char *LB, const char *RB, const char *result_array)
 Create a parameter list from a single parameter value. More...
 
void y_array_grep (const char *source_param_array, const char *search, const char *result_array)
 Search a parameter array for a specific text and build a new array containing only parameters containing that text. More...
 
void y_array_filter (const char *source_param_array, const char *search, const char *result_array)
 Search a parameter array for a specific string and and build a new result array containing only parameters NOT containing the string. More...
 
int y_array_merge (const char *param_array_left, const char *param_array_right, const char *separator, const char *result_array)
 
void y_array_split (const char *source_param_array, const char *separator, const char *param_array_left, const char *param_array_right)
 
void y_array_shuffle (char *source_param_array, char *result_array)
 

Variables

int _y_random_array_index = 0
 

Detailed Description

This file contains loadrunner parameter array helper functions.

This file provides functions that make using and manipulating loadrunner parameter arrays easier. A parameter array is a set of loadrunner parameters that is usually created by web_reg_save_param() with the "Ord=All" argument. These parameters all use the same name, postfixed with a number to indicate the index into the array.

Note
Some historical functions now have loadrunner equivalents, starting with LoadRunner version 9. Those functions have been replaced with macros that will call the correct modern equivalent instead. If Y_COMPAT_LR_8 is enabled the old behaviour is restored. If you still use loadrunner versions earlier than 9 you may need to add the line below to your script: #define Y_COMPAT_LR_8
See also
lr_paramarr_random(), lr_paramarr_idx()

Definition in file y_param_array.c.

Macro Definition Documentation

#define y_array_count (   param_array)    lr_paramarr_len(param_array)

Determine the number of elements in the target parameter array.

Parameters
[in]param_arrayThe name of the parameter array.
Returns
The number of elements in the array.
Note
Superseded by the LR 9 function lr_paramarr_len(). If Y_COMPAT_LR_8 is not defined this function is replaced with a simple macro calling the new loadrunner equivalent.

Example:

1 {
2  web_reg_save_param("TAG", "LB=<a", "RB=>", "ORD=ALL", LAST);
3  web_url("URL=www.google.nl", LAST);
4  lr_log_message("RESULT: %d", y_array_count("TAG")); // Logs the text "RESULT: " followed by how many hyperlinks are found on the www.google.nl index page.
5 }
See also
lr_paramarr_len()
Author
Floris Kraak

Definition at line 80 of file y_param_array.c.

#define y_array_get (   source_param_array,
  param_array_index 
)    lr_paramarr_idx(source_param_array, param_array_index)

Fetch the content of a specific element from a parameter list based on index.

Parameters
[in]source_param_arrayThe name of the parameter array.
[in]param_array_indexThe index of the chosen element.
Returns
A char* pointer pointing to the content of the chosen element, if it exist. Will call lr_abort() if it doesn't.
Note
Superseded by the LR 9 function lr_paramarr_idx(). If Y_COMPAT_LR_8 is not defined this function is replaced with a simple macro calling the new loadrunner equivalent.
If the data inside the parameter contains embedded null (\x00) characters you may have an issue processing the return value.
See also
y_array_get_no_zeroes()

Example:

1 {
2  web_reg_save_param("TAG", "LB=<a", "RB=>", "ORD=ALL", LAST);
3  web_url("URL=www.google.nl", LAST);
4  lr_log_message("Fourth tag on www.google.nl: %s", y_array_get("TAG", 4));
5 }
See also
lr_paramarr_idx()
Author
Floris Kraak

Definition at line 134 of file y_param_array.c.

Function Documentation

void y_array_add ( const char *  source_param_array,
const char *  value 
)

Add a new element to the end of the target parameter array.

Note
This will call y_array_save_count() each time it is called. For bulk inserts this should not be used - the performance will suck.
Parameters
[in]source_param_arrayThe target array to resize. If this array does not exist, a new one will be created.
[in]valuethe value to add.

Example:

1 web_reg_save_param("TAG", "LB=<a", "RB=>", "ORD=ALL", LAST);
2 web_url("URL=www.google.nl", LAST);
3 y_array_add("TAG", "newValue"); // the added value (=last one) in {TAG} is now "newValue".
See also
y_array_save()
Author
Floris Kraak

Definition at line 282 of file y_param_array.c.

void y_array_concat ( const char *  source_param_array_first,
const char *  source_param_array_second,
const char *  result_array 
)

Concatenate two arrays together and save the result into a third array.

Example:

1 web_reg_save_param("TAG1", "LB=<a h", "RB=>", "ORD=ALL", LAST);
2 web_reg_save_param("TAG2", "LB=<A id", "RB=>", "ORD=ALL", LAST);
3 web_url("URL=www.google.nl", LAST);
4  // Loadrunner saves parameters:
5  // TAG1 - "TAG1_1" to "TAG1_12", "TAG1_count" = 12
6  // TAG2 - "TAG2_1" to "TAG2_14", "TAG2_count" = 14
7 y_array_concat("TAG1", "TAG2", "TAG"); // saves "TAG_1" to "TAG_26", "TAG_count" = 26
See also
y_array_save()
Author
Floris Kraak

Definition at line 305 of file y_param_array.c.

void y_array_dump ( const char *  source_param_array)

Dump the contents of a list of saved parameters to standard output (the run log)

Parameters
[in]source_param_arrayThe name of the array to log.

Example:

1 web_reg_save_param("TAG", "LB=<a", "RB=>", "ORD=ALL", LAST);
2 web_url("URL=www.google.nl", LAST);
3 y_array_dump("TAG"); // Prints the content of the parameter array named "TAG" to the output log.
Author
Raymond de Jongh

Definition at line 431 of file y_param_array.c.

void y_array_filter ( const char *  source_param_array,
const char *  search,
const char *  result_array 
)

Search a parameter array for a specific string and and build a new result array containing only parameters NOT containing the string.

As y_array_grep(), but reversed.

Parameters
[in]source_param_arrayThe name of the array to be searched.
[in]searchThe string to search for.
[in]result_arrayThe name of the array to hold the resulting values. Can be the same as the original parameter array.

Example:

1 lr_save_string("<apple><balloon><crayon><drum>", "SOURCE");
2 y_array_save_param_list("SOURCE", "<", ">", "VALUES");
3 y_array_filter("VALUES", "r", "VALUES2"); // get all elements NOT containing "r" (apple, balloon)
4 y_array_dump("VALUES2");
See also
y_array_grep(), y_array_concat(), y_array_pick_random()
Author
Floris Kraak

Definition at line 562 of file y_param_array.c.

char* y_array_get_no_zeroes ( const char *  source_param_array,
const int  param_array_index 
)

Get the content the nth member of target parameter array, but without embedded zeroes.

As y_array_get(), but it filters embedded zeroes from the input, replacing them with a single space: ' '. It's not ideal, but better than having your script break on this particular type of broken web page.

Warning
the return value of this function needs to be freed using lr_eval_string_ext_free().
Parameters
[in]source_param_arrayThe name of the parameter array to get an element from.
[in]param_array_indexThe index number of the element to fetch.
Returns
The parameter value at index param_array_index in the target parameter array.
Warning
the return value of this function needs to be freed using lr_eval_string_ext_free().

Example:

1 {
2  char *result;
3  lr_save_string("bar", "foo_1");
4  lr_save_string("baz", "foo_2");
5  lr_save_int(2, "foo_count");
6 
7  result = y_array_get_no_zeroes("foo", 1);
8  lr_log_message("Result: %s", result); // Prints "Result: bar"
9  free(result);
10  result = y_array_get_no_zeroes("foo", 2);
11  lr_log_message("Result: %s", result); // Prints "Result: baz"
12  free(result);
13 }
14 {
15  char buffer[11] = { '\0', 'b', '\0', 'r','o', '\0', 'k', 'e', 'n', '\0', '\0' };
16  char *tmp;
17  lr_save_var(buffer, 11, 0, "broken_1");
18  y_array_save_count(1, "broken");
19  tmp = y_array_get_no_zeroes("broken", 1);
20  lr_log_message("Result: '%s'", tmp); // prints "Result: ' b ro ken '"
21  free(tmp);
22 }
See also
y_array_get(), lr_paramarr_idx(), y_int_strlen(), lr_eval_string_ext()
Author
Floris Kraak

Definition at line 180 of file y_param_array.c.

char* y_array_get_random ( const char *  source_param_array)

Get a random element from a parameter list.

Fetch the contents of a random element in a parameter array. As lr_paramarr_random(), but stores the rolled index number internally.

Parameters
[in]source_param_arrayThe name of the parameter array to fetch a random value from.
Returns
The value of the randomly chosen parameter.
Deprecated:
This doesn't really do anything that lr_paramarr_random() doesn't already do.
See also
lr_paramarr_random(), y_rand()
Author
Floris Kraak

Definition at line 351 of file y_param_array.c.

char* y_array_get_random_no_zeroes ( const char *  source_param_array)

Get a random element from a parameter list without embedded zeroes.

Fetch the contents of a random element in a parameter array, filtering out any embedded zeroes. Stores the rolled index number internally.

Warning
the return value of this function needs to be freed using lr_eval_string_ext_free().
Parameters
[in]source_param_arrayThe name of the parameter array to fetch a random value from.
Returns
The value of the randomly chosen parameter, minus any embedded \x00 characters.
See also
lr_paramarr_random(), y_array_get_random(), y_rand()
Author
Floris Kraak

Definition at line 378 of file y_param_array.c.

void y_array_grep ( const char *  source_param_array,
const char *  search,
const char *  result_array 
)

Search a parameter array for a specific text and build a new array containing only parameters containing that text.

Let's just call it 'grep'. :)

Parameters
[in]source_param_arrayThe name of the array to be searched.
[in]searchThe string to search for.
[in]result_arrayThe name of the array to hold the resulting values. Can be the same as the original parameter array.

Example:

1 lr_save_string("<apple><balloon><crayon><drum>", "SOURCE");
2 y_array_save_param_list("SOURCE", "<", ">", "VALUES");
3 y_array_grep("VALUES", "r", "VALUES2"); // get all elements containing "r" (crayon and drum)
4 y_array_dump("VALUES2");
See also
y_array_filter(), y_array_concat(), y_array_pick_random()
Author
Floris Kraak

Definition at line 525 of file y_param_array.c.

int y_array_merge ( const char *  param_array_left,
const char *  param_array_right,
const char *  separator,
const char *  result_array 
)

Merge two parameter arrays into a single array.

Warning
The source parameter arrays have to be of the same length.

The resulting list contains each item from the left array appended to the item with the same index in the right array, with an optional glue separator in the middle for convenient re-splitting later.

This thing is mostly created to facilitate situations where you have two lists of parameters that contain data that is related to each other. Example: Hyperlinks consist of a hyperlink and a title, and each of these is captured seperately. Since the entries in these lists are closely correlated picking one involves correlating entries in the hyperlink list with the entries in the title list.

With this function you can just glue the two lists together based on their index and continue processing from there.

Parameters
[in]param_array_leftThe parameter array to use for the lefthand side of the concatenations.
[in]param_array_rightThe parameter array to use for the righthand side of the concatenations.
[in]separatorA fixed string to be used as a seperator between the two values.
[in]result_arrayThe name of the array to hold the resulting values. Can be the same as either the left or the righthand parameter array.

Example:

1 lr_save_string("<apple><balloon><crayon><drum>", "THING");
2 lr_save_string("<fruit><toy><art><music>", "CAT");
3 y_array_save_param_list("THING", "<", ">", "THING2"); // {THING2} contains "balloon" (no quotes)
4 y_array_save_param_list("CAT", "<", ">", "CAT2"); // {CAT2} contains "toy"
5 y_array_merge("THING2", "CAT2", "=>", "RESULT"); // {RESULT_2} now contains balloon=>toy
6 y_array_dump("RESULT");
See also
y_array_split(), y_array_concat(), y_array_pick_random()
Author
Floris Kraak

Definition at line 612 of file y_param_array.c.

int y_array_pick_random ( const char *  source_param_array)

Choose an element at random from a saved parameter list and store it in a parameter with the same name.

Fetch the contents of a random element in a parameter array, filtering out any embedded zeroes, and saves it as a parameter with the same name.

Parameters
[in]source_param_arrayThe name of the parameter array to fetch a random value from.
Returns
The index number of the randomly chosen parameter.
See also
lr_paramarr_random(), y_array_get_random_no_zeroes(), y_rand()
Author
Floris Kraak

Definition at line 402 of file y_param_array.c.

void y_array_save ( const char *  value,
const char *  source_param_array,
const int  param_array_index 
)

Save a string value into an array at a specified position.

This does not update the size of the array.

Parameters
[in]valueThe value to store
[in]source_param_arrayThe name of the array to store the value in
[in]param_array_indexThe index of the element to be updated.

Example:

1 web_reg_save_param("TAG", "LB=<a", "RB=>", "ORD=ALL", LAST);
2 web_url("URL=www.google.nl", LAST);
3 y_array_save("newvalue", "TAG", 2); // save the sting "newvalue" into {TAG_2}
4 lr_log_message("Value: %s", y_array_get("TAG", 2)); // print the value of {TAG_2}. (will be "newvalue" in this example)
See also
y_array_get(), y_array_count()
Author
Floris Kraak

Definition at line 217 of file y_param_array.c.

void y_array_save_count ( const int  count,
const char *  source_param_array 
)

Change the size of the target parameter array.

Updates the _count field of the chosen parameter array, changing the reported size of the array.

Note
This does not verify if the array in question actually contains that number of elements.
Parameters
[in]countThe new size of the array.
[in]source_param_arrayThe target array to resize.
See also
y_array_save()
Author
Floris Kraak

Definition at line 246 of file y_param_array.c.

void y_array_save_param_list ( const char *  sourceParam,
const char *  LB,
const char *  RB,
const char *  result_array 
)

Create a parameter list from a single parameter value.

As if using web_reg_save_param() with "Ord=All" as an option, but for already saved parameters instead of web requests. This is especially useful when there is a need to save lists of parameters from sections of the application output instead of the entire thing.

For example, HTML dropdown boxes look like this:

1 <select>
2  <option value="volvo">Volvo</option>
3  <option value="saab">Saab</option>
4  <option value="mercedes">Mercedes</option>
5  <option value="audi">Audi</option>
6 </select>

These cannot be correlated using just <option> and </option> as the left and right boundaries if there is more than one dropdown box on a page. Using this function you can save the HTML for the entire dropdown box in a parameter instead, then have the options saved as a parameter list afterwards.

Warning
Using this for large lists can be really slow. This is running lr_save_string() in a loop, and lr_save_string() will slow down if you use it a few thousand times.
Todo:
Write a wrapper around this - let's call it 'y_dropdown()' specifically for HTML dropdown boxes, as that is the most common case.
Parameters
[in]sourceParamThe name of a single parameter containing a list of elements. See dropdown example, above.
[in]LBThe left boundary of the values you wish to save into a list. Example: <option>
[in]RBThe right boundary of the values you wish to save into a list. Example: </option>
[in]result_arrayThe name of the parameter array to save the values into.

Example:

1 lr_save_string("<option value=\"water\"><option value=\"fire\"><option value=\"burn\">", "SOURCE");
2 y_array_save_param_list("SOURCE", "value=\"", "\">", "VALUES");
3 y_array_dump("VALUES"); // {VALUES_1} contains "water" (no quotes) {VALUES_2} contains "fire" (no quotes) etc...
Author
Floris Kraak

Definition at line 482 of file y_param_array.c.

void y_array_shuffle ( char *  source_param_array,
char *  result_array 
)

Shuffle a parameter array and store the result in a new array of parameters.

Warning
Unlike most of the parameter array functions, the source parameter array CANNOT be the same as the result parameter array.
Note
y_array_pick_random() is usually better and much faster than using this function. Only use it if you cannot allow the code to repeatedly pick the same element.
Parameters
[in]source_param_arrayThe name of the array holding the values to be shuffled.
[in]result_arrayThe parameter array holding the shuffled result. This array must NOT have the same name as the original array.

Example:

1 web_reg_save_param("TAG", "LB=<a", "RB=>", "ORD=ALL", LAST);
2 web_url("URL=www.google.nl", LAST);
3 y_array_shuffle("TAG", "SHUFFLE_TAG");
4 y_array_dump("SHUFFLE_TAG");
5 // Now, suppose {TAG_1}="cow", {TAG_2}="chicken", {TAG_3}="boneless", {TAG_4}="redguy".
6 // Then this could be the result:
7 // {SHUFFLE_TAG_1} = "chicken", {SHUFFLE_TAG_2}="redguy", {SHUFFLE_TAG_3} = "cow", {SHUFFLE_TAG_4}="boneless".
See also
y_array_pick_random()
Author
Raymond de Jongh, Floris Kraak

Definition at line 715 of file y_param_array.c.

void y_array_split ( const char *  source_param_array,
const char *  separator,
const char *  param_array_left,
const char *  param_array_right 
)

Split an input array vertically into two new arrays, based on a search parameter.

This is the reverse of y_array_merge(). It will examine each parameter in turn and save each value into two separate parameter lists.

Note
Using the same array for the left and right hand side result arrays will result in one side overwriting the values from the other side.
Parameters
[in]source_param_arrayThe name of the array holding the values to be split.
[in]separatorA fixed string to be used as a seperator between the two values.
[in]param_array_leftThe parameter array to use for the lefthand side of the concatenations. Can be the same as the input array.
[in]param_array_rightThe parameter array to use for the righthand side of the concatenations. Can also be the same as the input array.
See also
y_array_merge(), y_array_concat(), y_array_pick_random(), y_split_str()
Author
Floris Kraak

Definition at line 662 of file y_param_array.c.

Variable Documentation

int _y_random_array_index = 0

Definition at line 45 of file y_param_array.c.