Skip to content

Commit

Permalink
chore(core): add a test to print out ICU and Unicode version
Browse files Browse the repository at this point in the history
  • Loading branch information
srl295 committed May 13, 2024
1 parent d3c9fbb commit 337dd45
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 2 deletions.
16 changes: 14 additions & 2 deletions core/tests/unit/ldml/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,26 @@ if cpp_compiler.get_id() == 'emscripten'
normalization_tests_flags += ['-lnodefs.js', '-sEXPORTED_RUNTIME_METHODS=[\'UTF8ToString\']']
endif

t = executable('test_context_normalization',
tc = executable('test_context_normalization',
['test_context_normalization.cpp', '../emscripten_filesystem.cpp'],
cpp_args: defns + warns,
include_directories: [inc, libsrc, '../../../../developer/src/ext/json'],
link_args: links + normalization_tests_flags,
dependencies: [icu_uc, icu_i18n],
objects: lib.extract_all_objects(recursive: false))
test('test_context_normalization', t, suite: 'ldml')
test('test_context_normalization', tc, suite: 'ldml')

# Build and run additional test_unicode test

u = executable('test_unicode', 'test_unicode.cpp',
'test_unicode.cpp',
cpp_args: defns + warns,
include_directories: [inc, libsrc, '../../../../developer/src/ext/json'],
link_args: links + tests_flags,
dependencies: [icu_uc, icu_i18n],
objects: lib.extract_all_objects(recursive: false))
test('test_unicode', u, suite: 'ldml')


# Run tests on all keyboards (`tests` defined in keyboards/meson.build)

Expand Down
72 changes: 72 additions & 0 deletions core/tests/unit/ldml/test_unicode.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
Copyright: © 2024 SIL International.
Description: Tests for normalization in the context API.
Create Date: 3 May 2024
Authors: Steven R. Loomis
History: 3 May 2024 - SRL - Initial implementation.
*/

#include <string>
#include "keyman_core.h"

#include "path.hpp"
#include "action.hpp"

#include <test_assert.h>
#include "../emscripten_filesystem.h"
#include <unicode/uversion.h>
#include <unicode/uchar.h>

//-------------------------------------------------------------------------------------
// Unicode version tests
//-------------------------------------------------------------------------------------

std::string arg_path;

void test_unicode_versions() {
std::cout << "== " << __FUNCTION__ << std::endl;

std::cout << "ICU: " << U_ICU_VERSION << std::endl;
std::cout << "Unicode: " << U_UNICODE_VERSION << std::endl;

}

void test_all() {
std::cout << "= " << __FUNCTION__ << std::endl;
test_unicode_versions();
}

//-------------------------------------------------------------------------------------
// Launcher
//-------------------------------------------------------------------------------------

constexpr const auto help_str = "\
test_unicode [--color]\n\
\n\
--color Force color output\n";

int error_args() {
std::cerr << "test_unicode: Invalid arguments." << std::endl;
std::cout << help_str;
return 1;
}

int main(int argc, char *argv []) {
auto arg_color = argc > 1 && std::string(argv[1]) == "--color";
console_color::enabled = console_color::isaterminal() || arg_color;

// Get the path of the current executable
arg_path = argv[0];
auto last = arg_path.find_last_of("/\\");
if(last == std::string::npos) {
std::cerr << "could not parse argv[0]: " << argv[0] << std::endl;
return 1;
}
arg_path.resize(last+1);

#ifdef __EMSCRIPTEN__
arg_path = get_wasm_file_path(arg_path);
#endif

test_all();
}

0 comments on commit 337dd45

Please sign in to comment.