lr_convert_string_encoding=convert a string to a different encoding.
By using this Loadrunner function we can convert string to following formats
Unicode
UTF8
System Locale
The function saves the result string, including its terminating NULL, in the parameter name. Printable characters in the Output result string are displayed in VuGen and its logs as the actual characters. Non-printable characters are displayed in Hexadecimal.
For example:
rc = lr_convert_string_encoding("A", NULL, LR_ENC_UTF8, "stringInUnicode");
The output in the vugen string displays as A\x00, and not \x41\x00, because A is a printable character.
Add lr_convert_string_encoding is not recorded during recording. We need to insert manually when needed.
Script in Vugen:
Action()
{
int rc = 0;
//Convert String to Unicode in Loadrunner
rc = lr_convert_string_encoding("Hello world",
LR_ENC_SYSTEM_LOCALE,
LR_ENC_UNICODE,
"stringInUnicode");
// Convert String to UTF8 in loadrunner
rc = lr_convert_string_encoding("Hello world",
LR_ENC_SYSTEM_LOCALE,
LR_ENC_UTF8,
"stringInUTF8code");
return 0;
}
Note: To get the output please enable parameter substitution in runtime settings->Log->Extended Log->Parameter Substitution.
Output:
Starting iteration 1.
Maximum number of concurrent connections per server: 2 [MsgId: MMSG-26000]
Starting action Action.
Action.c(7): Notify: Saving Parameter "stringInUnicode = H\x00e\x00l\x00l\x00o\x00 \x00w\x00o\x00r\x00l\x00d\x00\x00\x00".
Action.c(17): Notify: Saving Parameter "stringInUTF8code = Hello world\x00".
Ending action Action.
Ending iteration 1.
By using this Loadrunner function we can convert string to following formats
Unicode
UTF8
System Locale
The function saves the result string, including its terminating NULL, in the parameter name. Printable characters in the Output result string are displayed in VuGen and its logs as the actual characters. Non-printable characters are displayed in Hexadecimal.
For example:
rc = lr_convert_string_encoding("A", NULL, LR_ENC_UTF8, "stringInUnicode");
The output in the vugen string displays as A\x00, and not \x41\x00, because A is a printable character.
Add lr_convert_string_encoding is not recorded during recording. We need to insert manually when needed.
Script in Vugen:
Action()
{
int rc = 0;
//Convert String to Unicode in Loadrunner
rc = lr_convert_string_encoding("Hello world",
LR_ENC_SYSTEM_LOCALE,
LR_ENC_UNICODE,
"stringInUnicode");
// Convert String to UTF8 in loadrunner
rc = lr_convert_string_encoding("Hello world",
LR_ENC_SYSTEM_LOCALE,
LR_ENC_UTF8,
"stringInUTF8code");
return 0;
}
Note: To get the output please enable parameter substitution in runtime settings->Log->Extended Log->Parameter Substitution.
Output:
Starting iteration 1.
Maximum number of concurrent connections per server: 2 [MsgId: MMSG-26000]
Starting action Action.
Action.c(7): Notify: Saving Parameter "stringInUnicode = H\x00e\x00l\x00l\x00o\x00 \x00w\x00o\x00r\x00l\x00d\x00\x00\x00".
Action.c(17): Notify: Saving Parameter "stringInUTF8code = Hello world\x00".
Ending action Action.
Ending iteration 1.
No comments:
Post a Comment