Ejemplo n.º 1
0
int main (int argc, char **argv)
{
	g_mime_init ();
	
	testsuite_init (argc, argv);
	
	testsuite_start ("indexing");
	test_indexing ();
	testsuite_end ();

	testsuite_start ("removing");
	test_remove ();
	testsuite_end ();
	
	testsuite_start ("removing at an index");
	test_remove_at ();
	testsuite_end ();
	
	testsuite_start ("header synchronization");
	test_content_type_sync ();
	test_disposition_sync ();
	test_address_sync ();
	testsuite_end ();
	
	testsuite_start ("header formatting");
	test_header_formatting ();
	testsuite_end ();
	
	g_mime_shutdown ();
	
	return testsuite_exit ();
}
int main()
{
	test_insert();
	test_lookup();
	test_remove();
	return 0;
}
Ejemplo n.º 3
0
static void run_tests()
{
    test_misc();
    test_insert();
    test_remove();
    test_clear();
    test_extend();
    test_circular();
}
Ejemplo n.º 4
0
int main() {
  test_create(1);
  test_add(2);
  test_print(3);
  test_remove(4);
  test_remove_last_node();
  test_remove_first_node();
  test_add_with_index(0);
  test_add_with_index(1);
  test_add_with_index(2);
  return 0;
}
/*
 * Main - Try inserting / searching / deleting some nodes from a tree.
 */
int main(void) {
  printf("-- Simple Binary Search Tree --\n");

  /* Populate a tree */
  struct btree_tree *test = btree_create();
  btree_insert(test, 10);
  btree_insert(test, 3);
  btree_insert(test, 15);
  btree_insert(test, 9);
  btree_insert(test, 14);
  btree_insert(test, 20);
  btree_insert(test, 12);
  btree_insert(test, 21);
  btree_insert(test, 16);
  btree_insert(test, 17);
  btree_insert(test, 18);
  btree_insert(test, 11);
  btree_insert(test, 13);
  btree_insert(test, 2);

  printf("\nThere are now %i items in the tree.\n\n", test->count);

  int item;

  /* Remove an item with no right child */
  item = 2;
  test_remove(test, item);

  /* Remove an item with a right child that has no left child */
  item = 12;
  test_remove(test, item);

  /* Remove an item with a right child that has a left child */
  item = 20;
  test_remove(test, item);

  printf("There are now %i items in the tree.", test->count);

  return EXIT_SUCCESS;
}
Ejemplo n.º 6
0
int test_main( int , char* [] ) {

    const char **p = &test_strings[0];

    while ( *p != NULL ) {
        interop ( *p, *p );
        test_substr ( *p );
        test_remove ( *p );
        null_tests ( *p );
    
        p++;
        }

    return 0;
    }
Ejemplo n.º 7
0
int main(int argc, char* argv[]) {
    int errors = 0;

    test_append(&errors);
    test_remove(&errors);
    test_is_empty(&errors);
    test_reverse(&errors);
    test_sort(&errors);

    if (errors == 0)
        printf("All tests passed\n");
    else
        printf("\nTests done with %d error(s)\n", errors);

    return 0;
}
Ejemplo n.º 8
0
int run_remove_test(const char * path, bool exists){
	printf("testing remove()...");

	if ( test_remove(path) < 0 ){
		if ( (errno == ENOENT) && (exists == false) ){
			printf("does not exist...passed\n");
		} else {
			fflush(stdout);
			perror("unexpected error");
			return -1;
		}
	} else {
		printf("passed\n");
	}

	return 0;
}
Ejemplo n.º 9
0
/*
 * The main function just calls all unit tests and prints a summary
 * message (success or failure).
 *
 * \return zero on success.
 */
