<commit_before>
// -*- mode: c++; c-basic-offset:4 -*-

// This file is part of libdap, A C++ implementation of the OPeNDAP Data
// Access Protocol.

// Copyright (c) 2002,2003 OPeNDAP, Inc.
// Author: <NAME> <<EMAIL>>
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.

#include <cppunit/TextTestRunner.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/extensions/HelperMacros.h>

#include <cstring>
#include <iterator>
#include <string>
#include <algorithm>
#include <functional>

//#define DODS_DEBUG

#include "GNURegex.h"
#include "HTTPConnect.h"
#include "RCReader.h"

#include "debug.h"

#include "test_config.h"

using namespace CppUnit;
using namespace std;

namespace libdap
{

class HTTPConnectTest: public TestFixture {
  private:
    HTTPConnect * http;
    string localhost_url, localhost_pw_url, localhost_digest_pw_url;
    string etag;
    string lm;
    string netcdf_das_url;

  protected:
    bool re_match(Regex & r, const char *s) {
        return r.match(s, strlen(s)) == (int) strlen(s);
    }

    struct REMatch: public unary_function<const string &, bool> {
        Regex &d_re;
        REMatch(Regex &re) : d_re(re) {}
        ~REMatch() {}
        bool operator()(const string &str) {
            const char *s = str.c_str();
            return d_re.match(s, strlen(s)) == (int) strlen(s);
        }
    };

    // This is defined in HTTPConnect.cc but has to be defined here as well.
    // Don't know why... jhrg
    class HeaderMatch : public unary_function<const string &, bool> {
        const string &d_header;
        public:
            HeaderMatch(const string &header) : d_header(header) {}
            bool operator()(const string &arg) { return arg.find(d_header) == 0; }
    };

  public:
     HTTPConnectTest() {
    }
    ~HTTPConnectTest() {
    }

    void setUp() {
        putenv((char*)"DODS_CONF=cache-testsuite/dodsrc");
        http = new HTTPConnect(RCReader::instance());

        localhost_url = "http://test.opendap.org/test-304.html";

        // Two request header values that will generate a 304 response to the
        // above URL. The values below much match the etag and last-modified
        // time returned by the server. Run this test with DODS_DEBUG defined
        // to see the values it's returning.
        etag = "\"a10df-157-139c2680\""; // a10df-157-139c2680a
        lm = "Wed, 13 Jul 2005 19:32:26 GMT";

        localhost_pw_url =
            "http://jimg:dods_test@test.opendap.org/basic/page.txt";
        localhost_digest_pw_url =
            "http://jimg:dods_digest@test.opendap.org/digest/page.txt";
        netcdf_das_url =
            "http://test.opendap.org/dap/data/nc/fnoc1.nc.das";
    }

    void tearDown() {
        delete http;
        http = 0;
    }

    CPPUNIT_TEST_SUITE(HTTPConnectTest);
#if 0
    CPPUNIT_TEST(read_url_test);
    CPPUNIT_TEST(fetch_url_test);
    CPPUNIT_TEST(get_response_headers_test);
    CPPUNIT_TEST(server_version_test);
    CPPUNIT_TEST(type_test);
#endif
    CPPUNIT_TEST(cache_test);
#if 0
    CPPUNIT_TEST(set_accept_deflate_test);
    CPPUNIT_TEST(set_xdap_protocol_test);
    CPPUNIT_TEST(read_url_password_test);
    CPPUNIT_TEST(read_url_password_test2);
#endif
#if 0
    CPPUNIT_TEST(read_url_password_proxy_test);
#endif

    CPPUNIT_TEST_SUITE_END();

