예제 #1
0
int
main ()
{
  test_strncmp ();

  /* Test comparison with non-BMP characters.  */
  {
    static const UNIT input1[] = { 0xF0, 0x9D, 0x94, 0x9E, 0 };
    static const UNIT input2[] = { 0xEF, 0xBB, 0xBF, 0 };
    ASSERT (U_STRNCMP (input1, input2, 1) > 0);
    ASSERT (U_STRNCMP (input2, input1, 1) < 0);
    ASSERT (U_STRNCMP (input1, input2, 2) > 0);
    ASSERT (U_STRNCMP (input2, input1, 2) < 0);
    ASSERT (U_STRNCMP (input1, input2, 3) > 0);
    ASSERT (U_STRNCMP (input2, input1, 3) < 0);
    ASSERT (U_STRNCMP (input1, input2, 4) > 0);
    ASSERT (U_STRNCMP (input2, input1, 4) < 0);
    ASSERT (U_STRNCMP (input1, input2, 5) > 0);
    ASSERT (U_STRNCMP (input2, input1, 5) < 0);
    ASSERT (U_STRNCMP (input1, input2, 1000000) > 0);
    ASSERT (U_STRNCMP (input2, input1, 1000000) < 0);
  }

  return 0;
}
예제 #2
0
파일: main.c 프로젝트: KennyWuLee/strings
int main()
{
	//strcpy
	printf("%d\n", test_strcpy("hello", 0));

	//strncpy
	printf("%d\n", test_strncpy("hellohellohello", 7, 0));
	printf("%d\n", test_strncpy("hello", 7, 0));
	printf("%d\n", test_strncpy("hellohello", 10, 0));

	//strcmp
	printf("%d\n", test_strcmp("aaa", "arc", 0));
	printf("%d\n", test_strcmp("abc", "abc", 0));
	printf("%d\n", test_strcmp("ccc", "abc", 0));

	//strncmp
	printf("%d\n", test_strncmp("aaaddd", "alcccc", 3, 0));
	printf("%d\n", test_strncmp("abcddd", "abcccc", 3, 0));
	printf("%d\n", test_strncmp("cccddd", "abcccc", 3, 0));

	//strcat
	printf("%d\n", test_strcat("world", "hello", 0));
	printf("%d\n", test_strcat("fg", "", 0));
	printf("%d\n", test_strcat("", "hello", 0));

	//strncat
	printf("%d\n", test_strncat("world", "hello", 3, 0));
	printf("%d\n", test_strncat("world", "hello", 10, 0));
	printf("%d\n", test_strncat("", "hello", 10, 0));

	//strlen
	printf("%d\n", test_strlen("", 0));
	printf("%d\n", test_strlen("hello", 0));

	//strchr
	printf("%d\n", test_strchr("world", 'r', 0));
	printf("%d\n", test_strchr("world", 'a', 0));
	printf("%d\n", test_strchr("", 'a', 0));

	//strstr
	printf("%d\n", test_strstr("world", "rl", 0));
	printf("%d\n", test_strstr("needle", "nee", 0));
	printf("%d\n", test_strstr("world", "hello", 0));


	return 0;
}
예제 #3
0
static int __init test_init (void)
{
  int status;

  /* Test strcmp first because we use it to test other things.  */
  test_strcmp ();

  /* Test strcpy next because we need it to set up other tests.  */
  test_strcpy ();

  /* strncmp.  */
  test_strncmp ();

  /* strncpy.  */
  test_strncpy ();

  /* memcmp.  */
  test_memcmp ();

  /* memchr.  */
  test_memchr ();

  /* memcpy - need not work for overlap.  */
  test_memcpy ();

  /* memmove - must work on overlap.  */
  test_memmove ();

  /* memset.  */
  test_memset ();

  if (errors == 0)
    {
      status = 0;
      printf("TEST PASS.\n");
    }
  else
    {
      status = 1;
      printf("%Zd errors.\n", errors);
      printf("TEST FAIL.\n");
    }

  return status;
}
예제 #4
0
int main()
{
	test_strchr();
	test_strcmp();
	test_strncmp();
	test_strcpy();
	test_strncpy();
	test_strcspn();
	test_strlen();
	test_strcat();
	test_strncat();
	test_strpbrk();
	test_strrchr();
	test_strspn();
	test_strstr();
	test_strtok();
	return 0;
}
예제 #5
0
int
main ()
{
  test_strncmp ();

  /* Test comparison with non-BMP characters.  */
  {
    static const UNIT input1[] = { 0x1D51F, 0 };
    static const UNIT input2[] = { 0xFEFF, 0 };
    ASSERT (U_STRNCMP (input1, input2, 1) > 0);
    ASSERT (U_STRNCMP (input2, input1, 1) < 0);
    ASSERT (U_STRNCMP (input1, input2, 2) > 0);
    ASSERT (U_STRNCMP (input2, input1, 2) < 0);
    ASSERT (U_STRNCMP (input1, input2, 1000000) > 0);
    ASSERT (U_STRNCMP (input2, input1, 1000000) < 0);
  }

  return 0;
}
예제 #6
0
int main(int argc, char **argv)
{
  test_memcpy();
  test_memmove();
  test_strlen();
  test_strnlen();
  test_memset();
  test_strcmp();
  test_strncmp();
  test_memcmp();
  test_strcat();
  // strncat is not tested (code from the man page)
  test_strcpy();
  test_strncpy();
  test_strchr();
  test_strrchr();
  test_memchr();
  test_memrchr();
  test_strstr();
  // strerror not tested
  // strdup not tested (uses malloc)
  // strndup not tested (uses malloc)
  return 0;
}