#!/usr/bin/perl -w
# Copyright (C) 2007 Olly Betts
#
# This program 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 of the
# License, or (at your option) any later version.
#
# This program 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

use strict;

my $generated_warning =
"/* Warning: This file is generated by $0 - do not modify directly! */\n";

my @uncopyableclasses = qw(
    BM25Weight
    BoolWeight
    TradWeight
);

my %copyableclasses = (
    'Database' => '',
    'DateValueRangeProcessor' => '0',
    'Document' => '',
    'ESet' => '',
    'ESetIterator' => '',
    'Enquire' => 'Xapian::InMemory::open()',
    'MSet' => '',
    'MSetIterator' => '',
    'MultiValueSorter' => '',
    'NumberValueRangeProcessor' => '0, ""',
    'PositionIterator' => '',
    'PostingIterator' => '',
    'Query' => '',
    'QueryParser' => '',
    'RSet' => '',
    'SimpleStopper' => '',
    'Stem' => '',
    'StringValueRangeProcessor' => '0',
    'TermGenerator' => '',
    'TermIterator' => '',
    'ValueIterator' => '',
    'WritableDatabase' => '',
);

print <<'END';
/** @file api_common.cc
 * @brief test common features of API classes
 */
END
print $generated_warning;
print <<'END';
/* Copyright (C) 2007 Olly Betts
 *
 * This program 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 of the License, or
 * (at your option) any later version.
 *
 * This program 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.h>

#include "api_generated.h"

#include <xapian.h>

#include "apitest.h"
#include "testutils.h"

using namespace std;

/// Check uncopyable API classes which should have a default ctor actually do.
DEFINE_TESTCASE(defaultctor1, !backend) {
END

for my $class (@uncopyableclasses) {
    my $object = lc $class;
    $class = "Xapian::$class";
    print "    $class $object;\n";
}

print <<'END';
    return true;
}

/// Test that API classes have a copy ctor and assignment operator.
DEFINE_TESTCASE(copyassign1, !backend) {
END

for my $class (sort keys %copyableclasses) {
    my $params = $copyableclasses{$class};
    if ($params ne '') {
	$params = "($params)";
    }
    my $object = lc $class;
    $class = "Xapian::$class";
    print "    $class $object$params;\n";
    print "    $class copy_$object($object);\n";
    print "    $object = copy_$object;\n";
    print "\n";
}

print <<'END';
    return true;
}
END
