コード例 #1
0
ファイル: parser.c プロジェクト: CindyLinz/h3
int main() {
    FILE *fp = fopen("t/data/01-chrome-github.txt", "r");
    if (fp==NULL) {fputs ("File error",stderr); exit (1);}

    fseek(fp, 0 , SEEK_END);
    size_t fsize = ftell(fp);
    rewind(fp);
    
    char * buf = (char*) malloc(sizeof(char) * fsize);
    size_t s;

    s = fread(buf, sizeof(char), fsize, fp );

    if (s != fsize) {fputs ("Reading error",stderr); exit (3);}
    // printf("%zu\n%s", s, buf);

    RequestHeader *header;

    header = h3_request_header_new();
    h3_request_header_parse(header, buf, s);
    h3_request_header_free(header);



    test_header(SS("GET /method HTTP/1.1\r\n") );

    test_header(SS("GET /method\r\n"));

    test_header(SS("GET /path"));

    char *headerbody1 = "GET /method HTTP/1.1\r\n"
        "Host: github.com\r\n"
        "Connection: keep-alive\r\n"
        "Content-Length: 12611\r\n"
        "Cache-Control: no-cache\r\n"
        "\r\n"
        ;

    header = h3_request_header_new();
    h3_request_header_parse( header, SL(headerbody1));
    h3_request_header_free(header);

    /*
    while (feof(fp) == 0) {
        s = fread(buf, sizeof(char), flen, fp );
        printf("\n%zu\n%s", s, buf);
    }
    */
    /*
    while( (s = fread(buf, sizeof(char), BUFSIZE, fp )) > 0 ) {
        printf("%zu ==> %s\n", s, buf);
    }
    */
    fclose(fp);
    free (buf);
}
コード例 #2
0
void BinaryTreeTest::test_node_children_are_null_by_default() {
  test_header( "node children are null by default" );

  Node<int> node;

  print_test( node.left == NULL && node.right == NULL );
}
コード例 #3
0
void test_double_float() {
    test_header();

    double d = 2.2354e-10;
    float f = d;
    uint32_t i = 7821334;
    uchar_vec b;
    unsigned char *buffer = NULL;

    kv_init(b);
    dump_double(d, &b);
    buffer = b.a;
    fprintf(stderr, "%g == %g - ", d, load_double(&buffer));
    fprintf(stderr, "buffer used: %zu\n", buffer - b.a);

    kv_clear(b);
    dump_float(f, &b);
    buffer = b.a;
    fprintf(stderr, "%g == %g - ", d, load_float(&buffer));
    fprintf(stderr, "buffer used: %zu\n", buffer - b.a);

    kv_clear(b);
    dump_uint32(i, &b);
    buffer = b.a;
    fprintf(stderr, "%d == %d - ", i, load_uint32(&buffer));
    fprintf(stderr, "buffer used: %zu\n", buffer - b.a);

    kv_destroy(b);
}
コード例 #4
0
void BinaryTreeTest::test_node_creation_with_value() {
  test_header( "node creation with value" );

  int test_value = 42;
  Node<int> node( test_value );

  print_test( node.data == test_value );
}
コード例 #5
0
void BinaryTreeTest::test_tree_contains() {
  test_header( "tree insert and contains" );

  int something = 42;
  Tree<int> tree;
  tree.insert( something );

  print_test( tree.contains( something ) == true );
}
コード例 #6
0
void
assert_ptr(const char *file, int line, const char *a1, const char *a2,
    const void *aa1, const void *aa2, enum test_predicate pred)
{
	TEST_CHECK(aa1, aa2, pred);
	test_header(file, line, a1, a2, "PTR", pred);
	fprintf(stderr, "%12s = %p\n", a1, aa1);
	fprintf(stderr, "%12s = %p\n", a2, aa2);
	test_die();
}
コード例 #7
0
ファイル: queue_test.cpp プロジェクト: awmiller/a4nodequeue
void QueueTest::clear_queue() {
  test_header( "clearing the queue (isEmpty and dequeue)" );

  while( ! queue->isEmpty() ) {
    queue->dequeue();
  }

  // Makes the assumption that program would fail if loop fails
  print_test( true );
}
コード例 #8
0
void
assert_u32(const char *file, int line, const char *a1, const char *a2,
    u_int32_t aa1, u_int32_t aa2, enum test_predicate pred)
{
	TEST_CHECK(aa1, aa2, pred);
	test_header(file, line, a1, a2, "U32", pred);
	fprintf(stderr, "%12s = 0x%08x %u\n", a1, aa1, aa1);
	fprintf(stderr, "%12s = 0x%08x %u\n", a2, aa2, aa2);
	test_die();
}
コード例 #9
0
void BinaryTreeTest::test_tree_remove() {
  test_header( "tree remove" );

  int something = 42;
  Tree<int> tree;
  tree.insert( something );
  tree.remove( something );

  print_test( tree.contains( something ) == false );
}
コード例 #10
0
void
assert_u_int(const char *file, int line, const char *a1, const char *a2,
    u_int aa1, u_int aa2, enum test_predicate pred)
{
	TEST_CHECK(aa1, aa2, pred);
	test_header(file, line, a1, a2, "U_INT", pred);
	fprintf(stderr, "%12s = %u / 0x%x\n", a1, aa1, aa1);
	fprintf(stderr, "%12s = %u / 0x%x\n", a2, aa2, aa2);
	test_die();
}
コード例 #11
0
void
assert_size_t(const char *file, int line, const char *a1, const char *a2,
    size_t aa1, size_t aa2, enum test_predicate pred)
{
	TEST_CHECK(aa1, aa2, pred);
	test_header(file, line, a1, a2, "SIZE_T", pred);
	fprintf(stderr, "%12s = %zu\n", a1, aa1);
	fprintf(stderr, "%12s = %zu\n", a2, aa2);
	test_die();
}
コード例 #12
0
void
assert_long_long(const char *file, int line, const char *a1, const char *a2,
    long long aa1, long long aa2, enum test_predicate pred)
{
	TEST_CHECK(aa1, aa2, pred);
	test_header(file, line, a1, a2, "LONG LONG", pred);
	fprintf(stderr, "%12s = %lld / 0x%llx\n", a1, aa1, aa1);
	fprintf(stderr, "%12s = %lld / 0x%llx\n", a2, aa2, aa2);
	test_die();
}
コード例 #13
0
ファイル: test_helper.c プロジェクト: hshoexer/libopenssh
void
assert_mem(const char *file, int line, const char *a1, const char *a2,
    const void *aa1, const void *aa2, size_t l, enum test_predicate pred)
{
	int r = memcmp(aa1, aa2, l);

	TEST_CHECK_INT(r, pred);
	test_header(file, line, a1, a2, "STRING", pred);
	fprintf(stderr, "%12s = %s (len %zu)\n", a1, tohex(aa1, MIN(l, 256)), l);
	fprintf(stderr, "%12s = %s (len %zu)\n", a2, tohex(aa2, MIN(l, 256)), l);
	test_die();
}
コード例 #14
0
ファイル: test_helper.c プロジェクト: hshoexer/libopenssh
void
assert_string(const char *file, int line, const char *a1, const char *a2,
    const char *aa1, const char *aa2, enum test_predicate pred)
{
	int r = strcmp(aa1, aa2);

	TEST_CHECK_INT(r, pred);
	test_header(file, line, a1, a2, "STRING", pred);
	fprintf(stderr, "%12s = %s (len %zu)\n", a1, aa1, strlen(aa1));
	fprintf(stderr, "%12s = %s (len %zu)\n", a2, aa2, strlen(aa2));
	test_die();
}
コード例 #15
0
void
assert_u64(const char *file, int line, const char *a1, const char *a2,
    u_int64_t aa1, u_int64_t aa2, enum test_predicate pred)
{
	TEST_CHECK(aa1, aa2, pred);
	test_header(file, line, a1, a2, "U64", pred);
	fprintf(stderr, "%12s = 0x%016llx %llu\n", a1,
	    (unsigned long long)aa1, (unsigned long long)aa1);
	fprintf(stderr, "%12s = 0x%016llx %llu\n", a2,
	    (unsigned long long)aa2, (unsigned long long)aa2);
	test_die();
}
コード例 #16
0
void
assert_bignum(const char *file, int line, const char *a1, const char *a2,
    const BIGNUM *aa1, const BIGNUM *aa2, enum test_predicate pred)
{
	int r = BN_cmp(aa1, aa2);

	TEST_CHECK_INT(r, pred);
	test_header(file, line, a1, a2, "BIGNUM", pred);
	fprintf(stderr, "%12s = 0x%s\n", a1, BN_bn2hex(aa1));
	fprintf(stderr, "%12s = 0x%s\n", a2, BN_bn2hex(aa2));
	test_die();
}
コード例 #17
0
void
assert_char(const char *file, int line, const char *a1, const char *a2,
    char aa1, char aa2, enum test_predicate pred)
{
	char buf[8];

	TEST_CHECK(aa1, aa2, pred);
	test_header(file, line, a1, a2, "CHAR", pred);
	fprintf(stderr, "%12s = '%s' / 0x02%x\n", a1,
	    vis(buf, aa1, VIS_SAFE|VIS_NL|VIS_TAB|VIS_OCTAL, 0), aa1);
	fprintf(stderr, "%12s = '%s' / 0x02%x\n", a1,
	    vis(buf, aa2, VIS_SAFE|VIS_NL|VIS_TAB|VIS_OCTAL, 0), aa2);
	test_die();
}
コード例 #18
0
void test_run(const char *test_name, void (*test_fcn) (void), int do_test, int headeronly)
{
    static int test_set = 1;

    if (headeronly || do_test == 0 || do_test == test_set)
        test_header(test_name, test_set);

    if (!headeronly && (do_test == 0 || do_test == test_set)) {
        (*test_fcn) ();
        if (!QUIET)
            printf("\n");
    }
    test_set++;
}
コード例 #19
0
void BinaryTreeTest::test_tree_height() {
  test_header( "tree height" );

  Tree<int> tree;
  print_test( tree.height() == 0 );

  tree.insert( 10 );
  print_test( tree.height() == 1 );

  tree.insert( 15 );
  print_test( tree.height() == 2 );

  tree.insert( 5 );
  print_test( tree.height() == 2 );
}
コード例 #20
0
ファイル: test_stream_flags.c プロジェクト: AgamAgarwal/minix
int
main(void)
{
	// Valid headers
	known_flags.backward_size = 1024;
	for (lzma_check check = LZMA_CHECK_NONE;
			check <= LZMA_CHECK_ID_MAX; ++check) {
		test_header();
		test_footer();
	}

	// Invalid headers
	test_encode_invalid();
	test_decode_invalid();

	return 0;
}
コード例 #21
0
void
assert_string(const char *file, int line, const char *a1, const char *a2,
    const char *aa1, const char *aa2, enum test_predicate pred)
{
	int r;

	/* Verify pointers are not NULL */
	assert_ptr(file, line, a1, "NULL", aa1, NULL, TEST_NE);
	assert_ptr(file, line, a2, "NULL", aa2, NULL, TEST_NE);

	r = strcmp(aa1, aa2);
	TEST_CHECK_INT(r, pred);
	test_header(file, line, a1, a2, "STRING", pred);
	fprintf(stderr, "%12s = %s (len %zu)\n", a1, aa1, strlen(aa1));
	fprintf(stderr, "%12s = %s (len %zu)\n", a2, aa2, strlen(aa2));
	test_die();
}
コード例 #22
0
void BinaryTreeTest::test_tree_is_full() {
  test_header( "tree is full" );

  Tree<int> tree;
  tree.insert( 50 );
  tree.insert( 100 );
  tree.insert( 25 );
  tree.insert( 12 );
  tree.insert( 35 );
  tree.insert( 30 );
  tree.insert( 40 );

  print_test( tree.isFull() );

  tree.insert( 5 );

  print_test( ! tree.isFull() );
}
コード例 #23
0
ファイル: test_helper.c プロジェクト: hshoexer/libopenssh
void
assert_mem_filled(const char *file, int line, const char *a1,
    const void *aa1, u_char v, size_t l, enum test_predicate pred)
{
	size_t where = -1;
	int r = memvalcmp(aa1, v, l, &where);
	char tmp[64];

	if (l == 0)
		return;
	TEST_CHECK_INT(r, pred);
	test_header(file, line, a1, NULL, "MEM_ZERO", pred);
	fprintf(stderr, "%20s = %s%s (len %zu)\n", a1,
	    tohex(aa1, MIN(l, 20)), l > 20 ? "..." : "", l);
	snprintf(tmp, sizeof(tmp), "(%s)[%zu]", a1, where);
	fprintf(stderr, "%20s = 0x%02x (expected 0x%02x)\n", tmp,
	    ((u_char *)aa1)[where], v);
	test_die();
}
コード例 #24
0
void
assert_mem(const char *file, int line, const char *a1, const char *a2,
    const void *aa1, const void *aa2, size_t l, enum test_predicate pred)
{
	int r;

	if (l == 0)
		return;
	/* If length is >0, then verify pointers are not NULL */
	assert_ptr(file, line, a1, "NULL", aa1, NULL, TEST_NE);
	assert_ptr(file, line, a2, "NULL", aa2, NULL, TEST_NE);

	r = memcmp(aa1, aa2, l);
	TEST_CHECK_INT(r, pred);
	test_header(file, line, a1, a2, "STRING", pred);
	fprintf(stderr, "%12s = %s (len %zu)\n", a1, tohex(aa1, MIN(l, 256)), l);
	fprintf(stderr, "%12s = %s (len %zu)\n", a2, tohex(aa2, MIN(l, 256)), l);
	test_die();
}
コード例 #25
0
ファイル: gzio.c プロジェクト: TemmeR/grub2
/* Open a new decompressing object on the top of IO. If TRANSPARENT is true,
   even if IO does not contain data compressed by gzip, return a valid file
   object. Note that this function won't close IO, even if an error occurs.  */
