[Groonga-commit] ranguba/chupa-text at 7ed004c [master] Add tests for OpenDocument Spreadsheet and Presentation

Back to archive index
Kouhei Sutou null+****@clear*****
Mon Feb 25 17:54:38 JST 2019


Kouhei Sutou	2019-02-25 17:54:38 +0900 (Mon, 25 Feb 2019)

  Revision: 7ed004ca788cfee7e3fe57e09a9464f5735b045a
  https://github.com/ranguba/chupa-text/commit/7ed004ca788cfee7e3fe57e09a9464f5735b045a

  Message:
    Add tests for OpenDocument Spreadsheet and Presentation
    
    They are still failed. We need to fix them.

  Added files:
    test/decomposers/test-open-document-presentation.rb
    test/decomposers/test-open-document-spreadsheet.rb
    test/fixture/odp/attributes.odp
    test/fixture/odp/multi-slides.odp
    test/fixture/odp/one-slide.odp
    test/fixture/ods/attributes.ods
    test/fixture/ods/multi-sheets.ods
    test/fixture/ods/one-sheet.ods
  Modified files:
    lib/chupa-text/decomposers/open-document.rb

  Modified: lib/chupa-text/decomposers/open-document.rb (+1 -1)
===================================================================
--- lib/chupa-text/decomposers/open-document.rb    2019-02-25 17:40:51 +0900 (159f9ba)
+++ lib/chupa-text/decomposers/open-document.rb    2019-02-25 17:54:38 +0900 (400024c)
@@ -33,7 +33,7 @@ module ChupaText
       MIME_TYPES = [
         "application/vnd.oasis.opendocument.text",
         "application/vnd.oasis.opendocument.spreadsheet",
-        "application/vnd.oasis.opendocument.presentation ",
+        "application/vnd.oasis.opendocument.presentation",
       ]
       def target?(data)
         EXTENSIONS.include?(data.extension) or

  Added: test/decomposers/test-open-document-presentation.rb (+138 -0) 100644
===================================================================
--- /dev/null
+++ test/decomposers/test-open-document-presentation.rb    2019-02-25 17:54:38 +0900 (3ae7819)
@@ -0,0 +1,138 @@
+# Copyright (C) 2019  Kouhei Sutou <kou****@clear*****>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+
+class TestDecomposersOpenDocumentPresentation < Test::Unit::TestCase
+  include Helper
+
+  def setup
+    @decomposer = ChupaText::Decomposers::OpenDocument.new({})
+  end
+
+  def decompose(path)
+    data = ChupaText::InputData.new(path)
+    decomposed = []
+    @decomposer.decompose(data) do |decomposed_data|
+      decomposed << decomposed_data
+    end
+    decomposed
+  end
+
+  sub_test_case("#target_score") do
+    def test_extension
+      data = ChupaText::Data.new
+      data.body = ""
+      data.uri = "document.odp"
+      assert_equal(-1, @decomposer.target_score(data))
+    end
+
+    def test_mime_type
+      data = ChupaText::Data.new
+      data.mime_type = "application/vnd.oasis.opendocument.presentation"
+      assert_equal(-1, @decomposer.target_score(data))
+    end
+  end
+
+  sub_test_case("#decompose") do
+    sub_test_case("attributes") do
+      def decompose(attribute_name)
+        super(fixture_path("odp", "attributes.odp")).collect do |data|
+          data[attribute_name]
+        end
+      end
+
+      def test_title
+        assert_equal(["Title"], decompose("title"))
+      end
+
+      def test_author
+        assert_equal([nil], decompose("author"))
+      end
+
+      def test_subject
+        assert_equal(["Subject"], decompose("subject"))
+      end
+
+      def test_keywords
+        assert_equal([["Keyword1", "Keyword2"]], decompose("keywords"))
+      end
+
+      def test_created_time
+        assert_equal([Time],
+                     decompose("created_time").collect(&:class))
+      end
+
+      def test_modified_time
+        assert_equal([Time],
+                     decompose("modified_time").collect(&:class))
+      end
+
+      def test_generator
+        assert_equal(["LibreOffice"],
+                     normalize_generators(decompose("generator")))
+      end
+
+      def normalize_generators(generators)
+        generators.collect do |generator|
+          normalize_generator(generator)
+        end
+      end
+
+      def normalize_generator(generator)
+        if generator.start_with?("LibreOffice")
+          "LibreOffice"
+        else
+          generator
+        end
+      end
+
+      def test_creation_date
+        assert_equal([nil], decompose("creation_date"))
+      end
+    end
+
+    sub_test_case("one slide") do
+      def decompose
+        super(fixture_path("odp", "one-slide.odp"))
+      end
+
+      def test_body
+        assert_equal([<<-BODY], decompose.collect(&:body))
+Slide1 title
+Slide1 content
+        BODY
+      end
+    end
+
+    sub_test_case("multi slides") do
+      def decompose
+        super(fixture_path("odp", "multi-slides.odp"))
+      end
+
+      def test_body
+        assert_equal([<<-BODY], decompose.collect(&:body))
+Slide1 title
+Slide1 content
+
+Slide2 title
+Slide2 content
+
+Slide3 title
+Slide3 content
+        BODY
+      end
+    end
+  end
+end

  Added: test/decomposers/test-open-document-spreadsheet.rb (+138 -0) 100644
