22 #ifndef HYPERTABLE_TESTDATA_H
23 #define HYPERTABLE_TESTDATA_H
25 #include <boost/shared_array.hpp>
33 typedef boost::shared_array<const char>
CharPtr;
37 bool load(
const std::string &datadir) {
39 char *contentdata, *worddata, *urldata;
40 char *base, *ptr, *last, *
str;
42 std::string shakespearefile = datadir +
"/shakespeare.txt";
43 std::string shakespearegz = datadir +
"/shakespeare.txt.gz";
44 std::string wordsfile = datadir +
"/words";
45 std::string wordsgz = datadir +
"/words.gz";
46 std::string urlsfile = datadir +
"/urls.txt";
47 std::string urlsgz = datadir +
"/urls.txt.gz";
53 if (stat(shakespearefile.c_str(), &statbuf) != 0) {
54 if (stat(shakespearegz.c_str(), &statbuf) != 0) {
55 HT_ERRORF(
"Unable to stat file 'shakespeare.txt.gz' : %s",
59 syscmd =
"zcat " + shakespearegz +
" > " + shakespearefile;
60 if (system(syscmd.c_str())) {
61 HT_ERRORF(
"Unable to decompress file '%s'", shakespearegz.c_str());
64 if (stat(shakespearefile.c_str(), &statbuf) != 0) {
65 HT_ERRORF(
"Unable to stat file '%s' : %s", shakespearefile.c_str(),
74 while ((ptr = strstr(base,
"\n\n")) != 0) {
76 str =
new char [strlen(base) + 1];
82 delete [] contentdata;
87 if (stat(wordsfile.c_str(), &statbuf) != 0) {
88 if (stat(wordsgz.c_str(), &statbuf) != 0) {
89 HT_ERRORF(
"Unable to stat file '%s' : %s", wordsgz.c_str(),
93 syscmd =
"zcat " + wordsgz +
" > " + wordsfile;
94 if (system(syscmd.c_str())) {
95 HT_ERRORF(
"Unable to decompress file '%s'", wordsgz.c_str());
98 if (stat(wordsfile.c_str(), &statbuf) != 0) {
99 HT_ERRORF(
"Unable to stat file '%s' : %s", wordsfile.c_str(),
106 base = strtok_r(worddata,
"\n\r", &last);
108 str =
new char [strlen(base) + 1];
111 base = strtok_r(0,
"\n\r", &last);
119 if (stat(urlsfile.c_str(), &statbuf) != 0) {
120 if (stat(urlsgz.c_str(), &statbuf) != 0) {
121 HT_ERRORF(
"Unable to stat file 'urls.txt.gz' : %s", strerror(errno));
124 syscmd =
"zcat " + urlsgz +
" > " + urlsfile;
125 if (system(syscmd.c_str())) {
126 HT_ERRORF(
"Unable to decompress file '%s'", urlsgz.c_str());
129 if (stat(urlsfile.c_str(), &statbuf) != 0) {
130 HT_ERRORF(
"Unable to stat file '%s' : %s", urlsfile.c_str(),
137 base = strtok_r(urldata,
"\n\r", &last);
139 str =
new char [strlen(base) + 1];
142 base = strtok_r(0,
"\n\r", &last);
155 #endif // HYPERTABLE_TESTDATA_H
static char * file_to_buffer(const String &fname, off_t *lenp)
Reads a full file into a new buffer; the buffer is allocated with operator new[], and the caller has ...
Po::typed_value< String > * str(String *v=0)
File system utility functions.
boost::shared_array< const char > CharPtr
Logging routines and macros.
A simple testing framework with some helpers for dealing with golden files (comparing files...
std::vector< CharPtr > urls
std::vector< CharPtr > words
#define HT_ERRORF(msg,...)
std::vector< CharPtr > content
bool load(const std::string &datadir)