Skip to content

Commit

Permalink
Wrap the libopenmpt informational error functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
hainesr committed Aug 25, 2018
1 parent d9c5f8b commit 25052d2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lib/ffi/openmpt/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,31 @@ module API
attach_function :openmpt_log_func_silent, [:string, :pointer], :void

# Error handling API calls
OPENMPT_ERROR_OK = 0
OPENMPT_ERROR_BASE = 256

OPENMPT_ERROR_UNKNOWN = OPENMPT_ERROR_BASE + 1
OPENMPT_ERROR_EXCEPTION = OPENMPT_ERROR_BASE + 11
OPENMPT_ERROR_OUT_OF_MEMORY = OPENMPT_ERROR_BASE + 21

OPENMPT_ERROR_RUNTIME = OPENMPT_ERROR_BASE + 30
OPENMPT_ERROR_RANGE = OPENMPT_ERROR_BASE + 31
OPENMPT_ERROR_OVERFLOW = OPENMPT_ERROR_BASE + 32
OPENMPT_ERROR_UNDERFLOW = OPENMPT_ERROR_BASE + 33

OPENMPT_ERROR_LOGIC = OPENMPT_ERROR_BASE + 40
OPENMPT_ERROR_DOMAIN = OPENMPT_ERROR_BASE + 41
OPENMPT_ERROR_LENGTH = OPENMPT_ERROR_BASE + 42
OPENMPT_ERROR_OUT_OF_RANGE = OPENMPT_ERROR_BASE + 43
OPENMPT_ERROR_INVALID_ARGUMENT = OPENMPT_ERROR_BASE + 44

OPENMPT_ERROR_GENERAL = OPENMPT_ERROR_BASE + 101
OPENMPT_ERROR_INVALID_MODULE_POINTER = OPENMPT_ERROR_BASE + 102
OPENMPT_ERROR_ARGUMENT_NULL_POINTER = OPENMPT_ERROR_BASE + 103

attach_function :openmpt_error_is_transient, [:int], :int
attach_function :openmpt_error_string, [:int], :pointer

OPENMPT_ERROR_FUNC_RESULT_NONE = 0
OPENMPT_ERROR_FUNC_RESULT_LOG = (1 << 0)
OPENMPT_ERROR_FUNC_RESULT_STORE = (1 << 1)
Expand Down
13 changes: 13 additions & 0 deletions test/openmpt_api_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ def test_logging_funcs
assert_nil openmpt_log_func_silent('hello', nil)
end

def test_error_information_funcs
assert_equal openmpt_error_is_transient(OPENMPT_ERROR_OUT_OF_MEMORY), 1
assert_equal openmpt_error_is_transient(OPENMPT_ERROR_LOGIC), 0

err = openmpt_error_string(OPENMPT_ERROR_OUT_OF_MEMORY)
assert_equal err.read_string, 'out of memory'
openmpt_free_string(err)

err = openmpt_error_string(11_111)
assert_equal err.read_string, 'unknown error'
openmpt_free_string(err)
end

def test_error_funcs
assert_equal openmpt_error_func_default(1, nil),
OPENMPT_ERROR_FUNC_RESULT_DEFAULT
Expand Down

0 comments on commit 25052d2

Please sign in to comment.