<commit_before>/* Copyright 2014 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <apr.h>
#include <apr_hash.h>
#include <apr_strings.h>

#include "MockHTTP.h"

/* Include here to test some internals */
#include "MockHTTP_private.h"

#include "tests.h"
#include "CuTest/CuTest.h"

#define CRLF "\r\n"

void *testSetupNoServer(void *dummy)
{
    return NULL;
}

void *testSetupWithHTTPServer(void *dummy)
{
    MockHTTP *mh;

    mh = mhInit();
    InitMockServers(mh)
      SetupServer(WithHTTP, WithID("server"), WithPort(30080))
    EndInit

    return mh;
}

void *testTeardown(void *baton)
{
    MockHTTP *mh = baton;

    mhCleanup(mh);

    return NULL;
}

static void test_mock_init(CuTest *tc)
{
    MockHTTP *mh = tc->testBaton;
    CuAssertPtrNotNull(tc, mh);
}

static void test_urlmatcher(CuTest *tc)
{
    MockHTTP *mh = tc->testBaton;
    mhRequestMatcher_t *rm;
    mhReqMatcherBldr_t *mp;
    mhRequest_t *req;

    rm = mhGivenRequest(mh, "GET");
    mp = mhMatchURLEqualTo(mh, "/index.html");
    CuAssertPtrNotNull(tc, mp);

    /* Create a fake request and check that the matcher works */
    req = _mhInitRequest(mh->pool);
    req->url = "/index.html";
    CuAssertIntEquals(tc, mp->matcher(mp, req), YES);

    req = _mhInitRequest(mh->pool);
    req->url = "/index2.html";
    CuAssertIntEquals(tc, mp->matcher(mp, req), NO);
}

static void test_urlnotmatcher(CuTest *tc)
{
    MockHTTP *mh = tc->testBaton;
    mhRequestMatcher_t *rm;
    mhReqMatcherBldr_t *mp;
    mhRequest_t *req;

    rm = mhGivenRequest(mh, "GET");
    mp = mhMatchURLNotEqualTo(mh, "/index2.html");
    CuAssertPtrNotNull(tc, mp);

    /* Create a fake request and check that the matcher works */
    req = _mhInitRequest(mh->pool);
    req->url = "/index.html";
    CuAssertIntEquals(tc, mp->matcher(mp, req), YES);
<commit_msg>Fix crash in the test suite on Linux: always pass the terminating NULL argument to mhGivenRequest.<commit_after>/* Copyright 2014 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <apr.h>
#include <apr_hash.h>
#include <apr_strings.h>

#include "MockHTTP.h"

/* Include here to test some internals */
#include "MockHTTP_private.h"

#include "tests.h"
#include "CuTest/CuTest.h"

#define CRLF "\r\n"

void *testSetupNoServer(void *dummy)
{
    return NULL;
}

void *testSetupWithHTTPServer(void *dummy)
{
    MockHTTP *mh;

    mh = mhInit();
    InitMockServers(mh)
      SetupServer(WithHTTP, WithID("server"), WithPort(30080))
    EndInit

    return mh;
}

void *testTeardown(void *baton)
{
    MockHTTP *mh = baton;

    mhCleanup(mh);

    return NULL;
}

static void test_mock_init(CuTest *tc)
{
    MockHTTP *mh = tc->testBaton;
    CuAssertPtrNotNull(tc, mh);
}

static void test_urlmatcher(CuTest *tc)
{
    MockHTTP *mh = tc->testBaton;
    mhRequestMatcher_t *rm;
    mhReqMatcherBldr_t *mp;
    mhRequest_t *req;

    rm = mhGivenRequest(mh, "GET", NULL);
    mp = mhMatchURLEqualTo(mh, "/index.html");
    CuAssertPtrNotNull(tc, mp);

    /* Create a fake request and check that the matcher works */
    req = _mhInitRequest(mh->pool);
    req->url = "/index.html";
    CuAssertIntEquals(tc, mp->matcher(mp, req), YES);

    req = _mhInitRequest(mh->pool);
    req->url = "/index2.html";
    CuAssertIntEquals(tc, mp->matcher(mp, req), NO);
}

static void test_urlnotmatcher(CuTest *tc)
{
    MockHTTP *mh = tc->testBaton;
    mhRequestMatcher_t *rm;
    mhReqMatcherBldr_t *mp;
    mhRequest_t *req;

    rm = mhGivenRequest(mh, "GET", NULL);
    mp = mhMatchURLNotEqualTo(mh, "/index2.html");
    CuAssertPtrNotNull(tc, mp);

    /* Create a fake request and check that the matcher works */
    req = _mhInitRequest(mh->pool);
    req->url = "/index.html";
    CuAssertIntEquals(tc, mp->matcher(mp, req), YES);

{'fraction_non_alphanumeric': 0.12258466652815292, 'fraction_numerical': 0.006233118637024725, 'mean_word_length': 3.6155321188878236, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, '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': '1418182', 'n_tokens_mistral': 1732, 'n_tokens_neox': 1633, 'n_words': 473}