===================================================================
--- /dev/null
+++ test/decomposers/test-open-document-spreadsheet.rb    2019-02-25 17:54:38 +0900 (b83e18a)
@@ -0,0 +1,138 @@
+# Copyright (C) 2019  Kouhei Sutou <kou****@clear*****>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+
+class TestDecomposersOpenDocumentSpreadsheet < Test::Unit::TestCase
+  include Helper
+
+  def setup
+    @decomposer = ChupaText::Decomposers::OpenDocument.new({})
+  end
+
+  def decompose(path)
+    data = ChupaText::InputData.new(path)
+    decomposed = []
+    @decomposer.decompose(data) do |decomposed_data|
+      decomposed << decomposed_data
+    end
+    decomposed
+  end
+
+  sub_test_case("#target_score") do
+    def test_extension
+      data = ChupaText::Data.new
+      data.body = ""
+      data.uri = "document.ods"
+      assert_equal(-1, @decomposer.target_score(data))
+    end
+
+    def test_mime_type
+      data = ChupaText::Data.new
+      data.mime_type = "application/vnd.oasis.opendocument.spreadsheet"
+      assert_equal(-1, @decomposer.target_score(data))
+    end
+  end
+
+  sub_test_case("#decompose") do
+    sub_test_case("attributes") do
+      def decompose(attribute_name)
+        super(fixture_path("ods", "attributes.ods")).collect do |data|
+          data[attribute_name]
+        end
+      end
+
+      def test_title
+        assert_equal(["Title"], decompose("title"))
+      end
+
+      def test_author
+        assert_equal([nil], decompose("author"))
+      end
+
+      def test_subject
+        assert_equal(["Subject"], decompose("subject"))
+      end
+
+      def test_keywords
+        assert_equal([["Keyword1", "Keyword2"]], decompose("keywords"))
+      end
+
+      def test_created_time
+        assert_equal([Time],
+                     decompose("created_time").collect(&:class))
+      end
+
+      def test_modified_time
+        assert_equal([Time],
+                     decompose("modified_time").collect(&:class))
+      end
+
+      def test_generator
+        assert_equal(["LibreOffice"],
+                     normalize_generators(decompose("generator")))
+      end
+
+      def normalize_generators(generators)
+        generators.collect do |generator|
+          normalize_generator(generator)
+        end
+      end
+
+      def normalize_generator(generator)
+        if generator.start_with?("LibreOffice")
+          "LibreOffice"
+        else
+          generator
+        end
+      end
+
+      def test_creation_date
+        assert_equal([nil], decompose("creation_date"))
+      end
+    end
+
+    sub_test_case("one sheet") do
+      def decompose
+        super(fixture_path("ods", "one-sheet.ods"))
+      end
+
+      def test_body
+        assert_equal([<<-BODY], decompose.collect(&:body))
+Sheet1 - A1\tSheet1 - B1
+Sheet1 - A2\tSheet1 - B2
+        BODY
+      end
+    end
+
+    sub_test_case("multi sheets") do
+      def decompose
+        super(fixture_path("ods", "multi-sheets.ods"))
+      end
+
+      def test_body
+        assert_equal([<<-BODY], decompose.collect(&:body))
+Sheet1 - A1\tSheet1 - B1
+Sheet1 - A2\tSheet1 - B2
+
+Sheet2 - A1\tSheet2 - B1
+Sheet2 - A2\tSheet2 - B2
+
+Sheet3 - A1\tSheet3 - B1
+Sheet3 - A2\tSheet3 - B2
+        BODY
+      end
+    end
+  end
+end

  Added: test/fixture/odp/attributes.odp (+23 -0) 100644