int main (int argc, char ** argv)
{
  int ok = 1;
  if (0 != test_append())
    ok = 0;
  if (0 != test_prepend())
    ok = 0;
  if (0 != test_insert())
    ok = 0;
  if (0 != test_remove())
    ok = 0;
  
  if (ok) {
    printf ("\nall tests PASSED\n");
    return 0;
  }
  printf ("\none or more tests FAILED\n");
  return 1;
}
Ejemplo n.º 10
0
int main(int argc, char *argv[])
{
	printf("--- test inode table leaf methods ---\n");
	struct sb *sb = &(struct sb){ .blocksize = 4096 };
	struct btree *btree = &(struct btree){
		.sb = sb,
		.ops = &itable_ops,
		.entries_per_leaf = 64, // !!! should depend on blocksize
	};
	struct ileaf *leaf = ileaf_create(btree);
	struct ileaf *dest = ileaf_create(btree);
	leaf->ibase = to_be_u64(0x10);
	ileaf_dump(btree, leaf);
	test_append(btree, leaf, 0x13, 2, 'a');
	test_append(btree, leaf, 0x14, 4, 'b');
	test_append(btree, leaf, 0x16, 6, 'c');
	ileaf_dump(btree, leaf);
	ileaf_split(btree, 0x10, leaf, dest);
	ileaf_dump(btree, leaf);
	ileaf_dump(btree, dest);
	ileaf_merge(btree, leaf, dest);
	ileaf_dump(btree, leaf);
	test_append(btree, leaf, 0x13, 3, 'x');
	ileaf_dump(btree, leaf);
	test_append(btree, leaf, 0x18, 3, 'y');
	ileaf_dump(btree, leaf);
	test_remove(btree, leaf, 0x16, 5);
	ileaf_dump(btree, leaf);
	unsigned size = 0;
	char *inode = ileaf_lookup(btree, 0x13, leaf, &size);
	hexdump(inode, size);
	for (int i = 0x11; i <= 0x20; i++)
		printf("goal 0x%x => 0x%Lx\n", i, (L)find_empty_inode(btree, leaf, i));
	ileaf_purge(btree, 0x14, leaf);
	ileaf_purge(btree, 0x18, leaf);
	ileaf_check(btree, leaf);
	ileaf_dump(btree, leaf);
	ileaf_destroy(btree, leaf);
	ileaf_destroy(btree, dest);
	exit(0);
}
Ejemplo n.º 11
0
int main(){
	MyAllocator allocator;
	allocator.constructor(1000);
	SplayTree<int,int> lol;
	lol.constructor(&allocator);
	srand(time(NULL));
	int n=10000000;
	int k=n;
	while(k--){
		lol.insert(k);
	}
	
	int i=0;
	SplayTreeIterator<int,int> iterator(&lol);
	while(iterator.hasNext()){
		SplayNode<int,int>*node=iterator.next();
		int v=node->getKey();
		i++;
	}

	lol.freeze();

	assert(i==n);
	assert(n==lol.size());
	SplayTreeIterator<int,int> iterator2(&lol);
	i=0;
	while(iterator2.hasNext()){
		SplayNode<int,int>*node=iterator2.next();
		int v=node->getKey();
		i++;
	}
	assert(i==n);
	assert(n==lol.size());

	test_remove();
	test_iterator();
	return 0;
}
Ejemplo n.º 12
0
int main()
{
    int i;

    init();
    test_not_found();
    test_add();
    test_get();
    for (i = 0; i < 5; i++) {
        test_remove();
    }

#ifdef _USE_TIRPC
    test_not_found_6();
    test_add_6();
    test_get_6();
    for (i = 0; i < 5; i++) {
        test_remove_6();
    }
#endif

    return 0;
}
Ejemplo n.º 13
0
// run all tests
void run_alex_tests() {
    const int numTests = 6;
    for (int i = 1; i <= numTests; i++) {
        list* l = before();

        switch(i) {
            case 1: test_emptyList(l);
                    break;
            case 2: test_endOfList(l);
                    break;
            case 3: test_add(l);
                    break;
            case 4: test_remove(l);
                    break;
            case 5: test_list_ops(l);
                    break;
            case 6: test_copy_list_trivial(l);
                    break;
        }

        after(l);
    }
}
Ejemplo n.º 14
0
/*
 * TEST1: add all elements in a[0 ... n-1] to hmap
 * then remove them all one by one.
 */
static void test1(xq_hmap_t *map, xrational_t *q, uint32_t n) {
  uint32_t i;

  printf("Test1: start map\n");
  print_hmap(map);
  printf("\n");

  for (i=0; i<n; i++) {
    test_add(map, q + i);
  }

  printf("\nTest1: after additions\n");
  print_hmap(map);
  printf("\n");

  for (i=0; i<n; i++) {
    test_remove(map, q + i);
  }

  printf("\nTest1: after removals\n");
  print_hmap(map);
  printf("\n");
}
Ejemplo n.º 15
0
/*
 * Tests: add and remove
 */
