How to Save ServerResponse values into an Array/List using C and then Compare with existing values of .dat file

988 views
Skip to first unread message

Sam K

unread,
Sep 1, 2015, 8:28:22 AM9/1/15
to LoadRunner
I have a Scenario of Saving a List of VehicleDrivers into an Array/List and then Comparing This Array with another set of values present into .dat file.
I am saving the List of VehicleDrivers from ServerResponse using Correlation.
using the code below-
web_reg_save_param("DriverName","LB=Driver\"\":\"","RB=\"","Search=Body","ORD=ALL",LAST);

and I am getting the list of Drivers which I can see in Outpur window.

Now the problem is 
1- How can i save all these VehicleDrivers values into an Array/List using C language.
2- After Saving all these Driver Values, how can i Compare these values OneByOne FROM existing .dat file, to make sure if  ServerResponse has any Existing values (as present in .dat file)

So the Pseudo Code will be like below-

//Get the Total Count of Drivers using Correlation and Loop through it -
driverCount = atoi(lr_eval_string("{DriverName_count}"));
for (i = 1; i <= driverCount; i++) 
// Create Full List of Drivers
    sprintf(DriverArr, "{DriverName_%d}", i);
//Now Comparing the ServerResponse With DriverName present into  .dat file (FirstName and LastName) 
if (strcmp(lr_eval_string(DriverArr),strcat(strcat(lr_eval_string("{NewDriverFirst}"), " "), lr_eval_string("{NewDriverLast}"))) == 0)

So, Could you please let me know, 
1- How can I Store ALL DriverNames coming in ServerResponse into an ARRAY or LIST ?
2- Compare that Array/List (ALL Values OnebyOne) with EACH Value present into .dat file  (Here, How can I Iterate the Loop Completely EACH time For All the values present into .dat file,
So that Each DriverName present into .dat file Should get Compared with ALL values of ServerResponse OneByOne

Thanks
Sam

James Pulley

unread,
Sep 1, 2015, 8:50:35 AM9/1/15
to LoadRunner
They are already in an array (of sorts) in the form of DriverName_1 through Drivername_Count (as the limit)

So  (You will need to declare variables)

Number_of_items_in_your_dat_file=x;
Number_of_items_in_your_correlation=atoi(lr_eval_string("{Drivername_count}"));
found=false


for ( outer_loop=1; outer_loop<=Number_of_items_in_your_correlation; outer_loop++)
{
   sprintf( my_array_value, "{Drivername_%d}", outer_loop );
 
 
   for ( inner_loop = 1; inner_loop<=Number_of_items_in_your_dat_file; inner_loop++)
   {

      if ( strcmp( lr_eval_string("{My_dat_param}"),lr_eval_string(my_array_value) == 0 ) // Match!!!
      {
           found=true;
           inner_loop=Number_of_items_in_your_dat_file+1;        // Causes inner loop to quit
           outer_loop=Number_of_items_in_your_correlation+1;   // Causes outer loop to quit
      }
      lr_advance_param("My_dat_param"); 
  }
}

If ( found=true) { // then do something }

Code is untested and directly out of my head to this message.  No warranty or support implied.  Defects due to fat fingered code are par for the course and may require debugging on your end.  A book I own and one I have recommended to family (Brother and uncle) is one you may find useful, "C For Dummies."   Despite the title, it is an excellent book.

James Pulley

Sam K

unread,
Sep 2, 2015, 8:14:06 AM9/2/15
to LoadRunner
Thanks James...

I tried with the solution as suggested by you, But I am stuck at "my_array_value". I could not see the Array's value of Driver's Name.
Only in the Output Window During Correlation I can see the List of Driver Names.
But, When I tried with "lr_output_message(lr_eval_string(my_array_value));" I can see the Output is coming -> "{Drivername_1}"
Could you let me know, How can I get the DriverName instead of this Output.
And because of this, " if (strcmp ( lr_eval_string("{NewDriverFirst}"),lr_eval_string(my_array_value)) == 0) " Condition is also Failing.

Note - I have declared "my_array_value" as => char my_array_value[200];

Let me know, if I am missing anything.

--------------------------------

yathish kumar

unread,
Sep 4, 2015, 5:01:59 PM9/4/15
to LR-Loa...@googlegroups.com
You may have to declare my_array_value as double * pointer or [] []
In single dimensional array only you can save one set of chars (one string).. 

char **my_array_value;
or
char * my_array_value [];
or
char my_array_value [][];


On Fri, Sep 4, 2015 at 4:02 PM, yathish kumar <yath...@gmail.com> wrote:
Sam-

Instead of this sprintf statement 
sprintf( my_array_value, "{Drivername_%d}", outer_loop );


use these statements. 
    char *temp;
    
    temp = lr_paramarr_idx("Drivername", outer_loop);
    strcpy(my_array_value[outer_loop], temp);

Thanks,
Yathish

--
You received this message because you are subscribed to the Google Groups "LoadRunner" group.
To unsubscribe from this group and stop receiving emails from it, send an email to LR-LoadRunne...@googlegroups.com.
To post to this group, send email to LR-Loa...@googlegroups.com.
Visit this group at http://groups.google.com/group/LR-LoadRunner.
To view this discussion on the web visit https://groups.google.com/d/msgid/LR-LoadRunner/628b6e01-4404-4f3a-90be-4e2248b5cb42%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


yathish kumar

unread,
Sep 4, 2015, 5:02:00 PM9/4/15
to LR-Loa...@googlegroups.com
Sam-

Instead of this sprintf statement 
sprintf( my_array_value, "{Drivername_%d}", outer_loop );


use these statements. 
    char *temp;
    
    temp = lr_paramarr_idx("Drivername", outer_loop);
    strcpy(my_array_value[outer_loop], temp);

Thanks,
Yathish
On Wed, Sep 2, 2015 at 4:43 PM, Sam K <lrhe...@gmail.com> wrote:

André Luyer

unread,
Sep 4, 2015, 5:02:00 PM9/4/15
to LoadRunner
> I can see the Output is coming -> "{Drivername_1}"
Was this after the message "Warning: The string 'Drivername_1' with parameter delimiters is not a parameter."?
If so what did that message tell you?
Anyway check the spelling of the Loadrunner parameter name.

And lookup the functions lr_paramarr_idx and lr_paramarr_len and use these instead of atoi and s(n)printf.

I wonder why you want to do this anyway.
If this is a one off then it is easier to store the DriverNames into a file and do a file compare with the dat-file.
If you want to do this during a load test then there are faster methods...

André
Reply all
Reply to author
Forward
0 new messages