aboutsummaryrefslogtreecommitdiff
path: root/src/test/fst_test.h
diff options
context:
space:
mode:
authorPrzemyslaw Szczepaniak <pszczepaniak@google.com>2013-03-04 11:30:34 +0000
committerPrzemyslaw Szczepaniak <pszczepaniak@google.com>2013-03-04 11:30:34 +0000
commit5bf56ba7027cd5f22ff52d0138893f7a585135fb (patch)
tree19e17fc79b8873e66f211276d4dd169c480cede1 /src/test/fst_test.h
parent3da1eb108d36da35333b2d655202791af854996b (diff)
parent5b6dc79427b8f7eeb6a7ff68034ab8548ce670ea (diff)
downloadopenfst-jb-mr2-release.tar.gz
Diffstat (limited to 'src/test/fst_test.h')
-rw-r--r--src/test/fst_test.h41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/test/fst_test.h b/src/test/fst_test.h
index 8f9dca0..fdc9209 100644
--- a/src/test/fst_test.h
+++ b/src/test/fst_test.h
@@ -51,6 +51,8 @@ class FstTester {
testfst_ = new F(vfst);
}
+ explicit FstTester(F *testfst) : testfst_(testfst) { }
+
~FstTester() {
delete testfst_;
}
@@ -207,6 +209,7 @@ class FstTester {
template <class G>
void TestIO(const G &fst) const {
const string filename = FLAGS_tmpdir + "/test.fst";
+ const string aligned = FLAGS_tmpdir + "/aligned.fst";
{
// write/read
CHECK(fst.Write(filename));
@@ -232,6 +235,44 @@ class FstTester {
delete hfst;
}
+ {
+ // check mmaping by first writing the file with the aligned attribute set
+ {
+ ofstream ostr(aligned.c_str());
+ FstWriteOptions opts;
+ opts.source = aligned;
+ opts.align = true;
+ CHECK(fst.Write(ostr, opts));
+ }
+ ifstream istr(aligned.c_str());
+ FstReadOptions opts;
+ opts.mode = FstReadOptions::ReadMode("map");
+ opts.source = aligned;
+ G *gfst = G::Read(istr, opts);
+ CHECK(gfst);
+ TestBase(*gfst);
+ delete gfst;
+ }
+
+ // check mmaping of unaligned files to make sure it does not fail.
+ {
+ {
+ ofstream ostr(aligned.c_str());
+ FstWriteOptions opts;
+ opts.source = aligned;
+ opts.align = false;
+ CHECK(fst.Write(ostr, opts));
+ }
+ ifstream istr(aligned.c_str());
+ FstReadOptions opts;
+ opts.mode = FstReadOptions::ReadMode("map");
+ opts.source = aligned;
+ G *gfst = G::Read(istr, opts);
+ CHECK(gfst);
+ TestBase(*gfst);
+ delete gfst;
+ }
+
// expanded write/read/test
if (fst.Properties(kExpanded, false)) {
ExpandedFst<Arc> *efst = ExpandedFst<Arc>::Read(filename);