QTP Calling Library function - vbscript

I have same Function present in multiple Functional Library, when i call the function in driver script which function will be executed? for both multiple library and multiple function in same Functional Library.

If you have a function with the same name in multiple libraries, then which version will be executed depends on the order in which the libraries are associated to your QTP script.
If you have Library1.vbs and Library2.vbs associated in that order, the function within Library2.vbs will be executed as it will supercede the earlier loaded library.
Arguably you should never have the same function present in multiple libraries though as it can (and will) get confusing when you're trying to debug, maintain or improve your library code.

Related

TC3: Calling an FB method from the XAE Environment for testing purposes

I was wondering if it is possible to call a method directly from the XAE environment (online) for testing purposes. This would vastly reduce the amount of time to quickly test a function.
As an example; now I would write for each method:
IF bTestMethod THEN
fbFunctionBlock.method(parameters);
bTestMethod := FALSE;
END_IF
It would be nice to be able to call the function directly from the header within the online XAE interface by (for example) using a pragma like properties.
Maybe this functionality is already available that I'm not aware of? What would be the best / fastest way to test methods?
Thanks in advance,
Wouter
It would be nice to be able to call the function directly from the header within the online XAE interface by (for example) using a pragma like properties.
There is a pragma for calling methods remotely {attribute 'TcRpcEnable'}. But I don't know of any way to call it directly from XAE.
In the past I have used this pragma to test a method against an online 'calculator' with the help of node-red and this ADS node.
You can also add the method with the pragma to an opc-ua server. And use a client like UA-Expert to call the method manually.
Once you added the pragma, there are multiple ways to call it and test it over Ads. For many languages is a library available to make the ads calls. You can build a small test script, or a full test framework.
Like already mentioned in other answers, there is also a unit-testing library available to test code inside the controller without the need for extra software and pragma's: TcUnit
Maybe this functionality is already available that I'm not aware of?
Not that I'm aware of. There is no way to just call a function/method from XAE, because all the code is executed cyclically. So you need some way to 'activate' the function.
What would be the best / fastest way to test methods?
Make unit tests for individual functions and function blocks. Or you can make a digital twin to simulate machine behavior.

How do I define myself how functions must use my objects when making them available to theses functions (using my object at the end of the spec)?

In this question, I've given examples of package/object that :
implement some functions.
are used to define other functions by only making them availaible to those functions. It means. I don't write a function body but only a spec with "using package_name" or "using package_body" in the end.
I suppose that the way to use my pakcage/object to implement another function is defined somewhere.
I would like to know if there a way to define myself how to use a package/object. I want a way to implement a functions without writing the body everytime but only by writing in the spec that the function is using my package.
What I'm asking for is similar to already implemented function in a interface in java or an extention method in c#.
P.S. : I don't think that title is very clear. I would be glad if someone would propose another title.
I want a way to implement a functions without writing the body everytime but only by writing in the spec that the function is using my package.
You cannot define a function/procedure that references an SQL stored function/procedure like that. If you declare a function or procedure then it must include the signature and the body.
From the documentation:
create_function::=
plsql_function_source ::=
For a standalone function the body is required.
For a call specification, you can reference a function but it will be an external Java method or a C function and NOT another function defined in SQL.

Can we dynamically create a function in go?

I'm trying to create a service where a user needs to operate over a data and can manipulate it in numerous ways, so I'm not aware of the manipulations at the time of compiling of my program. One way to achieve this is to give the user a function with data as param. Which landed me in the following direction.
Dynamically create a function
Dynamically linking a function after compiling it separately.
I'm open to suggestions. If you have other ways to achieve the end goal.
If you don't like this as an answer I can move to the comment section, but it's rather long that's why I put here in the answer section.
Dynamically Dispatched Method: The only way to have dynamically dispatched methods is through an interface. Methods on a struct or any other concrete type are always resolved statically.
Closure: Go supports anonymous functions, which can form closures. Anonymous functions are useful when you want to define a function inline without having to name it.
Dyncamically call method on Interface:
Please let me know if that helps you to understand the concept in golang.

Instantiate inline class method

