mirror of
https://github.com/keymanapp/keyman.git
synced 2026-09-30 03:27:44 +00:00
These two codes are not true error or message codes, but are used as return values extensively throughout kmcmplib. The codes are never passed to message callbacks. As such, I have renamed them to reflect usage, but opted not to change their values as there would be some risk in doing so (e.g. use of `!v` vs `v == CERR_None`).
99 lines
3.3 KiB
C++
99 lines
3.3 KiB
C++
/*
|
|
* Keyman is copyright (C) SIL International. MIT License.
|
|
*
|
|
* API endpoint unit tests for kmcmplib
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
|
|
#ifdef _MSC_VER
|
|
#include <io.h>
|
|
#else
|
|
#include <unistd.h>
|
|
#endif
|
|
|
|
#include <vector>
|
|
#include <string>
|
|
#include <kmcmplibapi.h>
|
|
#include <kmn_compiler_errors.h>
|
|
#include "../src/compfile.h"
|
|
#include <test_assert.h>
|
|
#include "util_filesystem.h"
|
|
#include "util_callbacks.h"
|
|
|
|
void setup();
|
|
void test_kmcmp_CompileKeyboard(char *kmn_file);
|
|
void test_GetCompileTargetsFromTargetsStore();
|
|
|
|
int main(int argc, char *argv[]) {
|
|
if(argc < 1) {
|
|
puts("Usage: api-test <full-path-to-blank_keyboard.kmn>");
|
|
puts("Warning: blank_keyboard will be overwritten");
|
|
return 1;
|
|
}
|
|
setup();
|
|
test_kmcmp_CompileKeyboard(argv[1]);
|
|
|
|
test_GetCompileTargetsFromTargetsStore();
|
|
|
|
return 0;
|
|
}
|
|
|
|
void setup() {
|
|
error_vec.clear();
|
|
}
|
|
|
|
/*
|
|
TODO: tests to run:
|
|
4. ANSI (no BOM of course) #8884
|
|
8. file without blank last line (cannot compare with fixture due to bug in kmcmpdll...)
|
|
Hint to add: k004_ansi.kmn: Hint: 10A6 Keyman Developer has detected that the file has ANSI encoding. Consider converting this file to UTF-8
|
|
*/
|
|
|
|
void test_kmcmp_CompileKeyboard(char *kmn_file) {
|
|
// Create an empty file
|
|
FILE *fp = Open_File(kmn_file, "wb");
|
|
fclose(fp);
|
|
|
|
// It should fail when a zero-byte file is passed in
|
|
KMCMP_COMPILER_RESULT result;
|
|
KMCMP_COMPILER_OPTIONS options;
|
|
options.saveDebug = true;
|
|
options.compilerWarningsAsErrors = false;
|
|
options.warnDeprecatedCode = true;
|
|
options.shouldAddCompilerVersion = false;
|
|
options.target = CKF_KEYMAN;
|
|
assert(!kmcmp_CompileKeyboard(kmn_file, options, msgproc, loadfileProc, nullptr, result));
|
|
assert(error_vec.size() == 1);
|
|
assert(error_vec[0] == CERR_InfileNotExist); // zero byte no longer gives us CERR_CannotReadInfile
|
|
|
|
unlink(kmn_file);
|
|
}
|
|
|
|
extern KMX_DWORD GetCompileTargetsFromTargetsStore(const KMX_WCHAR* store, int &targets);
|
|
|
|
void test_GetCompileTargetsFromTargetsStore() {
|
|
int targets = 0;
|
|
assert(GetCompileTargetsFromTargetsStore(u"any", targets) == STATUS_Success);
|
|
assert(targets == (COMPILETARGETS_KMX | COMPILETARGETS_JS));
|
|
assert(GetCompileTargetsFromTargetsStore(u"windows", targets) == STATUS_Success);
|
|
assert(targets == COMPILETARGETS_KMX);
|
|
assert(GetCompileTargetsFromTargetsStore(u"desktop", targets) == STATUS_Success);
|
|
assert(targets == COMPILETARGETS_KMX);
|
|
assert(GetCompileTargetsFromTargetsStore(u"mobile", targets) == STATUS_Success);
|
|
assert(targets == COMPILETARGETS_JS);
|
|
assert(GetCompileTargetsFromTargetsStore(u"web", targets) == STATUS_Success);
|
|
assert(targets == COMPILETARGETS_JS);
|
|
assert(GetCompileTargetsFromTargetsStore(u"desktop mobile", targets) == STATUS_Success);
|
|
assert(targets == (COMPILETARGETS_KMX | COMPILETARGETS_JS));
|
|
assert(GetCompileTargetsFromTargetsStore(u"desktop tablet", targets) == STATUS_Success);
|
|
assert(targets == (COMPILETARGETS_KMX | COMPILETARGETS_JS));
|
|
assert(GetCompileTargetsFromTargetsStore(u"foo bar baz", targets) == CERR_InvalidTarget);
|
|
assert(targets == 0);
|
|
assert(GetCompileTargetsFromTargetsStore(u"windows chromeos", targets) == CERR_InvalidTarget);
|
|
assert(targets == 0);
|
|
assert(GetCompileTargetsFromTargetsStore(u" ", targets) == CERR_NoTargetsSpecified);
|
|
assert(targets == 0);
|
|
assert(GetCompileTargetsFromTargetsStore(u"", targets) == CERR_NoTargetsSpecified);
|
|
assert(targets == 0);
|
|
}
|