Ejemplo n.º 1
0
static void test_delenv(CuTest *tc)
{
    char *value;
    apr_status_t rv;

    if (!have_env_set) {
        CuNotImpl(tc, "apr_env_set (skip test for apr_env_delete)");
        return;
    }

    rv = apr_env_delete(TEST_ENVVAR_NAME, p);
    have_env_del = (rv != APR_ENOTIMPL);
    if (!have_env_del) {
        CuNotImpl(tc, "apr_env_delete");
        return;
    }
    apr_assert_success(tc, "delete environment variable", rv);

    if (!have_env_get) {
        CuNotImpl(tc, "apr_env_get (skip sanity check for apr_env_delete)");
        return;
    }
    rv = apr_env_get(&value, TEST_ENVVAR_NAME, p);
    CuAssertIntEquals(tc, APR_ENOENT, rv);
}
Ejemplo n.º 2
0
	void testSrchWildcard(CuTest *tc ){
#ifdef NO_WILDCARD_QUERY
		CuNotImpl(tc,_T("Wildcard"));
#else
		CuAssert(tc,_T("Searcher was not open"),s!=NULL);
		//testWildcard
		_TestSearchesRun(tc, &a,s, _T("term*") );
		_TestSearchesRun(tc, &a,s, _T("term*^2") );
		_TestSearchesRun(tc, &a,s, _T("term~") );
		_TestSearchesRun(tc, &a,s, _T("term^2~") );
		_TestSearchesRun(tc, &a,s, _T("term~^2") );
		_TestSearchesRun(tc, &a,s, _T("term*germ") );
		_TestSearchesRun(tc, &a,s, _T("term*germ^3") );

		//test problem reported by Gary Mangum
		BooleanQuery* bq = _CLNEW BooleanQuery();
		Term* upper = _CLNEW Term(_T("contents"),_T("0105"));
		Term* lower = _CLNEW Term(_T("contents"),_T("0105"));
		RangeQuery* rq=_CLNEW RangeQuery(lower,upper,true);
		bq->add(rq,true,true,false);
		_CLDECDELETE(upper);
		_CLDECDELETE(lower);

		Term* prefix = _CLNEW Term(_T("contents"),_T("reuters21578"));
		PrefixQuery* pq = _CLNEW PrefixQuery(prefix);
		_CLDECDELETE(prefix);
		bq->add(pq,true,true,false);

		Hits* h = NULL;
		try{
			h = s->search( bq );
		}_CLFINALLY(
		_CLDELETE(h);
		_CLDELETE(bq);
		);
Ejemplo n.º 3
0
static void corkable(CuTest *tc)
{
#if !APR_HAVE_CORKABLE_TCP
    CuNotImpl(tc, "TCP isn't corkable");
#else
    apr_status_t rv;
    apr_int32_t ck;

    rv = apr_socket_opt_set(sock, APR_TCP_NODELAY, 1);
    CuAssertIntEquals(tc, APR_SUCCESS, rv);

    rv = apr_socket_opt_get(sock, APR_TCP_NODELAY, &ck);
    CuAssertIntEquals(tc, APR_SUCCESS, rv);
    CuAssertIntEquals(tc, 1, ck);

    rv = apr_socket_opt_set(sock, APR_TCP_NOPUSH, 1);
    CuAssertIntEquals(tc, APR_SUCCESS, rv);

    rv = apr_socket_opt_get(sock, APR_TCP_NOPUSH, &ck);
    CuAssertIntEquals(tc, APR_SUCCESS, rv);
    CuAssertIntEquals(tc, 1, ck);

    rv = apr_socket_opt_get(sock, APR_TCP_NODELAY, &ck);
    CuAssertIntEquals(tc, APR_SUCCESS, rv);
    CuAssertIntEquals(tc, 0, ck);

    rv = apr_socket_opt_set(sock, APR_TCP_NOPUSH, 0);
    CuAssertIntEquals(tc, APR_SUCCESS, rv);

    rv = apr_socket_opt_get(sock, APR_TCP_NODELAY, &ck);
    CuAssertIntEquals(tc, APR_SUCCESS, rv);
    CuAssertIntEquals(tc, 1, ck);
#endif
}
Ejemplo n.º 4
0
static void test_exp_lt(CuTest *tc)
{
    apr_status_t rv;
    apr_time_exp_t xt;
    time_t posix_secs = (time_t)apr_time_sec(now);
    struct tm *posix_exp = localtime(&posix_secs);

    rv = apr_time_exp_lt(&xt, now);
    if (rv == APR_ENOTIMPL) {
        CuNotImpl(tc, "apr_time_exp_lt");
    }
    CuAssertTrue(tc, rv == APR_SUCCESS);

#define CHK_FIELD(f) \
    CuAssert(tc, "Mismatch in " #f, posix_exp->f == xt.f)

    CHK_FIELD(tm_sec);
    CHK_FIELD(tm_min);
    CHK_FIELD(tm_hour);
    CHK_FIELD(tm_mday);
    CHK_FIELD(tm_mon);
    CHK_FIELD(tm_year);
    CHK_FIELD(tm_wday);
    CHK_FIELD(tm_yday);
    CHK_FIELD(tm_isdst);
#undef CHK_FIELD
}
Ejemplo n.º 5
0
/** http://issues.apache.org/bugzilla/show_bug.cgi?id=40764 */
static void test_emptyenv(CuTest *tc)
{
    char *value;
    apr_status_t rv;

    if (!(have_env_set && have_env_get)) {
        CuNotImpl(tc, "apr_env_set (skip test_emptyenv)");
        return;
    }
    /** Set empty string and test that rv != ENOENT) */
    rv = apr_env_set(TEST_ENVVAR_NAME, "", p);
    apr_assert_success(tc, "set environment variable", rv);
    rv = apr_env_get(&value, TEST_ENVVAR_NAME, p);
    apr_assert_success(tc, "get environment variable", rv);
    CuAssertStrEquals(tc, "", value);

    if (!have_env_del) {
        CuNotImpl(tc, "apr_env_del (skip recycle test_emptyenv)");
        return;
    }
    /** Delete and retest */
    rv = apr_env_delete(TEST_ENVVAR_NAME, p);
    apr_assert_success(tc, "delete environment variable", rv);
    rv = apr_env_get(&value, TEST_ENVVAR_NAME, p);
    CuAssertIntEquals(tc, APR_ENOENT, rv);

    /** Set second variable + test*/
    rv = apr_env_set(TEST_ENVVAR2_NAME, TEST_ENVVAR_VALUE, p);
    apr_assert_success(tc, "set second environment variable", rv);
    rv = apr_env_get(&value, TEST_ENVVAR2_NAME, p);
    apr_assert_success(tc, "get second environment variable", rv);
    CuAssertStrEquals(tc, TEST_ENVVAR_VALUE, value);

    /** Finally, test ENOENT (first variable) followed by second != ENOENT) */
    rv = apr_env_get(&value, TEST_ENVVAR_NAME, p);
    CuAssertIntEquals(tc, APR_ENOENT, rv);
    rv = apr_env_get(&value, TEST_ENVVAR2_NAME, p);
    apr_assert_success(tc, "verify second environment variable", rv);
    CuAssertStrEquals(tc, TEST_ENVVAR_VALUE, value);

    /** Cleanup */
    apr_env_delete(TEST_ENVVAR2_NAME, p);
}
Ejemplo n.º 6
0
static void test_getenv(CuTest *tc)
{
    char *value;
    apr_status_t rv;

    if (!have_env_set) {
        CuNotImpl(tc, "apr_env_set (skip test for apr_env_get)");
        return;
    }

    rv = apr_env_get(&value, TEST_ENVVAR_NAME, p);
    have_env_get = (rv != APR_ENOTIMPL);
    if (!have_env_get) {
        CuNotImpl(tc, "apr_env_get");
        return;
    }
    apr_assert_success(tc, "get environment variable", rv);
    CuAssertStrEquals(tc, TEST_ENVVAR_VALUE, value);
}
Ejemplo n.º 7
0
static void username(CuTest *tc)
{
    apr_uid_t uid;
    apr_gid_t gid;
    apr_uid_t retreived_uid;
    apr_gid_t retreived_gid;
    apr_status_t rv;
    char *uname = NULL;

    rv = apr_uid_current(&uid, &gid, p);
    CuAssertIntEquals(tc, APR_SUCCESS, rv);

    rv = apr_uid_name_get(&uname, uid, p);
    CuAssertIntEquals(tc, APR_SUCCESS, rv);
    CuAssertPtrNotNull(tc, uname);

    rv = apr_uid_get(&retreived_uid, &retreived_gid, uname, p);
    CuAssertIntEquals(tc, APR_SUCCESS, rv);

    CuAssertIntEquals(tc, APR_SUCCESS, apr_uid_compare(uid, retreived_uid));
#ifdef WIN32
    /* ### this fudge was added for Win32 but makes the test return NotImpl
     * on Unix if run as root, when !gid is also true. */
    if (!gid || !retreived_gid) {
        /* The function had no way to recover the gid (this would have been
         * an ENOTIMPL if apr_uid_ functions didn't try to double-up and
         * also return apr_gid_t values, which was bogus.
         */
        if (!gid) {
            CuNotImpl(tc, "Groups from apr_uid_current");
        }
        else {
            CuNotImpl(tc, "Groups from apr_uid_get");
        }        
    }
    else {
#endif
        CuAssertIntEquals(tc, APR_SUCCESS, apr_gid_compare(gid, retreived_gid));
#ifdef WIN32
    }
#endif
}
Ejemplo n.º 8
0
static void test_setenv(CuTest *tc)
{
    apr_status_t rv;

    rv = apr_env_set(TEST_ENVVAR_NAME, TEST_ENVVAR_VALUE, p);
    have_env_set = (rv != APR_ENOTIMPL);
    if (!have_env_set) {
        CuNotImpl(tc, "apr_env_set");
        return;
    }
    apr_assert_success(tc, "set environment variable", rv);
}
Ejemplo n.º 9
0
static void test_rfcstr(CuTest *tc)
{
    apr_status_t rv;
    char str[STR_SIZE];

    rv = apr_rfc822_date(str, now);
    if (rv == APR_ENOTIMPL) {
        CuNotImpl(tc, "apr_rfc822_date");
    }
    CuAssertTrue(tc, rv == APR_SUCCESS);
    CuAssertStrEquals(tc, "Sat, 14 Sep 2002 19:05:36 GMT", str);
}
Ejemplo n.º 10
0
static void test_gmtstr(CuTest *tc)
{
    apr_status_t rv;
    apr_time_exp_t xt;

    rv = apr_time_exp_gmt(&xt, now);
    if (rv == APR_ENOTIMPL) {
        CuNotImpl(tc, "apr_time_exp_gmt");
    }
    CuAssertTrue(tc, rv == APR_SUCCESS);
    CuAssertStrEquals(tc, "2002-08-14 19:05:36.186711 +0000 [257 Sat]", 
                      print_time(p, &xt));
}
Ejemplo n.º 11
0
void apr_assert_success(CuTest* tc, const char* context, apr_status_t rv)
{
    if (rv == APR_ENOTIMPL) {
        CuNotImpl(tc, context);
    }

    if (rv != APR_SUCCESS) {
        char buf[STRING_MAX], ebuf[128];
        sprintf(buf, "%s (%d): %s\n", context, rv,
                apr_strerror(rv, ebuf, sizeof ebuf));
        CuFail(tc, buf);
    }
}
Ejemplo n.º 12
0
	void testSrchSlop(CuTest *tc ){
#ifdef NO_FUZZY_QUERY
		CuNotImpl(tc,_T("Fuzzy"));
#else
		CuAssert(tc,_T("Searcher was not open"),s!=NULL);
		//test slop
		_TestSearchesRun(tc, &a,s, _T("\"term germ\"~2") );
		_TestSearchesRun(tc, &a,s, _T("\"term germ\"~2 flork") );
		_TestSearchesRun(tc, &a,s, _T("\"term\"~2") );
		_TestSearchesRun(tc, &a,s, _T("\" \"~2 germ") );
		_TestSearchesRun(tc, &a,s, _T("\"term germ\"~2^2") );
#endif
	}
Ejemplo n.º 13
0
static void test_strftimeoffset(CuTest *tc)
{
    apr_status_t rv;
    apr_time_exp_t xt;
    char str[STR_SIZE];
    apr_size_t sz;
    apr_int32_t hr_off = -5 * 3600; /* 5 hours in seconds */

    apr_time_exp_tz(&xt, now, hr_off);
    rv = apr_strftime(str, &sz, STR_SIZE, "%T", &xt);
    if (rv == APR_ENOTIMPL) {
        CuNotImpl(tc, "apr_strftime");
    }
    CuAssertTrue(tc, rv == APR_SUCCESS);
}
Ejemplo n.º 14
0
static void test_imp_gmt(CuTest *tc)
{
    apr_status_t rv;
    apr_time_exp_t xt;
    apr_time_t imp;

    rv = apr_time_exp_gmt(&xt, now);
    CuAssertTrue(tc, rv == APR_SUCCESS);
    rv = apr_time_exp_gmt_get(&imp, &xt);
    if (rv == APR_ENOTIMPL) {
        CuNotImpl(tc, "apr_time_exp_gmt_get");
    }
    CuAssertTrue(tc, rv == APR_SUCCESS);
    CuAssertTrue(tc, now == imp);
}
Ejemplo n.º 15
0
static void test_strftimesmall(CuTest *tc)
{
    apr_status_t rv;
    apr_time_exp_t xt;
    char str[STR_SIZE];
    apr_size_t sz;

    rv = apr_time_exp_gmt(&xt, now);
    rv = apr_strftime(str, &sz, STR_SIZE, "%T", &xt);
    if (rv == APR_ENOTIMPL) {
        CuNotImpl(tc, "apr_strftime");
    }
    CuAssertTrue(tc, rv == APR_SUCCESS);
    CuAssertStrEquals(tc, "19:05:36", str);
}
Ejemplo n.º 16
0
static void test_strftime(CuTest *tc)
{
    apr_status_t rv;
    apr_time_exp_t xt;
    char *str = NULL;
    apr_size_t sz;

    rv = apr_time_exp_gmt(&xt, now);
    str = apr_palloc(p, STR_SIZE + 1);
    rv = apr_strftime(str, &sz, STR_SIZE, "%R %A %d %B %Y", &xt);
    if (rv == APR_ENOTIMPL) {
        CuNotImpl(tc, "apr_strftime");
    }
    CuAssertTrue(tc, rv == APR_SUCCESS);
    CuAssertStrEquals(tc, "19:05 Saturday 14 September 2002", str);
}
Ejemplo n.º 17
0
static void test_ctime(CuTest *tc)
{
    apr_status_t rv;
    char apr_str[STR_SIZE];
    char libc_str[STR_SIZE];
    time_t posix_sec = (time_t)apr_time_sec(now);

    rv = apr_ctime(apr_str, now);
    if (rv == APR_ENOTIMPL) {
        CuNotImpl(tc, "apr_ctime");
    }
    CuAssertTrue(tc, rv == APR_SUCCESS);
    strcpy(libc_str, ctime(&posix_sec));
    *strchr(libc_str, '\n') = '\0';

    CuAssertStrEquals(tc, libc_str, apr_str);
}
Ejemplo n.º 18
0
static void test_exp_get_lt(CuTest *tc)
{
    apr_status_t rv;
    apr_time_exp_t xt;
    apr_time_t imp;
    apr_int64_t hr_off_64;

    rv = apr_time_exp_lt(&xt, now);
    CuAssertTrue(tc, rv == APR_SUCCESS);
    rv = apr_time_exp_get(&imp, &xt);
    if (rv == APR_ENOTIMPL) {
        CuNotImpl(tc, "apr_time_exp_get");
    }
    CuAssertTrue(tc, rv == APR_SUCCESS);
    hr_off_64 = (apr_int64_t) xt.tm_gmtoff * APR_USEC_PER_SEC;
    CuAssertTrue(tc, now + hr_off_64 == imp);
}
Ejemplo n.º 19
0
static void test_exp_tz(CuTest *tc)
{
    apr_status_t rv;
    apr_time_exp_t xt;
    apr_int32_t hr_off = -5 * 3600; /* 5 hours in seconds */

    rv = apr_time_exp_tz(&xt, now, hr_off);
    if (rv == APR_ENOTIMPL) {
        CuNotImpl(tc, "apr_time_exp_tz");
    }
    CuAssertTrue(tc, rv == APR_SUCCESS);
    CuAssertTrue(tc, (xt.tm_usec == 186711) && 
                     (xt.tm_sec == 36) &&
                     (xt.tm_min == 5) && 
                     (xt.tm_hour == 14) &&
                     (xt.tm_mday == 14) &&
                     (xt.tm_mon == 8) &&
                     (xt.tm_year == 102) &&
                     (xt.tm_wday == 6) &&
                     (xt.tm_yday == 256));
}
Ejemplo n.º 20
0
static void proc_mutex(CuTest *tc)
{
#if APR_HAS_FORK
    apr_status_t rv;
    const char *shmname = "tpm.shm";
    apr_shm_t *shm;

    /* Use anonymous shm if available. */
    rv = apr_shm_create(&shm, sizeof(int), NULL, p);
    if (rv == APR_ENOTIMPL) {
        apr_file_remove(shmname, p);
        rv = apr_shm_create(&shm, sizeof(int), shmname, p);
    }

    apr_assert_success(tc, "create shm segment", rv);

    x = apr_shm_baseaddr_get(shm);
    test_exclusive(tc, NULL);
#else
    CuNotImpl(tc, "APR lacks fork() support");
#endif
}
Ejemplo n.º 21
0
static void users_not_impl(CuTest *tc)
{
    CuNotImpl(tc, "Users not implemented on this platform");
}
Ejemplo n.º 22
0
static void test_not_impl(CuTest *tc)
{
    CuNotImpl(tc, "Test not implemented on this platform yet");
}
Ejemplo n.º 23
0
static void threads_not_impl(CuTest *tc)
{
    CuNotImpl(tc, "Threads not implemented on this platform");
}
Ejemplo n.º 24
0
static void fail_userinfo(CuTest *tc)
{
    CuNotImpl(tc, "Intregal uid/gid not present on this platform");
}