static void run_tests(rba_buffer_t *b) {
  uint32_t i, h, n;

  check_tree(b);
  init_tests();

  // add all power products
  n = NUM_TESTS;
  for (i=0; i<n; i++) {
    test_add(b, test[i]);
  }
  printf("\nAfter %"PRIu32" additions\n", n);
  printf("   num_nodes = %"PRIu32"\n", b->num_nodes);
  printf("   num_terms = %"PRIu32"\n", b->nterms);
  printf("   root node = %"PRIu32"\n", b->root);
  if (is_balanced(b, b->root, &h)) {
    printf("   b-height    = %"PRIu32"\n", h);
    printf("   full height = %"PRIu32"\n", tree_height(b));
  } else {
    printf("   not balanced\n");
  }
  printf("\n");

  // remove half
  n = NUM_TESTS/2;
  for (i=0; i<n; i++) {
    test_remove(b, test[i]);
  }
  printf("\nAfter %"PRIu32" removals\n", n);
  printf("   num_nodes = %"PRIu32"\n", b->num_nodes);
  printf("   num_terms = %"PRIu32"\n", b->nterms);
  printf("   root node = %"PRIu32"\n", b->root);
  if (is_balanced(b, b->root, &h)) {
    printf("   b-height    = %"PRIu32"\n", h);
    printf("   full height = %"PRIu32"\n", tree_height(b));
  } else {
    printf("   not balanced\n");
  }

  // add them back
  for (i=0; i<n; i++) {
    test_add(b, test[i]);
  }
  printf("\nAfter %"PRIu32" additions\n", n);
  printf("   num_nodes = %"PRIu32"\n", b->num_nodes);
  printf("   num_terms = %"PRIu32"\n", b->nterms);
  printf("   root node = %"PRIu32"\n", b->root);
  if (is_balanced(b, b->root, &h)) {
    printf("   b-height    = %"PRIu32"\n", h);
    printf("   full height = %"PRIu32"\n", tree_height(b));
  } else {
    printf("   not balanced\n");
  }
  printf("\n");


  // Try again after reset
  reset_rba_buffer(b);
  n = NUM_TESTS/2;
  i = n;
  while (i > 0) {
    i --;
    test_add(b, test[i]);
  }

  printf("\nAfter %"PRIu32" additions\n", n);
  printf("   num_nodes = %"PRIu32"\n", b->num_nodes);
  printf("   num_terms = %"PRIu32"\n", b->nterms);
  printf("   root node = %"PRIu32"\n", b->root);
  if (is_balanced(b, b->root, &h)) {
    printf("   b-height    = %"PRIu32"\n", h);
    printf("   full height = %"PRIu32"\n", tree_height(b));
  } else {
    printf("   not balanced\n");
  }
  printf("\n");

  i = n;
  while (i > 0) {
    i --;
    test_remove(b, test[i]);
  }

  printf("\nAfter %"PRIu32" removals\n", n);
  printf("   num_nodes = %"PRIu32"\n", b->num_nodes);
  printf("   num_terms = %"PRIu32"\n", b->nterms);
  printf("   root node = %"PRIu32"\n", b->root);
  if (is_balanced(b, b->root, &h)) {
    printf("   b-height    = %"PRIu32"\n", h);
    printf("   full height = %"PRIu32"\n", tree_height(b));
  } else {
    printf("   not balanced\n");
  }



  fflush(stdout);
}
Ejemplo n.º 16
0
int main(int argc, char **argv) {
    char workdir[1024];
    char workdirbasename[1024];
    char *nfsdir, *nfshost, *hosttemp=DEFAULT_HOSTTEMP;
    int c;
    int skipread=0, skipwrite=0, skipdir=0;

    while (1) {
        c=getopt(argc, argv, "o:t:l:f:c:");
        if (c == -1)
            break;

        switch(c) {
        case '?':
            usage(argv[0]);
        /* notreached */
        case 'o':
            if (!strcmp(optarg, "skipread")) {
                skipread=1;
            } else if (!strcmp(optarg, "skipwrite")) {
                skipwrite=1;
            } else if (!strcmp(optarg, "skipdir")) {
                skipdir=1;
            } else {
                printf("Unrecognized -o option: %s\n", optarg);
                usage(argv[0]);
            }
            break;
        case 't':
            hosttemp=strdup(optarg);
            break;
        case 'l':
            localtemp=strdup(optarg);
            break;
        case 'f':
            testfile=strdup(optarg);
            break;
        case 'c':
            testfiles=atoi(optarg);
            break;
        }
    }

    if (argc-optind != 2) {
        printf("Invalid number of required arguments\n");
        usage(argv[0]);
    }

    nfshost=argv[optind++];
    nfsdir=argv[optind++];

    /* Begin */

    test_statfs(nfsdir);

    /* Start with a fresh work area */
    sprintf(workdirbasename, "tmp%d", getpid());
    sprintf(workdir, "%s/%s", nfsdir, workdirbasename);
    printf("workdir is %s\n", workdir);

    test_mkdir(workdir);

    test_create(workdir);

    test_setattr(workdir);

    test_link(workdir);

    if (!skipread)
        test_read(nfsdir);

    if (!skipwrite)
        test_write(workdir, nfshost, hosttemp, workdirbasename);

    test_rename(workdir);

    if (!skipdir)
        test_readdir(workdir);

    test_remove(workdir);

    test_rmdir(workdir);

    return 0;

}
Ejemplo n.º 17
0
void test_hash_table(void)
{
    test_set_get();
    test_remove();
    test_resize();
}
Ejemplo n.º 18
0
int stress_test1(){
	int i;
	int j;
	int ret;
	int len;
	struct stat st;
	char buffer[64];
	int loc;

	void * f;
	i = 0;

	test_remove("log.txt");

	printf("append test %d...", i);
	fflush(stdout);
	for(i = 0; i < 1000; i++){
		if ( i % 50 == 0 ){
			printf("%d...", i);
			fflush(stdout);
		}

		f = test_open("log.txt", O_APPEND | O_RDWR | O_CREAT, 0666);
		if ( f == NULL ){
			perror("Failed to open file");
			return -1;
		}

		test_fstat(f, &st);
		loc = st.st_size;

		strcpy(buffer, "1234567890123456789012345678901234567890123456789\n");
		len = strlen(buffer);
		ret = test_write(f, loc, buffer, len);
		if ( ret != strlen(buffer) ){
			printf("Ret is %d == %d\n", ret, len);
		}
		if ( ret != strlen(buffer) ){
			perror("write failed");
			test_close(f);
			break;
		}

		fstat(fileno(f), &st);
		test_close(f);

		fflush(stdout);
		f = test_open("log.txt", O_RDONLY, 0);
		if ( f == NULL ){
			perror("Failed to open file");
			return -1;
		}

		loc = 0;

		j = 0;
		errno = 0;
		while(1){

			if ( test_read(f, loc, buffer, len) != len ){
				break;
			}

			loc += len;
			if ( strcmp(buffer, "1234567890123456789012345678901234567890123456789\n") != 0 ){
				printf("Bad comparison at line %d %d\n", j, (int)st.st_size);
				exit(1);
			}
			j++;
		}
		test_fstat(f, &st);
		test_close(f);
	}
	printf("passed\n");

	return 0;
}
Ejemplo n.º 19
0
int main(int c, char **v)
{
        test_remove();
	return 0;
}
Ejemplo n.º 20
0
int main(int argc, char* argv[]) {
  int errors = 0;

  test_insert(&errors);
  test_lookup(&errors);
  test_present(&errors);
  test_remove(&errors);
  test_destroy(&errors);

  if (errors == 0)
    printf("All tests passed\n");
  else
    printf("\nTests done with %d error(s)\n", errors);

  if (argc >= 2) {
    /* Check for correct invocation: */
    if (argc != 2) {
      printf("Usage: %s <N>\n"
             "Run test inserting a total of N items\n", argv[0]);
      return 1;
    }
    int N = atoi(argv[1]);
    if (N <= 0 || N > kMaxInsertions) {
      N = kMaxInsertions;
    }

    /* Create the hash table. */
    hash_table* ht = hash_create(hash_fn, hash_strcmp);

    /* First phase: insert some data. */
    printf("\nInsert phase:\n");
    char* k;
    int64_t* v;
    char* removed_key = NULL;
    int64_t* removed_value = NULL;
    for (int i = 0; i < N * 2; i++) {
      k = (char*) malloc(kBufferLength);
      snprintf(k, kBufferLength, "String %d", i % N);
      v = (int64_t*) malloc(sizeof(int64_t));
      *v = i;
      // The hash map takes ownership of the key and value:
      hash_insert(ht, k, v, (void**) &removed_key, (void**) &removed_value);
      if (removed_value != NULL) {
        printf("Replaced (%s, %" PRIi64 ") while inserting (%s, %" PRIi64 ")\n",
               removed_key, *removed_value, k, *v);
        free(removed_key);
        free(removed_value);
      } else {
        printf("Inserted (%s, %" PRIi64 ")\n", k, *v);
      }
    }

    /* Second phase: look up some data. */
    printf("\nLookup phase:\n");
    char strbuf[kBufferLength];
    for (int i = N - 1; i >= 0; i--) {
      snprintf(strbuf, kBufferLength, "String %d", i);
      if (!hash_lookup(ht, strbuf, (void**) &v)) {
        printf("Entry for %s not found\n", strbuf);
      } else {
        printf("%s -> %" PRIi64 "\n", strbuf, *v);
      }
    }

    /* Look up a key that hasn't been inserted: */
    if (!hash_lookup(ht, kNotFoundKey, (void**) &v)) {
      printf("Lookup of \"%s\" failed (as expected)\n", kNotFoundKey);
    } else {
      printf("%s -> %" PRIi64 " (unexpected!)\n", kNotFoundKey, *v);
    }

    /* Destroy the hash table and free things that we've allocated. Because
     * we allocated both the keys and the values, we instruct the hash map
     * to free both.
     */
    hash_destroy(ht, true, true);
  }
  return 0;
}