Esempio n. 1
0
File: example.c Progetto: mllev/trie
int main (void)
{
  Trie* trie = trieInit();
  int i;
  double end, start;
  nByte_t str[32];
  srand(time(NULL));
  start = (float)clock()/CLOCKS_PER_SEC;
  for( i=0; i<500000; ++i ){
    teststr(str);
    trieAdd(trie, (unsigned char*)str, KEY_LENGTH, "val");
  }
  trieAdd(trie, (unsigned char*)"hello", 5, "world");
  for( i=0; i<500000; ++i ){
    teststr(str);
    trieAdd(trie, (unsigned char*)str, KEY_LENGTH, "val");
  }
  end = (float)clock()/CLOCKS_PER_SEC;
  printf("Used %lu total bytes.\n", bytes);
  printf("Finshed in %f. Press enter.", end-start);
  getchar();

  puts((const char*)trieGet(trie, (unsigned char*)"hello", 5));
  trieDelete(trie, (unsigned char *)"hello", 5, &destroy);
  return 0;
}
Esempio n. 2
0
int
testarg(char *sec, char *qry)
{
	if (teststr(sec) || teststr(qry))
		return -1;
	if (!strcasecmp(sec, "any"))
		sec[0] = 0;
	return 0;
}
Esempio n. 3
0
int main(void)
{
	handle("--");
	testnull(inputname);
	testnull(outputname);

	handle("-E", "input");
	teststr(inputname, "input");
	testnull(outputname);
	
	return 0;
}
Esempio n. 4
0
int
main()
{
  int count;
  int tmp;
  int nextc;
  FILE *f;

  printf("checking: chars "); fflush(stdout);
  teststr("abcd", "%c", "a");
  teststr(" abcd", "%2c", " a");

  printf("strings ");
  teststr("abcd", "%3s", "abc");
  teststr("a", "%1s", "a");
  teststr("  abcd", "%5s", "abcd");
  teststr("hello world", "%s", "hello");
  teststr("THE0bestA", "%[A-Z]", "THE");
  teststr("1THE0bestA", "%[0-9a-z]", "1");
  teststr("not here", "%[0-9]", "");
  teststr("0ab9AB7", "%[0-9A-Z]", "0");
  teststr("7THE0bestA", "%[a-z0-9]", "7");
  teststr("123456789", "%3[0-9]", "123");
  teststr("ab123cd", "%4[^0-9]", "ab");
  teststr("[[a", "%[[]", "[[");
  teststr("ab]]", "%[^]]", "ab");
  teststr("ab]]", "%[]]", "");
  teststr("]]cd", "%[]]", "]]");

  setlocale(LC_ALL, "");

  printf("wchars "); fflush(stdout);
#define AlphaBetaGamma "\u03B1\u03B2\u03B3"

  testwstr(AlphaBetaGamma, "%lc", L"\u03B1");

  printf("wstrings "); fflush(stdout);
  testwstr(" abcd", "%3ls", L"abc");
  testwstr(" \u03B1  ", "%ls", L"\u03B1");
  testwstr(AlphaBetaGamma, "%ls", L"\u03B1\u03B2\u03B3");
  testwstr(AlphaBetaGamma, "%1ls", L"\u03B1");
  testwstr(AlphaBetaGamma, "%2ls", L"\u03B1\u03B2");
  testwstr(AlphaBetaGamma, "%3ls", L"\u03B1\u03B2\u03B3");
  testwstr("ab123cd", "%4l[^0-9]", L"ab");
  testwstr("[[a", "%l[[]", L"[[");
  testwstr("ab]]", "%l[^]]", L"ab");
  testwstr("ab]]", "%l[]]", L"");
  testwstr("]]cd", "%l[]]", L"]]");
  testwstr(AlphaBetaGamma, "%l[\u03B1\u03B2]", L"\u03B1\u03B2");
  testwstr(AlphaBetaGamma, "%l[^\u03B2]", L"");

  memset(wbuf, 0, sizeof(wbuf));
  testwstr("a\x80R", "%ls", L"a");

  printf("done\n");

  printf("testing 2 strings: "); fflush(stdout);
  test2str("12345 ab", "%s %s", "12345", "ab");
  test2str("12345ab", "%[0-9]%s", "12345", "ab");
  test2str("hello bob, how are you today?", "hello %[^,], how are %s today?", "bob", "you");

  test2wstr("12345\u0310ab", "%l[0-9]%ls", L"12345", L"\u0310ab");
  printf("done\n");

  printf("checking some corner cases... "); fflush(stdout);
  f = fmemopen(test0x, strlen(test0x), "r");
  tmp = -1;
  count = fscanf(f, "%d", &tmp);
  nextc = fgetc(f);
  EXPECTEQ(count, 1);
  EXPECTEQ(tmp, 0);
  EXPECTEQ(nextc, 'x');
  rewind(f);
  count = fscanf(f, "%c", &buf[0]);
  nextc = fgetc(f);
  EXPECTEQ(count, 1);
  EXPECTEQ(buf[0], '0');
  EXPECTEQ(nextc, 'x');

  rewind(f);
  tmp = 12;
  count = fscanf(f, "0%x", &tmp);
  nextc = fgetc(f);
  EXPECTEQ(count, 0);
  EXPECTEQ(tmp, 12);
  EXPECTEQ(nextc, 'x');

  /* this test is a little bit nasty; the string "0xyz" has a valid
     hex prefix, but is not a valid number. strtol will return 0 for it
     and leave the pointer at "x", but scanf can't because the
     standard doesn't allow more than 1 character of pushback;
     so it has to fail and leave the pointer at "y". GLIBC on Linux actually
     gets this wrong :-(
  */
  rewind(f);
  count = fscanf(f, "%x", &tmp);
  nextc = fgetc(f);
  EXPECTEQ(count, 0);
  EXPECTEQ(nextc, 'y');
  rewind(f);
  count = fscanf(f, "%i", &tmp);
  nextc = fgetc(f);
  EXPECTEQ(count, 0);
  EXPECTEQ(nextc, 'y');

  fclose(f);

  count = sscanf("0178ag", "%i%c", &tmp, &buf[0]);
  EXPECTEQ(count, 2);
  EXPECTEQ(tmp, 017);
  EXPECTEQ(buf[0], '8');
  count = sscanf("0178ag", "%d%c", &tmp, &buf[0]);
  EXPECTEQ(count, 2);
  EXPECTEQ(tmp, 178);
  EXPECTEQ(buf[0], 'a');
  count = sscanf("0178ag", "%x%c", &tmp, &buf[0]);
  EXPECTEQ(count, 2);
  EXPECTEQ(tmp, 0x178a);
  EXPECTEQ(buf[0], 'g');
  count = sscanf("0178ag", "%o%c", &tmp, &buf[0]);
  EXPECTEQ(count, 2);
  EXPECTEQ(tmp, 15);
  EXPECTEQ(buf[0], '8');

  strcpy(buf, "xxxxxx");
  strcpy(buf2, "xxxxxx");
  wcscpy(wbuf, L"xxxxxx");
  count = sscanf("ab\u0311\u0312cd", "a%[a-z]%l[^a-z]%c", buf, wbuf, buf2);
  EXPECTEQ(count, 3);
  EXPECTEQ(strcmp(buf, "b"), 0);
  EXPECTEQ(wbuf[0], L'\u0311');
  EXPECTEQ(wbuf[1], L'\u0312');
  EXPECTEQ(strcmp(buf2, "cxxxxx"), 0);

  printf("done\n");

  if (numerrors > 0) {
    printf("*** TEST FAILURES! ***\n");
  }
  return numerrors;
}