Beispiel #1
0
void uri_free(uri_t *target) {
	mutable_string_free(&(target->uri));
	mutable_string_free(&(target->path));
	mutable_string_free(&(target->file));
	mutable_string_free(&(target->anchor));
	return;
}
Beispiel #2
0
void qs_entry_free(qs_entry_t *target) {
	if (!target) {
		return;
	}
	mutable_string_free(&(target->key));
	mutable_string_free(&(target->value));

	return;
}
void t_mutable_string_append_mutable_string(void) {
	mutable_string_t a;
	mutable_string_t b;

	CU_ASSERT_PTR_NOT_NULL(
		mutable_string_init(
			&a
		)
	);

	CU_ASSERT_PTR_NOT_NULL(
		mutable_string_init_with_value(
			&b, TEST_APPEND_TAIL
		)
	);

	CU_ASSERT_EQUAL(
		mutable_string_get_length(&a),
		0
	);

	CU_ASSERT_PTR_NOT_NULL(
		mutable_string_assign(
			&a,
			TEST_APPEND_HEAD
		)
	);

	CU_ASSERT_STRING_EQUAL(
		MUTSTR(&a),
		TEST_APPEND_HEAD
	);

	CU_ASSERT_PTR_NOT_NULL(
		mutable_string_append_mutable_string(
			&a,
			&b
		)
	);

	CU_ASSERT_STRING_EQUAL(
		MUTSTR(&a),
		TEST_APPEND_WHOLE
	);

	mutable_string_free(&a);
	mutable_string_free(&b);
}
void t_mutable_string_parse_int(void) {
	mutable_string_t a;

	CU_ASSERT_PTR_NOT_NULL(
		mutable_string_init_with_value(
			&a, TEST_STR_NUMERIC_1
		)
	);
	CU_ASSERT_EQUAL(
		mutable_string_parse_int(&a),
		123
	);
	CU_ASSERT_EQUAL(
		mutable_string_parse_long(&a),
		123
	);
	CU_ASSERT_EQUAL(
		mutable_string_parse_long_long(&a),
		123
	);
	
	CU_ASSERT_PTR_NOT_NULL(
		mutable_string_assign(
			&a, TEST_STR_NUMERIC_2
		)
	);
	CU_ASSERT_EQUAL(
		mutable_string_parse_double(&a),
		1.23
	);
	mutable_string_free(&a);
}
void t_mutable_string_copy(void) {
	mutable_string_t a;
	mutable_string_t b;

	CU_ASSERT_PTR_NOT_NULL(mutable_string_init(&a));
	CU_ASSERT_PTR_NOT_NULL(mutable_string_init(&b));

	CU_ASSERT_PTR_NOT_NULL(mutable_string_assign(&a, TEST_STR_1));
	CU_ASSERT_PTR_NOT_NULL(mutable_string_assign(&b, TEST_APPEND_WHOLE));

	CU_ASSERT_STRING_EQUAL(MUTSTR(&a), TEST_STR_1);
	CU_ASSERT_STRING_EQUAL(MUTSTR(&b), TEST_APPEND_WHOLE);

	CU_ASSERT_PTR_NOT_NULL(mutable_string_copy(&b, &a));

	CU_ASSERT_STRING_EQUAL(MUTSTR(&a), TEST_STR_1);
	CU_ASSERT_STRING_EQUAL(MUTSTR(&b), TEST_STR_1);

	mutable_string_free(&a);
	mutable_string_free(&b);
}
Beispiel #6
0
void url_free(url_t *target) {
	if (!target) {
		return;
	}

	mutable_string_free(&(target->url));
	endpoint_free(&(target->endpoint));
	uri_free(&(target->uri));
	qs_free(&(target->query_string));

	return;
}
Beispiel #7
0
continue_t template_finish(template_context_t *ctx) {
	mutable_string_free(&(ctx->buffer));

	// Close the stream if it's open.
	if (ctx->instream != NULL) {
		if (fclose(ctx->instream) == EOF) {
			template_set_error_to_errno(ctx, ERR_FATAL_YES, ERR_TPL_CONTENT_NO);
			return CONTINUE_NO;
		}
	}

	return CONTINUE_YES;
}
void t_mutable_string_char_at(void) {
/* 	fprintf(stderr, "t_mutable_string_char_at\n"); */
	mutable_string_t a;

	CU_ASSERT_PTR_NOT_NULL(
		mutable_string_init(
			&a
		)
	);

	CU_ASSERT_EQUAL(
		mutable_string_get_length(&a),
		0
	);

	CU_ASSERT_PTR_NOT_NULL(
		mutable_string_assign(
			&a,
			TEST_APPEND_WHOLE
		)
	);

	CU_ASSERT_EQUAL(
		mutable_string_char_at(&a, 2),
		'C'
	);

	CU_ASSERT_EQUAL(
		mutable_string_char_at(&a, -1),
		'D'
	);

	CU_ASSERT_EQUAL(
		mutable_string_char_at(&a, -4),
		'A'
	);

	CU_ASSERT_EQUAL(
		mutable_string_char_at(&a, -5),
		0
	);

	CU_ASSERT_EQUAL(
		mutable_string_get_error(),
		MUTABLE_STRING_ERROR_OUT_OF_RANGE
	);

	mutable_string_free(&a);
}
void t_mutable_string_init_with_value(void) {
	mutable_string_t a;

	CU_ASSERT_PTR_NOT_NULL(
		mutable_string_init_with_value(
			&a, TEST_STR_1
		)
	);
	CU_ASSERT_STRING_EQUAL(
		MUTSTR(&a),
		TEST_STR_1
	);

	mutable_string_free(&a);
}
static void test_mutable_string_copy(void)
{
	MutableString* ms = mutable_string_new("Ryan");
	expect(ms != NULL);
	expect(ms->capacity == 5);
	expect(ms->length == 4);
	expect(ms->buffer != NULL);
	expect(str_equal("Ryan", ms->buffer));
	expect(ms->buffer[ms->length] == '\0');

	MutableString* copy;
	copy = mutable_string_copy(ms);

	expect(copy != NULL);
	expect(copy->capacity == 5);
	expect(copy->length == 4);
	expect(copy->buffer != NULL);
	expect(str_equal("Ryan", copy->buffer));
	expect(copy->buffer[copy->length] == '\0');

	mutable_string_free(ms);
	mutable_string_free(copy);

}
void t_mutable_string_resize(void) {
	mutable_string_t a;
	mutable_string_t b;
	
	// Test a shrinking resize
	CU_ASSERT_PTR_NOT_NULL(
		mutable_string_init_with_value(
			&a, TEST_STR_1
		)
	);
	CU_ASSERT_STRING_EQUAL(
		MUTSTR(&a),
		TEST_STR_1
	);
	CU_ASSERT_PTR_NOT_NULL(
		mutable_string_resize(&a, TEST_STR_TRUNC_LEN));
	CU_ASSERT_STRING_EQUAL(
		MUTSTR(&a),
		TEST_STR_TRUNC
	);
	
	// Test a growing resize
	// Test a shrinking resize
	CU_ASSERT_PTR_NOT_NULL(
		mutable_string_init_with_value(
			&b, TEST_STR_1
		)
	);
	CU_ASSERT_STRING_EQUAL(
		MUTSTR(&b),
		TEST_STR_1
	);
	CU_ASSERT_PTR_NOT_NULL(
		mutable_string_resize(&a, TEST_STR_GROW_LEN));
	CU_ASSERT_STRING_EQUAL(
		MUTSTR(&b),
		TEST_STR_1
	);

	// Clean up
	mutable_string_free(&a);
}
void t_mutable_string_append_char(void) {
	mutable_string_t a;

	CU_ASSERT_PTR_NOT_NULL(
		mutable_string_init(
			&a
		)
	);

	CU_ASSERT_EQUAL(
		mutable_string_get_length(&a),
		0
	);

	CU_ASSERT_PTR_NOT_NULL(
		mutable_string_assign(
			&a,
			TEST_APPEND_HEAD
		)
	);

	CU_ASSERT_STRING_EQUAL(
		MUTSTR(&a),
		TEST_APPEND_HEAD
	);

	CU_ASSERT_PTR_NOT_NULL(
		mutable_string_append_char(
			&a,
			TEST_APPEND_CHAR
		)
	);

	CU_ASSERT_STRING_EQUAL(
		MUTSTR(&a),
		TEST_APPEND_CHAR_WHOLE
	);

	mutable_string_free(&a);
}
void t_mutable_string_assign(void) {
	mutable_string_t a;

	CU_ASSERT_PTR_NOT_NULL(
		mutable_string_init(
			&a
		)
	);
	CU_ASSERT_EQUAL(
		mutable_string_get_length(&a),
		0
	);

	CU_ASSERT_PTR_NOT_NULL(
		mutable_string_assign(
			&a,
			TEST_STR_1
		)
	);

	CU_ASSERT_STRING_EQUAL(
		MUTSTR(&a),
		TEST_STR_1
	);

	CU_ASSERT_PTR_NOT_NULL(
		mutable_string_assign(
			&a,
			TEST_STR_TRUNC
		)
	);

	CU_ASSERT_STRING_EQUAL(
		MUTSTR(&a),
		TEST_STR_TRUNC
	);

	mutable_string_free(&a);	
}
/* TESTS */
void t_mutable_string_init(void) {
	mutable_string_t a;

	CU_ASSERT_PTR_NOT_NULL(mutable_string_init(&a));
	mutable_string_free(&a);
}
Beispiel #15
0
void endpoint_free(endpoint_t *target) {
	mutable_string_free(&(target->endpoint));
	mutable_string_free(&(target->host));

	return;
}