Skip to content

Commit

Permalink
chore(common/web): Merge branch 'master' into test/common/web/types/9…
Browse files Browse the repository at this point in the history
…052-unit-tests-file-types
  • Loading branch information
markcsinclair committed Dec 3, 2024
2 parents b923e13 + c233208 commit 15a171f
Show file tree
Hide file tree
Showing 197 changed files with 7,690 additions and 1,503 deletions.
15 changes: 15 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# Keyman Version History

## 18.0.150 alpha 2024-12-02

* fix(core,developer): use `NDEBUG` flag to disable assertions in release build (#12715)

## 18.0.149 alpha 2024-12-01

* refactor(developer): unify test action (#12736)

## 18.0.148 alpha 2024-11-29

* test(common/web/types): unit tests for unicodeset-parser-api (#12714)
* chore(developer): rename test files (#12707)
* feat(core,linux,developer,windows): implement loading KMX from blob (#12721)
* chore(common): add offline support for emscripten (#12740)

## 18.0.147 alpha 2024-11-28

* docs(android): Add android/docs/internal/README (#12717)
Expand Down
2 changes: 1 addition & 1 deletion VERSION.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
18.0.148
18.0.151
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ public void onStartInput(EditorInfo attribute, boolean restarting) {
super.onStartInput(attribute, restarting);
KMManager.onStartInput(attribute, restarting);
KMManager.resetContext(KeyboardType.KEYBOARD_TYPE_SYSTEM);

// Determine special handling for ENTER key
int inputType = attribute.inputType;
KMManager.setEnterMode(attribute.imeOptions, inputType);

// User switched to a new input field so we should extract the text from input field
// and pass it to Keyman Engine together with selection range
InputConnection ic = getCurrentInputConnection();
Expand Down
28 changes: 14 additions & 14 deletions common/include/test_assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
#include <string>
#include "test_color.h"

#ifdef _assert_failed
#undef _assert_failed
#ifdef _test_assert_failed
#undef _test_assert_failed
#endif
#define _assert_failed(result, exprText) { \
#define _test_assert_failed(result, exprText) { \
std::wcerr << console_color::fg(console_color::BRIGHT_RED) \
<< "Test failed with " << (result) \
<< " at " << __FILE__ << ":" << __LINE__ << ":" \
Expand All @@ -31,23 +31,23 @@
#define try_status(expr) { \
auto __s = (expr); \
if (__s != KM_CORE_STATUS_OK) { \
_assert_failed(__s, u ## #expr); \
_test_assert_failed(__s, u ## #expr); \
} \
}

#ifdef assert
#undef assert
#ifdef test_assert
#undef test_assert
#endif
#define assert(expr) { \
#define test_assert(expr) { \
if (!(expr)) { \
_assert_failed(0, u ## #expr); \
_test_assert_failed(0, u ## #expr); \
} \
}

#ifdef assert_equal
#undef assert_equal
#ifdef test_assert_equal
#undef test_assert_equal
#endif
#define assert_equal(actual, expected) { \
#define test_assert_equal(actual, expected) { \
if ((actual) != (expected)) { \
std::wcerr << console_color::fg(console_color::BRIGHT_RED) \
<< "Test failed at " << __FILE__ << ":" << __LINE__ << ":" \
Expand All @@ -59,10 +59,10 @@
} \
}

#ifdef assert_string_equal
#undef assert_string_equal
#ifdef test_assert_string_equal
#undef test_assert_string_equal
#endif
#define assert_string_equal(actual, expected) { \
#define test_assert_string_equal(actual, expected) { \
if (u16cmp((actual), (expected)) != 0) { \
std::wcerr << console_color::fg(console_color::BRIGHT_RED) \
<< "Test failed at " << __FILE__ << ":" << __LINE__ << ":" \
Expand Down
8 changes: 6 additions & 2 deletions common/include/test_color.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@

#include <ostream>

#ifdef _MSC_VER
#include <io.h>
#else
#include <unistd.h>
#endif

namespace console_color {

enum ansi_code {
Expand Down Expand Up @@ -65,12 +71,10 @@ __define_ansi_code__(reversed, "7");
#undef __define_ansi_code__

#ifdef _MSC_VER
#include <io.h>
inline bool isaterminal() {
return _isatty(_fileno(stdout));
}
#else
#include <unistd.h>
inline bool isaterminal() {
return isatty(STDOUT_FILENO);
}
Expand Down
8 changes: 7 additions & 1 deletion common/windows/delphi/general/KeymanPaths.pas
Original file line number Diff line number Diff line change
Expand Up @@ -436,12 +436,18 @@ class function TKeymanPaths.RunningFromSource(var keyman_root: string): Boolean;
class function TKeymanPaths.KeymanCoreLibraryPath(const Filename: string): string;
var
keyman_root: string;
configuration: string;
begin
// Look up KEYMAN_ROOT development variable -- if found and executable
// within that path then use that as source path
if TKeymanPaths.RunningFromSource(keyman_root) then
begin
Exit(keyman_root + 'core\build\x86\debug\src\' + Filename);
{$IFDEF DEBUG}
configuration := 'debug';
{$ELSE}
configuration := 'release';
{$ENDIF}
Exit(keyman_root + 'core\build\x86\'+configuration+'\src\' + Filename);
end;

Result := GetDebugPath('KeymanCoreLibraryPath', '');
Expand Down
66 changes: 64 additions & 2 deletions core/include/keyman/keyman_core_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,11 @@ Provides read-only information about a keyboard.
typedef struct {
km_core_cu const * version_string;
km_core_cu const * id;

// TODO-web-core: Deprecate this field (#12497)
// KMN_DEPRECATED
km_core_path_name folder_path;

km_core_option_item const * default_options;
} km_core_keyboard_attrs;

Expand All @@ -1022,7 +1026,7 @@ typedef struct {
: Keyman keyboard ID string.
`folder_path`
: Path to the unpacked folder containing the keyboard and associated resources.
: Path to the unpacked folder containing the keyboard and associated resources (deprecated).
`default_options`
: Set of default values for any options included in the keyboard.
Expand Down Expand Up @@ -1096,12 +1100,16 @@ typedef struct {
## Description
DEPRECATED: use [km_core_keyboard_load_from_blob] instead.
Parse and load keyboard from the supplied path and a pointer to the loaded keyboard
into the out paramter.
into the out parameter.
## Specification
```c */
// TODO-web-core: Deprecate this function (#12497)
// KMN_DEPRECATED_API
KMN_API
km_core_status
km_core_keyboard_load(km_core_path_name kb_path,
Expand Down Expand Up @@ -1140,6 +1148,60 @@ km_core_keyboard_load(km_core_path_name kb_path,
-------------------------------------------------------------------------------
# km_core_keyboard_load_from_blob()
## Description
Parse and load keyboard from the supplied blob and a pointer to the loaded keyboard
into the out paramter.
## Specification
```c */
KMN_API
km_core_status km_core_keyboard_load_from_blob(const km_core_path_name kb_name,
const void* blob,
const size_t blob_size,
km_core_keyboard** keyboard);

/*
```
## Parameters
`kb_name`
: a string with the name of the keyboard.
`blob`
: a byte array containing the content of a KMX/KMX+ file.
`blob_size`
: a size_t variable with the size of the blob in bytes.
`keyboard`
: A pointer to result variable: A pointer to the opaque keyboard
object returned by the Processor. This memory must be freed with a
call to [km_core_keyboard_dispose].
## Returns
`KM_CORE_STATUS_OK`
: On success.
`KM_CORE_STATUS_NO_MEM`
: In the event an internal memory allocation fails.
`KM_CORE_STATUS_IO_ERROR`
: In the event the keyboard file is unparseable for any reason
`KM_CORE_STATUS_INVALID_ARGUMENT`
: In the event `keyboard` is null.
`KM_CORE_STATUS_OS_ERROR`
: Bit 31 (high bit) set, bits 0-30 are an OS-specific error code.
-------------------------------------------------------------------------------
# km_core_keyboard_dispose()
## Description
Expand Down
5 changes: 3 additions & 2 deletions core/include/keyman/keyman_core_api_bits.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#define _kmn_unused(x) UNUSED_ ## x __attribute__((__unused__))
#else
#define _kmn_unused(x) UNUSED_ ## x

#endif

#if defined _WIN32 || defined __CYGWIN__
Expand All @@ -36,7 +35,7 @@
#undef _kmn_static_flag
#else // How MSVC sepcifies function level attributes adn deprecation
#define _kmn_and
#define _kmn_tag_fn(a) __declspec(a)
#define _kmn_tag_fn(a) __declspec(a)
#define _kmn_deprecated_flag deprecated
#endif
#define _kmn_export_flag dllexport
Expand All @@ -48,6 +47,8 @@
#define _KM_CORE_EXT_SEPARATOR ('.')
#endif

#define KMN_DEPRECATED _kmn_tag_fn(_kmn_deprecated_flag)

#if defined KM_CORE_LIBRARY_STATIC
#define KMN_API _kmn_tag_fn(_kmn_static_flag)
#define KMN_DEPRECATED_API _kmn_tag_fn(_kmn_deprecated_flag _kmn_and _kmn_static_flag)
Expand Down
4 changes: 4 additions & 0 deletions core/src/action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ bool km::core::action_item_list_to_actions_object(
if(output.empty()) {
actions->code_points_to_delete++;
} else {
#ifndef NDEBUG
auto last_context_item = output.back();
#endif
output.pop_back();
assert(last_context_item.type == KM_CORE_CT_CHAR);
assert(last_context_item.character == action_items->backspace.expected_value);
Expand All @@ -71,7 +73,9 @@ bool km::core::action_item_list_to_actions_object(
if(output.empty()) {
// deleting a marker has no effect on the application
} else {
#ifndef NDEBUG
auto last_context_item = output.back();
#endif
output.pop_back();
assert(last_context_item.type == KM_CORE_CT_MARKER);
assert(last_context_item.marker == action_items->backspace.expected_value);
Expand Down
7 changes: 2 additions & 5 deletions core/src/keyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,16 @@ void keyboard_attributes::render()
// Make attributes point to the stored values above.
id = _keyboard_id.c_str();
version_string = _version_string.c_str();
folder_path = _folder_path.c_str();
default_options = _default_opts.data();
}


keyboard_attributes::keyboard_attributes(std::u16string const & kbid,
std::u16string const & version,
path_type const & path,
options_store const &opts)
: _keyboard_id(kbid),
_version_string(version),
_folder_path(path),
_folder_path(""),
_default_opts(opts)
{
// Ensure that the default_options array will be properly terminated.
Expand All @@ -40,7 +38,7 @@ keyboard_attributes::keyboard_attributes(std::u16string const & kbid,
keyboard_attributes::keyboard_attributes(keyboard_attributes &&rhs)
: _keyboard_id(std::move(rhs._keyboard_id)),
_version_string(std::move(rhs._version_string)),
_folder_path(std::move(rhs._folder_path)),
_folder_path(""),
_default_opts(std::move(rhs._default_opts))
{
rhs.id = rhs.version_string = nullptr;
Expand All @@ -58,7 +56,6 @@ json & km::core::operator << (json & j, km::core::keyboard_attributes const & kb
{
j << json::object
<< "id" << kb.id
<< "folder" << kb._folder_path
<< "version" << kb.version_string
<< "rules" << json::array << json::close;

Expand Down
5 changes: 1 addition & 4 deletions core/src/keyboard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ namespace core
{
std::u16string _keyboard_id;
std::u16string _version_string;
// unused and deprecated
core::path _folder_path;
std::vector<option> _default_opts;

void render();

public:
using options_store = decltype(_default_opts);
using path_type = decltype(_folder_path);

keyboard_attributes()
: km_core_keyboard_attrs {nullptr, nullptr, nullptr, nullptr} {}
Expand All @@ -42,7 +42,6 @@ namespace core

keyboard_attributes(std::u16string const & id,
std::u16string const & version,
path_type const & path,
options_store const &opts);

keyboard_attributes & operator = (keyboard_attributes const &) = delete;
Expand All @@ -52,8 +51,6 @@ namespace core

options_store const & default_opts_store() const noexcept { return _default_opts; }
options_store & default_opts_store() noexcept { return _default_opts; }

path_type const & path() const noexcept { return _folder_path; }
};

json & operator << (json &, km::core::keyboard_attributes const &);
Expand Down
Loading

0 comments on commit 15a171f

Please sign in to comment.