<commit_before>#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <sys/time.h>

#include "hiredis.h"

/* The following line is our testing "framework" :) */
#define test_cond(_c) if(_c) printf("PASSED\n"); else {printf("FAILED\n"); fails++;}

static long long usec(void) {
    struct timeval tv;
    gettimeofday(&tv,NULL);
    return (((long long)tv.tv_sec)*1000000)+tv.tv_usec;
}

static void __connect(int *fd) {
    redisReply *reply = redisConnect(fd, "127.0.0.1", 6379);
    if (reply != NULL) {
        printf("Connection error: %s", reply->reply);
        exit(1);
    }
}

int main(void) {
    int fd;
    int i, fails = 0;
    long long t1, t2;
    redisReply *reply;
    __connect(&fd);

    /* test 0 */
    printf("#0 Returns I/O error when the connection is lost: ");
    reply = redisCommand(fd,"QUIT");
    test_cond(reply->type == REDIS_REPLY_ERROR &&
        strcasecmp(reply->reply,"i/o error") == 0);
    freeReplyObject(reply);
    __connect(&fd); /* reconnect */

    /* test 1 */
    printf("#1 Is able to deliver commands: ");
    reply = redisCommand(fd,"PING");
    test_cond(reply->type == REDIS_REPLY_STRING &&
        strcasecmp(reply->reply,"pong") == 0)

    /* Switch to DB 9 for testing, now that we know we can chat. */
    reply = redisCommand(fd,"SELECT 9");
    freeReplyObject(reply);

    /* Make sure the DB is emtpy */
    reply = redisCommand(fd,"DBSIZE");
    if (reply->type != REDIS_REPLY_INTEGER ||
        reply->integer != 0) {
        printf("Sorry DB 9 is not empty, test can not continue\n");
        exit(1);
    } else {
        printf("DB 9 is empty... test can continue\n");
    }
    freeReplyObject(reply);

    /* test 2 */
    printf("#2 Is a able to send commands verbatim: ");
    reply = redisCommand(fd,"SET foo bar");
    test_cond (reply->type == REDIS_REPLY_STRING &&<commit_msg>Free reply in test.c to make hiredis-test run cleanly on Valgrind<commit_after>#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <sys/time.h>

#include "hiredis.h"

/* The following line is our testing "framework" :) */
#define test_cond(_c) if(_c) printf("PASSED\n"); else {printf("FAILED\n"); fails++;}

static long long usec(void) {
    struct timeval tv;
    gettimeofday(&tv,NULL);
    return (((long long)tv.tv_sec)*1000000)+tv.tv_usec;
}

static void __connect(int *fd) {
    redisReply *reply = redisConnect(fd, "127.0.0.1", 6379);
    if (reply != NULL) {
        printf("Connection error: %s", reply->reply);
        exit(1);
    }
}

int main(void) {
    int fd;
    int i, fails = 0;
    long long t1, t2;
    redisReply *reply;
    __connect(&fd);

    /* test 0 */
    printf("#0 Returns I/O error when the connection is lost: ");
    reply = redisCommand(fd,"QUIT");
    test_cond(reply->type == REDIS_REPLY_ERROR &&
        strcasecmp(reply->reply,"i/o error") == 0);
    freeReplyObject(reply);
    __connect(&fd); /* reconnect */

    /* test 1 */
    printf("#1 Is able to deliver commands: ");
    reply = redisCommand(fd,"PING");
    test_cond(reply->type == REDIS_REPLY_STRING &&
        strcasecmp(reply->reply,"pong") == 0)
    freeReplyObject(reply);

    /* Switch to DB 9 for testing, now that we know we can chat. */
    reply = redisCommand(fd,"SELECT 9");
    freeReplyObject(reply);

    /* Make sure the DB is emtpy */
    reply = redisCommand(fd,"DBSIZE");
    if (reply->type != REDIS_REPLY_INTEGER ||
        reply->integer != 0) {
        printf("Sorry DB 9 is not empty, test can not continue\n");
        exit(1);
    } else {
        printf("DB 9 is empty... test can continue\n");
    }
    freeReplyObject(reply);

    /* test 2 */
    printf("#2 Is a able to send commands verbatim: ");
    reply = redisCommand(fd,"SET foo bar");
    test_cond (reply->type == REDIS_REPLY_STRING &&
{'fraction_non_alphanumeric': 0.15938637545501821, 'fraction_numerical': 0.018200728029121163, 'mean_word_length': 2.998960498960499, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5569795', 'n_tokens_mistral': 1361, 'n_tokens_neox': 1302, 'n_words': 353}