Example #1
0
cParseRole *cparse_role_with_name(const char *name) {
	cParseRole *obj = cparse_object_new();

	obj->className = strdup(CPARSE_CLASS_ROLE);

	obj->urlPath = strdup(CPARSE_ROLES_PATH);

	cparse_object_set_string(obj, CPARSE_KEY_NAME, name);

	return obj;
}
Example #2
0
cParseObject *cparse_new_test_object(const char *name, int score)
{
    cParseObject *obj = NULL;

    obj = cparse_object_with_class_name(TEST_CLASS);

    cparse_object_set_string(obj, "playerName", name);
    cparse_object_set_number(obj, "score", score);

    cparse_add_test_object(obj);

    return obj;
}
Example #3
0
int main(int argc, char *argv[])
{
	char *buffer = NULL;
	size_t bufsiz = 0;
	ssize_t bytes_read = 0;
	FILE *stream = stdin;
	
	union {
		cParseNumber num;
		double real;
		char str[2048];
	} var;

	puts("AFL test harness");
	
	read_env_config();

	read_test_config();
	
	if (!is_valid_config()) {
		die("test configuration is not valid");
	}
	obj = cparse_object_with_class_name("Fuzzer");	

	atexit(harness_cleanup);

	while((bytes_read = getline(&buffer, &bufsiz, stream)) >= 0) {
		char key[128];
		size_t len = strlen(buffer);

		if (len > 0) {
			buffer[len-1] = '\0';
		}

		if (buffer[0] == '\0') {
			break;
		}

		if (sscanf(buffer, "%s = %d", key, &var.num) == 2) {
			cparse_object_set_number(obj, key, var.num);
		} else if (sscanf(buffer, "%s = %lf", key, &var.real) == 2) {
			cparse_object_set_real(obj, key, var.num);
		} else if (sscanf(buffer, "%s = %[^\n]", key, var.str) == 2) {
			cparse_object_set_string(obj, key, var.str);
		} else if (sscanf(buffer, "%s = %s", key, var.str) == 2 && !strcmp(var.str, "true")) {
			cparse_object_set_bool(obj, key, true);
		} else if (sscanf(buffer, "%s = %s", key, var.str) == 2 && !strcmp(var.str, "false")) {
			cparse_object_set_bool(obj, key, false);
		} else if (sscanf(buffer, "%s == %[^\n]", key, var.str) == 2) {
			if (harness_compare_string(key, var.str)) {
				exit(1);
			}
		} else if (sscanf(buffer, "%s != %[^\n]", key, var.str) == 2) {
			if (!harness_compare_string(key, var.str)) {
				exit(1);
			}
		} else if (sscanf(buffer, "%s == %d", key, &var.num) == 2) {
			if (harness_compare_number(key, var.num)) {
				exit(1);
			}
		} else if (sscanf(buffer, "%s != %d", key, &var.num) == 2) {
			if (!harness_compare_number(key, var.num)) {
				exit(1);
			}
		} else if (sscanf(buffer, "%s == %lf", key, &var.real) == 2) {
			if (harness_compare_real(key, var.real, MAX_REL_ERR)) {
				exit(1);
			}
		} else if (sscanf(buffer, "%s != %lf", key, &var.real) == 2) {
			if (!harness_compare_real(key, var.real, MAX_REL_ERR)) {
				exit(1);
			}
		} else if ((sscanf(buffer, "%s == %s", key, var.str) == 2 && !strcmp(var.str, "true"))  
				|| (sscanf(buffer, "%s != %s", key, var.str) == 2 && !strcmp(var.str, "false"))) {
			if (harness_compare_bool(key, true)) {
				exit(1);
			}
		} else if ((sscanf(buffer, "%s == %s", key, var.str) == 2 && !strcmp(var.str, "false"))
				|| (sscanf(buffer, "%s != %s", key, var.str) == 2 && !strcmp(var.str, "true"))) {
			if (harness_compare_bool(key, false)) {
				exit(1);
			}
		} else if (sscanf(buffer, "rem %s", key) == 1) {
			if (!cparse_object_contains(obj, key)) {
				printf("object does not contain key (%s)\n", key);
			} else {
				cparse_object_remove(obj, key);
			}
		} else if (!strcmp(buffer, "save")) {
			if (!cparse_object_save(obj, &error)) {
				puts(cparse_error_message(error));
				cparse_error_free(error);
				error = NULL;
			}
		} else if (!strcmp(buffer, "delete")) {
			if (!cparse_object_delete(obj, &error)) {
				puts(cparse_error_message(error));
				cparse_error_free(error);
				error = NULL;
			}
		} else if (!strcmp(buffer, "refresh")) {
			if (!cparse_object_refresh(obj, &error)) {
				puts(cparse_error_message(error));
				cparse_error_free(error);
				error = NULL;
			}
		} else if (!strcmp(buffer, "fetch")) {
			if (!cparse_object_fetch(obj, &error)) {
				puts(cparse_error_message(error));
				cparse_error_free(error);
				error = NULL;
			}
		} else {
			printf("No op (%s) in AFL harness\n", buffer);
		}
	}

	return 0;
}