===================================================================
--- /dev/null
+++ test/fixture/odp/attributes.odp    2019-02-25 17:54:38 +0900 (5a528e6)
@@ -0,0 +1,23 @@
+MIME-Version: 1.0
+mime-type: application/vnd.oasis.opendocument.presentation
+uri: file:/tmp/rlGNIr_attributes.odp
+path: /tmp/rlGNIr_attributes.odp
+size: 12808
+Content-Type: multipart/mixed; boundary=9ac51edb1795f4b8dfcc8d2736bb121e7a0a7547
+
+--9ac51edb1795f4b8dfcc8d2736bb121e7a0a7547
+mime-type: text/plain
+uri: file:/tmp/rlGNIr_attributes.txt
+path: /tmp/rlGNIr_attributes.txt
+size: 6
+title: Title
+created_time: 2019-02-25 08:55:14 UTC
+source-mime-types: ["application/pdf", "application/vnd.oasis.opendocument.presentation"]
+subject: Subject
+keywords: Keyword1, Keyword2
+creator: Impress
+producer: LibreOffice 5.2
+
+Title
+
+--9ac51edb1795f4b8dfcc8d2736bb121e7a0a7547--

  Added: test/fixture/odp/multi-slides.odp (+27 -0) 100644
===================================================================
--- /dev/null
+++ test/fixture/odp/multi-slides.odp    2019-02-25 17:54:38 +0900 (3fc6087)
@@ -0,0 +1,27 @@
+MIME-Version: 1.0
+mime-type: application/vnd.oasis.opendocument.presentation
+uri: file:/tmp/zmOoRh_multi-slides.odp
+path: /tmp/zmOoRh_multi-slides.odp
+size: 13509
+Content-Type: multipart/mixed; boundary=5867ca0d97494c3e5c14f40aa5ec62cd4ac469e6
+
+--5867ca0d97494c3e5c14f40aa5ec62cd4ac469e6
+mime-type: text/plain
+uri: file:/tmp/zmOoRh_multi-slides.txt
+path: /tmp/zmOoRh_multi-slides.txt
+size: 92
+created_time: 2019-02-25 08:55:15 UTC
+source-mime-types: ["application/pdf", "application/vnd.oasis.opendocument.presentation"]
+creator: Impress
+producer: LibreOffice 5.2
+
+Slide1 title
+Slide1 content
+Slide2 title
+●
+Slide2 content
+Slide3 title
+●
+Slide3 content
+
+--5867ca0d97494c3e5c14f40aa5ec62cd4ac469e6--

  Added: test/fixture/odp/one-slide.odp (+21 -0) 100644
===================================================================
--- /dev/null
+++ test/fixture/odp/one-slide.odp    2019-02-25 17:54:38 +0900 (d82d1b0)
@@ -0,0 +1,21 @@
+MIME-Version: 1.0
+mime-type: application/vnd.oasis.opendocument.presentation
+uri: file:/tmp/INBSEg_one-slide.odp
+path: /tmp/INBSEg_one-slide.odp
+size: 11868
+Content-Type: multipart/mixed; boundary=820018c714dd93f4e5b2aa9e837c480e82e02952
+
+--820018c714dd93f4e5b2aa9e837c480e82e02952
+mime-type: text/plain
+uri: file:/tmp/INBSEg_one-slide.txt
+path: /tmp/INBSEg_one-slide.txt
+size: 28
+created_time: 2019-02-25 08:55:17 UTC
+source-mime-types: ["application/pdf", "application/vnd.oasis.opendocument.presentation"]
+creator: Impress
+producer: LibreOffice 5.2
+
+Slide1 title
+Slide1 content
+
+--820018c714dd93f4e5b2aa9e837c480e82e02952--

  Added: test/fixture/ods/attributes.ods (+24 -0) 100644
===================================================================
--- /dev/null
+++ test/fixture/ods/attributes.ods    2019-02-25 17:54:38 +0900 (7068c11)
@@ -0,0 +1,24 @@
+MIME-Version: 1.0
+mime-type: application/vnd.oasis.opendocument.spreadsheet
+uri: file:/tmp/aD40ia_attributes.ods
+path: /tmp/aD40ia_attributes.ods
+size: 8368
+Content-Type: multipart/mixed; boundary=b09137e12fd0bcfd4507737d7cf93fc9e1eac0ca
+
+--b09137e12fd0bcfd4507737d7cf93fc9e1eac0ca
+mime-type: text/plain
+uri: file:/tmp/aD40ia_attributes.txt
+path: /tmp/aD40ia_attributes.txt
+size: 12
+source-mime-types: ["application/vnd.oasis.opendocument.spreadsheet"]
+name: Sheet1
+digest: b6906a8292c58517cf73036ad0ace729518f79b4
+size: 12
+first-row: 1
+last-row: 1
+first-column: A
+last-column: A
+
+"Sheet1 A1"
+
+--b09137e12fd0bcfd4507737d7cf93fc9e1eac0ca--

  Added: test/fixture/ods/multi-sheets.ods (+59 -0) 100644
