Unit Testing on Nginx custom Modules - unit-testing

I'd like to find a way to make unit testing on my custom nginx modules but failed. Could anyone provide some suggestions? I once found the Test::Nginx framework, but it works as system test. Some people told me that I can use ngx_lua_module to expose C function in nginx module by the way of FFI. Could anyone know how to do that?

You can compile that custom module as a library and then load the function with FFI with any available language that supports it e.g. Python with Ctypes or directly in C by linking against that new library and then using its symbols (such as functions) to assert against certain behavior / return values.

Related

how many dynamic features are there in QT(Not in QML)?

We know that Qt has a plugin architecture that makes it possible to load code into an application without recompiling or relinking.
We also can integrate javascript into Qt using QScriptEngine.
I am wondering if there are any other dynamic features in Qt, which can add new features/functions to our application, without recompling or relinking.
Maybe too many (that's why your post is downvoted)
For example, you can get a python shell in your code without changing almost anything via the PythonQt library
You can get Lua too!

AS3 to C++ conversion – possible?

I built an iPad app in actionscript. A potential partner wants to pull my app into their app. They built their app natively using XCode. From what I understand, if my app had been built natively, I could simply export the code as a static library (.a file) for use by their app. Alas, I built mine in actionscript. So...
Is there a way to convert ActionScript 3 to C++?
Is one possible solution to do this conversion via AS3 to Haxe to C++?
Am I simply SOL and need to rebuild the game using XCode?
Thanks in advance.
Jason
You might consider the Tamarin project or Tamarin redux.
http://www-archive.mozilla.org/projects/tamarin/
It can be compiled in XCode as well. However, if your application is heavily depended on Flash runtime you have to implement all classes by yourself, because AVM contains only the basic AS3 classes.

Which C++ Unit Test framework does not require I build my application as a library?

I would like to write some test code for a C++ class. Because the class is part of an application but not a part of library I would like to know which unit test framework does not require building project as a library in order to run unit test code?
I tried the WinUnit but it seems only can test a library.
Any testing framework I know would allow that. It is an issue with the setting for your build environment, not the testing framework itself.
The easiest way to maintain it is to set up a library for your application code though.
I never used WinUnit, but I have used CppUnit and GoogleTest within VisualStudio projects where the code under test was not in a library, but the implementation files for the SUT were referenced (included) in the unit test project and it worked out.
Executables don't export symbols by default. You need to enable that with -Wl,--export-dynamic then link against the produced executable as though it was a library. This also means you need to do proper import/export on the classes you want to use etc.

Scripting C++ with python

I have a C++ program and I want to implement scripts on it. The desired scenario is, I have an executable of c++ code, it then calls at specific times a python script so it knows what to do through the embeded interpreter and the script then uses some form of API from the c++ program. This is where I ran into a problem. To expose c++ code to python you need to compile a DLL of the wrappers that you want and load it as a module inside python and that breaks my intention of python accessing the executable's functions.
Any way to resolve this problem without resorting to put so much pieces of c++ on a shared library?
What you want to do is to embed Python code into your application. There is an article on python.org on how to do that using raw CPython, but it's not that exhaustive when it comes to C++. A better bet might be to use Boost.Python or SWIG.

Calling python from a c++ program for distribution

I would like to call python script files from my c++ program.
I am not sure that the people I will distribute to will have python installed.
I would like to call python script files from my c++ program.
This means that you want to embed Python in your C++ application. As mentioned in Embedding Python in Another Application:
Embedding Python is similar to
extending it, but not quite. The
difference is that when you extend
Python, the main program of the
application is still the Python
interpreter, while if you embed
Python, the main program may have
nothing to do with Python — instead,
some parts of the application
occasionally call the Python
interpreter to run some Python code.
I suggest that you first go through Embedding Python in Another Application. Then refer the following examples
Embedding Python in C/C++: Part I
Embedding Python in C/C++: Part II
Embedding Python in Multi-Threaded C/C++ Applications
If you like Boost.Python, you may visit the following links:
Embedding Python with Boost.Python Part 1
Boost has a python interface library which could help you.
Boost.Python
Interestingly, nobody has mentioned pybind11, yet. From their documentation:
pybind11 is a lightweight header-only library that exposes C++ types
in Python and vice versa, mainly to create Python bindings of existing
C++ code. Its goals and syntax are similar to the excellent
Boost.Python library by David Abrahams: to minimize boilerplate code
in traditional extension modules by inferring type information using
compile-time introspection. [...] Since its creation, this library has
grown beyond Boost.Python in many ways, leading to dramatically
simpler binding code in many common situations.
Concretely, calling into a Python function (called embedding) is as simple as this (taken from the documentation):
#include <pybind11/embed.h> // everything needed for embedding
namespace py = pybind11;
int main() {
py::scoped_interpreter guard{}; // start the interpreter and keep it alive
py::print("Hello, World!"); // use the Python API
}
Use system call to run a python script from C++
#include<iostream>
#include <cstdlib>
using namespace std;
int main ()
{
int result = system("/usr/bin/python3 testGen1.py 1");
cout << result;
}
Embeding the Python interpreter inside your C++ app will let you run Python programs using your application run Python scripts. It will also make it easier possible for those scripts to call C++ functions in your application. If this is what you want then the Boost library mentioned previously may be what you want to make it easier to create the link. In the past I have used SWIG to generate Python interfaces to C++ code. It was not clear from your question whether you wanted the Python scripts to call your C++ program or whether you just wanted the C++ to call Python.
Many of the Python functions use modules which are not built into the Python interpreter. If your Python scripts call these functions then you will either need to have your users install Python or include the python runtime files with your application. It will depend on what modules you import in you Python scripts.
Boost is probably the best choice, however if you're wanting something that's more standalone, and if this is for use with Windows (which seems feasible given that they are the people least likely to have Python installed), then you can use py2exe to create a DLL with entry points suitable for COM objects. You can then interface with the library via COM. (Obviously this is not at all useful as a cross-platform solution).
Using Inter Process Communication (IPC) over socket can be a possible solution. Use a local network socket to listen/trasfer commands between both.