/**
 * @brief when unpack end, delete all the unpacked files
 */
void testUnunpackEntryNormalDeleteResult()
{
  int Pid = fork();
  if (Pid < 0)
  {
    fprintf(stderr,"Fork error!\n");
    exit(-1);
  }
  else  if (Pid == 0)
  {
    int argc = 5;
    char *argv[] = {"../ununpack", "-qCRx", "./test-data/testdata4unpack.7z", "-d", "./test-result/"};
    deleteTmpFiles("./test-result/");
    existed = file_dir_existed("./test-result/");
    CU_ASSERT_EQUAL(existed, 0); // ./test-result/ does not exist
    int rc = system("mkdir ./test-result; cp ./test-data/testdata4unpack/ununpack.c.Z ./test-result");
    if (rc != 0) exit(-1);
    UnunpackEntry(argc, argv);
    exit(0);
  } else
  {
    int status;
    waitpid(Pid, &status, 0);
    existed = file_dir_existed("./test-result/testdata4unpack.7z.dir/testdata4unpack/libfossagent.a.dir/libfossagent.o");
    CU_ASSERT_EQUAL(existed, 0); // the file above does not exist
    existed = file_dir_existed("./test-result/");
    CU_ASSERT_EQUAL(existed, 0); // ./test-result/ does not exist 
  }
}
/**
 * @brief when unpack end, do not delete all the unpacked files
 * the package is xx.tar/xxx.rpm type
 * multy process
 */
void testUnunpackEntryNormalMultyProcess()
{
  int Pid = fork();
  if (Pid < 0)
  {
    fprintf(stderr,"Fork error!\n");
    exit(-1);
  }
  else  if (Pid == 0)
  {
    int argc = 7;
    char *argv[] = {"../ununpack", "-qCR", "-m", "5", "./test-data/testdata4unpack/rpm.tar", "-d", "./test-result/"}; 
    deleteTmpFiles("./test-result/");
    existed = file_dir_existed("./test-result/");
    CU_ASSERT_EQUAL(existed, 0); // ./test-result/ does not exist
    UnunpackEntry(argc, argv);
    exit(0);
  } else
  {
    int status;
    waitpid(Pid, &status, 0);
    existed = file_dir_existed("./test-result/rpm.tar.dir/yast2-trans-bn.rpm.unpacked.dir/yast2-trans-bn.rpm.dir/usr/share/doc/packages/yast2-trans-bn/status.txt");
    CU_ASSERT_EQUAL(existed, 1); // the file above exists 
  }
}
/**
 * @brief the option is invalid
 */
void testUnunpackEntryOptionInvalid()
{
  int Pid = fork();
  if (Pid < 0)
  {     
    fprintf(stderr,"Fork error!\n");    
    exit(-1);     
  }    
  else if (Pid == 0)
  {
    int argc = 5;
    char *argv[] = {"../ununpack", "-qCRs",
         "./test-data/testdata4unpack/rpm.tar", "-d", "./test-result/"}; // option H is invalid
    deleteTmpFiles("./test-result/");
    existed = file_dir_existed("./test-result/");
    CU_ASSERT_EQUAL(existed, 0); // ./test-result/ does not exist
    UnunpackEntry(argc, argv);
    exit(0);
  } else
  {
    int status;
    waitpid(Pid, &status, 0);
    int code = WEXITSTATUS(status);
    existed = file_dir_existed("./test-result/rpm.tar.dir/yast2-trans-bn.rpm.unpacked.dir/yast2-trans-bn.rpm.dir/usr/share/doc/packages/yast2-trans-bn/status.txt");
    CU_ASSERT_EQUAL(existed, 0); // the file above does not exist 
    CU_ASSERT_EQUAL(code, 25); // the exit code of unpack agent is 25
  }
}
Пример #4
0
int main()
{
  int result = file_dir_existed("./test-data");
  printf("result is:%d\n", result);
  return 0;
}