void test_nghttp2_session_open_idle_stream(void) {
  nghttp2_session *session;
  nghttp2_session_callbacks callbacks;
  nghttp2_stream *stream;
  nghttp2_stream *opened_stream;
  nghttp2_priority_spec pri_spec;
  nghttp2_frame frame;

  memset(&callbacks, 0, sizeof(nghttp2_session_callbacks));

  nghttp2_session_server_new(&session, &callbacks, NULL);

  nghttp2_priority_spec_init(&pri_spec, 0, 3, 0);

  nghttp2_frame_priority_init(&frame.priority, 1, &pri_spec);

  CU_ASSERT(0 == nghttp2_session_on_priority_received(session, &frame));

  stream = nghttp2_session_get_stream_raw(session, 1);

  CU_ASSERT(NGHTTP2_STREAM_IDLE == stream->state);
  CU_ASSERT(NULL == stream->closed_prev);
  CU_ASSERT(NULL == stream->closed_next);
  CU_ASSERT(1 == session->num_idle_streams);
  CU_ASSERT(session->idle_stream_head == stream);
  CU_ASSERT(session->idle_stream_tail == stream);

  opened_stream = open_recv_stream2(session, 1, NGHTTP2_STREAM_OPENING);

  CU_ASSERT(stream == opened_stream);
  CU_ASSERT(NGHTTP2_STREAM_OPENING == stream->state);
  CU_ASSERT(0 == session->num_idle_streams);
  CU_ASSERT(NULL == session->idle_stream_head);
  CU_ASSERT(NULL == session->idle_stream_tail);

  nghttp2_frame_priority_free(&frame.priority);

  nghttp2_session_del(session);
}
void test_nghttp2_session_open_idle_stream(void) {
  nghttp2_session *session;
  nghttp2_session_callbacks callbacks;
  nghttp2_stream *stream;
  nghttp2_stream *opened_stream;
  nghttp2_priority_spec pri_spec;
  nghttp2_frame frame;

  memset(&callbacks, 0, sizeof(nghttp2_session_callbacks));

  nghttp2_session_server_new(&session, &callbacks, NULL);

  nghttp2_priority_spec_init(&pri_spec, 0, 3, 0);

  nghttp2_frame_priority_init(&frame.priority, 1, &pri_spec);

  CU_ASSERT(0 == nghttp2_session_on_priority_received(session, &frame));

  stream = nghttp2_session_get_stream_raw(session, 1);

  CU_ASSERT(NGHTTP2_STREAM_IDLE == stream->state);
  CU_ASSERT(NULL == stream->closed_prev);
  CU_ASSERT(NULL == stream->closed_next);
  CU_ASSERT(1 == session->num_idle_streams);
  CU_ASSERT(session->idle_stream_head == stream);
  CU_ASSERT(session->idle_stream_tail == stream);

  opened_stream = open_recv_stream2(session, 1, NGHTTP2_STREAM_OPENING);

  CU_ASSERT(stream == opened_stream);
  CU_ASSERT(NGHTTP2_STREAM_OPENING == stream->state);
  CU_ASSERT(0 == session->num_idle_streams);
  CU_ASSERT(NULL == session->idle_stream_head);
  CU_ASSERT(NULL == session->idle_stream_tail);

  nghttp2_frame_priority_free(&frame.priority);

  nghttp2_session_del(session);
}