I write a library, this library includes a function void f() this function is a one line function and when I compile the library to shared object with -O3 gcc optimization flag it is inlined. I call it in a critical place in the code (must be as fast as possible) and I don't want to call it not inlined (hits performance substantially). The problem is that this function is part of the API that my library exposes so when library users link with my library and call this function they get undefined reference linkage error. Is there a way for my code to use the function inlined but still instantiate it in the object file so library users will be able to link and use it? (When I say "instantiate it in the object file" I mean I'd like to see it when I run objdump -t on the shared object). Just to make it clear, I'm not interested in a solution to wrap it with a function
void F() __attribute__((noinline)) { f(); }
Because I have many functions like that and I don't want to keep a copy for every function due to the enormous amount of overhead. I'm looking for a way to tell the compiler to use it inline when the definition is available to it, but still instantiate the function in the object file, so library users can link to with it too.
Check out this How can I tell gcc not to inline a function?
I found this solution the most appropriate. I'd like to note the main thing is that the code inside the library is still inlined so there is no performance penalty but users can still use the API as all functions have instantiation
Also another possible solution in the compilation level is to use -fkeep-inline-functions gcc switch which also instantiates inline functions and and uses them inlined where possible (unlike -fno-inline switch). The main problem with this switch is that if your code is heavily templated compilation time is much longer and the binary product becomes much bigger

CodeIgniter: Decision making for creating of library & helper in CodeIgniter

After developing in CodeIgniter for awhile, I find it difficult to make decisions when to create a custom library and when to create a custom helper.
I do understand that both allow having business logic in it and are reusable across the framework (calling from different controller etc.)
But I strongly believe that the fact that CI core developers are separating libraries from helpers, there has to be a reason behind it and I guess, this is the reason waiting for me to discover and get enlightened.
CI developers out there, pls advise.
i think it's better to include an example.
I could have a
class notification_lib {
function set_message() { /*...*/}
function get_message() {/*...*/}
function update_message() {/*...*/}
}
Alternatively, i could also include all the functions into a helper.
In a notification_helper.php file, i will include set_message(), get_message(), update_message()..
Where either way, it still can be reused. So this got me thinking about the decision making point about when exactly do we create a library and a helper particularly in CI.
In a normal (framework-less) php app, the choice is clear as there is no helper, you will just need to create a library in order to reuse codes. But here, in CI, I would like to understand the core developers seperation of libraries and helpers
Well the choice comes down to set of functions or class. The choice is almost the same as a instance class verses a static class.
If you have just a simply group of functions then you only need to make a group of functions. If these group of functions share a lot of data, then you need to make a class that has an instance to store this data in between the method (class function) calls.
Do you have many public or private properties to store relating to your notification messages?
If you use a class, you could set multiple messages through the system then get_messages() could return a private array of messages. That would make it perfect for being a library.
There is a question I ask myself when deciding this that I think will help you as well. The question is: Am I providing a feature to my framework or am I consolidating?
If you have a feature that you are adding to your framework, then you'll want to create a library for that. Form validation, for example, is a feature that you are adding to a framework. Even though you can do form validation without this library, you're creating a standard system for validation which is a feature.
However, there is also a form helper which helps you create the HTML of forms. The big difference from the form validation library is that the form helper isn't creating a new feature, its just a set of related functions that help you write the HTML of forms properly.
Hopefully this differentiation will help you as it has me.
First of all, you should be sure that you understand the difference between CI library and helper class. Helper class is anything that helps any pre-made thing such as array, string, uri, etc; they are there and PHP already provides functions for them but you still create a helper to add more functionality to them.
On the other hand, library can be anything like something you are creating for the first time, any solution which might not be necessarily already out there.
Once you understand this difference fully, taking decision must not be that difficult.
Helper contains a group of functions to help you do a particular task.
Available helpers in CI
Libraries usually contain non-CI specific functionality. Like an image library. Something which is portable between applications.
Available libraries in CI
Source link
If someone ask me what the way you follow when time comes to create Helpers or Libraries.
I think these differences:
Class : In a nutshell, a Class is a blueprint for an object. And an object encapsulates conceptually related State and Responsibility of something in your Application and usually offers an programming interface with which to interact with these. This fosters code reuse and improves maintainability.
Functions : A function is a piece of code which takes one more input in the form of parameter and does some processing and returns a value. You already have seen many functions like fopen() and fread() etc. They are built-in functions but PHP gives you option to create your own functions as well.
So go for Class i.e. libraries if any one point matches
global variable need to use in two or more functions or even one, I hate using Global keyword
default initialization as per each time call or load
some tasks are private to entity not publicly open, think of functions never have public modifiers why?
function to function dependencies i.e. tasks are separated but two or more tasks needs it. Think of validate_email check only for email sending script for to,cc,bcc,etc. all of these needs validate_email.
And Lastly not least all related tasks i.e. functions should be placed in single object or file, it's easier for reference and remembrance.
For Helpers : any point which not matches with libraries
Personally I use libraries for big things, say an FTP-library I built that is a lot faster than CodeIgniters shipped library. This is a class with a lot of methods that share data with each other.
I use helpers for smaller tasks that are not related to a lot of other functionality. Small functions like decorating strings might be an example. Or copying a directory recursively to another location.

Resources