}
public:
+ MyThread() :
+ m_rpcUnixClient(NULL),
+ m_rpcFakeClient(NULL),
+ m_connections(0),
+ m_sentData(0),
+ m_receivedData(0)
+ {}
+
virtual ~MyThread()
{
// Always quit thread
#include <dpl/db/naive_synchronization_object.h>
#include <dpl/thread.h>
+namespace {
+ unsigned int seed = time(NULL);
+}
+
namespace DPL {
namespace DB {
void NaiveSynchronizationObject::Synchronize()
{
// Sleep for about 10ms - 30ms
- Thread::MiliSleep(10 + rand() % 20);
+ Thread::MiliSleep(10 + rand_r(&seed) % 20);
}
void NaiveSynchronizationObject::NotifyAll()
DPL::String langdescr =
LocaleToBCP47LanguageTag(DPL::FromUTF8String(language));
- size_t position;
if (langdescr.empty()) {
LogError("Empty language description while correct value needed");
} else {
/* Language tags list should not be cleared before this place to
* avoid losing current data when new data are invalid */
+ size_t position;
while (true) {
LogDebug("Processing language description: " << langdescr);
m_languageTagsList.push_back(langdescr);
bool ParseCollectorFileArg(const std::string &arg, std::string &filename)
{
const std::string argname = "--file=";
- if (0 == arg.find(argname)) {
+ if (arg.find(argname) == 0 ) {
filename = arg.substr(argname.size());
return true;
}
return -1;
}
- struct dirent* entry = NULL;
- do {
+ int return_code;
+ struct dirent entry = NULL;
+ struct dirent* entry_result;
+
+ for (return_code = readdir_r(dir, &entry, &entry_result) != 0;
+ entry_result != NULL && return_code != 0;
+ return_code = readdir_r(dir, &entry, &entry_result))
+ {
errno = 0;
- if (NULL != (entry = ::readdir(dir))) {
- if (!::strncmp(entry->d_name, ".", 1) ||
- !::strncmp(entry->d_name, "..", 2))
- {
- continue;
- }
- std::string fullPath = WrtDB::PathBuilder(path)
- .Append(entry->d_name)
- .GetFullPath();
- if (RmNode(fullPath.c_str()) != 0) {
- int error = errno;
- TEMP_FAILURE_RETRY(::closedir(dir));
- errno = error;
- return -1;
- }
+ if (!::strncmp(entry.d_name, ".", 1) ||
+ !::strncmp(entry.d_name, "..", 2))
+ {
+ continue;
}
- } while (NULL != entry);
+ std::string fullPath = WrtDB::PathBuilder(path)
+ .Append(entry.d_name)
+ .GetFullPath();
+ if (RmNode(fullPath.c_str()) != 0) {
+ int error = errno;
+ TEMP_FAILURE_RETRY(::closedir(dir));
+ errno = error;
+ return -1;
+ }
+ }
- int error = errno;
+ int error = (!errno) ? errno : return_code;
if (TEMP_FAILURE_RETRY(::closedir(dir)) != 0) {
return -1;
}
// ignore environment variables if this flag is not set
#ifdef GLOBAL_SETTINGS_CONTROL
char * envStr = getenv(WRT_TEST_MODE);
- int testMode = 0;
if (NULL != envStr) {
std::string env = envStr;
+ int testMode = 0;
if ("1" == env) {
testMode = ALL_TEST;
} else {
#include <orm_generator_wrt.h>
#include <dpl/wrt-dao-ro/WrtDatabase.h>
+namespace {
+ unsigned int seed = time(NULL);
+}
+
namespace WrtDB {
//TODO in current solution in each getter there exists a check
//"IsWidgetInstalled". Maybe it should be verified, if it could be done
//make it more precise due to very fast tests
struct timeval tv;
gettimeofday(&tv, NULL);
- srand(time(NULL) + tv.tv_usec);
DbWidgetHandle widgetHandle;
do {
- widgetHandle = rand();
+ widgetHandle = rand_r(&seed);
} while (isWidgetInstalled(widgetHandle));
registerWidget(*pWidgetRegisterInfo.configInfo.tizenAppId,
#include <orm_generator_wrt.h>
#include <LanguageTagsProvider.h>
+namespace {
+ unsigned int seed = time(NULL);
+}
+
namespace WrtDB {
//TODO in current solution in each getter there exists a check
//"IsWidgetInstalled". Maybe it should be verified, if it could be done
pkgId.resize(MAX_TIZENID_LENGTH);
do {
for (int i = 0; i < MAX_TIZENID_LENGTH; ++i) {
- pkgId[i] = allowed[rand() % allowed.length()];
+ pkgId[i] = allowed[rand_r(&seed) % allowed.length()];
}
} while (isWidgetInstalled(pkgId));
return pkgId;
double rubbish; // to ensure this class has non-zero size.
public:
+ COtherClass() :
+ rubbish(0)
+ {}
+
virtual ~COtherClass()
{}
class VeryBigClass
{
+ public:
+ VeryBigClass() {
+ memset(letsMakeThingsComplicated, 0,
+ 400 * sizeof(letsMakeThingsComplicated[0]));
+ }
+
+ private:
int letsMakeThingsComplicated[400];
};
c.push_back(str2);
c.push_back(str1 + str2);
}
- TestClass(DPL::IStream& stream)
+ TestClass(DPL::IStream& stream) :
+ a(0) //TODO: consider the need (g.rynkowski)
{
DPL::Deserialization::Deserialize(stream, a);
DPL::Deserialization::Deserialize(stream, b);
PluginHandle depHandles[] = { 117, 119 };
PluginHandleSetPtr dependencies(new PluginHandleSet);
+ dependencies->insert(depHandles[0]);
dependencies->insert(depHandles[1]);
- dependencies->insert(depHandles[2]);
PluginDAO::registerPluginLibrariesDependencies(handle, dependencies);
retDependencies->size() == sizeof(depHandles) /
sizeof(depHandles[0]));
RUNNER_ASSERT(
- retDependencies->find(depHandles[1]) != retDependencies->end());
+ retDependencies->find(depHandles[0]) != retDependencies->end());
RUNNER_ASSERT(
- retDependencies->find(depHandles[2]) != retDependencies->end());
+ retDependencies->find(depHandles[1]) != retDependencies->end());
}
}
// properly
for (std::list<TestTableDelete::Row>::iterator i = originalList.begin();
i != originalList.end();
- i++)
+ ++i)
{
TestTableDelete::Insert insert(interface.get());
insert.Values(*i);
DPL::FromASCIIString(
"test 6"), "Wrong row 1 order");
RUNNER_ASSERT_MSG(iter->Get_TestID() == 10, "Wrong row 1 order");
- iter++;
+ ++iter;
}
{ //2 row
RUNNER_ASSERT_MSG(*iter->Get_TestText33() ==
DPL::FromASCIIString(
"test 5"), "Wrong row 2 order");
RUNNER_ASSERT_MSG(iter->Get_TestID() == 7, "Wrong row 2 order");
- iter++;
+ ++iter;
}
{ //3 row
RUNNER_ASSERT_MSG(iter->Get_Value3() == 111, "Wrong row 3 order");
DPL::FromASCIIString(
"test 2"), "Wrong row 3 order");
RUNNER_ASSERT_MSG(iter->Get_TestID() == 2, "Wrong row 3 order");
- iter++;
+ ++iter;
}
{ //4 row
RUNNER_ASSERT_MSG(iter->Get_Value3() == 111, "Wrong row 4 order");
DPL::FromASCIIString(
"test 1"), "Wrong row 4 order");
RUNNER_ASSERT_MSG(iter->Get_TestID() == 1, "Wrong row 4 order");
- iter++;
+ ++iter;
}
{ //5 row
RUNNER_ASSERT_MSG(iter->Get_Value3() == 222, "Wrong row 5 order");
DPL::FromASCIIString(
"test 4"), "Wrong row 5 order");
RUNNER_ASSERT_MSG(iter->Get_TestID() == 6, "Wrong row 5 order");
- iter++;
+ ++iter;
}
{ //6 row
RUNNER_ASSERT_MSG(iter->Get_Value3() == 222, "Wrong row 6 order");
DPL::FromASCIIString(
"test 3"), "Wrong row 6 order");
RUNNER_ASSERT_MSG(iter->Get_TestID() == 3, "Wrong row 6 order");
- iter++;
+ ++iter;
}
}
}
RUNNER_TEST_GROUP_INIT(DPL)
+namespace {
+ unsigned int seed = time(NULL);
+}
+
class IntController :
public DPL::Event::Controller<DPL::TypeListDecl<int>::Type>
{
return;
}
++testContextPtr->g_SentCounter;
- int id = rand() % static_cast<int>(testContextPtr->controllers.size());
+ int id = rand_r(&seed) % static_cast<int>(testContextPtr->controllers.size());
testContextPtr->controllers.at(id)->DPL::Event::
ControllerEventHandler<RandomEvent>::PostEvent(RandomEvent());
}
protected:
explicit EnumTestSO1(const std::string& semaphore) :
- TestSharedObject(semaphore) {}
+ TestSharedObject(semaphore),
+ m_waitable(NULL)
+ {}
+
virtual void PropertyChanged(size_t propertyEnum);
RUNNER_ASSERT(g_values[2] == 3);
int array[64];
- memset(array, 64 * sizeof(array[0]), 0);
+ memset(array, 0, 64 * sizeof(array[0]));
array[5] = 5;
sho->SetProperty<3, int[64]>(array);
Wait(waitable);
*/
class LazySharedObject : public SharedObject<TestTypeList>
{
+ private:
+ LazySharedObject() :
+ m_read(false)
+ {}
+
public:
explicit LazySharedObject(const std::string& semaphore) :
SharedObject<TestTypeList>(semaphore)
};
explicit ShmController4(DPL::WaitableEvent* event) :
- ListeningController<MTSharedObject>(event)
+ ListeningController<MTSharedObject>(event),
+ m_counter(0)
{}
virtual void OnEventReceived(const int& event);
void Sleep();
size_t m_counter;
+ static unsigned int seed = time(NULL);
};
void ShmController4::ValueChanged(size_t propertyEnum,
void ShmController4::Sleep()
{
DPL::Thread::GetCurrentThread()->MiliSleep(
- rand() % MAX_SINGLETON_LISTENER_DELAY);
+ rand_r(&seed) % MAX_SINGLETON_LISTENER_DELAY);
}
void ShmController4::OnEventReceived(const int& event)
{
RemoveIpcs(); // we need non existing shm
- srand(time(NULL));
-
// writer shared object
TestSharedObjectPtr sho = SharedObjectFactory<TestSharedObject>::Create(
SHM_KEY, SEM_NAME);
RUNNER_TEST(SqlConnection_MassiveReadWrite_SemaphoreSynchronization)
{
- srand(time(NULL));
-
std::ostringstream dbSemaporeFileNameStream;
+ unsigned int seed = time(NULL);
+
dbSemaporeFileNameStream << "dpl_tests_dbso_sem_";
- dbSemaporeFileNameStream << rand() << ".sem";
+ dbSemaporeFileNameStream << rand_r(&seed) << ".sem";
std::string dbSemaphoreFileName = dbSemaporeFileNameStream.str();
RUNNER_TEST(wrt_utility_WrtUtilMakeDir_PermissionError)
{
if (0 == getuid()) {
+ int bufsize;
+ if ((bufsize = sysconf(_SC_GETPW_R_SIZE_MAX)) == -1)
+ RUNNER_ASSERT_MSG(false,
+ "Getting an initial value suggested for the size of buffer failed.");
+
//Change UID to execute the test correctly
errno = 0;
- struct passwd *p = getpwnam("app");
- if (p == NULL) {
+ char *buffer = new char[bufsize];
+ struct passwd p;
+ struct passwd *result = NULL;
+ int return_value = getpwnam_r("app", &p, buffer, bufsize, &result);
+ delete[] buffer;
+
+ if (return_value != 0 || !result) {
int error = errno;
RUNNER_ASSERT_MSG(false, "Getting app user UID failed: "
<< (error ==
0 ? "No error detected" : strerror(error)));
}
- if (setuid(p->pw_uid) != 0) {
+ if (setuid(p.pw_uid) != 0) {
int error = errno;
RUNNER_ASSERT_MSG(false, "Changing to app user's UID failed: "
<< (error ==