    void read_url_test() {
        vector < string > *resp_h = new vector < string >;;

        try {
            FILE *dump = fopen("/dev/null", "w");
            long status = http->read_url(localhost_url, dump, resp_h);
            CPPUNIT_ASSERT(status == 200);

            vector < string > request_h;

            // First test using a time with if-modified-since
            request_h.push_back(string("If-Modified-Since: ") + lm);
            status =<commit_msg>All tests back in.<commit_after>
// -*- mode: c++; c-basic-offset:4 -*-

// This file is part of libdap, A C++ implementation of the OPeNDAP Data
// Access Protocol.

// Copyright (c) 2002,2003 OPeNDAP, Inc.
// Author: <NAME> <<EMAIL>>
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.

#include <cppunit/TextTestRunner.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/extensions/HelperMacros.h>

#include <cstring>
#include <iterator>
#include <string>
#include <algorithm>
#include <functional>

//#define DODS_DEBUG

#include "GNURegex.h"
#include "HTTPConnect.h"
#include "RCReader.h"

#include "debug.h"

#include "test_config.h"

using namespace CppUnit;
using namespace std;

namespace libdap
{

class HTTPConnectTest: public TestFixture {
  private:
    HTTPConnect * http;
    string localhost_url, localhost_pw_url, localhost_digest_pw_url;
    string etag;
    string lm;
    string netcdf_das_url;

  protected:
    bool re_match(Regex & r, const char *s) {
        return r.match(s, strlen(s)) == (int) strlen(s);
    }

    struct REMatch: public unary_function<const string &, bool> {
        Regex &d_re;
        REMatch(Regex &re) : d_re(re) {}
        ~REMatch() {}
        bool operator()(const string &str) {
            const char *s = str.c_str();
            return d_re.match(s, strlen(s)) == (int) strlen(s);
        }
    };

    // This is defined in HTTPConnect.cc but has to be defined here as well.
    // Don't know why... jhrg
    class HeaderMatch : public unary_function<const string &, bool> {
        const string &d_header;
        public:
            HeaderMatch(const string &header) : d_header(header) {}
            bool operator()(const string &arg) { return arg.find(d_header) == 0; }
    };

  public:
     HTTPConnectTest() {
    }
    ~HTTPConnectTest() {
    }

    void setUp() {
        putenv((char*)"DODS_CONF=cache-testsuite/dodsrc");
        http = new HTTPConnect(RCReader::instance());

        localhost_url = "http://test.opendap.org/test-304.html";

        // Two request header values that will generate a 304 response to the
        // above URL. The values below much match the etag and last-modified
        // time returned by the server. Run this test with DODS_DEBUG defined
        // to see the values it's returning.
        etag = "\"a10df-157-139c2680\""; // a10df-157-139c2680a
        lm = "Wed, 13 Jul 2005 19:32:26 GMT";

        localhost_pw_url =
            "http://jimg:dods_test@test.opendap.org/basic/page.txt";
        localhost_digest_pw_url =
            "http://jimg:dods_digest@test.opendap.org/digest/page.txt";
        netcdf_das_url =
            "http://test.opendap.org/dap/data/nc/fnoc1.nc.das";
    }

    void tearDown() {
        delete http;
        http = 0;
    }

    CPPUNIT_TEST_SUITE(HTTPConnectTest);
#if 1
    CPPUNIT_TEST(read_url_test);
    CPPUNIT_TEST(fetch_url_test);
    CPPUNIT_TEST(get_response_headers_test);
    CPPUNIT_TEST(server_version_test);
    CPPUNIT_TEST(type_test);
#endif
    CPPUNIT_TEST(cache_test);
#if 1
    CPPUNIT_TEST(set_accept_deflate_test);
    CPPUNIT_TEST(set_xdap_protocol_test);
    CPPUNIT_TEST(read_url_password_test);
    CPPUNIT_TEST(read_url_password_test2);
#endif
#if 0
    CPPUNIT_TEST(read_url_password_proxy_test);
#endif

    CPPUNIT_TEST_SUITE_END();

    void read_url_test() {
        vector < string > *resp_h = new vector < string >;;

        try {
            FILE *dump = fopen("/dev/null", "w");
            long status = http->read_url(localhost_url, dump, resp_h);
            CPPUNIT_ASSERT(status == 200);

            vector < string > request_h;

            // First test using a time with if-modified-since
            request_h.push_back(string("If-Modified-Since: ") + lm);
            status =
{'fraction_non_alphanumeric': 0.11296519925348557, 'fraction_numerical': 0.019541113184762322, 'mean_word_length': 2.8325620530079934, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, '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': '3925775', 'n_tokens_mistral': 3094, 'n_tokens_neox': 2879, 'n_words': 825}