예제 #1
0
static void setup_pipe(void)
{
  if (send_file1 != 0) {
    if (send_file2 != 0)
      eprintf("Only one nesting of suite runs supported", __FILE__, __LINE__);
    open_tmp_file(&send_file2);
  } else {
    open_tmp_file(&send_file1);
  }
}
예제 #2
0
static void
setup_pipe (void)
{
  if (send_file1 == NULL) {
    send_file1 = open_tmp_file (&send_file1_name);
    return;
  }
  if (send_file2 == NULL) {
    send_file2 = open_tmp_file (&send_file2_name);
    return;
  }
  eprintf ("Only one nesting of suite runs supported", __FILE__, __LINE__);
}
예제 #3
0
END_TEST

START_TEST(test_ppack_nofail)
{
  FILE * result_file;
  char * result_file_name = NULL;
  CtxMsg cmsg;
  LocMsg lmsg;
  RcvMsg *rmsg;

  lmsg.file = (char *) "abc123.c";
  lmsg.line = 10;
  cmsg.ctx = CK_CTX_SETUP;
  result_file = open_tmp_file(&result_file_name);
  free(result_file_name);
  ppack (result_file, CK_MSG_CTX, (CheckMsg *) &cmsg);
  ppack (result_file, CK_MSG_LOC, (CheckMsg *) &lmsg);
  rewind (result_file);
  rmsg = punpack (result_file);

  ck_assert_msg (rmsg != NULL && rmsg->msg == NULL,
	       "Failure result should be NULL with no failure message");
  
  free (rmsg);
  fclose(result_file);
}
예제 #4
0
END_TEST

START_TEST(test_ppack_multictx)
{
  FILE * result_file;
  char * result_file_name = NULL;
  CtxMsg cmsg;
  LocMsg lmsg;
  RcvMsg *rmsg;
  
  cmsg.ctx = CK_CTX_SETUP;
  lmsg.line = 5;
  lmsg.file = (char *) "abc123.c";
  result_file = open_tmp_file(&result_file_name);
  free(result_file_name);
  ppack (result_file, CK_MSG_CTX, (CheckMsg *) &cmsg);
  ppack (result_file, CK_MSG_LOC, (CheckMsg *) &lmsg);
  cmsg.ctx = CK_CTX_TEST;
  ppack (result_file, CK_MSG_CTX, (CheckMsg *) &cmsg);
  ppack (result_file, CK_MSG_LOC, (CheckMsg *) &lmsg);
  cmsg.ctx = CK_CTX_TEARDOWN;
  ppack (result_file, CK_MSG_CTX, (CheckMsg *) &cmsg);
  rewind(result_file);
  rmsg = punpack (result_file);

  ck_assert_msg (rmsg != NULL && rmsg->test_line == 5,
	       "Test loc not being preserved on CTX change");

  ck_assert_msg (rmsg->fixture_line == -1,
	       "Fixture not reset on CTX change");

  free (rmsg);
  fclose(result_file);
}
예제 #5
0
END_TEST

START_TEST(test_ppack_onlyctx)
{
  FILE * result_file;
  char * result_file_name = NULL;
  CtxMsg cmsg;
  RcvMsg *rmsg;
  
  cmsg.ctx = CK_CTX_SETUP;
  result_file = open_tmp_file(&result_file_name);
  free(result_file_name);
  ppack (result_file, CK_MSG_CTX, (CheckMsg *) &cmsg);
  rewind(result_file);
  rmsg = punpack (result_file);

  ck_assert_msg (rmsg != NULL && rmsg->msg == NULL,
	       "Result message should be NULL with only CTX");
  ck_assert_msg (rmsg->fixture_line == -1,
	       "Result loc line should be -1 with only CTX");
  ck_assert_msg (rmsg->test_line == -1,
	       "Result loc line should be -1 with only CTX");

  if (rmsg != NULL)
    free (rmsg);
  fclose(result_file);
}
예제 #6
0
END_TEST

