int main() { test_insert(); test_lookup(); test_remove(); return 0; }
int main(int argc, char **argv) { const struct test_suite *test = NULL; int test_nr = -1; int opt; /* TODO it must be agreed with shell maximum command length */ char test_name[100] = { 0 }; getopt_init(); while (-1 != (opt = getopt(argc, argv, "hn:t:i"))) { switch (opt) { case 'n': if ((optarg == NULL) || (!sscanf(optarg, "%d", &test_nr))) { printf("test -n: number expected\n"); print_usage(); return -EINVAL; } break; case 't': if ((optarg == NULL) || (!sscanf(optarg, "%s", test_name))) { printf("test -t: test name expected\n"); print_usage(); return -EINVAL; } break; case '?': case 'h': print_usage(); /* FALLTHROUGH */ default: return 0; } } if (test_nr != -1) { if (NULL == (test = get_test_by_nr(test_nr))) { return -ENOENT; } } if (*test_name != 0) { if (NULL == (test = test_lookup(test_name))) { printf("Can't find test named \"%s\"\n", test_name); return -ENOENT; } } if (NULL == test) { print_tests(); return 0; } return test_suite_run(test); }
int main(int argc, char** argv) { if (!parse_args(argc,argv)) { return 0; } plan_tests(16); Waypoints waypoints; ok(setup_waypoints(waypoints),"waypoint setup",0); unsigned size = waypoints.size(); ok(test_lookup(waypoints,3),"waypoint lookup",0); ok(!test_lookup(waypoints,5000),"waypoint bad lookup",0); ok(test_nearest(waypoints),"waypoint nearest",0); ok(test_nearest_landable(waypoints),"waypoint nearest landable",0); ok(test_location(waypoints,true),"waypoint location good",0); ok(test_location(waypoints,false),"waypoint location bad",0); ok(test_range(waypoints,100)==1,"waypoint visit range 100m",0); ok(test_radius(waypoints,100)==1,"waypoint radius 100m",0); ok(test_range(waypoints,500000)== waypoints.size(),"waypoint range 500000m",0); ok(test_radius(waypoints,25000)<= test_range(waypoints,25000),"waypoint radius<range",0); // test clear waypoints.clear(); ok(waypoints.size()==0,"waypoint clear",0); setup_waypoints(waypoints); ok(size == waypoints.size(),"waypoint setup after clear",0); ok(test_copy(waypoints),"waypoint copy",0); ok(test_erase(waypoints,3),"waypoint erase",0); ok(test_replace(waypoints,4),"waypoint replace",0); return exit_status(); }
int main (int argc, char *argv[]) { /* run tests in legacy (pre-session support) mode */ setenv ("UPSTART_NO_SESSIONS", "1", 1); test_add (); test_append (); test_set (); test_lookup (); test_get (); test_getn (); test_all_valid (); test_expand (); return 0; }
int main (int argc, char *argv[]) { flux_t *h; int ch; uint32_t nodeid = FLUX_NODEID_ANY; test_t *t; log_init ("treq"); while ((ch = getopt_long (argc, argv, OPTIONS, longopts, NULL)) != -1) { switch (ch) { case 'h': /* --help */ usage (); break; case 'r': /* --rank N */ nodeid = strtoul (optarg, NULL, 10); break; default: usage (); break; } } if (optind == argc) usage (); if (!(t = test_lookup (argv[optind]))) usage (); if (!(h = flux_open (NULL, 0))) log_err_exit ("flux_open"); t->fun (h, nodeid); flux_close (h); log_fini (); return 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; }
int main(void) { struct dirent *de; unsigned int fd, target_fd; if (unshare(CLONE_FILES) == -1) return 1; /* Wipe fdtable. */ do { DIR *d; d = opendir("/proc/self/fd"); if (!d) return 1; de = xreaddir(d); assert(de->d_type == DT_DIR); assert(streq(de->d_name, ".")); de = xreaddir(d); assert(de->d_type == DT_DIR); assert(streq(de->d_name, "..")); next: de = xreaddir(d); if (de) { unsigned long long fd_ull; unsigned int fd; char *end; assert(de->d_type == DT_LNK); fd_ull = xstrtoull(de->d_name, &end); assert(*end == '\0'); assert(fd_ull == (unsigned int)fd_ull); fd = fd_ull; if (fd == dirfd(d)) goto next; close(fd); } closedir(d); } while (de); /* Now fdtable is clean. */ fd = open("/", O_PATH|O_DIRECTORY); assert(fd == 0); test_lookup(fd); close(fd); /* Clean again! */ fd = open("/", O_PATH|O_DIRECTORY); assert(fd == 0); /* Default RLIMIT_NOFILE-1 */ target_fd = 1023; while (target_fd > 0) { if (dup2(fd, target_fd) == target_fd) break; target_fd /= 2; } assert(target_fd > 0); close(fd); test_lookup(target_fd); close(target_fd); return 0; }