===================================================================
--- /dev/null
+++ test/fixture/ods/multi-sheets.ods    2019-02-25 17:54:38 +0900 (107b73d)
@@ -0,0 +1,59 @@
+MIME-Version: 1.0
+mime-type: application/vnd.oasis.opendocument.spreadsheet
+uri: file:/tmp/EdNuzd_multi-sheets.ods
+path: /tmp/EdNuzd_multi-sheets.ods
+size: 8773
+Content-Type: multipart/mixed; boundary=f52135ef4019d4ab968f077b1e4c37d8c169fb01
+
+--f52135ef4019d4ab968f077b1e4c37d8c169fb01
+mime-type: text/plain
+uri: file:/tmp/EdNuzd_multi-sheets.txt
+path: /tmp/EdNuzd_multi-sheets.txt
+size: 56
+source-mime-types: ["application/vnd.oasis.opendocument.spreadsheet"]
+name: Sheet1
+digest: 9011cb9443faf652afa3746acfae5c623ec5c7c9
+size: 56
+first-row: 1
+last-row: 2
+first-column: A
+last-column: B
+
+"Sheet1 - A1","Sheet1 - B1"
+"Sheet1 - A2","Sheet1 - B2"
+
+--f52135ef4019d4ab968f077b1e4c37d8c169fb01
+mime-type: text/plain
+uri: file:/tmp/EdNuzd_multi-sheets.txt
+path: /tmp/EdNuzd_multi-sheets.txt
+size: 56
+source-mime-types: ["application/vnd.oasis.opendocument.spreadsheet"]
+name: Sheet2
+digest: be99be632ea81d909f2d44b26e3dde28214cb126
+size: 56
+first-row: 1
+last-row: 2
+first-column: A
+last-column: B
+
+"Sheet2 - A1","Sheet2 - B1"
+"Sheet2 - A2","Sheet2 - B2"
+
+--f52135ef4019d4ab968f077b1e4c37d8c169fb01
+mime-type: text/plain
+uri: file:/tmp/EdNuzd_multi-sheets.txt
+path: /tmp/EdNuzd_multi-sheets.txt
+size: 56
+source-mime-types: ["application/vnd.oasis.opendocument.spreadsheet"]
+name: Sheet3
+digest: c03c013aba6e69703ba402967fc2a85cebbe9a28
+size: 56
+first-row: 1
+last-row: 2
+first-column: A
+last-column: B
+
+"Sheet3 - A1","Sheet3 - B1"
+"Sheet3 - A2","Sheet3 - B2"
+
+--f52135ef4019d4ab968f077b1e4c37d8c169fb01--

  Added: test/fixture/ods/one-sheet.ods (+25 -0) 100644
===================================================================
--- /dev/null
+++ test/fixture/ods/one-sheet.ods    2019-02-25 17:54:38 +0900 (41336a6)
@@ -0,0 +1,25 @@
+MIME-Version: 1.0
+mime-type: application/vnd.oasis.opendocument.spreadsheet
+uri: file:/tmp/BGAHxv_one-sheet.ods
+path: /tmp/BGAHxv_one-sheet.ods
+size: 8695
+Content-Type: multipart/mixed; boundary=75680d768ac26912bf38f45791fb8a35987abec3
+
+--75680d768ac26912bf38f45791fb8a35987abec3
+mime-type: text/plain
+uri: file:/tmp/BGAHxv_one-sheet.txt
+path: /tmp/BGAHxv_one-sheet.txt
+size: 56
+source-mime-types: ["application/vnd.oasis.opendocument.spreadsheet"]
+name: Sheet1
+digest: 9011cb9443faf652afa3746acfae5c623ec5c7c9
+size: 56
+first-row: 1
+last-row: 2
+first-column: A
+last-column: B
+
+"Sheet1 - A1","Sheet1 - B1"
+"Sheet1 - A2","Sheet1 - B2"
+
+--75680d768ac26912bf38f45791fb8a35987abec3--
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20190225/02aabbef/attachment-0001.html>


More information about the Groonga-commit mailing list
Back to archive index