mirror of
https://github.com/keymanapp/keyman.git
synced 2026-08-05 08:25:32 +00:00
- split keyboard loading into loading KMX file into blob and then loading the keyboard processor from the blob. - deprecate `km_core_keyboard_load` - move file access next to deprecated method. This is now the only place that loads a file in Core; unit tests have some more places that load files. - introduce GTest and add unit tests for loading from blob Cherry-picked from `epic/web-core` branch. Cherry-Pick-Commit:1deaa323adCherry-Pick-Commit:59019cc8b7Cherry-Pick-Commit:bc46458368Cherry-Pick-Commit:d06aa29956Cherry-Pick-Commit:1c88166f6eCherry-Pick-Commit:069cd21ecdCherry-Pick-Commit:052ae2ec35Cherry-Pick-Commit:11a2a3ba3aPart-of: #11293 Part-of: #8093
34 lines
724 B
C++
34 lines
724 B
C++
#include <fstream>
|
|
#include <iostream>
|
|
#include <list>
|
|
#include <string>
|
|
|
|
#include "kmx_file.h"
|
|
#include "path.hpp"
|
|
#include "utfcodec.hpp"
|
|
|
|
namespace km::tests {
|
|
|
|
std::vector<uint8_t> load_kmx_file(km::core::path const& kb_path) {
|
|
std::vector<uint8_t> data;
|
|
std::ifstream file(static_cast<std::string>(kb_path), std::ios::binary | std::ios::ate);
|
|
if (file.fail()) {
|
|
return std::vector<uint8_t>();
|
|
}
|
|
const std::streamsize size = file.tellg();
|
|
if (size >= KMX_MAX_ALLOWED_FILE_SIZE) {
|
|
return std::vector<uint8_t>();
|
|
}
|
|
|
|
file.seekg(0, std::ios::beg);
|
|
|
|
data.resize((size_t)size);
|
|
if (!file.read((char*)data.data(), size)) {
|
|
return std::vector<uint8_t>();
|
|
}
|
|
|
|
file.close();
|
|
return data;
|
|
}
|
|
|
|
}
|