~ubuntu-branches/ubuntu/oneiric/mozc/oneiric

« back to all changes in this revision

Viewing changes to converter/connector_test.cc

  • Committer: Bazaar Package Importer
  • Author(s): Nobuhiro Iwamatsu
  • Date: 2010-07-14 03:26:47 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100714032647-13qjisj6m8cm8jdx
Tags: 0.12.410.102-1
* New upstream release (Closes: #588971).
  - Add mozc-server, mozc-utils-gui and scim-mozc packages.
* Update debian/rules.
  Add --gypdir option to build_mozc.py.
* Update debian/control.
  - Bumped standards-version to 3.9.0.
  - Update description.
* Add mozc icon (Closes: #588972).
* Add patch which revises issue 18.
  ibus_mozc_issue18.patch
* kFreeBSD build support.
  support_kfreebsd.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
#include "base/file_stream.h"
33
33
#include "base/mmap.h"
34
34
#include "base/util.h"
35
 
#include "converter/connector.h"
36
 
#include "converter/converter_compiler.h"
 
35
#include "converter/connector_interface.h"
 
36
#include "converter/sparse_connector.h"
37
37
#include "testing/base/public/gunit.h"
38
38
 
39
39
DECLARE_string(test_tmpdir);
40
 
DECLARE_bool(use_sparse_connector);
41
40
 
42
41
namespace mozc {
43
42
 
44
 
class ConnectorTest : public testing::Test {
45
 
 protected:
46
 
  void ConnectorOpenTest() {
47
 
    const string input_filename
48
 
        = mozc::Util::JoinPath(FLAGS_test_tmpdir, "connector.txt");
49
 
 
50
 
    const string output_filename
51
 
        = mozc::Util::JoinPath(FLAGS_test_tmpdir, "connector.db");
52
 
 
53
 
    {
54
 
      mozc::OutputFileStream ofs(input_filename.c_str());
55
 
      EXPECT_TRUE(ofs);
56
 
 
57
 
      ofs << "3 3" << endl;  // 3x3 matrix
58
 
      for (int i = 0; i < 3; ++i) {
59
 
        for (int j = 0; j < 3; ++j) {
60
 
          // lid, rid, cost
61
 
          ofs << i << " " << j << " " << 3 * i + j << endl;
62
 
        }
63
 
      }
64
 
    }
65
 
 
66
 
    ConverterCompiler::CompileConnectionTable(input_filename,
67
 
                                              output_filename);
68
 
 
69
 
    Mmap<char> cmmap;
70
 
    CHECK(cmmap.Open(output_filename.c_str()))
71
 
        << "Failed to open matrix image" << output_filename;
72
 
    CHECK_GE(cmmap.Size(), 4) << "Malformed matrix image";
73
 
    scoped_ptr<ConnectorInterface> connector(
74
 
        ConnectorInterface::OpenFromArray(cmmap.begin(), cmmap.GetFileSize()));
75
 
 
 
43
TEST(SparseConnectorTest, SparseConnecterOpenTest) {
 
44
  const string input_filename
 
45
      = mozc::Util::JoinPath(FLAGS_test_tmpdir, "connector.txt");
 
46
 
 
47
  const string output_filename
 
48
      = mozc::Util::JoinPath(FLAGS_test_tmpdir, "connector.db");
 
49
 
 
50
  {
 
51
    mozc::OutputFileStream ofs(input_filename.c_str());
 
52
    EXPECT_TRUE(ofs);
 
53
 
 
54
    ofs << "3 3" << endl;  // 3x3 matrix
76
55
    for (int i = 0; i < 3; ++i) {
77
56
      for (int j = 0; j < 3; ++j) {
78
 
        EXPECT_EQ(3 * i + j, connector->GetTransitionCost(i, j));
 
57
        // lid, rid, cost
 
58
        ofs << i << " " << j << " " << 3 * i + j << endl;
79
59
      }
80
60
    }
81
61
  }
82
 
};
83
 
 
84
 
// This code is a kind of kludge to use 2 implementations of transition
85
 
// cost matrix. We might remove this later.
86
 
TEST_F(ConnectorTest, DenseConnecterOpenTest) {
87
 
  FLAGS_use_sparse_connector = false;
88
 
  ConnectorOpenTest();
89
 
}
90
 
 
91
 
TEST_F(ConnectorTest, SparseConnecterOpenTest) {
92
 
  FLAGS_use_sparse_connector = true;
93
 
  ConnectorOpenTest();
 
62
 
 
63
  SparseConnectorBuilder::Compile(input_filename.c_str(),
 
64
                                  output_filename.c_str());
 
65
 
 
66
  Mmap<char> cmmap;
 
67
  CHECK(cmmap.Open(output_filename.c_str()))
 
68
      << "Failed to open matrix image" << output_filename;
 
69
  CHECK_GE(cmmap.Size(), 4) << "Malformed matrix image";
 
70
  scoped_ptr<SparseConnector> connector(
 
71
      new SparseConnector(cmmap.begin(), cmmap.GetFileSize()));
 
72
 
 
73
  for (int i = 0; i < 3; ++i) {
 
74
    for (int j = 0; j < 3; ++j) {
 
75
      EXPECT_EQ(3 * i + j, connector->GetTransitionCost(i, j));
 
76
    }
 
77
  }
94
78
}
95
79
 
96
80
TEST(SparseConnectorTest, key_coding) {