chore(developer): move tests (for ErrorMessages) to common/test/keyboards

This commit is contained in:
Sabine 2022-09-16 20:22:51 +02:00
parent e5bdeebc28
commit 92c5c01e95
3 changed files with 42 additions and 11 deletions

View file

@ -0,0 +1,28 @@
#-----------------------------------------
# Tests for kmcompxtest()
#-----------------------------------------
This folder contains several kmn-files that are used for testing resulting Errorcodes.
These tests are all copied from balochi_phonetic and contain alterations of the data to produce (at least) 1 Error.
#-----------------------------------------
# Naming Convention:
# CERR_404D_balochi_phonetic.kmn
#-----------------------------------------
The naming convention of the files is as follows:
All Files MUST start with CERR_ followed by 4 characters and an underscore.
After the second underscore all combination of char can be used.
The 4 characters following CERR_ correspond to the last 4 digits of the Error-Code which is expected to be produced by this file.
( e.g. CERR_404D_balochi_phonetic.kmn should produce Error 0x0000404D ).
#-----------------------------------------
While running kmcompxtest extracts the 4 chars of the Filename and compares them to the actual Error found.
If they correspond the test will be marked as OK.
If the file is supposed to produce an Error and does not the test will be marked as FAILED
If more than 1 Error is produced only the Error coded in the Filename will be detected
#-----------------------------------------

View file

@ -14,6 +14,8 @@ rem - vietnamese_telex
rem - vietnamese_telex_legacy
rem - vietnamese_vni
rem dir /s/b ..\..\..\..\keyboards\release\*.kmn | more | findstr /v /i "viet*" | findstr /v /i "eKwTamil99UniUpdt" | findstr /v /i "CERR*"
rem added CERR_XXXX-Tests to test if right ErrorMessage is sent
dir /s/b ..\..\..\common\test\keyboards\kmcompx_tests\*.kmn
dir /s/b ..\..\..\..\keyboards\release\*.kmn | more | findstr /v /i "viet*" | findstr /v /i "eKwTamil99UniUpdt"

View file

@ -11,7 +11,6 @@
#include <vector>
#include <string>
#include <sstream>
//#include <bitset>
using namespace std;
vector < int > error_vec;
@ -42,7 +41,13 @@ int main(int argc, char *argv[])
puts(argv[1]);
puts(argv[2]);
char first5[6] = "CERR_";
char* pfirst5 = first5;
if (CompileKeyboardFile(argv[1], argv[2], FALSE, FALSE, TRUE, msgproc)) {
char* Testname = 1 + strrchr( (char*) argv[1], '\\');
if (strncmp(Testname, pfirst5, 5) == 0) return 1; //no Error found + CERR_ in Name
// TODO: compare argv[2] to ../build/argv[2]
FILE* fp1 = fopen(argv[2], "rb");
char fname[260];
@ -71,22 +76,18 @@ int main(int argc, char *argv[])
fread(buf2, 1, sz1, fp2);
return memcmp(buf1, buf2, sz1) ? 3 : 0;
}
else /*if Errors are found - check if errors are tested for */
else /*if Errors found check number (CERR_4061_balochi_phonetic.kmn should produce Error 4061)*/
{
// check failed tests for Errornumber in Name
// e.g. (CERR_4061_balochi_phonetic.kmn contains Error 4061)
char* Testname = 1 + strrchr( (char*) argv[1], '\\');
char first5[6] = "CERR_";
char* pfirst5 = first5;
int Error_Val = 0;
char* ErrNr= 1+strchr(Testname, '_');
char* ErrNr = 1 + strchr(Testname, '_');
ErrNr[4] = '\0';
int Error_Val = 0;
// Does Testname contain CERR_Nr ?-> Get Value
// Does Testname contain CERR_Nr ? -> Get Value
if (strncmp(Testname, pfirst5, 5) == 0) {
std::istringstream(ErrNr) >> std::hex >> Error_Val;
// check if Error_Val is in Array of Errors; if it is found return 0 ( its not an error)
// check if Error_Val is in Array of Errors; if it is found return 0 (its not an error)
for (int i = 0; i < error_vec.size() ; i++) {
if (error_vec[i] == Error_Val)
return 0;