void binpath(TreeNode *root, vector<string> &res, string cur) {

        if (!root)
            return;

        if(!cur.empty())
            cur+= "->";

        if(!root->left && !root->right) {
            cur = cur + to_string(root->val);
            res.push_back(cur);
            return;
        }

        binpath(root->left, res, cur + to_string(root->val));
        binpath(root->right, res, cur + to_string(root->val));
    }
Exemple #2
0
    void addTestFunctionsAndPaths(lua_State* L)
    {
        lua_atpanic(L, atPanicThrow);
        lua_pushcfunction(L, ts_fail);
        lua_setglobal(L, "TS_FAIL");
        lua_pushcfunction(L, ts_trace);
        lua_setglobal(L, "TS_TRACE");
        lua_pushcfunction(L, ts_warn);
        lua_setglobal(L, "TS_WARN");

        lua_getglobal(L, "package");
        luaL_checktype(L, 1, LUA_TTABLE);

        // for cxxtest.lua
        lua_getfield(L, 1, "path");
        lua_pushstring(L, ";");
        lua_pushstring(L, srcpath().c_str());
        lua_pushstring(L, "/?.lua");
        lua_concat(L, 4);
        lua_setfield(L, 1, "path");

        // for libluacppreflect
        lua_getfield(L, 1, "cpath");
        lua_pushstring(L, ";");
        lua_pushstring(L, binpath().c_str());
        lua_pushstring(L, "/../lua_module/?.so");
        lua_pushstring(L, ";");
        lua_pushstring(L, binpath().c_str());
        lua_pushstring(L, "/../lua_module/?.dll"); // don't want to mess with platform DEFINEs
        lua_concat(L, 7);
        lua_setfield(L, 1, "cpath");

        // Uncomment this to prevent the unloading of the library
        // When the library is unloaded valgrind cannot translate function addresses to names
        // in the stacktrace
        //std::string library_path = fmt_str("%1/../lua_module/libluaselfportrait.so", binpath());
        //void* handle = dlopen(library_path.c_str(), RTLD_NOW);
    }
    vector<string> binaryTreePaths(TreeNode* root) {

        vector<string> res;

        if (!root)
            return res;

        string cur = "";

        binpath(root, res, cur);

        return res;



    }
Exemple #4
0
std::string Support::binpath(const std::string& file)
{
    const std::string s = binpath() + file;
    return s;
}
void TestBinRunner::_run_stuff()
{
    ///
    /// initialization

    // get arguments
    // avoid first argument (i.e., parent binary)
    QStringList args;
    for (int i = 1; i < _argc; i++)
        args << _argv[i];

    // declare process and output binder
    QProcess* pro;
    QtOutputBinder* qob;

    ///
    /// execute tests binaries
    for (std::list<TestSuiteDescriptor>::const_iterator ci = _testbins.begin();
         ci != _testbins.end();
         ++ci){

        // get path and name
        QString binid((*ci).id.c_str());
        QString binpath((*ci).path.c_str());
        QString bindesc((*ci).description.c_str());

        _running_instance = (*ci);

        std::cout << "+---------------------------------------------------------" << std::endl
                  << "  Executing: " << binpath.toStdString() << std::endl;

        // execute test bin

        // create process and connect output
        pro = new QProcess();
        qob = new QtOutputBinder(pro);
        qob->set_enabled(true);// enable for debugging

        // connect signal handlers
        pro->connect(pro,SIGNAL(error(QProcess::ProcessError)),this, SLOT(_qprocess_error_handler(QProcess::ProcessError)));
        //pro->connect(pro,SIGNAL(finished(int,QProcess::ExitStatus)),this, SLOT(_qprocess_finished_handler(int,QProcess::ExitStatus)));

        // execute binary and wait for it
        pro->start(binpath,args,QIODevice::ReadWrite | QIODevice::Text);

        if(!pro->waitForFinished()) // beware the timeout default parameter
        {
            std::cerr << "Error: Executing program failed with exit code " << pro->exitCode() << std::endl;
            _qprocess_error_handler(pro->error());
        }

        // do output stuff
        std::cout << "  Collecting output" << std::endl;
        _do_output_options();

        // clean
        pro->close();
        delete pro; delete qob;
        std::cout << "  Finished" << std::endl;

        // sleep if set
        _check_pause_between();
    }
}