static grub_file_t
grub_gzio_open (grub_file_t io)
{
  grub_file_t file;
  grub_gzio_t gzio = 0;

  file = (grub_file_t) grub_malloc (sizeof (*file));
  if (! file)
    return 0;

  gzio = grub_zalloc (sizeof (*gzio));
  if (! gzio)
    {
      grub_free (file);
      return 0;
    }

  gzio->file = io;

  file->device = io->device;
  file->offset = 0;
  file->data = gzio;
  file->read_hook = 0;
  file->fs = &grub_gzio_fs;
  file->not_easly_seekable = 1;

  if (! test_header (file))
    {
      grub_free (gzio);
      grub_free (file);
      grub_file_seek (io, 0);

      if (grub_errno == GRUB_ERR_BAD_FILE_TYPE)
	{
	  grub_errno = GRUB_ERR_NONE;
	  return io;
	}
    }

  return file;
}
コード例 #26
0
void
test_end_of_header (void)
{
    const gchar *packet;
    gsize packet_size;

    test_header();
    channel_free();

    reply_continue();

    cut_assert_true(milter_server_context_end_of_header(context));
    pump_all_events();
    milter_test_assert_state(END_OF_HEADER);
    milter_test_assert_status(NOT_CHANGE);

    milter_command_encoder_encode_end_of_header(encoder, &packet, &packet_size);
    milter_test_assert_packet(channel, packet, packet_size);

    cut_assert_equal_uint(0, n_message_processed);
}
コード例 #27
0
void test_forest_serialization() {
    test_header();

    ET_problem prob;
    ET_params params;
    ET_forest *forest, *forest2;
    uchar_vec buffer;
    unsigned char *mobile_buffer;
    float vector[] = {3, 1, 1, 6, 6, 2};

    kv_init(buffer);
    problem_init(&prob, big_vectors, big_labels);

    EXTRA_TREE_DEFAULT_REGR_PARAMS(prob, params);
    params.number_of_trees = 100;
    params.number_of_features_tested = 1;
    params.select_features_with_replacement = true;

    forest = ET_forest_build(&prob, &params);
    ET_forest_dump(forest, &buffer, true);
    fprintf(stderr, "forest dump: %zu bytes\n", kv_size(buffer));

    mobile_buffer = buffer.a;
    forest2 = ET_forest_load(&mobile_buffer);
    forest2->params = forest->params; // FIXME

    fprintf(stderr, "orig   forest pred: %g\n",
        ET_forest_predict(forest, vector));
    fprintf(stderr, "cloned forest pred: %g\n",
        ET_forest_predict(forest2, vector));

    kv_destroy(buffer);
    ET_forest_destroy(forest);
    ET_forest_destroy(forest2);
    free(forest);
    free(forest2);
}
コード例 #28
0
ファイル: queue_test.cpp プロジェクト: awmiller/a4nodequeue
void QueueTest::check_queue_dequeue() {
  test_header( "dequeue should be " + std::to_string( expected_front() ) );
  print_test( queue->dequeue() == expected_front() );

  test_index++;
}
コード例 #29
0
ファイル: queue_test.cpp プロジェクト: awmiller/a4nodequeue
void QueueTest::check_queue_front() {
  test_header( "queue front is " + std::to_string( expected_front() ) );
  print_test( queue->front() == expected_front() );
}
コード例 #30
0
ファイル: xzio.c プロジェクト: Spacy/grub-fuse
static grub_file_t
grub_xzio_open (grub_file_t io)
{
  grub_file_t file;
  grub_xzio_t xzio;

  file = (grub_file_t) grub_zalloc (sizeof (*file));
  if (!file)
    return 0;

  xzio = grub_zalloc (sizeof (*xzio));
  if (!xzio)
    {
      grub_free (file);
      return 0;
    }

  xzio->file = io;
  xzio->saved_offset = 0;

  file->device = io->device;
  file->offset = 0;
  file->data = xzio;
  file->read_hook = 0;
  file->fs = &grub_xzio_fs;
  file->size = GRUB_FILE_SIZE_UNKNOWN;
  file->not_easly_seekable = 1;

  if (grub_file_tell (xzio->file) != 0)
    grub_file_seek (xzio->file, 0);

  /* Allocated 64KiB for dictionary.
   * Decoder will relocate if bigger is needed.  */
  xzio->dec = xz_dec_init (1 << 16);
  if (!xzio->dec)
    {
      grub_free (file);
      grub_free (xzio);
      return 0;
    }

  xzio->buf.in = xzio->inbuf;
  xzio->buf.in_pos = 0;
  xzio->buf.in_size = 0;
  xzio->buf.out = xzio->outbuf;
  xzio->buf.out_pos = 0;
  xzio->buf.out_size = XZBUFSIZ;

  /* FIXME: don't test footer on not easily seekable files.  */
  if (!test_header (file) || !test_footer (file))
    {
      grub_errno = GRUB_ERR_NONE;
      grub_file_seek (io, 0);
      xz_dec_end (xzio->dec);
      grub_free (xzio);
      grub_free (file);

      return io;
    }

  return file;
}