Esempio n. 1
0
Test(test_pathutils, test_get_filename_extension)
{
  cr_assert_str_eq(get_filename_extension("test.foo"), "foo", "wrong file name extension returned");
  cr_assert_str_eq(get_filename_extension("/test/test.foo.bar"), "bar", "wrong file name extension returned");
  cr_assert_str_eq(get_filename_extension("/test/.test/test.foo.bar"), "bar", "wrong file name extension returned");

  cr_assert_null(get_filename_extension("/test"), "wrong file name extension returned");
  cr_assert_null(get_filename_extension("test."), "wrong file name extension returned");
  cr_assert_null(get_filename_extension(""), "wrong file name extension returned");
  cr_assert_null(get_filename_extension(NULL), "wrong file name extension returned");
}
Esempio n. 2
0
Test(data, initializer_type_to_array) {
    struct type **types;
    gc_t gc = gc_init();
    cr_assert_eq(initializer_type_to_array, itta);

    types = itta(stt{
        construct_type(tid_integral, NULL, &gc),
        construct_type(tid_real, NULL, &gc),
    }, 2, &gc);
    cr_assert_eq(types[0]->single, tid_integral);
    cr_assert_null(types[0]->multiple); 
    cr_assert_eq(types[1]->single, tid_real);
    cr_assert_null(types[1]->multiple);
    cr_assert_null(types[2]);

    types = itta(stt{
        construct_type(tid_real, NULL, &gc),
        construct_type(tid_integral, NULL, &gc),
        construct_type(tid_tuple, itta(
            stt{construct_type(tid_string, NULL, &gc)}, 1, &gc
        ), &gc),
    }, 3, &gc);
    cr_assert_eq(types[0]->single, tid_real);
    cr_assert_null(types[0]->multiple); 
    cr_assert_eq(types[1]->single, tid_integral);
    cr_assert_null(types[1]->multiple);
    cr_assert_eq(types[2]->single, tid_tuple);
    cr_assert_eq(types[2]->multiple[0]->single, tid_string);
    cr_assert_null(types[2]->multiple[0]->multiple);
    cr_assert_null(types[2]->multiple[1]);
    cr_assert_null(types[3]);

    gc_clean(&gc);
}
Esempio n. 3
0
Test(data, construct_type_basic)
{
    gc_t gc = gc_init();
    struct type *type;
    struct type *multiple[10] = {NULL};
    
    type = construct_type(tid_integral, NULL, &gc);
    cr_assert_eq(type->single, tid_integral);
    cr_assert_null(type->multiple);

    type = construct_type(tid_string, NULL, &gc);
    cr_assert_eq(type->single, tid_string);
    cr_assert_null(type->multiple);

    multiple[0] = construct_type(tid_atom, NULL, &gc);
    type = construct_type(tid_list, multiple, &gc);
    cr_assert_eq(type->single, tid_list);
    cr_assert_eq(type->multiple[0]->single, tid_atom);
    cr_assert_null(type->multiple[0]->multiple);
    cr_assert_null(type->multiple[1]);

    multiple[0] = construct_type(tid_integral, NULL, &gc);
    multiple[1] = construct_type(tid_real, NULL, &gc);
    multiple[2] = construct_type(tid_string, NULL, &gc);
    type = construct_type(tid_tuple, multiple, &gc);
    cr_assert_eq(type->single, tid_tuple);
    cr_assert_eq(type->multiple[0]->single, tid_integral);
    cr_assert_null(type->multiple[0]->multiple);
    cr_assert_eq(type->multiple[1]->single, tid_real);
    cr_assert_null(type->multiple[1]->multiple);
    cr_assert_eq(type->multiple[2]->single, tid_string);
    cr_assert_null(type->multiple[2]->multiple);
    cr_assert_null(type->multiple[3]);

    gc_clean(&gc);
}
Esempio n. 4
0
void
assert_if_tokenizer_concatenated_result_not_match(STRTOK_R_FUN tokenizer,
                                                  const char *delim,
                                                  const char *input,
                                                  const char *expected)
{
  gchar *token;
  gchar *saveptr;
  gchar *result = (char *)g_malloc(strlen(input)+1);
  gchar *raw_string;
  gchar *result_ref = NULL;
  int result_idx = 0;
  int token_length;

  raw_string = g_strdup(input);

  for (token = tokenizer(raw_string, delim, &saveptr); token; token = tokenizer(NULL, delim, &saveptr))
    {
      token_length = strlen(token);
      memcpy(result + result_idx, token, token_length);
      result_idx += token_length;
    }

  result[result_idx] = '\0';

  if (result_idx)
    result_ref = result;

  if (NULL == expected)
    cr_assert_null(result_ref);
  else
    cr_expect_str_eq(result_ref, expected, "strtok return value mismatch");

  g_free(raw_string);
  g_free(result);
}
Esempio n. 5
0
static void straddr_test(void)
{
	const char *buf;
#define ADDRSTR_LEN 128
	char addrstr[ADDRSTR_LEN];
	size_t addrstr_len;
	char *pend;
	long int value;

	addrstr_len = 10; /* too short */
	buf = fi_av_straddr(av, &simple_ep_names[0], addrstr, &addrstr_len);
	cr_assert_eq(buf, addrstr);
	cr_assert_eq(addrstr_len, 10);

	addrstr_len = ADDRSTR_LEN;
	buf = fi_av_straddr(av, &simple_ep_names[0], addrstr, &addrstr_len);
	cr_assert_eq(buf, addrstr);
	cr_assert_eq(addrstr_len, GNIX_AV_MAX_STR_ADDR_LEN);

	/* extract the first component */
	buf = strtok(addrstr, ":");
	cr_assert_not_null(buf, "version not found");

	value = strtol(buf, &pend, 16);

	/* verify the version has been returned. */
	cr_assert_eq(GNIX_AV_STR_ADDR_VERSION, value, "Invalid version");

	/* extract the second component */
	buf = strtok(NULL, ":");
	cr_assert_not_null(buf, "device_addr not found");

	value = strtol(buf, &pend, 16);

	/* verify the device addrstr has been returned. */
	cr_assert_eq(simple_ep_names[0].gnix_addr.device_addr, value,
		    "Invalid device_addr");

	/* extract the third component */
	buf = strtok(NULL, ":");
	cr_assert_not_null(buf, "cdm_id not found");

	value = strtol(buf, &pend, 16);

	/* verify the cdm_id has been returned. */
	cr_assert_eq(simple_ep_names[0].gnix_addr.cdm_id, value,
		     "Invalid cdm_id");

	/* extract the fourth component */
	buf = strtok(NULL, ":");
	cr_assert_not_null(buf, "name_type not found");

	value = strtol(buf, &pend, 10);

	/* verify the name_type has been returned. */
	cr_assert_eq(simple_ep_names[0].name_type, value, "Invalid name_type");

	/* extract the fifth component */
	buf = strtok(NULL, ":");
	cr_assert_not_null(buf, "cm_nic_cdm_id not found");

	value = strtol(buf, &pend, 16);

	/* verify the cm_nic_cdm_id has been returned. */
	cr_assert_eq(simple_ep_names[0].cm_nic_cdm_id, value,
		     "Invalid cm_nic_cdm_id");

	/* extract the sixth component */
	buf = strtok(NULL, ":");
	cr_assert_not_null(buf, "cookie not found");

	value = strtol(buf, &pend, 16);

	/* verify the cookie has been returned. */
	cr_assert_eq(simple_ep_names[0].cookie, value, "Invalid cookie");

	/* check to see if additional component are specified */
	buf = strtok(NULL, ":");
	cr_assert_null(buf, "extra values specified");
}
Esempio n. 6
0
Test(data, init_type) {
    struct type type = init_type();
    cr_assert_eq(type.single, __tid_size);
    cr_assert_null(type.multiple);
}