void CreateTestFile(struct NaClHostDesc *d_out,
                    struct NaClHostDesc *d_ronly_out,
                    char const *pathname,
                    struct TestParams const *param) {
  struct NaClHostDesc hd;
  int err;

  printf("pathname = %s, perms %#o\n", pathname, param->file_perms);
  if (0 != (err = NaClHostDescOpen(&hd,
                                   pathname,
                                   NACL_ABI_O_WRONLY |
                                   NACL_ABI_O_CREAT |
                                   NACL_ABI_O_TRUNC,
                                   param->file_perms))) {
    fprintf(stderr, "Could not open test scratch file: NaCl errno %d\n", -err);
    exit(1);
  }
  if (0 != (err = CreateTestData(&hd))) {
    fprintf(stderr,
            "Could not write test data into test scratch file: NaCl errno %d\n",
            -err);
    exit(1);
  }
  if (0 != (err = NaClHostDescClose(&hd))) {
    fprintf(stderr,
            "Error while closing test data file, NaCl errno %d\n", -err);
    exit(1);
  }
  if (0 != (err = NaClHostDescOpen(d_out,
                                   pathname,
                                   param->open_flags,
                                   param->file_perms))) {
    fprintf(stderr, "Could not open test scratch file: NaCl errno %d\n", -err);
    exit(1);
  }
  if (0 != (err = NaClHostDescOpen(d_ronly_out,
                                   pathname,
                                   NACL_ABI_O_RDONLY,
                                   0))) {
    fprintf(stderr,
            "Could not open read-only verification handle: NaCl errno %d\n",
            -err);
    exit(1);
  }
}
예제 #2
0
void medTestDbApp::run()
{
    dataManager = medDataManager::instance();
    CHECK_TEST_RESULT( dataManager );

    testData =  CreateTestData() ;
    CHECK_TEST_RESULT(testData);

    connect(dataManager, SIGNAL(importFailed(medDataIndex,QString)), this, SLOT(onImportFailed(const medDataIndex&,const QString&)));
    connect(dataManager, SIGNAL(dataAdded(const medDataIndex&)), this, SLOT(onNonPersistentDataImported(const medDataIndex&)));

    // Initially should be empty
    CHECK_TEST_RESULT( dataManager->nonPersistentDataCount() == 0 );

    // Test import of new data
    dataManager->importNonPersistent( testData );

    //  Wait until the data is actually imported.
}
void CreateTestFile(struct NaClHostDesc *d_out,
                    char const *pathname,
                    struct TestParams *param) {
  struct NaClHostDesc hd;
  int err;
  nacl_off64_t off;
  size_t desired_write;
  ssize_t bytes_written;

  printf("pathname = %s, perms 0%o\n", pathname, param->file_perms);
  if (0 != (err = NaClHostDescOpen(&hd,
                                   pathname,
                                   NACL_ABI_O_WRONLY |
                                   NACL_ABI_O_CREAT |
                                   NACL_ABI_O_TRUNC,
                                   param->file_perms))) {
    fprintf(stderr, "Could not open test scratch file: NaCl errno %d\n", -err);
    exit(1);
  }
  if (0 != (err = CreateTestData(&hd))) {
    fprintf(stderr,
            "Could not write test data into test scratch file: NaCl errno %d\n",
            -err);
    exit(1);
  }
  if (NULL != param->test_data_start) {
    off = NaClHostDescSeek(&hd, 0, 0);
    if (off < 0) {
      fprintf(stderr,
              "Could not seek to create test data: NaCl errno %d\n",
              (int) -off);
      exit(1);
    }
    desired_write = param->test_data_size;
    bytes_written = NaClHostDescWrite(&hd,
                                      param->test_data_start,
                                      desired_write);
    if (bytes_written < 0) {
      fprintf(stderr,
              "Could not write specialized test data: NaCl errno %d\n",
              (int) -bytes_written);
      exit(1);
    }
    if ((size_t) bytes_written != desired_write) {
      fprintf(stderr,
              "Error while writing specialized test data:"
              " tried to write %d, actual %d\n",
              (int) desired_write, (int) bytes_written);
      exit(1);
    }
  }
  if (0 != (err = NaClHostDescClose(&hd))) {
    fprintf(stderr,
            "Error while closing test data file, errno %d\n", -err);
    exit(1);
  }
  if (0 != (err = NaClHostDescOpen(d_out,
                                   pathname,
                                   param->open_flags,
                                   param->file_perms))) {
    fprintf(stderr, "Could not open test scratch file: NaCl errno %d\n", -err);
    exit(1);
  }
}
int CreateTestFile(char const *pathname,
                   struct TestParams *param) {
  int d;
  struct stat stbuf;
  off_t off;
  size_t desired_write;
  ssize_t bytes_written;

  printf("pathname = %s, %d bytes\n", pathname, param->file_size);
  if (-1 == (d = open(pathname,
                      O_WRONLY | O_CREAT | O_TRUNC,
                      param->file_mode))) {
    fprintf(stderr, "Could not open test scratch file: NaCl errno %d\n", errno);
    exit(1);
  }
  if (0 != CreateTestData(d, param->file_size, param->halt_fill)) {
    fprintf(stderr,
            "Could not write test data into test scratch file: NaCl errno %d\n",
            errno);
    exit(1);
  }
  if (fstat(d, &stbuf) == -1) {
    fprintf(stderr, "fstat failed\n");
    exit(1);
  }
  if (stbuf.st_size != param->file_size) {
    fprintf(stderr, "file size incorrect!\n");
    exit(1);
  }
  if (NULL != param->test_data_start) {
    off = lseek(d, 0LL, 0);
    if (off < 0) {
      fprintf(stderr,
              "Could not seek to create test data: NaCl errno %d\n",
              errno);
      exit(1);
    }
    desired_write = param->test_data_size;
    bytes_written = write(d,
                          param->test_data_start,
                          desired_write);
    if (bytes_written < 0) {
      fprintf(stderr,
              "Could not write specialized test data: NaCl errno %d\n",
              errno);
      exit(1);
    }
    if ((size_t) bytes_written != desired_write) {
      fprintf(stderr,
              "Error while writing specialized test data:"
              " tried to write %d, actual %d\n",
              (int) desired_write, (int) bytes_written);
      exit(1);
    }
  }
  CHECK(0 == close(d));
  if (-1 == (d = open(pathname,
                      param->open_flags,
                      0777))) {
    fprintf(stderr, "Re-opening of %s failed, NaCl errno %d\n",
            pathname, errno);
    exit(1);
  }
  return d;
}