-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbuild_t.c
82 lines (65 loc) · 2.39 KB
/
build_t.c
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Copyright (C) 2001-2013 Mischa Sandberg <mischasan@gmail.com>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License Version 2 as
// published by the Free Software Foundation. You may not use, modify or
// distribute this program under any other version of the GNU General
// Public License.
//
// 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 Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
// IF YOU HAVE NO WAY OF WORKING WITH GPL, CONTACT ME.
//-------------------------------------------------------------------------------
#include "tap.h"
#include "_hx.h"
#include "util.h"
static void try(char const *, int nrecs);
int
main(void)
{
char input[999];
setenv("hx", ".", 0);
setvbuf(stdout, 0, _IOLBF, 0);
plan_tests(1 + 4 * 4);
HXRET rc = hxbuild(0, 0, 1 << 20, 0.0);
ok(rc == HXERR_BAD_REQUEST, "hxbuild rejects NULL arg: %s", hxerror(rc));
try("/dev/null", 0);
try(strcat(strcpy(input, getenv("hx")), "/data.tab"), 88172);
try("cat $hx/data.tab", 88172);
try("head -2335 $hx/data.tab", 2335);
return exit_status();
}
static void
try(char const *inpfile, int nrecs)
{
FILE *fp = (strchr(inpfile, ' ') ? popen : fopen)(inpfile, "r");
ok(fp, "input %s", inpfile);
if (!fp)
die(": unable to open %s:", inpfile);
setvbuf(fp, NULL, _IOFBF, 16384);
hxcreate("build_t.hx", 0755, 4096, "", 0);
HXFILE *hp = hxopen("build_t.hx", HX_UPDATE);
double alpha = tick();
HXRET rc = hxbuild(hp, fp, 1 << 20, 0.0); //128MB
double omega = tick();
if (strchr(inpfile, ' '))
pclose(fp);
else
fclose(fp);
ok(rc == 0, "hxbuild from (%s) in %.3g secs, returns %s",
inpfile, omega - alpha, hxerror(rc));
rc = hxfix(hp, 0, 0, 0, 0);
ok(rc == (HXRET) HX_UPDATE, "hxcheck returns: %s", hxmode(rc));
HXSTAT st;
hxstat(hp, &st);
ok(st.nrecs == nrecs, "hxbuild loaded %.0f/%d records", st.nrecs, nrecs);
hxclose(hp);
unlink("build_t.hx");
}