Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ARROW-4955: [GLib] Add garrow_file_is_closed() #3970

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions c_glib/arrow-glib/file.cpp
Expand Up @@ -63,6 +63,21 @@ garrow_file_close(GArrowFile *file,
return garrow_error_check(error, status, "[io][file][close]");
}

/**
* garrow_file_is_closed:
* @file: A #GArrowFile.
*
* Returns: %TRUE if the @file is already closed, %FALSE otherwise.
*
* Since: 0.13.0
*/
gboolean
garrow_file_is_closed(GArrowFile *file)
{
auto arrow_file = garrow_file_get_raw(file);
return arrow_file->closed();
}

/**
* garrow_file_tell:
* @file: A #GArrowFile.
Expand Down
30 changes: 11 additions & 19 deletions c_glib/arrow-glib/file.h
Expand Up @@ -20,30 +20,22 @@
#pragma once

#include <arrow-glib/file-mode.h>
#include <arrow-glib/gobject-type.h>
#include <arrow-glib/version.h>

G_BEGIN_DECLS

#define GARROW_TYPE_FILE \
(garrow_file_get_type())
#define GARROW_FILE(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), \
GARROW_TYPE_FILE, \
GArrowFile))
#define GARROW_IS_FILE(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj), \
GARROW_TYPE_FILE))
#define GARROW_FILE_GET_IFACE(obj) \
(G_TYPE_INSTANCE_GET_INTERFACE((obj), \
GARROW_TYPE_FILE, \
GArrowFileInterface))

typedef struct _GArrowFile GArrowFile;
typedef struct _GArrowFileInterface GArrowFileInterface;

GType garrow_file_get_type(void) G_GNUC_CONST;
#define GARROW_TYPE_FILE (garrow_file_get_type())
G_DECLARE_INTERFACE(GArrowFile,
garrow_file,
GARROW,
FILE,
GObject)

gboolean garrow_file_close(GArrowFile *file,
GError **error);
GError **error);
GARROW_AVAILABLE_IN_0_13
gboolean garrow_file_is_closed(GArrowFile *file);
gint64 garrow_file_tell(GArrowFile *file,
GError **error);
GArrowFileMode garrow_file_get_mode(GArrowFile *file);
Expand Down
45 changes: 24 additions & 21 deletions c_glib/test/test-memory-mapped-input-stream.rb
Expand Up @@ -16,11 +16,15 @@
# under the License.

class TestMemoryMappedInputStream < Test::Unit::TestCase
def setup
@data = "Hello World"
@tempfile = Tempfile.open("arrow-memory-mapped-input-stream")
@tempfile.write(@data)
@tempfile.close
end

def test_new
tempfile = Tempfile.open("arrow-memory-mapped-input-stream")
tempfile.write("Hello")
tempfile.close
input = Arrow::MemoryMappedInputStream.new(tempfile.path)
input = Arrow::MemoryMappedInputStream.new(@tempfile.path)
begin
buffer = input.read(5)
assert_equal("Hello", buffer.data.to_s)
Expand All @@ -29,23 +33,28 @@ def test_new
end
end

def test_close
input = Arrow::MemoryMappedInputStream.new(@tempfile.path)
assert do
not input.closed?
end
input.close
assert do
input.closed?
end
end

def test_size
tempfile = Tempfile.open("arrow-memory-mapped-input-stream")
tempfile.write("Hello")
tempfile.close
input = Arrow::MemoryMappedInputStream.new(tempfile.path)
input = Arrow::MemoryMappedInputStream.new(@tempfile.path)
begin
assert_equal(5, input.size)
assert_equal(@data.bytesize, input.size)
ensure
input.close
end
end

def test_read
tempfile = Tempfile.open("arrow-memory-mapped-input-stream")
tempfile.write("Hello World")
tempfile.close
input = Arrow::MemoryMappedInputStream.new(tempfile.path)
input = Arrow::MemoryMappedInputStream.new(@tempfile.path)
begin
buffer = input.read(5)
assert_equal("Hello", buffer.data.to_s)
Expand All @@ -55,10 +64,7 @@ def test_read
end

def test_read_at
tempfile = Tempfile.open("arrow-memory-mapped-input-stream")
tempfile.write("Hello World")
tempfile.close
input = Arrow::MemoryMappedInputStream.new(tempfile.path)
input = Arrow::MemoryMappedInputStream.new(@tempfile.path)
begin
buffer = input.read_at(6, 5)
assert_equal("World", buffer.data.to_s)
Expand All @@ -68,10 +74,7 @@ def test_read_at
end

def test_mode
tempfile = Tempfile.open("arrow-memory-mapped-input-stream")
tempfile.write("Hello World")
tempfile.close
input = Arrow::MemoryMappedInputStream.new(tempfile.path)
input = Arrow::MemoryMappedInputStream.new(@tempfile.path)
begin
assert_equal(Arrow::FileMode::READWRITE, input.mode)
ensure
Expand Down