MyLoadTest / IDocWizard

A LoadRunner extension to enable users to generate SAP IDoc files.
2 stars 0 forks source link

Add idoc_save function to C++ DLL #1

Closed StuartMoncrieff closed 11 years ago

StuartMoncrieff commented 11 years ago

Can you please add a function called "idoc_save" to the C++ DLL.

/// Saves a string (containing an IDoc) to the file system. /// @param the file name (including path) to save the IDoc to. /// @param the string containing the IDoc. /// @return true if the file was saved successfully.

I have added the function definition to IDocReplayDLL.cpp

VictorKouznetsov commented 11 years ago

Yes On 9/08/2013 5:47 PM, "Stuart Moncrieff" notifications@github.com wrote:

Can you please add a function called "idoc_save" to the C++ DLL.

/// Saves a string (containing an IDoc) to the file system. /// @param https://github.com/param the file name (including path) to save the IDoc to. /// @param https://github.com/param the string containing the IDoc. /// @return https://github.com/return true if the file was saved successfully.

I have added the function definition to IDocReplayDLL.cpp

— Reply to this email directly or view it on GitHubhttps://github.com/StuartMoncrieff/IDocWizard/issues/1 .

StuartMoncrieff commented 11 years ago

Closed by mistake (pressed the wrong button).

The new function definition can be found in 6d07819, which was committed on 2013-08-09

HarinezumiSama commented 11 years ago

@StuartMoncrieff: That's not clear what the idocString parameter in idoc_save function contains. Is it the same as the idocXml parameter in idoc_create function?

StuartMoncrieff commented 11 years ago

The save_idoc function should actually be able to save any string to a file. The only tricky bit is that the input arguments might contain parameters, so lr_eval_string should be called on the file_name before opening the file, and lr_eval_string should be called on the input string before writing the string to the file.

Here is a version I wrote previously (which I am sure you can improve upon). Note that it is missing the lr_eval_string functions.

int idoc_save(char* file_name, char* string) {
    int fp; // file pointer
    int rc; // return code
    int length = strlen(string);

    // Check that file_name is not NULL.
    if (file_name == NULL) {
        lr_error_message("Error. File name is NULL");
        return -1;
    }

    // Is there a way we can create the folder too if it does not exist?
    fp = fopen(file_name, "w"); // open file in "write" mode.
    if (fp == NULL) {
        lr_error_message("Error opening file: %s", file_name);
        return -1;
    }

    rc = fprintf(fp, "%s", string);
    if (rc != length) {
         lr_error_message("Error writing to file: %s", file_name);
         return -1;
    }

    rc = fclose(fp);
    if (rc != 0) {
        lr_error_message("Error closing file: %s", file_name);
        return -1;
    }

    return 0;
}
HarinezumiSama commented 11 years ago

Is it enough to call lr_eval_string on method parameters? Or should idoc_eval_string be called as well?

StuartMoncrieff commented 11 years ago

It shouldn't need idoc_eval_string, just lr_eval_string. Thanks. :)

HarinezumiSama commented 11 years ago

Thank you for the fast response. Then the issue has been implemented :) Closing the issue.