From 92c5c01e955ad4b7f2e02db73eae9bd26edecd2b Mon Sep 17 00:00:00 2001 From: Sabine Date: Fri, 16 Sep 2022 20:22:51 +0200 Subject: [PATCH] chore(developer): move tests (for ErrorMessages) to common/test/keyboards --- common/test/keyboards/kmcompx_tests/README.md | 28 +++++++++++++++++++ .../get_test_source_exclude_some_kmn.bat | 4 ++- developer/kmcompx/tests/kmcompxtest.cpp | 21 +++++++------- 3 files changed, 42 insertions(+), 11 deletions(-) create mode 100644 common/test/keyboards/kmcompx_tests/README.md diff --git a/common/test/keyboards/kmcompx_tests/README.md b/common/test/keyboards/kmcompx_tests/README.md new file mode 100644 index 0000000000..1650b764ce --- /dev/null +++ b/common/test/keyboards/kmcompx_tests/README.md @@ -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 +#----------------------------------------- + + + diff --git a/developer/kmcompx/tests/get_test_source_exclude_some_kmn.bat b/developer/kmcompx/tests/get_test_source_exclude_some_kmn.bat index 56958f0008..6244e88358 100644 --- a/developer/kmcompx/tests/get_test_source_exclude_some_kmn.bat +++ b/developer/kmcompx/tests/get_test_source_exclude_some_kmn.bat @@ -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" diff --git a/developer/kmcompx/tests/kmcompxtest.cpp b/developer/kmcompx/tests/kmcompxtest.cpp index a8b656ec83..c25c9db45f 100644 --- a/developer/kmcompx/tests/kmcompxtest.cpp +++ b/developer/kmcompx/tests/kmcompxtest.cpp @@ -11,7 +11,6 @@ #include #include #include -//#include 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;