Example #1
0
//////// Meta testcases ////////////////////////////////////////////////////////
static void
crank_test_meta_expected_fail (gconstpointer userdata)
{
  gchar *efail_path = (gchar*) userdata;

  g_test_trap_subprocess (efail_path, 0, G_TEST_SUBPROCESS_INHERIT_STDERR);
  g_test_trap_assert_failed ();
}
Example #2
0
void test_wrong_option(void) {
    if (g_test_subprocess()) {
        char *test_argv[] = { "", "--nonex-option" };
        evaluate_options(2, test_argv);
    }

    g_test_trap_subprocess(NULL, 0, 0);
    g_test_trap_assert_failed();
    g_test_trap_assert_stderr("*Unrecognised option*");
}
Example #3
0
void test_bind_nonexisting(bool use_ipv6) {
    warnx("If this test fails check if host %s accidentally exists\n", host1);

    if (g_test_subprocess()) {
        test_bind(host1, 6, use_ipv6);
    }

    g_test_trap_subprocess(NULL, 0, 0);
    g_test_trap_assert_failed();
}
Example #4
0
void test_bind_local_root(bool use_ipv6) {
    warnx("If this test fails check that you are not root\n");

    if (g_test_subprocess()) {
        test_bind("localhost", 6, use_ipv6);
    }

    g_test_trap_subprocess(NULL, 0, 0);
    g_test_trap_assert_failed();
}
Example #5
0
/* Test g_warn macros */
static void
test_warnings (void)
{
  if (!g_test_undefined ())
    return;

  if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
    {
      g_warn_if_reached ();
    }
  g_test_trap_assert_failed();
  g_test_trap_assert_stderr ("*WARNING*test_warnings*should not be reached*");

  if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
    {
      g_warn_if_fail (FALSE);
    }
  g_test_trap_assert_failed();
  g_test_trap_assert_stderr ("*WARNING*test_warnings*runtime check failed*");
}
Example #6
0
void test_no_options(void) {
    if (g_test_subprocess()) {
        char *test_argv[] = { "" };
        evaluate_options(1, test_argv);
    }

    g_test_trap_subprocess(NULL, 0, 0);
    g_test_trap_assert_failed();
    g_test_trap_assert_stderr(
            "*Both ports are required for forwarding.\n\nUsage*");
}
Example #7
0
static void test_handler_run_failed(void)
{
    if (g_test_subprocess()) {
        handler_add("http", "unknown-program %s");
        handle_uri(TEST_URI);
        return;
    }
    g_test_trap_subprocess(NULL, 0, 0);
    g_test_trap_assert_failed();
    g_test_trap_assert_stderr("*Can't run *unknown-program*");
}
Example #8
0
static void
_cpml_sanity_get_length(gint i)
{
    switch (i) {
    case 1:
        cpml_primitive_get_length(NULL);
        break;
    default:
        g_test_trap_assert_failed();
        break;
    }
}
Example #9
0
static void
_cpml_sanity_offset(gint i)
{
    switch (i) {
    case 1:
        cpml_primitive_offset(NULL, 1);
        break;
    default:
        g_test_trap_assert_failed();
        break;
    }
}
Example #10
0
static void
_cpml_sanity_dump(gint i)
{
    switch (i) {
    case 1:
        cpml_segment_dump(NULL);
        break;
    default:
        g_test_trap_assert_failed();
        break;
    }
}
Example #11
0
static void test_sc_string_append_char__NULL_buf()
{
	if (g_test_subprocess()) {
		sc_string_append_char(NULL, 2, 'a');

		g_test_message("expected sc_string_append_char not to return");
		g_test_fail();
		return;
	}
	g_test_trap_subprocess(NULL, 0, 0);
	g_test_trap_assert_failed();
	g_test_trap_assert_stderr("cannot append character: buffer is NULL\n");
}
Example #12
0
static void test_sc_string_init__NULL_buf()
{
	if (g_test_subprocess()) {
		sc_string_init(NULL, 1);

		g_test_message("expected sc_string_init not to return");
		g_test_fail();
		return;
	}
	g_test_trap_subprocess(NULL, 0, 0);
	g_test_trap_assert_failed();
	g_test_trap_assert_stderr("cannot initialize string, buffer is NULL\n");
}
Example #13
0
static void test_sc_must_snprintf__fail()
{
	if (g_test_subprocess()) {
		char buf[5];
		sc_must_snprintf(buf, sizeof buf, "12345");
		g_test_message("expected sc_must_snprintf not to return");
		g_test_fail();
		return;
	}
	g_test_trap_subprocess(NULL, 0, 0);
	g_test_trap_assert_failed();
	g_test_trap_assert_stderr("cannot format string: 1234\n");
}
Example #14
0
static void test_sc_snap_name_validate__respects_error_protocol()
{
	if (g_test_subprocess()) {
		sc_snap_name_validate("hello world", NULL);
		g_test_message("expected sc_snap_name_validate to return");
		g_test_fail();
		return;
	}
	g_test_trap_subprocess(NULL, 0, 0);
	g_test_trap_assert_failed();
	g_test_trap_assert_stderr
	    ("snap name must use lower case letters, digits or dashes\n");
}
Example #15
0
static void
_test_new_good_null(gpointer fixture, gconstpointer user_data)
{
    if ( ! g_test_undefined() )
            return;
    if ( g_test_subprocess() )
    {
        eventd_event_new_for_uuid_string(EVENTD_EVENT_TEST_UUID, NULL, NULL);
        exit(0);
    }
    g_test_trap_subprocess(NULL, 0, 0);
    g_test_trap_assert_failed();
}
Example #16
0
static void
_test_add_data_null_good_good(gpointer fixture, gconstpointer user_data)
{
    if ( ! g_test_undefined() )
            return;
    if ( g_test_subprocess() )
    {
        eventd_event_add_data_string(NULL, EVENTD_EVENT_TEST_DATA_NAME, EVENTD_EVENT_TEST_DATA_CONTENT);
        exit(0);
    }
    g_test_trap_subprocess(NULL, 0, 0);
    g_test_trap_assert_failed();
}
Example #17
0
static void test_sc_string_quote_NULL_str()
{
	if (g_test_subprocess()) {
		char buf[16] = { 0 };
		sc_string_quote(buf, sizeof buf, NULL);

		g_test_message("expected sc_string_quote not to return");
		g_test_fail();
		return;
	}
	g_test_trap_subprocess(NULL, 0, 0);
	g_test_trap_assert_failed();
	g_test_trap_assert_stderr("cannot quote string: string is NULL\n");
}
Example #18
0
static void test_sc_enable_sanity_timeout()
{
	if (g_test_subprocess()) {
		sc_enable_sanity_timeout();
		debug("waiting...");
		usleep(4 * G_USEC_PER_SEC);
		debug("woke up");
		sc_disable_sanity_timeout();
		return;
	}
	g_test_trap_subprocess(NULL, 5 * G_USEC_PER_SEC,
			       G_TEST_SUBPROCESS_INHERIT_STDERR);
	g_test_trap_assert_failed();
}
Example #19
0
static void test_sc_unlock_ns_mutex_precondition()
{
	sc_test_use_fake_ns_dir();
	if (g_test_subprocess()) {
		struct sc_ns_group *group = sc_alloc_ns_group();
		g_test_queue_free(group);
		// Try to unlock the mutex, this should abort because we never opened the
		// lock file and don't have a valid file descriptor.
		sc_unlock_ns_mutex(group);
		return;
	}
	g_test_trap_subprocess(NULL, 0, 0);
	g_test_trap_assert_failed();
}
Example #20
0
static void
_test_add_data_notnull_good_bad(gpointer fixture, gconstpointer user_data)
{
    SettersData *data = fixture;

    if ( ! g_test_undefined() )
            return;
    if ( g_test_subprocess() )
    {
        eventd_event_add_data_string(data->event, EVENTD_EVENT_TEST_DATA_NAME, NULL);
        exit(0);
    }
    g_test_trap_subprocess(NULL, 0, 0);
    g_test_trap_assert_failed();
}
Example #21
0
void test_wrong_port2(void) {
    if (g_test_subprocess()) {
        char *test_argv[] = {
            "",
            "-p", "6",
            "-q", "DEF",
        };
        int test_argc = 5;
        evaluate_options(test_argc, test_argv);
    }

    g_test_trap_subprocess(NULL, 0, 0);
    g_test_trap_assert_failed();
    g_test_trap_assert_stderr("*Second port invalid*");
}
Example #22
0
// Check that `src' cannot be NULL.
static void test_sc_string_append__NULL_str()
{
	if (g_test_subprocess()) {
		char buf[4];

		sc_string_append(buf, sizeof buf, NULL);

		g_test_message("expected sc_string_append not to return");
		g_test_fail();
		return;
	}
	g_test_trap_subprocess(NULL, 0, 0);
	g_test_trap_assert_failed();
	g_test_trap_assert_stderr("cannot append string: string is NULL\n");
}
Example #23
0
static void test_sc_string_append_char__uninitialized_buf()
{
	if (g_test_subprocess()) {
		char buf[2] = { 0xFF, 0xFF };
		sc_string_append_char(buf, sizeof buf, 'a');

		g_test_message("expected sc_string_append_char not to return");
		g_test_fail();
		return;
	}
	g_test_trap_subprocess(NULL, 0, 0);
	g_test_trap_assert_failed();
	g_test_trap_assert_stderr
	    ("cannot append character: dst is unterminated\n");
}
Example #24
0
static void test_sc_string_append_char__overflow()
{
	if (g_test_subprocess()) {
		char buf[1] = { 0 };
		sc_string_append_char(buf, sizeof buf, 'a');

		g_test_message("expected sc_string_append_char not to return");
		g_test_fail();
		return;
	}
	g_test_trap_subprocess(NULL, 0, 0);
	g_test_trap_assert_failed();
	g_test_trap_assert_stderr
	    ("cannot append character: not enough space\n");
}
Example #25
0
static void
test_double_vtable (void)
{
  if (g_test_subprocess ())
    {
      GMemVTable vtable = { malloc, realloc, free, NULL, NULL, NULL };

      g_mem_set_vtable (&vtable);
      g_mem_set_vtable (&vtable);
      exit (0);
    }
  g_test_trap_subprocess (NULL, 0, 0);
  g_test_trap_assert_failed ();
  g_test_trap_assert_stderr ("*can only be set once*");
}
Example #26
0
static void test_sc_string_append_char__invalid_zero()
{
	if (g_test_subprocess()) {
		char buf[2] = { 0 };
		sc_string_append_char(buf, sizeof buf, '\0');

		g_test_message("expected sc_string_append_char not to return");
		g_test_fail();
		return;
	}
	g_test_trap_subprocess(NULL, 0, 0);
	g_test_trap_assert_failed();
	g_test_trap_assert_stderr
	    ("cannot append character: cannot append string terminator\n");
}
Example #27
0
// Check that rm_rf_tmp doesn't remove things outside of /tmp
static void test_rm_rf_tmp()
{
	if (access("/nonexistent", F_OK) == 0) {
		g_test_message
		    ("/nonexistent exists but this test doesn't want it to");
		g_test_fail();
		return;
	}
	if (g_test_subprocess()) {
		rm_rf_tmp("/nonexistent");
		return;
	}
	g_test_trap_subprocess(NULL, 0, 0);
	g_test_trap_assert_failed();
}
Example #28
0
static void test_sc_string_init__empty_buf()
{
	if (g_test_subprocess()) {
		char buf[1] = { 0xFF };

		sc_string_init(buf, 0);

		g_test_message("expected sc_string_init not to return");
		g_test_fail();
		return;
	}
	g_test_trap_subprocess(NULL, 0, 0);
	g_test_trap_assert_failed();
	g_test_trap_assert_stderr
	    ("cannot initialize string, buffer is too small\n");
}
Example #29
0
static void
test_conform_todo_test (TestConformSimpleFixture *fixture,
                        gconstpointer             data)
{
#ifdef G_OS_UNIX
  const TestConformTodo *todo = data;

  if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT | G_TEST_TRAP_SILENCE_STDERR))
    {
      todo->func (fixture, NULL);
      exit (0);
    }

  g_test_trap_assert_failed ();
#endif
}
Example #30
0
static void
test_incomplete_vtable (void)
{
  if (g_test_subprocess ())
    {
      GMemVTable vtable = { malloc, realloc, NULL, NULL, NULL, NULL };
      gpointer p;

      g_mem_set_vtable (&vtable);
      p = g_malloc0 (1000);
      g_free (p);
      exit (0);
    }
  g_test_trap_subprocess (NULL, 0, 0);
  g_test_trap_assert_failed ();
  g_test_trap_assert_stderr ("*lacks one of*");
}