chore(developer): restored kmcompxtest, adapted readme

This commit is contained in:
Sabine 2023-01-19 14:08:00 +01:00
parent 1a552a9036
commit db72606b08
4 changed files with 25 additions and 33 deletions

View file

@ -1,9 +1,9 @@
# **Tests for kmcompxtest()**
<br/>
This folder contains several kmn-files that are used for testing resulting Errorcodes.
This folder contains several kmn-files that are used for testing resulting error codes.
Most of these tests are copied from balochi_phonetic and contain alterations of the data to produce (at least) 1 Error.
Most of these tests are copied from balochi_phonetic and contain alterations of the data to produce (at least) 1 error.
<br/>
<br/>
@ -20,24 +20,27 @@ The naming convention of the files is as follows:
* 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.
* 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).
( e.g. CERR_404D_balochi_phonetic.kmn should produce error 0x0000404D).
<br/>
---
<br/>
While running kmcompxtest extracts the 4 chars from the Filename and compares them to the actual Error found.
While running, kmcompxtest extracts those 4 characters from the Filename (e.g. 404D for CERR_404D_balochi_phonetic) and compares those to the actual error found.
* If they correspond the test will be marked as OK. (Code 0)
* If these 4 characters correspond to the actual error given, the test will be marked as OK. (Code 0)
<br/>
* If these 4 characters signifiy an error but **no error** does occur, the test will be marked as FAILED (Code 1)
<br/>
* If these 4 characters signifiy an error but this **specific error** does not occur, the test will be marked as FAILED (Code 4)
<br/>
* If these 4 characters signifiy an error number that is **not correct**, the test will be marked as FAILED (Code 5)
<br/>
* If more than 1 error is produced, only the error coded in the Filename will be detected
* If the file is supposed to produce an Error and does not the test will be marked as FAILED (Code 1)
* If the filename is not correct the test will be marked as FAILED (Code 1)
* If more than 1 Error is produced only the Error coded in the Filename will be detected
### Tests are available for the following CERR_:

Binary file not shown.

Binary file not shown.

View file

@ -48,7 +48,7 @@ int main(int argc, char *argv[])
if (kmcmp_CompileKeyboardFile(kmn_file, kmx_file, FALSE, FALSE, TRUE, msgproc)) {
char* testname = strrchr( (char*) kmn_file, '\\') + 1;
if (strncmp(testname, pfirst5, 5) == 0) return 1; //no Error found + CERR_ in Name
if (strncmp(testname, pfirst5, 5) == 0) return 1; // exit code 1: CERR_ in Name + no Error found
// TODO: compare argv[2] to ../build/argv[2]
FILE* fp1 = fopen(argv[2], "rb");
@ -56,25 +56,13 @@ int main(int argc, char *argv[])
strcpy(fname, argv[2]);
char* p = strrchr(fname, '\\');
if (!p) p = fname;
strcpy(p, "\\..\\build\\");
strcpy(p, "\\..\\build\\");
char* q = strrchr(argv[2], '\\');
if (!q) q = argv[2]; else q++;
strcat(p, q);
/*
// TODO: compare kmx_file to ../build/kmx_file
FILE* fp1 = fopen(kmx_file, "rb");
char fname[260];
strcpy(fname, kmx_file);
kmx_file[strlen(kmx_file)-1] = 'x'; // .kmn->.kmx
*/
FILE* fp2 = fopen(fname, "rb");
if (!fp2) return 0; //assume pass if no reference kmx file
if (!fp2) return 0; // exit code 0: assume pass if no reference kmx file in build-folder
fseek(fp1, 0, SEEK_END);
auto sz1 = ftell(fp1);
@ -82,15 +70,16 @@ int main(int argc, char *argv[])
fseek(fp2, 0, SEEK_END);
auto sz2 = ftell(fp2);
fseek(fp2, 0, SEEK_SET);
if (sz1 != sz2) return 2;
if (sz1 != sz2) return 2; // exit code 2: size of kmx-file in build differs from size of kmx-file in source folder
char* buf1 = new char[sz1];
char* buf2 = new char[sz1];
fread(buf1, 1, sz1, fp1);
fread(buf2, 1, sz1, fp2);
return memcmp(buf1, buf2, sz1) ? 3 : 0;
return memcmp(buf1, buf2, sz1) ? 3 : 0; // exit code 3: when contents of kmx-file in build differs from contents of kmx-file in source folder
// exit code 0: when contents of kmx-file in build and source folder are the same
}
else /*if Errors found check number (e.g. CERR_4061_balochi_phonetic.kmn should produce Error 4061)*/
else /*if Errors found: check number (e.g. CERR_4061_balochi_phonetic.kmn should produce Error 4061)*/
{
int error_val = 0;
char* testname = strrchr( (char*) kmn_file, '\\') + 1;
@ -104,12 +93,12 @@ int main(int argc, char *argv[])
// check if error_val is in Array of Errors; if it is found return 0 (it's not an error)
for (int i = 0; i < error_vec.size() ; i++) {
if (error_vec[i] == error_val)
return 0;
return 0; // exit code 0: CERR_ in Name + Error (specified in CERR_Name) IS found
}
return 4;
return 4; // exit code 4: CERR_ in Name + Error (specified in CERR_Name) is NOT found
}
else
return 1; // no CERR_ in Name => CompileKeyboardFile failed
return 5; // exit code 5: no correct CERR_ in Name + CompileKeyboardFile failed
}
return 1;
return 6; // exit code 6: else
}