// extract the name from an environment variable // that is given in the form "NAME=VALUE" static OString env_var_name(const OString& env_var)
{
sal_Int32 pos_equal_sign =
env_var.indexOf('=');
if (pos_equal_sign != -1) return env_var.copy(0, pos_equal_sign);
return OString();
}
private:
std::vector<OString> exclude_list_;
};
void tidy_container(std::vector<OString> &env_container)
{ //sort them because there are no guarantees to ordering
std::sort(env_container.begin(), env_container.end()); if (RUNNING_ON_VALGRIND)
{
std::erase_if(
env_container,
[](OString const & s) { return s.startsWith("LD_PRELOAD=")
|| s.startsWith("VALGRIND_LIB="); });
}
}
}
staticvoid read_parent_environment(std::vector<OString>* env_container)
{ for (int i = 0; environ[i] != nullptr; i++)
env_container->push_back(OString(environ[i]));
tidy_container(*env_container);
}
#endif
class Test_osl_executeProcess : public CppUnit::TestFixture
{ const OUString env_param_;
std::string line;
line.reserve(1024); while (std::getline(file, line, '\0'))
env_container->push_back(OString(line.c_str()));
tidy_container(*env_container);
}
// environment of the child process that was // started. The child process writes his // environment into a file void compare_environments()
{
std::vector<OString> parent_env;
read_parent_environment(&parent_env);
OString msg(
OString::number(parent_env.size()) + "/"
+ OString::number(child_env.size())); auto min = std::min(parent_env.size(), child_env.size()); for (decltype(min) i = 0; i != min; ++i) {
CPPUNIT_ASSERT_EQUAL_MESSAGE(
msg.getStr(), parent_env[i], child_env[i]);
} if (parent_env.size() != child_env.size()) {
CPPUNIT_ASSERT_EQUAL_MESSAGE(
(parent_env.size() >= child_env.size()
? parent_env.back() : child_env.back()).getStr(),
parent_env.size(), child_env.size());
}
}
// compare the equal environment parts and the // different part of the child environment bool compare_merged_environments(const std::vector<OString>& different_env_vars)
{
std::vector<OString> parent_env;
read_parent_environment(&parent_env);
//remove the environment variables that we have changed //in the child environment from the read parent environment
std::erase_if(parent_env, exclude(different_env_vars));
//read the child environment and exclude the variables that //are different
std::vector<OString> child_env;
read_child_environment(&child_env);
for (auto& env : child_env)
std::cout << "initial child env: " << env << "\n"; //partition the child environment into the variables that //are different to the parent environment (they come first) //and the variables that should be equal between parent //and child environment auto iter_logical_end =
std::stable_partition(child_env.begin(), child_env.end(), exclude(different_env_vars));
// test that parent and child process have the // same environment when osl_executeProcess will // be called without setting new environment // variables void osl_execProc_parent_equals_child_environment()
{
oslProcess process;
oslProcessError osl_error = osl_executeProcess(
suExecutableFileURL.pData,
parameters_,
parameters_count_,
osl_Process_NORMAL,
nullptr,
suCWD.pData,
nullptr, 0,
&process);
CPPUNIT_ASSERT_EQUAL_MESSAGE
( "osl_joinProcess returned with failure",
osl_Process_E_None, osl_error
);
osl_freeProcessHandle(process);
}
CPPUNIT_TEST_SUITE(Test_osl_executeProcess); //TODO: Repair these (at least under Windows) #if !defined(_WIN32)
CPPUNIT_TEST(osl_execProc_parent_equals_child_environment);
CPPUNIT_TEST(osl_execProc_merged_child_environment); #endif
CPPUNIT_TEST(osl_execProc_test_batch); ///TODO: Repair test (or tested function ;-) - test fails.
CPPUNIT_TEST_SUITE_END();
};
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.