X-Git-Url: http://sru.miketaylor.org.uk/?a=blobdiff_plain;f=src%2Ffilter_backend_test.cpp;h=40f9a051fa258e566ef58d9cba532dea0d41c580;hb=665559cbc22546e8df69be33a7d492294cab9fb1;hp=27102fe82aef225b45c01e1f994a0dc1559f4df1;hpb=069ac83475b2cdad04789d5001659a195f851a11;p=metaproxy-moved-to-github.git diff --git a/src/filter_backend_test.cpp b/src/filter_backend_test.cpp index 27102fe..40f9a05 100644 --- a/src/filter_backend_test.cpp +++ b/src/filter_backend_test.cpp @@ -1,8 +1,20 @@ -/* $Id: filter_backend_test.cpp,v 1.21 2006-10-10 09:47:50 adam Exp $ - Copyright (c) 2005-2006, Index Data. +/* This file is part of Metaproxy. + Copyright (C) 2005-2008 Index Data - See the LICENSE file for details - */ +Metaproxy is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 2, or (at your option) any later +version. + +Metaproxy 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 General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ #include "config.hpp" @@ -22,6 +34,7 @@ #include #include #include +#include namespace mp = metaproxy_1; namespace yf = mp::filter; @@ -91,8 +104,7 @@ Z_Records *yf::BackendTest::Rep::fetch( int start, int number, int &error_code, std::string &addinfo, int *number_returned, int *next_position) { - oident *prefformat; - oid_value form; + const char *element_set_name = "F"; // default to use if (number + start - 1 > result_set_size || start < 1) { @@ -100,18 +112,20 @@ Z_Records *yf::BackendTest::Rep::fetch( return 0; } - if (!(prefformat = oid_getentbyoid(preferredRecordSyntax))) - form = VAL_NONE; - else - form = prefformat->value; - switch(form) + if (!preferredRecordSyntax) + preferredRecordSyntax = odr_oiddup(odr, yaz_oid_recsyn_usmarc); + + if (preferredRecordSyntax) { - case VAL_NONE: - case VAL_USMARC: - break; - default: - error_code = YAZ_BIB1_RECORD_SYNTAX_UNSUPP; - return 0; + if (!oid_oidcmp(preferredRecordSyntax, yaz_oid_recsyn_xml)) + ; + else if (!oid_oidcmp(preferredRecordSyntax, yaz_oid_recsyn_usmarc)) + ; + else + { + error_code = YAZ_BIB1_RECORD_SYNTAX_UNSUPP; + return 0; + } } // no element set, "B" and "F" are supported @@ -123,14 +137,23 @@ Z_Records *yf::BackendTest::Rep::fetch( = YAZ_BIB1_SPECIFIED_ELEMENT_SET_NAME_NOT_VALID_FOR_SPECIFIED_; return 0; } - const char *name = esn->u.generic; - if (strcmp(name, "B") && strcmp(name, "F")) - { - error_code - = YAZ_BIB1_SPECIFIED_ELEMENT_SET_NAME_NOT_VALID_FOR_SPECIFIED_; - addinfo = std::string(name); - return 0; - } + element_set_name = esn->u.generic; + } + if (!strcmp(element_set_name, "B") + && !oid_oidcmp(preferredRecordSyntax, yaz_oid_recsyn_usmarc)) + ; // Brief + else if (!strcmp(element_set_name, "F") + && !oid_oidcmp(preferredRecordSyntax, yaz_oid_recsyn_usmarc)) + ; // Full + else if (!strncmp(element_set_name, "FF", 2) + && !oid_oidcmp(preferredRecordSyntax, yaz_oid_recsyn_xml)) + ; // Huge XML test record + else + { + error_code + = YAZ_BIB1_SPECIFIED_ELEMENT_SET_NAME_NOT_VALID_FOR_SPECIFIED_; + addinfo = std::string(element_set_name); + return 0; } Z_Records *rec = (Z_Records *) odr_malloc(odr, sizeof(Z_Records)); rec->which = Z_Records_DBOSD; @@ -148,12 +171,31 @@ Z_Records *yf::BackendTest::Rep::fetch( npr->databaseName = 0; npr->which = Z_NamePlusRecord_databaseRecord; - char *tmp_rec = odr_strdup(odr, marc_record); - char offset_str[30]; - sprintf(offset_str, "test__%09d_", i+start); - memcpy(tmp_rec+186, offset_str, strlen(offset_str)); - npr->u.databaseRecord = z_ext_record(odr, VAL_USMARC, - tmp_rec, strlen(tmp_rec)); + if (!strncmp(element_set_name, "FF", 2)) + { // Huge XML test record + size_t sz = 1024; + if (element_set_name[2]) + sz = atoi(element_set_name+2) * 1024; + if (sz < 10) + sz = 10; + char *tmp_rec = (char*) xmalloc(sz); + + memset(tmp_rec, 'a', sz); + memcpy(tmp_rec, "", 3); + memcpy(tmp_rec + sz - 4, "", 4); + + npr->u.databaseRecord = z_ext_record_xml(odr, tmp_rec, sz); + xfree(tmp_rec); + } + else + { + char *tmp_rec = odr_strdup(odr, marc_record); + char offset_str[30]; + sprintf(offset_str, "test__%09d_", i+start); + memcpy(tmp_rec+186, offset_str, strlen(offset_str)); + npr->u.databaseRecord = z_ext_record_usmarc( + odr, tmp_rec, strlen(tmp_rec)); + } } *number_returned = number; @@ -355,8 +397,9 @@ extern "C" { /* * Local variables: * c-basic-offset: 4 + * c-file-style: "Stroustrup" * indent-tabs-mode: nil - * c-file-style: "stroustrup" * End: * vim: shiftwidth=4 tabstop=8 expandtab */ +