I have existing C++ code, which creates a child process using fork() system call. And child process executes linux command using execlp() system call. Now I want to test this code using gmock framework with 100% code coverage. I googled a lot but I did not get any full proof solution. Can anybody help me with this?
This is my SUT:
int someclass :: os_fork()
{
pid_t pid = fork();
if (pid == -1) {
cout<<"fork() failed with errno" <<errno <<endl;
return false;
}
if (pid == 0 && (execlp("ls", "ls", nullptr) != 0))
{
cout<<"child process failed with errno"<<errno<<endl;
return false;
}
int ppid = pid;
return 0;
}
I want to mock fork() and execlp() system calls. How could I do that?