START_TEST(test_ppack_noctx)
{
  FILE * result_file;
  char * result_file_name = NULL;
  LocMsg lmsg;
  FailMsg fmsg;
  RcvMsg *rmsg;
  
  lmsg.file = (char *) "abc123.c";
  lmsg.line = 10;
  fmsg.msg = (char *) "oops";
  result_file = open_tmp_file(&result_file_name);
  free(result_file_name);
  ppack (result_file, CK_MSG_LOC, (CheckMsg *) &lmsg);
  ppack (result_file, CK_MSG_FAIL, (CheckMsg *) &fmsg);

  rewind(result_file);
  rmsg = punpack (result_file);

  ck_assert_msg (rmsg == NULL,
	       "Result should be NULL with no CTX");

  if (rmsg != NULL)
    free (rmsg);
  fclose(result_file);
}
예제 #7
0
static BHandle *
block_backend_fs_open_block (BlockBackend *bend,
                             const char *store_id,
                             int version,
                             const char *block_id,
                             int rw_type)
{
    BHandle *handle;
    int fd = -1;
    char *tmp_file;

    g_return_val_if_fail (block_id != NULL, NULL);
    g_return_val_if_fail (strlen(block_id) == 40, NULL);
    g_return_val_if_fail (rw_type == BLOCK_READ || rw_type == BLOCK_WRITE, NULL);

    if (rw_type == BLOCK_READ) {
        char path[SEAF_PATH_MAX];
        get_block_path (bend, block_id, path, store_id, version);
        fd = g_open (path, O_RDONLY | O_BINARY, 0);
        if (fd < 0) {
            ccnet_warning ("[block bend] failed to open block %s for read: %s\n",
                           block_id, strerror(errno));
            return NULL;
        }
    } else {
        fd = open_tmp_file (bend, block_id, &tmp_file);
        if (fd < 0) {
            ccnet_warning ("[block bend] failed to open block %s for write: %s\n",
                           block_id, strerror(errno));
            return NULL;
        }
    }

    handle = g_new0(BHandle, 1);
    handle->fd = fd;
    memcpy (handle->block_id, block_id, 41);
    handle->rw_type = rw_type;
    if (rw_type == BLOCK_WRITE)
        handle->tmp_file = tmp_file;
    if (store_id)
        handle->store_id = g_strdup(store_id);
    handle->version = version;

    return handle;
}
예제 #8
0
END_TEST

#define BIG_MSG_LEN 1037

START_TEST(test_ppack_big)
{
  FILE * result_file;
  char * result_file_name = NULL;
  CtxMsg cmsg;
  LocMsg lmsg;
  FailMsg fmsg;
  RcvMsg *rmsg;

  cmsg.ctx = CK_CTX_TEST;
  lmsg.file = (char *)emalloc (BIG_MSG_LEN);
  memset (lmsg.file,'a',BIG_MSG_LEN - 1);
  lmsg.file[BIG_MSG_LEN - 1] = '\0';
  lmsg.line = 10;
  fmsg.msg = (char *)emalloc (BIG_MSG_LEN);
  memset (fmsg.msg, 'a', BIG_MSG_LEN - 1);
  fmsg.msg[BIG_MSG_LEN - 1] = '\0';
  result_file = open_tmp_file(&result_file_name);
  free(result_file_name);
  ppack (result_file, CK_MSG_CTX, (CheckMsg *) &cmsg);
  ppack (result_file, CK_MSG_LOC, (CheckMsg *) &lmsg);
  ppack (result_file, CK_MSG_FAIL, (CheckMsg *) &fmsg);
  rewind (result_file);
  rmsg = punpack (result_file);

  ck_assert_msg (rmsg != NULL,
	       "Return value from ppack should always be malloc'ed");
  ck_assert_msg (rmsg->lastctx == CK_CTX_TEST,
	       "CTX not set correctly in ppack");
  ck_assert_msg (rmsg->test_line == 10,
	       "Test line not received correctly");
  ck_assert_msg (strcmp (rmsg->test_file, lmsg.file) == 0,
	       "Test file not received correctly");
  ck_assert_msg (strcmp (rmsg->msg, fmsg.msg) == 0,
	       "Failure message not received correctly");
  
  free (rmsg);
  free (lmsg.file);
  free (fmsg.msg);
  fclose(result_file);
}
예제 #9
0
END_TEST

/* the ppack probably means 'pipe' pack */
#if defined(HAVE_FORK) && HAVE_FORK==1
START_TEST(test_ppack)
{
  FILE * result_file;
  char * result_file_name = NULL;
  CtxMsg cmsg;
  LocMsg lmsg;
  FailMsg fmsg;
  RcvMsg *rmsg;
  
  cmsg.ctx = CK_CTX_TEST;
  lmsg.file = (char *) "abc123.c";
  lmsg.line = 10;
  fmsg.msg = (char *) "oops";
  result_file = open_tmp_file(&result_file_name);
  free(result_file_name);
  ppack (result_file, CK_MSG_CTX, (CheckMsg *) &cmsg);
  ppack (result_file, CK_MSG_LOC, (CheckMsg *) &lmsg);
  ppack (result_file, CK_MSG_FAIL, (CheckMsg *) &fmsg);

  rewind(result_file);
  rmsg = punpack (result_file);

  ck_assert_msg (rmsg != NULL,
	       "Return value from ppack should always be malloc'ed");
  ck_assert_msg (rmsg->lastctx == CK_CTX_TEST,
	       "CTX not set correctly in ppack");
  ck_assert_msg (rmsg->fixture_line == -1,
	       "Default fixture loc not correct");
  ck_assert_msg (rmsg->fixture_file == NULL,
	       "Default fixture loc not correct");
  ck_assert_msg (rmsg->test_line == 10,
	       "Test line not received correctly");
  ck_assert_msg (strcmp(rmsg->test_file,"abc123.c") == 0,
	       "Test file not received correctly");
  ck_assert_msg (strcmp(rmsg->msg, "oops") == 0,
	       "Failure message not received correctly");

  free(rmsg);
  fclose(result_file);
}