コード例 #1
0
ファイル: gtester.c プロジェクト: endlessm/glib
static gboolean
child_report_cb (GIOChannel  *source,
                 GIOCondition condition,
                 gpointer     data)
{
  GTestLogBuffer *tlb = data;
  GIOStatus status = G_IO_STATUS_NORMAL;
  gboolean first_read_eof = FALSE, first_read = TRUE;
  gsize length = 0;
  do
    {
      guint8 buffer[READ_BUFFER_SIZE];
      GError *error = NULL;
      status = g_io_channel_read_chars (source, (gchar*) buffer, sizeof (buffer), &length, &error);
      if (first_read && (condition & G_IO_IN))
        {
          /* on some unixes (MacOS) we need to detect non-blocking fd EOF
           * by an IO_IN select/poll followed by read()==0.
           */
          first_read_eof = length == 0;
        }
      first_read = FALSE;
      if (length)
        {
          GTestLogMsg *msg;
          g_test_log_buffer_push (tlb, length, buffer);
          do
            {
              msg = g_test_log_buffer_pop (tlb);
              if (msg)
                {
                  test_log_msg (msg);
                  g_test_log_msg_free (msg);
                }
            }
          while (msg);
        }
      g_clear_error (&error);
      /* ignore the io channel status, which will report intermediate EOFs for non blocking fds */
      (void) status;
    }
  while (length > 0);
  /* g_print ("LASTIOSTATE: first_read_eof=%d condition=%d\n", first_read_eof, condition); */
  if (first_read_eof || (condition & (G_IO_ERR | G_IO_HUP)))
    {
      /* if there's no data to read and select() reports an error or hangup,
       * the fd must have been closed remotely
       */
      subtest_io_pending = FALSE;
      return FALSE;
    }
  return TRUE; /* keep polling */
}
コード例 #2
0
ファイル: test-utils.c プロジェクト: cdaffara/symbiandump-os2
void test_g_log_buffer()
    {
    GTestLogBuffer* log_buffer;
    GTestLogMsg* log_msg;
	GTestLogMsg msg_ip;
    gchar *astrings[1] = {NULL};
    guint8 *dbuffer;
    guint dbufferlen;
    int i;

    msg_ip.log_type = G_TEST_LOG_MESSAGE;
    msg_ip.n_strings = 1;
    msg_ip.strings = astrings;
    astrings[0] = (gchar*) "test-log-some-dummy-log";
    msg_ip.n_nums = 0;
    msg_ip.nums = 0;
    dbuffer = (guint8*)g_test_log_dump(&msg_ip, &dbufferlen);
    
    log_buffer = g_test_log_buffer_new();
    
    if(log_buffer)
        {
        g_test_log_buffer_push(log_buffer, dbufferlen, (const guint8*)dbuffer);
            
        log_msg = g_test_log_buffer_pop(log_buffer);
        
        if(log_msg)
            {
            g_test_log_msg_free(log_msg);
            }
        else
            {
            std_log(LOG_FILENAME_LINE, "g_test_log_buffer_pop returned NULL");
            assert_failed = 1;
            }
        
        g_test_log_buffer_free(log_buffer);
        }
    else
        {
        std_log(LOG_FILENAME_LINE, "g_test_log_buffer_new returned NULL");
        assert_failed = 1;
        }

	g_free (dbuffer);
    }