[Groonga-commit] groonga/groonga [master] add a test of grn::dat::File.

Back to archive index

null+****@clear***** null+****@clear*****
2011年 11月 10日 (木) 11:00:59 JST


Susumu Yata	2011-11-10 02:00:59 +0000 (Thu, 10 Nov 2011)

  New Revision: d82671a475163293212ab0108a81e98649027c6b

  Log:
    add a test of grn::dat::File.

  Added files:
    test/unit/core/dat/test-file.cpp
  Modified files:
    test/unit/core/dat/Makefile.am

  Modified: test/unit/core/dat/Makefile.am (+2 -2)
===================================================================
--- test/unit/core/dat/Makefile.am    2011-11-10 01:57:24 +0000 (dd6e71e)
+++ test/unit/core/dat/Makefile.am    2011-11-10 02:00:59 +0000 (5d209e3)
@@ -6,13 +6,13 @@ noinst_LTLIBRARIES =				\
 	test-check.la				\
 	test-cursor-factory.la			\
 	test-entry.la				\
+	test-file.la				\
 	test-header.la				\
 	test-key.la				\
 	test-node.la				\
 	test-string.la				\
 	test-vector.la
 
-#	test-file.la				\
 #	test-id-cursor.la			\
 #	test-key-cursor.la			\
 #	test-predictive-cursor.la		\
@@ -46,7 +46,7 @@ test_block_la_SOURCES			= test-block.cpp
 test_check_la_SOURCES			= test-check.cpp
 test_cursor_factory_la_SOURCES		= test-cursor-factory.cpp
 test_entry_la_SOURCES			= test-entry.cpp
-#test_file_la_SOURCES			= test-file.cpp
+test_file_la_SOURCES			= test-file.cpp
 test_header_la_SOURCES			= test-header.cpp
 #test_id_cursor_la_SOURCES		= test-id-cursor.cpp
 #test_key_cursor_la_SOURCES		= test-key-cursor.cpp

  Added: test/unit/core/dat/test-file.cpp (+119 -0) 100644
===================================================================
--- /dev/null
+++ test/unit/core/dat/test-file.cpp    2011-11-10 02:00:59 +0000 (e48af16)
@@ -0,0 +1,119 @@
+/* -*- c-basic-offset: 2; coding: utf-8 -*- */
+/*
+  Copyright (C) 2011  Brazil
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License version 2.1 as published by the Free Software Foundation.
+
+  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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+#include <gcutter.h>
+#include <cppcutter.h>
+
+#include <grn-assertions.h>
+#include <dat/file.hpp>
+
+#include <cstring>
+
+namespace test_dat_file
+{
+  void test_invalid_file(void)
+  {
+    const grn::dat::File file;
+
+    cppcut_assert_equal(file.ptr(), static_cast<void *>(NULL));
+    cppcut_assert_equal(file.size(), static_cast<grn::dat::UInt64>(0));
+  }
+
+  void test_create_without_path(void)
+  {
+    grn::dat::File file;
+
+    try {
+      file.create(NULL, 0);
+      cut_fail("A zero-byte request is not allowed.");
+    } catch (const grn::dat::Exception &) {
+    }
+
+    file.create(NULL, 32);
+    cut_assert(file.ptr() != NULL);
+    cppcut_assert_equal(file.size(), static_cast<grn::dat::UInt64>(32));
+
+    grn::dat::UInt8 * const buf = static_cast<grn::dat::UInt8 *>(file.ptr());
+    for (grn::dat::UInt64 i = 0; i < file.size(); ++i) {
+      buf[i] = static_cast<grn::dat::UInt8>(i);
+      cppcut_assert_equal(buf[i], static_cast<grn::dat::UInt8>(i));
+    }
+  }
+
+  void test_create_with_path(void)
+  {
+    grn::dat::File file;
+
+    try {
+      file.create("test_dat_file.tmp", 0);
+      cut_fail("A zero-byte request is not allowed.");
+    } catch (const grn::dat::Exception &) {
+    }
+
+    file.create("test_dat_file.tmp", 32);
+    cut_assert(file.ptr() != NULL);
+    cppcut_assert_equal(file.size(), static_cast<grn::dat::UInt64>(32));
+
+    grn::dat::UInt8 * const buf = static_cast<grn::dat::UInt8 *>(file.ptr());
+    for (grn::dat::UInt64 i = 0; i < file.size(); ++i) {
+      buf[i] = static_cast<grn::dat::UInt8>(i);
+      cppcut_assert_equal(buf[i], static_cast<grn::dat::UInt8>(i));
+    }
+  }
+
+  void test_open(void)
+  {
+    grn::dat::File file;
+
+    try {
+      file.open(NULL);
+      cut_fail("A null-path request is not allowed.");
+    } catch (const grn::dat::Exception &) {
+    }
+
+    file.create("test_dat_file.tmp", 32);
+    std::strcpy(static_cast<char *>(file.ptr()), "This is a pen.");
+
+    file.close();
+    cppcut_assert_equal(file.ptr(), static_cast<void *>(NULL));
+    cppcut_assert_equal(file.size(), static_cast<grn::dat::UInt64>(0));
+
+    file.open("test_dat_file.tmp");
+    cut_assert(file.ptr() != NULL);
+    cppcut_assert_equal(file.size(), static_cast<grn::dat::UInt64>(32));
+    cut_assert(!std::strcmp(static_cast<char *>(file.ptr()), "This is a pen."));
+  }
+
+  void test_swap(void)
+  {
+    grn::dat::File file;
+
+    file.create(NULL, 100);
+    cut_assert(file.ptr() != NULL);
+    cppcut_assert_equal(file.size(), static_cast<grn::dat::UInt64>(100));
+
+    grn::dat::File file_new;
+    file_new.swap(&file);
+
+    cppcut_assert_equal(file.ptr(), static_cast<void *>(NULL));
+    cppcut_assert_equal(file.size(), static_cast<grn::dat::UInt64>(0));
+
+    cut_assert(file_new.ptr() != NULL);
+    cppcut_assert_equal(file_new.size(), static_cast<grn::dat::UInt64>(100));
+  }
+}




Groonga-commit メーリングリストの案内
Back to archive index