File: 04functions.t

package info (click to toggle)
libsearch-xapian-perl 1.2.25.5-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 848 kB
  • sloc: perl: 2,332; makefile: 6
file content (49 lines) | stat: -rw-r--r-- 1,480 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use strict;
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl test.pl'

#########################

use Test::More;
BEGIN { plan tests => 26 };
use Search::Xapian qw(:standard);
use Config;

ok(1); # If we made it this far, we're ok.

#########################

# Test non-class functions.

my $version = join(".", (
	Search::Xapian::major_version(),
	Search::Xapian::minor_version(),
	Search::Xapian::revision()
    ));

ok($version eq Search::Xapian::version_string());

my $ldbl = (defined($Config{uselongdouble}) &&
	    $Config{uselongdouble} eq "define" &&
	    $Config{doublesize} != $Config{longdblsize});
for my $val (-9e10, -1234.56, -1, -1e-10, 0, 1e-10, 1, 2, 4, 8, 9, 9e10) {
    my $enc_val = Search::Xapian::sortable_serialise($val);
    if ($ldbl) {
	# Perl is configured with -Duselongdouble and long double isn't the
	# same as double, so we may have rounded the input value slightly
	# passing it to Xapian.
	my $de_enc_val = Search::Xapian::sortable_unserialise($enc_val);
	ok(abs($de_enc_val - $val) < 1e-12);
	# But encoding and decoding the value we got back should give exactly
	# the same value.
	my $re_enc_val = Search::Xapian::sortable_serialise($de_enc_val);
	ok(Search::Xapian::sortable_unserialise($re_enc_val) == $de_enc_val);
    } else {
	# We should get the exact same value back.
	ok(Search::Xapian::sortable_unserialise($enc_val) == $val);
	ok(1);
    }
}


1;